ShopController.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\MainClass;
  4. use biz\shop\classes\ShopAdminClass;
  5. use biz\shop\classes\ShopExtClass;
  6. use biz\sj\services\MerchantExtendService;
  7. use bizGhs\admin\classes\AdminClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use bizGhs\ghs\classes\GhsClass;
  10. use bizGhs\merchant\classes\MerchantClass;
  11. use bizGhs\merchant\classes\ShopClass;
  12. use bizGhs\merchant\services\ShopService;
  13. use bizGhs\pictext\classes\PicTextClass;
  14. use bizHd\saas\services\RegionService;
  15. use common\components\arrayUtil;
  16. use common\components\dict;
  17. use common\components\dirUtil;
  18. use common\components\httpUtil;
  19. use common\components\imgUtil;
  20. use common\components\IntraCityExpress;
  21. use common\components\stringUtil;
  22. use common\components\util;
  23. use common\components\wxUtil;
  24. use Yii;
  25. use bizGhs\stat\classes\StatSaleClass;
  26. class ShopController extends BaseController
  27. {
  28. public $guestAccess = ['all'];
  29. public function actionModifySjName()
  30. {
  31. $get = Yii::$app->request->get();
  32. $adminId = $this->adminId;
  33. if (getenv('YII_ENV') == 'production') {
  34. if ($adminId != 4) {
  35. util::fail('请联系管理员修改');
  36. }
  37. } else {
  38. if ($adminId != 919) {
  39. util::fail('请联系管理员修改');
  40. }
  41. }
  42. $name = $get['name'] ?? '';
  43. if (empty($name)) {
  44. util::fail('请填写名称');
  45. }
  46. $shop = $this->shop;
  47. $shop->merchantName = $name;
  48. $shop->save();
  49. $sjId = $shop->sjId;
  50. $sj = MerchantClass::getById($sjId, true);
  51. if (empty($sj)) {
  52. util::fail('门店信息缺失呢');
  53. }
  54. $sj->name = $name;
  55. $sj->save();
  56. $fullName = $shop->shopName == '首店' ? $name : $name . ' ' . $shop->shopName;
  57. $shopId = $shop->id;
  58. $py = stringUtil::py($fullName);
  59. GhsClass::updateByCondition(['shopId' => $shopId], ['name' => $fullName, 'py' => $py]);
  60. util::complete('修改成功');
  61. }
  62. //小程序端使用,下载收款码 ssh 20250821
  63. public function actionMiniGatheringCode()
  64. {
  65. $shop = $this->shop;
  66. $lsShopId = $shop->lsShopId ?? 0;
  67. if (empty($lsShopId)) {
  68. util::fail('没有零售店ID');
  69. }
  70. $lsShop = ShopClass::getById($lsShopId, true);
  71. if (empty($lsShop)) {
  72. util::fail('没有零售店呢');
  73. }
  74. $sjId = $lsShop->sjId ?? 0;
  75. $imgUrl = \biz\shop\classes\ShopClass::generateGatheringCode($sjId, $lsShopId);
  76. util::success(['imgUrl' => $imgUrl]);
  77. }
  78. //修改客户微信二维码 ssh 20240714
  79. public function actionChangeWx()
  80. {
  81. $get = Yii::$app->request->get();
  82. $url = $get['url'] ?? '';
  83. $shop = $this->shop;
  84. $shop->superWx = $url;
  85. $shop->save();
  86. util::complete('修改成功');
  87. }
  88. //我的可以进入的门店 ssh 20230424
  89. public function actionMyShop()
  90. {
  91. $staff = $this->shopAdmin;
  92. $shopList = [];
  93. if (isset($staff->super) && $staff->super == 1) {
  94. $sjId = $this->sjId ?? 0;
  95. $shopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'ptStyle' => 2], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id');
  96. }
  97. $adminId = $this->adminId;
  98. $staffList = ShopAdminClass::getAllByCondition(['adminId' => $adminId], null, '*', null, true);
  99. $mainIdList = [];
  100. if (!empty($staffList)) {
  101. foreach ($staffList as $staff) {
  102. $isPt = $staff->isPt ?? 0;
  103. $delStatus = $staff->delStatus ?? 0;
  104. //$super = $staff->super ?? 0;
  105. $mainId = $staff->mainId ?? 0;
  106. if ($isPt == 0 && $delStatus == 0) {
  107. $mainIdList[] = $mainId;
  108. }
  109. }
  110. }
  111. if (!empty($mainIdList)) {
  112. $addShopList = ShopClass::getAllByCondition(['mainId' => ['in', $mainIdList], 'ptStyle' => 2], null, 'id,shopName,merchantName,sjId,mainId,ptStyle', 'id');
  113. if (!empty($addShopList)) {
  114. foreach ($addShopList as $addShop) {
  115. $addShopId = $addShop['id'] ?? 0;
  116. if (!isset($shopList[$addShopId])) {
  117. $shopList[$addShopId] = $addShop;
  118. }
  119. }
  120. }
  121. }
  122. $list = array_values($shopList);
  123. util::success(['list' => $list]);
  124. }
  125. //绑定零售店 ssh 20220430
  126. public function actionBindLsShop()
  127. {
  128. $id = Yii::$app->request->get('id');
  129. $connection = Yii::$app->db;
  130. $transaction = $connection->beginTransaction();
  131. util::fail('此方法已停用,如需启用请确认有没问题');
  132. try {
  133. $shop = $this->shop ?? [];
  134. $lsShopId = $shop->lsShopId ?? 0;
  135. if (!empty($lsShopId)) {
  136. util::fail('您已经绑定过了');
  137. }
  138. ShopClass::bindLsShopByCustomId($shop, $id, $this->adminId);
  139. $transaction->commit();
  140. util::complete();
  141. } catch (\Exception $exception) {
  142. $transaction->rollBack();
  143. util::fail('绑定失败');
  144. }
  145. }
  146. //预订设置 ssh 20220324
  147. public function actionBookSet()
  148. {
  149. $get = Yii::$app->request->get();
  150. $presell = $get['presell'] ?? 0;
  151. $this->shop->presell = $presell;
  152. $this->shop->save();
  153. util::complete();
  154. }
  155. //当前门店信息
  156. public function actionInfo()
  157. {
  158. $shop = $this->shop ?? [];
  159. util::success($shop);
  160. }
  161. //获取当前门店信息 ssh 2021.3.27
  162. public function actionCurrentShop()
  163. {
  164. $main = $this->shop;
  165. util::success($main);
  166. }
  167. //门店列表 ssh 2021.1.14
  168. public function actionList()
  169. {
  170. $where = [];
  171. $where['sjId'] = $this->sjId;
  172. $where['delStatus'] = 0;
  173. $list = ShopClass::getShopList($where);
  174. util::success($list);
  175. }
  176. //更新门店 ssh 2020.2.29
  177. public function actionUpdate()
  178. {
  179. $post = Yii::$app->request->post();
  180. $post['sjId'] = $this->sjId;
  181. $id = $post['id'] ?? 0;
  182. $shop = ShopService::getById($id);
  183. if (empty($shop)) {
  184. util::fail('没有找到门店,编号657701');
  185. }
  186. $staff = $this->shopAdmin;
  187. if (!isset($staff->finance) || $staff->finance == 0) {
  188. //花掌柜的小石,源花汇的小吕和小吴,没有财务权限也要能修改门店
  189. if (!in_array($this->adminId, [4, 11961, 11976])) {
  190. util::fail('没有修改门店权限');
  191. }
  192. }
  193. if (!isset($staff->super) || $staff->super == 0) {
  194. //花掌柜的小石,源花汇的小吕和小吴,没有改库存改价格权限也要能修改门店
  195. if (!in_array($this->adminId, [4, 11961, 11976])) {
  196. util::fail('没有修改门店权限哦');
  197. }
  198. }
  199. if ($this->mainId == 59421) {
  200. if (!in_array($this->adminId, [4])) {
  201. util::fail('已停用,请联系管理员');
  202. }
  203. }
  204. $post['meetNum'] = isset($post['meetNum']) && !empty($post['meetNum']) ? $post['meetNum'] : 0;
  205. $post['meetAmount'] = isset($post['meetAmount']) && !empty($post['meetAmount']) ? $post['meetAmount'] : 0;
  206. $post['cutAmount'] = isset($post['cutAmount']) && !empty($post['cutAmount']) ? $post['cutAmount'] : 0;
  207. ShopClass::valid($shop, $this->sjId);
  208. //手机号具有唯一性,暂时不允许修改 --- 同零售端 app-hd/controllers/ShopController.php 保持一致
  209. unset($post['mobile']);
  210. $post['img'] = isset($post['img']) && is_array($post['img']) ? json_encode($post['img']) : '';
  211. \biz\shop\classes\ShopClass::updateShop($shop, $post);
  212. util::complete();
  213. }
  214. // 更新门店头像
  215. public function actionUpdateAvatar()
  216. {
  217. $post = Yii::$app->request->post();
  218. $shopId = $post['shopId'];
  219. if ($post['shopId'] != $this->shopId or $this->mainId == 0) {
  220. util::fail('不是您的门店');
  221. }
  222. $avatar = $post['avatar'];
  223. if ($avatar == '') {
  224. util::fail('头像地址不能为空');
  225. }
  226. $shop = ShopClass::getById($shopId, true);
  227. $shop->avatar = $avatar;
  228. $shop->save();
  229. $ptStyle = $shop['ptStyle'] ?? dict::getDict('ptStyle', 'hd');
  230. $update = ['avatar' => $avatar];
  231. $where = ['mainId' => $this->mainId];
  232. if ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
  233. GhsClass::updateByCondition($where, $update);
  234. } else {
  235. util::fail('门店头像更新失败,平台类型错误');
  236. }
  237. $shopImg = imgUtil::groupImg($shop->avatar);
  238. $smallShopImg = imgUtil::groupImg($shop->avatar) . "?x-oss-process=image/resize,m_fill,h_80,w_80";
  239. util::success(['shopImg' => $shopImg, 'smallShopImg' => $smallShopImg], '门店头像更新成功');
  240. }
  241. //添加门店 ssh 2021.1.14
  242. public function actionAdd()
  243. {
  244. $shop = $this->shop;
  245. $default = $shop->default ?? 0;
  246. if ($default == 0) {
  247. util::fail('当前直营分店,请切回总店添加');
  248. }
  249. $adminId = $this->adminId;
  250. $ptSuperAdminId = \biz\admin\classes\AdminClass::getPtSuperAdminId();
  251. if ($adminId != $shop->adminId && $adminId != $ptSuperAdminId) {
  252. util::fail('本店超管才能添加门店');
  253. }
  254. $mainId = $this->mainId;
  255. if (getenv('YII_ENV') == 'production') {
  256. if ($mainId == 42490) {
  257. util::fail('无法建分店,请联系石头');
  258. }
  259. } else {
  260. if ($mainId == 644) {
  261. util::fail('无法建分店,请联系石头');
  262. }
  263. }
  264. $data = Yii::$app->request->post();
  265. $data['sjId'] = $this->sjId;
  266. $data['shopId'] = $this->shopId;
  267. $data['adminId'] = $this->adminId;
  268. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  269. util::fail('请填写门店名称');
  270. }
  271. $sj = $this->sj;
  272. $sjName = $sj->name ?? '';
  273. $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
  274. $data['ptStyle'] = $ptStyle;
  275. $data['merchantName'] = $sjName;
  276. $data['default'] = 0;
  277. $connection = Yii::$app->db;
  278. $transaction = $connection->beginTransaction();
  279. try {
  280. $mobile = $data['mobile'] ?? 0;
  281. if (stringUtil::isMobile($mobile) == false) {
  282. util::fail('请填写正确手机号');
  283. }
  284. $adminInfo = ['name' => $mobile, 'mobile' => $mobile];
  285. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  286. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  287. $adminId = $admin['id'] ?? 0;
  288. $data['adminId'] = $adminId;
  289. ShopClass::addMainShop($data, $this->shop, $this->sj);
  290. $transaction->commit();
  291. util::complete();
  292. } catch (\Exception $exception) {
  293. $transaction->rollBack();
  294. util::fail();
  295. }
  296. }
  297. //PC下载微信和支付宝收款码 ssh 2020.2.29
  298. public function actionGatheringCode()
  299. {
  300. $id = Yii::$app->request->get('id', 0);
  301. $shop = ShopService::getById($id);
  302. ShopClass::valid($shop, $this->sjId);
  303. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  304. $file = dirUtil::getImgDir() . $gatheringCode;
  305. if (file_exists($file) == false) {
  306. util::fail('没有找到收款码');
  307. }
  308. if (httpUtil::isMiniProgram()) {
  309. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  310. util::success(['imgUrl' => $imgUrl]);
  311. }
  312. $fileName = "门店({$id})收款码.jpg";
  313. $contentType = 'image/jpeg';
  314. header("Cache-control: private");
  315. header("Content-type: $contentType"); //设置要下载的文件类型
  316. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  317. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  318. readfile($file);
  319. }
  320. //PC获取小程序的收款码 ssh
  321. public function actionGatheringMiniCode()
  322. {
  323. $id = Yii::$app->request->get('id', 0);
  324. $extend = MerchantExtendService::getBySjId($this->sjId);
  325. if ($extend['miniAuth'] == 0) {
  326. util::fail('您的小程序还没有授权');
  327. }
  328. $shop = ShopService::getById($id);
  329. ShopClass::valid($shop, $this->sjId);
  330. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  331. $file = dirUtil::getImgDir() . $applyMemberCode;
  332. if (file_exists($file) == false) {
  333. util::fail('没有找到注册会员码');
  334. }
  335. if (httpUtil::isMiniProgram()) {
  336. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  337. util::success(['imgUrl' => $imgUrl]);
  338. }
  339. $fileName = "门店({$id})小程序收款码.jpg";
  340. $contentType = 'image/jpeg';
  341. header("Cache-control: private");
  342. header("Content-type: $contentType"); //设置要下载的文件类型
  343. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  344. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  345. readfile($file);
  346. }
  347. //PC下载会员注册码 ssh 2020.2.29
  348. public function actionApplyMemberCode()
  349. {
  350. $id = Yii::$app->request->get('id', 0);
  351. $extend = MerchantExtendService::getBySjId($this->sjId);
  352. if ($extend['miniAuth'] == 0) {
  353. util::fail('您的小程序还没有授权');
  354. }
  355. $shop = ShopService::getById($id);
  356. ShopClass::valid($shop, $this->sjId);
  357. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  358. $file = dirUtil::getImgDir() . $applyMemberCode;
  359. if (file_exists($file) == false) {
  360. util::fail('没有找到注册会员码');
  361. }
  362. if (httpUtil::isMiniProgram()) {
  363. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  364. util::success(['imgUrl' => $imgUrl]);
  365. }
  366. $fileName = "注册会员码{$id}.jpg";
  367. $contentType = 'image/jpeg';
  368. header("Cache-control: private");
  369. header("Content-type: $contentType"); //设置要下载的文件类型
  370. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  371. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  372. readfile($file);
  373. }
  374. //删除门店 ssh 2020.3.1
  375. public function actionDelete()
  376. {
  377. util::fail('禁止操作');
  378. $id = Yii::$app->request->get('id', 0);
  379. $shop = ShopService::getById($id);
  380. ShopClass::valid($shop, $this->sjId);
  381. ShopClass::deleteShop($shop);
  382. util::complete();
  383. }
  384. //获取所有门店lqh 2021.1.31
  385. public function actionAll()
  386. {
  387. $res = ShopClass::getAllShop($this->sjId);
  388. util::success($res);
  389. }
  390. //切换门店 lqh 2021.1.31
  391. public function actionToggleShop()
  392. {
  393. $mainId = $this->mainId;
  394. $adminId = $this->adminId;
  395. //多处要同步修改,关键词 no_allow_toggle_shop
  396. if (getenv('YII_ENV') == 'production') {
  397. //安海恋善不允许切换门店
  398. if (in_array($mainId, [44759, 56314, 56315, 56452])) {
  399. if (in_array($adminId, [54630, 54723])) {
  400. util::fail('专用账号,不允许切换门店');
  401. }
  402. }
  403. //惠雅南城不允许切换门店
  404. if ($mainId == 52 && $adminId == 3539) {
  405. util::fail('收银专用账号,不允许切换门店');
  406. }
  407. //惠雅莞城不允许切换门店
  408. if ($mainId == 1459 && $adminId == 2812) {
  409. util::fail('收银专用账号,不允许切换门店');
  410. }
  411. //淘花里中山店
  412. if ($mainId == 16948 && $adminId == 17908) {
  413. util::fail('收银专用账号,不允许切换门店');
  414. }
  415. //淘花里小榄店
  416. if ($mainId == 72057 && $adminId == 69792) {
  417. util::fail('收银专用账号,不允许切换门店');
  418. }
  419. }
  420. $shopAdmin = $this->shopAdmin;
  421. $switchShop = ShopAdminClass::hasSwitchShopRight($shopAdmin);
  422. if ($switchShop == 0) {
  423. util::fail('不能切换门店');
  424. }
  425. $newShopId = Yii::$app->request->post('shopId', 0);
  426. $newShop = ShopClass::getById($newShopId, true);
  427. if (empty($newShop)) {
  428. util::fail('没有找到门店66');
  429. }
  430. $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  431. util::success($res);
  432. }
  433. //提现信息更新 ssh 2021.3.23
  434. public function actionCashUpdate()
  435. {
  436. $get = Yii::$app->request->get();
  437. $cashAccount = $get['cashAccount'] ?? '';
  438. $cashName = $get['cashName'] ?? '';
  439. $cashBank = $get['cashBank'] ?? '';
  440. if (empty($cashName)) {
  441. util::fail('请填写姓名');
  442. }
  443. if (empty($cashAccount)) {
  444. util::fail('请填写银行卡号');
  445. }
  446. if (empty($cashBank)) {
  447. util::fail('请输入开户行');
  448. }
  449. $shopAdmin = $this->shopAdmin;
  450. $mainId = $shopAdmin->mainId ?? 0;
  451. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  452. util::fail('超管才能操作');
  453. }
  454. MainClass::updateById($mainId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  455. $shop = $this->shop;
  456. $sjName = $shop->merchantName ?? '';
  457. $shopName = $shop->shopName ?? '';
  458. //noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347');
  459. util::complete();
  460. }
  461. //获取门店详情 ssh 2021.4.23
  462. public function actionDetail()
  463. {
  464. $shopId = Yii::$app->request->get('shopId');
  465. if (empty($shopId)) {
  466. $shopId = $this->shopId;
  467. }
  468. $shop = ShopClass::getById($shopId, true);
  469. if ($shop->mainId != $this->mainId) {
  470. //这个注释不能打开,因为首店可能修改其它分店信息
  471. //util::fail('无法查看');
  472. }
  473. $shop = $shop->toArray();
  474. $shop['hasMap'] = dict::getDict('hasMap'); //添加 hasMap 属性(字典中的 hasMap)
  475. util::success(['info' => $shop]);
  476. }
  477. //获取平台所有的供货商门店 ssh 20210908
  478. public function actionGetPtGhsShop()
  479. {
  480. $hasSale = Yii::$app->request->get('hasSale', 0);
  481. $name = Yii::$app->request->get('name', '');
  482. $arr = ['ptStyle' => 2, 'live' => 1];
  483. if (!empty($name)) {
  484. $arr['merchantName'] = ['like', $name];
  485. $hasSale = 0;
  486. }
  487. $shopList = ShopClass::getAllByCondition($arr, 'id asc', '*');
  488. $totalSale = 0;
  489. $totalShopNum = 0;
  490. $totalBalance = 0;
  491. if (!empty($shopList)) {
  492. foreach ($shopList as $key => $shop) {
  493. $mainId = $shop['mainId'] ?? 0;
  494. $main = MainClass::getById($mainId, true);
  495. $balance = $main->balance ?? 0;
  496. if (!empty($name) || $hasSale == 0) {
  497. $incomeList = [];
  498. } else {
  499. $respond = StatSaleClass::profile($mainId);
  500. $incomeList = $respond['income'] ?? [];
  501. }
  502. $todaySale = 0;
  503. if (!empty($incomeList)) {
  504. foreach ($incomeList as $item) {
  505. //调拨出库暂时不算到收入里去
  506. if (isset($item['id']) && $item['id'] == 'allot') {
  507. continue;
  508. }
  509. $todaySale = bcadd($todaySale, $item['amount'], 2);
  510. }
  511. }
  512. $shopList[$key]['balance'] = $balance;
  513. $shopList[$key]['todaySale'] = $todaySale;
  514. $count = CustomClass::getCount(['ownMainId' => $mainId]);
  515. $count = $count > 0 ? $count : 0;
  516. $shopList[$key]['shopNum'] = $count;
  517. if ($hasSale == 1 && $todaySale <= 0) {
  518. unset($shopList[$key]);
  519. }
  520. $totalSale = bcadd($totalSale, $todaySale, 2);
  521. $totalSale = floatval($totalSale);
  522. $totalBalance = bcadd($totalBalance, $balance, 2);
  523. $totalBalance = floatval($totalBalance);
  524. $totalShopNum = bcadd($totalShopNum, $count);
  525. }
  526. $shopList = arrayUtil::arraySort($shopList, 'todaySale');
  527. }
  528. util::success(['list' => $shopList, 'totalSale' => $totalSale, 'totalBalance' => $totalBalance, 'totalShopNum' => $totalShopNum]);
  529. }
  530. //切换门店 ssh 20220624
  531. public function actionSwitchGhsShop()
  532. {
  533. $shopId = Yii::$app->request->get('shopId', 0);
  534. $shop = ShopClass::getById($shopId, true);
  535. if (empty($shop)) {
  536. util::fail('没有找到门店67');
  537. }
  538. $shopAdmin = $this->shopAdmin;
  539. $admin = $this->admin;
  540. $adminId = $this->adminId ?? 0;
  541. if (getenv('YII_ENV') == 'production') {
  542. if (in_array($adminId, [4]) == false) {
  543. util::fail('开发中');
  544. }
  545. } else {
  546. if (in_array($adminId, [919]) == false) {
  547. util::fail('开发中');
  548. }
  549. }
  550. ShopAdminClass::changeShopAddRelate($shopAdmin, $shop, 1);
  551. $admin->currentGhsShopId = $shopId;
  552. $lsShopId = $shop->lsShopId ?? 0;
  553. $admin->currentShopId = $lsShopId;
  554. $admin->save();
  555. util::complete();
  556. }
  557. //散客门店详情 ssh 20211007
  558. public function actionSkCustom()
  559. {
  560. $skCustomId = $this->shop->skCustomId ?? 0;
  561. $custom = [];
  562. if (!empty($skCustomId)) {
  563. $custom = CustomClass::getById($skCustomId);
  564. $avatar = $custom['avatar'] ?? '';
  565. $custom['avatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  566. }
  567. util::success(['custom' => $custom]);
  568. }
  569. //散客门店设置
  570. public function actionSkCustomSet()
  571. {
  572. $id = Yii::$app->request->get('id', 0);
  573. $custom = CustomClass::getById($id, true);
  574. CustomClass::valid($custom, $this->shopId);
  575. $this->shop->skCustomId = $id;
  576. $this->shop->save();
  577. util::complete('修改成功');
  578. }
  579. //运费模式和运费成本设置 ssh 20211014
  580. public function actionUpdateCgModel()
  581. {
  582. $get = Yii::$app->request->get();
  583. $cgModel = $get['cgModel'] ?? 0;
  584. $cgPerCost = $get['cgPerCost'] ?? 0;
  585. if ($cgModel == 1) {
  586. if (is_numeric($cgPerCost) == false || $cgPerCost < 0) {
  587. util::fail('请输入运费成本');
  588. }
  589. $this->shop->cgPerCost = $cgPerCost;
  590. }
  591. $this->shop->cgModel = $cgModel;
  592. $this->shop->save();
  593. util::complete('修改成功');
  594. }
  595. //地区 ssh 20220606
  596. public function actionRegion()
  597. {
  598. $regionTree = RegionService::tree();
  599. util::success(['region' => $regionTree]);
  600. }
  601. //获取购买须知信息
  602. public function actionPurchaseGuide()
  603. {
  604. $shopId = intval($this->shopId);
  605. if ($shopId <= 0) {
  606. util::fail('门店数据错误');
  607. }
  608. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, shopId, purchaseGuide');
  609. if ($shopExt['purchaseGuide'] > 0) {
  610. $picText = PicTextClass::getById($shopExt['purchaseGuide'], false, 'id, title');
  611. $shopExt['title'] = $picText['title'] ?? '';
  612. }
  613. $shop = $this->shop;
  614. util::success(['shopExt' => $shopExt, 'shop' => $shop]);
  615. }
  616. }