AdIndexList.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace backendApi\modules\v1\models\lists\ad;
  3. use backendApi\modules\v1\models\Admin;
  4. use backendApi\modules\v1\models\AdminCountry;
  5. use common\libs\dataList\DataListInterface;
  6. use common\models\Ad;
  7. use common\models\AdLocation;
  8. use common\models\Countries;
  9. use common\libs\dataList\column\DateTime;
  10. use Yii;
  11. class AdIndexList extends \common\libs\dataList\DataList implements DataListInterface
  12. {
  13. /**
  14. * 列表名称
  15. * @return string
  16. */
  17. public function getListName(){
  18. return '广告列表';
  19. }
  20. public function dataHandle()
  21. {
  22. $this->condition .= '';
  23. $this->listData = Ad::lists($this->condition, $this->params, [
  24. 'select' => 'AD.*,ADC.NAME AS COUNTRY_NAME, ADC.CODE AS COUNTRY_CODE',
  25. 'from' => Ad::tableName().' AS AD',
  26. 'join' => [
  27. ['INNER JOIN', Countries::tableName() . ' AS ADC', 'ADC.ID=AD.COUNTRY_ID'],
  28. ],
  29. 'orderBy' => 'AD.STATUS DESC,AD.SORT DESC,AD.CREATED_AT ASC',
  30. ]);
  31. }
  32. public function getColumn(){
  33. if(!$this->columns){
  34. $this->columns = [
  35. 'ID' => null,
  36. 'TITLE' => null,
  37. 'COUNTRY_ID' => [
  38. 'header' => Yii::t('ctx', 'country'),
  39. 'headerOther' => ['width' => '150'],
  40. ],
  41. 'COUNTRY_NAME' => null,
  42. // 'LID' => [
  43. // 'label' => '广告位',
  44. // 'type' => function($data){
  45. // $value = $data['value'];
  46. // $adLocation = AdLocation::findOneAsArray('ID=:ID', [':ID'=>$value], 'LOCATION_NAME');
  47. // return $adLocation['LOCATION_NAME'];
  48. // },
  49. // ],
  50. 'STATUS' => [
  51. 'header' => Yii::t('ctx', 'status'),
  52. 'headerOther' => ['width' => '100'],
  53. ],
  54. 'SORT' => null,
  55. 'CREATED_AT' => [
  56. 'header' => Yii::t('ctx', 'createTime'),
  57. 'value' => function($row) {
  58. return (new DateTime([
  59. 'value' => $row['CREATED_AT'],
  60. ]))->result();
  61. },
  62. 'headerOther' => ['width' => '180'],
  63. ],
  64. ];
  65. }
  66. return $this->columns;
  67. }
  68. /**
  69. * 前台用于筛选的类型集合
  70. * @return mixed
  71. */
  72. public function getFilterTypes()
  73. {
  74. if (!$this->filterTypes) {
  75. $this->filterTypes = [
  76. 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
  77. 'CONTENT' => ['name'=> Yii::t('ctx', 'content')],
  78. // 确保这里的键名与getColumn()方法中的列名一致
  79. 'COUNTRY'=> [
  80. 'name'=> \Yii::t('ctx', 'country'),
  81. 'other'=> 'select',
  82. 'selectData'=> self::getCountry()
  83. ],
  84. 'STATUS'=> [
  85. 'name'=> Yii::t('ctx', 'status'),
  86. 'other'=> 'select',
  87. 'selectData'=> [
  88. ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
  89. ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
  90. ]
  91. ],
  92. ];
  93. }
  94. return $this->filterTypes;
  95. }
  96. public function getCountry()
  97. {
  98. $admin = Admin::findOne(Yii::$app->user->id);
  99. $roleId = $admin->ROLE_ID;
  100. if ($roleId == \Yii::$app->params['superAdminRoleId']) {
  101. $countries = Countries::find()->asArray()->all();
  102. } else {
  103. $countries = Countries::find()
  104. ->select('COU.ID, COU.CODE, COU.NAME')
  105. ->from(['COU' => Countries::tableName()])
  106. ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
  107. ->where(['ADL.ADMIN_ID' => $admin->ID])
  108. ->asArray()
  109. ->all();
  110. }
  111. $data = [];
  112. foreach ($countries as $country) {
  113. $data[] = [
  114. 'id' => $country['ID'],
  115. 'name' => $country['NAME'],
  116. ];
  117. }
  118. return $data;
  119. }
  120. }