request->isAjax) { $upload_license_image = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter.upload_license_image'); if(empty($upload_license_image)) $upload_license_image= 0; return $this->render('/store-audit/index',['upload_license_image'=>$upload_license_image]); } if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $tabname = \Yii::$app->request->get('tabname', 'waiting-audit'); if (!in_array($tabname, ['waiting-audit', 'reject', 'record'])) { return $this->error('参数错误'); } if ('waiting-audit' == $tabname) { $check_status = StoreEnum::CHECK_WAITING; } else if ('reject' == $tabname){ $check_status = StoreEnum::CHECK_FAILED; } else { $check_status = StoreEnum::CHECK_ADOPT; } $store_name = \Yii::$app->request->get('store_name'); $cate_id = \Yii::$app->request->get('cate_id'); $storeowner = \Yii::$app->request->get('storeowner'); $nickname = \Yii::$app->request->get('nickname'); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => $check_status]; if (!empty($cate_id)) { $wheres[] = ['c_id' => $cate_id]; } if (!empty($store_name)) { $wheres[] = ['like', 'store_name', $store_name]; } if (!empty($storeowner)) { $wheres[] = ['like', 'shop_owner', $storeowner]; } if (!empty($nickname)) { $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['like', 'nickname', $nickname]) ->andWhere(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('id') ->all(); $user_ids = array_column($users, 'id'); $wheres[] = ['user_id' => $user_ids]; } $params = [ '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,street_id,community_id,is_examine', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit, ]; $store_list = Store::listPage($params); if (false === $store_list) { return $this->error(Store::getStaticError()); } if (!empty($store_list['list'])) { if (empty($users)) { $user_ids = array_unique(array_column($store_list['list'], 'user_id')); $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('id') ->all(); } $cate_ids = array_unique(array_column($store_list['list'], 'c_id')); $categorys = StoreCate::find() ->select('id,name') ->where(['id' => $cate_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->indexBy('id') ->all(); $region_ids = []; $province_ids = array_unique(array_column($store_list['list'], 'province_id')); $city_ids = array_unique(array_column($store_list['list'], 'city_id')); $district_ids = array_unique(array_column($store_list['list'], 'district_id')); $street_ids = array_unique(array_column($store_list['list'], 'street_id')); $community_ids = array_unique(array_column($store_list['list'], 'community_id')); $store_ids = array_unique(array_column($store_list['list'], 'id')); $region_ids = array_merge($province_ids, $city_ids, $district_ids); $regions = Region::find() ->select('id,name') ->where(['id' => $region_ids]) ->asArray() ->indexBy('id') ->all(); $streets = town::find() ->select('id,name') ->where(['id'=>$street_ids]) ->asArray() ->indexBy('id') ->all(); $communitys = StoreCommunity::find() ->select('id,community_name') ->where(['mall_id'=>$this->mall_id,'id'=>$community_ids]) ->asArray() ->indexBy('id') ->all(); $examineList = array_column($store_list['list'], 'is_examine'); $validExamineIds = array_unique(array_filter($examineList, function($id) {return $id !== null;})); $admins = []; if (!empty($validExamineIds)) { $admins = Admin::find()->where(['id' => $validExamineIds])->indexBy('id') ->asArray()->all(); } $adminList = []; foreach ($examineList as $examineId) { $adminList[] = $examineId !== null ? ($admins[$examineId] ?? null) : null; } $store_setting = StoreSettings::find() ->where([ 'store_id' => $store_ids, 'status' => StatusEnum::ENABLED ]) ->indexBy('store_id') ->all(); foreach ($store_list['list'] as $k => &$list) { $user = $users[$list['user_id']] ?? []; $category = $categorys[$list['c_id']] ?? []; $province = $regions[$list['province_id']] ?? []; $city = $regions[$list['city_id']] ?? []; $district = $regions[$list['district_id']] ?? []; $streetInfo = $streets[$list['street_id']] ?? []; if($list['community_id'] == '-1'){ $CommunityInfo = '其它社区'; }else{ if(isset($communitys[$list['community_id']])){ $CommunityInfo = $communitys[$list['community_id']]['community_name']; }else{ $CommunityInfo = ''; } } $list['nickname'] = $user['nickname'] ?? ''; $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; $list['category'] = $category['name'] ?? ''; //判断详细地址里面是否有省市区,如果有的话,那么就只拼接社区 preg_match('/(.*?(?:省|自治区|北京市|天津市|上海市|重庆市))+(.*?(?:市|自治州|地区|区划|县))+(.*?(?:市|区|县|镇|乡|街道))/', $list['address'], $matches); if(count($matches) > 1){ $list['store_address'] = $list['address']; }else{ $list['store_address'] = ($province['name'] ?? '') . ($city['name'] ?? '') . ($district['name'] ?? ''). ($streetInfo['name'] ?? ''). ($CommunityInfo ?? '') . $list['address']; } if ($list['check_status'] == StoreEnum::CHECK_WAITING) { $list['check_status'] = 1; } if (isset($list['is_examine']) && $list['is_examine'] !== null) { if($list['is_examine'] == -1){ $list['is_examine'] = '后台添加'; } else if ($list['is_examine'] == 0){ $list['is_examine'] = '直接通过'; } else{ $list['is_examine'] = 'id:'.$adminList[$k]['id'].','.$adminList[$k]['username']; } } $list['store_service_ratio'] = 0; if (isset($store_setting[$list['id']]) && $store_setting[$list['id']]['store_service_fee']) { $list['store_service_ratio'] = $store_setting[$list['id']]['store_service_ratio']; } } } $cate_list = StoreCate::find() ->select('id,name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $store_list['cate_list'] = $cate_list; return $this->success('success', $store_list); } } /** * @name: * @msg: 门店审核 * @param {*} * @return {*} */ public function actionAudit() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $post = \Yii::$app->request->post(); if (!in_array($post['action'], ['adopt', 'reject'])) { return $this->error('参数错误'); } $rules = [ [['id', 'action'], 'required'], ['id', 'integer'], [['action', 'check_remark'], 'string'], ['check_remark', 'safe'], ['check_remark', 'string', 'max' => 255], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if ('adopt' == $post['action']) { $check_status = StoreEnum::CHECK_ADOPT; $is_freeze = StoreEnum::FREEZE_NO; $is_admin = 1; } else { $check_status = StoreEnum::CHECK_FAILED; } $params = [ 'mall_id' => $this->mall_id, 'id' => $post['id'], 'check_status' => $check_status, 'check_remark' => $post['check_remark'] ?? '', ]; if(isset($is_freeze)){ $params['is_freeze'] = $is_freeze; } if(isset($is_admin)){ $params['is_examine'] = $this->admin->id; } $enter = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter'); if($enter['is_template'] && $enter['is_front_template']) { $params['is_sync'] = 1; } $store = Store::setData($params); if (false === $store) { return $this->error(Store::getStaticError()); } if ('adopt' == $post['action']) { // 订单为审核通过 则删除前端保留缓存 //删除草稿缓存 $res = \Yii::$app->cache->get('draft_store_apply'); if(isset($res[$this->mall_id][$store['user_id']])) { unset($res[$this->mall_id][$store['user_id']]); \Yii::$app->cache->set('draft_store_apply', $res); } } $cate = StoreCate::findOne(['id'=>$store['c_id']]); if(!empty($cate['is_collect_service_fee'])&&!empty($store['check_status'])&&$store['check_status']==1){ $exist_setting = StoreSettings::find() ->where([ 'store_id' => $store['id'], ])->one(); $cashier_info = [ 'store_service_fee' => $cate['is_collect_service_fee'], 'store_service_ratio' => $exist_setting['store_service_ratio'] ?? $cate['collect_service_fee'], 'cachier_service_ratio' => $exist_setting['store_service_ratio'] ?? $cate['collect_service_fee'], 'store_settle_type' => 1, 'store_settle_scene' =>1, 'store_id' => $store['id'], ]; StoreSettings::setData($this->mall_id,$cashier_info); } if($check_status==StoreEnum::CHECK_ADOPT){ $add_cate = [ 'mall_id'=>$this->mall_id, 'store_id'=>$post['id'], 'parent_id'=>0, 'name'=>'全部', 'pic'=>'', 'big_pic'=>'', 'advert_pic'=>'', 'advert_url'=>'', 'advert_open_type'=>'', 'advert_params'=>'', 'is_show'=>1, ]; $res = StoreGoodsCate::setData($add_cate); if(!empty($store)){ $params = [ 'mall_id'=>$store['mall_id'], 'user_id'=>$store['user_id'], 'store_id'=>$store['id'], 'remark'=>'门店审核通过添加', ]; $res = StoreClerk::setData($params); } //处理复制数据,判断是否开启模板门店、前端入驻同步模板门店 if ($enter['is_template'] && $enter['is_front_template']) { \Yii::$app->services->rabbitMq->delay(10, [ 'mall_id' => $this->mall_id, 'self_store_id'=> $store['id'], ], StoreCreateSync::class, 'synStoreData'); } //触发招商分红用户条件升级 if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_BUSINESS_BONUS)) { $store_info = Store::find() ->where(['id' => $post['id']]) ->one(); $event = new UpgradeUserEvent($this->mall_id); $data = ['mall_id' => $this->mall_id, 'user_id' => $store_info['user_id']]; \Yii::$app->services->events->dispatch($event, $data, $event->listeners); } } $key = StoreEnum::STORE_WAITING_AUDIT_STORE_NUMBERS . ':' . $this->mall_id; \Yii::$app->redis->decrby($key, 1);//待审核门店 return $this->success('操作成功'); } }