feat: implement order relation type tracking
- Add OrderRelationType enum (UNASSIGNED, LEGACY, FIRST, CONTINUED, NEUTRAL) - Create play_clerk_customer_relation table to track first-completed history - Add order_relation_type column to play_order_info - Migrate existing orders to set relation types based on completion history - Update order services to determine relation type on creation - Update order VOs and controllers to expose relation type in API responses - Update clerk performance calculations to account for relation types - Update revenue calculations to distinguish between first and continued orders - Add comprehensive API and unit tests for order relation functionality
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
CREATE TABLE play_clerk_customer_relation (
|
||||
id VARCHAR(64) NOT NULL COMMENT '主键',
|
||||
purchaser_by VARCHAR(64) NOT NULL COMMENT '顾客ID',
|
||||
tenant_id VARCHAR(32) DEFAULT NULL COMMENT '租户ID',
|
||||
accept_by VARCHAR(64) NOT NULL COMMENT '店员ID',
|
||||
has_completed VARCHAR(1) NOT NULL DEFAULT '0' COMMENT '是否有已完成历史 0否 1是',
|
||||
first_completed_order_id VARCHAR(64) DEFAULT NULL COMMENT '首次完成订单ID',
|
||||
first_completed_time DATETIME DEFAULT NULL COMMENT '首次完成时间',
|
||||
created_by VARCHAR(64) DEFAULT NULL COMMENT '创建人',
|
||||
created_time DATETIME DEFAULT NULL COMMENT '创建时间',
|
||||
updated_by VARCHAR(64) DEFAULT NULL COMMENT '更新人',
|
||||
updated_time DATETIME DEFAULT NULL COMMENT '更新时间',
|
||||
deleted TINYINT(1) NOT NULL DEFAULT '0' COMMENT '逻辑删除 1已删除 0未删除',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_clerk_customer_relation (tenant_id, purchaser_by, accept_by)
|
||||
) COMMENT '客户-店员关系(完成历史)';
|
||||
|
||||
INSERT INTO play_clerk_customer_relation (
|
||||
id,
|
||||
purchaser_by,
|
||||
tenant_id,
|
||||
accept_by,
|
||||
has_completed,
|
||||
first_completed_time,
|
||||
created_time,
|
||||
updated_time,
|
||||
deleted
|
||||
)
|
||||
SELECT
|
||||
REPLACE(UUID(), '-', ''),
|
||||
purchaser_by,
|
||||
tenant_id,
|
||||
accept_by,
|
||||
'1',
|
||||
MIN(COALESCE(order_end_time, purchaser_time)),
|
||||
NOW(),
|
||||
NOW(),
|
||||
0
|
||||
FROM play_order_info
|
||||
WHERE order_status = '3'
|
||||
AND purchaser_by IS NOT NULL
|
||||
AND purchaser_by <> ''
|
||||
AND tenant_id IS NOT NULL
|
||||
AND tenant_id <> ''
|
||||
AND accept_by IS NOT NULL
|
||||
AND accept_by <> ''
|
||||
GROUP BY tenant_id, purchaser_by, accept_by;
|
||||
|
||||
ALTER TABLE play_order_info
|
||||
ADD COLUMN order_relation_type VARCHAR(32) NOT NULL DEFAULT 'LEGACY';
|
||||
|
||||
UPDATE play_order_info o
|
||||
LEFT JOIN (
|
||||
SELECT purchaser_by, accept_by, MIN(purchaser_time) AS first_completed_time
|
||||
FROM play_order_info
|
||||
WHERE order_status = '3'
|
||||
GROUP BY purchaser_by, accept_by
|
||||
) h ON o.purchaser_by = h.purchaser_by AND o.accept_by = h.accept_by
|
||||
SET o.order_relation_type = CASE
|
||||
WHEN o.place_type = '1' THEN 'FIRST'
|
||||
WHEN o.accept_by IS NULL OR o.accept_by = '' THEN 'LEGACY'
|
||||
WHEN h.first_completed_time IS NOT NULL AND o.purchaser_time > h.first_completed_time THEN 'CONTINUED'
|
||||
ELSE 'FIRST'
|
||||
END
|
||||
WHERE o.order_relation_type IS NULL
|
||||
OR o.order_relation_type = ''
|
||||
OR o.order_relation_type = 'LEGACY';
|
||||
Reference in New Issue
Block a user