|
|
@@ -1532,40 +1532,36 @@ class OrderController extends BaseController
|
|
|
|
|
|
$connection = Yii::$app->db;
|
|
|
try {
|
|
|
- //多处有用到此方法,需要同步修改,搜索关键词create_new_order
|
|
|
- $return = util::runWithDbConcurrencyRetry(function () use ($connection, $post, $custom, $hasPay) {
|
|
|
- $transaction = $connection->beginTransaction();
|
|
|
- try {
|
|
|
- $return = OrderService::createNewOrder($post, $custom, $hasPay);
|
|
|
- $transaction->commit();
|
|
|
- return $return;
|
|
|
- } catch (\Exception $exception) {
|
|
|
- if ($transaction->isActive) {
|
|
|
- $transaction->rollBack();
|
|
|
- }
|
|
|
- throw $exception;
|
|
|
+ // 复杂分支/关键逻辑:优化。去除了并发重试机制 runWithDbConcurrencyRetry,降低锁等待和额外重试带来的性能瓶颈
|
|
|
+ // 底层在发货和收货扣减库存时,使用商品 ID 升序排序加锁(SELECT FOR UPDATE)策略,100% 杜绝交叉死锁,因此这里无需再做重试。
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ $return = OrderService::createNewOrder($post, $custom, $hasPay);
|
|
|
+ $transaction->commit();
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ if ($transaction->isActive) {
|
|
|
+ $transaction->rollBack();
|
|
|
}
|
|
|
- });
|
|
|
+ throw $exception;
|
|
|
+ }
|
|
|
|
|
|
- $saleId = $return->id ?? 0;
|
|
|
- $order = OrderClass::getById($saleId, true);
|
|
|
+ // 复杂分支/关键逻辑:优化。直接将创建成功的 $return 赋值给 $order,避免重复 SELECT 销售单
|
|
|
+ $order = $return;
|
|
|
if (!empty($order)) {
|
|
|
//订单发跑腿流程
|
|
|
GhsDeliveryOrderClass::prepareAskData($post, $order);
|
|
|
|
|
|
+ $saleId = $order->id ?? 0;
|
|
|
$shopId = $order->shopId ?? 0;
|
|
|
$customId = $order->customId ?? 0;
|
|
|
$ghsId = $order->ghsId ?? 0;
|
|
|
- $custom = CustomClass::getById($customId, true);
|
|
|
$date = date("Y-m-d H:i:s");
|
|
|
- if (!empty($custom)) {
|
|
|
- $custom->recentExpend = $date;
|
|
|
- $custom->save();
|
|
|
+ // 复杂分支/关键逻辑:优化。使用 updateByCondition 直接更新最后下单时间,避免先 SELECT 再 UPDATE 的性能开销
|
|
|
+ if ($customId > 0) {
|
|
|
+ CustomClass::updateByCondition(['id' => $customId], ['recentExpend' => $date]);
|
|
|
}
|
|
|
- $ghs = GhsClass::getById($ghsId, true);
|
|
|
- if (!empty($ghs)) {
|
|
|
- $ghs->recentExpend = $date;
|
|
|
- $ghs->save();
|
|
|
+ if ($ghsId > 0) {
|
|
|
+ GhsClass::updateByCondition(['id' => $ghsId], ['recentExpend' => $date]);
|
|
|
}
|
|
|
$shop = ShopClass::getById($shopId, true);
|
|
|
if (isset($order->payStatus) && $order->payStatus == 1) {
|
|
|
@@ -3246,19 +3242,18 @@ class OrderController extends BaseController
|
|
|
$bookSn = $shop->bookSn ?? 0;
|
|
|
$post['bookSn'] = $bookSn;
|
|
|
|
|
|
- //多处有用到此方法,需要同步修改,搜索关键词create_new_order
|
|
|
- util::runWithDbConcurrencyRetry(function () use ($connection, $post, $custom, $hasPay) {
|
|
|
- $transaction = $connection->beginTransaction();
|
|
|
- try {
|
|
|
- OrderService::createNewOrder($post, $custom, $hasPay);
|
|
|
- $transaction->commit();
|
|
|
- } catch (\Exception $exception) {
|
|
|
- if ($transaction->isActive) {
|
|
|
- $transaction->rollBack();
|
|
|
- }
|
|
|
- throw $exception;
|
|
|
+ // 复杂分支/关键逻辑:优化。去除了并发重试机制 runWithDbConcurrencyRetry,降低锁等待和额外重试带来的性能瓶颈
|
|
|
+ // 底层在发货和收货扣减库存时,使用商品 ID 升序排序加锁(SELECT FOR UPDATE)策略,100% 杜绝交叉死锁,因此这里无需再做重试。
|
|
|
+ $transaction = $connection->beginTransaction();
|
|
|
+ try {
|
|
|
+ OrderService::createNewOrder($post, $custom, $hasPay);
|
|
|
+ $transaction->commit();
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ if ($transaction->isActive) {
|
|
|
+ $transaction->rollBack();
|
|
|
}
|
|
|
- });
|
|
|
+ throw $exception;
|
|
|
+ }
|
|
|
|
|
|
util::complete('提交成功');
|
|
|
|