<?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.ruoyi.dk.mapper.CustomerMapper">
    <update id="incsAmount">
        update dk_customer
        set account = account + #{totalLoanMoney},
            borrow_account = #{totalLoanMoney},
            repayment_account = repayment_account + #{totalRepayment}
        where id = #{customerId}
    </update>
    <update id="withdraw">
        update dk_customer
        set account = account - #{withdrawAmount}
        where id = #{customerId}
    </update>
    <select id="pageAdmin" resultType="com.ruoyi.dk.dto.admin.resp.CustomerAdminResp">
        select *,t2.allow_signature
        from dk_customer t1
        left join dk_customer_info t2 on t1.id = t2.customer_id
        <where>
            <if test="bo.phoneNumber != null and bo.phoneNumber != ''">
                and t1.phone_number like concat('%',#{bo.phoneNumber},'%')
            </if>
            <if test="bo.userCode != null and bo.userCode != ''">
                and t1.user_code = #{bo.userCode}
            </if>
            <if test="bo.nickName != null and bo.nickName != ''">
                and (t1.nick_name like concat('%',#{bo.nickName},'%') or t2.real_name like concat('%',#{bo.nickName},'%'))
            </if>
        </where>
        order by t1.update_time desc
    </select>
    <select id="exportAdmin" resultType="com.ruoyi.dk.dto.admin.resp.CustomerExportVo">
        select phone_number, nick_name, real_name_auth, loans_flag, withdraw_flag,
               account, borrow_account, repayment_account, withdraw_account,
               status, last_login_ip, last_login_time, update_time,
               customer_id, real_name, card_num, card_front_picture,
               card_back_picture, company_name, company_title, company_phone,
               company_year, company_address, company_address_info,
               customer_address, customer_address_info, kinsfolk_name,
               kinsfolk_phone, kinsfolk_ref, bank_type, back_card_num
        from dk_customer t1
        left join dk_customer_info t2 on t1.id = t2.customer_id
        <where>
            <if test="bo.phoneNumber != null and bo.phoneNumber != ''">
                and t1.phone_number like concat('%',#{bo.phoneNumber},'%')
            </if>
            <if test="bo.userCode != null and bo.userCode != ''">
                and t1.user_code = #{bo.userCode}
            </if>
            <if test="bo.nickName != null and bo.nickName != ''">
                and (t1.nick_name like concat('%',#{bo.nickName},'%') or t2.real_name like concat('%',#{bo.nickName},'%'))
            </if>
        </where>
        order by t1.update_time desc
    </select>
</mapper>
