ApplyController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. $fillMobile = $post['fillMobile'] ?? 1;
  90. $miniOpenId = $post['miniOpenId'] ?? '';
  91. if (empty($mobile)) {
  92. util::fail('请填写手机号');
  93. }
  94. if (!stringUtil::isMobile($mobile)) {
  95. util::fail('手机号错误');
  96. }
  97. $inviteCode = $post['inviteCode'] ?? '';
  98. if (empty($inviteCode) && !empty($miniOpenId)) {
  99. util::fail('请填写邀请码');
  100. }
  101. if ($inviteCode != 2025 && !empty($miniOpenId)) {
  102. util::fail('邀请码错误');
  103. }
  104. //避免重复提交
  105. util::checkRepeatCommit($mobile, 10);
  106. $connection = Yii::$app->db;
  107. $transaction = $connection->beginTransaction();
  108. try {
  109. $shopName = $post['name'] ?? '';
  110. if (empty($shopName)) {
  111. util::fail('名称不能为空');
  112. }
  113. if (stringUtil::getWordNum($shopName) > 8) {
  114. util::fail('名称不能超过8个汉字');
  115. }
  116. $hasShopList = ShopClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
  117. if (!empty($hasShopList)) {
  118. foreach ($hasShopList as $hasShop) {
  119. if ($hasShop->ptStyle == 2) {
  120. util::fail('这个手机号已经开了批发店');
  121. }
  122. }
  123. }
  124. $apply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  125. if (!empty($apply)) {
  126. $shop = ShopClass::getByCondition(['mobile' => $mobile], true);
  127. if (!empty($shop)) {
  128. $apply->introSjId = 1;
  129. $apply->introStyle = 0;
  130. $apply->introSjName = 0;
  131. $apply->introShopId = 0;
  132. $apply->name = $shopName;
  133. $apply->style = 2;
  134. $apply->status = 1;
  135. $apply->save();
  136. $transaction->commit();
  137. noticeUtil::push("{$shopName} 手机号 {$mobile} 申请开通批发店", '15280215347');
  138. util::complete('已提交申请');
  139. }
  140. $apply->updateTime = date('Y-m-d H:i:s');
  141. $apply->save();
  142. }
  143. $ptStyle = Yii::$app->params['ptStyle'];
  144. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  145. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  146. if ($fillMobile == 1) {
  147. if ($authCode != 19640123) {
  148. if (empty($saveAuthCode)) {
  149. util::fail('请填写验证码哦');
  150. }
  151. if (empty($authCode)) {
  152. util::fail('请填写验证码');
  153. }
  154. if ($saveAuthCode != $authCode) {
  155. util::fail('验证码错误');
  156. }
  157. }
  158. } else {
  159. $cacheKey = 'getMobile_' . $mobile;
  160. $hasGet = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  161. if (empty($hasGet)) {
  162. util::fail('请获取手机');
  163. }
  164. }
  165. $adminName = $post['adminName'] ?? '';
  166. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'ghsMiniOpenId' => $miniOpenId];
  167. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  168. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  169. $adminId = $admin['id'] ?? 0;
  170. $post['adminId'] = $adminId;
  171. $currentShopId = $admin['currentGhsShopId'] ?? 0;
  172. if (!empty($currentShopId)) {
  173. util::fail('您已提交过申请,管理员ID:' . $adminId);
  174. }
  175. if (isset($admin['openGhsShop']) && $admin['openGhsShop'] == 2) {
  176. util::fail('审核中,无需重复申请');
  177. }
  178. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  179. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  180. $post['from'] = ApplyClass::FROM_GHS;
  181. //新申请
  182. ApplyService::replaceGhs($post);
  183. $transaction->commit();
  184. noticeUtil::push("{$shopName} 手机号 {$mobile} 申请开通批发店", '15280215347');
  185. } catch (\Exception $exception) {
  186. $transaction->rollBack();
  187. Yii::info("申请报错:" . $exception->getMessage());
  188. util::fail('提交失败');
  189. }
  190. util::complete();
  191. }
  192. //申请状态
  193. public function actionApplyStatus()
  194. {
  195. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  196. $status = -1;
  197. util::success(['status' => $status]);
  198. }
  199. //地图相关信息 ssh 2020.1.14
  200. public function actionRegionRelate()
  201. {
  202. $regionTree = RegionService::tree();
  203. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  204. $out = ['region' => $regionTree, 'thirdMapKey' => $mapKey];
  205. util::success($out);
  206. }
  207. //获取申请的验证码 ssh 2020.2.23
  208. public function actionGetValidateCode()
  209. {
  210. $mobile = Yii::$app->request->get('mobile');
  211. util::success(['code' => rand(1111, 9999)]);
  212. }
  213. }