condition .= ''; $this->listData = Ad::lists($this->condition, $this->params, [ 'select' => 'AD.*', 'from' => Ad::tableName().' AS AD', 'orderBy' => 'AD.STATUS DESC,AD.SORT DESC,AD.CREATED_AT ASC', ]); // COUNTRY_ID是逗号分割的ID,需要提取国家名称、CODE foreach($this->listData['list'] as $key => $row){ $countryIds = explode(',', $row['COUNTRY_ID']); $countryNames = []; $countryCodes = []; foreach($countryIds as $countryId){ $country = Countries::findOneAsArray('ID=:ID', [':ID'=>$countryId], 'NAME,CODE'); $countryNames[] = $country['NAME']; $countryCodes[] = $country['CODE']; } $this->listData['list'][$key]['COUNTRY_NAME'] = implode(',', $countryNames); $this->listData['list'][$key]['COUNTRY_CODE'] = implode(',', $countryCodes); } } public function getColumn(){ if(!$this->columns){ $this->columns = [ 'ID' => null, 'TITLE' => [ 'header' => Yii::t('ctx', 'title'), ], 'COUNTRY_ID' => [ 'header' => Yii::t('ctx', 'country'), 'headerOther' => ['width' => '150'], ], 'COUNTRY_NAME' => null, 'COUNTRY_CODE' => null, 'LID' => [ 'header' => '广告位', 'value' => function($row){ $adLocation = AdLocation::findOneAsArray('ID=:ID', [':ID'=>$row['LID']], 'LOCATION_NAME'); return $adLocation['LOCATION_NAME']; }, 'headerOther' => ['width' => '180'], ], 'STATUS' => [ 'header' => Yii::t('ctx', 'status'), 'headerOther' => ['width' => '100'], ], // 'CONTENT' => [ // 'header' => Yii::t('ctx', 'content'), // ], 'TYPE' => null, 'SORT' => null, 'CREATED_AT' => [ 'header' => Yii::t('ctx', 'createTime'), 'value' => function($row) { return (new DateTime([ 'value' => $row['CREATED_AT'], ]))->result(); }, 'headerOther' => ['width' => '180'], ], ]; } return $this->columns; } /** * 前台用于筛选的类型集合 * @return mixed */ public function getFilterTypes() { if (!$this->filterTypes) { $this->filterTypes = [ 'TITLE'=> ['name'=> Yii::t('ctx', 'title')], // 'CONTENT' => ['name'=> Yii::t('ctx', 'content')], 'COUNTRY_ID'=> [ 'name'=> \Yii::t('ctx', 'country'), 'other'=> 'select', 'selectData'=> self::getCountry() ], 'STATUS'=> [ 'name'=> Yii::t('ctx', 'status'), 'other'=> 'select', 'selectData'=> [ ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')], ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')] ] ], ]; } return $this->filterTypes; } public function getCountry() { $admin = Admin::findOne(Yii::$app->user->id); $roleId = $admin->ROLE_ID; if ($roleId == \Yii::$app->params['superAdminRoleId']) { $countries = Countries::find()->asArray()->all(); } else { $countries = Countries::find() ->select('COU.ID, COU.CODE, COU.NAME') ->from(['COU' => Countries::tableName()]) ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID') ->where(['ADL.ADMIN_ID' => $admin->ID]) ->asArray() ->all(); } $data = []; foreach ($countries as $country) { $data[] = [ 'id' => $country['ID'], 'name' => $country['NAME'], ]; } return $data; } }