IndexList.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /**
  43. * 前台用于筛选的类型集合
  44. * @return mixed
  45. */
  46. public function getFilterTypes()
  47. {
  48. if (!$this->filterTypes) {
  49. $this->filterTypes = [
  50. 'TITLE'=> ['name'=> Yii::t('ctx', 'title')],
  51. 'COUNTRY'=> [
  52. 'name'=> \Yii::t('ctx', 'country'),
  53. 'other'=> 'select',
  54. 'selectData'=> self::getCountry()
  55. ],
  56. 'STATUS'=> [
  57. 'name'=> Yii::t('ctx', 'activeStatus'),
  58. 'other'=> 'select',
  59. 'selectData'=> [
  60. ['id'=> 0, 'name'=> Yii::t('ctx', 'Hide')],
  61. ['id'=> 1, 'name'=> Yii::t('ctx', 'Show')]
  62. ]
  63. ],
  64. ];
  65. }
  66. return $this->filterTypes;
  67. }
  68. public function getCountry()
  69. {
  70. $admin = Admin::findOne(Yii::$app->user->id);
  71. $roleId = $admin->ROLE_ID;
  72. if ($roleId == \Yii::$app->params['superAdminRoleId']) {
  73. $countries = Countries::find()->asArray()->all();
  74. } else {
  75. $countries = Countries::find()
  76. ->select('COU.ID, COU.CODE, COU.NAME')
  77. ->from(['COU' => Countries::tableName()])
  78. ->join('INNER JOIN', AdminCountry::tableName() . ' AS ADL', 'ADL.COUNTRY_ID = COU.ID')
  79. ->where(['ADL.ADMIN_ID' => $admin->ID])
  80. ->asArray()
  81. ->all();
  82. }
  83. $data = [];
  84. foreach ($countries as $country) {
  85. $data[] = [
  86. 'id' => $country['ID'],
  87. 'name' => $country['NAME'],
  88. ];
  89. }
  90. return $data;
  91. }
  92. }