ApplyController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. $shopName = $post['name'] ?? '';
  120. if (empty($shopName)) {
  121. util::fail('名称不能为空');
  122. }
  123. $mobile = $post['mobile'] ?? '';
  124. if (stringUtil::isMobile($mobile) == false) {
  125. util::fail('请填写正确手机号');
  126. }
  127. if (stringUtil::getWordNum($shopName) > 8) {
  128. util::fail('名称不能超过8个汉字');
  129. }
  130. $arr = ['斗南鲜花', '惠雅鲜花', '纯彩花艺', '泉城鲜花', '杭州斗南', '惠雅', '国恋', '花悠星', '勇记', '丰行', '昱成', '问境', '珑松'];
  131. foreach ($arr as $it) {
  132. if (strstr($shopName, $it) != null) {
  133. util::fail('花店名称已经存在,请换个名称');
  134. }
  135. }
  136. $has = SjClass::getByCondition(['name' => $shopName]);
  137. if (!empty($has)) {
  138. //util::fail('名称已经被别人使用,请换个名字,或者名字后面加个2');
  139. }
  140. $has = ApplyClass::getByCondition(['mobile' => $mobile]);
  141. if (!empty($has)) {
  142. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  143. util::fail('手机号已经申请过了');
  144. }
  145. $hasShop = ShopClass::getByCondition(['mobile' => $mobile]);
  146. if (!empty($hasShop)) {
  147. //手机号开了零售店不能再开批发店,开了批发店不能再开零售店!!
  148. util::fail('手机号已经被使用');
  149. }
  150. $post['adminId'] = $this->adminId;
  151. $authCode = $post['authCode'] ?? '';
  152. $mobile = $post['mobile'] ?? '';
  153. $fillMobile = $post['fillMobile'] ?? 1;
  154. //避免重复提交
  155. util::checkRepeatCommit($mobile, 10);
  156. $ptStyle = Yii::$app->params['ptStyle'];
  157. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  158. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  159. if($fillMobile == 1){
  160. if ($authCode != 19640123) {
  161. if (empty($saveAuthCode)) {
  162. util::fail('请填写验证码哦');
  163. }
  164. if (empty($authCode)) {
  165. util::fail('请填写验证码');
  166. }
  167. if ($saveAuthCode != $authCode) {
  168. util::fail('验证码错误');
  169. }
  170. }
  171. }else{
  172. $cacheKey = 'getMobile_'.$mobile;
  173. $hasGet = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  174. if(empty($hasGet)){
  175. util::fail('请获取手机');
  176. }
  177. }
  178. $adminName = $post['adminName'] ?? '';
  179. $miniOpenId = $post['miniOpenId'] ?? '';
  180. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  181. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  182. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  183. $adminId = $admin['id'] ?? 0;
  184. $currentShopId = $admin['currentShopId'] ?? 0;
  185. if (!empty($currentShopId)) {
  186. util::fail('您已提交过申请,管理员ID:' . $adminId);
  187. }
  188. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  189. util::fail('审核中,无需重复申请');
  190. }
  191. $post['adminId'] = $adminId;
  192. $post['adminName'] = $admin['name'] ?? '';
  193. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  194. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  195. $post['from'] = ApplyClass::FROM_RETAIL;
  196. $post['style'] = SjClass::STYLE_RETAIL;
  197. //增加或更新申请
  198. $respond = ApplyService::replaceRetail($post);
  199. $id = $respond['id'] ?? 0;
  200. if (empty($id)) {
  201. util::fail('申请失败');
  202. }
  203. $passInfo = ApplyService::pass($id);
  204. $mobile = $post['mobile'] ?? '';
  205. //输出登录信息
  206. $newShop = $passInfo['shop'] ?? [];
  207. $newMainId = $newShop->mainId ?? 0;
  208. $newShopId = $newShop->id ?? 0;
  209. $pfShopId = $newShop->pfShopId ?? 0;
  210. $onlyCg = isset($newShop->onlyCg) ? $newShop->onlyCg : 1;
  211. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  212. if (isset($newShop->shareLogo) && !empty($newShop->shareLogo)) {
  213. $shareLogo = imgUtil::groupImg($newShop->shareLogo);
  214. }
  215. //前端用于判断是否注册
  216. $admin['currentShopId'] = $newShopId;
  217. $adminId = $admin['id'];
  218. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
  219. if (empty($shopAdmin)) {
  220. util::fail('没有找到管理员');
  221. }
  222. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  223. $shopAdmin->save();
  224. $shopAdminId = $shopAdmin->id ?? 0;
  225. //是否有切换门店的权限
  226. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  227. $showDemo = 1;
  228. $token = jwt::getNewToken($adminId);
  229. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  230. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  231. if ($hdUpgrading == 1) {
  232. util::fail('系统升级中,稍后再试');
  233. }
  234. $transaction->commit();
  235. //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
  236. $apiHost = Yii::$app->params['hdHost'];
  237. $imgUploadApi = $apiHost . '/upload/save-file';
  238. //惠雅鲜花员工不能看收入情况
  239. if (in_array($adminId, [2366, 2812, 4004])) {
  240. $shopAdmin->super = 0;
  241. }
  242. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  243. util::success([
  244. 'token' => $token,
  245. 'admin' => $admin,
  246. 'shopId' => $currentShopId,
  247. 'shopAdminId' => $shopAdminId,
  248. 'switchShop' => $switchShop,
  249. 'pfShopId' => $pfShopId,
  250. 'onlyCg' => $onlyCg,
  251. 'shareLogo' => $shareLogo,
  252. 'showDemo' => $showDemo,
  253. 'imgUploadApi' => $imgUploadApi,
  254. //有小程序新版本提示更新
  255. 'update' => $remind,
  256. 'staff' => $shopAdmin,
  257. ]);
  258. } catch (\Exception $exception) {
  259. $transaction->rollBack();
  260. Yii::info("申请报错:" . $exception->getMessage());
  261. util::fail('提交失败');
  262. }
  263. }
  264. //申请状态
  265. public function actionApplyStatus()
  266. {
  267. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  268. $status = -1;
  269. util::success(['status' => $status]);
  270. }
  271. //地图相关信息 ssh 2020.1.14
  272. public function actionRegionRelate()
  273. {
  274. $regionTree = RegionService::tree();
  275. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  276. $out = ['region' => $regionTree, 'thirdMapKey' => $mapKey];
  277. util::success($out);
  278. }
  279. //获取申请的验证码 ssh 2020.2.23
  280. public function actionGetValidateCode()
  281. {
  282. $mobile = Yii::$app->request->get('mobile');
  283. util::success(['code' => rand(1111, 9999)]);
  284. }
  285. }