ShopExtController.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 common\components\printUtil;
  7. use common\components\util;
  8. use Yii;
  9. class ShopExtController extends BaseController
  10. {
  11. public $guestAccess = [];
  12. //添加外采打印机 ssh 20230618
  13. public function actionAddWcPrint()
  14. {
  15. $shopAdmin = $this->shopAdmin;
  16. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  17. util::fail('超管才能修改');
  18. }
  19. $shopId = $this->shopId;
  20. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  21. $get = Yii::$app->request->get();
  22. $wcPrintSn = $get['wcPrintSn'] ?? '';
  23. $wcPrintKey = $get['wcPrintKey'] ?? '';
  24. $wcPrintSn2 = $get['wcPrintSn2'] ?? '';
  25. $wcPrintKey2 = $get['wcPrintKey2'] ?? '';
  26. $wcPrintSn3 = $get['wcPrintSn3'] ?? '';
  27. $wcPrintKey3 = $get['wcPrintKey3'] ?? '';
  28. $shop = $this->shop;
  29. $default = $shop->default ?? 0;
  30. $shopName = $shop->shopName ?? '';
  31. $sj = $this->sj;
  32. $sjName = $sj->name ?? '';
  33. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  34. if (empty($wcPrintSn) && !empty($wcPrintSn2)) {
  35. util::fail('请先填写小票机编号1');
  36. }
  37. if (empty($wcPrintSn2) && !empty($wcPrintSn3)) {
  38. util::fail('请先填写小票机编号2');
  39. }
  40. $hasFail = 0;
  41. if (!empty($wcPrintSn) && !empty($wcPrintKey)) {
  42. $print = new printUtil($wcPrintSn);
  43. $return = $print->addPrint($wcPrintKey, $name);
  44. if ($return) {
  45. $ext->wcPrintSn = $wcPrintSn;
  46. $ext->wcPrintKey = $wcPrintKey;
  47. $ext->save();
  48. } else {
  49. $hasFail = 1;
  50. }
  51. } else {
  52. $ext->wcPrintSn = '';
  53. $ext->wcPrintKey = '';
  54. $ext->save();
  55. }
  56. if (!empty($wcPrintSn2) && !empty($wcPrintKey2)) {
  57. $print = new printUtil($wcPrintSn2);
  58. $return = $print->addPrint($wcPrintKey2, $name);
  59. if ($return) {
  60. $ext->wcPrintSn2 = $wcPrintSn2;
  61. $ext->wcPrintKey2 = $wcPrintKey2;
  62. $ext->save();
  63. } else {
  64. $hasFail = 1;
  65. }
  66. } else {
  67. $ext->wcPrintSn2 = '';
  68. $ext->wcPrintKey2 = '';
  69. $ext->save();
  70. }
  71. if (!empty($wcPrintSn3) && !empty($wcPrintKey3)) {
  72. $print = new printUtil($wcPrintSn3);
  73. $return = $print->addPrint($wcPrintKey3, $name);
  74. if ($return) {
  75. $ext->wcPrintSn3 = $wcPrintSn3;
  76. $ext->wcPrintKey3 = $wcPrintKey3;
  77. $ext->save();
  78. } else {
  79. $hasFail = 1;
  80. }
  81. } else {
  82. $ext->wcPrintSn3 = '';
  83. $ext->wcPrintKey3 = '';
  84. $ext->save();
  85. }
  86. $wcPrintNum = 1;
  87. if (isset($ext->wcPrintSn2) && !empty($ext->wcPrintSn2)) {
  88. $wcPrintNum = 2;
  89. }
  90. if (isset($ext->wcPrintSn3) && !empty($ext->wcPrintSn3)) {
  91. $wcPrintNum = 3;
  92. }
  93. ShopExtClass::updateByCondition(['shopId' => $this->shopId], ['wcPrintNum' => $wcPrintNum]);
  94. if ($hasFail == 1) {
  95. util::success(['hasFail' => 1], '出现添加失败的情况');
  96. }
  97. util::complete();
  98. }
  99. //添加打印机 ssh 20210712
  100. public function actionAddPrint()
  101. {
  102. $shopAdmin = $this->shopAdmin;
  103. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  104. util::fail('超管才能修改');
  105. }
  106. $hasFail = 0;
  107. $shopId = $this->shopId;
  108. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  109. $get = Yii::$app->request->get();
  110. $printSn = $get['printSn'] ?? '';
  111. $printKey = $get['printKey'] ?? '';
  112. $printLabelSn = $get['printLabelSn'] ?? '';
  113. $printLabelKey = $get['printLabelKey'] ?? '';
  114. $wlLabelSn = $get['wlLabelSn'] ?? '';
  115. $wlLabelKey = $get['wlLabelKey'] ?? '';
  116. $shop = $this->shop;
  117. $default = $shop->default ?? 0;
  118. $shopName = $shop->shopName ?? '';
  119. $sj = $this->sj;
  120. $sjName = $sj->name ?? '';
  121. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  122. if (!empty($printSn) && !empty($printKey)) {
  123. $print = new printUtil($printSn);
  124. $return = $print->addPrint($printKey, $name);
  125. if ($return) {
  126. $ext->printSn = $printSn;
  127. $ext->printKey = $printKey;
  128. $ext->save();
  129. } else {
  130. $hasFail = 1;
  131. }
  132. } else {
  133. $ext->printSn = '';
  134. $ext->printKey = '';
  135. $ext->save();
  136. }
  137. if (!empty($printLabelSn) && !empty($printLabelKey)) {
  138. $labelPrint = new printUtil($printLabelSn);
  139. $return = $labelPrint->addPrint($printLabelKey, $name);
  140. if ($return) {
  141. $ext->printLabelSn = $printLabelSn;
  142. $ext->printLabelKey = $printLabelKey;
  143. $ext->save();
  144. //将打印纸张设置为50X40
  145. $labelPrint->times = 1;
  146. $content = '<SIZE>50,40</SIZE>';
  147. $labelPrint->printLabelMsg($content);
  148. } else {
  149. $hasFail = 1;
  150. }
  151. } else {
  152. $ext->printLabelSn = '';
  153. $ext->printLabelKey = '';
  154. $ext->save();
  155. }
  156. if (!empty($wlLabelSn) && !empty($wlLabelKey)) {
  157. $labelPrint = new printUtil($wlLabelSn);
  158. $return = $labelPrint->addPrint($wlLabelKey, $name);
  159. if ($return) {
  160. $ext->wlLabelSn = $wlLabelSn;
  161. $ext->wlLabelKey = $wlLabelKey;
  162. $ext->save();
  163. //将打印纸张设置为60X100
  164. $labelPrint->times = 1;
  165. $content = '<SIZE>60,100</SIZE>';
  166. $labelPrint->printLabelMsg($content);
  167. } else {
  168. $hasFail = 1;
  169. }
  170. } else {
  171. $ext->wlLabelSn = '';
  172. $ext->wlLabelKey = '';
  173. $ext->save();
  174. }
  175. if ($hasFail == 1) {
  176. util::success(['hasFail' => 1], '出现添加失败的情况');
  177. }
  178. util::complete();
  179. }
  180. //获取打印机信息
  181. public function actionGetPrint()
  182. {
  183. $shopId = $this->shopId;
  184. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  185. util::success($ext);
  186. }
  187. //获取云喇叭信息 ssh 20220105
  188. public function actionGetLb()
  189. {
  190. $shopId = $this->shopId;
  191. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  192. util::success($ext);
  193. }
  194. //添加喇叭 ssh 20220105
  195. public function actionAddLb()
  196. {
  197. $shopAdmin = $this->shopAdmin;
  198. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  199. util::fail('超管才能修改');
  200. }
  201. $shopId = $this->shopId;
  202. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  203. $get = Yii::$app->request->get();
  204. $lbSn = $get['lbSn'] ?? '';
  205. $lbVersion = $get['lbVersion'] ?? '';
  206. $ext->lbSn = $lbSn;
  207. $ext->lbVersion = $lbVersion;
  208. $ext->save();
  209. util::complete('设置成功');
  210. }
  211. //小菊启用和停用 ssh 20211210
  212. public function actionReplaceXj()
  213. {
  214. $act = Yii::$app->request->get('act', 'start');
  215. $id = Yii::$app->request->get('id', 0);
  216. $xj = XjClass::getById($id, true);
  217. if (empty($xj)) {
  218. util::fail('没有找到小菊');
  219. }
  220. $status = $act == 'start' ? 1 : 2;
  221. $xj->status = $status;
  222. $xj->save();
  223. util::complete();
  224. }
  225. }