修复内容

This commit is contained in:
2026-01-30 18:48:13 +08:00
parent 5fe5289e26
commit 76cfa6b278
25 changed files with 943 additions and 289 deletions

View File

@@ -38,7 +38,7 @@ class GoodsLogic{
$goods = new Goods();
//品牌筛选
if(isset($get['brand_id']) && $get['brand_id']) {
$where[] = ['brand_id', '=', $get['brand_id']];
$where[] = ['third_category_id', '=', $get['brand_id']];
}
//分类筛选
if(isset($get['category_id']) && $get['category_id']){

View File

@@ -491,8 +491,8 @@ class OrderLogic extends LogicBase
// 拆分后每个订单的金额需要重新计算,这里先验证原始总金额
// 实际拆分时每个订单会独立计算
} else {
if($user_money < $data['order_amount']){
throw new Exception('账户余额不足');
if($user_money < $data['order_amount']){
throw new Exception('账户余额不足');
}
}
}
@@ -556,10 +556,13 @@ class OrderLogic extends LogicBase
// 创建单个订单
$single_goods_lists = $single_order_data['goods_lists'];
if (empty($single_goods_lists)) {
throw new Exception('商品信息获取失败');
}
$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_id = $order['order_id'];
$order_ids[] = $order_id;
self::addOrderGoods($order_id, $single_goods_lists);
@@ -590,6 +593,9 @@ class OrderLogic extends LogicBase
}
$single_goods_lists = $single_order_data['goods_lists'];
if (empty($single_goods_lists)) {
throw new Exception('商品信息获取失败');
}
$single_goods_id = $single_goods_lists[0]['goods_id'];
$order = self::addOrder($user_id, $single_order_data, $order_source, $user_address, $single_goods_id);
@@ -607,30 +613,36 @@ class OrderLogic extends LogicBase
}
} else {
// 普通商品:保持原有逻辑
if (empty($goods_lists)) {
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'];
$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'], []);
}
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]);
// 砍价订单处理
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_ids[0] ?? 0, 'order_ids' => $order_ids, 'type' => 'order']);
if (empty($order_ids)) {
throw new Exception('订单创建失败');
}
return self::dataSuccess('', ['order_id' => $order_ids[0], 'order_ids' => $order_ids, 'type' => 'order']);
} catch (Exception $e) {
Db::rollback();

View File

@@ -1,5 +1,6 @@
<?php
namespace app\api\logic;
use app\api\model\OrderPoints;
use think\Db;
use think\Exception;
use app\common\server\UrlServer;
@@ -9,13 +10,16 @@ class PointsLogic
{
//获取积分的分类
public static function classify(){
return Db::name('printer_type')->select();
return Db::name('printer_type')->where('del',0)->select();
}
//获取到积分的商品列表
public static function goodslist(){
$where=[];
public static function goodslist($clsssId){
$where=[
'brand_id'=>$clsssId,
'del'=>0
];
$goods = Db::name('printer_goods')
->where($where)
->select();
@@ -34,21 +38,83 @@ class PointsLogic
return $data;
}
/**
* 积分商品下单(扣减积分并生成订单)
* @param array $data ['id','name','price','user_id','number'(可选)]
* @return array
*/
public static function goodsSub($data){
$data=[
'name' =>$data['name'],
'goods_id' =>$data['id'],
'price' =>$data['price'],
'number' =>1,
'user_id' =>$data['user_id'],
'create_time'=>time()
];
$insert=Db::name('printer_order')->data($data)->insert();
if($insert){
$user=UserLogic::getUserInfo($data['user_id']);
db::name('user')->where('id',$data['user_id'])->update(['user_integral'=>$user['user_integral']-$data['price']]);
// Db::name('printer_goods')->where('')
}
if(empty($data) || !is_array($data)){
return ['code'=>0,'msg'=>'参数错误'];
}
// 基础校验
if(empty($data['id']) || empty($data['user_id']) || !isset($data['price'])){
return ['code'=>0,'msg'=>'参数不完整'];
}
$number = isset($data['number']) && intval($data['number'])>0 ? intval($data['number']) : 1;
$price = floatval($data['price']);
$needIntegral = $price * $number;
Db::startTrans();
try{
// 加锁读取用户积分
$user = Db::name('user')->where('id',$data['user_id'])->lock(true)->find();
if(!$user){
throw new Exception('用户不存在');
}
if($user['user_integral'] < $needIntegral){
throw new Exception('积分不足');
}
$orderData = [
'name' => $data['name'] ?? '',
'goods_id' => $data['id'],
'price' => $price,
'number' => $number,
'user_id' => $data['user_id'],
'create_time' => time(),
'address_id' => $data['addressId'],
'state' => 1
];
$insert = Db::name('printer_order')->insert($orderData);
if(!$insert){
throw new Exception('下单失败');
}
// 扣减积分
Db::name('user')
->where('id',$data['user_id'])
->setDec('user_integral', $needIntegral);
Db::commit();
return ['code'=>1,'msg'=>'兑换成功'];
}catch (\Exception $e){
Db::rollback();
return ['code'=>0,'msg'=>$e->getMessage()];
}
}
//获取积分订单
public static function orderList($userId, $state = null)
{
$order = new OrderPoints();
$query = $order->with([
'address' => function($query){
$query->where('del',0)->field('id,address');
},
'pointsGoods' => function($query){
$query->where('del',0)->field('id,images');
}
])->where('user_id', $userId);
// 如果传了state参数才添加state条件否则查询全部
if($state !== null && $state !== ''){
$query = $query->where('state', $state);
}
$orderArray = $query->paginate(10);
return $orderArray;
}
}