| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace ghs\controllers;
- use bizGhs\order\classes\PurchaseOrderClass;
- use bizGhs\order\classes\PurchaseOrderItemClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\util;
- use Yii;
- class PurchaseOrderController extends BaseController
- {
- //新增采购订单
- public function actionCreateOrder()
- {
- $post = Yii::$app->request->post();
- $post['merchantId'] = $this->merchantId;
- $post['shopId'] = $this->shopId;
- $post['adminId'] = $this->adminId;
- $ghsItemInfo = $post['itemInfo']??'';
- if(empty($ghsItemInfo)){
- util::fail('请选择花材');
- }
- $ghsItemInfo = json_decode($ghsItemInfo,true); // [{productId:0,itemId:0,num:1,smallNum:0}]
- if(!is_array($ghsItemInfo)){
- util::fail('花材格式不正确');
- }
- //判断花材格式,是否属于当前门店
- $productIds = array_column($ghsItemInfo,'productId');
- ProductClass::valid($productIds,$this->shopId);
- //判断花材里的信息
- foreach ($ghsItemInfo as $v){
- $itemId = $v['itemId']??0;
- $num = $v['num']??0;
- $productId = $v['productId']??0;
- $smallNum = $v['smallNum']??0;
- if(!isset($v['itemPrice'])){
- util::fail('采购价格不能为空');
- }
- if(!$itemId || !$productId){
- util::fail('花材不存在');
- }
- if($num <=0 && $smallNum <=0){
- util::fail('花材数量不能为0');
- }
- }
- $post['itemInfo'] = $ghsItemInfo;
- $order = PurchaseOrderClass::addOrder($post);
- if($order){
- util::success($order);
- }else{
- util::fail();
- }
- }
- //订单列表
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $orderStatus = $get['orderStatus']??'';
- if($orderStatus){
- $where['orderStatus'] = $orderStatus;
- }
- $where['merchantId'] = $this->merchantId;
- $where['shopId'] = $this->shopId;
- $data = PurchaseOrderClass::getOrderList($where);
- util::success($data);
- }
- //订单详情
- public function actionDetail()
- {
- $orderSn = Yii::$app->request->get('orderSn','');
- $orderData = PurchaseOrderClass::getOrderDetail($orderSn,$this->shopId);
- util::success($orderData);
- }
- }
|