|
|
|
@@ -20,4 +20,89 @@ ADD COLUMN `source_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1:A端发卷,2 |
|
|
|
ALTER TABLE `wx_c_user_basic_info` |
|
|
|
MODIFY COLUMN `tenant_id` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '租户ID' AFTER `id`; |
|
|
|
|
|
|
|
update wx_c_user_basic_info set tenant_id = concat(",",final_tenant_id,","); |
|
|
|
update wx_c_user_basic_info set tenant_id = concat(",",final_tenant_id,","); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CREATE DEFINER=`root`@`%` PROCEDURE `move_after_group`(IN tenantIds VARCHAR(125)) |
|
|
|
BEGIN |
|
|
|
|
|
|
|
DECLARE done INT DEFAULT 0; |
|
|
|
DECLARE phonestr VARCHAR(50); |
|
|
|
DECLARE phones CURSOR FOR SELECT phone FROM `wx_c_user_basic_info` WHERE FIND_IN_SET(final_tenant_id,tenantIds) GROUP BY phone HAVING count(1) > 1; |
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET done = -1; |
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; |
|
|
|
|
|
|
|
START TRANSACTION; |
|
|
|
OPEN phones; |
|
|
|
FETCH phones INTO phonestr; |
|
|
|
while done<>1 DO |
|
|
|
BEGIN |
|
|
|
DECLARE done2 int DEFAULT 0; |
|
|
|
DECLARE userid BIGINT; |
|
|
|
DECLARE num INT DEFAULT 0; |
|
|
|
DECLARE oldCuserId BIGINT DEFAULT 0; |
|
|
|
DECLARE newCuserId BIGINT DEFAULT 0; |
|
|
|
|
|
|
|
DECLARE users CURSOR FOR SELECT id FROM `wx_c_user_basic_info` WHERE phone = phonestr and FIND_IN_SET(final_tenant_id,tenantIds) order by active_time DESC; |
|
|
|
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done2 = 1; |
|
|
|
|
|
|
|
OPEN users; |
|
|
|
FETCH users INTO userid; |
|
|
|
WHILE done2 <> 1 DO |
|
|
|
if num = 0 THEN |
|
|
|
SET oldCuserId =userid; |
|
|
|
ELSE |
|
|
|
SET newCuserId =userid; |
|
|
|
|
|
|
|
UPDATE wx_c_user SET user_id = newCuserId WHERE user_id = oldCuserId ; |
|
|
|
UPDATE wx_activity_join SET user_id = newCuserId WHERE user_id = oldCuserId ; |
|
|
|
UPDATE wx_game_action_log SET user_id = newCuserId WHERE user_id = oldCuserId ; |
|
|
|
UPDATE wx_order_group SET user_id = newCuserId WHERE user_id = oldCuserId ; |
|
|
|
UPDATE wx_order_press SET user_id = newCuserId WHERE user_id = oldCuserId ; |
|
|
|
UPDATE wx_question_log SET user_id = newCuserId WHERE user_id = oldCuserId ; |
|
|
|
|
|
|
|
UPDATE wx_c_user_car SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_c_user_from_b SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_coupon_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_credit_history SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_pay_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_refund_order SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
UPDATE wx_score_history SET c_user_id = newCuserId WHERE c_user_id = oldCuserId ; |
|
|
|
|
|
|
|
UPDATE wx_card_spend SET owner_id = newCuserId WHERE owner_id = oldCuserId ; |
|
|
|
UPDATE wx_coupon_order SET owner_id = newCuserId WHERE owner_id = oldCuserId ; |
|
|
|
|
|
|
|
UPDATE wx_credit_history SET operator_id = newCuserId WHERE operator_type in (1,2) and operator_id = oldCuserId ; |
|
|
|
|
|
|
|
UPDATE wx_c_user_basic_info SET poins = (SELECT SUM(poins) FROM wx_c_user_basic_info WHERE id in (oldCuserId,newCuserId)), |
|
|
|
credit = (SELECT SUM(credit) FROM wx_c_user_basic_info WHERE id in (oldCuserId,newCuserId)), |
|
|
|
login_count = (SELECT SUM(login_count) FROM wx_c_user_basic_info WHERE id in (oldCuserId,newCuserId)) |
|
|
|
WHERE id = newCuserId ; |
|
|
|
|
|
|
|
UPDATE wx_c_user_basic_info SET phone = concat(phone,'(作废)',"--",num),`status` = 1 WHERE id = oldCuserId ; |
|
|
|
|
|
|
|
END IF; |
|
|
|
SET num = num +1; |
|
|
|
|
|
|
|
FETCH users INTO userid; |
|
|
|
END WHILE; |
|
|
|
CLOSE users; |
|
|
|
|
|
|
|
END; |
|
|
|
|
|
|
|
FETCH phones INTO phonestr; |
|
|
|
END WHILE; |
|
|
|
CLOSE phones; |
|
|
|
|
|
|
|
IF done = -1 THEN |
|
|
|
ROLLBACK; |
|
|
|
ELSE |
|
|
|
COMMIT; |
|
|
|
END IF; |
|
|
|
END |