ApplyController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. //避免重复提交
  154. util::checkRepeatCommit($mobile, 10);
  155. $ptStyle = Yii::$app->params['ptStyle'];
  156. $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile;
  157. $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  158. if ($authCode != 19640123) {
  159. if (empty($saveAuthCode)) {
  160. util::fail('请填写验证码哦');
  161. }
  162. if (empty($authCode)) {
  163. util::fail('请填写验证码');
  164. }
  165. if ($saveAuthCode != $authCode) {
  166. util::fail('验证码错误');
  167. }
  168. }
  169. $adminName = $post['adminName'] ?? '';
  170. $miniOpenId = $post['miniOpenId'] ?? '';
  171. $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId];
  172. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  173. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  174. $adminId = $admin['id'] ?? 0;
  175. $currentShopId = $admin['currentShopId'] ?? 0;
  176. if (!empty($currentShopId)) {
  177. util::fail('您已提交过申请,管理员ID:' . $adminId);
  178. }
  179. if (isset($admin['openShop']) && $admin['openShop'] == 2) {
  180. util::fail('审核中,无需重复申请');
  181. }
  182. $post['adminId'] = $adminId;
  183. $post['adminName'] = $admin['name'] ?? '';
  184. $post['long'] = isset($post['longitude']) ? $post['longitude'] : '';
  185. $post['lat'] = isset($post['latitude']) ? $post['latitude'] : '';
  186. $post['from'] = ApplyClass::FROM_RETAIL;
  187. $post['style'] = SjClass::STYLE_RETAIL;
  188. //增加或更新申请
  189. $respond = ApplyService::replaceRetail($post);
  190. $id = $respond['id'] ?? 0;
  191. if (empty($id)) {
  192. util::fail('申请失败');
  193. }
  194. $passInfo = ApplyService::pass($id);
  195. $mobile = $post['mobile'] ?? '';
  196. //输出登录信息
  197. $newShop = $passInfo['shop'] ?? [];
  198. $newMainId = $newShop->mainId ?? 0;
  199. $newShopId = $newShop->id ?? 0;
  200. $pfShopId = $newShop->pfShopId ?? 0;
  201. $onlyCg = isset($newShop->onlyCg) ? $newShop->onlyCg : 1;
  202. $shareLogo = imgUtil::groupImg('buy_logo.jpg');
  203. if (isset($newShop->shareLogo) && !empty($newShop->shareLogo)) {
  204. $shareLogo = imgUtil::groupImg($newShop->shareLogo);
  205. }
  206. //前端用于判断是否注册
  207. $admin['currentShopId'] = $newShopId;
  208. $adminId = $admin['id'];
  209. $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
  210. if (empty($shopAdmin)) {
  211. util::fail('没有找到管理员');
  212. }
  213. $shopAdmin->lastLogin = date("Y-m-d H:i:s");
  214. $shopAdmin->save();
  215. $shopAdminId = $shopAdmin->id ?? 0;
  216. //是否有切换门店的权限
  217. $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
  218. $showDemo = 1;
  219. $token = jwt::getNewToken($adminId);
  220. $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
  221. $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
  222. if ($hdUpgrading == 1) {
  223. util::fail('系统升级中,稍后再试');
  224. }
  225. $transaction->commit();
  226. //noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
  227. $apiHost = Yii::$app->params['hdHost'];
  228. $imgUploadApi = $apiHost . '/upload/save-file';
  229. //惠雅鲜花员工不能看收入情况
  230. if (in_array($adminId, [2366, 2812, 4004])) {
  231. $shopAdmin->super = 0;
  232. }
  233. //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
  234. util::success([
  235. 'token' => $token,
  236. 'admin' => $admin,
  237. 'shopId' => $currentShopId,
  238. 'shopAdminId' => $shopAdminId,
  239. 'switchShop' => $switchShop,
  240. 'pfShopId' => $pfShopId,
  241. 'onlyCg' => $onlyCg,
  242. 'shareLogo' => $shareLogo,
  243. 'showDemo' => $showDemo,
  244. 'imgUploadApi' => $imgUploadApi,
  245. //有小程序新版本提示更新
  246. 'update' => $remind,
  247. 'staff' => $shopAdmin,
  248. ]);
  249. } catch (\Exception $exception) {
  250. $transaction->rollBack();
  251. Yii::info("申请报错:" . $exception->getMessage());
  252. util::fail('提交失败');
  253. }
  254. }
  255. //申请状态
  256. public function actionApplyStatus()
  257. {
  258. //-1申请试用 0审核中 1审核通过、试用中 2审核未通过 3已付费,立即订购 4试用到期失效,待付款,立即订购,价格不显示
  259. $status = -1;
  260. util::success(['status' => $status]);
  261. }
  262. //地图相关信息 ssh 2020.1.14
  263. public function actionRegionRelate()
  264. {
  265. $regionTree = RegionService::tree();
  266. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  267. $out = ['region' => $regionTree, 'txMapKey' => $mapKey];
  268. util::success($out);
  269. }
  270. //获取申请的验证码 ssh 2020.2.23
  271. public function actionGetValidateCode()
  272. {
  273. $mobile = Yii::$app->request->get('mobile');
  274. util::success(['code' => rand(1111, 9999)]);
  275. }
  276. }