PurchaseOrderController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. foreach ($ghsItemInfo as $v) {
  39. $bigNum = $v['bigNum'] ?? 0;
  40. $productId = $v['productId'] ?? 0;
  41. $smallNum = $v['smallNum'] ?? 0;
  42. if (!isset($v['itemPrice'])) {
  43. util::fail('采购价格不能为空');
  44. }
  45. if (!$productId) {
  46. util::fail('花材不存在');
  47. }
  48. if ($bigNum <= 0 && $smallNum <= 0) {
  49. util::fail('花材数量不能为0');
  50. }
  51. }
  52. $post['itemInfo'] = $ghsItemInfo;
  53. $order = PurchaseOrderClass::addOrder($post);
  54. if ($order) {
  55. util::success($order);
  56. }
  57. util::fail();
  58. }
  59. //订单列表
  60. public function actionList()
  61. {
  62. $get = Yii::$app->request->get();
  63. $orderStatus = $get['status'] ?? '';
  64. if ($orderStatus) {
  65. $where['status'] = $orderStatus;
  66. }
  67. $where['sjId'] = $this->sjId;
  68. $where['shopId'] = $this->shopId;
  69. $data = PurchaseOrderClass::getOrderList($where);
  70. //状态统计
  71. $statData = PurchaseOrderClass::statNum($this->shopId);
  72. $data = array_merge($data, $statData);
  73. util::success($data);
  74. }
  75. //订单详情
  76. public function actionDetail()
  77. {
  78. $orderSn = Yii::$app->request->get('orderSn', '');
  79. $orderData = PurchaseOrderClass::getOrderDetail($orderSn, $this->shopId);
  80. util::success($orderData);
  81. }
  82. }