ShopExtController.php 13 KB

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