优化线索、商机、项目相关开发
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
-- =============================================================================
|
||||
-- 修正「负责人 / 回访人 / 上传人」姓名:把登录账号刷成真实姓名
|
||||
--
|
||||
-- 背景:
|
||||
-- 历史代码把 JWT 里的 Username(登录账号,如 hero920103)写进了
|
||||
-- owner_user_name / last_owner_name 等字段,导致界面显示账号而不是人名。
|
||||
-- 后端已改为按 uid 查 yz_system_tenant_user.name 写入真实姓名,
|
||||
-- 本脚本用于修正存量数据。
|
||||
--
|
||||
-- 说明:
|
||||
-- - 按 tenant_id + owner_user_id(uid) 关联 yz_system_tenant_user 取 name;
|
||||
-- - 只更新「能匹配到用户且姓名非空」的记录,不动其它数据;
|
||||
-- - 幂等,可重复执行(姓名已一致的行不会被更新)。
|
||||
-- =============================================================================
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
-- 1. 客户:负责人姓名
|
||||
UPDATE `yz_backend_erp_customer` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`owner_user_id` AS UNSIGNED)
|
||||
SET c.`owner_user_name` = u.`name`
|
||||
WHERE c.`owner_user_id` IS NOT NULL AND c.`owner_user_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`owner_user_name` IS NULL OR c.`owner_user_name` <> u.`name`);
|
||||
|
||||
-- 2. 客户:公海记录里的「原负责人」姓名
|
||||
UPDATE `yz_backend_erp_customer` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`owner_user_id` AS UNSIGNED)
|
||||
SET c.`last_owner_name` = u.`name`
|
||||
WHERE c.`owner_user_id` IS NOT NULL AND c.`owner_user_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND c.`last_owner_name` IS NOT NULL AND c.`last_owner_name` <> ''
|
||||
AND c.`last_owner_name` <> u.`name`;
|
||||
|
||||
-- 3. 线索:负责人姓名
|
||||
UPDATE `yz_backend_crm_clue` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`owner_user_id` AS UNSIGNED)
|
||||
SET c.`owner_user_name` = u.`name`
|
||||
WHERE c.`owner_user_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`owner_user_name` IS NULL OR c.`owner_user_name` <> u.`name`);
|
||||
|
||||
-- 4. 商机:负责人姓名
|
||||
UPDATE `yz_backend_crm_business` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`owner_user_id` AS UNSIGNED)
|
||||
SET c.`owner_user_name` = u.`name`
|
||||
WHERE c.`owner_user_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`owner_user_name` IS NULL OR c.`owner_user_name` <> u.`name`);
|
||||
|
||||
-- 5. 项目:负责人姓名
|
||||
UPDATE `yz_backend_crm_project` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`owner_user_id` AS UNSIGNED)
|
||||
SET c.`owner_user_name` = u.`name`
|
||||
WHERE c.`owner_user_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`owner_user_name` IS NULL OR c.`owner_user_name` <> u.`name`);
|
||||
|
||||
-- 6. 回访记录:回访人姓名
|
||||
UPDATE `yz_backend_crm_follow` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`owner_user_id` AS UNSIGNED)
|
||||
SET c.`owner_user_name` = u.`name`
|
||||
WHERE c.`owner_user_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`owner_user_name` IS NULL OR c.`owner_user_name` <> u.`name`);
|
||||
|
||||
-- 7. 附件:上传人姓名
|
||||
UPDATE `yz_backend_crm_attach` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`uploader_id` AS UNSIGNED)
|
||||
SET c.`uploader_name` = u.`name`
|
||||
WHERE c.`uploader_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`uploader_name` IS NULL OR c.`uploader_name` <> u.`name`);
|
||||
|
||||
-- 8. 操作日志:操作人姓名
|
||||
UPDATE `yz_backend_crm_operate_log` c
|
||||
JOIN `yz_system_tenant_user` u
|
||||
ON u.`tid` = CAST(c.`tenant_id` AS UNSIGNED)
|
||||
AND u.`uid` = CAST(c.`operator_id` AS UNSIGNED)
|
||||
SET c.`operator_name` = u.`name`
|
||||
WHERE c.`operator_id` <> ''
|
||||
AND u.`name` IS NOT NULL AND u.`name` <> ''
|
||||
AND (c.`operator_name` IS NULL OR c.`operator_name` <> u.`name`);
|
||||
|
||||
-- 9. 核对:客户负责人分布
|
||||
SELECT `owner_user_id`, `owner_user_name`, COUNT(*) AS `cnt`
|
||||
FROM `yz_backend_erp_customer`
|
||||
GROUP BY `owner_user_id`, `owner_user_name`;
|
||||
Reference in New Issue
Block a user