PurchaseOrderController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\admin\classes\AdminRoleClass;
  4. use biz\ghs\classes\GhsClass;
  5. use bizGhs\order\classes\PurchaseOrderClass;
  6. use bizGhs\order\classes\PurchaseOrderItemClass;
  7. use bizGhs\product\classes\ProductClass;
  8. use common\components\printUtil;
  9. use common\components\util;
  10. use Yii;
  11. class PurchaseOrderController extends BaseController
  12. {
  13. //打印全部 ssh 20220602
  14. public function actionPrintAll()
  15. {
  16. $get = Yii::$app->request->get();
  17. $orderSn = $get['orderSn'] ?? 0;
  18. $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
  19. if (empty($itemList)) {
  20. util::fail('没有商品');
  21. }
  22. $ext = $this->shopExt;
  23. $printLabelSn = $ext->printLabelSn ?? '';
  24. if(empty($printLabelSn)){
  25. util::fail('请设置条码打印机');
  26. }
  27. $p = new printUtil($printLabelSn);
  28. foreach ($itemList as $item) {
  29. $name = $item->name ?? '';
  30. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  31. if (empty($num)) {
  32. util::fail('没有花材数量');
  33. }
  34. $ptItemId = $item->itemId ?? '';
  35. $p->times = $num;
  36. $content = '<TEXT x="50" y="20" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  37. $content .= '<BC128 x="50" y="90" h="80" s="1" r="0" n="2" w="2">' . $ptItemId . '</BC128>';
  38. $p->printLabelMsg($content);
  39. }
  40. util::complete();
  41. }
  42. //打印全部 ssh 20220
  43. public function actionPrintItem()
  44. {
  45. $get = Yii::$app->request->get();
  46. $id = $get['id'] ?? 0;
  47. $item = PurchaseOrderItemClass::getById($id, true);
  48. if (empty($item)) {
  49. util::fail('没有找到花材');
  50. }
  51. $name = $item->name ?? '';
  52. $num = !empty($item->itemNum) ? floatval($item->itemNum) : 0;
  53. if (empty($num)) {
  54. util::fail('没有花材数量');
  55. }
  56. $ext = $this->shopExt;
  57. $printLabelSn = $ext->printLabelSn ?? '';
  58. if(empty($printLabelSn)){
  59. util::fail('请设置条码打印机');
  60. }
  61. $p = new printUtil($printLabelSn);
  62. $ptItemId = $item->itemId ?? '';
  63. $p->times = $num;
  64. $content = '<TEXT x="50" y="20" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  65. $content .= '<BC128 x="50" y="90" h="80" s="1" r="0" n="2" w="2">' . $ptItemId . '</BC128>';
  66. $p->printLabelMsg($content);
  67. util::complete();
  68. }
  69. //新增采购订单
  70. public function actionCreateOrder()
  71. {
  72. $post = Yii::$app->request->post();
  73. $post['sjId'] = $this->sjId;
  74. $post['shopId'] = $this->shopId;
  75. $post['adminId'] = $this->adminId;
  76. $post['mainId'] = $this->mainId;
  77. $shopAdmin = $this->shopAdmin;
  78. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  79. util::fail('超管才能修改');
  80. }
  81. // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  82. $ghsItemInfo = $post['itemInfo'] ?? '';
  83. if (empty($ghsItemInfo)) {
  84. util::fail('请选择花材');
  85. }
  86. $ghsItemInfo = json_decode($ghsItemInfo, true);
  87. if (!is_array($ghsItemInfo)) {
  88. util::fail('花材格式不正确');
  89. }
  90. //合并
  91. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  92. //判断花材格式,是否属于当前门店
  93. ProductClass::valid($ghsItemInfo, $this->mainId);
  94. //获取供应商信息
  95. $ghsId = $post['ghsId'];
  96. if (empty($ghsId)) {
  97. util::fail("请选择供应商");
  98. }
  99. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  100. GhsClass::valid($ghsInfo, $this->shopId);
  101. $post['ghsInfo'] = json_encode($ghsInfo);
  102. $post['ghsName'] = $ghsInfo['name'] ?? '';
  103. //判断花材里的信息
  104. foreach ($ghsItemInfo as $v) {
  105. $bigNum = $v['bigNum'] ?? 0;
  106. $productId = $v['productId'] ?? 0;
  107. $smallNum = $v['smallNum'] ?? 0;
  108. if (!isset($v['itemPrice'])) {
  109. util::fail('采购价格不能为空');
  110. }
  111. if (!$productId) {
  112. util::fail('花材不存在');
  113. }
  114. if ($bigNum <= 0 && $smallNum <= 0) {
  115. util::fail('花材数量不能为0');
  116. }
  117. }
  118. $post['itemInfo'] = $ghsItemInfo;
  119. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  120. $order = PurchaseOrderClass::addOrder($post);
  121. util::success($order);
  122. util::fail();
  123. }
  124. //订单列表
  125. public function actionList()
  126. {
  127. $get = Yii::$app->request->get();
  128. $orderStatus = $get['status'] ?? '';
  129. if ($orderStatus) {
  130. $where['status'] = $orderStatus;
  131. }
  132. $ghsId = $get['ghsId'] ?? 0;
  133. if (!empty($ghsId)) {
  134. $where['ghsId'] = $ghsId;
  135. }
  136. $where['sjId'] = $this->sjId;
  137. $where['shopId'] = $this->shopId;
  138. $data = PurchaseOrderClass::getOrderList($where);
  139. //状态统计
  140. $statData = PurchaseOrderClass::statNum($this->shopId);
  141. $data = array_merge($data, $statData);
  142. util::success($data);
  143. }
  144. //订单详情
  145. public function actionDetail()
  146. {
  147. $orderSn = Yii::$app->request->get('orderSn', '');
  148. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  149. util::success($orderData);
  150. }
  151. //修改备注
  152. public function actionUpdateRemark()
  153. {
  154. $remark = Yii::$app->request->post('remark', '');
  155. $id = Yii::$app->request->post('id', '');
  156. $cg = PurchaseOrderClass::getById($id, true);
  157. if (empty($cg)) {
  158. util::fail('没有找到订单');
  159. }
  160. if ($cg->shopId != $this->shopId) {
  161. util::fail('没有权限修改');
  162. }
  163. $cg->remark = $remark;
  164. $cg->save();
  165. util::complete('修改成功');
  166. }
  167. }