ApplyController.php 10 KB

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