Project

General

Profile

解析Bug #382

v3.0: Duplicate index_total and ca_index in order lists

Added by Zhongbao Ye over 1 year ago. Updated about 1 year ago.

Status:
新建
Priority:
普通
Assignee:
Target version:
IT: Easytryck (Sweden) - v3.0
Start date:
Due date:
% Done:

0%

Estimated time:
8.00 h

Description

Task Details
  1. 查找重复的原因已经解决方案
    • 原因:因该系统在并发方面的处理不够完善,导致2人同时下单时,都获取到同一个total_index和ca_index
    • 方案:添加锁机制(也许可以使用文件锁?或者数据库锁)在并发下单时,通过锁机制避免使用相同的index。
      • 数据库锁相关内容补充:使用行锁:select ... for update, 以下是个demo
        <?php
        // 连接数据库
        $pdo = new PDO("mysql:host=localhost;dbname=your_database", "username", "password");
        
        try {
            // 开始事务
            $pdo->beginTransaction();
        
            // 获取最大键值并加锁
            $stmt = $pdo->prepare("SELECT MAX(key) AS max_key FROM order_table FOR UPDATE");
            $stmt->execute();
            $row = $stmt->fetch(PDO::FETCH_ASSOC);
            $maxKey = $row['max_key'];
        
            // 生成新订单的键值
            $newKey = $maxKey + 1;
        
            // 插入新订单
            $stmt = $pdo->prepare("INSERT INTO order_table (key, ...) VALUES (?, ...)");
            $stmt->execute([$newKey, ...]); // 插入其他订单信息
        
            // 提交事务
            $pdo->commit();
        
            echo "订单生成成功!新订单的键值为:" . $newKey;
        } catch (Exception $e) {
            // 出现异常时回滚事务
            $pdo->rollBack();
            echo "订单生成失败:" . $e->getMessage();
        }
        ?>
        
        
Input
  • QQ from sales staff
Output
  • Report and Solution

Others

#1

Updated by Xihua Fan about 1 year ago

  • Target version set to v3.0
#2

Updated by Xihua Fan about 1 year ago

  • Subject changed from Duplicate index_total and ca_index in order lists to v3.0: Duplicate index_total and ca_index in order lists
#3

Updated by Xihua Fan about 1 year ago

  • Assignee set to Xihua Fan

Also available in: Atom PDF