| <?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.order.mapper.RedPaperRuleMapper">  | 
|     <select id="getOne" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select  | 
|         id,rule_name "ruleName",applicable_object "applicableObject",designated_user "designatedUser",  | 
|         designated_weight "designatedWeight",issuance_rules "issuanceRules",random_amount_average "randomAmountAverage",amount  | 
|         ,surplus_amount "surplusAmount"  | 
|         ,surplus_num "surplusNum",  | 
|         red_envelopes_num "redEnvelopesNum",  | 
|         start_time "startTime",end_time "endTime",status,create_time "createTime",update_time "updateTime",del_flag "delFlag",sharing_profit_type "sharingProfitType",  | 
|         share_ratio "shareRatio",  | 
|         rule_type "ruleType",conversion_per_unit "conversionPerUnit",conversion_per_unit_flag "conversionPerUnitFlag",product_type "productType",package_id "packageId",partner_id "partnerId"  | 
|         from xzx_user_redpaper_rule where  del_flag=0 and `status`=1 and ( #{now} between start_time and end_time)  and partner_id=#{partnerId}  | 
|         <if test="ruleType!=null and ruleType!=''">  | 
|             and rule_type=#{ruleType}  | 
|         </if>  | 
|         limit  1  | 
|     </select>  | 
|   | 
|   | 
|     <select id="queryByCondition" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select  | 
|         t.*,(select a.partner_name from xzx_city_partner a where a.id=t.partner_id) as partnerName  | 
|         from xzx_user_redpaper_rule t  | 
|         where t.del_flag=0  | 
|         <if test="ruleName != null and ruleName != ''">  | 
|             and  t.rule_name =#{ruleName}  | 
|         </if>  | 
|   | 
|         <if test="ruleType != null and ruleType != ''">  | 
|             and  t.rule_type =#{ruleType}  | 
|         </if>  | 
|         <if test="partnerId != null and partnerId != ''">  | 
|             and  t.partner_id =#{partnerId} and t.del_flag=0  | 
|         </if>  | 
|     </select>  | 
|     <delete id="batchDelXzxUserRedpaperRuleByIds">  | 
|         update xzx_user_redpaper_rule set del_flag = 1 where id  in  | 
|         <foreach collection="ids" index="index" item="id" open="(" separator="," close=")">  | 
|             #{id}  | 
|         </foreach>  | 
|     </delete>  | 
|     <select id="queryRebateList" resultType="com.xzx.gc.model.admin.XzxPlatformCapitalInfoModel">  | 
|         select a.create_time,a.order_id,b.nick_name,b.mobile_phone,  | 
|         IFNULL(sum(c.weight),0) as designatedWeight,a.order_money,  | 
|         a.royalty_money,a.user_id,a.invited_user_id,  | 
|         (select d.applicable_object from xzx_user_redpaper_rule d where a.rule_id=d.id) as applicableObject  | 
|         from xzx_platform_capital_info a  | 
|         left join xzx_user_info b on b.user_id=a.user_id  | 
|         left join xzx_order_item_info c on c.order_id=a.order_id  | 
|         left join(  | 
|         select m.partner_id,n.order_id from xzx_user_other_info m  | 
|         LEFT JOIN xzx_order_info n on n.receiver=m.user_id  | 
|         )j on a.order_id = j.order_id  | 
|         where a.rule_type=3 and a.royalty_money>0  | 
|         and b.del_flag=0  | 
|   | 
|         <if test="startTime != null and startTime != ''">  | 
|             and  a.create_time >=#{startTime}  | 
|         </if>  | 
|   | 
|         <if test="endTime != null and endTime != ''">  | 
|             and  a.create_time <=#{endTime}  | 
|         </if>  | 
|   | 
|         <if test="mobilePhone != null and mobilePhone != ''">  | 
|             and  (b.mobile_phone like   concat("%",#{mobilePhone} ,"%") or  b.nick_name like concat("%",#{nickName} ,"%"))  | 
|         </if>  | 
|         <if test="partnerId != null and partnerId != ''">  | 
|             and  j.partner_id = #{partnerId}  | 
|         </if>  | 
|         <if test="partnerId==null or partnerId == ''">  | 
|             AND j.partner_id is NULL  | 
|         </if>  | 
|         <if test="partnerIds!= null and partnerIds.size() != 0">  | 
|             AND  j.partner_id in  | 
|   | 
|             <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">  | 
|                 #{id}  | 
|             </foreach>  | 
|         </if>  | 
|         group by a.order_id order by a.create_time desc  | 
|     </select>  | 
|     <select id="queryTotalAmountByParam" resultType="java.lang.String">  | 
|         select sum(a.royalty_money)  | 
|         from xzx_platform_capital_info a  | 
|         left join xzx_user_info b on b.user_id=a.user_id and b.del_flag=0  | 
|         left join(  | 
|         select m.partner_id,n.order_id from xzx_user_other_info m  | 
|         LEFT JOIN xzx_order_info n on n.receiver=m.user_id  | 
|         )j on a.order_id = j.order_id  | 
|         where a.rule_type=3  | 
|         <if test="startTime != null and startTime != ''">  | 
|             and  a.create_time >=#{startTime}  | 
|         </if>  | 
|   | 
|         <if test="endTime != null and endTime != ''">  | 
|             and  a.create_time <=#{endTime}  | 
|         </if>  | 
|   | 
|         <if test="mobilePhone != null and mobilePhone != ''">  | 
|             and  (b.mobile_phone like   concat("%",#{mobilePhone} ,"%") or  b.nick_name like concat("%",#{nickName} ,"%"))  | 
|         </if>  | 
|   | 
|         <if test="partnerIds!= null and partnerIds.size() != 0">  | 
|             AND  j.partner_id in  | 
|   | 
|             <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">  | 
|                 #{id}  | 
|             </foreach>  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryUserOrderIds" resultType="java.lang.String">  | 
|         select a.order_id from xzx_order_info a  | 
|         left join xzx_order_detail_info b on b.order_id=a.order_id  | 
|         where a.order_status in (4,5,7)  | 
|   | 
|         <if test="completeTime != null and completeTime != ''">  | 
|             and  b.complete_time <= #{completeTime}  | 
|         </if>  | 
|   | 
|         <if test="userId != null and userId != ''">  | 
|             and  a.create_user_id = #{userId}  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryAfterWeightByOrderIds" parameterType="java.util.List" resultType="java.lang.String">  | 
|         select sum(weight) from xzx_order_item_info where order_id in  | 
|         <foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">  | 
|             #{id}  | 
|         </foreach>  | 
|     </select>  | 
|     <select id="queryTotalOrderMoney" resultType="java.lang.String">  | 
|         select sum(money) from xzx_order_item_info where order_id in  | 
|         <foreach collection="orderIds" index="index" item="id" open="(" separator="," close=")">  | 
|             #{id}  | 
|         </foreach>  | 
|     </select>  | 
|     <select id="queryRedpaperList" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =1  | 
|         and del_flag=0  | 
|         <if test="startTime != null and startTime != ''">  | 
|             and  end_time>=#{startTime}  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryRedpaperListStartAndEnd" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =#{ruleType}  | 
|         and del_flag=0 and status=1  | 
|         <if test="startTime != null and startTime != ''">  | 
|             and  (  (#{startTime} >=start_time and #{startTime} <=end_time) or (#{startTime} <=start_time and #{endTime} >=start_time ))  | 
|         </if>  | 
|         and partner_id=#{partnerId}  | 
|   | 
|         <if test="id != null">  | 
|             and id!=#{id}  | 
|         </if>  | 
|   | 
|     </select>  | 
|     <select id="queryShareListByTime" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =2  | 
|         and del_flag=0  | 
|         <if test="startTime != null and startTime != ''">  | 
|             and  (end_time>=#{startTime} or end_time>=#{endTime})  | 
|         </if>  | 
|   | 
|         <choose>  | 
|             <when test="partnerId != null and partnerId != ''">  | 
|                 and  partner_id=#{partnerId}  | 
|             </when>  | 
|             <otherwise>  | 
|                 and partner_id is null  | 
|             </otherwise>  | 
|         </choose>  | 
|     </select>  | 
|     <select id="queryCommListByTime" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =8  | 
|         and del_flag=0  | 
|         <if test="startTime != null and startTime != ''">  | 
|             and  (end_time>=#{startTime} or end_time>=#{endTime})  | 
|         </if>  | 
|   | 
|         <if test="id != null and id != ''">  | 
|             and  id!=#{id}  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryRebateRulePriceList" resultType="com.xzx.gc.entity.RebateRule">  | 
|         select * from  xzx_rebate_rule_price  | 
|         where   rule_id =#{ruleId} and del_flag=0 order by sort asc  | 
|     </select>  | 
|     <select id="queryRebateRuleList" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =3  | 
|         and del_flag=0  | 
|         <choose>  | 
|             <when test="partnerId != null and partnerId != ''">  | 
|                 and  partner_id=#{partnerId}  | 
|             </when>  | 
|             <otherwise>  | 
|                 and partner_id is null  | 
|             </otherwise>  | 
|         </choose>  | 
|   | 
|         <if test="status != null">  | 
|             and  status=#{status}  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryWeightRuleList" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =5  | 
|         and del_flag=0  | 
|         <choose>  | 
|             <when test="partnerId != null and partnerId != ''">  | 
|                 and  partner_id=#{partnerId}  | 
|             </when>  | 
|             <otherwise>  | 
|                 and partner_id is null  | 
|             </otherwise>  | 
|         </choose>  | 
|   | 
|         <if test="status != null">  | 
|             and  status=#{status}  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryAccountList" resultType="com.xzx.gc.model.admin.CommissionModel">  | 
|         select a.create_time as commissionTime,a.flow_no as orderNo,sum(b.money) as orderMoney,  | 
|         a.hbb as commissionEarn,c.partner_name as partnerName,  | 
|         c.mobile_phone as mobile from xzx_platform_account_log a  | 
|         left join xzx_order_item_info b on a.flow_no=b.order_id  | 
|         inner join xzx_city_partner c on a.create_user_id=c.id  | 
|         where type=4 and c.id=#{partnerId}  | 
|   | 
|         <if test="mobile != null and mobile != ''">  | 
|             and (c.partner_name like  concat("%",#{mobile} "%") or c.mobile_phone like concat("%",#{mobile} ,"%"))  | 
|         </if>  | 
|   | 
|         <if test="startTime != null and startTime != ''">  | 
|             and a.create_time>=#{startTime}  | 
|         </if>  | 
|   | 
|         <if test="endTime != null and endTime != ''">  | 
|             and a.create_time<=#{endTime}  | 
|         </if>  | 
|         group by a.flow_no order by a.create_time desc  | 
|     </select>  | 
|     <select id="queryTotalCommissionMoney" resultType="java.lang.String">  | 
|         select  | 
|         IFNULL(sum(a.hbb),0) from xzx_platform_account_log a  | 
|         left join xzx_city_partner c on a.create_user_id=c.id  | 
|         where type=4  | 
|         <if test="mobile != null and mobile != ''">  | 
|             and (c.partner_name like  concat("%",#{mobile} "%") or c.mobile_phone like concat("%",#{mobile} ,"%"))  | 
|         </if>  | 
|   | 
|         <if test="startTime != null and startTime != ''">  | 
|             and a.create_time>=#{startTime}  | 
|         </if>  | 
|   | 
|         <if test="endTime != null and endTime != ''">  | 
|             and a.create_time<=#{endTime}  | 
|         </if>  | 
|     </select>  | 
|     <select id="queryAccountListCount" resultType="java.lang.String">  | 
|         select count(k.count) from (select count(a.flow_no) as count from xzx_platform_account_log a  | 
|         left join xzx_order_item_info b on a.flow_no=b.order_id  | 
|         left join xzx_city_partner c on a.create_user_id=c.id  | 
|         where type=4  | 
|         <if test="mobile != null and mobile != ''">  | 
|             and (c.partner_name like concat("%",#{mobile} "%") or c.mobile_phone like concat("%",#{mobile} ,"%"))  | 
|         </if>  | 
|   | 
|         <if test="startTime != null and startTime != ''">  | 
|             and a.create_time>=#{startTime}  | 
|         </if>  | 
|   | 
|         <if test="endTime != null and endTime != ''">  | 
|             and a.create_time<=#{endTime}  | 
|         </if>  | 
|         group by a.flow_no order by a.create_time desc  | 
|         )k  | 
|     </select>  | 
|   | 
|     <delete id="deleteByRuleId">  | 
|         update xzx_rebate_rule_price  set del_flag=1  where rule_id =#{ruleId}  | 
|     </delete>  | 
|   | 
|     <select id="queryRoyalRuleList" resultType="com.xzx.gc.entity.RedPaperRule">  | 
|         select * from  xzx_user_redpaper_rule  | 
|         where   rule_type =7  | 
|   | 
|         <if test="packageId != null and packageId != ''">  | 
|             and package_id=#{packageId}  | 
|         </if>  | 
|   | 
|         <if test="partnerId != null and partnerId != ''">  | 
|             and partner_id=#{partnerId}  | 
|         </if>  | 
|   | 
|         and del_flag=0  | 
|     </select>  | 
|   | 
|     <select id="queryRoyalty" resultType="com.xzx.gc.model.admin.XzxUserRedpaperRuleModel">  | 
|         select * from xzx_user_redpaper_rule where rule_type=7 and del_flag=0  | 
|         <if test="partnerId != null and partnerId != ''">  | 
|             and partner_id =#{partnerId}  | 
|         </if>  | 
|         <if test="partnerId==null or partnerId == ''">  | 
|             AND partner_id is NULL  | 
|         </if>  | 
|         <if test=" partnerIds != null and partnerIds.size() != 0">  | 
|             AND partner_id in  | 
|             <foreach collection="partnerIds" index="index" item="id" open="(" separator="," close=")">  | 
|                 #{id}  | 
|             </foreach>  | 
|         </if>  | 
|     </select>  | 
|   | 
| </mapper> |