ApplyController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\sj\classes\SjClass;
  5. use bizGhs\admin\classes\AdminClass;
  6. use bizGhs\admin\services\AdminService;
  7. use bizHd\saas\services\ApplyService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\miniUtil;
  12. use common\components\noticeUtil;
  13. use common\components\sms;
  14. use common\components\stringUtil;
  15. use Yii;
  16. use common\components\util;
  17. use bizHd\saas\classes\ApplyClass;
  18. use bizHd\saas\services\RegionService;
  19. class ApplyController extends BaseController
  20. {
  21. public $guestAccess = ['register', 'get-auth-code'];
  22. //获取验证码 ssh 20210117
  23. public function actionGetAuthCode()
  24. {
  25. $get = Yii::$app->request->get();
  26. $mobile = $get['mobile'] ?? '';
  27. if (stringUtil::isMobile($mobile) == false) {
  28. util::fail('请输入正确手机号');
  29. }
  30. $rand = rand(11111, 99999);
  31. $minute = 10;
  32. if (getenv('YII_ENV') != 'production') {
  33. noticeUtil::push("注册验证码:{$rand},{$minute}分钟内有效", '15280215347');
  34. }
  35. sms::send($mobile . ',' . $rand . ',' . $minute, '注册验证码:{$var},{$var}分钟内有效');
  36. $ptStyle = Yii::$app->params['ptStyle'];
  37. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  38. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  39. util::complete();
  40. }
  41. //邀请花店海报 ssh 20210610
  42. public function actionInviteHdPoster()
  43. {
  44. $merchant = WxOpenClass::getWxInfo();
  45. $page = 'pagesClient/official/index';
  46. $ptStyle = dict::getDict('ptStyle', 'hd');
  47. $scene = 'ghsShopAdminId=' . $this->shopAdminId;
  48. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  49. $url = imgUtil::groupImg($imgUrl);
  50. $respond = [
  51. 'imgUrl' => $url,
  52. ];
  53. util::success($respond);
  54. }
  55. //邀请花店海报 ssh 20210610
  56. public function actionInviteGhsPoster()
  57. {
  58. $merchant = WxOpenClass::getGhsWxInfo();
  59. $page = 'pagesClient/official/index';
  60. $ptStyle = dict::getDict('ptStyle', 'ghs');
  61. $scene = 'ghsShopAdminId=' . $this->shopAdminId;
  62. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  63. $url = imgUtil::groupImg($imgUrl);
  64. $respond = [
  65. 'imgUrl' => $url,
  66. ];
  67. util::success($respond);
  68. }
  69. //邀请开店列表 ssh 2021.1.28
  70. public function actionList()
  71. {
  72. $get = Yii::$app->request->get();
  73. $where = [];
  74. $where['introSjId'] = $this->sjId;
  75. $status = $get['status'] ?? 0;
  76. if (!empty($status)) {
  77. $where['status'] = $status;
  78. }
  79. $data = ApplyService::getApplyList($where);
  80. $data['balance'] = $this->shop->balance ?? 0;
  81. util::success($data);
  82. }
  83. //申请试用,花店添加新客户 ssh 2021.1.8
  84. public function actionRegister()
  85. {
  86. $post = Yii::$app->request->post();
  87. $authCode = $post['authCode'] ?? '';
  88. $mobile = $post['mobile'] ?? '';
  89. $miniOpenId = $post['miniOpenId'] ?? '';
  90. if (empty($mobile)) {
  91. util::fail('请填写手机号');
  92. }
  93. if (!stringUtil::isMobile($mobile)) {
  94. util::fail('手机号错误');
  95. }
  96. $inviteCode = $post['inviteCode'] ?? '';
  97. if (empty($inviteCode) && !empty($miniOpenId)) {
  98. util::fail('请填写邀请码');
  99. }
  100. if ($inviteCode != 2025 && !empty($miniOpenId)) {
  101. util::fail('邀请码错误');
  102. }
  103. //避免重复提交
  104. util::checkRepeatCommit($mobile, 10);
  105. $connection = Yii::$app->db;
  106. $transaction = $connection->beginTransaction();
  107. try {
  108. $shopName = $post['name'] ?? '';
  109. if (empty($shopName)) {
  110. util::fail('名称不能为空');
  111. }
  112. if (stringUtil::getWordNum($shopName) > 8) {
  113. util::fail('名称不能超过8个汉字');
  114. }
  115. $hasShopList = ShopClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
  116. if (!empty($hasShopList)) {
  117. foreach ($hasShopList as $hasShop) {
  118. if ($hasShop->ptStyle == 2) {
  119. util::fail('这个手机号已经开了批发店');
  120. }
  121. }
  122. }
  123. $apply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  124. if (!empty($apply)) {
  125. $shop = ShopClass::getByCondition(['mobile' => $mobile], true);
  126. if (!empty($shop)) {
  127. $apply->introSjId = 1;
  128. $apply->introStyle = 0;
  129. $apply->introSjName = 0;
  130. $apply->introShopId = 0;
  131. $apply->name = $shopName;
  132. $apply->style = 2;
  133. $apply->status = 1;
  134. $apply->save();
  135. $transaction->commit();
  136. noticeUtil::push("{$shopName} 手机号 {$mobile} 申请开通批发店", '15280215347');
  137. util::complete('已提交申请');
  138. }
  139. $apply->updateTime = date('Y-m-d H:i:s');
  140. $apply->save();
  141. }
  142. $ptStyle = Yii::$app->params['ptStyle'];
  143. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  144. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  145. if (empty($saveAuthCode)) {
  146. util::fail('请填写验证码哦');
  147. }
  148. if (empty($authCode)) {
  149. util::fail('请填写验证码');
  150. }
  151. if ($saveAuthCode != $authCode) {
  152. util::fail('验证码错误');
  153. }
  154. $adminName = $post['adminName'] ?? '';
  155. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'ghsMiniOpenId' => $miniOpenId];
  156. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  157. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  158. $adminId = $admin['id'] ?? 0;
  159. $post['adminId'] = $adminId;
  160. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  161. if (!empty($currentShopId)) {
  162. util::fail('您已提交过申请,管理员ID:' . $adminId);
  163. }
  164. if (isset($admin['openGhsShop']) && $admin['openGhsShop'] == 2) {
  165. util::fail('审核中,无需重复申请');
  166. }
  167. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  168. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  169. $post['from'] = ApplyClass::FROM_GHS;
  170. //新申请
  171. ApplyService::replaceGhs($post);
  172. $transaction->commit();
  173. noticeUtil::push("{$shopName} 手机号 {$mobile} 申请开通批发店", '15280215347');
  174. } catch (\Exception $exception) {
  175. $transaction->rollBack();
  176. Yii::info("申请报错:" . $exception->getMessage());
  177. util::fail('提交失败');
  178. }
  179. util::complete();
  180. }
  181. //申请状态
  182. public function actionApplyStatus()
  183. {
  184. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  185. $status = -1;
  186. util::success(['status' => $status]);
  187. }
  188. //地图相关信息 ssh 2020.1.14
  189. public function actionRegionRelate()
  190. {
  191. $regionTree = RegionService::tree();
  192. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  193. $out = ['region' => $regionTree, 'thirdMapKey' => $mapKey];
  194. util::success($out);
  195. }
  196. //获取申请的验证码 ssh 2020.2.23
  197. public function actionGetValidateCode()
  198. {
  199. $mobile = Yii::$app->request->get('mobile');
  200. util::success(['code' => rand(1111, 9999)]);
  201. }
  202. }