PurchaseOrderController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use bizGhs\order\classes\PurchaseOrderClass;
  5. use bizGhs\product\classes\ProductClass;
  6. use common\components\util;
  7. use Yii;
  8. class PurchaseOrderController extends BaseController
  9. {
  10. //新增采购订单
  11. public function actionCreateOrder()
  12. {
  13. $post = Yii::$app->request->post();
  14. $post['sjId'] = $this->sjId;
  15. $post['shopId'] = $this->shopId;
  16. $post['adminId'] = $this->adminId;
  17. $ghsItemInfo = $post['itemInfo'] ?? '';
  18. if (empty($ghsItemInfo)) {
  19. util::fail('请选择花材');
  20. }
  21. $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
  22. if (!is_array($ghsItemInfo)) {
  23. util::fail('花材格式不正确');
  24. }
  25. //合并
  26. $ghsItemInfo = PurchaseOrderClass::mergeItemInfo($ghsItemInfo);
  27. //判断花材格式,是否属于当前门店
  28. ProductClass::valid($ghsItemInfo, $this->shopId);
  29. //获取供应商信息
  30. $ghsId = $post['ghsId'];
  31. if (empty($ghsId)) {
  32. util::fail("请选择供应商");
  33. }
  34. $ghsInfo = GhsClass::getGhsInfo($ghsId);
  35. GhsClass::valid($ghsInfo, $this->shopId);
  36. $post['ghsInfo'] = json_encode($ghsInfo);
  37. //判断花材里的信息
  38. //判定重量
  39. $weight = 0;
  40. foreach ($ghsItemInfo as $v) {
  41. $bigNum = $v['bigNum'] ?? 0;
  42. $productId = $v['productId'] ?? 0;
  43. $smallNum = $v['smallNum'] ?? 0;
  44. if (!isset($v['itemPrice'])) {
  45. util::fail('采购价格不能为空');
  46. }
  47. if (!$productId) {
  48. util::fail('花材不存在');
  49. }
  50. if ($bigNum <= 0 && $smallNum <= 0) {
  51. util::fail('花材数量不能为0');
  52. }
  53. if (getenv('YII_ENV', 'local') == 'production') {
  54. $currentWeight = $v['weight'] ?? 0;
  55. } else {
  56. $currentWeight = 0.6;
  57. }
  58. $weight = bcadd($weight, $currentWeight, 2);
  59. }
  60. if ($weight <= 0) {
  61. util::fail('请填写重量');
  62. }
  63. $post['itemInfo'] = $ghsItemInfo;
  64. $post['debt'] = PurchaseOrderClass::DEBT_YES;
  65. $order = PurchaseOrderClass::addOrder($post);
  66. if ($order) {
  67. util::success($order);
  68. }
  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. }