ShopExtController.php 7.1 KB

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