ApplyController.php 6.9 KB

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