add point totalConsumed
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
ALTER TABLE `gao_point_account`
|
||||
ADD COLUMN `total_consumed` BIGINT NOT NULL DEFAULT 0 COMMENT '累计消耗积分' AFTER `total_earned`;
|
||||
|
||||
UPDATE `gao_point_account` account
|
||||
LEFT JOIN (
|
||||
SELECT `account_id`, SUM(-`point_delta`) AS `total_consumed`
|
||||
FROM `gao_point_ledger`
|
||||
WHERE `change_type` = 'CONSUME'
|
||||
AND `point_delta` < 0
|
||||
AND `deleted_at` IS NULL
|
||||
GROUP BY `account_id`
|
||||
) ledger ON ledger.`account_id` = account.`id`
|
||||
SET account.`total_consumed` = COALESCE(ledger.`total_consumed`, 0);
|
||||
@@ -12,9 +12,9 @@
|
||||
|
||||
<insert id="insertIfAbsent">
|
||||
INSERT INTO `gao_point_account` (
|
||||
`id`, `store_id`, `customer_id`, `balance`, `total_earned`, `total_revoked`, `total_adjusted`, `version`, `created_at`, `updated_at`, `deleted_at`
|
||||
`id`, `store_id`, `customer_id`, `balance`, `total_earned`, `total_consumed`, `total_revoked`, `total_adjusted`, `version`, `created_at`, `updated_at`, `deleted_at`
|
||||
) VALUES (
|
||||
#{account.id}, #{account.storeId}, #{account.customerId}, #{account.balance}, #{account.totalEarned}, #{account.totalRevoked}, #{account.totalAdjusted}, #{account.version}, #{account.createdAt}, #{account.updatedAt}, #{account.deletedAt}
|
||||
#{account.id}, #{account.storeId}, #{account.customerId}, #{account.balance}, #{account.totalEarned}, #{account.totalConsumed}, #{account.totalRevoked}, #{account.totalAdjusted}, #{account.version}, #{account.createdAt}, #{account.updatedAt}, #{account.deletedAt}
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE `id` = `id`
|
||||
</insert>
|
||||
@@ -33,6 +33,7 @@
|
||||
SET
|
||||
`balance` = `balance` + #{delta},
|
||||
`total_earned` = `total_earned` + #{totalEarnedDelta},
|
||||
`total_consumed` = `total_consumed` + #{totalConsumedDelta},
|
||||
`total_revoked` = `total_revoked` + #{totalRevokedDelta},
|
||||
`total_adjusted` = `total_adjusted` + #{totalAdjustedDelta},
|
||||
`version` = `version` + 1,
|
||||
|
||||
Reference in New Issue
Block a user