添加生成支付订单功能并优化订单逻辑
- 在 BeforehandOrderController 中新增 generateOrder 方法,用于生成支付订单 - 在 BeforehandOrderLogic 中实现 generateOrder 方法,处理订单生成逻辑 - 优化 StoreOrderLogic 中的退款逻辑,改进数据库更新操作
This commit is contained in:
parent
2a784c783c
commit
ef47fe0147
@ -59,6 +59,14 @@ class BeforehandOrderController extends BaseAdminController
|
||||
$result = BeforehandOrderLogic::add($params);
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
* 生成支付订单
|
||||
*/
|
||||
public function generateOrder(){
|
||||
$params = $this->request->post();
|
||||
$result = BeforehandOrderLogic::generateOrder($params);
|
||||
return $this->success('生成成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
* 一键出库
|
||||
*/
|
||||
|
@ -4,12 +4,16 @@ namespace app\admin\logic\beforehand_order;
|
||||
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\api\logic\order\CartLogic;
|
||||
use app\api\logic\order\OrderLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo;
|
||||
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;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use support\exception\BusinessException;
|
||||
@ -77,6 +81,53 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 生成支付订单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/09/30 11:26
|
||||
*/
|
||||
public static function generateOrder(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order= BeforehandOrder::where('id',$params['id'])->find();
|
||||
$cart_info=BeforehandOrderCartInfo::where('bhoid',$params['id'])->select()->toArray();
|
||||
$cartId = [];
|
||||
foreach ($cart_info as $k => $v) {
|
||||
$v['uid'] = $params['user_id'];
|
||||
$v['store_id'] = $params['store_id'];
|
||||
$find=StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->find();
|
||||
if(!$find){
|
||||
$product=StoreProduct::where('id', $v['product_id'])->find();
|
||||
$find=StoreProductLogic::ordinary($product, $params['store_id'], 0, $product);
|
||||
}
|
||||
if(in_array($order['order_type'],[2,3])){
|
||||
if(isset($v['purchase']) && $v['purchase'] > 0){
|
||||
$purchase = $v['purchase'];
|
||||
}else{
|
||||
$purchase=$v['price'];
|
||||
}
|
||||
$find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]);
|
||||
}
|
||||
unset($v['id']);
|
||||
$cart = CartLogic::add($v);
|
||||
$cartId[] = $cart['id'];
|
||||
}
|
||||
$user = User::where('id', $params['user_id'])->find();
|
||||
$params['shipping_type'] = 2;
|
||||
$params['source'] =2;//后台下单
|
||||
$res = OrderLogic::createOrder($cartId, null, $user, $params);
|
||||
$order->order_sn=$res['order_id'];
|
||||
$order->save();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑预订单表
|
||||
|
@ -212,6 +212,6 @@ class StoreOrderLogic extends BaseLogic
|
||||
$detail['refund_price']=$refund_price;
|
||||
CommissionnLogic::setStore($detail, $village_uid, $brigade_uid, $transaction_id);
|
||||
|
||||
StoreOrder::where('id', $detail['oid'])->update(['refund_price' => $refund_price, 'refund_num' => $refund_num]);
|
||||
StoreOrder::where('id', $detail['id'])->inc('refund_price',$refund_price)->inc('refund_num',$refund_num)->update();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user