erp/app/api/controller/order/PurchaseOrderController.php
2024-04-26 11:26:12 +08:00

50 lines
1.5 KiB
PHP

<?php
namespace app\api\controller\order;
use app\admin\logic\order\CartLogic;
use app\api\logic\order\OrderLogic;
use app\api\controller\BaseApiController;
use app\common\logic\order\RetailOrderLogic;
use app\common\enum\PayEnum;
use app\common\model\order\Cart;
use app\common\model\user\User;
/**
* 购货单控制器
*/
class PurchaseOrderController extends BaseApiController
{
public function checkOrder(){
$params=$this->request->get();
$params['store_id']=1;
$res=OrderLogic::cartIdByPurchaseOrderInfo($params);
return $this->data($res);
}
/**
* @notes 创建购货订单
*/
public function createOrder(){
$user=User::where('id',$this->request->userId)->find();
$cartId = (Array)$this->request->post('cart_id', []);
$addressId = (int)$this->request->post('address_id');
$pay_type = (int)$this->request->post('pay_type');
$auth_code = $this->request->post('auth_code'); //微信支付条码
$params=$this->request->post();
$order=OrderLogic::createOrder($cartId,$addressId,null,$params);
if(is_object($order)){
if($pay_type==PayEnum::BALANCE_PAY){
$user=User::where('id',$this->request->userId)->find();
RetailOrderLogic::payBalance($user,$order);
return $this->success('支付成功');
}
return $this->data(['order_id'=>$order->id]);
}else{
return $this->fail(OrderLogic::getError());
}
}
}