ApplyController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopClass;
  4. use biz\shop\services\ShopAdminService;
  5. use biz\sj\classes\SjClass;
  6. use bizGhs\admin\classes\AdminClass;
  7. use bizGhs\admin\services\AdminService;
  8. use bizHd\saas\services\ApplyService;
  9. use bizHd\wx\classes\WxOpenClass;
  10. use common\components\dict;
  11. use common\components\imgUtil;
  12. use common\components\jwt;
  13. use common\components\miniUtil;
  14. use common\components\noticeUtil;
  15. use common\components\sms;
  16. use common\components\stringUtil;
  17. use Yii;
  18. use common\components\util;
  19. use bizHd\saas\classes\ApplyClass;
  20. use bizHd\saas\services\RegionService;
  21. class ApplyController extends BaseController
  22. {
  23. public $guestAccess = ['register', 'get-auth-code'];
  24. //申请开通批发店 ssh 20231125
  25. public function actionOpenPf()
  26. {
  27. $shop = $this->shop;
  28. $pfShopId = $shop->pfShopId ?? 0;
  29. if (!empty($pfShopId)) {
  30. util::fail('已经开通过了,无需重复申请');
  31. }
  32. $mobile = $shop->mobile ?? 0;
  33. if (empty($mobile)) {
  34. util::fail('没有找到手机号');
  35. }
  36. $apply = ApplyClass::getByCondition(['mobile' => $mobile], true);
  37. if (empty($apply)) {
  38. util::fail('找不到历史申请记录');
  39. }
  40. $apply->introSjId = 1;
  41. $apply->introStyle = 0;
  42. $apply->introSjName = 0;
  43. $apply->introShopId = 0;
  44. $apply->status = 1;
  45. $apply->save();
  46. $shopName = $shop->shopName ?? '';
  47. $sjName = $shop->merchantName ?? '';
  48. $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  49. noticeUtil::push("重要提醒,零售店【{$name}】申请开通批发店", '15280215347');
  50. util::complete('已提交申请');
  51. }
  52. //获取验证码 ssh 20210117
  53. public function actionGetAuthCode()
  54. {
  55. $get = Yii::$app->request->get();
  56. $mobile = $get['mobile'] ?? '';
  57. if (stringUtil::isMobile($mobile) == false) {
  58. util::fail('请输入正确手机号');
  59. }
  60. $rand = rand(11111, 99999);
  61. $minute = 10;
  62. sms::send($mobile . ',' . $rand . ',' . $minute, '注册验证码:{$var},{$var}分钟内有效');
  63. $ptStyle = Yii::$app->params['ptStyle'];
  64. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  65. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 600, $rand]);
  66. util::complete();
  67. }
  68. //邀请花店海报 ssh 20210610
  69. public function actionInviteHdPoster()
  70. {
  71. $merchant = WxOpenClass::getWxInfo();
  72. $page = 'pagesClient/official/index';
  73. $ptStyle = dict::getDict('ptStyle', 'hd');
  74. $scene = 'hdShopAdminId=' . $this->shopAdminId;
  75. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  76. $url = imgUtil::groupImg($imgUrl);
  77. $respond = [
  78. 'imgUrl' => $url,
  79. ];
  80. util::success($respond);
  81. }
  82. //邀请花店海报 ssh 20210610
  83. public function actionInviteGhsPoster()
  84. {
  85. $merchant = WxOpenClass::getGhsWxInfo();
  86. $page = 'pagesClient/official/index';
  87. $ptStyle = dict::getDict('ptStyle', 'ghs');
  88. $scene = 'hdShopAdminId=' . $this->shopAdminId;
  89. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  90. $url = imgUtil::groupImg($imgUrl);
  91. $respond = [
  92. 'imgUrl' => $url,
  93. ];
  94. util::success($respond);
  95. }
  96. //我的代理 ssh 2019.12.26
  97. public function actionList()
  98. {
  99. $get = Yii::$app->request->get();
  100. $where = [];
  101. $where['introSjId'] = $this->sjId;
  102. $status = $get['status'] ?? 0;
  103. $style = $get['style'] ?? SjClass::STYLE_RETAIL;
  104. if (!empty($status)) {
  105. $where['status'] = $status;
  106. }
  107. $where['style'] = $style;
  108. $data = ApplyService::getApplyList($where);
  109. util::success($data);
  110. }
  111. //申请试用 ssh 2020.1.11
  112. public function actionRegister()
  113. {
  114. $connection = Yii::$app->db;
  115. $transaction = $connection->beginTransaction();
  116. try {
  117. $post = Yii::$app->request->post();
  118. $shopName = $post['name'] ?? '';
  119. if (empty($shopName)) {
  120. util::fail('名称不能为空');
  121. }
  122. $mobile = $post['mobile'] ?? '';
  123. if (stringUtil::isMobile($mobile) == false) {
  124. util::fail('请填写正确手机号');
  125. }
  126. if (stringUtil::getWordNum($shopName) > 8) {
  127. util::fail('名称不能超过8个汉字');
  128. }
  129. $arr = ['斗南鲜花', '惠雅鲜花', '纯彩花艺', '泉城鲜花', '杭州斗南', '惠雅', '国恋', '花悠星', '勇记', '丰行', '昱成', '问境', '珑松'];
  130. foreach ($arr as $it) {
  131. if (strstr($shopName, $it) != null) {
  132. util::fail('花店名称已经存在,请换个名称');
  133. }
  134. }
  135. $has = SjClass::getByCondition(['name' => $shopName]);
  136. if (!empty($has)) {
  137. //util::fail('名称已经被别人使用,请换个名字,或者名字后面加个2');
  138. }
  139. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  140. if (!empty($has)) {
  141. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  142. util::fail('手机号已经申请过了');
  143. }
  144. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  145. if (!empty($hasShop)) {
  146. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  147. util::fail('手机号已经被使用');
  148. }
  149. $post['adminId'] = $this->adminId;
  150. $authCode = $post['authCode'] ?? '';
  151. $mobile = $post['mobile'] ?? '';
  152. //避免重复提交
  153. util::checkRepeatCommit($mobile, 10);
  154. $ptStyle = Yii::$app->params['ptStyle'];
  155. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  156. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  157. if (empty($saveAuthCode)) {
  158. util::fail('请填写验证码哦');
  159. }
  160. if (empty($authCode)) {
  161. util::fail('请填写验证码');
  162. }
  163. if ($saveAuthCode != $authCode) {
  164. util::fail('验证码错误');
  165. }
  166. $adminName = $post['adminName'] ?? '';
  167. $miniOpenId = $post['miniOpenId'] ?? '';
  168. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  169. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  170. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  171. $adminId = $admin['id'] ?? 0;
  172. $currentShopId = $admin['currentShopId'] ?? 0;
  173. if (!empty($currentShopId)) {
  174. util::fail('您已提交过申请,管理员ID:' . $adminId);
  175. }
  176. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  177. util::fail('审核中,无需重复申请');
  178. }
  179. $post['adminId'] = $adminId;
  180. $post['adminName'] = $admin['name'] ?? '';
  181. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  182. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  183. $post['from'] = ApplyClass::FROM_RETAIL;
  184. $post['style'] = SjClass::STYLE_RETAIL;
  185. //增加或更新申请
  186. $respond = ApplyService::replaceRetail($post);
  187. $id = $respond['id'] ?? 0;
  188. if (empty($id)) {
  189. util::fail('申请失败');
  190. }
  191. $passInfo = ApplyService::pass($id);
  192. $mobile = $post['mobile'] ?? '';
  193. //输出登录信息
  194. $newShop = $passInfo['shop'] ?? [];
  195. $newMainId = $newShop->mainId ?? 0;
  196. $newShopId = $newShop->id ?? 0;
  197. $pfShopId = $newShop->pfShopId ?? 0;
  198. $onlyCg = 1;
  199. //前端用于判断是否注册
  200. $admin['currentShopId'] = $newShopId;
  201. $adminId = $admin['id'];
  202. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
  203. if (empty($shopAdmin)) {
  204. util::fail('没有找到管理员');
  205. }
  206. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  207. $shopAdmin->save();
  208. $shopAdminId = $shopAdmin->id ?? 0;
  209. //是否有切换门店的权限
  210. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  211. $showDemo = 1;
  212. $token = jwt::getNewToken($adminId);
  213. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  214. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  215. if ($hdUpgrading == 1) {
  216. util::fail('系统升级中,稍后再试');
  217. }
  218. $transaction->commit();
  219. //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
  220. $apiHost = Yii::$app->params['hdHost'];
  221. $imgUploadApi = $apiHost . '/upload/save-file';
  222. //惠雅鲜花员工不能看收入情况
  223. if (in_array($adminId, [2366, 2812, 4004])) {
  224. $shopAdmin->super = 0;
  225. }
  226. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  227. util::success([
  228. 'token' => $token,
  229. 'admin' => $admin,
  230. 'shopId' => $currentShopId,
  231. 'shopAdminId' => $shopAdminId,
  232. 'switchShop' => $switchShop,
  233. 'pfShopId' => $pfShopId,
  234. 'onlyCg' => $onlyCg,
  235. 'showDemo' => $showDemo,
  236. 'imgUploadApi' => $imgUploadApi,
  237. //有小程序新版本提示更新
  238. 'update' => $remind,
  239. 'staff' => $shopAdmin,
  240. ]);
  241. } catch (\Exception $exception) {
  242. $transaction->rollBack();
  243. Yii::info("申请报错:" . $exception->getMessage());
  244. util::fail('提交失败');
  245. }
  246. }
  247. //申请状态
  248. public function actionApplyStatus()
  249. {
  250. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  251. $status = -1;
  252. util::success(['status' => $status]);
  253. }
  254. //地图相关信息 ssh 2020.1.14
  255. public function actionRegionRelate()
  256. {
  257. $regionTree = RegionService::tree();
  258. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  259. $out = ['region' => $regionTree, 'txMapKey' => $mapKey];
  260. util::success($out);
  261. }
  262. //获取申请的验证码 ssh 2020.2.23
  263. public function actionGetValidateCode()
  264. {
  265. $mobile = Yii::$app->request->get('mobile');
  266. util::success(['code' => rand(1111, 9999)]);
  267. }
  268. }