ApplyController.php 7.7 KB

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