Helius
2021-06-16 4e51778362c2130598a4c73ec4cebe6629dbc53f
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<?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.xzx.gc.pay.mapper.PayInfoMapper">
    <resultMap id="PayMap" type="com.xzx.gc.model.pay.PayInfoVo">
        <result column="pay_order_id" jdbcType="VARCHAR" property="payOrderId"/>
        <result column="order_id" jdbcType="VARCHAR" property="orderId"/>
        <result column="create_user_id" jdbcType="VARCHAR" property="createUserId"/>
        <result column="account_id" jdbcType="VARCHAR" property="accountId"/>
        <result column="create_time" jdbcType="VARCHAR" property="createTime"/>
        <result column="pay_type" jdbcType="VARCHAR" property="payType"/>
        <result column="open_id" jdbcType="VARCHAR" property="openId"/>
    </resultMap>
 
    <resultMap id="AccountMap" type="com.xzx.gc.model.user.AccountVo">
        <result column="account_id" jdbcType="VARCHAR" property="accountId"/>
        <result column="account_name" jdbcType="VARCHAR" property="accountName"/>
        <result column="user_id" jdbcType="VARCHAR" property="userId"/>
        <result column="pay_password" jdbcType="VARCHAR" property="payPassword"/>
        <result column="freeze_money" jdbcType="VARCHAR" property="freezeMoney"/>
        <result column="withdraw_money" jdbcType="VARCHAR" property="withdrawMoney"/>
        <result column="overdraft_limit" jdbcType="VARCHAR" property="overdraftLimit"/>
        <result column="lock_time" jdbcType="VARCHAR" property="lockTime"/>
    </resultMap>
 
    <!-- 支付信息录入 -->
    <insert id="payInfoAdd" parameterType="map">
        insert into xzx_pay_info(pay_order_id,order_id,create_user_id,money,
        account_id,pay_type,open_id,status,create_time,fee)
        values (#{payOrderId},#{orderId},#{createUserId},#{money},
        #{accountId},#{payType},#{openId},#{status},#{createTime},#{fee} )
    </insert>
 
    <insert id="payRequestInfoAdd" parameterType="map">
        insert into xzx_pay_request_info(pay_order_id,order_id,create_user_id,money,
        account_id,pay_type,open_id,status,create_time,account_bind_id)
        values (#{payOrderId},#{orderId},#{createUserId},#{money},
        #{accountId},#{payType},#{openId},#{status},#{createTime},#{accountBindId} )
    </insert>
 
    <!-- 查询我的环保金 -->
    <select id="queryMyMoney" parameterType="map" resultMap="AccountMap">
        SELECT a.user_id,a.account_name,a.freeze_money,a.money,a.account_id,
        a.withdraw_money,a.overdraft_limit,a.lock_time,a.pay_password
        FROM xzx_account_info a
        where del_flag=0 and is_prohibit='0'
        <if test="userId!=null and userId!=''">
            and a.user_id=#{userId}
        </if>
        <if test="createUserId!=null and createUserId!=''">
            and a.user_id=#{createUserId}
        </if>
    </select>
 
 
    <!-- 回收员支付环保金  订单创建人入账 -->
    <update id="updateMyMoneyByOrder" parameterType="map">
        update xzx_account_info
        set money = cast((cast(money as DECIMAL(9,2))+#{money}) as CHAR)
        where user_id=#{userId} and del_flag=0 and is_prohibit='0'
    </update>
 
    <!-- 支付信息查询 -->
    <select id="queryPayInfo" parameterType="map" resultMap="PayMap">
        SELECT a.pay_order_id,a.order_id,a.money,a.account_id,
        a.pay_type,a.create_time,a.create_user_id,a.status,a.fee
        FROM xzx_pay_info a
        where 1=1
        <if test="createUserId!=null and createUserId!=''">
            and a.create_user_id=#{createUserId}
        </if>
        <if test="payOrderId!=null and payOrderId!=''">
            and a.pay_order_id=#{payOrderId}
        </if>
 
    </select>
 
    <select id="queryPayRequestInfo" parameterType="map" resultMap="PayMap">
        SELECT a.pay_order_id,a.order_id,a.money,a.account_id,
        a.pay_type,a.create_time,a.create_user_id,a.status
        FROM xzx_pay_request_info a
        where 1=1
        <if test="createUserId!=null and createUserId!=''">
            and a.create_user_id=#{createUserId}
        </if>
        <if test="payOrderId!=null and payOrderId!=''">
            and a.pay_order_id=#{payOrderId}
        </if>
 
    </select>
 
    <!-- 提现次数查询(一天只能提现一次) -->
    <select id="queryWithdrawInfo" parameterType="map" resultMap="PayMap">
        SELECT a.pay_order_id,a.order_id,a.money,
        a.pay_type,a.create_time,a.account_id
        FROM xzx_pay_request_info a
        where a.create_user_id=#{createUserId} and a.pay_type='4' and (status!=2 or  pay_flag!=3)
        and DATE_FORMAT(a.create_time,'%Y-%m-%d') =current_date
    </select>
    <!--提现记录审核 取状态不为2的记录-->
    <insert id="withdrawInfoVerify" parameterType="map">
        insert into xzx_pay_info(pay_order_id,order_id,create_user_id,money,
        account_id,pay_type,open_id,status,create_time)
        select pay_order_id,order_id,create_user_id,money,
        account_id,pay_type,open_id,"3",create_time
        from xzx_pay_request_info
        where pay_order_id=#{payOrderId} and status!="2"
    </insert>
 
    <!--提现记录更新为审核状态  2为审核-->
    <update id="updateWithdrawStatus" parameterType="map">
        update xzx_pay_request_info set status=#{status}
        where pay_order_id=#{payOrderId}
    </update>
 
    <!-- 充值记录更新为2(已支付) -->
    <update id="updatePayInfoStatus" parameterType="map">
        update xzx_pay_info set status=#{status}
        where pay_order_id=#{payOrderId}
    </update>
 
    <select id="findForWeekByUserIdAndType" resultType="com.xzx.gc.entity.PayInfo">
        SELECT
            *
        FROM
            xzx_pay_info
        WHERE
            YEARWEEK( date_format( create_time, '%Y-%m-%d' ), 1 ) = YEARWEEK( now( ), 1 )
            AND create_user_id = #{userId}
            AND pay_type = #{payType}
            AND (`status` =2 or status=5)
    </select>
    <select id="findPayMethod" resultType="com.xzx.gc.entity.AccountBindInfo">
        SELECT
            b.account_type AS accountType,
            b.account_number AS accountNumber,
            b.id,
            b.account_name AS accountName,
            b.bank_name AS bankName
        FROM
            xzx_pay_request_info a
            INNER JOIN xzx_account_bind_info b ON a.account_bind_id = b.id
        WHERE
            a.pay_type = '4'
            AND a.create_user_id = #{userId}
            AND b.del_flag = 0
        ORDER BY
            a.create_time DESC  limit 1
    </select>
 
    <insert id="addPayInfo">
        INSERT INTO `xzx_pay_info` (`pay_order_id`, `order_id`, `create_user_id`, `money`,
                                    `account_id`, `pay_type`, `open_id`, `status`, `create_time`, `check_num`, `pay_img`, `pay_time`)
        VALUES (#{payOrderId}, NULL, #{createUserId}, #{money}, #{accountId},
                               '1', NULL, #{status}, SYSDATE(), NULL, #{payImg}, #{payTime})
    </insert>
 
    <select id="queryRechangeMoney" resultType="java.lang.String">
        select sum(k.money) from ( select IFNULL(sum(a.money),0) as money
        from xzx_pay_info a
        left join xzx_user_info b on a.create_user_id=b.user_id
        left join xzx_user_other_info c on a.create_user_id=c.user_id
        where 1=1
        <if test="status!= null and status.size() != 0">
            and a.status in
            <foreach collection="status" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="payType!= null and payType!=''">
            and a.pay_type=#{payType}
        </if>
        <if test="startTime!= null and startTime!=''">
            and a.create_time<![CDATA[>= ]]>#{startTime}
        </if>
        <if test="endTime!= null and endTime!=''">
            and a.create_time<![CDATA[<= ]]>#{endTime}
        </if>
        <if test="partnerIds!= null and partnerIds.size() != 0">
            and c.partner_id in
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        )k
    </select>
 
 
    <select id="queryRechangeApiList" parameterType="com.xzx.gc.model.admin.MoneyModel" resultType="com.xzx.gc.model.admin.MoneyModel">
        select a.pay_order_id, a.create_time, a.money, IFNULL(b.nick_name,c.name) as nickName,
        b.user_type,IFNULL(b.mobile_phone,c.mobile_phone) as mobilePhone,a.status, b.name,a.pay_time,a.create_user_id as createUserId,
        IFNULL((select d.role_name from xzx_user_role_info d where role_code= c.user_type limit 1),'普通用户') as roleName,
        e.partner_name as partnerName,e.mobile_phone as partnerPhone,e.partner_type as partnerType,a.pay_img,a.unpass_reason,a.fee,c.del_flag as delFlag
        from xzx_pay_info a
        left join xzx_user_info b on a.create_user_id=b.user_id
        left join xzx_user_other_info c on a.create_user_id=c.user_id
        left join xzx_city_partner e on a.create_user_id=e.user_id
        where 1=1
        <if test="status!= null and status != ''">
            and a.status=#{status}
        </if>
        <if test="payType!= null and payType!=''">
            and a.pay_type=#{payType}
        </if>
        <if test="nickName!= null and nickName!=''">
            and (from_base64(b.nick_name) like concat("%",#{nickName},"%") or b.mobile_phone like concat("%",#{nickName},"%") or c.mobile_phone like concat("%",#{nickName},"%")
            or e.mobile_phone like concat("%",#{nickName},"%") or e.partner_name like concat("%",#{nickName},"%")  or c.name like concat("%",#{nickName},"%") )
        </if>
        <if test="name!= null and name != ''">
            and b.name=#{name}
        </if>
        <if test="startTime!= null and startTime!=''">
            and a.create_time<![CDATA[>= ]]>#{startTime}
        </if>
        <if test="endTime!= null and endTime!=''">
            and a.create_time<![CDATA[<= ]]>#{endTime}
        </if>
        <if test="partnerIds!= null and partnerIds.size() != 0">
            and c.partner_id in
            <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
 
        order by a.create_time desc
    </select>
 
 
    <select id="queryRechangeApiDetail" parameterType="com.xzx.gc.model.admin.PayInfoModel" resultType="com.xzx.gc.model.admin.PayInfoModel">
        select a.*,
            b.nick_name as nickName,
            b.user_type as userType,
            b.mobile_phone as mobilePhone,
            IFNULL((select d.role_name from xzx_user_role_info d where d.role_code= f.user_type),'普通用户') as roleName,
            IFNULL(f.name,b.name) as name
        from xzx_pay_info a
            LEFT JOIN xzx_user_info b ON a.create_user_id = b.user_id
            LEFT JOIN xzx_user_other_info f ON a.create_user_id = f.user_id
        where a.pay_order_id=#{payOrderId}
              and a.create_user_id = b.user_id
    </select>
 
 
    <select id="queryPayInfoById" resultType="com.xzx.gc.model.admin.PayInfoModel">
        select *
        from xzx_pay_info
        where pay_order_id = #{payOrderId}
    </select>
 
    <update id="updatePayInfoPass">
        update xzx_pay_info set
        status=#{status}
        <if test="unpassReason != null and unpassReason != ''">
            , unpass_reason=#{unpassReason}
        </if>
        where pay_order_id=#{payOrderId}
    </update>
 
    <select id="scoreList" resultType="com.xzx.gc.model.pay.PayScoreResPerDTO">
        SELECT
            a.pay_order_id,
            a.create_time,
            a.money,
            a.`status`,
            b.channel_type,
            b.role_type,
            b.new_plat_score,
            c.rela_name,
            c.rela_phone
        FROM
            xzx_pay_info a
            INNER JOIN xzx_account_score_log b ON a.pay_order_id = b.pay_id
            LEFT JOIN xzx_order_info c ON b.order_id = c.order_id
            LEFT JOIN xzx_user_info d on b.create_user_id=d.user_id
        WHERE
            a.pay_type = '17'
            <if test="status != null and status != ''">
                and a.status=#{status}
            </if>
            <if test="partnerId != null and partnerId != ''">
                and locate(#{partnerId} ,d.partner_id)>0
            </if>
            <if test="channelType != null">
              and b.channel_type=#{channelType}
            </if>
            <if test="roleType != null">
                and b.role_type=#{roleType}
            </if>
        order by a.create_time desc
    </select>
 
 
</mapper>