ShopExtController.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. if (isset($ext->wcPrintSn2) && !empty($ext->wcPrintSn2)) {
  87. PurchaseOrderClass::updateByCondition(['mainId' => $this->mainId], ['wcPrintNum' => 2]);
  88. }
  89. if (isset($ext->wcPrintSn3) && !empty($ext->wcPrintSn3)) {
  90. PurchaseOrderClass::updateByCondition(['mainId' => $this->mainId], ['wcPrintNum' => 3]);
  91. }
  92. if ($hasFail == 1) {
  93. util::success(['hasFail' => 1], '出现添加失败的情况');
  94. }
  95. util::complete();
  96. }
  97. //添加打印机 ssh 20210712
  98. public function actionAddPrint()
  99. {
  100. $shopAdmin = $this->shopAdmin;
  101. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  102. util::fail('超管才能修改');
  103. }
  104. $hasFail = 0;
  105. $shopId = $this->shopId;
  106. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  107. $get = Yii::$app->request->get();
  108. $printSn = $get['printSn'] ?? '';
  109. $printKey = $get['printKey'] ?? '';
  110. $printLabelSn = $get['printLabelSn'] ?? '';
  111. $printLabelKey = $get['printLabelKey'] ?? '';
  112. $shop = $this->shop;
  113. $default = $shop->default ?? 0;
  114. $shopName = $shop->shopName ?? '';
  115. $sj = $this->sj;
  116. $sjName = $sj->name ?? '';
  117. $name = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  118. if (!empty($printSn) && !empty($printKey)) {
  119. $print = new printUtil($printSn);
  120. $return = $print->addPrint($printKey, $name);
  121. if ($return) {
  122. $ext->printSn = $printSn;
  123. $ext->printKey = $printKey;
  124. $ext->save();
  125. } else {
  126. $hasFail = 1;
  127. }
  128. } else {
  129. $ext->printSn = '';
  130. $ext->printKey = '';
  131. $ext->save();
  132. }
  133. if (!empty($printLabelSn) && !empty($printLabelKey)) {
  134. $labelPrint = new printUtil($printLabelSn);
  135. $return = $labelPrint->addPrint($printLabelKey, $name);
  136. if ($return) {
  137. $ext->printLabelSn = $printLabelSn;
  138. $ext->printLabelKey = $printLabelKey;
  139. $ext->save();
  140. //将打印纸张设置为50X70
  141. $labelPrint->times = 1;
  142. $content = '<SIZE>50,70</SIZE>';
  143. $labelPrint->printLabelMsg($content);
  144. } else {
  145. $hasFail = 1;
  146. }
  147. } else {
  148. $ext->printLabelSn = '';
  149. $ext->printLabelKey = '';
  150. $ext->save();
  151. }
  152. if ($hasFail == 1) {
  153. util::success(['hasFail' => 1], '出现添加失败的情况');
  154. }
  155. util::complete();
  156. }
  157. //获取打印机信息
  158. public function actionGetPrint()
  159. {
  160. $shopId = $this->shopId;
  161. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  162. util::success($ext);
  163. }
  164. //获取云喇叭信息 ssh 20220105
  165. public function actionGetLb()
  166. {
  167. $shopId = $this->shopId;
  168. $ext = ShopExtClass::getByCondition(['shopId' => $shopId]);
  169. util::success($ext);
  170. }
  171. //添加喇叭 ssh 20220105
  172. public function actionAddLb()
  173. {
  174. $shopAdmin = $this->shopAdmin;
  175. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  176. util::fail('超管才能修改');
  177. }
  178. $shopId = $this->shopId;
  179. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  180. $get = Yii::$app->request->get();
  181. $lbSn = $get['lbSn'] ?? '';
  182. $lbVersion = $get['lbVersion'] ?? '';
  183. $ext->lbSn = $lbSn;
  184. $ext->lbVersion = $lbVersion;
  185. $ext->save();
  186. util::complete('设置成功');
  187. }
  188. //小菊启用和停用 ssh 20211210
  189. public function actionReplaceXj()
  190. {
  191. $act = Yii::$app->request->get('act', 'start');
  192. $id = Yii::$app->request->get('id', 0);
  193. $xj = XjClass::getById($id, true);
  194. if (empty($xj)) {
  195. util::fail('没有找到小菊');
  196. }
  197. $status = $act == 'start' ? 1 : 2;
  198. $xj->status = $status;
  199. $xj->save();
  200. util::complete();
  201. }
  202. }