ApplyController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace hd\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 = 'hdShopAdminId=' . $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 = 'hdShopAdminId=' . $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 2019.12.26
  65. public function actionList()
  66. {
  67. $get = Yii::$app->request->get();
  68. $where = [];
  69. $where['introSjId'] = $this->sjId;
  70. $status = $get['status'] ?? 0;
  71. $style = $get['style'] ?? SjClass::STYLE_RETAIL;
  72. if (!empty($status)) {
  73. $where['status'] = $status;
  74. }
  75. $where['style'] = $style;
  76. $data = ApplyService::getApplyList($where);
  77. util::success($data);
  78. }
  79. //申请试用 ssh 2020.1.11
  80. public function actionRegister()
  81. {
  82. $connection = Yii::$app->db;
  83. $transaction = $connection->beginTransaction();
  84. try {
  85. $post = Yii::$app->request->post();
  86. $post['adminId'] = $this->adminId;
  87. $authCode = $post['authCode'] ?? '';
  88. $mobile = $post['mobile'] ?? '';
  89. //避免重复提交
  90. util::checkRepeatCommit($mobile, 10);
  91. $ptStyle = Yii::$app->params['ptStyle'];
  92. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  93. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  94. if (empty($saveAuthCode)) {
  95. util::fail('请填写验证码哦');
  96. }
  97. if (empty($authCode)) {
  98. util::fail('请填写验证码');
  99. }
  100. if ($saveAuthCode != $authCode) {
  101. util::fail('验证码错误');
  102. }
  103. $name = $post['adminName'] ?? '';
  104. $miniOpenId = $post['miniOpenId'] ?? '';
  105. $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  106. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  107. $admin = AdminService::replaceAdmin($adminInfo, $fromApp);
  108. $adminId = $admin['id'] ?? 0;
  109. $currentShopId = $admin['currentShopId'] ?? 0;
  110. if (!empty($currentShopId)) {
  111. util::fail('您已提交过申请');
  112. }
  113. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  114. util::fail('审核中,无需重复申请');
  115. }
  116. $post['adminId'] = $adminId;
  117. $post['adminName'] = $admin['name'] ?? '';
  118. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  119. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  120. $post['from'] = ApplyClass::FROM_RETAIL;
  121. $post['style'] = SjClass::STYLE_RETAIL;
  122. $name = $post['name'] ?? '';
  123. if (empty($name)) {
  124. util::fail('名称不能为空');
  125. }
  126. if (stringUtil::getWordNum($name) > 8) {
  127. util::fail('名称不能超过8个汉字');
  128. }
  129. $has = SjClass::getByCondition(['name' => $name, 'style' => ApplyClass::FROM_RETAIL]);
  130. if (!empty($has)) {
  131. util::fail('名称已经存在');
  132. }
  133. //增加或更新申请
  134. $respond = ApplyService::replaceRetail($post);
  135. $id = $respond['id'] ?? 0;
  136. if (!empty($id)) {
  137. ApplyService::pass($id);
  138. }
  139. $transaction->commit();
  140. $mobile = $post['mobile'] ?? '';
  141. noticeUtil::push("花店 {$name} 手机号 {$mobile} 注册", '15280215347');
  142. } catch (\Exception $exception) {
  143. $transaction->rollBack();
  144. Yii::info("申请报错:" . $exception->getMessage());
  145. util::fail('提交失败');
  146. }
  147. util::complete();
  148. }
  149. //申请状态
  150. public function actionApplyStatus()
  151. {
  152. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  153. $status = -1;
  154. util::success(['status' => $status]);
  155. }
  156. //地图相关信息 ssh 2020.1.14
  157. public function actionRegionRelate()
  158. {
  159. $regionTree = RegionService::tree();
  160. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  161. $out = ['region' => $regionTree, 'txMapKey' => $mapKey];
  162. util::success($out);
  163. }
  164. //获取申请的验证码 ssh 2020.2.23
  165. public function actionGetValidateCode()
  166. {
  167. $mobile = Yii::$app->request->get('mobile');
  168. util::success(['code' => rand(1111, 9999)]);
  169. }
  170. }