| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopClass;
- 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\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 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();
- }
- //邀请花店海报 ssh 20210610
- public function actionInviteHdPoster()
- {
- $merchant = WxOpenClass::getWxInfo();
- $page = 'pagesClient/official/index';
- $ptStyle = dict::getDict('ptStyle', 'hd');
- $scene = 'ghsShopAdminId=' . $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 = 'ghsShopAdminId=' . $this->shopAdminId;
- $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
- $url = imgUtil::groupImg($imgUrl);
- $respond = [
- 'imgUrl' => $url,
- ];
- util::success($respond);
- }
- //邀请开店列表 ssh 2021.1.28
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $where = [];
- $where['introSjId'] = $this->sjId;
- $status = $get['status'] ?? 0;
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $data = ApplyService::getApplyList($where);
- $data['balance'] = $this->shop->balance ?? 0;
- util::success($data);
- }
- //申请试用,花店添加新客户 ssh 2021.1.8
- public function actionRegister()
- {
- $post = Yii::$app->request->post();
- $authCode = $post['authCode'] ?? '';
- $mobile = $post['mobile'] ?? '';
- if (empty($mobile)) {
- util::fail('请填写手机号');
- }
- if (!stringUtil::isMobile($mobile)) {
- util::fail('手机号错误');
- }
- $inviteCode = $post['inviteCode'] ?? '';
- if (empty($inviteCode)) {
- util::fail('请填写邀请码');
- }
- if ($inviteCode != 2025) {
- util::fail('邀请码错误');
- }
- //避免重复提交
- util::checkRepeatCommit($mobile, 10);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shopName = $post['name'] ?? '';
- if (empty($shopName)) {
- util::fail('名称不能为空');
- }
- if (stringUtil::getWordNum($shopName) > 8) {
- util::fail('名称不能超过8个汉字');
- }
- $has = SjClass::getByCondition(['name' => $shopName]);
- if (!empty($has)) {
- //util::fail('名称已经存在');
- }
- $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
- if (!empty($hasApply)) {
- //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
- if ($hasApply->status == 1) {
- util::fail('此手机号已提交过申请,审核中');
- }
- if ($hasApply->status == 3) {
- util::fail('此手机号已提交申请,审核没有通过');
- }
- util::fail('手机号已经申请过了');
- }
- $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
- if (!empty($hasShop)) {
- //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
- util::fail('手机号已经被使用');
- }
- $ptStyle = Yii::$app->params['ptStyle'];
- $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
- $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($saveAuthCode)) {
- util::fail('请填写验证码哦');
- }
- if (empty($authCode)) {
- util::fail('请填写验证码');
- }
- if ($saveAuthCode != $authCode) {
- util::fail('验证码错误');
- }
- $adminName = $post['adminName'] ?? '';
- $miniOpenId = $post['miniOpenId'] ?? '';
- $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'ghsMiniOpenId' => $miniOpenId];
- $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
- $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
- $adminId = $admin['id'] ?? 0;
- $post['adminId'] = $adminId;
- $currentShopId = $admin['currentGhsShopId'] ?? 0;
- if (!empty($currentShopId)) {
- util::fail('您已提交过申请,管理员ID:' . $adminId);
- }
- if (isset($admin['openGhsShop']) && $admin['openGhsShop'] == 2) {
- util::fail('审核中,无需重复申请');
- }
- $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
- $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
- $post['from'] = ApplyClass::FROM_GHS;
- //新申请
- ApplyService::replaceGhs($post);
- $transaction->commit();
- $noticeMobile = '15280215347';
- //sms::freeSend($noticeMobile . ',' . $mobile, '有新的批发店申请开店,手机号:{$var}');
- noticeUtil::push("供货商 {$shopName} 手机号 {$mobile} 申请开店", '15280215347');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("申请报错:" . $exception->getMessage());
- util::fail('提交失败');
- }
- util::complete();
- }
- //申请状态
- 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)]);
- }
- }
|