PurchaseOrderController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\PurchaseOrderClass;
  4. use common\components\util;
  5. use Yii;
  6. class PurchaseOrderController extends BaseController
  7. {
  8. //新增采购订单
  9. public function actionCreateOrder()
  10. {
  11. $post = Yii::$app->request->post();
  12. $post['ghsId'] = $this->ghsId;
  13. $post['shopId'] = $this->shopId;
  14. $post['adminId'] = $this->adminId;
  15. $ghsItemInfo = $post['itemInfo']??'';
  16. if(empty($ghsItemInfo)){
  17. util::fail('请选择花材');
  18. }
  19. $ghsItemInfo = json_decode($ghsItemInfo,true);
  20. if(!is_array($ghsItemInfo)){
  21. util::fail('花材格式不正确');
  22. }
  23. //判断花材里的信息
  24. foreach ($ghsItemInfo as $v){
  25. $itemId = $v['itemId']??0;
  26. $itemNumBundle = $v['itemNumBundle']??0;
  27. $itemNumPiece = $v['itemNumPiece']??0;
  28. $itemPrice = $v['itemPrice']??0;
  29. if(!$itemId){
  30. util::fail('花材不存在');
  31. }
  32. if($itemNumPiece <=0 && $itemNumBundle <=0){
  33. util::fail('花材数量不能为0');
  34. }
  35. }
  36. $post['itemInfo'] = $ghsItemInfo;
  37. $order = PurchaseOrderClass::addOrder($post);
  38. if($order){
  39. util::success($order);
  40. }else{
  41. util::fail();
  42. }
  43. }
  44. }