ShopController.php 25 KB

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