123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?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.caimei.modules.order.dao.CmDiscernReceiptDao">
- <insert id="insertOrderReceipt" keyColumn="id" keyProperty="id"
- parameterType="com.caimei.modules.order.entity.ReceiptVo" useGeneratedKeys="true">
- insert into cm_discern_receipt(payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
- receiptDate, confirmDate, reviewDate, delFlag, receStatct)
- values (#{payWay}, #{payType}, #{receiptType}, #{receiptStatus}, #{receiptAmount}, 4, now(), now(), now(), 0, 0)
- </insert>
- <insert id="insertOrderRelation">
- INSERT INTO cm_receipt_order_relation(relationType,
- receiptID,
- associateAmount,
- orderID,
- delFlag)
- VALUES (#{relationType},
- #{receiptId},
- #{receiptAmount},
- #{orderId},
- 0)
- </insert>
- <select id="findRebateOrderId" resultType="integer">
- select cso.orderId AS orderId
- from cm_receipt_order_relation cror left join cm_shop_order cso
- on cror.orderId = cso.shopOrderId
- where cror.relationType = '1' and cror.delFlag = '0'
- and cso.orderId in
- <foreach collection="orderIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- </select>
- <select id="findOrderReceipt" resultType="double">
- select ifnull(sum(associateAmount),0)
- from cm_receipt_order_relation cror
- left join cm_discern_receipt cdr on cror.receiptId = cdr.id
- where cror.orderId = #{orderId}
- and cror.delFlag = '0'
- and cror.relationType = '2'
- and cdr.delFlag = '0'
- and cdr.receiptStatus = '3'
- </select>
- <select id="findReceiptList" resultType="com.caimei.modules.order.entity.ReceiptVo">
- SELECT
- a.id AS "receiptId",
- a.payWay AS "payWay",
- a.payType AS "payType",
- a.receiptStatus AS "receiptStatus",
- a.receiptAmount AS "receiptAmount",
- a.receiptDate AS "receiptTime",
- a.newReceiptType,
- cso.orderId AS orderId,
- cso.shopOrderNo as shopOrderNos,
- cso.shopOrderId as shopOrderId,
- cof.bankAccount AS bankNameType,
- cr.organizeId AS organizeId,
- cr.orderNo,
- cr.orderType,
- (CASE WHEN cr.orderType = '0' THEN
- ( CASE sp.status WHEN 91 THEN '默认采购员(官方账号)' ELSE sp.linkMan END )
- ELSE ''
- END) AS spName,
- c.name as clubName
- FROM cm_discern_receipt a
- left join cm_receipt_order_relation crr on crr.receiptId = a.id and crr.delFlag = '0'
- left join cm_order cr on cr.orderId = crr.orderId
- left join serviceprovider sp ON cr.spID = sp.serviceProviderID
- left join club c on cr.userId = c.userId
- left join cm_shop_order cso on cso.orderId = crr.orderId
- LEFT JOIN cm_offline_collection cof ON a.payType = cof.type
- <where>
- <if test="organizeId != null">
- AND cr.organizeId = #{organizeId}
- </if>
- <if test="receiptId != null">
- AND a.id = #{receiptId}
- </if>
- <if test="startTime != null and startTime != ''">
- AND (a.receiptDate > #{startTime} OR a.receiptDate = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (a.receiptDate < #{endTime} OR a.receiptDate = #{endTime})
- </if>
- <if test="payWay != null and payWay != ''">
- AND a.payWay = #{payWay}
- </if>
- <if test="payType != null and payType != ''">
- AND a.payType = #{payType}
- </if>
- <if test="receiptStatus != null and receiptStatus != ''">
- AND a.receiptStatus = #{receiptStatus}
- </if>
- <if test="orderNo != null and orderNo != ''">
- AND ((cr.orderNo like concat('%',#{orderNo},'%')) OR (cso.shopOrderNo like concat('%',#{orderNo},'%')))
- </if>
- <if test="orderId != null and orderId != ''">
- AND cr.orderId = #{orderId}
- </if>
- <if test="clubName != null and clubName != ''">
- AND (c.name LIKE concat('%',#{clubName},'%'))
- </if>
- <if test="receiptProgress != null">
- AND cr.receiptStatus = #{receiptProgress}
- </if>
- <if test="orderType != null">
- AND cr.orderType = #{orderType}
- </if>
- <if test="associationNum != null and associationNum != ''">
- <if test="associationNum == 1">
- and (select count(1) from cm_receipt_order_relation where receiptId = a.id and delFlag = '0') = 1
- </if>
- <if test="associationNum == 2">
- and (select count(1) from cm_receipt_order_relation where receiptId = a.id and delFlag = '0')
- <![CDATA[ > ]]> 1
- </if>
- </if>
- and a.delFlag = 0
- </where>
- group by a.id
- order by a.id desc
- </select>
- <select id="findReceiptDetail" resultType="com.caimei.modules.order.entity.ReceiptDetail">
- select cdr.id AS receiptId,
- cof.bankAccount AS bankNameType,
- cdr.receiptAmount AS receiptAmount,
- cdr.receiptDate AS receiptDate,
- cdr.receiptStatus AS receiptStatus,
- cdr.smsContent AS smsContent,
- cdr.payWay AS payWay,
- cror.orderId
- from cm_discern_receipt cdr
- left join cm_receipt_order_relation cror on cdr.id = cror.receiptID
- LEFT JOIN cm_offline_collection cof ON cdr.payType = cof.type
- where cdr.id = #{id}
- </select>
- <select id="findReceiptOrder" resultType="com.caimei.modules.order.entity.ReceiptOrderInfo">
- select co.orderNo,
- co.orderId,
- co.payTotalFee as orderAmount,
- co.payableAmount,
- co.orderType,
- (select ifnull(sum(cror.associateAmount),0)
- from cm_receipt_order_relation cror
- left join cm_order o on o.orderId = cror.orderId
- left join cm_discern_receipt cdr on cdr.id = cror.receiptId
- where o.orderId = co.orderId
- and cror.delFlag = '0'
- and cdr.delFlag = '0'
- and cdr.receiptStatus = '3'
- ) AS receiptAmount,
- c.name AS clubName,
- co.receiptStatus,
- co.orderTime,
- (CASE WHEN co.orderType = '0' THEN
- ( CASE sp.status WHEN 91 THEN '默认采购员(官方账号)' ELSE sp.linkMan END )
- ELSE ''
- END) AS spName
- from cm_order co
- left join club c on co.userId = c.userId
- left join serviceprovider sp ON co.spID = sp.serviceProviderID
- where co.orderId = #{orderId}
- </select>
- <select id="findOrderRelation" resultType="com.caimei.modules.order.entity.OrderRelationRecord">
- SELECT receiptDate as receiptTime,
- cof.bankAccount as bankNameType,
- receiptAmount,
- cror.mbOrderId,
- cdr.payWay
- FROM cm_discern_receipt cdr
- left join cm_offline_collection cof on cdr.payType = cof.type
- left join cm_receipt_order_relation cror on cdr.id = cror.receiptId
- where cdr.id = #{receiptId}
- </select>
- <select id="findReceiptShopOrder" resultType="com.caimei.modules.order.entity.NewShopOrder">
- select cso.shopOrderNo,
- shopOrderId,
- cso.realPay,
- cso.receiptAmount,
- cso.receiptStatus as shopReceiptStatus
- from cm_order co
- left join cm_shop_order cso on co.orderId = cso.orderId
- where co.orderId = #{orderId}
- </select>
- <select id="findReceiptType" resultType="com.caimei.modules.order.entity.ReceiptPayType">
- select type as id, bankAccount as name
- from cm_offline_collection
- where type in (12,17,13,14,15,29,30,31)
- </select>
- <select id="findOrderIds" resultType="java.lang.String">
- select cror.orderID
- from cm_receipt_order_relation cror
- where cror.receiptID = #{id}
- and cror.delFlag = '0'
- and cror.relationType = '1'
- </select>
- <select id="hasReceiptRecordOrder" resultType="java.lang.String">
- select cror.receiptId
- from cm_receipt_order_relation cror
- left join cm_discern_receipt cdr on cror.receiptID = cdr.id
- where cror.orderID = #{orderID}
- and cror.receiptID != #{receiptID}
- and cror.relationType = '2'
- and cror.delFlag = '0'
- and cdr.receiptStatus = '3'
- and cdr.delFlag = '0'
- </select>
- <select id="findPayType" resultType="com.caimei.modules.order.entity.ReceiptPayType">
- select type as id, bankAccount as name
- from cm_offline_collection
- where organizeId = 4
- </select>
- </mapper>
|