IndexList.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. 'COUNTRY_NAME' => null,
  56. 'STATUS' => [
  57. 'header' => Yii::t('ctx', 'status'),
  58. 'headerOther' => ['width' => '100'],
  59. ],
  60. 'SORT' => null,
  61. 'CREATED_AT' => [
  62. 'header' => Yii::t('ctx', 'createTime'),
  63. 'headerOther' => ['width' => '180'],
  64. ],
  65. ];
  66. }
  67. return $this->columns;
  68. }
  69. /**
  70. * 前台用于筛选的类型集合
  71. * @return mixed
  72. */
  73. public function getFilterTypes()
  74. {
  75. if (!$this->filterTypes) {
  76. $this->filterTypes = [
  77. 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
  78. 'COUNTRY'=> [
  79. 'name'=> \Yii::t('ctx', 'country'),
  80. 'other'=> 'select',
  81. 'selectData'=> self::getCountry()
  82. ],
  83. 'STATUS'=> [
  84. 'name'=> Yii::t('ctx', 'status'),
  85. 'other'=> 'select',
  86. 'selectData'=> [
  87. ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
  88. ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
  89. ]
  90. ],
  91. ];
  92. }
  93. return $this->filterTypes;
  94. }
  95. public function getCountry()
  96. {
  97. $admin = Admin::findOne(Yii::$app->user->id);
  98. $roleId = $admin->ROLE_ID;
  99. if ($roleId == \Yii::$app->params['superAdminRoleId']) {
  100. $countries = Countries::find()->asArray()->all();
  101. } else {
  102. $countries = Countries::find()
  103. ->select('COU.ID, COU.CODE, COU.NAME')
  104. ->from(['COU' => Countries::tableName()])
  105. ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
  106. ->where(['ADL.ADMIN_ID' => $admin->ID])
  107. ->asArray()
  108. ->all();
  109. }
  110. $data = [];
  111. foreach ($countries as $country) {
  112. $data[] = [
  113. 'id' => $country['ID'],
  114. 'name' => $country['NAME'],
  115. ];
  116. }
  117. return $data;
  118. }
  119. }