| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace ghs\controllers;
- use bizGhs\order\classes\PurchaseOrderClass;
- use common\components\util;
- use Yii;
- class PurchaseOrderController extends BaseController
- {
- //新增采购订单
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $post['ghsId'] = $this->ghsId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $ghsItemInfo = $post['itemInfo']??'';
- if(empty($ghsItemInfo)){
- util::fail('请选择花材');
- }
- $ghsItemInfo = json_decode($ghsItemInfo,true);
- if(!is_array($ghsItemInfo)){
- util::fail('花材格式不正确');
- }
- //判断花材里的信息
- foreach ($ghsItemInfo as $v){
- $itemId = $v['itemId']??0;
- $itemNumBundle = $v['itemNumBundle']??0;
- $itemNumPiece = $v['itemNumPiece']??0;
- $itemPrice = $v['itemPrice']??0;
- if(!$itemId){
- util::fail('花材不存在');
- }
- if($itemNumPiece <=0 && $itemNumBundle <=0){
- util::fail('花材数量不能为0');
- }
- }
- $post['itemInfo'] = $ghsItemInfo;
- $order = PurchaseOrderClass::addOrder($post);
- if($order){
- util::success($order);
- }else{
- util::fail();
- }
- }
- }
|