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