PurchaseOrderController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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\product\classes\ProductClass;
  7. use common\components\util;
  8. use Yii;
  9. class PurchaseOrderController extends BaseController
  10. {
  11. //新增采购订单
  12. public function actionCreateOrder()
  13. {
  14. $post = Yii::$app->request->post();
  15. $post['sjId'] = $this->sjId;
  16. $post['shopId'] = $this->shopId;
  17. $post['adminId'] = $this->adminId;
  18. $shop = $this->shop;
  19. $default = $shop->default ?? 0;
  20. if ($default != 1) {
  21. util::fail('请在首店发起采购');
  22. }
  23. $ghsItemInfo = $post['itemInfo'] ?? '';
  24. if (empty($ghsItemInfo)) {
  25. util::fail('请选择花材');
  26. }
  27. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  28. if (!is_array($ghsItemInfo)) {
  29. util::fail('花材格式不正确');
  30. }
  31. //合并
  32. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  33. //判断花材格式,是否属于当前门店
  34. ProductClass::valid($ghsItemInfo, $this->shopId);
  35. //获取供应商信息
  36. $ghsId = $post['ghsId'];
  37. if (empty($ghsId)) {
  38. util::fail("请选择供应商");
  39. }
  40. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  41. GhsClass::valid($ghsInfo, $this->shopId);
  42. $post['ghsInfo'] = json_encode($ghsInfo);
  43. //判断花材里的信息
  44. //判定重量
  45. $weight = 0;
  46. foreach ($ghsItemInfo as $v) {
  47. $bigNum = $v['bigNum'] ?? 0;
  48. $productId = $v['productId'] ?? 0;
  49. $smallNum = $v['smallNum'] ?? 0;
  50. if (!isset($v['itemPrice'])) {
  51. util::fail('采购价格不能为空');
  52. }
  53. if (!$productId) {
  54. util::fail('花材不存在');
  55. }
  56. if ($bigNum <= 0 && $smallNum <= 0) {
  57. util::fail('花材数量不能为0');
  58. }
  59. $currentWeight = $v['weight'] ?? 0;
  60. $weight = bcadd($weight, $currentWeight, 2);
  61. }
  62. if ($weight <= 0) {
  63. util::fail('请填写重量');
  64. }
  65. $post['itemInfo'] = $ghsItemInfo;
  66. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  67. $order = PurchaseOrderClass::addOrder($post);
  68. util::success($order);
  69. util::fail();
  70. }
  71. //订单列表
  72. public function actionList()
  73. {
  74. $get = Yii::$app->request->get();
  75. $orderStatus = $get['status'] ?? '';
  76. if ($orderStatus) {
  77. $where['status'] = $orderStatus;
  78. }
  79. $where['sjId'] = $this->sjId;
  80. $where['shopId'] = $this->shopId;
  81. $data = PurchaseOrderClass::getOrderList($where);
  82. //状态统计
  83. $statData = PurchaseOrderClass::statNum($this->shopId);
  84. $data = array_merge($data, $statData);
  85. util::success($data);
  86. }
  87. //订单详情
  88. public function actionDetail()
  89. {
  90. $orderSn = Yii::$app->request->get('orderSn', '');
  91. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  92. util::success($orderData);
  93. }
  94. //修改备注
  95. public function actionUpdateRemark()
  96. {
  97. $remark = Yii::$app->request->post('remark', '');
  98. $id = Yii::$app->request->post('id', '');
  99. $cg = PurchaseOrderClass::getById($id, true);
  100. if (empty($cg)) {
  101. util::fail('没有找到订单');
  102. }
  103. if ($cg->shopId != $this->shopId) {
  104. util::fail('没有权限修改');
  105. }
  106. $cg->remark = $remark;
  107. $cg->save();
  108. util::complete('修改成功');
  109. }
  110. }