ShopController.php 26 KB

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