PurchaseOrderController.php 4.9 KB

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