ShopExtController.php 6.5 KB

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