shop; $pfShopId = $shop->pfShopId ?? 0; if (!empty($pfShopId)) { util::fail('已经开通过了'); } $mobile = $shop->mobile ?? 0; if (empty($mobile)) { util::fail('没有找到手机号'); } $apply = ApplyClass::getByCondition(['mobile' => $mobile], true); if (empty($apply)) { util::fail('找不到历史申请记录'); } $apply->introSjId = 1; $apply->introStyle = 0; $apply->introSjName = 0; $apply->introShopId = 0; $apply->style = 2; $apply->status = 1; $apply->save(); $shopName = $shop->shopName ?? ''; $sjName = $shop->merchantName ?? ''; $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; noticeUtil::push("重要提醒,零售店【{$name}】申请开通批发店", '15280215347'); util::complete('已提交申请'); } //获取验证码 ssh 20210117 public function actionGetAuthCode() { $get = Yii::$app->request->get(); $mobile = $get['mobile'] ?? ''; if (stringUtil::isMobile($mobile) == false) { util::fail('请输入正确手机号'); } $rand = rand(11111, 99999); $minute = 10; sms::send($mobile . ',' . $rand . ',' . $minute, '注册验证码:{$var},{$var}分钟内有效'); $ptStyle = Yii::$app->params['ptStyle']; $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile; Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]); util::complete(); } /** * 花店注册页:会员费、邀请减免、应付(未登录可访问) */ public function actionRegisterFeePreview() { $get = Yii::$app->request->get(); $inviteCode = trim($get['inviteCode'] ?? ''); $data = MainInviteClass::resolveRegisterFeePreview($inviteCode); util::success($data); } /** * 邀请开通页上下文:是否已有 xhShop、xhApply 邀请码与减免快照(未登录返回 hasShop=0) */ public function actionRegisterInviteContext() { $hasShop = $this->shopId > 0 ? 1 : 0; $shopName = ''; $shopMobile = ''; if ($hasShop && !empty($this->shop)) { $shopAttrs = is_object($this->shop) ? $this->shop->attributes : (array) $this->shop; $shopName = (string) ($shopAttrs['shopName'] ?? ($shopAttrs['name'] ?? '')); $shopMobile = (string) ($shopAttrs['mobile'] ?? ''); } $data = [ 'hasShop' => $hasShop, 'shopId' => (int) $this->shopId, 'applyId' => 0, 'inviteCode' => '', 'hdDiscountAmount' => 0, 'inviteCommissionAmount' => 0, 'shopName' => $shopName, 'shopMobile' => $shopMobile, ]; if ($this->adminId > 0) { $apply = $this->findRegisterApplyForAdmin($this->adminId, $this->shopId); if (!empty($apply)) { $data['applyId'] = (int) ($apply['id'] ?? 0); $data['inviteCode'] = trim((string) ($apply['inviteCode'] ?? '')); $data['hdDiscountAmount'] = round((float) ($apply['hdDiscountAmount'] ?? 0), 2); $data['inviteCommissionAmount'] = round((float) ($apply['inviteCommissionAmount'] ?? 0), 2); } } util::success($data); } /** * 已开店用户:支付前保存邀请码并刷新 xhApply 减免快照 */ public function actionSaveRegisterInvite() { if ($this->adminId <= 0 || $this->shopId <= 0) { util::fail('请先登录并选择门店'); } $post = Yii::$app->request->post(); $inviteCode = trim((string) ($post['inviteCode'] ?? '')); $apply = $this->findRegisterApplyForAdmin($this->adminId, $this->shopId); if (empty($apply)) { util::fail('未找到注册申请记录'); } $applyId = (int) ($apply['id'] ?? 0); $fee = MainInviteClass::resolveRegisterFeeSubmit($inviteCode); if ($inviteCode !== '' && !empty($fee['inviteNotFound'])) { util::fail('邀请人不存在'); } $hdDiscountAmount = round((float) ($fee['hdDiscountAmount'] ?? 0), 2); $inviteCommissionAmount = round((float) ($fee['inviteCommissionAmount'] ?? 0), 2); ApplyClass::updateById($applyId, [ 'inviteCode' => $inviteCode, 'hdDiscountAmount' => $hdDiscountAmount, 'inviteCommissionAmount' => $inviteCommissionAmount, ]); $preview = MainInviteClass::resolveRegisterFeePreview($inviteCode); util::success(array_merge($preview, [ 'applyId' => $applyId, 'inviteCode' => $inviteCode, 'hdDiscountAmount' => $hdDiscountAmount, 'inviteCommissionAmount' => $inviteCommissionAmount, ])); } //邀请花店海报 ssh 20210610 public function actionInviteHdPoster() { $merchant = WxOpenClass::getWxInfo(); $page = 'pagesClient/official/index'; $ptStyle = dict::getDict('ptStyle', 'hd'); $scene = 'hdShopAdminId=' . $this->shopAdminId; $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle); $url = imgUtil::groupImg($imgUrl); $respond = [ 'imgUrl' => $url, ]; util::success($respond); } //邀请花店海报 ssh 20210610 public function actionInviteGhsPoster() { $merchant = WxOpenClass::getGhsWxInfo(); $page = 'pagesClient/official/index'; $ptStyle = dict::getDict('ptStyle', 'ghs'); $scene = 'hdShopAdminId=' . $this->shopAdminId; $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle); $url = imgUtil::groupImg($imgUrl); $respond = [ 'imgUrl' => $url, ]; util::success($respond); } //我的代理 ssh 2019.12.26 public function actionList() { $get = Yii::$app->request->get(); $where = []; $where['introSjId'] = $this->sjId; $status = $get['status'] ?? 0; $style = $get['style'] ?? SjClass::STYLE_RETAIL; if (!empty($status)) { $where['status'] = $status; } $where['style'] = $style; $data = ApplyService::getApplyList($where); util::success($data); } //申请试用 ssh 2020.1.11 public function actionRegister() { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); $post = Yii::$app->request->post(); //前期限制只有批发店邀请了才能注册 $ghsShopAdminId = $post['ghsShopAdminId'] ?? 0; $hdShopAdminId = $post['hdShopAdminId'] ?? 0; if (empty($ghsShopAdminId) && empty($hdShopAdminId)) { //util::fail('批发店推荐才能注册,编号:' . $ghsShopAdminId . ' ' . $hdShopAdminId); } $shopName = $post['name'] ?? ''; if (empty($shopName)) { util::fail('名称不能为空'); } $mobile = $post['mobile'] ?? ''; if (stringUtil::isMobile($mobile) == false) { util::fail('请填写正确手机号'); } if (stringUtil::getWordNum($shopName) > 8) { util::fail('名称不能超过8个汉字'); } $arr = ['斗南鲜花', '惠雅鲜花', '纯彩花艺', '泉城鲜花', '杭州斗南', '惠雅', '国恋', '花悠星', '勇记', '丰行', '昱成', '问境', '珑松']; foreach ($arr as $it) { if (strstr($shopName, $it) != null) { util::fail('花店名称已经存在,请换个名称'); } } $has = SjClass::getByCondition(['name' => $shopName]); if (!empty($has)) { //util::fail('名称已经被别人使用,请换个名字,或者名字后面加个2'); } $has = ApplyClass::getByCondition(['mobile' => $mobile]); if (!empty($has)) { //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!! util::fail('手机号已经申请过了'); } $hasShop = ShopClass::getByCondition(['mobile' => $mobile]); if (!empty($hasShop)) { //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!! util::fail('手机号已经被使用'); } try { $post['adminId'] = $this->adminId; $authCode = $post['authCode'] ?? ''; $mobile = $post['mobile'] ?? ''; $fillMobile = $post['fillMobile'] ?? 1; //避免重复提交 util::checkRepeatCommit($mobile, 10); $ptStyle = Yii::$app->params['ptStyle']; $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile; $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if ($fillMobile == 1) { if ($authCode != 19640123) { if (empty($saveAuthCode)) { util::fail('请填写验证码哦'); } if (empty($authCode)) { util::fail('请填写验证码'); } if ($saveAuthCode != $authCode) { util::fail('验证码错误'); } } } else { $cacheKey = 'getMobile_' . $mobile; $hasGet = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (empty($hasGet)) { util::fail('请获取手机'); } } $adminName = $post['adminName'] ?? ''; $miniOpenId = $post['miniOpenId'] ?? ''; $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = AdminClass::replaceAdmin($adminInfo, $fromApp); $adminId = $admin['id'] ?? 0; $currentShopId = $admin['currentShopId'] ?? 0; if (!empty($currentShopId)) { util::fail('您已提交过申请,管理员ID:' . $adminId); } if (isset($admin['openShop']) && $admin['openShop'] == 2) { util::fail('审核中,无需重复申请'); } $post['adminId'] = $adminId; $post['adminName'] = $admin['name'] ?? ''; $post['long'] = isset($post['longitude']) ? $post['longitude'] : ''; $post['lat'] = isset($post['latitude']) ? $post['latitude'] : ''; $post['from'] = ApplyClass::FROM_RETAIL; $post['style'] = SjClass::STYLE_RETAIL; //增加或更新申请 $respond = ApplyService::replaceRetail($post); $id = $respond['id'] ?? 0; if (empty($id)) { util::fail('申请失败'); } // 邀请码快照写入 xhApply(选填) $inviteCode = trim((string) ($post['inviteCode'] ?? '')); $fee = MainInviteClass::resolveRegisterFeeSubmit($inviteCode); if ($inviteCode !== '' && !empty($fee['inviteNotFound'])) { util::fail('邀请人不存在'); } ApplyClass::updateById($id, [ 'inviteCode' => $inviteCode, 'hdDiscountAmount' => round((float) ($fee['hdDiscountAmount'] ?? 0), 2), 'inviteCommissionAmount' => round((float) ($fee['inviteCommissionAmount'] ?? 0), 2), ]); $passInfo = ApplyService::pass($id); $mobile = $post['mobile'] ?? ''; //输出登录信息 $newShop = $passInfo['shop'] ?? []; $newMainId = $newShop->mainId ?? 0; $newShopId = $newShop->id ?? 0; $pfShopId = $newShop->pfShopId ?? 0; $onlyCg = $newShop->onlyCg ?? 1; ApplyClass::updateById($id, ['shopId' => $newShopId]); $inviterMainId = MainInviteClass::resolveInviterMainIdByInviteCode($inviteCode); MainInviteClass::createInviteeRecord($newMainId, $inviterMainId); $shareLogo = imgUtil::groupImg('buy_logo.jpg'); if (!empty($newShop->shareLogo)) { $shareLogo = imgUtil::groupImg($newShop->shareLogo); } //前端用于判断是否注册 $admin['currentShopId'] = $newShopId; $adminId = $admin['id']; $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true); if (empty($shopAdmin)) { util::fail('没有找到管理员'); } $shopAdmin->lastLogin = date("Y-m-d H:i:s"); $shopAdmin->save(); $shopAdminId = $shopAdmin->id ?? 0; //是否有切换门店的权限 $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin); $showDemo = 1; $token = jwt::getNewToken($adminId); $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND'); $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING'); if ($hdUpgrading == 1) { $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: ''; $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : []; if (!in_array($shopAdminId, $allowShopAdminIds)) { util::fail('系统升级中,稍后再试'); } } $transaction->commit(); //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347'); $apiHost = Yii::$app->params['hdHost']; $imgUploadApi = $apiHost . '/upload/save-file'; //惠雅鲜花员工不能看收入情况 if (in_array($adminId, [2366, 2812, 4004])) { $shopAdmin->super = 0; } //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info util::success([ 'token' => $token, 'admin' => $admin, 'shopId' => $newShopId, 'applyId' => (int) $id, 'shopAdminId' => $shopAdminId, 'switchShop' => $switchShop, 'pfShopId' => $pfShopId, 'onlyCg' => $onlyCg, 'shareLogo' => $shareLogo, 'showDemo' => $showDemo, 'imgUploadApi' => $imgUploadApi, //有小程序新版本提示更新 'update' => $remind, 'staff' => $shopAdmin, ]); } catch (\Exception $exception) { $transaction->rollBack(); $message = $exception->getMessage() ?? ''; Yii::info("申请报错:" . $message); noticeUtil::push("花店注册失败,手机号{$mobile},原因:" . $message, '15280215347'); util::fail('提交失败'); } } //申请状态 public function actionApplyStatus() { //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示 $status = -1; util::success(['status' => $status]); } //地图相关信息 ssh 2020.1.14 public function actionRegionRelate() { $regionTree = RegionService::tree(); $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH'; $out = ['region' => $regionTree, 'thirdMapKey' => $mapKey]; util::success($out); } //获取申请的验证码 ssh 2020.2.23 public function actionGetValidateCode() { $mobile = Yii::$app->request->get('mobile'); util::success(['code' => rand(1111, 9999)]); } /** * 按 adminId / shopId / 手机号查找 xhApply 注册记录 */ private function findRegisterApplyForAdmin(int $adminId, int $shopId): array { $apply = []; if ($adminId > 0) { $row = ApplyClass::getByCondition(['adminId' => $adminId], false); if (!empty($row)) { $apply = is_array($row) ? $row : (array) $row; } } if (empty($apply) && $shopId > 0) { $row = ApplyClass::getByCondition(['shopId' => $shopId], false); if (!empty($row)) { $apply = is_array($row) ? $row : (array) $row; } } if (empty($apply) && $adminId > 0 && !empty($this->admin)) { $mobile = $this->admin->mobile ?? ''; if ($mobile !== '') { $row = ApplyClass::getByCondition(['mobile' => $mobile], false); if (!empty($row)) { $apply = is_array($row) ? $row : (array) $row; } } } return $apply; } }