|  | <?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.iformall.mapper.AliBusinessCircleOrderMapper">
    <resultMap id="BaseResultMap" type="com.iformall.domain.po.AliBusinessCircleOrder">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
        <result column="notice_id" jdbcType="VARCHAR" property="noticeId" />
        <result column="notice_create_time" jdbcType="TIMESTAMP" property="noticeCreateTime"/>
        <result column="notice_event_type" jdbcType="VARCHAR" property="noticeEventType" />
        <result column="summary" jdbcType="VARCHAR" property="summary" />
        <result column="mall_id" jdbcType="VARCHAR" property="mallId" />
        <result column="mall_name" jdbcType="VARCHAR" property="mallName" />
        <result column="mall_store_id" jdbcType="VARCHAR" property="mallStoreId" />
        <result column="buyer_id" jdbcType="VARCHAR" property="buyerId" />
        <result column="time_end" jdbcType="TIMESTAMP" property="timeEnd"/>
        <result column="amount" jdbcType="INTEGER" property="amount"/>
        <result column="pay_amount" jdbcType="INTEGER" property="payAmount"/>
        <result column="transaction_id" jdbcType="VARCHAR" property="transactionId" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
        <result column="merchant_name" jdbcType="VARCHAR" property="merchantName" />
        <result column="c_user_id" jdbcType="BIGINT" property="cUserId"/>
        <result column="c_user_nick_name" jdbcType="VARCHAR" property="cUserNickName" />
        <result column="c_user_phone" jdbcType="VARCHAR" property="cUserPhone" />
        <result column="earn_points" jdbcType="TINYINT" property="earnPoints"/>
        <result column="increased_points" jdbcType="INTEGER" property="increasedPoints"/>
        <result column="points_update_time" jdbcType="TIMESTAMP" property="pointsUpdateTime"/>
        <result column="is_refund" jdbcType="TINYINT" property="isRefund"/>
        <result column="order_status" jdbcType="TINYINT" property="orderStatus"/>
        <result column="refund_id" jdbcType="VARCHAR" property="refundId" />
        <result column="refund_amount" jdbcType="INTEGER" property="refundAmount"/>
    </resultMap>
    <sql id="allColumns">
	    `id`, `tenant_id`, `parent_tenant_id`, `notice_id`, `notice_create_time`, `notice_event_type`,
	    `summary`,`mall_id`, `mall_name`, `mall_store_id`, `buyer_id`,
	    `time_end`, `amount`, `pay_amount`, `transaction_id`, `create_time`, `update_time`,
	    `merchant_id`,`merchant_name`, `c_user_id`, `c_user_nick_name`, `c_user_phone`,
	    `earn_points`, `increased_points`, `points_update_time`,
	    `is_refund`, `order_status`, `refund_id`, `refund_amount`
	</sql>
    <sql id="dynamicWhereConditions">
        where 1 = 1
        <if test=" null != id ">
            and `id` = #{id}
        </if>
        <if test=" null != tenantId and '' != tenantId">
            and `tenant_id` = #{tenantId}
        </if>
        <if test=" null != parentTenantId and '' != parentTenantId">
            and `parent_tenant_id` = #{parentTenantId}
        </if>
        <if test=" null != mallStoreId and '' != mallStoreId">
            and `mall_store_id` = #{mallStoreId}
        </if>
        <if test=" null != buyerId and '' != buyerId">
            and `buyer_id` = #{buyerId}
        </if>
        <if test=" null != noticeId and '' != noticeId">
            and `notice_id` = #{noticeId}
        </if>
        <if test=" null != startTime ">
            and `time_end` >= #{startTime}
        </if>
        <if test=" null != endTime">
            and `time_end` < #{endTime}
        </if>
        <if test=" null != transactionId and '' != transactionId">
            and `transaction_id` = #{transactionId}
        </if>
        <if test=" null != merchantId ">
            and `merchant_id` = #{merchantId}
        </if>
        <if test=" null != merchantName and ''!=merchantName">
            and `merchant_name` like concat('%', #{merchantName},'%')
        </if>
        <if test=" null != cUserId ">
            and `c_user_id` = #{cUserId}
        </if>
        <if test=" null != cUserNickName and ''!=cUserNickName">
            and `c_user_nick_name` like concat('%', #{cUserNickName},'%')
        </if>
        <if test=" null != cUserPhone and ''!=cUserPhone">
            and `c_user_phone` like concat('%', #{cUserPhone},'%')
        </if>
        <if test=" null != earnPoints ">
            and `earn_points` = #{earnPoints}
        </if>
        <if test=" null != isRefund ">
            and `is_refund` = #{isRefund}
        </if>
        <if test=" null != orderStatus ">
            and `order_status` = #{orderStatus}
        </if>
        <if test=" null != refundId and '' != refundId">
            and `refund_id` = #{refundId}
        </if>
        <if test=" null != ids ">
            and `id` in
            <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
                #{idItem}
            </foreach>
        </if>
    </sql>
    <select id="findList" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from ali_business_circle_order
        <include refid="dynamicWhereConditions"/>
        <if test=" null != sortColumns">order by ${sortColumns}</if>
    </select>
    <select id="getById" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from ali_business_circle_order
        where `id` = #{id}
        and tenant_id=#{tenantId}
    </select>
    <select id="getOrderByTransactionId" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from ali_business_circle_order
        where `is_refund` = 0
        and tenant_id = #{tenantId}
        and `transaction_id` = #{transactionId}
    </select>
    <select id="getRefundOrderByRefundId" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from ali_business_circle_order
        where `is_refund` = 1
        and tenant_id = #{tenantId}
        and `refund_id` = #{refundId}
    </select>
    <select id="getRefundOrderByTransactionId" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" resultMap="BaseResultMap">
        select
        <include refid="allColumns"/>
        from ali_business_circle_order
        where `is_refund` = 1
        and tenant_id = #{tenantId}
        and `transaction_id` = #{transactionId}
    </select>
    <insert id="insertNoticeOrder" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" >
		INSERT INTO ali_business_circle_order (
		`id`, `tenant_id`, `parent_tenant_id`, `notice_id`, `notice_create_time`, `notice_event_type`,
	    `summary`, `mall_id`, `mall_name`, `mall_store_id`, `buyer_id`,`time_end`, `amount`, `pay_amount`, `transaction_id`, `create_time`, `update_time`,
	    `merchant_id`,`merchant_name`, `c_user_id`, `c_user_nick_name`, `c_user_phone`, `earn_points`, `is_refund`
		)
		VALUES(
		#{id},#{tenantId},#{parentTenantId},#{noticeId},#{noticeCreateTime},#{noticeEventType},
		#{summary},#{mallId},#{mallName},#{mallStoreId},#{buyerId},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{createTime},#{updateTime},
		#{merchantId},#{merchantName},#{cUserId},#{cUserNickName},#{cUserPhone},0,0
		);
	</insert>
    <update id="updatePoints" parameterType="com.iformall.domain.po.AliBusinessCircleOrder">
        update ali_business_circle_order set
        `earn_points` = 1, `increased_points` = #{increasedPoints}, `points_update_time` = #{pointsUpdateTime},
        `update_time` = #{updateTime}
        where `id` = #{id} and `tenant_id` = #{tenantId}
    </update>
    <insert id="insertRefundNoticeOrder" parameterType="com.iformall.domain.po.AliBusinessCircleOrder" >
		INSERT INTO ali_business_circle_order (
		`id`, `tenant_id`, `parent_tenant_id`,`notice_id`, `notice_create_time`, `notice_event_type`,
	    `summary`,`mall_id`, `mall_name`, `mall_store_id`, `buyer_id`, `time_end`, `amount`,`pay_amount`, `transaction_id`, `create_time`, `update_time`,
	    `merchant_id`,`merchant_name`, `c_user_id`, `c_user_nick_name`, `c_user_phone`, `earn_points`, `is_refund`, `refund_id`, `refund_amount`
		)
		VALUES(
		#{id},#{tenantId},#{parentTenantId},#{noticeId},#{noticeCreateTime},#{noticeEventType},
		#{summary},#{mallId},#{mallName},#{mallStoreId},#{buyerId},#{timeEnd},#{amount},#{payAmount},#{transactionId},#{createTime},#{updateTime},
		#{merchantId},#{merchantName},#{cUserId},#{cUserNickName},#{cUserPhone},0,1,#{refundId},#{refundAmount}
		);
	</insert>
    <update id="updateOrderStatus" parameterType="com.iformall.domain.po.AliBusinessCircleOrder">
        update ali_business_circle_order set
        `order_status` = #{orderStatus},
        `update_time` = #{updateTime}
        where `id` = #{id} and `tenant_id` = #{tenantId}
    </update>
    <select id="sumCirclePayment" parameterType="com.iformall.domain.po.BusinessCircleBase" resultType="Integer">
        select
        IFNULL(SUM(`pay_amount`),0) as sum_pay_amount
        from ali_business_circle_order
        <include refid="dynamicWhereConditions"/>
        and is_refund = 0
    </select>
    <select id="sumCircleRefundAmount" parameterType="com.iformall.domain.po.BusinessCircleBase" resultType="Integer">
        select
        IFNULL(SUM(`refund_amount`),0) as sum_refund_amount
        from ali_business_circle_order
        <include refid="dynamicWhereConditions"/>
        and is_refund = 1
    </select>
</mapper>
 |