ApplyController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 (stringUtil::isMobile($mobile) == false) {
  87. util::fail('请填写正确手机号');
  88. }
  89. //避免重复提交
  90. util::checkRepeatCommit($mobile, 10);
  91. $connection = Yii::$app->db;
  92. $transaction = $connection->beginTransaction();
  93. try {
  94. $shopName = $post['name'] ?? '';
  95. if (empty($shopName)) {
  96. util::fail('名称不能为空');
  97. }
  98. if (stringUtil::getWordNum($shopName) > 8) {
  99. util::fail('名称不能超过8个汉字');
  100. }
  101. $has = SjClass::getByCondition(['name' => $shopName]);
  102. if (!empty($has)) {
  103. util::fail('名称已经存在');
  104. }
  105. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  106. if (!empty($has)) {
  107. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  108. util::fail('手机号已经申请过了');
  109. }
  110. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  111. if (!empty($hasShop)) {
  112. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  113. util::fail('手机号已经被使用');
  114. }
  115. $ptStyle = Yii::$app->params['ptStyle'];
  116. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  117. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  118. if (empty($saveAuthCode)) {
  119. util::fail('请填写验证码哦');
  120. }
  121. if (empty($authCode)) {
  122. util::fail('请填写验证码');
  123. }
  124. if ($saveAuthCode != $authCode) {
  125. util::fail('验证码错误');
  126. }
  127. $adminName = $post['adminName'] ?? '';
  128. $miniOpenId = $post['miniOpenId'] ?? '';
  129. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'ghsMiniOpenId' => $miniOpenId];
  130. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  131. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  132. $adminId = $admin['id'] ?? 0;
  133. $post['adminId'] = $adminId;
  134. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  135. if (!empty($currentShopId)) {
  136. util::fail('您已提交过申请,管理员ID:' . $adminId);
  137. }
  138. if (isset($admin['openGhsShop']) && $admin['openGhsShop'] == 2) {
  139. util::fail('审核中,无需重复申请');
  140. }
  141. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  142. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  143. $post['from'] = ApplyClass::FROM_GHS;
  144. //新申请
  145. ApplyService::replaceGhs($post);
  146. $transaction->commit();
  147. noticeUtil::push("供货商 {$shopName} 手机号 {$mobile} 申请开店", '15280215347');
  148. } catch (\Exception $exception) {
  149. $transaction->rollBack();
  150. Yii::info("申请报错:" . $exception->getMessage());
  151. util::fail('提交失败');
  152. }
  153. util::complete();
  154. }
  155. //申请状态
  156. public function actionApplyStatus()
  157. {
  158. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  159. $status = -1;
  160. util::success(['status' => $status]);
  161. }
  162. //地图相关信息 ssh 2020.1.14
  163. public function actionRegionRelate()
  164. {
  165. $regionTree = RegionService::tree();
  166. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  167. $out = ['region' => $regionTree, 'txMapKey' => $mapKey];
  168. util::success($out);
  169. }
  170. //获取申请的验证码 ssh 2020.2.23
  171. public function actionGetValidateCode()
  172. {
  173. $mobile = Yii::$app->request->get('mobile');
  174. util::success(['code' => rand(1111, 9999)]);
  175. }
  176. }