IndexList.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.SORT ASC,ART.CREATED_AT DESC',
  29. ]);
  30. }
  31. public function getColumn(){
  32. if(!$this->columns){
  33. $this->columns = [
  34. 'ID' => null,
  35. 'TITLE' => null,
  36. 'CID' => [
  37. 'header' => Yii::t('ctx', 'category'),
  38. 'headerOther' => ['width' => '150'],
  39. ],
  40. 'COUNTRY_ID' => [
  41. 'header' => Yii::t('ctx', 'country'),
  42. 'headerOther' => ['width' => '150'],
  43. ],
  44. 'COUNTRY_NAME' => null,
  45. 'STATUS' => [
  46. 'header' => Yii::t('ctx', 'status'),
  47. 'headerOther' => ['width' => '100'],
  48. ],
  49. 'SORT' => null,
  50. 'CREATED_AT' => [
  51. 'header' => Yii::t('ctx', 'createTime'),
  52. 'value' => function($row) {
  53. return (new DateTime([
  54. 'value' => $row['CREATED_AT'],
  55. ]))->result();
  56. },
  57. 'headerOther' => ['width' => '180'],
  58. ],
  59. ];
  60. }
  61. return $this->columns;
  62. }
  63. /**
  64. * 前台用于筛选的类型集合
  65. * @return mixed
  66. */
  67. public function getFilterTypes()
  68. {
  69. if (!$this->filterTypes) {
  70. $this->filterTypes = [
  71. 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
  72. 'COUNTRY'=> [
  73. 'name'=> \Yii::t('ctx', 'country'),
  74. 'other'=> 'select',
  75. 'selectData'=> self::getCountry()
  76. ],
  77. 'STATUS'=> [
  78. 'name'=> Yii::t('ctx', 'status'),
  79. 'other'=> 'select',
  80. 'selectData'=> [
  81. ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
  82. ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
  83. ]
  84. ],
  85. ];
  86. }
  87. return $this->filterTypes;
  88. }
  89. public function getCountry()
  90. {
  91. $admin = Admin::findOne(Yii::$app->user->id);
  92. $roleId = $admin->ROLE_ID;
  93. if ($roleId == \Yii::$app->params['superAdminRoleId']) {
  94. $countries = Countries::find()->asArray()->all();
  95. } else {
  96. $countries = Countries::find()
  97. ->select('COU.ID, COU.CODE, COU.NAME')
  98. ->from(['COU' => Countries::tableName()])
  99. ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
  100. ->where(['ADL.ADMIN_ID' => $admin->ID])
  101. ->asArray()
  102. ->all();
  103. }
  104. $data = [];
  105. foreach ($countries as $country) {
  106. $data[] = [
  107. 'id' => $country['ID'],
  108. 'name' => $country['NAME'],
  109. ];
  110. }
  111. return $data;
  112. }
  113. }