IndexList.php 4.0 KB

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