<?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.yami.shop.dao.ShopWithdrawCashMapper">

  <resultMap id="shopWithdrawCashMap" type="com.yami.shop.bean.model.ShopWithdrawCash">
    <id column="cash_id" property="cashId" />
    <result column="shop_id" property="shopId"/>
    <result column="auditor_id" property="auditorId"/>
    <result column="amount" property="amount"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="auditing_time" property="auditingTime"/>
    <result column="status" property="status"/>
    <result column="remarks" property="remarks"/>
    <result column="shop_name" property="shopName"/>
    <result column="shop_logo" property="shopLogo"/>
  </resultMap>

  <resultMap id="shopWithdrawCashList" type="com.yami.shop.bean.model.ShopWithdrawCash">
    <id column="cash_id" property="cashId" />
    <result column="shop_id" property="shopId"/>
    <result column="auditor_id" property="auditorId"/>
    <result column="amount" property="amount"/>
    <result column="create_time" property="createTime"/>
    <result column="update_time" property="updateTime"/>
    <result column="auditing_time" property="auditingTime"/>
    <result column="status" property="status"/>
    <result column="remarks" property="remarks"/>
    <result column="shop_remarks" property="shopRemarks"/>
    <result column="shop_name" property="shopName"/>
    <result column="shop_logo" property="shopLogo"/>
    <collection property="shopBankCard" ofType="com.yami.shop.bean.model.ShopBankCard">
      <result column="shop_bank_card_id" property="shopBankCardId"/>
      <result column="bank_name" property="bankName"/>
      <result column="opening_bank"  property="openingBank"/>
      <result column="recipient_name"  property="recipientName"/>
      <result column="card_no" jdbcType="VARCHAR" property="cardNo"/>
    </collection>
  </resultMap>
    <select id="pageShopWithdrawCash" resultMap="shopWithdrawCashList">
      SELECT twc.*,tsd.shop_name,tsd.shop_logo,tsd.shop_logo,sbc.* FROM  tz_shop_withdraw_cash twc
      JOIN tz_shop_detail tsd ON tsd.shop_id = twc.shop_id
      JOIN tz_shop_bank_card sbc ON twc.shop_bank_card_id = sbc.shop_bank_card_id
      <where>
        <if test="shopWithdrawCash.shopName != null and shopWithdrawCash.shopName != ''">
          AND tsd.shop_name like concat('%',#{shopWithdrawCash.shopName} ,'%')
        </if>
        <if test="shopWithdrawCash.status != null and shopWithdrawCash.status != ''">
          AND twc.status = #{shopWithdrawCash.status}
        </if>
      </where>
      ORDER BY twc.create_time DESC
    </select>
    <select id="getShopWithdrawCashByShopId" resultType="com.yami.shop.bean.model.ShopWithdrawCash">
      SELECT s.shop_name,sw.settled_amount amount
      FROM tz_shop_wallet sw
      JOIN tz_shop_detail s ON s.shop_id = sw.shop_id
      WHERE sw.shop_id = #{shopId}
    </select>
</mapper>
