PurchaseOrderController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\PurchaseOrderClass;
  4. use bizGhs\order\classes\PurchaseOrderItemClass;
  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['merchantId'] = $this->merchantId;
  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,itemId:0,num:1,smallNum:0}]
  22. if(!is_array($ghsItemInfo)){
  23. util::fail('花材格式不正确');
  24. }
  25. //判断花材格式,是否属于当前门店
  26. $productIds = array_column($ghsItemInfo,'productId');
  27. ProductClass::valid($productIds,$this->shopId);
  28. //判断花材里的信息
  29. foreach ($ghsItemInfo as $v){
  30. $itemId = $v['itemId']??0;
  31. $num = $v['num']??0;
  32. $productId = $v['productId']??0;
  33. $smallNum = $v['smallNum']??0;
  34. if(!isset($v['itemPrice'])){
  35. util::fail('采购价格不能为空');
  36. }
  37. if(!$itemId || !$productId){
  38. util::fail('花材不存在');
  39. }
  40. if($num <=0 && $smallNum <=0){
  41. util::fail('花材数量不能为0');
  42. }
  43. }
  44. $post['itemInfo'] = $ghsItemInfo;
  45. $order = PurchaseOrderClass::addOrder($post);
  46. if($order){
  47. util::success($order);
  48. }else{
  49. util::fail();
  50. }
  51. }
  52. //订单列表
  53. public function actionList()
  54. {
  55. $get = Yii::$app->request->get();
  56. $orderStatus = $get['orderStatus']??'';
  57. if($orderStatus){
  58. $where['orderStatus'] = $orderStatus;
  59. }
  60. $where['merchantId'] = $this->merchantId;
  61. $where['shopId'] = $this->shopId;
  62. $data = PurchaseOrderClass::getOrderList($where);
  63. util::success($data);
  64. }
  65. //订单详情
  66. public function actionDetail()
  67. {
  68. $orderSn = Yii::$app->request->get('orderSn','');
  69. $orderData = PurchaseOrderClass::getOrderDetail($orderSn,$this->shopId);
  70. util::success($orderData);
  71. }
  72. }