IndexList.php 4.2 KB

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