AdIndexList.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. 'header' => '广告位',
  44. 'value' => function($row){
  45. $adLocation = AdLocation::findOneAsArray('ID=:ID', [':ID'=>$row['LID']], 'LOCATION_NAME');
  46. return $adLocation['LOCATION_NAME'];
  47. },
  48. 'headerOther' => ['width' => '180'],
  49. ],
  50. 'STATUS' => [
  51. 'header' => Yii::t('ctx', 'status'),
  52. 'headerOther' => ['width' => '100'],
  53. ],
  54. 'TYPE' => null,
  55. 'SORT' => null,
  56. 'CREATED_AT' => [
  57. 'header' => Yii::t('ctx', 'createTime'),
  58. 'value' => function($row) {
  59. return (new DateTime([
  60. 'value' => $row['CREATED_AT'],
  61. ]))->result();
  62. },
  63. 'headerOther' => ['width' => '180'],
  64. ],
  65. ];
  66. }
  67. return $this->columns;
  68. }
  69. /**
  70. * 前台用于筛选的类型集合
  71. * @return mixed
  72. */
  73. public function getFilterTypes()
  74. {
  75. if (!$this->filterTypes) {
  76. $this->filterTypes = [
  77. 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
  78. 'CONTENT' => ['name'=> Yii::t('ctx', 'content')],
  79. // 确保这里的键名与getColumn()方法中的列名一致
  80. 'COUNTRY'=> [
  81. 'name'=> \Yii::t('ctx', 'country'),
  82. 'other'=> 'select',
  83. 'selectData'=> self::getCountry()
  84. ],
  85. 'STATUS'=> [
  86. 'name'=> Yii::t('ctx', 'status'),
  87. 'other'=> 'select',
  88. 'selectData'=> [
  89. ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
  90. ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
  91. ]
  92. ],
  93. ];
  94. }
  95. return $this->filterTypes;
  96. }
  97. public function getCountry()
  98. {
  99. $admin = Admin::findOne(Yii::$app->user->id);
  100. $roleId = $admin->ROLE_ID;
  101. if ($roleId == \Yii::$app->params['superAdminRoleId']) {
  102. $countries = Countries::find()->asArray()->all();
  103. } else {
  104. $countries = Countries::find()
  105. ->select('COU.ID, COU.CODE, COU.NAME')
  106. ->from(['COU' => Countries::tableName()])
  107. ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
  108. ->where(['ADL.ADMIN_ID' => $admin->ID])
  109. ->asArray()
  110. ->all();
  111. }
  112. $data = [];
  113. foreach ($countries as $country) {
  114. $data[] = [
  115. 'id' => $country['ID'],
  116. 'name' => $country['NAME'],
  117. ];
  118. }
  119. return $data;
  120. }
  121. }