Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
aimeiyue
service
Commits
a1a99506
Commit
a1a99506
authored
Oct 13, 2025
by
yink
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复订单退款和库存管理问题
修复订单退款时未返回结果的问题 调整库存管理逻辑,支持增加和减少库存 修复支付回调中积分记录的条件判断 优化积分解冻逻辑,支持批量处理记录
parent
762c96ed
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
20 deletions
+99
-20
app/Admin/Controllers/OrderInfoController.php
+3
-1
app/Admin/Controllers/UploadController.php
+11
-0
app/Http/Controllers/Api/GoodController.php
+1
-1
app/Http/Controllers/Api/OrderController.php
+11
-2
app/Http/Controllers/Api/StoreController.php
+31
-0
app/Models/Adapay.php
+26
-7
app/Models/UserPointChangeRec.php
+15
-8
routes/api.php
+1
-1
No files found.
app/Admin/Controllers/OrderInfoController.php
View file @
a1a99506
...
...
@@ -374,9 +374,11 @@ public function OrderAdminRefund()
}
if
(
$orderObj
->
is_div
==
0
)
{
OrderController
::
canceOrderFunc
(
$orderObj
);
return
OrderController
::
canceOrderFunc
(
$orderObj
);
}
else
{
return
response
()
->
json
([
'status'
=>
false
,
'message'
=>
'已分账,不允许退款!'
]);
}
//return response()->json(['status' => true, 'message' => '退款成功']);
}
}
app/Admin/Controllers/UploadController.php
View file @
a1a99506
...
...
@@ -113,9 +113,20 @@ public function goodsUpload()
{
$aliOss
=
new
AliOss
();
// 判断是否是删除文件请求
if
(
$this
->
isDeleteRequest
())
{
// 删除文件并响应
return
$this
->
deleteFileAndResponse
();
}
// 获取上传的文件
$file
=
$this
->
file
();
// 检查文件是否存在
if
(
!
$file
)
{
return
$this
->
responseErrorMessage
(
'文件不存在'
);
}
$ext
=
$file
->
getClientOriginalExtension
();
Image
::
make
(
$file
->
getRealPath
())
->
resize
(
640
,
null
,
function
(
$constraint
)
{
...
...
app/Http/Controllers/Api/GoodController.php
View file @
a1a99506
...
...
@@ -154,7 +154,7 @@ public function getIndexGoods(Request $request)
// }
$model
=
GoodModel
::
select
([
'id'
,
'goods_name'
,
'is_hot'
,
'cover_img'
,
'goods_brief'
,
'sku'
,
'tags'
])
->
where
([
'is_show'
=>
1
]);
->
where
([
'is_show'
=>
1
,
'is_hot'
=>
1
]);
if
(
$kw
)
{
$model
=
$model
->
where
(
"goods_name"
,
'like'
,
"%"
.
$kw
.
"%"
);
}
...
...
app/Http/Controllers/Api/OrderController.php
View file @
a1a99506
...
...
@@ -369,6 +369,10 @@ public function pay(Request $request)
$order
->
pay_status
=
1
;
//支付状态
$order
->
order_status
=
1
;
//订单状态
//更新商品库存
$Adapay
=
new
Adapay
();
$Adapay
->
updateGoodsStock
(
$order
);
$order
->
save
();
DB
::
commit
();
...
...
@@ -378,6 +382,11 @@ public function pay(Request $request)
return
$this
->
JsonResponse
(
''
,
'积分充足,可选择积分支付!'
,
500
);
}
//判断是否有足够的积分支付
if
(
$userObj
->
balance
<
$order_amount
)
{
return
$this
->
JsonResponse
(
''
,
'积分不足!'
,
500
);
}
//扣除积分
if
(
!
UserPointChangeRec
::
pointChangeRecord
(
$userObj
->
id
,
$userObj
->
balance
,
0
,
3
,
1
,
$order_id
))
{
return
$this
->
JsonResponse
(
''
,
'网络异常,积分抵扣失败!003'
,
500
);
...
...
@@ -533,7 +542,7 @@ public static function canceOrderFunc($order)
}
$Adapay
->
updateGoodsStock
(
$order
);
$Adapay
->
updateGoodsStock
(
$order
,
true
);
//判断支付方式现金还是积分, 1:微信,2:积分,3:微信+积分
//判断是否现金支付,查询是否需要收回冻结中的积分
...
...
@@ -593,7 +602,7 @@ public static function canceOrderFunc($order)
Log
::
add
(
'取消订单失败'
,
$exception
->
getMessage
());
return
(
new
self
())
->
JsonResponse
(
''
,
'取消订单失败'
,
201
);
}
return
(
new
self
())
->
JsonResponse
(
''
);
return
(
new
self
())
->
JsonResponse
(
'
成功
'
);
}
...
...
app/Http/Controllers/Api/StoreController.php
View file @
a1a99506
...
...
@@ -65,8 +65,39 @@ public function checkDistance(Request $request)
return
$this
->
JsonResponse
([
'flag'
=>
$flag
,
'delivery_store_id'
=>
$store_id
]);
}
//// 测试-距离判断
public
function
testHaversineDistance
(
Request
$request
)
{
$mid
=
25
;
$lat1
=
$request
->
lat
??
''
;
$lng1
=
$request
->
lng
??
''
;
$list
=
[];
if
(
$mid
)
{
$list
=
Store
::
where
([
'merchant_id'
=>
$mid
])
->
select
([
'id'
,
'title'
,
'lat_lng'
,
'address'
,
'contacts'
,
'phone'
])
->
get
();
foreach
(
$list
as
$key
=>
$val
)
{
$atng
=
$val
->
lat_lng
?
explode
(
','
,
$val
->
lat_lng
)
:
[];
$lat2
=
$atng
[
0
];
// 修正:第一个元素是纬度
$lng2
=
$atng
[
1
];
// 修正:第二个元素是经度
$list
[
$key
][
'distance'
]
=
(
$lat1
&&
$lat2
)
?
$this
->
haversineDistance
(
$lat1
,
$lng1
,
$lat2
,
$lng2
)
:
''
;
}
}
return
$this
->
JsonResponse
(
$list
);
}
function
haversineDistance
(
$lat1
,
$lng1
,
$lat2
,
$lng2
)
{
// 地球半径(单位:千米)
$radius
=
6371
;
...
...
app/Models/Adapay.php
View file @
a1a99506
...
...
@@ -95,6 +95,8 @@ public function payNotify($params = [])
if
(
$message
[
'status'
]
==
"succeeded"
&&
$orderObj
->
pay_status
==
0
)
{
DB
::
beginTransaction
();
try
{
//Log::add('支付回调', [$order_no]);
//更新订单
if
(
$orderObj
->
pay_status
==
0
)
{
$orderObj
->
order_status
=
1
;
...
...
@@ -102,7 +104,7 @@ public function payNotify($params = [])
$orderObj
->
freeze_stat
=
$message
[
'freeze_stat'
];
if
(
$orderObj
->
save
())
{
if
(
$orderObj
->
pay_type
=
1
)
{
//纯现金支付才返积分
if
(
$orderObj
->
pay_type
=
=
1
)
{
//纯现金支付才返积分
//创建直推分积分记录
$this
->
createPointRecordByOrder
(
$orderObj
->
id
);
}
...
...
@@ -110,7 +112,7 @@ public function payNotify($params = [])
//更新商品销量、库存
$this
->
updateGoodsStock
(
$orderObj
);
// //更新商品销量、库存
// //更新商品销量、库存
【上方已更新】
// $goodsList = OrderGoods::where("order_id", $orderObj->id)->get();
// foreach ($goodsList as $item) {
// //Log::add('--订单商品对象--', $item);
...
...
@@ -637,7 +639,7 @@ public static function createPointRecordByOrder($order_id)
//判断直推是否存在
if
(
$spuid
)
{
// 计算直推用户的积分
$total_first_commission
=
number_format
(
$goodsObj
->
total_first_commission
,
2
);
$total_first_commission
=
number_format
(
$goodsObj
->
total_first_commission
,
2
);
// 为直推用户创建积分记录
UserPointChangeRec
::
pointChangeRecord
(
$spuid
,
$total_first_commission
,
1
,
1
,
3
,
$order_id
);
//
...
...
@@ -676,6 +678,7 @@ public static function createPointRecordByOrder($order_id)
*
* 参数说明:
* @param OrderInfo $orderObj 订单对象
* @param bool $isIncreaseStock 是否增加库存,默认false(减少库存)
*
* 返回值说明:
* @return bool 更新成功返回true,失败返回false
...
...
@@ -685,13 +688,14 @@ public static function createPointRecordByOrder($order_id)
*
* 使用示例:
* $order = OrderInfo::find(123);
* Adapay::updateGoodsStock($order);
* Adapay::updateGoodsStock($order); // 默认减少库存
* Adapay::updateGoodsStock($order, true); // 增加库存
*
* 注意事项:
* 1. 需要在事务中调用此方法
* 2. 会同时更新商品规格库存、商品SKU和商户规格库存
*/
public
static
function
updateGoodsStock
(
$orderObj
)
public
static
function
updateGoodsStock
(
$orderObj
,
$isIncreaseStock
=
false
)
{
if
(
!
$orderObj
||
!
$orderObj
->
id
)
{
throw
new
Exception
(
'订单对象无效'
);
...
...
@@ -716,7 +720,14 @@ public static function updateGoodsStock($orderObj)
continue
;
}
$attr_stock
=
(
$attrObj
->
stock
-
$item
->
goods_number
)
>=
0
?
$attrObj
->
stock
-
$item
->
goods_number
:
0
;
// 根据参数决定是增加还是减少库存
if
(
$isIncreaseStock
)
{
// 增加库存:原库存加上购买数量
$attr_stock
=
$attrObj
->
stock
+
$item
->
goods_number
;
}
else
{
// 减少库存:原库存减去购买数量,确保库存不为负数
$attr_stock
=
(
$attrObj
->
stock
-
$item
->
goods_number
)
>=
0
?
$attrObj
->
stock
-
$item
->
goods_number
:
0
;
}
$attrObj
->
stock
=
$attr_stock
;
$attrObj
->
save
();
...
...
@@ -739,8 +750,16 @@ public static function updateGoodsStock($orderObj)
'merchant_id'
=>
$orderObj
->
merchant_id
])
->
first
();
// 如果订单有商户ID且找到对应的商户规格库存记录,则更新商户规格库存
if
(
$orderObj
->
merchant_id
&&
$mgsObj
)
{
$changeStock
=
(
$mgsObj
->
stock
>=
$item
->
goods_number
)
?
$mgsObj
->
stock
-
$item
->
goods_number
:
0
;
// 根据参数决定是增加还是减少库存
if
(
$isIncreaseStock
)
{
// 增加库存:原库存加上购买数量
$changeStock
=
$mgsObj
->
stock
+
$item
->
goods_number
;
}
else
{
// 减少库存:原库存减去购买数量,确保库存不为负数
$changeStock
=
(
$mgsObj
->
stock
>=
$item
->
goods_number
)
?
$mgsObj
->
stock
-
$item
->
goods_number
:
0
;
}
$mgsObj
->
stock
=
$changeStock
;
$mgsObj
->
save
();
}
...
...
app/Models/UserPointChangeRec.php
View file @
a1a99506
...
...
@@ -163,23 +163,30 @@ public static function pointUnfreezeimg($orderObj)
'order_id'
=>
$orderObj
->
id
,
'msg'
=>
'没有找到可解冻的积分记录'
]);
DB
::
commit
();
return
true
;
}
// 设置7天后的解冻结束日期
$freezeEndDate
=
date
(
'Y-m-d H:i:s'
,
strtotime
(
'+7 days'
));
// 更新积分记录状态为解冻中
DB
::
table
(
'user_point_change_rec'
)
->
where
(
'id'
,
$records
[
0
]
->
id
)
->
update
([
'point_state'
=>
2
,
// 解冻中
'freeze_end_date'
=>
$freezeEndDate
]);
// 遍历所有记录,更新每条积分记录状态为解冻中
$totalPointAmount
=
0
;
foreach
(
$records
as
$record
)
{
DB
::
table
(
'user_point_change_rec'
)
->
where
(
'id'
,
$record
->
id
)
->
update
([
'point_state'
=>
2
,
// 解冻中
'freeze_end_date'
=>
$freezeEndDate
]);
$totalPointAmount
+=
$record
->
point_amount
;
}
DB
::
commit
();
Log
::
add
(
'point_unfreeze'
,
[
'order_id'
=>
$orderObj
->
id
,
'point_amount'
=>
$records
[
0
]
->
point_amount
,
'total_point_amount'
=>
$totalPointAmount
,
'record_count'
=>
count
(
$records
),
'freeze_end_date'
=>
$freezeEndDate
]);
return
true
;
...
...
routes/api.php
View file @
a1a99506
...
...
@@ -27,7 +27,7 @@
//调试路由
Route
::
post
(
'simulate-login'
,
'LoginController@simulateLogin'
);
//模拟登陆
Route
::
get
(
'test1'
,
'
LoginController@test
'
);
//测试内容-什么都测
Route
::
get
(
'test1'
,
'
StoreController@testHaversineDistance
'
);
//测试内容-什么都测
Route
::
get
(
'test-order-div'
,
'CarouselController@orderDiv'
);
//测试订单分佣
Route
::
get
(
'test-order-div-point'
,
'CarouselController@orderDivByPoint'
);
//测试订单积分生成
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment