ShopController.php 24 KB

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