PurchaseOrderController.php 2.3 KB

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