ApplyController.php 12 KB

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