更新
This commit is contained in:
@@ -61,6 +61,16 @@ CREATE TABLE IF NOT EXISTS `zyt_qywx_promotion_link` (
|
||||
`name` varchar(80) NOT NULL DEFAULT '',
|
||||
`group_name` varchar(60) NOT NULL DEFAULT '默认分组',
|
||||
`wecom_url` varchar(1000) NOT NULL DEFAULT '',
|
||||
`remote_link_id` varchar(128) NULL DEFAULT NULL COMMENT '企业微信获客助手 link_id',
|
||||
`remote_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0历史手工 1远端有效 2远端已删除 3远端不可见 4同步失败',
|
||||
`remote_create_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`range_user_json` text NULL COMMENT '获客链接可用成员 userid JSON',
|
||||
`range_department_json` text NULL COMMENT '获客链接可用企微部门 ID JSON',
|
||||
`skip_verify` tinyint unsigned NOT NULL DEFAULT 0,
|
||||
`priority_option_json` text NULL,
|
||||
`remote_snapshot` mediumtext NULL,
|
||||
`last_sync_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`sync_error` varchar(500) NOT NULL DEFAULT '',
|
||||
`weight` smallint unsigned NOT NULL DEFAULT 1,
|
||||
`status` tinyint unsigned NOT NULL DEFAULT 1,
|
||||
`daily_limit` int unsigned NOT NULL DEFAULT 0 COMMENT '0为不限',
|
||||
@@ -77,6 +87,7 @@ CREATE TABLE IF NOT EXISTS `zyt_qywx_promotion_link` (
|
||||
`update_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`delete_time` int unsigned NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_remote_link_id` (`remote_link_id`),
|
||||
KEY `idx_pool_eligible` (`pool_id`,`status`,`active_start`,`active_end`),
|
||||
KEY `idx_account` (`account_id`),
|
||||
KEY `idx_owner` (`owner_admin_id`),
|
||||
@@ -110,7 +121,7 @@ SET @first_visit_menu_id = (
|
||||
INSERT INTO `zyt_system_menu`
|
||||
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
|
||||
SELECT
|
||||
@first_visit_menu_id, 'C', '企业微信推广助手', 'el-icon-Promotion', 60,
|
||||
@first_visit_menu_id, 'C', '企业微信获客助手', 'el-icon-Promotion', 60,
|
||||
'firstvisit.wecomPromotion/overview', 'wecom_promotion', 'first_visit/wecom_promotion/index',
|
||||
'', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
|
||||
FROM DUAL
|
||||
@@ -119,7 +130,7 @@ WHERE @first_visit_menu_id IS NOT NULL
|
||||
SELECT 1 FROM `zyt_system_menu`
|
||||
WHERE `perms` = 'firstvisit.wecomPromotion/overview'
|
||||
OR (`pid` = @first_visit_menu_id AND (
|
||||
TRIM(`name`) = '企业微信推广助手'
|
||||
TRIM(`name`) IN ('企业微信推广助手', '企业微信获客助手')
|
||||
OR TRIM(`paths`) = 'wecom_promotion'
|
||||
OR TRIM(`component`) = 'first_visit/wecom_promotion/index'
|
||||
))
|
||||
@@ -129,14 +140,14 @@ SET @wecom_promotion_menu_id = (
|
||||
SELECT `id` FROM `zyt_system_menu`
|
||||
WHERE `pid` = @first_visit_menu_id
|
||||
AND (`perms` = 'firstvisit.wecomPromotion/overview'
|
||||
OR TRIM(`name`) = '企业微信推广助手'
|
||||
OR TRIM(`name`) IN ('企业微信推广助手', '企业微信获客助手')
|
||||
OR TRIM(`component`) = 'first_visit/wecom_promotion/index')
|
||||
ORDER BY CASE WHEN `perms` = 'firstvisit.wecomPromotion/overview' THEN 0 ELSE 1 END, `id`
|
||||
LIMIT 1
|
||||
);
|
||||
|
||||
UPDATE `zyt_system_menu`
|
||||
SET `name` = '企业微信推广助手',
|
||||
SET `name` = '企业微信获客助手',
|
||||
`icon` = 'el-icon-Promotion',
|
||||
`sort` = 60,
|
||||
`perms` = 'firstvisit.wecomPromotion/overview',
|
||||
@@ -148,7 +159,7 @@ SET `name` = '企业微信推广助手',
|
||||
`update_time` = UNIX_TIMESTAMP()
|
||||
WHERE `id` = @wecom_promotion_menu_id;
|
||||
|
||||
-- 医助维护本人链接;组长/经理按部门范围管理;管理员全量管理并可发起企业授权。
|
||||
-- 医助维护本人获客助手链接;组长/经理按部门范围管理;管理员全量管理。
|
||||
INSERT IGNORE INTO `zyt_system_role_menu` (`role_id`, `menu_id`)
|
||||
SELECT `id`, @first_visit_menu_id
|
||||
FROM `zyt_system_role`
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
-- 已安装“企业微信获客助手”旧版数据表时执行一次。
|
||||
-- 新安装环境直接执行 add_first_visit_wecom_promotion.sql,无需再执行本文件。
|
||||
|
||||
ALTER TABLE `zyt_qywx_promotion_link`
|
||||
ADD COLUMN `remote_link_id` varchar(128) NULL DEFAULT NULL COMMENT '企业微信获客助手 link_id' AFTER `wecom_url`,
|
||||
ADD COLUMN `remote_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0历史手工 1远端有效 2远端已删除 3远端不可见 4同步失败' AFTER `remote_link_id`,
|
||||
ADD COLUMN `remote_create_time` int unsigned NOT NULL DEFAULT 0 AFTER `remote_status`,
|
||||
ADD COLUMN `range_user_json` text NULL COMMENT '获客链接可用成员 userid JSON' AFTER `remote_create_time`,
|
||||
ADD COLUMN `range_department_json` text NULL COMMENT '获客链接可用企微部门 ID JSON' AFTER `range_user_json`,
|
||||
ADD COLUMN `skip_verify` tinyint unsigned NOT NULL DEFAULT 0 AFTER `range_department_json`,
|
||||
ADD COLUMN `priority_option_json` text NULL AFTER `skip_verify`,
|
||||
ADD COLUMN `remote_snapshot` mediumtext NULL AFTER `priority_option_json`,
|
||||
ADD COLUMN `last_sync_time` int unsigned NOT NULL DEFAULT 0 AFTER `remote_snapshot`,
|
||||
ADD COLUMN `sync_error` varchar(500) NOT NULL DEFAULT '' AFTER `last_sync_time`,
|
||||
ADD UNIQUE KEY `uk_remote_link_id` (`remote_link_id`);
|
||||
@@ -0,0 +1,66 @@
|
||||
-- 企业微信获客助手:客户归因、累计收消息数与回调重试审计
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `zyt_qywx_customer_acquisition_customer` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`promotion_link_id` int unsigned NOT NULL DEFAULT 0 COMMENT '本地 qywx_promotion_link.id',
|
||||
`link_id` varchar(128) NOT NULL DEFAULT '' COMMENT '企业微信获客链接 ID',
|
||||
`external_userid` varchar(128) NOT NULL DEFAULT '',
|
||||
`userid` varchar(128) NOT NULL DEFAULT '' COMMENT '接待成员企业微信 userid',
|
||||
`owner_admin_id` int unsigned NOT NULL DEFAULT 0 COMMENT 'userid 对应后台管理员 ID,0 为未映射',
|
||||
`dept_id` int unsigned NOT NULL DEFAULT 0,
|
||||
`state` varchar(255) NOT NULL DEFAULT '',
|
||||
`chat_status` tinyint unsigned NOT NULL DEFAULT 0,
|
||||
`recv_msg_cnt` int unsigned NOT NULL DEFAULT 0 COMMENT 'get_chat_info 返回的累计值,只覆盖/max,不累加',
|
||||
`message_count_known` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '1已在 ChatKey 有效期内取得精确累计数,0仅有聊天状态',
|
||||
`first_acquired_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`last_chat_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`last_sync_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`raw_snapshot` mediumtext NULL,
|
||||
`create_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`update_time` int unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_link_external_user` (`link_id`,`external_userid`,`userid`),
|
||||
KEY `idx_owner_chat` (`owner_admin_id`,`chat_status`),
|
||||
KEY `idx_dept` (`dept_id`),
|
||||
KEY `idx_local_link` (`promotion_link_id`),
|
||||
KEY `idx_last_chat` (`last_chat_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='企微获客客户归因与消息统计';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `zyt_qywx_customer_acquisition_event` (
|
||||
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
|
||||
`event_key` char(64) NOT NULL COMMENT '回调稳定字段 SHA-256 幂等键',
|
||||
`change_type` varchar(64) NOT NULL DEFAULT '',
|
||||
`chat_key` varchar(512) NOT NULL DEFAULT '',
|
||||
`link_id` varchar(128) NOT NULL DEFAULT '',
|
||||
`external_userid` varchar(128) NOT NULL DEFAULT '',
|
||||
`userid` varchar(128) NOT NULL DEFAULT '',
|
||||
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0处理中 1成功 2待重试 3终态失败(过期或无效)',
|
||||
`attempts` smallint unsigned NOT NULL DEFAULT 0,
|
||||
`event_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`expire_time` int unsigned NOT NULL DEFAULT 0 COMMENT 'ChatKey 硬截止时间',
|
||||
`next_retry` int unsigned NOT NULL DEFAULT 0,
|
||||
`error_message` varchar(1000) NOT NULL DEFAULT '',
|
||||
`raw_json` mediumtext NULL,
|
||||
`create_time` int unsigned NOT NULL DEFAULT 0,
|
||||
`update_time` int unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_event_key` (`event_key`),
|
||||
KEY `idx_retry` (`status`,`next_retry`,`expire_time`),
|
||||
KEY `idx_chat_key` (`chat_key`(191)),
|
||||
KEY `idx_event_time` (`event_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='企微获客回调幂等与失败重试审计';
|
||||
|
||||
-- 依赖系统层每分钟执行 php think crontab;本任务自身也按每分钟调度,确保不浪费 ChatKey 30 分钟窗口。
|
||||
INSERT INTO `zyt_dev_crontab` (
|
||||
`name`, `type`, `system`, `remark`, `command`, `params`,
|
||||
`status`, `expression`, `create_time`, `update_time`
|
||||
)
|
||||
SELECT
|
||||
'重试企微获客会话回调', 1, 0,
|
||||
'重试 customer_start_chat/message_from_customer 的 get_chat_info;30 分钟后明确 failed_expired',
|
||||
'qywx:retry-customer-acquisition-events', '', 1, '* * * * *', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `zyt_dev_crontab`
|
||||
WHERE `command` = 'qywx:retry-customer-acquisition-events' AND `delete_time` IS NULL
|
||||
);
|
||||
Reference in New Issue
Block a user