WebShareProfitRecordMapper.xml 10.1 KB
<?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.sibu.orderHelper.integral.web.dao.WebShareProfitRecordDao">
	<sql id="shareProfitRecordSql">
		share_user_id, buyer_user_id, order_id, order_code, profit_money, profit_status, product_id, product_price,product_share_percentage, product_amount,profit_dt,order_dt,create_dt
	</sql>
	<resultMap type="com.sibu.orderHelper.integral.model.IMWebShareProfitRecord" id="shareProfitRecordMap">
		<id column="id" property="id" />
		<result column="share_user_id" property="shareUserId" />
		<result column="buyer_user_id" property="buyerUserId" />
		<result column="order_id" property="orderId" />
		<result column="order_code" property="orderCode" />
		<result column="profit_money" property="productPrice" />
		<result column="refund_money" property="refundMoney" />
		<result column="profit_status" property="profitStatus" />
		<result column="product_id" property="productId" />
		<result column="product_price" property="productPrice" />
		<result column="product_share_percentage" property="productSharePercentage" />
		<result column="product_amount" property="productAmount" />
		<result column="order_dt" property="orderDt" />
		<result column="refund_dt" property="refundDt" />
		<result column="create_dt" property="createDt" />
		<result column="update_dt" property="updateDt" />
		<result column="settlement_dt" property="settlementDt" />
	</resultMap>

	<select id="getShareProfitRecordById"  parameterType="java.lang.String" resultMap="shareProfitRecordMap">
		SELECT * FROM t_share_profit_record
		WHERE order_id=#{orderId}

	</select>

	<select id="totalShareProfitRecord" resultType="java.lang.Integer" parameterType="java.util.Map">
		SELECT IFNULL(SUM(id),0) AS total FROM t_share_profit_record
		WHERE order_id=#{orderId}

	</select>
	<insert id="insertShareProfitRecord" parameterType="com.sibu.orderHelper.integral.model.IMWebShareProfitRecord" >
		insert into t_share_profit_record (share_user_id, buyer_user_id, order_id, order_code, refund_money, product_id, product_price,
		product_share_percentage, product_amount,order_dt,refund_dt,create_dt,profit_status
		)
		values (#{shareUserId,jdbcType=VARCHAR}, #{buyerUserId,jdbcType=VARCHAR},
		#{orderId,jdbcType=VARCHAR}, #{orderCode,jdbcType=VARCHAR}, #{refundMoney},
		 #{productId,jdbcType=VARCHAR}, #{productPrice}, #{productSharePercentage},
		#{productAmount},#{orderDt},#{refundDt},now(),#{profitStatus}
		)
	</insert>

	<update id="updateShareProfitRecord" parameterType="java.util.Map">
		update t_share_profit_record
		set refund_money = #{refundMoney}, update_dt=now(),profit_status=#{profitStatus}
		WHERE order_id=#{orderId}   limit 1
	</update>

	<!--查询收益总额  待结算总金额-->
	<select id="selectTotalProfitAmount" parameterType="java.util.Map" resultType="java.math.BigDecimal">
		select sum(profit_money-refund_money) from `t_share_profit_record` WHERE profit_status=1 AND create_dt &lt; #{createDt};
	</select>

	<!--查询收益总额  待结算总金额 根据用户-->
	<select id="selectTotalProfitMoney" parameterType="java.util.Map" resultType="java.math.BigDecimal">
		select sum(profit_money-refund_money) from `t_share_profit_record` WHERE profit_status=1 AND create_dt &lt; #{createDt} AND  share_user_id = #{memberId};
	</select>

	<!--查询某月收益总额   某月预估奖励总金额-->
	<select id="selectMonthProfitAmount" parameterType="java.util.Map" resultType="java.math.BigDecimal">
		select sum(profit_money-refund_money) from `t_share_profit_record` WHERE profit_status =1 AND create_dt BETWEEN #{startDt} and #{endDt};
	</select>

	<!--查询待提现总金额-->
	<select id="selectHasWithdrawSum" parameterType="java.util.Map" resultType="java.math.BigDecimal">
		select sum(amount) from t_withdraw_record where status in(1,2)
	</select>

	<!-- 查询某月奖励订单付款笔数 -->
	<select id="countOrderPaymentPens" parameterType="java.util.Map" resultType="java.lang.Integer">
		SELECT COUNT(order_code) FROM t_share_profit_record
		WHERE profit_status=1 AND create_dt BETWEEN #{startDt} and #{endDt};
	</select>

	<!-- 分享奖励排名 -->
	<select id="sharingRewardRankings" parameterType="java.util.Map" resultMap="shareRewardsRecordMap">
		SELECT * FROM im_share_rewards_record
		where withdraw_status=1
		<if test="phone != null and phone != ''">
			and m.phone=#{phone}
		</if>
		<if test="nickName != null and nickName != ''">
			and m.nick_name like concat('%',#{nickName},'%')
		</if>
		<if test="idCard != null and idCard != ''">
			and m.id_card=#{idCard}
		</if>
		ORDER BY accumulative_amount_of_reward DESC,accumulative_amount_of_cash DESC,freezing_amount DESC
		limit ${pageNow}, ${pageSize}
	</select>

	<select id="totalSharingRewardRankings"  resultType="java.lang.Integer" parameterType="map">
		SELECT count(*) FROM im_share_rewards_record
		where withdraw_status=1
		<if test="phone != null and phone != ''">
			and m.phone=#{phone}
		</if>
		<if test="nickName != null and nickName != ''">
			and m.nick_name like concat('%',#{nickName},'%')
		</if>
		<if test="idCard != null and idCard != ''">
			and m.id_card=#{idCard}
		</if>
	</select>

	<!-- 查询分享奖励排名 -->
	<select id="selectSharingRewardRankings"  resultMap="shareRewardsRecordMap">
		SELECT * FROM im_share_rewards_record WHERE withdraw_status=1
	</select>

	<!-- 批量删除分享奖励 -->
	<delete id="batchDeleteShareRewardsRecord" parameterType="java.util.List">
		DELETE FROM im_share_rewards_record WHERE withdraw_status=1 and id in
		<foreach collection="list" item="id"  open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

	<insert id="insertShareRewardsRecord" parameterType="com.sibu.orderHelper.integral.reponse.ShareRewardsRecordResponse" >
		insert into im_share_rewards_record (id, name, phone, wechat, id_card,
		accumulative_amount_of_reward, accumulative_amount_of_cash,
		freezing_amount, withdraw_status,create_dt
		)
		values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
		#{phone,jdbcType=VARCHAR}, #{wechat,jdbcType=VARCHAR}, #{idCard,jdbcType=VARCHAR},
		#{accumulativeAmountOfReward}, #{accumulativeAmountOfCash}, #{freezingAmount},
		1,now()
		)
	</insert>

	<resultMap type="com.sibu.orderHelper.integral.reponse.ShareRewardsRecordResponse" id="shareRewardsRecordMap">
		<id column="id" property="id" />
		<result column="name" property="name" />
		<result column="phone" property="phone" />
		<result column="wechat" property="wechat" />
		<result column="id_card" property="idCard" />
		<result column="accumulative_amount_of_reward" property="accumulativeAmountOfReward" />
		<result column="accumulative_amount_of_cash" property="accumulativeAmountOfCash" />
		<result column="freezing_amount" property="freezingAmount" />
		<result column="withdraw_status" property="withdrawStatus" />
		<result column="create_dt" property="createDt" />
	</resultMap>

	<!-- 分享奖励排名:提现人累计提现金额  -->
	<select id="sharingRewardToAmount" resultMap="amountResultMap">
		SELECT m.nick_name,m.phone,m.wechat,m.id_card,
		SUM(amount) AS accumulativeAmountOfCash  FROM `t_withdraw_record` r
		INNER JOIN `t_member_info` m  ON r.`member_id` =m.`member_id`
		WHERE r.STATUS IN(1,2) AND m.id_card != ''
		GROUP BY m.nick_name,m.phone,m.wechat,m.id_card
	</select>
	<!-- 分享奖励排名:提现人累计奖励金额  -->
	<select id="sharingRewardToAccumulativeAmountOfReward" resultMap="amountResultMap">
		SELECT m.nick_name,m.phone,m.wechat,m.id_card,
		SUM(profit_money-refund_money) AS accumulativeAmountOfReward FROM
		t_share_profit_record spr
		INNER JOIN `t_member_info` m  ON spr.share_user_id =m.`member_id`
		WHERE spr.profit_status =1  AND m.id_card != ''
		GROUP BY m.nick_name,m.phone,m.wechat,m.id_card
	</select>
	<!-- 分享奖励排名:提现人冻结金额  -->
	<select id="sharingRewardToFreezingAmount" resultMap="amountResultMap">
		SELECT m.nick_name,m.phone,m.wechat,m.id_card,
		       SUM(profit_money-refund_money) AS freezingAmount FROM t_share_profit_record spr
		INNER JOIN `t_member_info` m  ON spr.share_user_id =m.`member_id`
		WHERE spr.profit_status =1 AND settlement_dt IS NULL  AND m.id_card != ''
		GROUP BY m.nick_name,m.phone,m.wechat,m.id_card
	</select>

	<resultMap type="com.sibu.orderHelper.integral.reponse.ShareAmountResponse" id="amountResultMap">
		<result column="phone" property="phone" />
		<result column="nick_name" property="nickName" />
		<result column="wechat" property="wechat" />
		<result column="id_card" property="idCard" />
		<result column="accumulativeAmountOfReward" property="accumulativeAmountOfReward" />
		<result column="accumulativeAmountOfCash" property="accumulativeAmountOfCash" />
		<result column="freezingAmount" property="freezingAmount" />
	</resultMap>


	<!--更新订单结算时间-->
	<update id="updateShareProfitRecordSettlementDt">
		UPDATE t_share_profit_record SET settlement_dt=NOW()
		WHERE profit_status=1 AND profit_dt >0
		AND <![CDATA[ profit_dt < #{endDT} ]]>
	</update>

	<resultMap type="com.sibu.orderHelper.integral.reponse.ShowShareRewardResponse" id="sharingRewardResultMap">
		<id column="id" property="id" />
		<result column="member_id" property="memberId" />
		<result column="partner_trade_no" property="partnerTradeNo" />
		<result column="open_id" property="openId" />
		<result column="amount" property="amount" />
		<result column="user_name" property="userName" />
		<result column="pay_desc" property="payDesc" />
		<result column="pay_dt" property="payDt" />
		<result column="create_dt" property="createDt" />
		<result column="status" property="status" />
		<result column="fail_code" property="failCode" />
		<result column="operator" property="operator" />
		<result column="phone" property="phone" />
		<result column="nick_name" property="nickName" />
		<result column="wechat" property="wechat" />
		<result column="id_card" property="idCard" />
		<result column="accumulativeAmountOfReward" property="accumulativeAmountOfReward" />
		<result column="accumulativeAmountOfCash" property="accumulativeAmountOfCash" />
		<result column="freezingAmount" property="freezingAmount" />
	</resultMap>
</mapper>