PurchaseOrderController.php 6.1 KB

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