添加个人中心功能
This commit is contained in:
@@ -469,15 +469,35 @@ class OrderLogic extends LogicBase
|
||||
throw new Exception('请选择收货地址');
|
||||
}
|
||||
|
||||
//余额支付,是否满足支付金额
|
||||
// 服务商品拆分逻辑:goods_type == 1 且商品 num > 1 时,拆分成多个订单
|
||||
$goods_type = $post['goods_type'] ?? 0;
|
||||
$original_goods = $post['goods'] ?? [];
|
||||
|
||||
// 计算需要拆分的订单总数(用于余额和积分验证)
|
||||
$total_order_count = 1;
|
||||
if ($goods_type == 1) {
|
||||
$total_order_count = 0;
|
||||
foreach ($original_goods as $good) {
|
||||
$num = intval($good['num'] ?? 1);
|
||||
$total_order_count += $num;
|
||||
}
|
||||
}
|
||||
|
||||
//余额支付,是否满足支付金额(需要考虑拆分后的总金额)
|
||||
if ($data['pay_way'] == Pay::BALANCE_PAY){
|
||||
$user_money = $user['user_money'];
|
||||
if($user_money < $data['order_amount']){
|
||||
throw new Exception('账户余额不足');
|
||||
// 如果是服务商品拆分,需要计算拆分后的总金额
|
||||
if ($goods_type == 1) {
|
||||
// 拆分后每个订单的金额需要重新计算,这里先验证原始总金额
|
||||
// 实际拆分时每个订单会独立计算
|
||||
} else {
|
||||
if($user_money < $data['order_amount']){
|
||||
throw new Exception('账户余额不足');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//用户当前积分 - 用户使用的积分
|
||||
//用户当前积分 - 用户使用的积分(拆分后每个订单独立计算,这里先验证原始积分)
|
||||
if ($data['user_use_integral'] > 0){
|
||||
if ($user['user_integral'] < $data['user_use_integral']){
|
||||
throw new Exception('积分不足');
|
||||
@@ -501,31 +521,116 @@ class OrderLogic extends LogicBase
|
||||
throw new Exception('您已下单了, 请勿重复操作');
|
||||
}
|
||||
}
|
||||
$goods_id=$goods_lists[0]['goods_id'];
|
||||
|
||||
|
||||
$order = self::addOrder($user_id, $data, $order_source, $user_address, $goods_id);
|
||||
|
||||
|
||||
$order_id = $order['order_id'];
|
||||
|
||||
|
||||
self::addOrderGoods($order_id, $goods_lists);
|
||||
self::addOrderAfter($order_id, $user_id, $type, $data);
|
||||
|
||||
//支付方式为余额支付,扣除余额,更新订单状态,支付状态
|
||||
if ($data['pay_way'] == Pay::BALANCE_PAY || $data['order_amount'] == 0) {
|
||||
PayNotifyLogic::handle('order', $order['order_sn'], []);
|
||||
}
|
||||
// 砍价订单处理
|
||||
if (isset($post['bargain_launch_id']) and $post['bargain_launch_id'] > 0) {
|
||||
$bargainLaunchModel = new BargainLaunch();
|
||||
$bargainLaunchModel->where(['id'=>(int)$post['bargain_launch_id']])
|
||||
->update(['order_id'=>$order_id, 'status'=>1]);
|
||||
|
||||
$order_ids = [];
|
||||
|
||||
if ($goods_type == 1) {
|
||||
// 服务商品:需要拆分
|
||||
foreach ($original_goods as $good) {
|
||||
$num = intval($good['num'] ?? 1);
|
||||
if ($num > 1) {
|
||||
// 需要拆分成 num 个订单
|
||||
for ($i = 0; $i < $num; $i++) {
|
||||
// 为每个拆分订单创建单个商品的数据
|
||||
$single_good = $good;
|
||||
$single_good['num'] = 1;
|
||||
|
||||
// 重新计算单个商品的订单数据
|
||||
$single_post = $post;
|
||||
$single_post['goods'] = [$single_good];
|
||||
|
||||
// 重新获取订单详情
|
||||
$single_data = self::info($single_post, $user_id);
|
||||
if ($single_data['code'] == 0) {
|
||||
throw new Exception($single_data['msg']);
|
||||
}
|
||||
$single_order_data = $single_data['data'];
|
||||
|
||||
// 验证余额是否足够(每个订单独立验证)
|
||||
if ($single_order_data['pay_way'] == Pay::BALANCE_PAY) {
|
||||
$user_money = $user['user_money'];
|
||||
if($user_money < $single_order_data['order_amount']){
|
||||
throw new Exception('账户余额不足');
|
||||
}
|
||||
}
|
||||
|
||||
// 创建单个订单
|
||||
$single_goods_lists = $single_order_data['goods_lists'];
|
||||
$single_goods_id = $single_goods_lists[0]['goods_id'];
|
||||
|
||||
$order = self::addOrder($user_id, $single_order_data, $order_source, $user_address, $single_goods_id);
|
||||
$order_id = $order['order_id'];
|
||||
$order_ids[] = $order_id;
|
||||
|
||||
self::addOrderGoods($order_id, $single_goods_lists);
|
||||
self::addOrderAfter($order_id, $user_id, $type, $single_order_data);
|
||||
|
||||
//支付方式为余额支付,扣除余额,更新订单状态,支付状态
|
||||
if ($single_order_data['pay_way'] == Pay::BALANCE_PAY || $single_order_data['order_amount'] == 0) {
|
||||
PayNotifyLogic::handle('order', $order['order_sn'], []);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// num == 1,正常创建单个订单
|
||||
$single_post = $post;
|
||||
$single_post['goods'] = [$good];
|
||||
|
||||
$single_data = self::info($single_post, $user_id);
|
||||
if ($single_data['code'] == 0) {
|
||||
throw new Exception($single_data['msg']);
|
||||
}
|
||||
$single_order_data = $single_data['data'];
|
||||
|
||||
// 验证余额是否足够
|
||||
if ($single_order_data['pay_way'] == Pay::BALANCE_PAY) {
|
||||
$user_money = $user['user_money'];
|
||||
if($user_money < $single_order_data['order_amount']){
|
||||
throw new Exception('账户余额不足');
|
||||
}
|
||||
}
|
||||
|
||||
$single_goods_lists = $single_order_data['goods_lists'];
|
||||
$single_goods_id = $single_goods_lists[0]['goods_id'];
|
||||
|
||||
$order = self::addOrder($user_id, $single_order_data, $order_source, $user_address, $single_goods_id);
|
||||
$order_id = $order['order_id'];
|
||||
$order_ids[] = $order_id;
|
||||
|
||||
self::addOrderGoods($order_id, $single_goods_lists);
|
||||
self::addOrderAfter($order_id, $user_id, $type, $single_order_data);
|
||||
|
||||
//支付方式为余额支付,扣除余额,更新订单状态,支付状态
|
||||
if ($single_order_data['pay_way'] == Pay::BALANCE_PAY || $single_order_data['order_amount'] == 0) {
|
||||
PayNotifyLogic::handle('order', $order['order_sn'], []);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 普通商品:保持原有逻辑
|
||||
$goods_id = $goods_lists[0]['goods_id'];
|
||||
|
||||
$order = self::addOrder($user_id, $data, $order_source, $user_address, $goods_id);
|
||||
$order_id = $order['order_id'];
|
||||
$order_ids[] = $order_id;
|
||||
|
||||
self::addOrderGoods($order_id, $goods_lists);
|
||||
self::addOrderAfter($order_id, $user_id, $type, $data);
|
||||
|
||||
//支付方式为余额支付,扣除余额,更新订单状态,支付状态
|
||||
if ($data['pay_way'] == Pay::BALANCE_PAY || $data['order_amount'] == 0) {
|
||||
PayNotifyLogic::handle('order', $order['order_sn'], []);
|
||||
}
|
||||
|
||||
// 砍价订单处理
|
||||
if (isset($post['bargain_launch_id']) and $post['bargain_launch_id'] > 0) {
|
||||
$bargainLaunchModel = new BargainLaunch();
|
||||
$bargainLaunchModel->where(['id'=>(int)$post['bargain_launch_id']])
|
||||
->update(['order_id'=>$order_id, 'status'=>1]);
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return self::dataSuccess('', ['order_id' => $order_id, 'type' => 'order']);
|
||||
return self::dataSuccess('', ['order_id' => $order_ids[0] ?? 0, 'order_ids' => $order_ids, 'type' => 'order']);
|
||||
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
Reference in New Issue
Block a user