ShopController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. $deviceId = Yii::$app->request->post('deviceId', '');
  427. $newShop = ShopClass::getById($newShopId, true);
  428. if (empty($newShop)) {
  429. util::fail('没有找到门店66');
  430. }
  431. $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  432. if ($deviceId != '') {
  433. //设备登录状态更新
  434. $oldDevice = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$this->shopId, 'deviceId'=>$deviceId], true);
  435. if ($oldDevice) {
  436. $oldDevice->status = 0;
  437. $oldDevice->save();
  438. }
  439. $newLoginDevice = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$newShop, 'deviceId'=>$deviceId], true);
  440. if ($newLoginDevice) {
  441. $newLoginDevice->status = 1;
  442. $newLoginDevice->save();
  443. }
  444. }
  445. util::success($res);
  446. }
  447. //提现信息更新 ssh 2021.3.23
  448. public function actionCashUpdate()
  449. {
  450. $get = Yii::$app->request->get();
  451. $cashAccount = $get['cashAccount'] ?? '';
  452. $cashName = $get['cashName'] ?? '';
  453. $cashBank = $get['cashBank'] ?? '';
  454. if (empty($cashName)) {
  455. util::fail('请填写姓名');
  456. }
  457. if (empty($cashAccount)) {
  458. util::fail('请填写银行卡号');
  459. }
  460. if (empty($cashBank)) {
  461. util::fail('请输入开户行');
  462. }
  463. $shopAdmin = $this->shopAdmin;
  464. $mainId = $shopAdmin->mainId ?? 0;
  465. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  466. util::fail('超管才能操作');
  467. }
  468. MainClass::updateById($mainId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  469. $shop = $this->shop;
  470. $sjName = $shop->merchantName ?? '';
  471. $shopName = $shop->shopName ?? '';
  472. //noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347');
  473. util::complete();
  474. }
  475. //获取门店详情 ssh 2021.4.23
  476. public function actionDetail()
  477. {
  478. $shopId = Yii::$app->request->get('shopId');
  479. if (empty($shopId)) {
  480. $shopId = $this->shopId;
  481. }
  482. $shop = ShopClass::getById($shopId, true);
  483. if ($shop->mainId != $this->mainId) {
  484. //这个注释不能打开,因为首店可能修改其它分店信息
  485. //util::fail('无法查看');
  486. }
  487. $shop = $shop->toArray();
  488. $shop['hasMap'] = dict::getDict('hasMap'); //添加 hasMap 属性(字典中的 hasMap)
  489. util::success(['info' => $shop]);
  490. }
  491. //获取平台所有的供货商门店 ssh 20210908
  492. public function actionGetPtGhsShop()
  493. {
  494. $hasSale = Yii::$app->request->get('hasSale', 0);
  495. $name = Yii::$app->request->get('name', '');
  496. $arr = ['ptStyle' => 2, 'live' => 1];
  497. if (!empty($name)) {
  498. $arr['merchantName'] = ['like', $name];
  499. $hasSale = 0;
  500. }
  501. $shopList = ShopClass::getAllByCondition($arr, 'id asc', '*');
  502. $totalSale = 0;
  503. $totalShopNum = 0;
  504. $totalBalance = 0;
  505. if (!empty($shopList)) {
  506. foreach ($shopList as $key => $shop) {
  507. $mainId = $shop['mainId'] ?? 0;
  508. $main = MainClass::getById($mainId, true);
  509. $balance = $main->balance ?? 0;
  510. if (!empty($name) || $hasSale == 0) {
  511. $incomeList = [];
  512. } else {
  513. $respond = StatSaleClass::profile($mainId);
  514. $incomeList = $respond['income'] ?? [];
  515. }
  516. $todaySale = 0;
  517. if (!empty($incomeList)) {
  518. foreach ($incomeList as $item) {
  519. //调拨出库暂时不算到收入里去
  520. if (isset($item['id']) && $item['id'] == 'allot') {
  521. continue;
  522. }
  523. $todaySale = bcadd($todaySale, $item['amount'], 2);
  524. }
  525. }
  526. $shopList[$key]['balance'] = $balance;
  527. $shopList[$key]['todaySale'] = $todaySale;
  528. $count = CustomClass::getCount(['ownMainId' => $mainId]);
  529. $count = $count > 0 ? $count : 0;
  530. $shopList[$key]['shopNum'] = $count;
  531. if ($hasSale == 1 && $todaySale <= 0) {
  532. unset($shopList[$key]);
  533. }
  534. $totalSale = bcadd($totalSale, $todaySale, 2);
  535. $totalSale = floatval($totalSale);
  536. $totalBalance = bcadd($totalBalance, $balance, 2);
  537. $totalBalance = floatval($totalBalance);
  538. $totalShopNum = bcadd($totalShopNum, $count);
  539. }
  540. $shopList = arrayUtil::arraySort($shopList, 'todaySale');
  541. }
  542. util::success(['list' => $shopList, 'totalSale' => $totalSale, 'totalBalance' => $totalBalance, 'totalShopNum' => $totalShopNum]);
  543. }
  544. //切换门店 ssh 20220624
  545. public function actionSwitchGhsShop()
  546. {
  547. $shopId = Yii::$app->request->get('shopId', 0);
  548. $shop = ShopClass::getById($shopId, true);
  549. if (empty($shop)) {
  550. util::fail('没有找到门店67');
  551. }
  552. $shopAdmin = $this->shopAdmin;
  553. $admin = $this->admin;
  554. $adminId = $this->adminId ?? 0;
  555. if (getenv('YII_ENV') == 'production') {
  556. if (in_array($adminId, [4]) == false) {
  557. util::fail('开发中');
  558. }
  559. } else {
  560. if (in_array($adminId, [919]) == false) {
  561. util::fail('开发中');
  562. }
  563. }
  564. ShopAdminClass::changeShopAddRelate($shopAdmin, $shop, 1);
  565. $admin->currentGhsShopId = $shopId;
  566. $lsShopId = $shop->lsShopId ?? 0;
  567. $admin->currentShopId = $lsShopId;
  568. $admin->save();
  569. util::complete();
  570. }
  571. //散客门店详情 ssh 20211007
  572. public function actionSkCustom()
  573. {
  574. $skCustomId = $this->shop->skCustomId ?? 0;
  575. $custom = [];
  576. if (!empty($skCustomId)) {
  577. $custom = CustomClass::getById($skCustomId);
  578. $avatar = $custom['avatar'] ?? '';
  579. $custom['avatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  580. }
  581. util::success(['custom' => $custom]);
  582. }
  583. //散客门店设置
  584. public function actionSkCustomSet()
  585. {
  586. $id = Yii::$app->request->get('id', 0);
  587. $custom = CustomClass::getById($id, true);
  588. CustomClass::valid($custom, $this->shopId);
  589. $this->shop->skCustomId = $id;
  590. $this->shop->save();
  591. util::complete('修改成功');
  592. }
  593. //运费模式和运费成本设置 ssh 20211014
  594. public function actionUpdateCgModel()
  595. {
  596. $get = Yii::$app->request->get();
  597. $cgModel = $get['cgModel'] ?? 0;
  598. $cgPerCost = $get['cgPerCost'] ?? 0;
  599. if ($cgModel == 1) {
  600. if (is_numeric($cgPerCost) == false || $cgPerCost < 0) {
  601. util::fail('请输入运费成本');
  602. }
  603. $this->shop->cgPerCost = $cgPerCost;
  604. }
  605. $this->shop->cgModel = $cgModel;
  606. $this->shop->save();
  607. util::complete('修改成功');
  608. }
  609. //地区 ssh 20220606
  610. public function actionRegion()
  611. {
  612. $regionTree = RegionService::tree();
  613. util::success(['region' => $regionTree]);
  614. }
  615. //获取购买须知信息
  616. public function actionPurchaseGuide()
  617. {
  618. $shopId = intval($this->shopId);
  619. if ($shopId <= 0) {
  620. util::fail('门店数据错误');
  621. }
  622. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, shopId, purchaseGuide,purchaseGuideText');
  623. if ($shopExt['purchaseGuide'] > 0) {
  624. $picText = PicTextClass::getById($shopExt['purchaseGuide'], false, 'id, title');
  625. $shopExt['title'] = $picText['title'] ?? '';
  626. }
  627. $shop = $this->shop;
  628. util::success(['shopExt' => $shopExt, 'shop' => $shop]);
  629. }
  630. }