ApplyController.php 5.8 KB

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