创建订单修改
This commit is contained in:
parent
b103582188
commit
df785c38c9
@ -114,39 +114,37 @@ class OrderController extends BaseApiController
|
||||
public function createOrder()
|
||||
{
|
||||
|
||||
// d(WeChatConfigService::getPayConfigByTerminal(1));
|
||||
$user = User::where('id', $this->request->userId)->find();
|
||||
$cartId = (array)$this->request->post('cart_id', []);
|
||||
$mer_id = (array)$this->request->post('mer_id', 0);
|
||||
$store_id = (array)$this->request->post('store_id', 0);
|
||||
$pay_type = (int)$this->request->post('pay_type');
|
||||
$addressId = (int)$this->request->post('address_id');
|
||||
$auth_code = $this->request->post('auth_code'); //微信支付条码
|
||||
$params = $this->request->post();
|
||||
if ($mer_id <= 0 && $pay_type != 9) {
|
||||
if ($store_id <= 0 && $pay_type != 9) {
|
||||
return $this->fail('自提点不能为空');
|
||||
}
|
||||
if (count($cartId) > 100) {
|
||||
return $this->fail('购物车商品不能超过100个');
|
||||
}
|
||||
|
||||
if ($pay_type == 9 || $pay_type == 17 ||$pay_type==13) {
|
||||
if (empty($this->request->userInfo['merchant'])) {
|
||||
return $this->fail('请先绑定商户');
|
||||
}
|
||||
$mer_id = $this->request->userInfo['merchant']['mer_id'];
|
||||
$params['mer_id'] = $mer_id;
|
||||
}
|
||||
// if ($pay_type == 9 || $pay_type == 17 ||$pay_type==13) {
|
||||
// if (empty($this->request->userInfo['merchant'])) {
|
||||
// return $this->fail('请先绑定商户');
|
||||
// }
|
||||
// $mer_id = $this->request->userInfo['merchant']['mer_id'];
|
||||
// $params['mer_id'] = $mer_id;
|
||||
// }
|
||||
$order = OrderLogic::createOrder($cartId, $addressId, null, $params);
|
||||
if ($order != false) {
|
||||
switch ($pay_type) {
|
||||
case PayEnum::BALANCE_PAY:
|
||||
//余额支付
|
||||
$user = User::where('id', $this->request->userId)->find();
|
||||
$res = OrderLogic::payBalance($user, $order);
|
||||
OrderLogic::payBalance($user, $order);
|
||||
if (OrderLogic::hasError()) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
} else {
|
||||
$res = OrderLogic::paySuccess($order, ['money' => $order['actual']]);
|
||||
OrderLogic::paySuccess($order, ['money' => $order['actual']]);
|
||||
if (OrderLogic::hasError()) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
@ -164,7 +162,6 @@ class OrderController extends BaseApiController
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
return $this->success('', $result);
|
||||
break;
|
||||
case PayEnum::WECHAT_PAY_BARCODE:
|
||||
//微信条码支付
|
||||
$result = PaymentLogic::codepay($auth_code, $order);
|
||||
@ -178,7 +175,6 @@ class OrderController extends BaseApiController
|
||||
return $this->success('用户支付中');
|
||||
}
|
||||
return $this->success('支付成功', ['out_trade_no'=>$result['out_trade_no'],'pay_type'=>PayEnum::WECHAT_PAY_BARCODE,'transaction_id'=>$result['transaction_id']]);
|
||||
break;
|
||||
case PayEnum::ALIPAY_BARCODE:
|
||||
//支付宝条码支付
|
||||
$result = PaymentLogic::ali_auth_code($auth_code, $order);
|
||||
@ -190,11 +186,10 @@ class OrderController extends BaseApiController
|
||||
}
|
||||
$result['create_time'] = $order['create_time'];
|
||||
return $this->success('支付成功', ['out_trade_no'=>$result['out_trade_no'],'pay_type'=>PayEnum::ALIPAY_BARCODE,'transaction_id'=>$result['trade_no']]);
|
||||
break;
|
||||
default:
|
||||
return $this->fail('支付方式错误');
|
||||
}
|
||||
return $this->data(['order_id' => $order->id]);
|
||||
// return $this->data(['order_id' => $order->id]);
|
||||
} else {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use app\common\model\opurchase\Opurchaseinfo;
|
||||
use app\common\model\order\Cart;
|
||||
use app\common\model\retail\Cashierclass;
|
||||
use app\common\model\retail\Cashierinfo;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
@ -51,15 +52,20 @@ class OrderLogic extends BaseLogic
|
||||
self::$total = 0;
|
||||
/** 计算价格 */
|
||||
foreach ($cart_select as $k => $v) {
|
||||
$find = StoreProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price')->find();
|
||||
$find = StoreBranchProduct::where(['id' => $v['goods']])->field('store_name,image,unit,price')->find();
|
||||
if(!$find){
|
||||
continue;
|
||||
}
|
||||
$cart_select[$k]['total'] = bcmul($v['cart_num'], $find['price'], 2);//钱
|
||||
$cart_select[$k]['price'] = $find['price'];
|
||||
$cart_select[$k]['name'] = $find['store_name'];
|
||||
$cart_select[$k]['imgs'] = $find['image'];
|
||||
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
|
||||
$cart_select[$k]['product_id'] = $find['goods'];
|
||||
$cart_select[$k]['old_cart_id'] = implode(',',$cartId);
|
||||
$cart_select[$k]['cart_num'] = $v['cart_num'];
|
||||
//理论上每笔都是拆分了
|
||||
// $cart_select[$k]['name'] = $find['store_name'];
|
||||
// $cart_select[$k]['imgs'] = $find['image'];
|
||||
// $cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name');
|
||||
|
||||
self::$total=bcadd(self::$total, $cart_select[$k]['total'], 2);
|
||||
}
|
||||
$order = [
|
||||
@ -67,9 +73,12 @@ class OrderLogic extends BaseLogic
|
||||
'create_time' => time(),
|
||||
'order_id' => getNewOrderId('PF'),
|
||||
'total_price' => self::$total,//总价
|
||||
'pay_price' => self::$total,//后期可能有降价抵扣
|
||||
'total_num' => count($cart_select),//总数
|
||||
'pay_type' => $params['pay_type'] ?? 0,
|
||||
'cart_id' => implode(',', $cartId),
|
||||
'store_id'=>$params['store_id'],
|
||||
'shipping_type'=>$params['shipping_type']//配送方式 1=快递 ,2=门店自提
|
||||
// 'delivery_msg'=>' 预计48小时发货 '
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
@ -81,7 +90,7 @@ class OrderLogic extends BaseLogic
|
||||
|
||||
/**
|
||||
* 创建新订单
|
||||
* @return Object|bool
|
||||
* @return Object|bool|array
|
||||
*/
|
||||
static public function createOrder($cartId, $addressId, $user = null, $params = [])
|
||||
{
|
||||
@ -89,44 +98,46 @@ class OrderLogic extends BaseLogic
|
||||
if(!$orderInfo){
|
||||
return false;
|
||||
}
|
||||
// `delivery_name`快递名称/送货人姓名',
|
||||
// `delivery_code`'快递公司编码',
|
||||
// `delivery_type` '发货类型',
|
||||
// `delivery_id'快递单号/手机号',
|
||||
$_order = $orderInfo['order'];
|
||||
if($orderInfo['order']['shipping_type'] == 1){
|
||||
$_order['delivery_name'] = $params['delivery_name'];
|
||||
$_order['delivery_id'] = $params['delivery_id'];
|
||||
}
|
||||
$_order['deduction_price'] = 0;
|
||||
$_order['merchant'] = $params['mer_id'];
|
||||
$_order['uid'] = request()->userId;
|
||||
$_order['money'] = 0;
|
||||
$_order['user'] = request()->userId;
|
||||
$_order['account'] = 0;
|
||||
$_order['payinfo'] = '';
|
||||
$_order['type'] = 0;
|
||||
$_order['source'] = 0;
|
||||
$_order['actual'] = $_order['total'];
|
||||
$user = User::where('id',\request()->userId)->find();
|
||||
$_order['real_name'] = $user['real_name'];
|
||||
$_order['mobile'] = $user['mobile'];
|
||||
$_order['pay_type'] = $user['pay_type'];
|
||||
|
||||
if($addressId>0){
|
||||
$address=UserAddress::where(['address_id'=>$addressId,'uid'=>Request()->userId])->find();
|
||||
if($address){
|
||||
$_order['real_name'] = $address['real_name'];
|
||||
$_order['user_phone'] = $address['phone'];
|
||||
$_order['user_address'] = $address['detail'];
|
||||
$_order['address_id'] = $addressId;
|
||||
}
|
||||
}
|
||||
if($params['pay_type']==PayEnum::WECHAT_PAY_BARCODE){
|
||||
$_order['source']=1;
|
||||
}
|
||||
if($params['pay_type']==PayEnum::CASH_PAY){
|
||||
$_order['money']=$_order['total'];
|
||||
}
|
||||
// if($params['pay_type']==PayEnum::WECHAT_PAY_BARCODE){
|
||||
// $_order['source']=1;
|
||||
// }
|
||||
// if($params['pay_type']==PayEnum::CASH_PAY){
|
||||
// $_order['money']=$_order['total'];
|
||||
// }
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = StoreOrder::create($_order);
|
||||
$goods_list = $orderInfo['cart_list'];
|
||||
foreach ($goods_list as $k => $v) {
|
||||
$goods_list[$k]['pid'] = $order->id;
|
||||
$goods_list[$k]['merchant'] = $params['mer_id'];
|
||||
$goods_list[$k]['oid'] = $order->id;
|
||||
$goods_list[$k]['uid'] = request()->userId;
|
||||
$goods_list[$k]['room'] = 0;
|
||||
$goods_list[$k]['discount'] = 0;
|
||||
$goods_list[$k]['warehouse'] = 0;
|
||||
$goods_list[$k]['nums'] = $v['cart_num'];
|
||||
$goods_list[$k]['cart_id'] = implode(',',$cartId);
|
||||
$goods_list[$k]['delivery_id'] = $params['store_id'];//商家id
|
||||
|
||||
}
|
||||
(new StoreOrderCartInfo())->saveAll($goods_list);
|
||||
$where = ['is_pay' => 0, 'is_del' => 0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user