ApplyController.php 6.2 KB

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