WebShareProfitRecordMapper.xml
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sibu.orderHelper.integral.web.dao.WebShareProfitRecordDao">
<sql id="shareProfitRecordSql">
share_user_id, buyer_user_id, order_id, order_code, profit_money, profit_status, product_id, product_price,product_share_percentage, product_amount,profit_dt,order_dt,create_dt
</sql>
<resultMap type="com.sibu.orderHelper.integral.model.IMWebShareProfitRecord" id="shareProfitRecordMap">
<id column="id" property="id" />
<result column="share_user_id" property="shareUserId" />
<result column="buyer_user_id" property="buyerUserId" />
<result column="order_id" property="orderId" />
<result column="order_code" property="orderCode" />
<result column="profit_money" property="productPrice" />
<result column="refund_money" property="refundMoney" />
<result column="profit_status" property="profitStatus" />
<result column="product_id" property="productId" />
<result column="product_price" property="productPrice" />
<result column="product_share_percentage" property="productSharePercentage" />
<result column="product_amount" property="productAmount" />
<result column="order_dt" property="orderDt" />
<result column="refund_dt" property="refundDt" />
<result column="create_dt" property="createDt" />
<result column="update_dt" property="updateDt" />
<result column="settlement_dt" property="settlementDt" />
</resultMap>
<select id="getShareProfitRecordById" parameterType="java.lang.String" resultMap="shareProfitRecordMap">
SELECT * FROM t_share_profit_record
WHERE order_id=#{orderId}
</select>
<select id="totalShareProfitRecord" resultType="java.lang.Integer" parameterType="java.util.Map">
SELECT IFNULL(SUM(id),0) AS total FROM t_share_profit_record
WHERE order_id=#{orderId}
</select>
<insert id="insertShareProfitRecord" parameterType="com.sibu.orderHelper.integral.model.IMWebShareProfitRecord" >
insert into t_share_profit_record (share_user_id, buyer_user_id, order_id, order_code, refund_money, product_id, product_price,
product_share_percentage, product_amount,order_dt,refund_dt,create_dt,profit_status
)
values (#{shareUserId,jdbcType=VARCHAR}, #{buyerUserId,jdbcType=VARCHAR},
#{orderId,jdbcType=VARCHAR}, #{orderCode,jdbcType=VARCHAR}, #{refundMoney},
#{productId,jdbcType=VARCHAR}, #{productPrice}, #{productSharePercentage},
#{productAmount},#{orderDt},#{refundDt},now(),#{profitStatus}
)
</insert>
<update id="updateShareProfitRecord" parameterType="java.util.Map">
update t_share_profit_record
set refund_money = #{refundMoney}, update_dt=now(),profit_status=#{profitStatus}
WHERE order_id=#{orderId} limit 1
</update>
<!--查询收益总额 待结算总金额-->
<select id="selectTotalProfitAmount" parameterType="java.util.Map" resultType="java.math.BigDecimal">
select sum(profit_money-refund_money) from `t_share_profit_record` WHERE profit_status=1 AND create_dt < #{createDt};
</select>
<!--查询收益总额 待结算总金额 根据用户-->
<select id="selectTotalProfitMoney" parameterType="java.util.Map" resultType="java.math.BigDecimal">
select sum(profit_money-refund_money) from `t_share_profit_record` WHERE profit_status=1 AND create_dt < #{createDt} AND share_user_id = #{memberId};
</select>
<!--查询某月收益总额 某月预估奖励总金额-->
<select id="selectMonthProfitAmount" parameterType="java.util.Map" resultType="java.math.BigDecimal">
select sum(profit_money-refund_money) from `t_share_profit_record` WHERE profit_status =1 AND create_dt BETWEEN #{startDt} and #{endDt};
</select>
<!--查询待提现总金额-->
<select id="selectHasWithdrawSum" parameterType="java.util.Map" resultType="java.math.BigDecimal">
select sum(amount) from t_withdraw_record where status in(1,2)
</select>
<!-- 查询某月奖励订单付款笔数 -->
<select id="countOrderPaymentPens" parameterType="java.util.Map" resultType="java.lang.Integer">
SELECT COUNT(order_code) FROM t_share_profit_record
WHERE profit_status=1 AND create_dt BETWEEN #{startDt} and #{endDt};
</select>
<!-- 分享奖励排名 -->
<select id="sharingRewardRankings" parameterType="java.util.Map" resultMap="shareRewardsRecordMap">
SELECT * FROM im_share_rewards_record
where withdraw_status=1
<if test="phone != null and phone != ''">
and m.phone=#{phone}
</if>
<if test="nickName != null and nickName != ''">
and m.nick_name like concat('%',#{nickName},'%')
</if>
<if test="idCard != null and idCard != ''">
and m.id_card=#{idCard}
</if>
ORDER BY accumulative_amount_of_reward DESC,accumulative_amount_of_cash DESC,freezing_amount DESC
limit ${pageNow}, ${pageSize}
</select>
<select id="totalSharingRewardRankings" resultType="java.lang.Integer" parameterType="map">
SELECT count(*) FROM im_share_rewards_record
where withdraw_status=1
<if test="phone != null and phone != ''">
and m.phone=#{phone}
</if>
<if test="nickName != null and nickName != ''">
and m.nick_name like concat('%',#{nickName},'%')
</if>
<if test="idCard != null and idCard != ''">
and m.id_card=#{idCard}
</if>
</select>
<!-- 查询分享奖励排名 -->
<select id="selectSharingRewardRankings" resultMap="shareRewardsRecordMap">
SELECT * FROM im_share_rewards_record WHERE withdraw_status=1
</select>
<!-- 批量删除分享奖励 -->
<delete id="batchDeleteShareRewardsRecord" parameterType="java.util.List">
DELETE FROM im_share_rewards_record WHERE withdraw_status=1 and id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<insert id="insertShareRewardsRecord" parameterType="com.sibu.orderHelper.integral.reponse.ShareRewardsRecordResponse" >
insert into im_share_rewards_record (id, name, phone, wechat, id_card,
accumulative_amount_of_reward, accumulative_amount_of_cash,
freezing_amount, withdraw_status,create_dt
)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{wechat,jdbcType=VARCHAR}, #{idCard,jdbcType=VARCHAR},
#{accumulativeAmountOfReward}, #{accumulativeAmountOfCash}, #{freezingAmount},
1,now()
)
</insert>
<resultMap type="com.sibu.orderHelper.integral.reponse.ShareRewardsRecordResponse" id="shareRewardsRecordMap">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="phone" property="phone" />
<result column="wechat" property="wechat" />
<result column="id_card" property="idCard" />
<result column="accumulative_amount_of_reward" property="accumulativeAmountOfReward" />
<result column="accumulative_amount_of_cash" property="accumulativeAmountOfCash" />
<result column="freezing_amount" property="freezingAmount" />
<result column="withdraw_status" property="withdrawStatus" />
<result column="create_dt" property="createDt" />
</resultMap>
<!-- 分享奖励排名:提现人累计提现金额 -->
<select id="sharingRewardToAmount" resultMap="amountResultMap">
SELECT m.nick_name,m.phone,m.wechat,m.id_card,
SUM(amount) AS accumulativeAmountOfCash FROM `t_withdraw_record` r
INNER JOIN `t_member_info` m ON r.`member_id` =m.`member_id`
WHERE r.STATUS IN(1,2) AND m.id_card != ''
GROUP BY m.nick_name,m.phone,m.wechat,m.id_card
</select>
<!-- 分享奖励排名:提现人累计奖励金额 -->
<select id="sharingRewardToAccumulativeAmountOfReward" resultMap="amountResultMap">
SELECT m.nick_name,m.phone,m.wechat,m.id_card,
SUM(profit_money-refund_money) AS accumulativeAmountOfReward FROM
t_share_profit_record spr
INNER JOIN `t_member_info` m ON spr.share_user_id =m.`member_id`
WHERE spr.profit_status =1 AND m.id_card != ''
GROUP BY m.nick_name,m.phone,m.wechat,m.id_card
</select>
<!-- 分享奖励排名:提现人冻结金额 -->
<select id="sharingRewardToFreezingAmount" resultMap="amountResultMap">
SELECT m.nick_name,m.phone,m.wechat,m.id_card,
SUM(profit_money-refund_money) AS freezingAmount FROM t_share_profit_record spr
INNER JOIN `t_member_info` m ON spr.share_user_id =m.`member_id`
WHERE spr.profit_status =1 AND settlement_dt IS NULL AND m.id_card != ''
GROUP BY m.nick_name,m.phone,m.wechat,m.id_card
</select>
<resultMap type="com.sibu.orderHelper.integral.reponse.ShareAmountResponse" id="amountResultMap">
<result column="phone" property="phone" />
<result column="nick_name" property="nickName" />
<result column="wechat" property="wechat" />
<result column="id_card" property="idCard" />
<result column="accumulativeAmountOfReward" property="accumulativeAmountOfReward" />
<result column="accumulativeAmountOfCash" property="accumulativeAmountOfCash" />
<result column="freezingAmount" property="freezingAmount" />
</resultMap>
<!--更新订单结算时间-->
<update id="updateShareProfitRecordSettlementDt">
UPDATE t_share_profit_record SET settlement_dt=NOW()
WHERE profit_status=1 AND profit_dt >0
AND <![CDATA[ profit_dt < #{endDT} ]]>
</update>
<resultMap type="com.sibu.orderHelper.integral.reponse.ShowShareRewardResponse" id="sharingRewardResultMap">
<id column="id" property="id" />
<result column="member_id" property="memberId" />
<result column="partner_trade_no" property="partnerTradeNo" />
<result column="open_id" property="openId" />
<result column="amount" property="amount" />
<result column="user_name" property="userName" />
<result column="pay_desc" property="payDesc" />
<result column="pay_dt" property="payDt" />
<result column="create_dt" property="createDt" />
<result column="status" property="status" />
<result column="fail_code" property="failCode" />
<result column="operator" property="operator" />
<result column="phone" property="phone" />
<result column="nick_name" property="nickName" />
<result column="wechat" property="wechat" />
<result column="id_card" property="idCard" />
<result column="accumulativeAmountOfReward" property="accumulativeAmountOfReward" />
<result column="accumulativeAmountOfCash" property="accumulativeAmountOfCash" />
<result column="freezingAmount" property="freezingAmount" />
</resultMap>
</mapper>