INSERT INTO mall_tier_benefit
(tier_code, name, tier_rank, min_spend_12m, min_orders_12m, discount_rate, free_ship_threshold,
point_earn_rate, priority_slot, birthday_coupon, exclusive_events, color, active)
VALUES
(#{tierCode}, #{name}, #{tierRank}, COALESCE(#{minSpend12m},0), COALESCE(#{minOrders12m},0),
COALESCE(#{discountRate},0), #{freeShipThreshold}, COALESCE(#{pointEarnRate},1.0),
COALESCE(#{prioritySlot},FALSE), COALESCE(#{birthdayCoupon},FALSE), COALESCE(#{exclusiveEvents},FALSE),
#{color}, COALESCE(#{active},TRUE))
UPDATE mall_tier_benefit SET
name=#{name}, tier_rank=#{tierRank},
min_spend_12m=COALESCE(#{minSpend12m},min_spend_12m),
min_orders_12m=COALESCE(#{minOrders12m},min_orders_12m),
discount_rate=COALESCE(#{discountRate},discount_rate),
free_ship_threshold=#{freeShipThreshold},
point_earn_rate=COALESCE(#{pointEarnRate},point_earn_rate),
priority_slot=COALESCE(#{prioritySlot},priority_slot),
birthday_coupon=COALESCE(#{birthdayCoupon},birthday_coupon),
exclusive_events=COALESCE(#{exclusiveEvents},exclusive_events),
color=#{color}, active=COALESCE(#{active},active), updated_at=NOW()
WHERE id=#{id}
DELETE FROM mall_tier_benefit WHERE id=#{id}
UPDATE mall_member SET tier = #{tier} WHERE username = #{username}
INSERT INTO mall_point_ledger (owner, entry_type, points, order_no, reason, expire_at)
VALUES (#{owner}, #{entryType}, #{points}, #{orderNo}, #{reason}, #{expireAt})