|
|
@@ -0,0 +1,136 @@
|
|
|
+<?php
|
|
|
+namespace backendApi\modules\v1\models\lists\article;
|
|
|
+
|
|
|
+use backendApi\modules\v1\models\Admin;
|
|
|
+use backendApi\modules\v1\models\AdminCountry;
|
|
|
+use common\libs\dataList\DataListInterface;
|
|
|
+use common\models\Ad;
|
|
|
+use common\models\AdLocation;
|
|
|
+use common\models\Countries;
|
|
|
+use common\libs\dataList\column\DateTime;
|
|
|
+use Yii;
|
|
|
+
|
|
|
+class IndexList extends \common\libs\dataList\DataList implements DataListInterface
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 列表名称
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getListName(){
|
|
|
+ return '广告列表';
|
|
|
+ }
|
|
|
+
|
|
|
+ public function dataHandle()
|
|
|
+ {
|
|
|
+ $this->condition .= '';
|
|
|
+ $this->listData = Ad::lists($this->condition, $this->params, [
|
|
|
+ 'select' => 'ART.ID,ART.TITLE,ART.CID,ART.COUNTRY_ID,ART.STATUS,ART.SORT,ART.CREATED_AT,,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
|
|
|
+ 'from' => Ad::tableName().' AS ART',
|
|
|
+ 'join' => [
|
|
|
+ ['INNER JOIN', Countries::tableName() . ' AS ADC', 'ADC.ID=ART.COUNTRY_ID'],
|
|
|
+ ],
|
|
|
+ 'orderBy' => 'ART.SORT ASC,ART.CREATED_AT DESC',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getColumn(){
|
|
|
+ if(!$this->columns){
|
|
|
+ $this->columns = [
|
|
|
+ 'ID' => null,
|
|
|
+ 'TITLE' => null,
|
|
|
+ 'COUNTRY_ID' => [
|
|
|
+ 'header' => Yii::t('ctx', 'country'),
|
|
|
+ 'headerOther' => ['width' => '150'],
|
|
|
+ ],
|
|
|
+ 'TYPE' => null,
|
|
|
+ 'TYPE_NAME' => [
|
|
|
+ 'label' => '类型',
|
|
|
+ 'type' => function($data){
|
|
|
+ $value = $data['value'];
|
|
|
+ return $value==1 ? 'External Link' : 'Article';
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ 'LID' => [
|
|
|
+ 'label' => '广告位',
|
|
|
+ 'type' => function($data){
|
|
|
+ $value = $data['value'];
|
|
|
+ $adLocation = AdLocation::findOneAsArray('ID=:ID', [':ID'=>$value], 'LOCATION_NAME');
|
|
|
+ return $adLocation['LOCATION_NAME'];
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ 'CONTENT' => null,
|
|
|
+ 'COUNTRY_NAME' => null,
|
|
|
+ 'STATUS' => [
|
|
|
+ 'header' => Yii::t('ctx', 'status'),
|
|
|
+ 'headerOther' => ['width' => '100'],
|
|
|
+ ],
|
|
|
+ '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'=> [
|
|
|
+ '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;
|
|
|
+ }
|
|
|
+}
|