<?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.ssm.manage.mapper.RefundRechargeMapper">
  <resultMap id="BaseResultMap" type="com.ssm.manage.entity.RefundRecharge">
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="refund_num" jdbcType="VARCHAR" property="refundNum" />
    <result column="refund_date" jdbcType="TIMESTAMP" property="refundDate" />
    <result column="store_id" jdbcType="BIGINT" property="storeId" />
    <result column="store_name" jdbcType="VARCHAR" property="storeName" />
    <result column="member_id" jdbcType="BIGINT" property="memberId" />
    <result column="member_name" jdbcType="VARCHAR" property="memberName" />
    <result column="member_identity_card" jdbcType="VARCHAR" property="memberIdentityCard" />
    <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone" />
    <result column="card" jdbcType="VARCHAR" property="card" />
    <result column="recharge_num" jdbcType="VARCHAR" property="rechargeNum" />
    <result column="recharge_type_id" jdbcType="BIGINT" property="rechargeTypeId" />
    <result column="recharge_type_name" jdbcType="VARCHAR" property="rechargeTypeName" />
    <result column="card_recharge_money" jdbcType="DECIMAL" property="cardRechargeMoney" />
    <result column="card_rest_money" jdbcType="DECIMAL" property="cardRestMoney" />
    <result column="card_gift_money" jdbcType="DECIMAL" property="cardGiftMoney" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="discount" jdbcType="DECIMAL" property="discount" />
    <result column="last_consume_time" jdbcType="TIMESTAMP" property="lastConsumeTime" />
    <result column="card_consume_money" jdbcType="DECIMAL" property="cardConsumeMoney" />
    <result column="gift_consume_money" jdbcType="DECIMAL" property="giftConsumeMoney" />
    <result column="rec_refund_money" jdbcType="DECIMAL" property="recRefundMoney" />
    <result column="rec_compensation" jdbcType="DECIMAL" property="recCompensation" />
    <result column="rec_account_id" jdbcType="BIGINT" property="recAccountId" />
    <result column="type_ratio" jdbcType="DECIMAL" property="typeRatio" />
    <result column="sale_one_number" jdbcType="VARCHAR" property="saleOneNumber" />
    <result column="sale_two_number" jdbcType="VARCHAR" property="saleTwoNumber" />
    <result column="sale_three_number" jdbcType="VARCHAR" property="saleThreeNumber" />
    <result column="sale_four_number" jdbcType="VARCHAR" property="saleFourNumber" />
    <result column="sale_one_staff_id" jdbcType="BIGINT" property="saleOneStaffId" />
    <result column="sale_two_staff_id" jdbcType="BIGINT" property="saleTwoStaffId" />
    <result column="sale_three_staff_id" jdbcType="BIGINT" property="saleThreeStaffId" />
    <result column="sale_four_staff_id" jdbcType="BIGINT" property="saleFourStaffId" />
    <result column="sale_one_staff_name" jdbcType="VARCHAR" property="saleOneStaffName" />
    <result column="sale_two_staff_name" jdbcType="VARCHAR" property="saleTwoStaffName" />
    <result column="sale_three_staff_name" jdbcType="VARCHAR" property="saleThreeStaffName" />
    <result column="sale_four_staff_name" jdbcType="VARCHAR" property="saleFourStaffName" />
    <result column="sale_one_identity" jdbcType="VARCHAR" property="saleOneIdentity" />
    <result column="sale_two_identity" jdbcType="VARCHAR" property="saleTwoIdentity" />
    <result column="sale_three_identity" jdbcType="VARCHAR" property="saleThreeIdentity" />
    <result column="sale_four_identity" jdbcType="VARCHAR" property="saleFourIdentity" />
    <result column="sale_one_ratio" jdbcType="DECIMAL" property="saleOneRatio" />
    <result column="sale_two_ratio" jdbcType="DECIMAL" property="saleTwoRatio" />
    <result column="sale_three_ratio" jdbcType="DECIMAL" property="saleThreeRatio" />
    <result column="sale_four_ratio" jdbcType="DECIMAL" property="saleFourRatio" />
    <result column="sale_one_achievement_amount" jdbcType="DECIMAL" property="saleOneAchievementAmount" />
    <result column="sale_two_achievement_amount" jdbcType="DECIMAL" property="saleTwoAchievementAmount" />
    <result column="sale_three_achievement_amount" jdbcType="DECIMAL" property="saleThreeAchievementAmount" />
    <result column="sale_four_achievement_amount" jdbcType="DECIMAL" property="saleFourAchievementAmount" />
    <result column="sale_one_commission_amount" jdbcType="DECIMAL" property="saleOneCommissionAmount" />
    <result column="sale_two_commission_amount" jdbcType="DECIMAL" property="saleTwoCommissionAmount" />
    <result column="sale_three_commission_amount" jdbcType="DECIMAL" property="saleThreeCommissionAmount" />
    <result column="sale_four_commission_amount" jdbcType="DECIMAL" property="saleFourCommissionAmount" />
    <result column="achievement_amount" jdbcType="DECIMAL" property="achievementAmount" />
    <result column="commission_amount" jdbcType="DECIMAL" property="commissionAmount" />
    <result column="manage_staff_id" jdbcType="BIGINT" property="manageStaffId" />
    <result column="manage_staff_name" jdbcType="VARCHAR" property="manageStaffName" />
    <result column="manage_identity" jdbcType="VARCHAR" property="manageIdentity" />
    <result column="manage_number" jdbcType="VARCHAR" property="manageNumber" />
    <result column="refund_type" jdbcType="INTEGER" property="refundType" />
    <result column="refund_gift_money" jdbcType="DECIMAL" property="refundGiftMoney"/>
    <result column="refund_amount" jdbcType="DECIMAL" property="refundAmount" />
    <result column="refund_gift_amount" jdbcType="DECIMAL" property="refundGiftAmount" />
    <result column="audit_date" jdbcType="TIMESTAMP" property="auditDate"/>
  </resultMap>

  <select id="selectList" parameterType="com.ssm.manage.query.RefundOrderResquest" resultMap="BaseResultMap">
    select b.*,a.audit_date from refund_order_list a, refund_recharge b
    where a.store_id = #{storeId, jdbcType = BIGINT}
    and b.store_id = #{storeId, jdbcType = BIGINT}
    and a.refund_num = b.refund_num
    and a.state = #{state, jdbcType = INTEGER}
    <if test="dateStr != null">
      and a.audit_date like concat( #{dateStr, jdbcType = VARCHAR}, '%')
    </if>
  </select>

  <select id="selectLists" parameterType="com.ssm.manage.query.RefundOrderResquest" resultMap="BaseResultMap">
    select b.* from refund_order_list a, refund_recharge b
    where a.store_id = #{storeId, jdbcType = BIGINT}
    and b.store_id = #{storeId, jdbcType = BIGINT}
    and a.state = #{state, jdbcType = INTEGER}
    <if test="dateStr != null">
      and a.refund_date between #{startTime, jdbcType = TIMESTAMP} and #{endTime, jdbcType = TIMESTAMP}
    </if>
    <if test="refundGiftMoney != null">
      and b.refund_gift_money > 0
    </if>
    <if test="recRefundMoney != null">
      and b.rec_refund_money > 0
    </if>
  </select>

  <select id="selectListschia" parameterType="com.ssm.manage.query.RefundOrderResquest" resultMap="BaseResultMap">
    select b.* from refund_order_list a, refund_recharge b
    where a.store_id = #{storeId, jdbcType = BIGINT}
      and b.store_id = #{storeId, jdbcType = BIGINT}
    and a.refund_num = b.refund_num
      and a.refund_date between #{startTime, jdbcType = TIMESTAMP} and #{endTime, jdbcType = TIMESTAMP}
  </select>
    <select id="selectListNew" resultMap="BaseResultMap" >
      select * from refund_recharge where SUBSTR(refund_date,1,7) = #{strDate}
                                      and store_id in <foreach collection="storeIds" item="item" separator="," close=")" open="(">
      #{item}
    </foreach>
    </select>
    <select id="selectFKJByDate" resultType="java.math.BigDecimal" parameterType="com.ssm.manage.query.StoreDailyRequest">
      select sum(ifnull(refund_recharge.refund_gift_money,0)) as refundGifMoney from refund_recharge
          left join refund_order_list on refund_recharge.refund_num = refund_order_list.refund_num
                                                                where refund_order_list.type = 0 and refund_order_list.state = 3
                                                                  and refund_order_list.store_id = #{storeId}
                                                                  and refund_order_list.audit_date between #{startTime} and #{endTime}
    </select>
  <select id="selectFKJByRechargeIn" resultType="java.math.BigDecimal">
        select sum(ifnull(out_gift_consume_money,0)) from recharge_account_outin where state = 1 and in_store_id = #{storeId} and audit_date between #{startTime} and #{endTime}
  </select>
  <select id="selectFKJByRechargeOut" resultType="java.math.BigDecimal">
    select sum(ifnull(out_gift_consume_money,0)) from recharge_account_outin where state = 1 and out_store_id = #{storeId} and audit_date between #{startTime} and #{endTime}
  </select>
  <select id="selectListsByRefundRecharge" parameterType="com.ssm.manage.query.RefundOrderResquest" resultMap="BaseResultMap">
    select b.* from refund_order_list a left join refund_recharge b on a.refund_num = b.refund_num
    where a.store_id = #{storeId, jdbcType = BIGINT}
    and b.store_id = #{storeId, jdbcType = BIGINT}
    and a.state = #{state, jdbcType = INTEGER}
    <if test="dateStr != null">
      and a.refund_date between #{startTime, jdbcType = TIMESTAMP} and #{endTime, jdbcType = TIMESTAMP}
    </if>
    <if test="refundGiftMoney != null">
      and b.refund_gift_money > 0
    </if>
    <if test="recRefundMoney != null">
      and b.rec_refund_money > 0
    </if>
  </select>


</mapper>