PurchaseOrderController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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,itemPrice:1,bigNum: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. $bigNum = $v['bigNum']??0;
  31. $productId = $v['productId']??0;
  32. $smallNum = $v['smallNum']??0;
  33. if(!isset($v['itemPrice'])){
  34. util::fail('采购价格不能为空');
  35. }
  36. if(!$productId){
  37. util::fail('花材不存在');
  38. }
  39. if($bigNum <=0 && $smallNum <=0){
  40. util::fail('花材数量不能为0');
  41. }
  42. }
  43. $post['itemInfo'] = $ghsItemInfo;
  44. $order = PurchaseOrderClass::addOrder($post);
  45. if($order){
  46. util::success($order);
  47. }else{
  48. util::fail();
  49. }
  50. }
  51. //订单列表
  52. public function actionList()
  53. {
  54. $get = Yii::$app->request->get();
  55. $orderStatus = $get['orderStatus']??'';
  56. if($orderStatus){
  57. $where['orderStatus'] = $orderStatus;
  58. }
  59. $where['merchantId'] = $this->merchantId;
  60. $where['shopId'] = $this->shopId;
  61. $data = PurchaseOrderClass::getOrderList($where);
  62. util::success($data);
  63. }
  64. //订单详情
  65. public function actionDetail()
  66. {
  67. $orderSn = Yii::$app->request->get('orderSn','');
  68. $orderData = PurchaseOrderClass::getOrderDetail($orderSn,$this->shopId);
  69. util::success($orderData);
  70. }
  71. }