ShopController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  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. //修改门店营业时间
  242. public function actionUpdateOpenTime()
  243. {
  244. $post = Yii::$app->request->post();
  245. $shopId = intval($post['shopId'] ?? $post['id'] ?? 0);
  246. if ($shopId <= 0) {
  247. $shopId = intval($this->shopId);
  248. }
  249. if ($shopId != intval($this->shopId)) {
  250. util::fail('不是您的门店');
  251. }
  252. $shop = ShopClass::getById($shopId);
  253. if (empty($shop)) {
  254. util::fail('门店不存在');
  255. }
  256. \biz\shop\classes\ShopClass::valid($shop, $this->sjId);
  257. \biz\shop\classes\ShopClass::updateOpenTime($shop, $post);
  258. util::complete('修改成功');
  259. }
  260. //添加门店 ssh 2021.1.14
  261. public function actionAdd()
  262. {
  263. $shop = $this->shop;
  264. $default = $shop->default ?? 0;
  265. if ($default == 0) {
  266. util::fail('当前直营分店,请切回总店添加');
  267. }
  268. $adminId = $this->adminId;
  269. $ptSuperAdminId = \biz\admin\classes\AdminClass::getPtSuperAdminId();
  270. if ($adminId != $shop->adminId && $adminId != $ptSuperAdminId) {
  271. util::fail('本店超管才能添加门店');
  272. }
  273. $mainId = $this->mainId;
  274. if (getenv('YII_ENV') == 'production') {
  275. if ($mainId == 42490) {
  276. util::fail('无法建分店,请联系石头');
  277. }
  278. } else {
  279. if ($mainId == 644) {
  280. util::fail('无法建分店,请联系石头');
  281. }
  282. }
  283. $data = Yii::$app->request->post();
  284. $data['sjId'] = $this->sjId;
  285. $data['shopId'] = $this->shopId;
  286. $data['adminId'] = $this->adminId;
  287. if (isset($data['shopName']) == false || empty($data['shopName'])) {
  288. util::fail('请填写门店名称');
  289. }
  290. $sj = $this->sj;
  291. $sjName = $sj->name ?? '';
  292. $ptStyle = $sj->style ?? dict::getDict('ptStyle', 'hd');
  293. $data['ptStyle'] = $ptStyle;
  294. $data['merchantName'] = $sjName;
  295. $data['default'] = 0;
  296. $connection = Yii::$app->db;
  297. $transaction = $connection->beginTransaction();
  298. try {
  299. $mobile = $data['mobile'] ?? 0;
  300. if (stringUtil::isMobile($mobile) == false) {
  301. util::fail('请填写正确手机号');
  302. }
  303. $adminInfo = ['name' => $mobile, 'mobile' => $mobile];
  304. $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
  305. $admin = AdminClass::replaceAdmin($adminInfo, $fromApp);
  306. $adminId = $admin['id'] ?? 0;
  307. $data['adminId'] = $adminId;
  308. ShopClass::addMainShop($data, $this->shop, $this->sj);
  309. $transaction->commit();
  310. util::complete();
  311. } catch (\Exception $exception) {
  312. $transaction->rollBack();
  313. util::fail();
  314. }
  315. }
  316. //PC下载微信和支付宝收款码 ssh 2020.2.29
  317. public function actionGatheringCode()
  318. {
  319. $id = Yii::$app->request->get('id', 0);
  320. $shop = ShopService::getById($id);
  321. ShopClass::valid($shop, $this->sjId);
  322. $gatheringCode = ShopClass::generateGatheringCode($this->sjId, $id);
  323. $file = dirUtil::getImgDir() . $gatheringCode;
  324. if (file_exists($file) == false) {
  325. util::fail('没有找到收款码');
  326. }
  327. if (httpUtil::isMiniProgram()) {
  328. $imgUrl = imgUtil::getPrefix() . $gatheringCode;
  329. util::success(['imgUrl' => $imgUrl]);
  330. }
  331. $fileName = "门店({$id})收款码.jpg";
  332. $contentType = 'image/jpeg';
  333. header("Cache-control: private");
  334. header("Content-type: $contentType"); //设置要下载的文件类型
  335. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  336. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  337. readfile($file);
  338. }
  339. //PC获取小程序的收款码 ssh
  340. public function actionGatheringMiniCode()
  341. {
  342. $id = Yii::$app->request->get('id', 0);
  343. $extend = MerchantExtendService::getBySjId($this->sjId);
  344. if ($extend['miniAuth'] == 0) {
  345. util::fail('您的小程序还没有授权');
  346. }
  347. $shop = ShopService::getById($id);
  348. ShopClass::valid($shop, $this->sjId);
  349. $applyMemberCode = wxUtil::generateGatheringMiniCode($this->sj->attributes, $id);
  350. $file = dirUtil::getImgDir() . $applyMemberCode;
  351. if (file_exists($file) == false) {
  352. util::fail('没有找到注册会员码');
  353. }
  354. if (httpUtil::isMiniProgram()) {
  355. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  356. util::success(['imgUrl' => $imgUrl]);
  357. }
  358. $fileName = "门店({$id})小程序收款码.jpg";
  359. $contentType = 'image/jpeg';
  360. header("Cache-control: private");
  361. header("Content-type: $contentType"); //设置要下载的文件类型
  362. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  363. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  364. readfile($file);
  365. }
  366. //PC下载会员注册码 ssh 2020.2.29
  367. public function actionApplyMemberCode()
  368. {
  369. $id = Yii::$app->request->get('id', 0);
  370. $extend = MerchantExtendService::getBySjId($this->sjId);
  371. if ($extend['miniAuth'] == 0) {
  372. util::fail('您的小程序还没有授权');
  373. }
  374. $shop = ShopService::getById($id);
  375. ShopClass::valid($shop, $this->sjId);
  376. $applyMemberCode = wxUtil::generateMemberCode($this->sj->attributes, $id);
  377. $file = dirUtil::getImgDir() . $applyMemberCode;
  378. if (file_exists($file) == false) {
  379. util::fail('没有找到注册会员码');
  380. }
  381. if (httpUtil::isMiniProgram()) {
  382. $imgUrl = imgUtil::getPrefix() . $applyMemberCode;
  383. util::success(['imgUrl' => $imgUrl]);
  384. }
  385. $fileName = "注册会员码{$id}.jpg";
  386. $contentType = 'image/jpeg';
  387. header("Cache-control: private");
  388. header("Content-type: $contentType"); //设置要下载的文件类型
  389. header("Content-Length:" . filesize($file)); //设置要下载文件的文件大小
  390. header("Content-Disposition: attachment; filename=" . urldecode($fileName)); //设置要下载文件的文件名
  391. readfile($file);
  392. }
  393. //删除门店 ssh 2020.3.1
  394. public function actionDelete()
  395. {
  396. util::fail('禁止操作');
  397. $id = Yii::$app->request->get('id', 0);
  398. $shop = ShopService::getById($id);
  399. ShopClass::valid($shop, $this->sjId);
  400. ShopClass::deleteShop($shop);
  401. util::complete();
  402. }
  403. //获取所有门店lqh 2021.1.31
  404. public function actionAll()
  405. {
  406. $res = ShopClass::getAllShop($this->sjId);
  407. util::success($res);
  408. }
  409. //切换门店 lqh 2021.1.31
  410. public function actionToggleShop()
  411. {
  412. $mainId = $this->mainId;
  413. $adminId = $this->adminId;
  414. //多处要同步修改,关键词 no_allow_toggle_shop
  415. if (getenv('YII_ENV') == 'production') {
  416. //安海恋善不允许切换门店
  417. if (in_array($mainId, [44759, 56314, 56315, 56452])) {
  418. if (in_array($adminId, [54630, 54723])) {
  419. util::fail('专用账号,不允许切换门店');
  420. }
  421. }
  422. //惠雅南城不允许切换门店
  423. if ($mainId == 52 && $adminId == 3539) {
  424. util::fail('收银专用账号,不允许切换门店');
  425. }
  426. //惠雅莞城不允许切换门店
  427. if ($mainId == 1459 && $adminId == 2812) {
  428. util::fail('收银专用账号,不允许切换门店');
  429. }
  430. //淘花里中山店
  431. if ($mainId == 16948 && $adminId == 17908) {
  432. util::fail('收银专用账号,不允许切换门店');
  433. }
  434. //淘花里小榄店
  435. if ($mainId == 72057 && $adminId == 69792) {
  436. util::fail('收银专用账号,不允许切换门店');
  437. }
  438. }
  439. $shopAdmin = $this->shopAdmin;
  440. $switchShop = ShopAdminClass::hasSwitchShopRight($shopAdmin);
  441. if ($switchShop == 0) {
  442. util::fail('不能切换门店');
  443. }
  444. $newShopId = Yii::$app->request->post('shopId', 0);
  445. $deviceId = Yii::$app->request->post('deviceId', '');
  446. $newShop = ShopClass::getById($newShopId, true);
  447. if (empty($newShop)) {
  448. util::fail('没有找到门店66');
  449. }
  450. $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
  451. if ($deviceId != '') {
  452. //设备登录状态更新
  453. $oldDevice = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$this->shopId, 'deviceId'=>$deviceId], true);
  454. if ($oldDevice) {
  455. $oldDevice->status = 0;
  456. $oldDevice->save();
  457. }
  458. $newLoginDevice = \bizGhs\device\classes\GhsDeviceClass::getByCondition(['shopId'=>$newShop, 'deviceId'=>$deviceId], true);
  459. if ($newLoginDevice) {
  460. $newLoginDevice->status = 1;
  461. $newLoginDevice->save();
  462. }
  463. }
  464. util::success($res);
  465. }
  466. //提现信息更新 ssh 2021.3.23
  467. public function actionCashUpdate()
  468. {
  469. $get = Yii::$app->request->get();
  470. $cashAccount = $get['cashAccount'] ?? '';
  471. $cashName = $get['cashName'] ?? '';
  472. $cashBank = $get['cashBank'] ?? '';
  473. if (empty($cashName)) {
  474. util::fail('请填写姓名');
  475. }
  476. if (empty($cashAccount)) {
  477. util::fail('请填写银行卡号');
  478. }
  479. if (empty($cashBank)) {
  480. util::fail('请输入开户行');
  481. }
  482. $shopAdmin = $this->shopAdmin;
  483. $mainId = $shopAdmin->mainId ?? 0;
  484. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  485. util::fail('超管才能操作');
  486. }
  487. MainClass::updateById($mainId, ['cashAccount' => $cashAccount, 'cashName' => $cashName, 'cashBank' => $cashBank]);
  488. $shop = $this->shop;
  489. $sjName = $shop->merchantName ?? '';
  490. $shopName = $shop->shopName ?? '';
  491. //noticeUtil::push("{$sjName}-{$shopName} 修改提现账号,{$cashName} {$cashAccount} {$cashBank}", '15280215347');
  492. util::complete();
  493. }
  494. //获取门店详情 ssh 2021.4.23
  495. public function actionDetail()
  496. {
  497. $shopId = Yii::$app->request->get('shopId');
  498. if (empty($shopId)) {
  499. $shopId = $this->shopId;
  500. }
  501. $shop = ShopClass::getById($shopId, true);
  502. if ($shop->mainId != $this->mainId) {
  503. //这个注释不能打开,因为首店可能修改其它分店信息
  504. //util::fail('无法查看');
  505. }
  506. $shop = $shop->toArray();
  507. $shop['hasMap'] = dict::getDict('hasMap'); //添加 hasMap 属性(字典中的 hasMap)
  508. util::success(['info' => $shop]);
  509. }
  510. //获取平台所有的供货商门店 ssh 20210908
  511. public function actionGetPtGhsShop()
  512. {
  513. $hasSale = Yii::$app->request->get('hasSale', 0);
  514. $name = Yii::$app->request->get('name', '');
  515. $arr = ['ptStyle' => 2, 'live' => 1];
  516. if (!empty($name)) {
  517. $arr['merchantName'] = ['like', $name];
  518. $hasSale = 0;
  519. }
  520. $shopList = ShopClass::getAllByCondition($arr, 'id asc', '*');
  521. $totalSale = 0;
  522. $totalShopNum = 0;
  523. $totalBalance = 0;
  524. if (!empty($shopList)) {
  525. foreach ($shopList as $key => $shop) {
  526. $mainId = $shop['mainId'] ?? 0;
  527. $main = MainClass::getById($mainId, true);
  528. $balance = $main->balance ?? 0;
  529. if (!empty($name) || $hasSale == 0) {
  530. $incomeList = [];
  531. } else {
  532. $respond = StatSaleClass::profile($mainId);
  533. $incomeList = $respond['income'] ?? [];
  534. }
  535. $todaySale = 0;
  536. if (!empty($incomeList)) {
  537. foreach ($incomeList as $item) {
  538. //调拨出库暂时不算到收入里去
  539. if (isset($item['id']) && $item['id'] == 'allot') {
  540. continue;
  541. }
  542. $todaySale = bcadd($todaySale, $item['amount'], 2);
  543. }
  544. }
  545. $shopList[$key]['balance'] = $balance;
  546. $shopList[$key]['todaySale'] = $todaySale;
  547. $count = CustomClass::getCount(['ownMainId' => $mainId]);
  548. $count = $count > 0 ? $count : 0;
  549. $shopList[$key]['shopNum'] = $count;
  550. if ($hasSale == 1 && $todaySale <= 0) {
  551. unset($shopList[$key]);
  552. }
  553. $totalSale = bcadd($totalSale, $todaySale, 2);
  554. $totalSale = floatval($totalSale);
  555. $totalBalance = bcadd($totalBalance, $balance, 2);
  556. $totalBalance = floatval($totalBalance);
  557. $totalShopNum = bcadd($totalShopNum, $count);
  558. }
  559. $shopList = arrayUtil::arraySort($shopList, 'todaySale');
  560. }
  561. util::success(['list' => $shopList, 'totalSale' => $totalSale, 'totalBalance' => $totalBalance, 'totalShopNum' => $totalShopNum]);
  562. }
  563. //切换门店 ssh 20220624
  564. public function actionSwitchGhsShop()
  565. {
  566. $shopId = Yii::$app->request->get('shopId', 0);
  567. $shop = ShopClass::getById($shopId, true);
  568. if (empty($shop)) {
  569. util::fail('没有找到门店67');
  570. }
  571. $shopAdmin = $this->shopAdmin;
  572. $admin = $this->admin;
  573. $adminId = $this->adminId ?? 0;
  574. if (getenv('YII_ENV') == 'production') {
  575. if (in_array($adminId, [4]) == false) {
  576. util::fail('开发中');
  577. }
  578. } else {
  579. if (in_array($adminId, [919]) == false) {
  580. util::fail('开发中');
  581. }
  582. }
  583. ShopAdminClass::changeShopAddRelate($shopAdmin, $shop, 1);
  584. $admin->currentGhsShopId = $shopId;
  585. $lsShopId = $shop->lsShopId ?? 0;
  586. $admin->currentShopId = $lsShopId;
  587. $admin->save();
  588. util::complete();
  589. }
  590. //散客门店详情 ssh 20211007
  591. public function actionSkCustom()
  592. {
  593. $skCustomId = $this->shop->skCustomId ?? 0;
  594. $custom = [];
  595. if (!empty($skCustomId)) {
  596. $custom = CustomClass::getById($skCustomId);
  597. $avatar = $custom['avatar'] ?? '';
  598. $custom['avatar'] = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  599. }
  600. util::success(['custom' => $custom]);
  601. }
  602. //散客门店设置
  603. public function actionSkCustomSet()
  604. {
  605. $id = Yii::$app->request->get('id', 0);
  606. $custom = CustomClass::getById($id, true);
  607. CustomClass::valid($custom, $this->shopId);
  608. $this->shop->skCustomId = $id;
  609. $this->shop->save();
  610. util::complete('修改成功');
  611. }
  612. //运费模式和运费成本设置 ssh 20211014
  613. public function actionUpdateCgModel()
  614. {
  615. $get = Yii::$app->request->get();
  616. $cgModel = $get['cgModel'] ?? 0;
  617. $cgPerCost = $get['cgPerCost'] ?? 0;
  618. if ($cgModel == 1) {
  619. if (is_numeric($cgPerCost) == false || $cgPerCost < 0) {
  620. util::fail('请输入运费成本');
  621. }
  622. $this->shop->cgPerCost = $cgPerCost;
  623. }
  624. $this->shop->cgModel = $cgModel;
  625. $this->shop->save();
  626. util::complete('修改成功');
  627. }
  628. //地区 ssh 20220606
  629. public function actionRegion()
  630. {
  631. $regionTree = RegionService::tree();
  632. util::success(['region' => $regionTree]);
  633. }
  634. //获取购买须知信息
  635. public function actionPurchaseGuide()
  636. {
  637. $shopId = intval($this->shopId);
  638. if ($shopId <= 0) {
  639. util::fail('门店数据错误');
  640. }
  641. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, shopId, purchaseGuide,purchaseGuideText');
  642. if ($shopExt['purchaseGuide'] > 0) {
  643. $picText = PicTextClass::getById($shopExt['purchaseGuide'], false, 'id, title');
  644. $shopExt['title'] = $picText['title'] ?? '';
  645. }
  646. $shop = $this->shop;
  647. util::success(['shopExt' => $shopExt, 'shop' => $shop]);
  648. }
  649. }