ApplyController.php 6.5 KB

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