ApplyController.php 9.7 KB

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