ShopExtController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\product\classes\XjClass;
  4. use biz\shop\classes\ShopExtClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use common\components\printUtil;
  7. use common\components\util;
  8. use Yii;
  9. class ShopExtController extends BaseController
  10. {
  11. public $guestAccess = [];
  12. //修改拓展信息表 ssh 20251005
  13. public function actionModifyExt()
  14. {
  15. $post = Yii::$app->request->post();
  16. $hdArr = [];
  17. $ghsArr = [];
  18. if (isset($post['orderFlow'])) {
  19. $hdArr['orderFlow'] = $post['orderFlow'];
  20. $ghsArr['orderFlow'] = $post['orderFlow'];
  21. }
  22. if (isset($post['thirdSend'])) {
  23. $hdArr['thirdSend'] = $post['thirdSend'];
  24. $ghsArr['thirdSend'] = $post['thirdSend'];
  25. }
  26. if (isset($post['thirdSendFee'])) {
  27. $hdArr['thirdSendFee'] = $post['thirdSendFee'];
  28. $ghsArr['thirdSendFee'] = $post['thirdSendFee'];
  29. }
  30. // 组建零售数据
  31. if (!empty($post['hcMap'])) {
  32. $str = $post['hcMap'];
  33. $map = json_decode($str, true);
  34. if (!empty($map)) {
  35. foreach ($map as $v) {
  36. foreach ($v as $v1) {
  37. if(!is_numeric($v1)){
  38. util::fail('请填写完整');
  39. }
  40. }
  41. }
  42. $hdArr['hcMap'] = json_encode($map);
  43. }
  44. }
  45. if(isset($post['hsFreeKm'])){
  46. $hdArr['hsFreeKm'] = $post['hsFreeKm'];
  47. }
  48. if(isset($post['hsAddFee'])){
  49. $hdArr['hsAddFee'] = $post['hsAddFee'];
  50. }
  51. if(isset($post['hcFreeKm'])){
  52. $hdArr['hcFreeKm'] = $post['hcFreeKm'];
  53. }
  54. // 组建批发数据
  55. if (!empty($post['pfHcMap'])) {
  56. $str = $post['pfHcMap'];
  57. $map = json_decode($str, true);
  58. if (!empty($map)) {
  59. foreach ($map as $v) {
  60. foreach ($v as $v1) {
  61. if(!is_numeric($v1)){
  62. util::fail('请填写完整');
  63. }
  64. }
  65. }
  66. $ghsArr['hcMap'] = json_encode($map);
  67. }
  68. }
  69. if(isset($post['pfHsFreeKm'])){
  70. $ghsArr['hsFreeKm'] = $post['pfHsFreeKm'];
  71. }
  72. if(isset($post['pfHsAddFee'])){
  73. $ghsArr['hsAddFee'] = $post['pfHsAddFee'];
  74. }
  75. if(isset($post['pfHcFreeKm'])){
  76. $ghsArr['hcFreeKm'] = $post['pfHcFreeKm'];
  77. }
  78. if (empty($hdArr) && empty($ghsArr)) {
  79. util::fail('没有需要修改');
  80. }
  81. //批发端更新
  82. $shopId = $this->shopId;
  83. ShopExtClass::updateByCondition(['shopId' => $shopId], $ghsArr);
  84. //零售端更新
  85. $shop = $this->shop;
  86. $lsShopId = $shop->lsShopId;
  87. ShopExtClass::updateByCondition(['shopId' => $lsShopId], $hdArr);
  88. util::complete('修改成功');
  89. }
  90. //设置处理花材、扫码收款和直接收款使用的花材 ssh 20250905
  91. public function actionSetItem()
  92. {
  93. $post = Yii::$app->request->post();
  94. $shopId = $this->shopId;
  95. $shop = $this->shop;
  96. $lsShopId = $shop->lsShopId ?? 0;
  97. $lsExt = null;
  98. //零售端需要同步修改
  99. if (!empty($lsShopId)) {
  100. $lsExt = \bizHd\shop\classes\ShopExtClass::getByCondition(['shopId' => $lsShopId], true);
  101. }
  102. $ext = \bizHd\shop\classes\ShopExtClass::getByCondition(['shopId' => $shopId], true);
  103. $losingItem = $post['losingItem'] ?? 0;
  104. if (!empty($losingItem)) {
  105. $info = ProductClass::getById($losingItem, true);
  106. if ($info->mainId != $this->mainId) {
  107. util::fail('不是你的花材呢,编号099323');
  108. }
  109. $ext->losingItem = $losingItem;
  110. $ext->save();
  111. if (!empty($lsExt)) {
  112. $lsExt->losingItem = $losingItem;
  113. $lsExt->save();
  114. }
  115. }
  116. $zjGatheringItem = $post['zjGatheringItem'] ?? 0;
  117. if (!empty($zjGatheringItem)) {
  118. $info = ProductClass::getById($losingItem, true);
  119. if ($info->mainId != $this->mainId) {
  120. util::fail('不是你的花材呢,编号099324');
  121. }
  122. $ext->zjGatheringItem = $zjGatheringItem;
  123. $ext->save();
  124. if (!empty($lsExt)) {
  125. $lsExt->zjGatheringItem = $zjGatheringItem;
  126. $lsExt->save();
  127. }
  128. }
  129. util::complete('修改成功');
  130. }
  131. public function actionInfo()
  132. {
  133. $ext = $this->shopExt;
  134. $losingItemId = $ext->losingItem ?? 0;
  135. $losingItem = ProductClass::getById($losingItemId, true);
  136. $losingItemName = $losingItem->name ?? '';
  137. $zjGatheringItemId = $ext->zjGatheringItem ?? 0;
  138. $zjGatheringItem = ProductClass::getById($zjGatheringItemId, true);
  139. $zjGatheringItemName = $zjGatheringItem->name ?? '';
  140. //零售 shopExt
  141. $shop = $this->shop;
  142. $lsShopId = $shop->lsShopId;
  143. $shopObj = ShopExtClass::getByCondition(['shopId' => $lsShopId], true, 'id,hcMap,hcFreeKm,hsFreeKm,hsAddFee');
  144. $arr = $shopObj->attributes;
  145. //批发 shopExt
  146. $arr['pfHcMap'] = $ext['hcMap'];
  147. $arr['pfHcFreeKm'] = $ext['hcFreeKm'];
  148. $arr['pfHsFreeKm'] = $ext['hsFreeKm'];
  149. $arr['pfHsAddFee'] = $ext['hsAddFee'];
  150. $arr['losingItemName'] = $losingItemName;
  151. $arr['zjGatheringItemName'] = $zjGatheringItemName;
  152. $arr['main'] = $this->main;
  153. util::success($arr);
  154. }
  155. //添加外采打印机 ssh 20230618
  156. public function actionAddWcPrint()
  157. {
  158. $shopAdmin = $this->shopAdmin;
  159. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  160. util::fail('超管才能修改');
  161. }
  162. $shopId = $this->shopId;
  163. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  164. $get = Yii::$app->request->get();
  165. $wcPrintSn = $get['wcPrintSn'] ?? '';
  166. $wcPrintKey = $get['wcPrintKey'] ?? '';
  167. $wcPrintSn2 = $get['wcPrintSn2'] ?? '';
  168. $wcPrintKey2 = $get['wcPrintKey2'] ?? '';
  169. $wcPrintSn3 = $get['wcPrintSn3'] ?? '';
  170. $wcPrintKey3 = $get['wcPrintKey3'] ?? '';
  171. $shop = $this->shop;
  172. $default = $shop->default ?? 0;
  173. $shopName = $shop->shopName ?? '';
  174. $sj = $this->sj;
  175. $sjName = $sj->name ?? '';
  176. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  177. if (empty($wcPrintSn) && !empty($wcPrintSn2)) {
  178. util::fail('请先填写小票机编号1');
  179. }
  180. if (empty($wcPrintSn2) && !empty($wcPrintSn3)) {
  181. util::fail('请先填写小票机编号2');
  182. }
  183. $hasFail = 0;
  184. if (!empty($wcPrintSn) && !empty($wcPrintKey)) {
  185. $print = new printUtil($wcPrintSn);
  186. $return = $print->addPrint($wcPrintKey, $name);
  187. if ($return) {
  188. $ext->wcPrintSn = $wcPrintSn;
  189. $ext->wcPrintKey = $wcPrintKey;
  190. $ext->save();
  191. } else {
  192. $hasFail = 1;
  193. }
  194. } else {
  195. $ext->wcPrintSn = '';
  196. $ext->wcPrintKey = '';
  197. $ext->save();
  198. }
  199. if (!empty($wcPrintSn2) && !empty($wcPrintKey2)) {
  200. $print = new printUtil($wcPrintSn2);
  201. $return = $print->addPrint($wcPrintKey2, $name);
  202. if ($return) {
  203. $ext->wcPrintSn2 = $wcPrintSn2;
  204. $ext->wcPrintKey2 = $wcPrintKey2;
  205. $ext->save();
  206. } else {
  207. $hasFail = 1;
  208. }
  209. } else {
  210. $ext->wcPrintSn2 = '';
  211. $ext->wcPrintKey2 = '';
  212. $ext->save();
  213. }
  214. if (!empty($wcPrintSn3) && !empty($wcPrintKey3)) {
  215. $print = new printUtil($wcPrintSn3);
  216. $return = $print->addPrint($wcPrintKey3, $name);
  217. if ($return) {
  218. $ext->wcPrintSn3 = $wcPrintSn3;
  219. $ext->wcPrintKey3 = $wcPrintKey3;
  220. $ext->save();
  221. } else {
  222. $hasFail = 1;
  223. }
  224. } else {
  225. $ext->wcPrintSn3 = '';
  226. $ext->wcPrintKey3 = '';
  227. $ext->save();
  228. }
  229. $wcPrintNum = 1;
  230. if (isset($ext->wcPrintSn2) && !empty($ext->wcPrintSn2)) {
  231. $wcPrintNum = 2;
  232. }
  233. if (isset($ext->wcPrintSn3) && !empty($ext->wcPrintSn3)) {
  234. $wcPrintNum = 3;
  235. }
  236. ShopExtClass::updateByCondition(['shopId' => $this->shopId], ['wcPrintNum' => $wcPrintNum]);
  237. if ($hasFail == 1) {
  238. util::success(['hasFail' => 1], '出现添加失败的情况');
  239. }
  240. util::complete();
  241. }
  242. //添加打印机 ssh 20210712
  243. public function actionAddPrint()
  244. {
  245. $shopAdmin = $this->shopAdmin;
  246. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  247. util::fail('超管才能修改');
  248. }
  249. $hasFail = 0;
  250. $shopId = $this->shopId;
  251. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  252. $get = Yii::$app->request->get();
  253. $printSn = $get['printSn'] ?? '';
  254. $printKey = $get['printKey'] ?? '';
  255. $printLabelSn = $get['printLabelSn'] ?? '';
  256. $printLabelKey = $get['printLabelKey'] ?? '';
  257. $wlLabelSn = $get['wlLabelSn'] ?? '';
  258. $wlLabelKey = $get['wlLabelKey'] ?? '';
  259. $shop = $this->shop;
  260. $default = $shop->default ?? 0;
  261. $shopName = $shop->shopName ?? '';
  262. $sj = $this->sj;
  263. $sjName = $sj->name ?? '';
  264. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  265. if (!empty($printSn) && !empty($printKey)) {
  266. $print = new printUtil($printSn);
  267. $return = $print->addPrint($printKey, $name);
  268. if ($return) {
  269. $ext->printSn = $printSn;
  270. $ext->printKey = $printKey;
  271. $ext->save();
  272. } else {
  273. $hasFail = 1;
  274. }
  275. } else {
  276. $ext->printSn = '';
  277. $ext->printKey = '';
  278. $ext->save();
  279. }
  280. if (!empty($printLabelSn) && !empty($printLabelKey)) {
  281. $labelPrint = new printUtil($printLabelSn);
  282. $return = $labelPrint->addPrint($printLabelKey, $name);
  283. if ($return) {
  284. $ext->printLabelSn = $printLabelSn;
  285. $ext->printLabelKey = $printLabelKey;
  286. $ext->save();
  287. //将打印纸张设置为50X40
  288. $labelPrint->times = 1;
  289. $content = '<SIZE>50,40</SIZE>';
  290. $labelPrint->printLabelMsg($content);
  291. } else {
  292. $hasFail = 1;
  293. }
  294. } else {
  295. $ext->printLabelSn = '';
  296. $ext->printLabelKey = '';
  297. $ext->save();
  298. }
  299. if (!empty($wlLabelSn) && !empty($wlLabelKey)) {
  300. $labelPrint = new printUtil($wlLabelSn);
  301. $return = $labelPrint->addPrint($wlLabelKey, $name);
  302. if ($return) {
  303. $ext->wlLabelSn = $wlLabelSn;
  304. $ext->wlLabelKey = $wlLabelKey;
  305. $ext->save();
  306. //将打印纸张设置为60X100
  307. $labelPrint->times = 1;
  308. $content = '<SIZE>60,100</SIZE>';
  309. $labelPrint->printLabelMsg($content);
  310. } else {
  311. $hasFail = 1;
  312. }
  313. } else {
  314. $ext->wlLabelSn = '';
  315. $ext->wlLabelKey = '';
  316. $ext->save();
  317. }
  318. if ($hasFail == 1) {
  319. util::success(['hasFail' => 1], '出现添加失败的情况');
  320. }
  321. util::complete();
  322. }
  323. //获取打印机信息
  324. public function actionGetPrint()
  325. {
  326. $shopId = $this->shopId;
  327. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  328. util::success($ext);
  329. }
  330. //获取云喇叭信息 ssh 20220105
  331. public function actionGetLb()
  332. {
  333. $shopId = $this->shopId;
  334. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  335. util::success($ext);
  336. }
  337. //添加喇叭 ssh 20220105
  338. public function actionAddLb()
  339. {
  340. $shopAdmin = $this->shopAdmin;
  341. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  342. util::fail('超管才能修改');
  343. }
  344. $shopId = $this->shopId;
  345. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  346. $get = Yii::$app->request->get();
  347. $lbSn = $get['lbSn'] ?? '';
  348. $lbVersion = $get['lbVersion'] ?? '';
  349. $ext->lbSn = $lbSn;
  350. $ext->lbVersion = $lbVersion;
  351. $ext->save();
  352. util::complete('设置成功');
  353. }
  354. //小菊启用和停用 ssh 20211210
  355. public function actionReplaceXj()
  356. {
  357. $act = Yii::$app->request->get('act', 'start');
  358. $id = Yii::$app->request->get('id', 0);
  359. $xj = XjClass::getById($id, true);
  360. if (empty($xj)) {
  361. util::fail('没有找到小菊');
  362. }
  363. $status = $act == 'start' ? 1 : 2;
  364. $xj->status = $status;
  365. $xj->save();
  366. util::complete();
  367. }
  368. }