StoreAuditController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace addons\Mch\backend\controllers;
  3. use addons\Mch\common\enums\MchEnum;
  4. use addons\Mch\common\models\Mch;
  5. use addons\Mch\common\models\MchCate;
  6. use common\enums\AddonsEnum;
  7. use common\enums\StatusEnum;
  8. use common\models\common\Region;
  9. use common\models\user\User;
  10. class StoreAuditController extends BaseController
  11. {
  12. public function actionIndex()
  13. {
  14. if (!\Yii::$app->request->isAjax) {
  15. $upload_license_image = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_MCH, 'enter.upload_license_image');
  16. if(empty($upload_license_image)) $upload_license_image= 0;
  17. return $this->render('/store-audit/index',['upload_license_image'=>$upload_license_image]);
  18. }
  19. if (\Yii::$app->request->isGet) {
  20. $page = \Yii::$app->request->get('page', 1);
  21. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  22. $tabname = \Yii::$app->request->get('tabname', 'waiting-audit');
  23. if (!in_array($tabname, ['waiting-audit', 'reject'])) {
  24. return $this->error('参数错误');
  25. }
  26. if ('waiting-audit' == $tabname) {
  27. $check_status = MchEnum::CHECK_WAITING;
  28. } else {
  29. $check_status = MchEnum::CHECK_FAILED;
  30. }
  31. $store_name = \Yii::$app->request->get('store_name');
  32. $cate_id = \Yii::$app->request->get('cate_id');
  33. $storeowner = \Yii::$app->request->get('storeowner');
  34. $nickname = \Yii::$app->request->get('nickname');
  35. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => $check_status];
  36. if (!empty($cate_id)) {
  37. $wheres[] = ['c_id' => $cate_id];
  38. }
  39. if (!empty($store_name)) {
  40. $wheres[] = ['like', 'store_name', $store_name];
  41. }
  42. if (!empty($storeowner)) {
  43. $wheres[] = ['like', 'shop_owner', $storeowner];
  44. }
  45. if (!empty($nickname)) {
  46. $users = User::find()
  47. ->select('id,nickname,mobile,avatar_url')
  48. ->where(['like', 'nickname', $nickname])
  49. ->andWhere(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  50. ->asArray()
  51. ->indexBy('id')
  52. ->all();
  53. $user_ids = array_column($users, 'id');
  54. $wheres[] = ['user_id' => $user_ids];
  55. }
  56. $params = [
  57. 'select' => 'id,mall_id,user_id,shop_owner,shop_mobile,store_name,c_id,province_id,city_id,district_id,address,logo_img,check_status,created_at,license_img',
  58. 'where' => $wheres,
  59. 'order' => 'created_at desc',
  60. 'page' => $page,
  61. 'limit' => $limit,
  62. ];
  63. $mch_list = Mch::listPage($params);
  64. if (false === $mch_list) {
  65. return $this->error(Mch::getStaticError());
  66. }
  67. if (!empty($mch_list['list'])) {
  68. if (empty($users)) {
  69. $user_ids = array_unique(array_column($mch_list['list'], 'user_id'));
  70. $users = User::find()
  71. ->select('id,nickname,mobile,avatar_url')
  72. ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  73. ->asArray()
  74. ->indexBy('id')
  75. ->all();
  76. }
  77. $cate_ids = array_unique(array_column($mch_list['list'], 'c_id'));
  78. $categorys = MchCate::find()
  79. ->select('id,name')
  80. ->where(['id' => $cate_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  81. ->asArray()
  82. ->indexBy('id')
  83. ->all();
  84. $region_ids = [];
  85. $province_ids = array_unique(array_column($mch_list['list'], 'province_id'));
  86. $city_ids = array_unique(array_column($mch_list['list'], 'city_id'));
  87. $district_ids = array_unique(array_column($mch_list['list'], 'district_id'));
  88. $region_ids = array_merge($province_ids, $city_ids, $district_ids);
  89. $regions = Region::find()
  90. ->select('id,name')
  91. ->where(['id' => $region_ids])
  92. ->asArray()
  93. ->indexBy('id')
  94. ->all();
  95. foreach ($mch_list['list'] as &$list) {
  96. $user = $users[$list['user_id']] ?? [];
  97. $category = $categorys[$list['c_id']] ?? [];
  98. $province = $regions[$list['province_id']] ?? [];
  99. $city = $regions[$list['city_id']] ?? [];
  100. $district = $regions[$list['district_id']] ?? [];
  101. $list['nickname'] = $user['nickname'] ?? '';
  102. $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  103. $list['category'] = $category['name'] ?? '';
  104. $list['store_address'] = ($province['name'] ?? '') . ($city['name'] ?? '') . ($district['name'] ?? '') . $list['address'];
  105. if ($list['check_status'] == MchEnum::CHECK_WAITING) {
  106. $list['check_status'] = 1;
  107. }
  108. }
  109. }
  110. $cate_list = MchCate::find()
  111. ->select('id,name')
  112. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  113. ->asArray()
  114. ->all();
  115. $mch_list['cate_list'] = $cate_list;
  116. return $this->success('success', $mch_list);
  117. }
  118. }
  119. /**
  120. * @name:
  121. * @msg: 门店审核
  122. * @param {*}
  123. * @return {*}
  124. */
  125. public function actionAudit()
  126. {
  127. if (!\Yii::$app->request->isPost) {
  128. return $this->error('请求方式错误');
  129. }
  130. $post = \Yii::$app->request->post();
  131. if (!in_array($post['action'], ['adopt', 'reject'])) {
  132. return $this->error('参数错误');
  133. }
  134. $rules = [
  135. [['id', 'action'], 'required'],
  136. ['id', 'integer'],
  137. [['action', 'check_remark'], 'string'],
  138. ['check_remark', 'safe'],
  139. ['check_remark', 'string', 'max' => 255],
  140. ];
  141. $res = \Yii::$app->services->validate->validate($post, $rules);
  142. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  143. if ('adopt' == $post['action']) {
  144. $check_status = MchEnum::CHECK_ADOPT;
  145. } else {
  146. $check_status = MchEnum::CHECK_FAILED;
  147. }
  148. $params = [
  149. 'mall_id' => $this->mall_id,
  150. 'id' => $post['id'],
  151. 'check_status' => $check_status,
  152. 'check_remark' => $post['check_remark'] ?? '',
  153. ];
  154. $res = Mch::setData($params);
  155. if (false === $res) {
  156. return $this->error(Mch::getStaticError());
  157. }
  158. return $this->success('操作成功');
  159. }
  160. }