ShopExtController.php 13 KB

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