| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- namespace hd\controllers;
- use biz\shop\classes\ShopClass;
- use biz\shop\services\ShopAdminService;
- use biz\sj\classes\SjClass;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\admin\services\AdminService;
- use bizHd\saas\services\ApplyService;
- use bizHd\wx\classes\WxOpenClass;
- use common\components\dict;
- use common\components\imgUtil;
- use common\components\jwt;
- use common\components\miniUtil;
- use common\components\noticeUtil;
- use common\components\sms;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- use bizHd\saas\classes\ApplyClass;
- use bizHd\saas\services\RegionService;
- class ApplyController extends BaseController
- {
- public $guestAccess = ['register', 'get-auth-code'];
- //申请开通批发店 ssh 20231125
- public function actionOpenPf()
- {
- $shop = $this->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]);
- noticeUtil::push("注册验证码:{$rand},{$mobile} 申请注册", '15280215347');
- util::complete();
- }
- //邀请花店海报 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('申请失败');
- }
- $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;
- $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,
- '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)]);
- }
- }
|