StoreAuditController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace addons\Happiness\backend\controllers;
  3. use addons\Happiness\common\enums\HappinessEnum;
  4. use addons\Happiness\common\models\HappinessStore;
  5. use common\enums\AddonsEnum;
  6. use common\enums\StatusEnum;
  7. use common\models\common\Region;
  8. use common\models\user\User;
  9. class StoreAuditController extends BaseController
  10. {
  11. public function actionIndex()
  12. {
  13. if (!\Yii::$app->request->isAjax) {
  14. $upload_license_image = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_HAPPINESS,
  15. '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 = HappinessEnum::CHECK_WAITING;
  28. } else {
  29. $check_status = HappinessEnum::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,business_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. 'with' => ['business'=>function ($query) {
  62. $query->select('id,nickname,mobile');
  63. }],
  64. 'limit' => $limit,
  65. ];
  66. $happiness_list = HappinessStore::listPage($params);
  67. if (false === $happiness_list) {
  68. return $this->error(HappinessStore::getStaticError());
  69. }
  70. if (!empty($happiness_list['list'])) {
  71. if (empty($users)) {
  72. $user_ids = array_unique(array_column($happiness_list['list'], 'user_id'));
  73. $users = User::find()
  74. ->select('id,nickname,mobile,avatar_url')
  75. ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  76. ->asArray()
  77. ->indexBy('id')
  78. ->all();
  79. }
  80. $region_ids = [];
  81. $province_ids = array_unique(array_column($happiness_list['list'], 'province_id'));
  82. $city_ids = array_unique(array_column($happiness_list['list'], 'city_id'));
  83. $district_ids = array_unique(array_column($happiness_list['list'], 'district_id'));
  84. $region_ids = array_merge($province_ids, $city_ids, $district_ids);
  85. $regions = Region::find()
  86. ->select('id,name')
  87. ->where(['id' => $region_ids])
  88. ->asArray()
  89. ->indexBy('id')
  90. ->all();
  91. foreach ($happiness_list['list'] as &$list) {
  92. $user = $users[$list['user_id']] ?? [];
  93. $province = $regions[$list['province_id']] ?? [];
  94. $city = $regions[$list['city_id']] ?? [];
  95. $district = $regions[$list['district_id']] ?? [];
  96. $list['nickname'] = $user['nickname'] ?? '';
  97. $list['user_mobile'] = $user['mobile'] ?? '';
  98. $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  99. $list['store_address'] = ($province['name'] ?? '') . ($city['name'] ?? '') . ($district['name'] ?? '') . $list['address'];
  100. if ($list['check_status'] == HappinessEnum::CHECK_WAITING) {
  101. $list['check_status'] = 1;
  102. }
  103. if($list['business'])
  104. {
  105. $list['business']['avatar_url']=$list['business']['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  106. }
  107. }
  108. }
  109. return $this->success('success', $happiness_list);
  110. }
  111. }
  112. /**
  113. * @name:
  114. * @msg: 门店审核
  115. * @param {*}
  116. * @return {*}
  117. */
  118. public function actionAudit()
  119. {
  120. if (!\Yii::$app->request->isPost) {
  121. return $this->error('请求方式错误');
  122. }
  123. $post = \Yii::$app->request->post();
  124. if (!in_array($post['action'], ['adopt', 'reject'])) {
  125. return $this->error('参数错误');
  126. }
  127. $rules = [
  128. [['id', 'action'], 'required'],
  129. ['id', 'integer'],
  130. [['action', 'check_remark'], 'string'],
  131. ['check_remark', 'safe'],
  132. ['check_remark', 'string', 'max' => 255],
  133. ];
  134. $res = \Yii::$app->services->validate->validate($post, $rules);
  135. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  136. if ('adopt' == $post['action']) {
  137. $check_status = HappinessEnum::CHECK_ADOPT;
  138. } else {
  139. $check_status = HappinessEnum::CHECK_FAILED;
  140. }
  141. $params = [
  142. 'mall_id' => $this->mall_id,
  143. 'id' => $post['id'],
  144. 'check_status' => $check_status,
  145. 'check_remark' => $post['check_remark'] ?? '',
  146. ];
  147. $res = HappinessStore::setData($params);
  148. if (false === $res) {
  149. return $this->error(HappinessStore::getStaticError());
  150. }
  151. return $this->success('操作成功');
  152. }
  153. }