ShopExtController.php 12 KB

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