feat(OrderLogic, PayNotifyLogic): 修改订单和支付逻辑,增加异常捕获和处理,修复了库存更新错误,并优化了相关代码。

This commit is contained in:
mkm 2024-06-23 19:56:55 +08:00
parent 6641010821
commit c6bcec76fa
2 changed files with 9 additions and 5 deletions

View File

@ -446,6 +446,7 @@ class OrderLogic extends BaseLogic
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
Db::rollback(); Db::rollback();
d($e);
self::setError($e->getMessage()); self::setError($e->getMessage());
return false; return false;
} }

View File

@ -742,11 +742,14 @@ class PayNotifyLogic extends BaseLogic
'product_id' => $v['product_id'], 'product_id' => $v['product_id'],
] ]
)->withTrashed()->find(); )->withTrashed()->find();
$updateData[] = [ if($StoreBranchProduct){
'id' => $StoreBranchProduct['id'], $updateData[] = [
'stock' => $StoreBranchProduct['stock'] - $v['cart_num'], 'id' => $StoreBranchProduct['id'],
'sales' => ['inc', $v['cart_num']] 'stock' => $StoreBranchProduct['stock'] - $v['cart_num'],
]; 'sales' => ['inc', $v['cart_num']]
];
}
} }
(new StoreBranchProduct())->saveAll($updateData); (new StoreBranchProduct())->saveAll($updateData);