request->isGet) { return $this->error('请求方式错误'); } $settings = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter'); $community_set = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'community_set'); $community_status = $community_set['community_status']??0; $settings['community_status'] = $community_status; if (0 == $settings['is_enable']) { return $this->error('商家入驻未开启'); } //检测是否需要实名认证 $need_auth = GlobalInvoke::exec(GlobalInvoke::REAL_AUTH_BUSINESS, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'type' => 'store']); if ($need_auth === true && !empty($settings['store_auth'])) { //需要先进行实名认证 return $this->error('请先进行实名认证', [], ApiStatusEnum::CODE_ERROR_NEED_REAL_AUTH); } // dd($settings); if (!empty($settings['goods_ids'])) { $settings['goods_ids'] = json_decode($settings['goods_ids'], true); $goods = Goods::find() ->select('id,goods_name,price,cover_pic') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $settings['goods_ids']]) ->asArray() ->all(); $settings['good_list'] = $goods; } // 是否有资格入驻门店 $is_can_enter = 0; if (3 == $settings['mode']) { // 条件入驻 if (StoreEntryLimit::check($this->user_id, $this->mall_id, $settings)) $is_can_enter = 1; if ($is_can_enter == 0) { $settings['mode_3'] = StoreEntryLimit::getMode3($this->mall_id, $this->user->parent_id, $settings); } } elseif (2 == $settings['mode']) { $qualification = StoreUserEnterQualification::findOne(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]); if (!empty($qualification)) { $is_can_enter = 1; } } else { $is_can_enter = 1; } $settings['is_can_enter'] = $is_can_enter; $store = Store::find() ->select('id,mall_id,user_id,shop_owner,shop_mobile,store_name,c_id,store_desc,logo_img,license_img,address,longitude,latitude,check_status,check_remark,is_freeze') ->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->one(); // 入驻申请进度,0:未申请;1:审核中;2:审核通过;3:审核未通过 $apply_step = 0; $store_account = []; if (!empty($store)) { $store['detail_address'] = $store['address']; if (StoreEnum::CHECK_WAITING == $store['check_status']) { $apply_step = 1; } else if (StoreEnum::CHECK_ADOPT == $store['check_status'] && StoreEnum::FREEZE_NO == $store['is_freeze']) { $apply_step = 2; $backend_domain = \Yii::$app->services->setting->platform->get('system.backend_url'); $backend_domain = empty($backend_domain) ? '' : (string)$backend_domain; $store_account = [ 'store_login_url' => trim($backend_domain, '/') . '?r=store/client/auth/login&sign=' . $this->mall['mall_sign'], 'account' => $store['shop_mobile'], 'login_pwd' => substr($store['shop_mobile'], -6), ]; } else if (StoreEnum::CHECK_FAILED == $store['check_status']) { $apply_step = 3; } } $categorys = StoreCate::find() ->select('id,name') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); $basic = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_STORE, 'basic'); $settings['service_fee'] = $basic['service_fee']; $settings['service_fee_type'] = $basic['service_fee_type']; $settings['max_platform_ratio'] = $basic['max_platform_ratio']; $settings['min_platform_ratio'] = $basic['min_platform_ratio']; $result = [ 'settings' => $settings, 'apply_step' => $apply_step, 'store' => $store, 'categorys' => $categorys, 'store_account' => $store_account, 'reduce_profit_config' => (new MerchantReduceProfitService())->profit($this->mall_id, $this->user_id, 0), ]; return $this->success('success', $result); } /** * @name: * @msg: 获取社区列表 * @param {*} * @return {*} */ public function actionCommunityList(){ if(Yii::$app->request->isGet){ $params = Yii::$app->request->get(); if(empty($params['province_id']) || empty($params['city_id']) || empty($params['district_id']) || empty($params['street_id'])){ return $this->error('参数错误'); } //校验 $settings = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'community_set'); $community_status = $settings['community_status']??0; if($community_status == 0){ return $this->error('请联系相关人员开启社区管理权限'); } $community_list = StoreCommunity::find()->where(['mall_id'=>$this->mall_id,'province_id'=>$params['province_id'],'city_id'=>$params['city_id'],'district_id'=>$params['district_id'],'street_id'=>$params['street_id'],'status'=>0])->asArray()->all(); $data = ['id'=>'-1','community_name'=>'其它社区']; $community_list[] = $data; return $this->success('获取成功',['community_list'=>$community_list]); }else{ return $this->error('请求方式不正确'); } } /** * @name: * @msg: 草稿保存 * @param {*} * @return {*} */ public function actionEnterDraft() { //根据商城,用户id为键存储 if (\Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $draft_store_apply[$this->mall_id][$this->user_id] = $params; $res = Yii::$app->cache->set('draft_store_apply', $draft_store_apply); if ($res) { return $this->success('保存成功'); } } //获取存储信息 if (\Yii::$app->request->isGet) { //获取草稿 $res = Yii::$app->cache->get('draft_store_apply'); $draftInfo = []; if (isset($res[$this->mall_id][$this->user_id])) { $draft_apply = $res[$this->mall_id][$this->user_id]; $draft_apply['mall_id'] = $this->mall_id; $model = new StoreService(); //处理地区信息 $draftInfo = $model->getDraftRegionInfo($draft_apply); } return $this->success('获取成功', ['draft_info' => $draftInfo]); } } /** * @name: * @msg: 提交门店入驻申请 * @param {*} * @return {*} */ public function actionEnterApply() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $settings = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter'); $upload_license_image = $settings['upload_license_image']; $post = \Yii::$app->request->post(); $post['store_desc'] = isset($post['store_desc']) ? ''.$post['store_desc'] : ''; $post['license_img'] = isset($post['license_img']) ? ''.$post['license_img'] : ''; $rules = [ [['store_desc'], 'required','message'=>'门店介绍不能为空'], [['logo_img'], 'required','message'=>'请上传商家logo'], [['license_img'], 'required','message'=>'请上传营业执照'], [['shop_owner', 'shop_mobile', 'store_name', 'c_id', 'address', 'detail_address', 'longitude', 'latitude', 'vcode'], 'required'], [['shop_owner', 'store_name', 'address', 'detail_address', 'store_desc', 'logo_img', 'license_img', 'longitude', 'latitude'], 'string', 'max' => 255], ['vcode', 'string'], [['shop_mobile', 'c_id','province_id','city_id','district_id','street_id','community_id'], 'integer'], [['province_id','city_id','district_id','street_id','community_id'], 'default', 'value' => 0], ['license_img', 'required', 'when' => function ($model) use ($upload_license_image) { return $upload_license_image == 1; }], [['id', 'store_background'], 'safe'], [['new_rate', 'store_service_ratio'], 'number'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); if (YII_ENV != 'dev' && !Sms::checkValidateCode($post['shop_mobile'], $post['vcode'])) { return $this->error('验证码不正确'); } if (empty($post['store_background'])) unset($post['store_background']); if (empty($post['new_rate'])) unset($post['new_rate']); if (3 == $settings['mode']) { // 条件入驻 if (!StoreEntryLimit::check($this->user_id, $this->user->parent_id, $this->mall_id, $settings)) return $this->error('条件不满足,无法入驻'); } $post['address'] = $post['detail_address']; $post['mall_id'] = $this->mall_id; $post['user_id'] = $this->user_id; unset($post['detail_address']); //这里修改 查询条件 与获取详情 查询条件不一致 // $query = Store::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'shop_mobile' => $post['shop_mobile'], 'shop_owner' => $post['shop_owner']]); $query = Store::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED,'user_id'=>$this->user_id]); if (!empty($post['id'])) { $query->andWhere(['id' => $post['id']]); } else { unset($post['id']); } $store = $query->one(); if (!empty($store)) { if (empty($post['id'])) { // 新提交的申请 if($store['is_freeze'] == StoreEnum::FREEZE_YES){ $post['id'] = $store['id']; }else{ return $this->error('您已经申请过请勿重复申请'); } } else { // 审核失败后重新提交的申请 if ($store->check_status != StoreEnum::CHECK_FAILED) { return $this->error('门店状态异常'); } $store->attributes = $post; $store->check_status = StoreEnum::CHECK_WAITING; $res = $store->save(); if (!$res) { return $this->error($store->getErrorMessage()); } //更新o2o门店服务费 $this->updateStoreServiceRatio($this->mall_id, $store->id, $post['store_service_ratio']); return $this->success('提交成功'); } } if ($settings['store_audit'] == 1) { $post['check_status'] = StoreEnum::CHECK_WAITING; } else { $post['check_status'] = StoreEnum::CHECK_ADOPT; $post['is_examine'] = 0; if($settings['is_template'] && $settings['is_front_template']) { $post['is_sync'] = 1; } } // 校验是否需要提交让利比例 $profitService = new MerchantReduceProfitService(); $callback = $profitService->storeApplyCreate($this->mall_id, $this->user_id, $post); if (is_string($callback)) return $this->error($callback); $basic = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_STORE, 'basic'); $is_set_store_service_ratio = false; if ($basic['service_fee'] == 1 && $basic['service_fee_type'] == 1) { if ($post['store_service_ratio'] < $basic['min_platform_ratio'] || $post['store_service_ratio'] > $basic['max_platform_ratio']) { return $this->error('只能设置在平台服务费比例区间内的比例当前平台服务费比例:' . $basic['min_platform_ratio'] . '%~' . $basic['max_platform_ratio'] . '%'); } $is_set_store_service_ratio = true; } try { $res = Store::addStore($post, $callback); } catch (Exception|\yii\base\Exception $e) { return $this->error($e->getMessage()); } if (false === $res) { return $this->error(Store::getStaticError()); } if ($settings['store_audit'] == 1) { $key = StoreEnum::STORE_WAITING_AUDIT_STORE_NUMBERS . ':' . $this->mall_id; \Yii::$app->redis->incrby($key, 1);//待审核门店 } //更新o2o门店服务费 $this->updateStoreServiceRatio($this->mall_id, $res['id'], $post['store_service_ratio']); //处理复制数据,判断是否开启模板门店、前端入驻同步模板门店 if ($post['is_sync'] === 1 && $res) { \Yii::$app->services->rabbitMq->delay(10, [ 'mall_id' => $this->mall_id, 'self_store_id'=> $res['id'], ], StoreCreateSync::class, 'synStoreData'); } if($post['check_status']==StoreEnum::CHECK_ADOPT){ if(!empty($store)){ $params = [ 'mall_id'=>$store['mall_id'], 'user_id'=>$store['user_id'], 'store_id'=>$store['id'], 'remark'=>'门店入驻免审核添加', ]; $res = StoreClerk::setData($params); } //触发招商分红用户条件升级 if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_BUSINESS_BONUS)) { $event = new UpgradeUserEvent($this->mall_id); $data = ['mall_id' => $this->mall_id, 'user_id' => $this->user_id]; \Yii::$app->services->events->dispatch($event, $data, $event->listeners); } } return $this->success('提交成功'); } public function updateStoreServiceRatio($mall_id, $store_id, $store_service_ratio) { $basic = \Yii::$app->services->setting->addons->get($mall_id, AddonsEnum::ADDONS_NAME_STORE, 'basic'); if ($basic['service_fee'] == 1 && $basic['service_fee_type'] == 1) { if ($store_service_ratio < $basic['min_platform_ratio'] || $store_service_ratio > $basic['max_platform_ratio']) { return $this->error('只能设置在平台服务费比例区间内的比例当前平台服务费比例:' . $basic['min_platform_ratio'] . '%~' . $basic['max_platform_ratio'] . '%'); } StoreSettings::setData($mall_id, [ 'store_id'=> $store_id, 'store_service_fee'=> 1, 'store_service_ratio'=> $store_service_ratio, 'cachier_service_ratio'=> $store_service_ratio, ]); } } // 五洲-绑定关系链 public function actionBindRelation() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } if (!MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_STORE_ENTRY_LIMIT)) { return $this->error('请先安装门店入驻条件限制插件'); } $service = (new SettingService()); $entry_setting = $service->get($this->mall_id); if ($entry_setting['is_enable'] == 0) return $this->error('门店入驻条件限制插件未开启'); if (empty($entry_setting['recommend_user'])) return $this->error('推荐人不能为空'); $user = User::findOne(['id' => $entry_setting['recommend_user']]); if (empty($user)) return $this->error('推荐人不存在'); if ($this->user->parent_id != 0) return $this->error('不能修改推荐人'); if ($this->user_id == $entry_setting['recommend_user']) return $this->error('不能推荐自己'); if(MallAddons::isInstall($this->mall_id, 'UserSync')){ $configs = \Yii::$app->services->setting->addons->get($this->mall_id, 'UserSync', 'basic'); if(!empty($configs['is_enable'])){ $insert = [ 'mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'type' => 2, ]; UserSync::setData($insert); } } try { $params['user_id'] = $this->user_id; $params['parent_id'] = $entry_setting['recommend_user']; $params['ip'] = ArrayHelper::get_client_ip(); $res = User::updateParentByLock($params); if (\common\models\mall\MallAddons::isInstall($this->mall_id, \common\enums\AddonsEnum::ADDONS_NAME_STORE)) { //安装了o2o,获取关联门店数据 $store_associated_user_service = new StoreAssociatedUserService(); $store_associated_user_service->getStoreAssociated([ 'user_id' => $params['user_id'], 'mall_id' => $this->mall_id, ]); } if ($res) return $this->success('修改成功'); }catch (\Exception $e){ return $this->error($e->getMessage()); } } }