ApplyController.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. $arr = ['斗南鲜花', '惠雅鲜花', '纯彩花艺', '泉城鲜花', '杭州斗南', '惠雅'];
  102. foreach ($arr as $it) {
  103. if (strstr($shopName, $it) != null) {
  104. util::fail('花店名称已经存在,请换个名称');
  105. }
  106. }
  107. $has = SjClass::getByCondition(['name' => $shopName]);
  108. if (!empty($has)) {
  109. //util::fail('名称已经被别人使用,请换个名字,或者名字后面加个2');
  110. }
  111. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  112. if (!empty($has)) {
  113. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  114. util::fail('手机号已经申请过了');
  115. }
  116. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  117. if (!empty($hasShop)) {
  118. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  119. util::fail('手机号已经被使用');
  120. }
  121. $post['adminId'] = $this->adminId;
  122. $authCode = $post['authCode'] ?? '';
  123. $mobile = $post['mobile'] ?? '';
  124. //避免重复提交
  125. util::checkRepeatCommit($mobile, 10);
  126. $ptStyle = Yii::$app->params['ptStyle'];
  127. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  128. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  129. if (empty($saveAuthCode)) {
  130. util::fail('请填写验证码哦');
  131. }
  132. if (empty($authCode)) {
  133. util::fail('请填写验证码');
  134. }
  135. if ($saveAuthCode != $authCode) {
  136. util::fail('验证码错误');
  137. }
  138. $adminName = $post['adminName'] ?? '';
  139. $miniOpenId = $post['miniOpenId'] ?? '';
  140. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  141. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  142. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  143. $adminId = $admin['id'] ?? 0;
  144. $currentShopId = $admin['currentShopId'] ?? 0;
  145. if (!empty($currentShopId)) {
  146. util::fail('您已提交过申请,管理员ID:' . $adminId);
  147. }
  148. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  149. util::fail('审核中,无需重复申请');
  150. }
  151. $post['adminId'] = $adminId;
  152. $post['adminName'] = $admin['name'] ?? '';
  153. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  154. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  155. $post['from'] = ApplyClass::FROM_RETAIL;
  156. $post['style'] = SjClass::STYLE_RETAIL;
  157. //增加或更新申请
  158. $respond = ApplyService::replaceRetail($post);
  159. $id = $respond['id'] ?? 0;
  160. if (empty($id)) {
  161. util::fail('申请失败');
  162. }
  163. $passInfo = ApplyService::pass($id);
  164. $mobile = $post['mobile'] ?? '';
  165. //输出登录信息
  166. $newShop = $passInfo['shop'] ?? [];
  167. $newMainId = $newShop->mainId ?? 0;
  168. $newShopId = $newShop->id ?? 0;
  169. $pfShopId = $newShop->pfShopId ?? 0;
  170. $onlyCg = 1;
  171. //前端用于判断是否注册
  172. $admin['currentShopId'] = $newShopId;
  173. $adminId = $admin['id'];
  174. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
  175. if (empty($shopAdmin)) {
  176. util::fail('没有找到管理员');
  177. }
  178. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  179. $shopAdmin->save();
  180. $shopAdminId = $shopAdmin->id ?? 0;
  181. //是否有切换门店的权限
  182. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  183. $showDemo = 1;
  184. $token = jwt::getNewToken($adminId);
  185. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  186. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  187. if ($hdUpgrading == 1) {
  188. util::fail('系统升级中,稍后再试');
  189. }
  190. $transaction->commit();
  191. //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
  192. $apiHost = Yii::$app->params['hdHost'];
  193. $imgUploadApi = $apiHost . '/upload/save-file';
  194. //惠雅鲜花员工不能看收入情况
  195. if (in_array($adminId, [2366, 2812, 4004])) {
  196. $shopAdmin->super = 0;
  197. }
  198. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  199. util::success([
  200. 'token' => $token,
  201. 'admin' => $admin,
  202. 'shopId' => $currentShopId,
  203. 'shopAdminId' => $shopAdminId,
  204. 'switchShop' => $switchShop,
  205. 'pfShopId' => $pfShopId,
  206. 'onlyCg' => $onlyCg,
  207. 'showDemo' => $showDemo,
  208. 'imgUploadApi' => $imgUploadApi,
  209. //有小程序新版本提示更新
  210. 'update' => $remind,
  211. 'staff' => $shopAdmin,
  212. ]);
  213. } catch (\Exception $exception) {
  214. $transaction->rollBack();
  215. Yii::info("申请报错:" . $exception->getMessage());
  216. util::fail('提交失败');
  217. }
  218. }
  219. //申请状态
  220. public function actionApplyStatus()
  221. {
  222. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  223. $status = -1;
  224. util::success(['status' => $status]);
  225. }
  226. //地图相关信息 ssh 2020.1.14
  227. public function actionRegionRelate()
  228. {
  229. $regionTree = RegionService::tree();
  230. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  231. $out = ['region' => $regionTree, 'txMapKey' => $mapKey];
  232. util::success($out);
  233. }
  234. //获取申请的验证码 ssh 2020.2.23
  235. public function actionGetValidateCode()
  236. {
  237. $mobile = Yii::$app->request->get('mobile');
  238. util::success(['code' => rand(1111, 9999)]);
  239. }
  240. }