AdIndexList.php 4.3 KB

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