AdIndexList.php 4.6 KB

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