Browse Source

fleat: update tag postchk

igb 1 week ago
parent
commit
37b53e1cbc
1 changed files with 38 additions and 2 deletions
  1. 38 2
      tag.php

+ 38 - 2
tag.php

@@ -15,10 +15,42 @@ if ($act == 'postchk') {
     $chkact = str_replace('t', '', $_POST['chkact'] ?? '');
 
     if (isset($_POST['chkbox'])) {
-        $sqlStr = "(" . implode(',', array_map('intval', (array)$_POST['chkbox'])) . ")";
+        $ids = implode(',', array_map('intval', (array)$_POST['chkbox']));
+        $count = count($_POST['chkbox']);
+        $sqlStr = "(" . $ids . ")";
+        
+        // 获取员工名称和代码
+        $stmt = $conn->prepare("SELECT em_code, em_user FROM employee WHERE id = ?");
+        $stmt->bind_param("i", $chkact);
+        $stmt->execute();
+        $result = $stmt->get_result();
+        $employeeCode = '';
+        $employeeName = '未知业务员';
+        if ($row = $result->fetch_assoc()) {
+            $employeeCode = $row['em_code'];
+            $employeeName = $row['em_user'];
+        }
+        $stmt->close();
+        
+        // 检查是否有客户已经属于目标业务员
+        $checkSql = "SELECT GROUP_CONCAT(id) as existing_ids FROM customer 
+                    WHERE cs_belong = " . (int)$chkact . " AND id IN " . $sqlStr;
+        $checkResult = $conn->query($checkSql);
+        $existingIds = "";
+        
+        if ($checkResult && $checkRow = $checkResult->fetch_assoc()) {
+            $existingIds = $checkRow['existing_ids'];
+        }
+        
+        if (!empty($existingIds)) {
+            // 有客户已经属于该业务员,显示错误信息
+            echo "<script>alert('无法转移,客户ID:{$existingIds} 已经属于业务员【{$employeeName}】!');history.back();</script>";
+            exit;
+        }
+        
         $updateStr = "UPDATE customer SET 
                      cs_updatetime='" . date('Y-m-d H:i:s') . "',
-                     cs_code=REPLACE(cs_code, '-', '/' + (SELECT em_code FROM employee WHERE id=" . (int)$chkact . ") + '-'),
+                     cs_code=REPLACE(cs_code, '-', '/$employeeCode-'),
                      cs_belong=" . (int)$chkact . ",
                      cs_chain=CONCAT(cs_chain,'," . (int)$chkact . "') 
                      WHERE id IN " . $sqlStr;
@@ -26,6 +58,10 @@ if ($act == 'postchk') {
         
         $conn->query($updateStr);
         $conn->query($deleteTag);
+        
+        // 记录操作日志
+        $action = "{$_SESSION['employee_name']} 从标签【{$tagName}】批量转移{$count}个客户({$ids})给业务员【{$employeeName}】";
+        logAction($action);
     }
     
     header('Location: tag.php?tagName=' . urlencode($tagName));