ApplyController.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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\services\AdminService;
  7. use bizHd\saas\services\ApplyService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\jwt;
  12. use common\components\miniUtil;
  13. use common\components\noticeUtil;
  14. use common\components\sms;
  15. use common\components\stringUtil;
  16. use Yii;
  17. use common\components\util;
  18. use bizHd\saas\classes\ApplyClass;
  19. use bizHd\saas\services\RegionService;
  20. class ApplyController extends BaseController
  21. {
  22. public $guestAccess = ['register', 'get-auth-code'];
  23. //获取验证码 ssh 20210117
  24. public function actionGetAuthCode()
  25. {
  26. $get = Yii::$app->request->get();
  27. $mobile = $get['mobile'] ?? '';
  28. if (stringUtil::isMobile($mobile) == false) {
  29. util::fail('请输入正确手机号');
  30. }
  31. $rand = rand(11111, 99999);
  32. $minute = 10;
  33. sms::send($mobile . ',' . $rand . ',' . $minute, '注册验证码:{$var},{$var}分钟内有效');
  34. $ptStyle = Yii::$app->params['ptStyle'];
  35. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  36. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  37. util::complete();
  38. }
  39. //邀请花店海报 ssh 20210610
  40. public function actionInviteHdPoster()
  41. {
  42. $merchant = WxOpenClass::getWxInfo();
  43. $page = 'pagesClient/official/index';
  44. $ptStyle = dict::getDict('ptStyle', 'hd');
  45. $scene = 'hdShopAdminId=' . $this->shopAdminId;
  46. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  47. $url = imgUtil::groupImg($imgUrl);
  48. $respond = [
  49. 'imgUrl' => $url,
  50. ];
  51. util::success($respond);
  52. }
  53. //邀请花店海报 ssh 20210610
  54. public function actionInviteGhsPoster()
  55. {
  56. $merchant = WxOpenClass::getGhsWxInfo();
  57. $page = 'pagesClient/official/index';
  58. $ptStyle = dict::getDict('ptStyle', 'ghs');
  59. $scene = 'hdShopAdminId=' . $this->shopAdminId;
  60. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  61. $url = imgUtil::groupImg($imgUrl);
  62. $respond = [
  63. 'imgUrl' => $url,
  64. ];
  65. util::success($respond);
  66. }
  67. //我的代理 ssh 2019.12.26
  68. public function actionList()
  69. {
  70. $get = Yii::$app->request->get();
  71. $where = [];
  72. $where['introSjId'] = $this->sjId;
  73. $status = $get['status'] ?? 0;
  74. $style = $get['style'] ?? SjClass::STYLE_RETAIL;
  75. if (!empty($status)) {
  76. $where['status'] = $status;
  77. }
  78. $where['style'] = $style;
  79. $data = ApplyService::getApplyList($where);
  80. util::success($data);
  81. }
  82. //申请试用 ssh 2020.1.11
  83. public function actionRegister()
  84. {
  85. $connection = Yii::$app->db;
  86. $transaction = $connection->beginTransaction();
  87. try {
  88. $post = Yii::$app->request->post();
  89. $shopName = $post['name'] ?? '';
  90. if (empty($shopName)) {
  91. util::fail('名称不能为空');
  92. }
  93. $mobile = $post['mobile'] ?? '';
  94. if (stringUtil::isMobile($mobile) == false) {
  95. util::fail('请填写正确手机号');
  96. }
  97. if (stringUtil::getWordNum($shopName) > 8) {
  98. util::fail('名称不能超过8个汉字');
  99. }
  100. $has = SjClass::getByCondition(['name' => $shopName]);
  101. if (!empty($has)) {
  102. util::fail('名称已经存在');
  103. }
  104. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  105. if (!empty($has)) {
  106. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  107. util::fail('手机号已经申请过了');
  108. }
  109. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  110. if (!empty($hasShop)) {
  111. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  112. util::fail('手机号已经被使用');
  113. }
  114. $post['adminId'] = $this->adminId;
  115. $authCode = $post['authCode'] ?? '';
  116. $mobile = $post['mobile'] ?? '';
  117. //避免重复提交
  118. util::checkRepeatCommit($mobile, 10);
  119. $ptStyle = Yii::$app->params['ptStyle'];
  120. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  121. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  122. if (empty($saveAuthCode)) {
  123. util::fail('请填写验证码哦');
  124. }
  125. if (empty($authCode)) {
  126. util::fail('请填写验证码');
  127. }
  128. if ($saveAuthCode != $authCode) {
  129. util::fail('验证码错误');
  130. }
  131. $adminName = $post['adminName'] ?? '';
  132. $miniOpenId = $post['miniOpenId'] ?? '';
  133. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  134. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  135. $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
  136. $adminId = $admin['id'] ?? 0;
  137. $currentShopId = $admin['currentShopId'] ?? 0;
  138. if (!empty($currentShopId)) {
  139. util::fail('您已提交过申请,管理员ID:' . $adminId);
  140. }
  141. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  142. util::fail('审核中,无需重复申请');
  143. }
  144. $post['adminId'] = $adminId;
  145. $post['adminName'] = $admin['name'] ?? '';
  146. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  147. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  148. $post['from'] = ApplyClass::FROM_RETAIL;
  149. $post['style'] = SjClass::STYLE_RETAIL;
  150. //增加或更新申请
  151. $respond = ApplyService::replaceRetail($post);
  152. $id = $respond['id'] ?? 0;
  153. if (empty($id)) {
  154. util::fail('申请失败');
  155. }
  156. $passInfo = ApplyService::pass($id);
  157. $mobile = $post['mobile'] ?? '';
  158. //输出登录信息
  159. $newShop = $passInfo['shop'] ?? [];
  160. $newMainId = $newShop->mainId ?? 0;
  161. $newShopId = $newShop->id ?? 0;
  162. //前端用于判断是否注册
  163. $admin['currentShopId'] = $newShopId;
  164. $adminId = $admin['id'];
  165. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
  166. if (empty($shopAdmin)) {
  167. util::fail('没有找到管理员');
  168. }
  169. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  170. $shopAdmin->save();
  171. $shopAdminId = $shopAdmin->id ?? 0;
  172. //是否有切换门店的权限
  173. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  174. $showDemo = 1;
  175. $token = jwt::getNewToken($adminId);
  176. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  177. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  178. if ($hdUpgrading == 1) {
  179. util::fail('系统升级中,稍后再试');
  180. }
  181. $transaction->commit();
  182. noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
  183. $apiHost = Yii::$app->params['hdHost'];
  184. $imgUploadApi = $apiHost . '/upload/save-file';
  185. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  186. util::success([
  187. 'token' => $token,
  188. 'admin' => $admin,
  189. 'shopId' => $currentShopId,
  190. 'shopAdminId' => $shopAdminId,
  191. 'switchShop' => $switchShop,
  192. 'showDemo' => $showDemo,
  193. 'imgUploadApi' => $imgUploadApi,
  194. //有小程序新版本提示更新
  195. 'update' => $remind,
  196. ]);
  197. } catch (\Exception $exception) {
  198. $transaction->rollBack();
  199. Yii::info("申请报错:" . $exception->getMessage());
  200. util::fail('提交失败');
  201. }
  202. }
  203. //申请状态
  204. public function actionApplyStatus()
  205. {
  206. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  207. $status = -1;
  208. util::success(['status' => $status]);
  209. }
  210. //地图相关信息 ssh 2020.1.14
  211. public function actionRegionRelate()
  212. {
  213. $regionTree = RegionService::tree();
  214. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  215. $out = ['region' => $regionTree, 'txMapKey' => $mapKey];
  216. util::success($out);
  217. }
  218. //获取申请的验证码 ssh 2020.2.23
  219. public function actionGetValidateCode()
  220. {
  221. $mobile = Yii::$app->request->get('mobile');
  222. util::success(['code' => rand(1111, 9999)]);
  223. }
  224. }