LeagueForm.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\modules\alliance\models;
  3. use app\models\SaaSLeaguePriceLog;
  4. use app\models\SaasUser;
  5. use app\models\Store;
  6. use yii\base\Model;
  7. class LeagueForm extends Model
  8. {
  9. public $saas_user;
  10. public $store_id;
  11. public $role;
  12. const ROLE_USER = 0;
  13. const ROLE_STORE = 1;
  14. public function leagueDetailLog() {
  15. if ($this->role === self::ROLE_USER) {
  16. $saas_user = $this->saas_user;
  17. $query = SaaSLeaguePriceLog::find()->alias('lpl')
  18. ->leftJoin(['su' => SaasUser::tableName()], 'su.id = lpl.saas_user_id')
  19. ->where(['lpl.role' => SaaSLeaguePriceLog::ROLE_USER, 'lpl.is_delete' => 0, 'lpl.saas_user_id' => $saas_user->id]);
  20. } else {
  21. $store_id = $this->store_id;
  22. $query = SaaSLeaguePriceLog::find()->alias('lpl')
  23. ->leftJoin(['s' => Store::tableName()], 's.id = lpl.store_id')
  24. ->where(['lpl.role' => SaaSLeaguePriceLog::ROLE_STORE, 'lpl.is_delete' => 0, 'lpl.store_id' => $store_id]);
  25. }
  26. $query->select('lpl.id, lpl.type, lpl.league_price, lpl.send_or_take_type, lpl.addtime')
  27. ->orderBy('lpl.id DESC');
  28. $list = pagination_make($query);
  29. foreach ($list['list'] as $index => &$item) {
  30. $item['send_or_take_type'] = intval($item['send_or_take_type']);
  31. $item['created_at'] = date('Y-m-d H:i:s', $item['addtime']);
  32. $item['type_text'] = SaaSLeaguePriceLog::getTypeStr($item['type']);
  33. unset($list['list'][$index]['addtime']);
  34. }
  35. return [
  36. 'code' => 0,
  37. 'msg' => '',
  38. 'data' => $list
  39. ];
  40. }
  41. }