|
|
@@ -67,10 +67,51 @@
|
|
|
from tz_points_record where order_number = #{orderNumber} and points_type =#{pointsType} order by expiry_date desc
|
|
|
</select>
|
|
|
<select id="findPage" resultType="com.yami.shop.bean.model.PointsRecord">
|
|
|
- select id,user_id,channel_id,order_number,points_id,`code`,parent_code,points,variable_points,points_type,points_audit,expiry_date,creation_date,currently_available_points from tz_points_record where channel_id = #{platform} and user_id = #{userId}
|
|
|
+ select * from (
|
|
|
+
|
|
|
+ select id,user_id,channel_id,order_number,points_id,`code`,parent_code,points,variable_points,points_type,points_audit,expiry_date,creation_date,currently_available_points from tz_points_record where channel_id = #{platform} and user_id = #{userId}
|
|
|
UNION ALL
|
|
|
- SELECT id,user_id,channel_id,order_number,points_id,`code`,parent_code,(points-IFNULL(variable_points,0)) AS points,variable_points, 4 as points_type,points_audit,expiry_date,creation_date,currently_available_points from tz_points_record where channel_id = #{platform} and user_id = #{userId} and expiry_date <=NOW() and points-IFNULL(variable_points,0) >0
|
|
|
- order by creation_date DESC
|
|
|
+ SELECT id,user_id,channel_id,order_number,points_id,`code`,parent_code,(points-IFNULL(variable_points,0)) AS points,variable_points, 4 as points_type,points_audit,expiry_date,creation_date,currently_available_points from tz_points_record where channel_id = #{platform} and user_id = #{userId} and expiry_date <=NOW() and points-IFNULL(variable_points,0) >0 and points_type =3
|
|
|
+
|
|
|
+ ) a
|
|
|
+ order by a.creation_date DESC,a.order_number
|
|
|
+
|
|
|
+ </select>
|
|
|
+ <select id="findByExpiredPoints" resultType="com.yami.shop.bean.model.PointsRecord">
|
|
|
+ select * from (
|
|
|
+ SELECT id,user_id,channel_id,null as order_number,points_id,`code`,parent_code,
|
|
|
+ (GREATEST(
|
|
|
+ SUM(
|
|
|
+ CASE WHEN expiry_date =#{today} and creation_date < #{today} THEN
|
|
|
+ CASE
|
|
|
+ WHEN points_type = 1 OR points_type = 3 THEN points
|
|
|
+ WHEN points_type = 2 THEN -variable_points
|
|
|
+ ELSE 0
|
|
|
+ END
|
|
|
+ ELSE 0 END
|
|
|
+ ),
|
|
|
+ 0
|
|
|
+ ) -- 今天之前已过期的 =0
|
|
|
+ - GREATEST(
|
|
|
+ SUM(
|
|
|
+ CASE WHEN expiry_date = #{yesterday} and creation_date < #{yesterday} THEN
|
|
|
+ CASE
|
|
|
+ WHEN points_type = 1 OR points_type = 3 THEN points
|
|
|
+ WHEN points_type = 2 THEN -variable_points
|
|
|
+ ELSE 0
|
|
|
+ END
|
|
|
+ ELSE 0 END
|
|
|
+ ),
|
|
|
+ 0
|
|
|
+ ) -- 昨天之前已过期的
|
|
|
+ -
|
|
|
+ GREATEST(
|
|
|
+ SUM(CASE WHEN points_type = 3 and creation_date >= #{yesterday} and creation_date < #{today} and expiry_date = #{yesterday} THEN points ELSE 0 END),
|
|
|
+ 0
|
|
|
+ ) -- 昨天过期退款的金额
|
|
|
+ ) as
|
|
|
+ points,variable_points, 4 as points_type,points_audit,expiry_date,expiry_date as creation_date,currently_available_points from tz_points_record where expiry_date =#{today} GROUP BY user_id ,channel_id
|
|
|
+ ) a where a.points>0
|
|
|
</select>
|
|
|
|
|
|
</mapper>
|