IndexList.php 4.0 KB

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