PurchaseOrderController.php 5.0 KB

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