IMCouponDao.xml 30.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
<?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.dao.IMCouponDao">
    <resultMap id="couponResponse" type="com.sibu.orderHelper.integral.reponse.CouponResponse" >
        <result column="id" property="id" />
        <result column="coupon_name" property="couponName" />
        <result column="use_start_date" property="useStartDate" />
        <result column="use_end_date" property="useEndDate" />
        <result column="full_money" property="fullMoney" />
        <result column="cut_money" property="cutMoney" />
        <result column="coupon_type" property="couponType" />
        <result column="has_get" property="hasGet" />
        <result column="instruction" property="instruction" />
        <result column="coupon_num" property="couponNum" />
        <result column="receive_num" property="receiveNum" />
        <result column="product_range" property="productRange"></result>
        <result column="range_id" property="rangeId"></result>
        <result column="supplier_id" property="supplierId"></result>
        <result column="supplier_name" property="supplierName"></result>
        <result column="platform_type" property="platformType"></result>
    </resultMap>

    <resultMap id="coupon" type="com.sibu.orderHelper.integral.reponse.CouponResponse" >
        <result column="id" property="id" />
        <result column="coupon_name" property="couponName" />
        <result column="use_start_date" property="useStartDate" />
        <result column="use_end_date" property="useEndDate" />
    </resultMap>


    <!--用户优惠券-->
    <resultMap id="userCoupon" type="com.sibu.orderHelper.integral.reponse.UserCouponResponse" >
        <result column="id" property="id" />
        <result column="coupon_name" property="couponName" />
        <result column="use_start_date" property="useStartDt" />
        <result column="use_end_date" property="useEndDt" />
        <result column="full_money" property="fullMoney" />
        <result column="cut_money" property="cutMoney" />
        <result column="coupon_id" property="couponId" />
        <result column="coupon_type" property="couponType" />
        <result column="use_dt" property="useDt" />
        <result column="use_order_code" property="useOrderCode" />
        <result column="create_dt" property="createDt" />
        <result column="instruction" property="instruction" />
        <result column="coupon_range" property="couponRange" />
        <result column="range_id" property="rangeId" />
        <result column="supplier_id" property="supplierId" />
        <result column="supplier_name" property="supplierName" />
        <result column="platform_type" property="platformType" />
    </resultMap>

    <resultMap id="memberCouponResponse" type="com.sibu.orderHelper.integral.reponse.UserCouponMemberResponse">
        <result column="id" property="id" />
        <result column="coupon_name" property="couponName" />
        <result column="use_order_code" property="useOrderCode" />
        <result column="member_id" property="memberId" />
    </resultMap>

    <!--优惠券明细-->
    <resultMap id="couponDetail" type="com.sibu.orderHelper.integral.reponse.CouponDetail">
        <result column="id" property="id" />
        <result column="full_money" property="fullMoney" />
        <result column="cut_money" property="cutMoney" />
        <result column="coupon_type" property="couponType" />
        <result column="range_id" property="rangeId" />
        <result column="range_type" property="rangeType" />
    </resultMap>


    <resultMap type="com.sibu.orderHelper.integral.model.IMAPIProductBean" id="listIMProduct">
        <result column="im_product_id" property="imProductId" />
        <result column="name" property="name" />
        <result column="short_name" property="shortName" />
        <result column="stock_num" property="stockNum" />
        <result column="details" property="details" />
        <result column="exchange_integral" property="exchangeIntegral" />
        <result column="xws_exchange_integral" property="xwsExchangeIntegral" />
        <result column="sibukg_exchange_integral" property="sibukgExchangeIntegral" />
        <result column="onther1_exchange_integral" property="onther1ExchangeIntegral" />
        <result column="onther2_exchange_integral" property="onther2ExchangeIntegral" />
        <result column="onther3_exchange_integral" property="onther3ExchangeIntegral" />
        <result column="thumb_img" property="thumbImg" />
        <result column="bannel_img1" property="bannelImg1" />
        <result column="bannel_img2" property="bannelImg2" />
        <result column="bannel_img3" property="bannelImg3" />
        <result column="bannel_img4" property="bannelImg4" />
        <result column="bannel_img5" property="bannelImg5" />
        <result column="limit_exchange_number" property="limitExchangeNumber"/>
        <result column="is_new" property="isNew" />
        <result column="is_hot" property="isHot" />
        <result column="is_reco" property="isReco" />
        <result column="cost" property="cost" />
        <result column="attention" property="attention" />
        <result column="total_comment_score" property="totalCommentScore" />
        <result column="total_comment_number" property="totalCommentNumber" />
        <result column="member_price" property="memberPrice" />
        <result column="retail_price" property="retailPrice" />
        <result column="market_price" property="marketPrice" />
        <result column="product_type" property="productType" />
        <result column="is_show" property="isShow"/>
        <result column="is_open_spec" property="isOpenSpec"/>
        <result column="spec" property="spec"/>
        <result column="mini_purchase_number" property="miniPurchaseNumber"/>
        <result column="format_str" property="formatStr"/>
        <result column="is_group" property="isGroup"/>
    </resultMap>

    <sql id="Base_Product_Column">
        p.im_product_id,
        p.name,
        p.short_name,
        p.stock_num,
        p.exchange_integral,
        p.xws_exchange_integral,
        p.sibukg_exchange_integral,
        p.onther1_exchange_integral,
        p.onther2_exchange_integral,
        p.onther3_exchange_integral,
        p.limit_exchange_number,
        p.thumb_img,
        p.is_new,
        p.is_hot,
        p.is_reco,
        p.cost,
        p.attention,
        p.is_show,
        p.product_type,
        p.member_price,
        p.retail_price,
        p.market_price,
        p.is_open_spec,
        p.spec,
        p.mini_purchase_number,
        p.format_str
    </sql>

    <!--分页查询优惠券列表-->
    <select id="selectCouponForPage" resultMap="couponResponse" parameterType="java.util.Map">
        SELECT 
			t.*,
			CASE WHEN u.id IS NULL 
				THEN 0 
				ELSE 1 
			END AS has_get FROM
        (
			SELECT 
				id,
				coupon_name,
				coupon_money AS cut_money,
				0 AS full_money,
				0 AS coupon_type,
				use_start_date ,
				use_end_date,
				direct_cut_instruction as instruction ,
				coupon_num ,
				receive_num,
				product_range,
				product_id as range_id,
				supplier_id,
				supplier_name,
				platform_type
			FROM`coupon_direct_cut`
			WHERE STATUS =1 AND NOW()>receive_start_date  AND receive_end_date >NOW() and coupon_num >receive_num and get_source=0
			UNION ALL
			SELECT 
				id,
				coupon_name,
				cut_money,
				full_money,
				1 AS coupon_type,
				use_start_date ,
				use_end_date ,
				full_cut_instruction as instruction,
				coupon_num ,
				receive_num,
				r.full_cut_range as product_range,
				r.full_cut_range_id as range_id,
				supplier_id,
				supplier_name,
				platform_type
			FROM `coupon_full_cut` c
			INNER JOIN 
			(
				SELECT 
					full_cut_id,
					full_cut_range ,
					full_cut_range_id   
				FROM `coupon_full_cut_range`  
				GROUP BY full_cut_id
			) r
			ON c.id =r.full_cut_id
			WHERE STATUS =1 AND now()>receive_start_date AND receive_end_date >NOW() and coupon_num >receive_num and get_source=0
        ) AS t LEFT JOIN `user_coupons` u
        ON t.id =u.`coupon_id`AND t.coupon_type=u.`coupon_type` AND u.`member_id`=#{memberId}
        <if test="isGet !=null and isGet==0">
            where u.id is null
        </if>
        order by t.id desc
        LIMIT #{pageNow},#{pageSize}
    </select>

    <!--统计数量-->
    <select id="countCoupons" resultType="java.lang.Integer" parameterType="java.lang.String">
        SELECT count(1) FROM(
        SELECT id,coupon_name,coupon_money AS cut_money, 0 AS full_money, 0 AS coupon_type, use_start_date ,use_end_date,direct_cut_instruction as instruction FROM`coupon_direct_cut`
        WHERE STATUS =1 AND NOW()>receive_start_date  AND receive_end_date >NOW() and coupon_num >receive_num and get_source=0
        UNION ALL
        SELECT id,coupon_name,cut_money,full_money,1 AS coupon_type,use_start_date ,use_end_date ,full_cut_instruction as instruction FROM `coupon_full_cut` c
        INNER JOIN (SELECT full_cut_id,full_cut_range FROM `coupon_full_cut_range`  GROUP BY full_cut_id) r
        ON c.id =r.full_cut_id
        WHERE STATUS =1 AND now()>receive_start_date AND receive_end_date >NOW() and coupon_num >receive_num and get_source=0
        ) AS t LEFT JOIN `user_coupons` u
        ON t.id =u.`coupon_id`AND t.coupon_type=u.`coupon_type` AND u.`member_id`=#{memberId}
        <if test="isGet !=null and isGet==0">
            where u.id is null
        </if>
    </select>
    <!--判断有效的优惠券-->
    <select id="selectCoupon" resultMap="coupon" parameterType="java.util.Map">
        SELECT id,coupon_name,use_start_date,use_end_date FROM ${tableName} WHERE id=#{id} and STATUS =1 AND now()>receive_start_date AND receive_end_date >NOW() and coupon_num >receive_num
    </select>

    <select id="selectCouponByMoney" resultMap="coupon" parameterType="java.math.BigDecimal">
      SELECT id,coupon_name,use_start_date,use_end_date FROM coupon_full_cut WHERE cut_money=#{cutMoney} and STATUS =1 and get_source = 1 AND now()>receive_start_date AND receive_end_date >NOW() and coupon_num > receive_num limit 1
    </select>

    <select id="selectCouponById" resultMap="coupon" parameterType="java.util.Map">
        SELECT id,coupon_name,use_start_date,use_end_date FROM coupon_full_cut WHERE id=#{couponId} and STATUS =1 and get_source = 1 AND now()>receive_start_date AND receive_end_date >NOW() and coupon_num > receive_num limit 1
    </select>

    <select id="selectCouponByCode" resultMap="memberCouponResponse" parameterType="java.lang.String">
        SELECT id,coupon_name,member_id,use_order_code FROM user_coupons WHERE coupon_code = #{couponCode} limit 1
    </select>

    <update id="updateCouponNum" parameterType="java.util.Map">
        update ${tableName} set receive_num =receive_num+1 where coupon_num > receive_num and id=#{id} and status =1
    </update>

    <!--激活优惠券-->
    <update id="activateCoupon" parameterType="com.sibu.orderHelper.integral.request.CouponActivateRequest">
        update user_coupons set member_id = #{memberId} where coupon_code=#{couponCode} and (member_id = '' or member_id is NULL) limit 1
    </update>

    <!--插入优惠券-->
    <insert id="insertUserCoupon" parameterType="com.sibu.orderHelper.integral.model.UserCoupons">
        INSERT INTO user_coupons( member_id,coupon_name,coupon_id, coupon_type,get_source,use_start_dt, use_end_dt,coupon_code)
        VALUES(#{memberId},#{couponName},#{couponId},#{couponType},#{getSource},#{useStartDt},#{useEndDt},#{couponCode})
    </insert>

    <select id="selectUserCoupons" parameterType="java.util.Map" resultMap="userCoupon">
	    SELECT 
			c.*,
			u.`use_dt`,u.`use_order_code`,u.`get_source`,u.`create_dt`,u.id 
		FROM`user_coupons` u INNER JOIN
	    ( 
			SELECT 
				id as coupon_id,coupon_name,coupon_money AS cut_money, 0 AS full_money, 0 AS coupon_type, use_start_date ,use_end_date ,product_range as coupon_range,
                supplier_id,platform_type,supplier_name,
				direct_cut_instruction as instruction,
				product_id AS range_id
            FROM`coupon_direct_cut` WHERE STATUS =1
            UNION ALL
            SELECT 
				c.id as coupon_id,c.coupon_name,cut_money,c.full_money,1 AS coupon_type,c.use_start_date ,c.use_end_date ,r.full_cut_range as coupon_range,
                c.supplier_id,c.platform_type,c.supplier_name,
				c.full_cut_instruction as instruction,r.full_cut_range_id as range_id
            FROM `coupon_full_cut` c inner join
			(
                SELECT MIN(id), full_cut_id ,full_cut_range, 
					CASE
						WHEN full_cut_range IN (0,2)
						THEN NULL
						WHEN full_cut_range = 1
						THEN full_cut_range_id
						ELSE NULL
					END AS full_cut_range_id 
				FROM `coupon_full_cut_range`GROUP BY full_cut_id
            ) r ON r.full_cut_id =c.id
            WHERE STATUS =1
        )
        AS c
		ON u.`coupon_id` =c.coupon_id AND u.`coupon_type` =c.coupon_type
		WHERE u.`member_id` =#{memberId}
		<if test="userCouponId !=null">
			and u.id =#{userCouponId}
		</if>
		order by u.id desc
    </select>

	<select id="findUserCoupons" parameterType="java.util.Map" resultMap="userCoupon">
	    SELECT 
			c.*,
			u.`use_dt`,u.`use_order_code`,u.`get_source`,u.`create_dt`,u.id 
		FROM`user_coupons` u INNER JOIN
	    ( 
			SELECT 
				id as coupon_id,
                coupon_name,
                coupon_money AS cut_money,
                0 AS full_money,
                0 AS coupon_type,
                use_start_date ,
                use_end_date ,
                product_range as coupon_range,
				direct_cut_instruction as instruction,
                product_id AS range_id,
                supplier_id,
                supplier_name,
                platform_type
            FROM`coupon_direct_cut` WHERE STATUS =1
            UNION ALL
            SELECT 
				c.id as coupon_id,
                c.coupon_name,
                cut_money,
                c.full_money,
                1 AS coupon_type,
                c.use_start_date ,
                c.use_end_date ,
                r.full_cut_range as coupon_range,
				c.full_cut_instruction as instruction,
                r.full_cut_range_id as range_id,
                c.supplier_id,
                c.supplier_name,
                c.platform_type
            FROM `coupon_full_cut` c inner join
			(
                SELECT MIN(id), full_cut_id ,full_cut_range, 
					CASE
						WHEN full_cut_range IN (0,2)
						THEN NULL
						WHEN full_cut_range = 1
						THEN full_cut_range_id
						ELSE NULL
					END AS full_cut_range_id 
				FROM `coupon_full_cut_range`GROUP BY full_cut_id
            ) r ON r.full_cut_id =c.id
            WHERE STATUS =1
        )
        AS c
		ON u.`coupon_id` =c.coupon_id AND u.`coupon_type` =c.coupon_type
		WHERE u.`member_id` =#{memberId}
		<if test="userCouponId !=null">
			and u.id =#{userCouponId}
		</if>
		order by u.id desc
    </select>
    <!--查询商品或者专题的优惠券,或者全品类优惠券-->
    <select id="selectProductCoupons" resultMap="couponResponse" parameterType="java.util.Map">
            SELECT t.*,CASE WHEN u.id IS NULL THEN 0 ELSE 1 END AS has_get FROM(
        SELECT id,coupon_name,coupon_money AS cut_money, 0 AS full_money, 0 AS coupon_type, use_start_date ,use_end_date ,coupon_num -receive_num as coupon_num FROM`coupon_direct_cut`
        WHERE STATUS =1 AND NOW()>receive_start_date  AND receive_end_date >NOW()
        <if test="getSource !=null">
            and get_source=#{getSource}
        </if>

        AND (product_range=0
         <if test="productIds !=null">
             or (product_range =2 and product_id in
             <foreach collection="productIds" item="productId" separator="," open="(" close=")">
                 #{productId}
             </foreach>
             )
         </if>
         <if test="topIds !=null and topIds.size>0">
             OR(product_range=1 and product_id IN
             <foreach collection="topIds" item="topId" separator="," open="(" close=")">
                 #{topId}
             </foreach>
             )
         </if>
           )
        UNION ALL
        SELECT id,coupon_name,cut_money,full_money,1 AS coupon_type,use_start_date ,use_end_date ,coupon_num -receive_num as coupon_num  FROM `coupon_full_cut`
        WHERE STATUS =1 AND NOW()>receive_start_date AND receive_end_date >NOW()
        <if test="getSource !=null">
            and get_source=#{getSource}
        </if>
        AND id IN(
		SELECT DISTINCT full_cut_id FROM `coupon_full_cut_range` WHERE delete_Flag=0 AND
		(full_cut_range=0
        <if test="productIds !=null">
            or (full_cut_range =2 and full_cut_range_id in
            <foreach collection="productIds" item="productId" separator="," open="(" close=")">
                #{productId}
            </foreach>
            )
        </if>
        <if test="topIds !=null and topIds.size>0">
            OR( full_cut_range=1 AND full_cut_range_id IN
            <foreach collection="topIds" item="topId" separator="," open="(" close=")">
                #{topId}
            </foreach>
            )
        </if>
        )
        )
        ) AS t LEFT JOIN `user_coupons` u
        ON t.id =u.`coupon_id`AND t.coupon_type=u.`coupon_type` AND u.`member_id`=#{memberId}
    </select>
    <!-- 查询V商城商品的优惠卷,含用户已领取与未领取优惠券 -->
    <select id="findProductCouponsByMemberIdAndGetSourceAndProductIds" resultMap="couponResponse" parameterType="java.util.Map">
        SELECT 
			t.*,
			CASE WHEN u.id IS NULL THEN 0 ELSE 1 END AS has_get 
		FROM
		(
			SELECT id,coupon_name,coupon_money AS cut_money, 0 AS full_money, 0 AS coupon_type, use_start_date ,use_end_date ,coupon_num -receive_num as coupon_num,
            platform_type,supplier_id,supplier_name,direct_cut_instruction AS instruction FROM`coupon_direct_cut`
			WHERE STATUS =1 AND NOW()>receive_start_date  AND receive_end_date >NOW()
            <if test="getSource !=null">
                and get_source=#{getSource}
            </if>
			AND
			(
				product_range=0
				or
				(
					product_range =2 and product_id in
					<foreach collection="productIds" item="productId" separator="," open="(" close=")">
					#{productId}
					</foreach>
				)
				or
				(
					product_range=1 and product_id in 
					(
						SELECT DISTINCT campaign_id FROM `campaign_product` WHERE product_id IN
						<foreach collection="productIds" item="productId" separator="," open="(" close=")">
							#{productId}
						</foreach>
					)
				)
			)
			and
			(
				platform_type=0
				or
				(
					platform_type=1 and supplier_id in 
					(
						select distinct supplier_id from im_product_supplier where product_id IN
						<foreach collection="productIds" item="productId" separator="," open="(" close=")">
							#{productId}
						</foreach>
					)
				)
			)
			UNION ALL
			SELECT id,coupon_name,cut_money,full_money,1 AS coupon_type,use_start_date ,use_end_date ,coupon_num -receive_num as coupon_num ,platform_type,supplier_id,supplier_name,full_cut_instruction AS  instruction FROM `coupon_full_cut`
			WHERE STATUS =1 AND NOW()>receive_start_date AND receive_end_date >NOW()
            <if test="getSource !=null">
                and get_source=#{getSource}
            </if>
			AND
			id IN
			(
				SELECT DISTINCT full_cut_id FROM `coupon_full_cut_range` WHERE delete_Flag=0
				AND
				(
					full_cut_range=0
					or
					(
						full_cut_range =2 and full_cut_range_id in						
						<foreach collection="productIds" item="productId" separator="," open="(" close=")">
						  #{productId}
						</foreach>
					)
					or
					( 
						full_cut_range=1 and full_cut_range_id in 
						(					
							SELECT DISTINCT campaign_id FROM `campaign_product` WHERE product_id IN
							<foreach collection="productIds" item="productId" separator="," open="(" close=")">
								#{productId}
							</foreach>
						)
					)
				)
			)
			and
			(
				platform_type=0
				or
				(
					platform_type=1 and supplier_id in 
					(
						select distinct supplier_id from im_product_supplier where product_id IN
						<foreach collection="productIds" item="productId" separator="," open="(" close=")">
							#{productId}
						</foreach>
					)
				)
			)
        ) AS t LEFT JOIN `user_coupons` u
        ON t.id =u.`coupon_id`AND t.coupon_type=u.`coupon_type` AND u.`member_id`=#{memberId}
    </select>
    <!--查询所有商品所在的主题-->
    <select id="selectTopIdsForProductId" resultType="java.lang.Long" parameterType="java.lang.String">
        SELECT DISTINCT campaign_id FROM `campaign_product` WHERE product_id IN
        <foreach collection="productIds" item="productId" separator="," open="(" close=")">
            #{productId}
        </foreach>
    </select>
    <!--查询所有商品所在的主题-->
    <select id="findTopicIdsByProductIdIn" resultType="java.lang.Long" parameterType="java.lang.String">
        SELECT DISTINCT campaign_id FROM `campaign_product` WHERE product_id IN
        <foreach collection="productIds" item="productId" separator="," open="(" close=")">
            #{productId}
        </foreach>
    </select>

    <select id="selectProductIdByCampagin" resultType="java.lang.String" parameterType="java.util.List">
        SELECT DISTINCT product_id FROM `campaign_product` WHERE product_type = 1 and campaign_id IN
        <foreach collection="campaginIds" item="campaginId" separator="," open="(" close=")">
            #{campaginId}
        </foreach>
    </select>

    <select id="selectMemberCouponCount" resultType="java.lang.Integer" parameterType="java.util.Map">
        SELECT COUNT(1) FROM `user_coupons` WHERE member_id =#{memberId} and coupon_id =#{couponId} AND coupon_type =#{couponType}
    </select>


    <select id="selectDirectCouponDetail" resultMap="couponDetail" parameterType="java.lang.Long">
      SELECT id,0 AS coupon_type, product_id AS range_id ,product_range AS range_type, 0 AS full_money,
      coupon_money AS cut_money
      FROM `coupon_direct_cut` WHERE id=#{id} and  STATUS =1 AND NOW() BETWEEN use_start_date AND use_end_date
    </select>

    <select id="selectFullCouponDetail" resultMap="couponDetail" parameterType="java.lang.Long">
         SELECT c.id,1 AS coupon_type,r.full_cut_range_id AS range_id ,r.full_cut_range AS range_type ,c.full_money,c.cut_money
        FROM `coupon_full_cut` c INNER JOIN `coupon_full_cut_range` r ON c.id =r.full_cut_id
        where c.id=#{id} and r.delete_flag =0 and c.STATUS =1 AND NOW() BETWEEN c.use_start_date AND c.use_end_date
    </select>
    <select id="findFullCouponRules" resultMap="couponDetail" parameterType="java.lang.Long">
        SELECT c.id,1 AS coupon_type,r.full_cut_range_id AS range_id ,r.full_cut_range AS range_type ,c.full_money,c.cut_money
        FROM `coupon_full_cut` c INNER JOIN `coupon_full_cut_range` r ON c.id =r.full_cut_id
        where c.id=#{fullCouponId} and r.delete_flag =0
    </select>

    <!--直减券商品-->
    <select id="selectDirectCouponProducts"  resultMap="listIMProduct" parameterType="java.util.Map">
        SELECT <include refid="Base_Product_Column"/>
        FROM `coupon_direct_cut` c INNER JOIN  `im_product` p
        ON c.`product_id` =p.im_product_id
        WHERE id=#{id}
        LIMIT #{pageNow},#{pageSize}
    </select>
    <!--满减券商品-->
    <select id="selectFullCouponProducts"  resultMap="listIMProduct" parameterType="java.util.Map">
        SELECT <include refid="Base_Product_Column"/>
        FROM `coupon_full_cut` c
        INNER JOIN `coupon_full_cut_range` r ON c.`id` =r.full_cut_id
        INNER JOIN  `im_product` p ON r.full_cut_range_id =p.im_product_id
        INNER JOIN im_product_inventory i ON i.im_product_id =p.im_product_id
        WHERE c.id =#{id}
        <if test='sortType != null and sortType == "priceAsc"'>
            order by p.retail_price asc
        </if>
        <if test='sortType != null and sortType == "priceDesc"'>
            order by p.retail_price desc
        </if>
        <if test='sortType != null and sortType == "discountAsc"'>
            order by p.retail_price/p.market_price asc
        </if>

        <if test='sortType != null and sortType == "discountDesc"'>
            order by p.retail_price/p.market_price desc
        </if>
        <if test='sortType != null and sortType == "saleAsc"'>
            order by i.cost asc
        </if>
        <if test='sortType != null and sortType == "saleDesc"'>
            order by i.cost desc
        </if>
        LIMIT #{pageNow},#{pageSize}
    </select>
    <!--满减券商品数量-->
    <select id="selectFullCouponProductsCounts" resultType="java.lang.Integer" parameterType="java.lang.Long">
        SELECT count(1)
        FROM `coupon_full_cut` c
        INNER JOIN `coupon_full_cut_range` r ON c.`id` =r.full_cut_id
        INNER JOIN  `im_product` p ON r.full_cut_range_id =p.im_product_id
        WHERE c.id =#{id}
    </select>
    <!--更新用户的优惠券-->
    <update id="updateUserCoupons" parameterType="java.util.Map" >
        UPDATE `user_coupons` SET use_order_code =#{orderCode},use_dt=NOW() WHERE member_id=#{memberId} AND id=#{userCouponId}
    </update>

    <update id="updateUserCouponsDoUse" parameterType="java.util.Map" >
        UPDATE `user_coupons` SET use_order_code =NULL, use_dt=null WHERE member_id=#{memberId} AND id=#{userCouponId}
    </update>

    <select id="getFullCutLimitBuFullId" parameterType="java.lang.Integer" resultMap="FullCutLimitResponseMap">
        select id,full_cut_id, full_cut_range, full_cut_range_id, range_name
        from coupon_full_cut_range
        WHERE full_cut_id=#{id} and delete_flag=0 limit 1
    </select>

    <resultMap id="FullCutLimitResponseMap" type="com.sibu.orderHelper.integral.reponse.CouponFullCutLimitResponse">
        <id property="id" column="id" />
        <result property="fullCutId" column="full_cut_id" />
        <result property="fullCutRange" column="full_cut_range" />
        <result property="fullCutRangeId" column="full_cut_range_id"/>
        <result property="rangeName" column="range_name" />
    </resultMap>

    <!--查询列表-->
    <sql id="couponDirectSql">
        id,product_id,range_name,product_range,coupon_money,coupon_num,direct_cut_instruction,coupon_name,coupon_type,receive_start_date,receive_end_date
        ,use_start_date,use_end_date,status,receive_num,get_source,supplier_id,supplier_name,platform_type
    </sql>
    <sql id="couponFullCutSql">
        id,full_money,cut_money,coupon_num,full_cut_instruction,coupon_name,receive_start_date,receive_end_date
        ,use_start_date,use_end_date,status,receive_num,get_source
    </sql>
    <!--获取对象-->
    <select id="getCouponDirectById" parameterType="java.lang.Integer" resultMap="couponDirectResponse">
        SELECT <include refid="couponDirectSql"/>
        from coupon_direct_cut
        where id = #{id}
        limit 1
    </select>
    <select id="getCouponFullCutById" parameterType="java.lang.Integer" resultMap="couponFullCutResponse">
        SELECT <include refid="couponFullCutSql"/>
        from coupon_full_cut
        where id = #{id}
        limit 1
    </select>
    <resultMap id="couponDirectResponse" type="com.sibu.orderHelper.integral.reponse.CouponDirectResponse">
        <id property="id" column="id" javaType="java.lang.Long" jdbcType="BIGINT"/>
        <result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result property="productId" column="product_id" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result property="rangeName" column="range_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result property="productRange" column="product_range" javaType="java.lang.Short" jdbcType="TINYINT"/>
        <result property="couponMoney" column="coupon_money" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
        <result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
        <result property="directCutInstruction" column="direct_cut_instruction" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result property="couponType" column="coupon_type" javaType="java.lang.Short" jdbcType="TINYINT"/>
        <result property="receiveStartDate" column="receive_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="receiveEndDate" column="receive_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="useStartDate" column="use_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="useEndDate" column="use_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" javaType="java.lang.Short" jdbcType="TINYINT"/>
        <result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
        <result property="getSource" column="get_source" javaType="java.lang.Short" jdbcType="TINYINT"/>
        <result column="supplier_id" property="supplierId" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result column="supplier_name" property="supplierName" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result column="platform_type" property="platformType" javaType="java.lang.Integer" jdbcType="INTEGER"/>
    </resultMap>
    <resultMap id="couponFullCutResponse" type="com.sibu.orderHelper.integral.reponse.CouponFullCutResponse">
        <id property="id" column="id" javaType="java.lang.Long" jdbcType="BIGINT"/>
        <result property="couponName" column="coupon_name" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result property="fullMoney" column="full_money" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
        <result property="cutMoney" column="cut_money" javaType="java.math.BigDecimal" jdbcType="DECIMAL"/>
        <result property="couponNum" column="coupon_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
        <result property="fullCutInstruction" column="full_cut_instruction" javaType="java.lang.String" jdbcType="VARCHAR"/>
        <result property="receiveStartDate" column="receive_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="receiveEndDate" column="receive_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="useStartDate" column="use_start_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="useEndDate" column="use_end_date" javaType="java.util.Date" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" javaType="java.lang.Short" jdbcType="TINYINT"/>
        <result property="receiveNum" column="receive_num" javaType="java.lang.Integer" jdbcType="INTEGER"/>
        <result property="getSource" column="get_source" javaType="java.lang.Short" jdbcType="TINYINT"/>
    </resultMap>
</mapper>