ApplyController.php 6.1 KB

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