ApplyController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\shop\services\ShopAdminService;
  5. use biz\sj\classes\SjClass;
  6. use bizGhs\admin\classes\AdminClass;
  7. use bizGhs\admin\services\AdminService;
  8. use bizHd\saas\services\ApplyService;
  9. use bizHd\wx\classes\WxOpenClass;
  10. use common\components\dict;
  11. use common\components\imgUtil;
  12. use common\components\jwt;
  13. use common\components\miniUtil;
  14. use common\components\noticeUtil;
  15. use common\components\sms;
  16. use common\components\stringUtil;
  17. use Yii;
  18. use common\components\util;
  19. use bizHd\saas\classes\ApplyClass;
  20. use bizHd\saas\services\RegionService;
  21. class ApplyController extends BaseController
  22. {
  23. public $guestAccess = ['register', 'get-auth-code'];
  24. //申请开通批发店 ssh 20231125
  25. public function actionOpenPf()
  26. {
  27. $shop = $this->shop;
  28. $pfShopId = $shop->pfShopId ?? 0;
  29. if (!empty($pfShopId)) {
  30. util::fail('已经开通过了');
  31. }
  32. $mobile = $shop->mobile ?? 0;
  33. if (empty($mobile)) {
  34. util::fail('没有找到手机号');
  35. }
  36. $apply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  37. if (empty($apply)) {
  38. util::fail('找不到历史申请记录');
  39. }
  40. $apply->introSjId = 1;
  41. $apply->introStyle = 0;
  42. $apply->introSjName = 0;
  43. $apply->introShopId = 0;
  44. $apply->style = 2;
  45. $apply->status = 1;
  46. $apply->save();
  47. $shopName = $shop->shopName ?? '';
  48. $sjName = $shop->merchantName ?? '';
  49. $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  50. noticeUtil::push("重要提醒,零售店【{$name}】申请开通批发店", '15280215347');
  51. util::complete('已提交申请');
  52. }
  53. //获取验证码 ssh 20210117
  54. public function actionGetAuthCode()
  55. {
  56. $get = Yii::$app->request->get();
  57. $mobile = $get['mobile'] ?? '';
  58. if (stringUtil::isMobile($mobile) == false) {
  59. util::fail('请输入正确手机号');
  60. }
  61. $rand = rand(11111, 99999);
  62. $minute = 10;
  63. sms::send($mobile . ',' . $rand . ',' . $minute, '注册验证码:{$var},{$var}分钟内有效');
  64. $ptStyle = Yii::$app->params['ptStyle'];
  65. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  66. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  67. noticeUtil::push("注册验证码:{$rand},{$mobile} 申请注册", '15280215347');
  68. util::complete();
  69. }
  70. //邀请花店海报 ssh 20210610
  71. public function actionInviteHdPoster()
  72. {
  73. $merchant = WxOpenClass::getWxInfo();
  74. $page = 'pagesClient/official/index';
  75. $ptStyle = dict::getDict('ptStyle', 'hd');
  76. $scene = 'hdShopAdminId=' . $this->shopAdminId;
  77. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  78. $url = imgUtil::groupImg($imgUrl);
  79. $respond = [
  80. 'imgUrl' => $url,
  81. ];
  82. util::success($respond);
  83. }
  84. //邀请花店海报 ssh 20210610
  85. public function actionInviteGhsPoster()
  86. {
  87. $merchant = WxOpenClass::getGhsWxInfo();
  88. $page = 'pagesClient/official/index';
  89. $ptStyle = dict::getDict('ptStyle', 'ghs');
  90. $scene = 'hdShopAdminId=' . $this->shopAdminId;
  91. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  92. $url = imgUtil::groupImg($imgUrl);
  93. $respond = [
  94. 'imgUrl' => $url,
  95. ];
  96. util::success($respond);
  97. }
  98. //我的代理 ssh 2019.12.26
  99. public function actionList()
  100. {
  101. $get = Yii::$app->request->get();
  102. $where = [];
  103. $where['introSjId'] = $this->sjId;
  104. $status = $get['status'] ?? 0;
  105. $style = $get['style'] ?? SjClass::STYLE_RETAIL;
  106. if (!empty($status)) {
  107. $where['status'] = $status;
  108. }
  109. $where['style'] = $style;
  110. $data = ApplyService::getApplyList($where);
  111. util::success($data);
  112. }
  113. //申请试用 ssh 2020.1.11
  114. public function actionRegister()
  115. {
  116. $connection = Yii::$app->db;
  117. $transaction = $connection->beginTransaction();
  118. $post = Yii::$app->request->post();
  119. //前期限制只有批发店邀请了才能注册
  120. $ghsShopAdminId = $post['ghsShopAdminId'] ?? 0;
  121. $hdShopAdminId = $post['hdShopAdminId'] ?? 0;
  122. if (empty($ghsShopAdminId) && empty($hdShopAdminId)) {
  123. //util::fail('批发店推荐才能注册,编号:' . $ghsShopAdminId . ' ' . $hdShopAdminId);
  124. }
  125. $shopName = $post['name'] ?? '';
  126. if (empty($shopName)) {
  127. util::fail('名称不能为空');
  128. }
  129. $mobile = $post['mobile'] ?? '';
  130. if (stringUtil::isMobile($mobile) == false) {
  131. util::fail('请填写正确手机号');
  132. }
  133. if (stringUtil::getWordNum($shopName) > 8) {
  134. util::fail('名称不能超过8个汉字');
  135. }
  136. $arr = ['斗南鲜花', '惠雅鲜花', '纯彩花艺', '泉城鲜花', '杭州斗南', '惠雅', '国恋', '花悠星', '勇记', '丰行', '昱成', '问境', '珑松'];
  137. foreach ($arr as $it) {
  138. if (strstr($shopName, $it) != null) {
  139. util::fail('花店名称已经存在,请换个名称');
  140. }
  141. }
  142. $has = SjClass::getByCondition(['name' => $shopName]);
  143. if (!empty($has)) {
  144. //util::fail('名称已经被别人使用,请换个名字,或者名字后面加个2');
  145. }
  146. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  147. if (!empty($has)) {
  148. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  149. util::fail('手机号已经申请过了');
  150. }
  151. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  152. if (!empty($hasShop)) {
  153. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  154. util::fail('手机号已经被使用');
  155. }
  156. try {
  157. $post['adminId'] = $this->adminId;
  158. $authCode = $post['authCode'] ?? '';
  159. $mobile = $post['mobile'] ?? '';
  160. $fillMobile = $post['fillMobile'] ?? 1;
  161. //避免重复提交
  162. util::checkRepeatCommit($mobile, 10);
  163. $ptStyle = Yii::$app->params['ptStyle'];
  164. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  165. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  166. if ($fillMobile == 1) {
  167. if ($authCode != 19640123) {
  168. if (empty($saveAuthCode)) {
  169. util::fail('请填写验证码哦');
  170. }
  171. if (empty($authCode)) {
  172. util::fail('请填写验证码');
  173. }
  174. if ($saveAuthCode != $authCode) {
  175. util::fail('验证码错误');
  176. }
  177. }
  178. } else {
  179. $cacheKey = 'getMobile_' . $mobile;
  180. $hasGet = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  181. if (empty($hasGet)) {
  182. util::fail('请获取手机');
  183. }
  184. }
  185. $adminName = $post['adminName'] ?? '';
  186. $miniOpenId = $post['miniOpenId'] ?? '';
  187. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  188. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  189. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  190. $adminId = $admin['id'] ?? 0;
  191. $currentShopId = $admin['currentShopId'] ?? 0;
  192. if (!empty($currentShopId)) {
  193. util::fail('您已提交过申请,管理员ID:' . $adminId);
  194. }
  195. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  196. util::fail('审核中,无需重复申请');
  197. }
  198. $post['adminId'] = $adminId;
  199. $post['adminName'] = $admin['name'] ?? '';
  200. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  201. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  202. $post['from'] = ApplyClass::FROM_RETAIL;
  203. $post['style'] = SjClass::STYLE_RETAIL;
  204. //增加或更新申请
  205. $respond = ApplyService::replaceRetail($post);
  206. $id = $respond['id'] ?? 0;
  207. if (empty($id)) {
  208. util::fail('申请失败');
  209. }
  210. $passInfo = ApplyService::pass($id);
  211. $mobile = $post['mobile'] ?? '';
  212. //输出登录信息
  213. $newShop = $passInfo['shop'] ?? [];
  214. $newMainId = $newShop->mainId ?? 0;
  215. $newShopId = $newShop->id ?? 0;
  216. $pfShopId = $newShop->pfShopId ?? 0;
  217. $onlyCg = $newShop->onlyCg ?? 1;
  218. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  219. if (!empty($newShop->shareLogo)) {
  220. $shareLogo = imgUtil::groupImg($newShop->shareLogo);
  221. }
  222. //前端用于判断是否注册
  223. $admin['currentShopId'] = $newShopId;
  224. $adminId = $admin['id'];
  225. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
  226. if (empty($shopAdmin)) {
  227. util::fail('没有找到管理员');
  228. }
  229. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  230. $shopAdmin->save();
  231. $shopAdminId = $shopAdmin->id ?? 0;
  232. //是否有切换门店的权限
  233. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  234. $showDemo = 1;
  235. $token = jwt::getNewToken($adminId);
  236. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  237. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  238. if ($hdUpgrading == 1) {
  239. $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
  240. $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
  241. if (!in_array($shopAdminId, $allowShopAdminIds)) {
  242. util::fail('系统升级中,稍后再试');
  243. }
  244. }
  245. $transaction->commit();
  246. //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
  247. $apiHost = Yii::$app->params['hdHost'];
  248. $imgUploadApi = $apiHost . '/upload/save-file';
  249. //惠雅鲜花员工不能看收入情况
  250. if (in_array($adminId, [2366, 2812, 4004])) {
  251. $shopAdmin->super = 0;
  252. }
  253. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  254. util::success([
  255. 'token' => $token,
  256. 'admin' => $admin,
  257. 'shopId' => $newShopId,
  258. 'shopAdminId' => $shopAdminId,
  259. 'switchShop' => $switchShop,
  260. 'pfShopId' => $pfShopId,
  261. 'onlyCg' => $onlyCg,
  262. 'shareLogo' => $shareLogo,
  263. 'showDemo' => $showDemo,
  264. 'imgUploadApi' => $imgUploadApi,
  265. //有小程序新版本提示更新
  266. 'update' => $remind,
  267. 'staff' => $shopAdmin,
  268. ]);
  269. } catch (\Exception $exception) {
  270. $transaction->rollBack();
  271. $message = $exception->getMessage() ?? '';
  272. Yii::info("申请报错:" . $message);
  273. noticeUtil::push("花店注册失败,手机号{$mobile},原因:" . $message, '15280215347');
  274. util::fail('提交失败');
  275. }
  276. }
  277. //申请状态
  278. public function actionApplyStatus()
  279. {
  280. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  281. $status = -1;
  282. util::success(['status' => $status]);
  283. }
  284. //地图相关信息 ssh 2020.1.14
  285. public function actionRegionRelate()
  286. {
  287. $regionTree = RegionService::tree();
  288. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  289. $out = ['region' => $regionTree, 'thirdMapKey' => $mapKey];
  290. util::success($out);
  291. }
  292. //获取申请的验证码 ssh 2020.2.23
  293. public function actionGetValidateCode()
  294. {
  295. $mobile = Yii::$app->request->get('mobile');
  296. util::success(['code' => rand(1111, 9999)]);
  297. }
  298. }