| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace common\models;
- use backendApi\modules\v1\models\Admin;
- use backendApi\modules\v1\models\AdminCountry;
- use common\helpers\Tool;
- use Yii;
- /**
- * This is the model class for table "{{%ARTICLE}}".
- *
- * @property string $ID
- * @property string $COUNTRY_ID 国家ID
- * @property string $TITLE 标题
- * @property string $CID 分类ID
- * @property string $CONTENT 内容
- * @property int $STATUS 状态
- * @property int $SORT 排序值
- * @property int $CREATED_AT 创建时间
- */
- class Article extends \common\components\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%ARTICLE}}';
- }
- public function dataHandle()
- {
- $this->condition .= '';
- $this->listData = Article::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' => Article::tableName().' AS ART',
- 'join' => [
- ['INNER JOIN', Countries::tableName() . ' AS ADC', 'ADC.ID=ART.COUNTRY_ID'],
- ],
- 'orderBy' => 'ART.SORT ASC,ART.CREATED_AT DESC',
- ]);
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CID', 'CREATED_AT', 'COUNTRY_ID'], 'required'],
- [['COUNTRY_ID'], 'string'],
- [['STATUS', 'CREATED_AT', 'SORT'], 'integer'],
- [['ID', 'CID'], 'string', 'max' => 32],
- [['TITLE'], 'string', 'max' => 255],
- [['CONTENT'], 'string', 'max' => 4000],
- [['TITLE'], 'unique'],
- [['ID'], 'unique'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'TITLE' => Yii::t('app', 'title'),
- 'COUNTRY_ID' => Yii::t('app', 'country'),
- 'CID' => Yii::t('app', 'category'),
- 'CONTENT' => Yii::t('app', 'content'),
- 'STATUS' => Yii::t('app', 'state'),
- 'Order' => Yii::t('app', 'sort'),
- 'CREATED_AT' => Yii::t('app', 'createAt'),
- ];
- }
- /**
- * 前台用于筛选的类型集合
- * @return mixed
- */
- public function getFilterTypes()
- {
- if (!$this->filterTypes) {
- $this->filterTypes = [
- 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
- 'COUNTRY'=> [
- 'name'=> \Yii::t('ctx', 'country'),
- 'other'=> 'select',
- 'selectData'=> self::getCountry()
- ],
- 'STATUS'=> [
- 'name'=> Yii::t('ctx', 'activeStatus'),
- '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;
- }
- }
|