ApplyController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\classes\SjClass;
  5. use bizGhs\admin\classes\AdminClass;
  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\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. //获取验证码 ssh 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. if (getenv('YII_ENV') != 'production') {
  33. noticeUtil::push("注册验证码:{$rand},{$minute}分钟内有效", '15280215347');
  34. }
  35. sms::send($mobile . ',' . $rand . ',' . $minute, '注册验证码:{$var},{$var}分钟内有效');
  36. $ptStyle = Yii::$app->params['ptStyle'];
  37. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  38. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  39. util::complete();
  40. }
  41. //邀请花店海报 ssh 20210610
  42. public function actionInviteHdPoster()
  43. {
  44. $merchant = WxOpenClass::getWxInfo();
  45. $page = 'pagesClient/official/index';
  46. $ptStyle = dict::getDict('ptStyle', 'hd');
  47. $scene = 'ghsShopAdminId=' . $this->shopAdminId;
  48. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  49. $url = imgUtil::groupImg($imgUrl);
  50. $respond = [
  51. 'imgUrl' => $url,
  52. ];
  53. util::success($respond);
  54. }
  55. //邀请花店海报 ssh 20210610
  56. public function actionInviteGhsPoster()
  57. {
  58. $merchant = WxOpenClass::getGhsWxInfo();
  59. $page = 'pagesClient/official/index';
  60. $ptStyle = dict::getDict('ptStyle', 'ghs');
  61. $scene = 'ghsShopAdminId=' . $this->shopAdminId;
  62. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  63. $url = imgUtil::groupImg($imgUrl);
  64. $respond = [
  65. 'imgUrl' => $url,
  66. ];
  67. util::success($respond);
  68. }
  69. //邀请开店列表 ssh 2021.1.28
  70. public function actionList()
  71. {
  72. $get = Yii::$app->request->get();
  73. $where = [];
  74. $where['introSjId'] = $this->sjId;
  75. $status = $get['status'] ?? 0;
  76. if (!empty($status)) {
  77. $where['status'] = $status;
  78. }
  79. $data = ApplyService::getApplyList($where);
  80. $data['balance'] = $this->shop->balance ?? 0;
  81. util::success($data);
  82. }
  83. //申请试用,花店添加新客户 ssh 2021.1.8
  84. public function actionRegister()
  85. {
  86. $post = Yii::$app->request->post();
  87. $authCode = $post['authCode'] ?? '';
  88. $mobile = $post['mobile'] ?? '';
  89. $miniOpenId = $post['miniOpenId'] ?? '';
  90. if (empty($mobile)) {
  91. util::fail('请填写手机号');
  92. }
  93. if (!stringUtil::isMobile($mobile)) {
  94. util::fail('手机号错误');
  95. }
  96. $inviteCode = $post['inviteCode'] ?? '';
  97. if (empty($inviteCode) && !empty($miniOpenId)) {
  98. util::fail('请填写邀请码');
  99. }
  100. if ($inviteCode != 2025 && !empty($miniOpenId)) {
  101. util::fail('邀请码错误');
  102. }
  103. //避免重复提交
  104. util::checkRepeatCommit($mobile, 10);
  105. $connection = Yii::$app->db;
  106. $transaction = $connection->beginTransaction();
  107. try {
  108. $shopName = $post['name'] ?? '';
  109. if (empty($shopName)) {
  110. util::fail('名称不能为空');
  111. }
  112. if (stringUtil::getWordNum($shopName) > 8) {
  113. util::fail('名称不能超过8个汉字');
  114. }
  115. $has = SjClass::getByCondition(['name' => $shopName]);
  116. if (!empty($has)) {
  117. //util::fail('名称已经存在');
  118. }
  119. $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  120. if (!empty($hasApply)) {
  121. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  122. if ($hasApply->status == 1) {
  123. util::fail('此手机号已提交过申请,审核中');
  124. }
  125. if ($hasApply->status == 3) {
  126. util::fail('此手机号已提交申请,审核没有通过');
  127. }
  128. util::fail('手机号已经申请过了');
  129. }
  130. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  131. if (!empty($hasShop)) {
  132. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  133. util::fail('手机号已经被使用');
  134. }
  135. $ptStyle = Yii::$app->params['ptStyle'];
  136. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  137. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  138. if (empty($saveAuthCode)) {
  139. util::fail('请填写验证码哦');
  140. }
  141. if (empty($authCode)) {
  142. util::fail('请填写验证码');
  143. }
  144. if ($saveAuthCode != $authCode) {
  145. util::fail('验证码错误');
  146. }
  147. $adminName = $post['adminName'] ?? '';
  148. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'ghsMiniOpenId' => $miniOpenId];
  149. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  150. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  151. $adminId = $admin['id'] ?? 0;
  152. $post['adminId'] = $adminId;
  153. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  154. if (!empty($currentShopId)) {
  155. util::fail('您已提交过申请,管理员ID:' . $adminId);
  156. }
  157. if (isset($admin['openGhsShop']) && $admin['openGhsShop'] == 2) {
  158. util::fail('审核中,无需重复申请');
  159. }
  160. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  161. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  162. $post['from'] = ApplyClass::FROM_GHS;
  163. //新申请
  164. ApplyService::replaceGhs($post);
  165. $transaction->commit();
  166. $noticeMobile = '15280215347';
  167. //sms::freeSend($noticeMobile . ',' . $mobile, '有新的批发店申请开店,手机号:{$var}');
  168. noticeUtil::push("供货商 {$shopName} 手机号 {$mobile} 申请开店", '15280215347');
  169. } catch (\Exception $exception) {
  170. $transaction->rollBack();
  171. Yii::info("申请报错:" . $exception->getMessage());
  172. util::fail('提交失败');
  173. }
  174. util::complete();
  175. }
  176. //申请状态
  177. public function actionApplyStatus()
  178. {
  179. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  180. $status = -1;
  181. util::success(['status' => $status]);
  182. }
  183. //地图相关信息 ssh 2020.1.14
  184. public function actionRegionRelate()
  185. {
  186. $regionTree = RegionService::tree();
  187. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  188. $out = ['region' => $regionTree, 'thirdMapKey' => $mapKey];
  189. util::success($out);
  190. }
  191. //获取申请的验证码 ssh 2020.2.23
  192. public function actionGetValidateCode()
  193. {
  194. $mobile = Yii::$app->request->get('mobile');
  195. util::success(['code' => rand(1111, 9999)]);
  196. }
  197. }