ApplyController.php 7.9 KB

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