ApplyController.php 6.3 KB

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