AdIndexList.php 4.4 KB

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