123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- <?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">
- <sql id="cmDiscernReceiptColumns">
- a.id AS "id",
- a.payWay AS "payWay",
- a.payType AS "payType",
- a.receiptType AS "receiptType",
- a.receiptStatus AS "receiptStatus",
- a.smsContent AS "smsContent",
- a.smsMd5Code AS "smsMd5Code",
- a.receiptAmount AS "receiptAmount",
- a.handlingFee AS "handlingFee",
- a.confirmType AS "confirmType",
- a.confirmUserPermissionID AS "confirmUserPermissionID",
- a.reviewUserPermissionID AS "reviewUserPermissionID",
- a.cancelUserPermissionID AS "cancelUserPermissionID",
- a.transactionNum AS "transactionNum",
- a.bankID AS "bankID",
- a.bankCode AS "bankCode",
- a.kuaiQianPayTypeID AS "kuaiQianPayTypeID",
- a.kuaiQianPayerID AS "kuaiQianPayerID",
- a.rePayFlag AS "rePayFlag",
- a.actualAmount AS "actualAmount",
- a.formData AS "formData",
- a.problem AS "problem",
- a.noOrderReason AS "noOrderReason",
- a.reviewReason AS "reviewReason",
- a.cancelReason AS "cancelReason",
- a.receiptDate AS "receiptDate",
- a.confirmDate AS "confirmDate",
- a.reviewDate AS "reviewDate",
- a.cancelDate AS "cancelDate",
- a.updateDate AS "updateDate",
- a.delFlag AS "delFlag",
- a.newReceiptType
- </sql>
- <sql id="cmDiscernReceiptJoins">
- </sql>
- <select id="get" resultType="CmDiscernReceipt">
- SELECT
- <include refid="cmDiscernReceiptColumns"/>
- FROM cm_discern_receipt a
- <include refid="cmDiscernReceiptJoins"/>
- WHERE a.id = #{id}
- </select>
- <select id="getAssociateAmount" resultType="double">
- select IFNULL(sum(cdr.receiptAmount),0) From cm_receipt_order_relation cror
- LEFT JOIN cm_discern_receipt cdr on cdr.id = cror.receiptID
- where cror.orderID = #{orderID} and cror.relationType = '2' and cdr.delFlag = 0
- and cror.delFlag = 0 and cdr.receiptStatus in (3) and payWay != '3';
- </select>
- <select id="getReturnBalanceAmount" resultType="double">
- select IFNULL(sum(amount),0) from cm_user_balance_record where balanceType = 2 and receiptId = #{receiptId} and delFlag = 0;
- </select>
- <select id="discern" resultType="String">
- SELECT
- u.userID,
- csp.id AS receiptID,
- cms.orderID,
- cms.shopOrderID,
- cms.shopOrderNo,
- cms.orderType as orderType,
- s.name AS shopName,
- cms.productAmount,
- cmo.orderNo,
- u.userName,
- u.name AS jgName,
- cmo.confirmTime,
- cms.receiptAmount,
- cms.needPayAmount
- FROM cm_shop_order cms
- LEFT JOIN shop s ON s.shopID = cms.shopID
- LEFT JOIN cm_order cmo ON cmo.orderID = cms.orderID
- LEFT JOIN `user` u ON u.userID = cms.userID
- LEFT JOIN cm_discern_receipt csp ON csp.shopOrderID = cms.shopOrderID
- </select>
- <select id="orderlist" resultType="CmDiscernReceipt">
- SELECT
- u.userID,
- csp.id AS receiptID,
- cms.orderID,
- cms.shopOrderID,
- cms.shopOrderNo,
- cms.orderType as orderType,
- s.name AS shopName,
- cms.productAmount,
- cmo.orderNo,
- u.userName,
- u.name AS jgName,
- cmo.confirmTime,
- cms.receiptAmount,
- cms.needPayAmount
- FROM cm_shop_order cms
- LEFT JOIN shop s ON s.shopID = cms.shopID
- LEFT JOIN cm_order cmo ON cmo.orderID = cms.orderID
- LEFT JOIN `user` u ON u.userID = cms.userID
- LEFT JOIN cm_discern_receipt csp ON csp.shopOrderID = cms.shopOrderID
- where csp.id=#{id}
- </select>
- <select id="findList" resultType="CmDiscernReceipt">
- -- relationType值为1是为子订单ID,为2时为主订单ID)
- SELECT
- <include refid="cmDiscernReceiptColumns"/>,
- cso_s.orderID AS orderID,
- cso_s.shopOrderNo as shopOrderNos,
- cso.shopOrderId as shopOrderId,
- cof.bankAccount AS bankNameType,
- s.checkMan,
- IF(crr.relationType = '1', s.name,IFNULL(s_a.name,'')) AS shopName,
- (case when crr.relationType = '1' then u_cr.userName else u.userName
- end) AS "userName",
- (case when crr.relationType = '1' then u_cr.name else u.name
- end) AS "name",
- IF(crr.relationType = '6',(SELECT NAME FROM USER mu WHERE mu.userId=ccb.userId),'') AS "backname",
- cr.organizeID AS organizeID
- FROM cm_discern_receipt a
- left join cm_receipt_order_relation crr on crr.receiptID = a.id and crr.delFlag = '0'
- LEFT JOIN cm_coupon_buyrecord ccb ON crr.couponRecordId=ccb.id
- -- 主订单
- left join cm_order cr on cr.orderID = crr.orderID
- left join user u on u.userID = cr.userID
- -- 子订单
- left join cm_shop_order cso on cso.shopOrderID = crr.orderID
- left join cm_order cso_cr on cso.orderID = cso_cr.orderID
- LEFT JOIN USER u_cr ON u_cr.userID = cso_cr.userID
- -- 供应商
- LEFT JOIN shop s ON s.shopID = cso.shopID
- LEFT JOIN cm_shop_order cso_s ON cso_s.shopOrderID = a.shopOrderID
- LEFT JOIN cm_shop_order cso_a ON cso_a.shopOrderID = crr.shopOrderID
- LEFT JOIN shop s_a ON s_a.shopID = cso_a.shopID
- LEFT JOIN cm_offline_collection cof ON a.payType = cof.type
- <where>
- <if test="id != null and id != '' and id != 0 ">
- AND a.id = #{id}
- </if>
- <if test="organizeID != null and organizeID != 9999 ">
- AND cr.organizeID = #{organizeID}
- </if>
- <if test="organizeID == 9999 ">
- AND cr.orderType = 2
- </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="receiptType != null and receiptType != ''">
- <if test="receiptType==2 and newReceiptType==3">
- and (a.receiptType = 9)
- or a.receiptType = #{receiptType}
- </if>
- <if test="receiptType!=2">
- AND a.receiptType = #{receiptType}
- </if>
- AND a.receiptType = #{receiptType}
- </if>
- <if test="newReceiptType !=null">
- <if test="newReceiptType==3">
- and a.newReceiptType =3
- </if>
- <if test="newReceiptType != 3">
- and a.newReceiptType=#{newReceiptType}
- </if>
- </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} OR (crr.relationType = '1' AND cso_cr.orderID = #{orderID}))
- </if>
- <if test="userName != null and userName != ''">
- AND (u.userName LIKE concat('%',#{userName},'%') or u.name LIKE concat('%',#{userName},'%'))
- </if>
- <if test="receiptProgress != null and receiptProgress != ''">
- and (case when crr.relationType = '1' then
- cso_cr.receiptStatus
- else
- cr.receiptStatus
- end) = #{receiptProgress}
- </if>
- <if test="receiptOrderType != null and receiptOrderType != ''">
- and (case when crr.relationType = '1' then
- cso.orderType
- else
- cr.orderType
- end) = #{receiptOrderType}
- </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>
- <if test="paYee !=null and paYee != ''">
- <if test="paYee == '采美'">
- and a.payWay = 3
- OR a.payWay = 2
- AND a.newReceiptType != 3 AND a.payWay = 2
- </if>
- <if test="payWay==1">
- and s.name=#{paYee}
- </if>
- </if>
- and a.delFlag = '0' group by a.id
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- order by a.receiptDate desc
- </otherwise>
- </choose>
- </select>
- <select id="findAllList" resultType="CmDiscernReceipt">
- SELECT
- <include refid="cmDiscernReceiptColumns"/>
- FROM cm_discern_receipt a
- <include refid="cmDiscernReceiptJoins"/>
- <where>
- </where>
- <choose>
- <when test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </select>
- <select id="exportTest" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT
- r.orderID,
- (select group_concat(distinct p.name) from product p left join cm_order_product cop on p.productID = cop.productID where cop.orderID = o.orderID group by cop.orderID) as productNames,
- IF(u.userIdentity = 2,u.name,u.userName) AS userName,
- d.receiptDate,
- d.payType,
- IFNULL(r.associateAmount,0) as associateAmount,
- cof.bankAccount AS bankNameType,
- d.receiptType
- FROM
- cm_receipt_order_relation r
- LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
- LEFT JOIN cm_order o ON r.orderID = o.orderID
- LEFT JOIN USER u ON u.userID = o.userID
- LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
- <where>
- <if test="startTime != null and startTime != ''">
- AND (d.receiptDate <![CDATA[ >= ]]> #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (d.receiptDate <![CDATA[ <= ]]> #{endTime})
- </if>
- <if test="receiptProgress != null and receiptProgress != ''">
- AND o.receiptStatus = #{receiptProgress}
- </if>
- AND d.receiptType = 1
- AND d.receiptStatus = 3
- AND d.delFlag = '0'
- AND r.delFlag = '0'
- </where>
- ORDER BY
- d.receiptDate DESC;
- </select>
- <select id="exportRebate" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT
- so.orderID,
- (select group_concat(distinct p.name) from product p left join cm_order_product cop on p.productID = cop.productID where cop.orderID = so.orderID group by cop.orderID) as productNames,
- IF(u.userIdentity = 2,u.name,u.userName) AS userName,
- d.receiptDate,
- d.payType,
- IFNULL(d.receiptAmount,0) as associateAmount,
- cof.bankAccount AS bankNameType,
- d.receiptType
- FROM
- cm_receipt_order_relation r
- LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
- LEFT JOIN cm_shop_order so ON r.orderID = so.shopOrderID
- LEFT JOIN USER u ON u.userID = so.userID
- LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
- <where>
- <if test="startTime != null and startTime != ''">
- AND (d.receiptDate <![CDATA[ >= ]]> #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (d.receiptDate <![CDATA[ <= ]]> #{endTime})
- </if>
- <if test="receiptProgress != null and receiptProgress != ''">
- AND o.receiptStatus = #{receiptProgress}
- </if>
- AND d.receiptStatus = 2
- AND d.delFlag = '0'
- AND r.delFlag = '0'
- AND r.relationType='1'
- </where>
- ORDER BY
- d.receiptDate DESC;
- </select>
- <!--订单已付款又进行交易全退,此处需要结合订单状态导出,单纯的进账会不明确-->
- <select id="exportReceiptPay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT
- DISTINCT r.orderID
- FROM
- cm_receipt_order_relation r
- LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
- LEFT JOIN cm_order o ON r.orderID = o.orderID
- LEFT JOIN USER u ON u.userID = o.userID
- <where>
- <if test="startTime != null and startTime != ''">
- AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
- </if>
- <if test="receiptProgress != null and receiptProgress != ''">
- AND o.receiptStatus = #{receiptProgress}
- </if>
- AND d.receiptStatus = 3
- AND d.delFlag = '0'
- AND r.delFlag = '0'
- </where>
- ORDER BY
- d.receiptDate DESC;
- </select>
- <select id="exportOnlyBalancePay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT
- DISTINCT o.orderID
- FROM
- cm_order o
- <where>
- <if test="startTime != null and startTime != ''">
- AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
- </if>
- <if test="receiptProgress != null and receiptProgress != ''">
- AND o.receiptStatus = #{receiptProgress}
- </if>
- AND o.balancePayFee > 0
- AND o.delFlag = '0'
- </where>
- HAVING (SELECT count(a.id) as num from cm_receipt_order_relation a left JOIN cm_discern_receipt d on a.receiptID
- = d.id where a.orderID=o.orderID and d.receiptStatus = 3 and d.delFlag = '0') = 0
- ORDER BY
- o.orderTime DESC;
- </select>
- <select id="exportPay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT
- ps.id AS orderID,
- u.`name` AS userName,
- r.payTime AS receiptDate,
- ps.payType AS payType,
- ps.totalAmount AS associateAmount,
- GROUP_CONCAT(CONCAT(ss.shopOrderID , '/' ,ss.payedShopAmount , '/' , ss.`userName` )) AS shopOrderID
- FROM
- cm_pay_shop ps
- LEFT JOIN cm_pay_shop_record r ON ps.id = r.payShopID
- LEFT JOIN (select so.shopOrderID,so.payedShopAmount,o.userName from cm_shop_order so LEFT JOIN user o on
- o.userID = so.userID) as ss on ss.shopOrderID = r.shopOrderID
- LEFT JOIN shop u ON r.shopID = u.shopID
- <where>
- <if test="startTime != null and startTime != ''">
- AND (r.payTime <![CDATA[ > ]]> #{startTime} OR r.payTime = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (r.payTime <![CDATA[ < ]]> #{endTime} OR r.payTime = #{endTime})
- </if>
- AND r. STATUS = 1
- AND ps. STATUS = 1
- </where>
- GROUP BY
- ps.id
- ORDER BY
- r.payTime DESC;
- </select>
- <select id="exportPayData" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT DISTINCT
- o.orderID
- FROM
- cm_order o
- LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
- LEFT JOIN cm_pay_shop_record psr ON psr.shopOrderID = so.shopOrderID
- <where>
- <if test="startTime != null and startTime != ''">
- AND (psr.payTime <![CDATA[ > ]]> #{startTime} OR psr.payTime = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (psr.payTime <![CDATA[ < ]]> #{endTime} OR psr.payTime = #{endTime})
- </if>
- <if test="receiptProgress != null and receiptProgress != ''">
- AND o.payStatus = #{receiptProgress}
- </if>
- AND psr. STATUS = 1
- </where>
- ORDER BY
- psr.payTime DESC
- </select>
- <select id="exportOrderDate" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT DISTINCT
- o.orderID,o.status
- FROM
- cm_order o
- <where>
- <if test="startTime != null and startTime != ''">
- AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
- </if>
- AND o.delFlag='0'
- AND o.status!='6'
- AND o.orderID NOT IN (
- SELECT so.orderID
- FROM cm_shop_order so
- LEFT JOIN cm_receipt_order_relation ror ON ror.orderID = so.shopOrderID
- LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
- WHERE ror.relationType = '1'
- AND dr.receiptStatus = '2'
- AND so.delFlag = '0'
- GROUP BY so.orderID
- )
- </where>
- </select>
- <select id="getListOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT o.orderID, o.status, SUM(dr.receiptAmount) AS receiptAmount, ror.relationType
- FROM cm_order o
- LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
- LEFT JOIN cm_receipt_order_relation ror ON so.shopOrderID = ror.`orderID`
- LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
- <where>
- <if test="startTime != null and startTime != ''">
- AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
- </if>
- AND ror.`relationType` = '1'
- AND dr.receiptStatus = '2'
- AND o.delFlag='0'
- </where>
- GROUP BY o.orderID
- </select>
- <select id="exportPayment" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT so.orderID, ror.relationType, SUM(dr.receiptAmount) AS receiptAmount
- FROM cm_shop_order so
- LEFT JOIN cm_receipt_order_relation ror ON ror.orderID = so.shopOrderID
- LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
- <where>
- <if test="startTime != null and startTime != ''">
- AND (dr.receiptDate <![CDATA[ > ]]> #{startTime} OR dr.receiptDate = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (dr.receiptDate <![CDATA[ < ]]> #{endTime} OR dr.receiptDate = #{endTime})
- </if>
- AND ror.relationType = '1'
- AND dr.receiptStatus = '2'
- AND so.delFlag = '0'
- </where>
- GROUP BY so.orderID
- </select>
- <insert id="insert" parameterType="CmDiscernReceipt" keyProperty="id" useGeneratedKeys="true">
- INSERT INTO cm_discern_receipt(
- payWay,
- payType,
- receiptType,
- receiptStatus,
- smsContent,
- smsMd5Code,
- receiptAmount,
- handlingFee,
- confirmType,
- confirmUserPermissionID,
- reviewUserPermissionID,
- cancelUserPermissionID,
- transactionNum,
- bankID,
- bankCode,
- kuaiQianPayTypeID,
- kuaiQianPayerID,
- rePayFlag,
- actualAmount,
- formData,
- problem,
- noOrderReason,
- reviewReason,
- cancelReason,
- receiptDate,
- confirmDate,
- reviewDate,
- cancelDate,
- updateDate,
- delFlag
- ) VALUES (
- #{payWay},
- #{payType},
- #{receiptType},
- #{receiptStatus},
- #{smsContent},
- #{smsMd5Code},
- #{receiptAmount},
- #{handlingFee},
- #{confirmType},
- #{confirmUserPermissionID},
- #{reviewUserPermissionID},
- #{cancelUserPermissionID},
- #{transactionNum},
- #{bankID},
- #{bankCode},
- #{kuaiQianPayTypeID},
- #{kuaiQianPayerID},
- #{rePayFlag},
- #{actualAmount},
- #{formData},
- #{problem},
- #{noOrderReason},
- #{reviewReason},
- #{cancelReason},
- #{receiptDate},
- #{confirmDate},
- #{reviewDate},
- #{cancelDate},
- #{cancelDate},
- #{delFlag}
- )
- </insert>
- <update id="update">
- UPDATE cm_discern_receipt SET
- payWay = #{payWay},
- payType = #{payType},
- receiptType = #{receiptType},
- receiptStatus = #{receiptStatus},
- smsContent = #{smsContent},
- smsMd5Code = #{smsMd5Code},
- receiptAmount = #{receiptAmount},
- handlingFee = #{handlingFee},
- confirmType = #{confirmType},
- confirmUserPermissionID = #{confirmUserPermissionID},
- reviewUserPermissionID = #{reviewUserPermissionID},
- cancelUserPermissionID = #{cancelUserPermissionID},
- transactionNum = #{transactionNum},
- bankID = #{bankID},
- bankCode = #{bankCode},
- kuaiQianPayTypeID = #{kuaiQianPayTypeID},
- kuaiQianPayerID = #{kuaiQianPayerID},
- rePayFlag = #{rePayFlag},
- actualAmount = #{actualAmount},
- formData = #{formData},
- problem = #{problem},
- noOrderReason = #{noOrderReason},
- reviewReason = #{reviewReason},
- cancelReason = #{cancelReason},
- receiptDate = #{receiptDate},
- confirmDate = #{confirmDate},
- reviewDate = #{reviewDate},
- cancelDate = #{cancelDate},
- updateDate = DATE_FORMAT(#{updateDate},'%Y-%m-%d %H:%i:%s'),
- balanceAccountsRemark = #{balanceAccountsRemark},
- delFlag = #{delFlag}
- WHERE id = #{id}
- </update>
- <delete id="delete">
- DELETE FROM cm_discern_receipt
- WHERE id = #{id}
- </delete>
- <select id="getOrderIDStr" parameterType="string" resultType="map">
- -- relationType值为1是为子订单ID,为2时为主订单ID)
- select
- (case when cror.relationType = '1'
- then concat('子订单',cso.shopOrderNo,'(', cso.shopOrderID,')')
- else concat(cou.orderNo,'(', cou.orderID,')')
- end) AS orderNo,
- (CASE WHEN cror.relationType = '1'
- THEN co.orderID
- ELSE cou.orderID
- END) AS orderID ,
- (case when cror.relationType = '1'
- then (select b.orderType from cm_shop_order b where cso.shopOrderID = b.shopOrderID)
- else (select c.orderType from cm_order c where cou.orderID = c.orderID)
- end) AS orderType
- from cm_receipt_order_relation cror
- left join cm_shop_order cso on cror.orderID = cso.shopOrderID
- left join cm_order co on cso.orderID = co.orderID
- LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
- where cror.receiptID = #{id} and cror.delFlag = '0'
- </select>
- <select id="getInfos" parameterType="CmDiscernReceipt" resultType="com.caimei.modules.order.entity.ReceiptDetailVo">
- select
- cdr.id AS receiptID,
- cdr.receiptType AS receiptType,
- cdr.confirmType AS confirmType,
- cdr.payType AS payType,
- cof.bankAccount AS bankNameType,
- cdr.receiptAmount AS receiptAmount,
- cdr.receiptDate AS receiptDate,
- cdr.receiptStatus AS receiptStatus,
- cdr.noOrderReason AS noOrderReason,
- cdr.confirmDate AS confirmTime,
- cdr.smsContent AS smsContent,
- cdr.cancelReason AS cancelReason,
- cdr.payWay AS payWay,
- rup.name AS confirmer,
- cdr.rebateRemarks AS rebateRemarks,
- cdr.shopName as shopName
- from
- cm_discern_receipt cdr
- left join receipt_user_permission rup on cdr.confirmUserPermissionID = rup.id
- LEFT JOIN cm_offline_collection cof ON cdr.payType = cof.type
- where cdr.id = #{receiptID}
- </select>
- <select id="getOrderInfoByShopOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
- select
- cso.orderNo AS orderNo,
- cso.orderID AS orderID,
- co.payTotalFee AS orderAmount,
- co.payableAmount AS payableAmount,
- co.onlinePayFlag,
- (select
- sum(o.needPayAmount)
- from cm_receipt_order_relation cror
- left join cm_shop_order o on cror.orderID = o.shopOrderID
- left join cm_discern_receipt cdr on cdr.id = cror.receiptID
- where o.orderID = cso.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
- and cdr.receiptStatus = '2'
- ) AS receiptAmount,
- bou.name AS customerName,
- co.receiptStatus AS receiptStatus,
- co.orderType AS orderType,
- co.orderTime AS orderTime,
- co.userID AS userID,
- cso.shopOrderNo AS shopOrderNo,
- cso.shopOrderID AS shopOrderID,
- cso.needPayAmount AS shopOrderAmount,
- cso.shouldPayShopAmount AS shouldPayShopAmount,
- cso.payedShopAmount AS payedShopAmount,
- s.name AS shopName
- from cm_shop_order cso
- left join cm_order co on cso.orderID = co.orderID
- left join shop s on cso.shopID = s.shopID
- left join bp_order_userinfo bou on bou.orderId = cso.orderID
- where cso.shopOrderID = #{shopOrderID}
- </select>
- <select id="getOrderInfoByOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
- select
- co.orderNo AS orderNo,
- co.orderID AS orderID,
- co.payTotalFee AS orderAmount,
- co.payableAmount AS payableAmount,
- co.onlinePayFlag,
- (select
- sum(cror.associateAmount)
- 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,
- bou.name AS customerName,
- co.receiptStatus AS receiptStatus,
- co.orderType AS orderType,
- co.orderTime AS orderTime,
- co.organizeID AS organizeID,
- co.userID AS userID
- from cm_order co
- left join bp_order_userinfo bou on bou.orderId = co.orderID
- where co.orderID = #{orderID}
- </select>
- <select id="findReceiptRecordByOrderID" resultType="com.caimei.modules.order.entity.ReceiptRecordVo">
- select
- cror.receiptID AS receiptID,
- cdr.receiptDate AS receiptTime,
- cdr.receiptStatus AS receiptStatus,
- cdr.confirmType AS confirmType,
- cdr.receiptType AS receiptType,
- cdr.payType AS payType,
- cof.bankAccount AS bankNameType,
- cdr.receiptAmount AS receiptAmount,
- cror.associationType AS associationType,
- cdr.payWay AS payWay,
- cdr.transactionNum AS transactionNum,
- cror.mbOrderId AS mbOrderId,
- cdr.confirmUserPermissionID AS confirmUserPermissionID,
- (select rup.name from receipt_user_permission rup where rup.id = cdr.confirmUserPermissionID) AS
- confirmUserName,
- cdr.confirmDate AS confirmDate,
- cdr.reviewUserPermissionID AS reviewUserPermissionID,
- (select rup.name from receipt_user_permission rup where rup.id = cdr.reviewUserPermissionID) AS reviewUserName,
- cdr.reviewDate AS reviewDate,
- cdr.cancelUserPermissionID AS cancelUserPermissionID,
- (select su.name from sys_user su where su.id = cdr.cancelUserPermissionID) AS cancelUserName,
- cdr.cancelDate AS cancelDate,
- cdr.cancelReason AS cancelReason
- from cm_receipt_order_relation cror
- join cm_discern_receipt cdr on cdr.id = cror.receiptID
- join cm_offline_collection cof on cdr.payType = cof.type
- where cror.delFlag = '0' and cdr.delFlag = '0'
- <if test="relationType == 1">
- and cror.orderID in (select shopOrderID from cm_shop_order where orderID = #{orderID}) and cror.relationType
- = '1'
- </if>
- <if test="relationType == 2">
- and cror.orderID = #{orderID} and cror.relationType = '2'
- </if>
- </select>
- <select id="findOrderIDs" resultType="string">
- select orderID from cm_receipt_order_relation cror
- where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '2'
- </select>
- <select id="hasReceiptRecordOrder" resultType="string">
- select cror.receiptID
- from cm_receipt_order_relation cror
- 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="findShopOrderIDs" resultType="string">
- select cror.orderID from cm_receipt_order_relation cror
- where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '1'
- </select>
- <select id="hasReceiptRecordShopOrder" resultType="string">
- select cror.receiptID
- from cm_receipt_order_relation cror
- join cm_discern_receipt cdr on cror.receiptID = cdr.id
- where cror.orderID in
- (select cso2.shopOrderID
- from cm_shop_order cso1
- left join cm_shop_order cso2 on cso2.orderID = cso1.orderID
- where cso1.shopOrderID = #{shopOrderID} and cso2.shopOrderID != #{shopOrderID})
- and cror.orderID != #{shopOrderID}
- and cdr.receiptStatus = '2' and cdr.delFlag = '0'
- and cror.relationType = '1' and cror.delFlag = '0'
- </select>
- <select id="getExportInfo" resultType="com.caimei.modules.order.entity.ReceiptExportVo">
- -- 1订单款,2非订单款,3返佣款
- select
- (case when co.orderType = '0' then '协销' else '自主' end) AS type,
- (case when co.freePostFlag = '1'
- then co.freight else 0 end) as freight,
- (select sum(cop.totalAddedValueTax) from cm_order_product cop where cop.orderID = co.orderID) AS tax,
- <if test="t == 1">
- -- 1订单款
- co.payTotalFee AS amount,
- cror.associateAmount AS associateAmount,
- co.orderNo AS no,
- </if>
- <if test="t == 3">
- -- 3返佣款
- concat(cso.needPayAmount, '(子)') AS amount,
- concat(cso.needPayAmount, '(子)') AS associateAmount,
- concat(cso.shopOrderNo, '(子)') AS no,
- </if>
- co.orderID AS id
- from cm_receipt_order_relation cror
- left join cm_discern_receipt cdr on cror.receiptID = cdr.id
- <if test="t == 1">
- left join cm_order co on cror.orderID = co.orderID
- </if>
- <if test="t == 3">
- left join cm_shop_order cso on cror.orderID = cso.shopOrderID
- left join cm_order co on cso.orderID = co.orderID
- </if>
- where cror.receiptID = #{id} and cror.delFlag = '0'
- and cdr.delFlag = '0'
- <if test="t == 1">
- and cror.relationType = '2'
- </if>
- <if test="t == 3">
- and cror.relationType = '1'
- </if>
- </select>
- <select id="getReceiptRecords" resultType="integer">
- select cror.receiptID from cm_receipt_order_relation cror
- where cror.delFlag = '0' and (
- (cror.orderID = #{shopOrderID} and cror.relationType = '1')
- or
- (cror.orderID in (select orderID from cm_shop_order where shopOrderID = #{shopOrderID}) and cror.relationType = '2')
- )
- </select>
- <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
- LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
- where cror.relationType = '1' and cror.delFlag = '0' AND cdr.receiptStatus = '2'
- and cdr.receiptType = '3' and cso.orderID in
- <foreach collection="orderIds" item="id" open="(" close=")" separator=",">
- #{id}
- </foreach>
- </select>
- <select id="findShopOrder" resultType="com.caimei.modules.order.entity.CmReceiptExport">
- SELECT
- o.orderID,
- o.payStatus,
- so.shopID,
- so.shopOrderID,
- o.orderTime,
- u.userName,
- p. NAME AS supplierName,
- (
- so.productAmount - IFNULL(so.discountAmount, 0)
- ) AS productFee,
- IFNULL(so.totalAddedValueTax,0) AS taxFee,
- IFNULL(so.totalAmount,0) AS receiptAmount,
- IFNULL(so.shopTaxFee,0) AS payTaxFee,
- IFNULL(so.shopPostFee,0) AS payFreight,
- IFNULL(so.shopOtherFee,0) AS payOther,
- IFNULL(so.shouldPayShopAmount,0) AS payAmount,
- IFNULL(so.productAmount,0) AS productAmount
- FROM
- cm_order o
- LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
- LEFT JOIN user u ON u.userID = o.userID
- LEFT JOIN shop p ON p.shopID = so.shopID
- WHERE
- o.orderID = #{orderID}
- AND so.delFlag = 0
- AND o.delFlag = 0;
- </select>
- <select id="findSmoothoutInfo" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
- select * from cm_discern_receipt cdr
- LEFT JOIN cm_receipt_order_relation cror on cror.receiptID = cdr.id
- where cdr.receiptType = 1 and cror.relationType = 2 and cror.delFlag = 0
- and cdr.delFlag = 0 and cdr.confirmType in (1,2,3) and cdr.receiptStatus = '3'
- and cror.orderID = #{orderID} LIMIT 1;
- </select>
- <select id="findOrderReceipt" resultType="double">
- select sum(associateAmount) 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' and cdr.payWay != '3'
- </select>
- <select id="gathering" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT
- d.receiptDate,d.payType
- FROM
- cm_receipt_order_relation r
- LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
- WHERE r.orderID=#{orderID}
- AND d.receiptStatus = 3
- AND d.delFlag = '0'
- AND r.delFlag = '0'
- </select>
- <select id="exportRefund" resultType="com.caimei.modules.order.entity.CmReturnedPurchase">
- SELECT bou.name as userName, cof.bankAccount AS bankNameType, crp.*
- FROM `cm_returned_purchase` crp
- LEFT JOIN bp_order_userinfo bou ON bou.orderId = crp.orderId
- LEFT JOIN cm_offline_collection cof ON crp.payType = cof.type
- <where>
- <if test="startTime != null and startTime != ''">
- AND (crp.confirmReturnTime <![CDATA[ > ]]> #{startTime} OR crp.confirmReturnTime = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (crp.confirmReturnTime <![CDATA[ < ]]> #{endTime} OR crp.confirmReturnTime = #{endTime})
- </if>
- AND crp.status= 2
- </where>
- ORDER BY crp.confirmReturnTime DESC
- </select>
- <select id="theOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
- FROM cm_discern_receipt d
- LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
- <where>
- <if test="startTime != null and startTime != ''">
- AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
- </if>
- AND d.receiptStatus = 2
- AND d.receiptType = 2
- AND d.delFlag = '0'
- </where>
- ORDER BY d.receiptDate DESC;
- </select>
- <select id="findDiscernReceipt" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
- SELECT
- cdr.*
- FROM
- cm_discern_receipt cdr
- LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
- WHERE
- cdr.receiptType = 1
- AND cror.relationType = 2
- AND cdr.receiptStatus = 3
- AND cror.delFlag = 0
- AND cdr.delFlag = 0
- AND cror.orderID = #{orderID}
- ORDER BY
- id DESC
- LIMIT
- 1
- </select>
- <select id="findPayType" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
- SELECT
- cdr.*
- FROM
- cm_discern_receipt cdr
- LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
- WHERE
- cdr.receiptType = 1
- AND cror.relationType = 2
- AND cdr.receiptStatus = 3
- AND cror.delFlag = 0
- AND cdr.delFlag = 0
- AND cror.orderID = #{orderID}
- ORDER BY
- payWay ASC
- LIMIT
- 1
- </select>
- <select id="findOrderLastReceiptDetailId" resultType="java.lang.Integer">
- select cdr.id
- from cm_discern_receipt cdr
- left join cm_receipt_order_relation cror on cdr.id = cror.receiptID
- where cdr.delFlag = '0'
- and cror.delFlag = '0'
- and cror.orderID = #{orderID}
- order by cdr.id desc
- limit 1
- </select>
- <select id="findSplitTime" resultType="date">
- SELECT
- splitTime
- FROM
- cm_split_account
- WHERE
- payStatus = 1
- AND orderId = #{orderID}
- ORDER BY
- splitTime DESC
- LIMIT
- 1
- </select>
- <select id="getVipRecordId" resultType="java.lang.Integer">
- select vipRecordId from cm_receipt_order_relation where receiptID=#{receiptId}
- </select>
- <select id="getVipUserId" resultType="java.lang.Integer">
- select userId from cm_svip_history where id=#{vipRecordId}
- </select>
- <select id="getUserNameByUserId" resultType="java.lang.String">
- select userName from user where userID = #{userId} LIMIT 1
- </select>
- <select id="getReceiptVipInfo" resultType="com.caimei.modules.order.entity.ReceiptVipInfoVo">
- select svipr.id,
- svipr.userId,
- svipr.packageId,
- svipr.beginTime,
- svipr.endTime,
- svipr.price,
- svipr.payTime,
- cror.orderRequestNo,
- cror.vipRecordId,
- svipp.duration,
- c.name as clubName
- from cm_svip_history svipr
- left join cm_receipt_order_relation cror on svipr.id = cror.vipRecordId
- left join club c on svipr.userId = c.userId
- left join cm_svip_package svipp on svipp.id = svipr.packageId
- where cror.receiptID=#{receiptID}
- LIMIT 1
- </select>
- <select id="svipReceipt" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT d.receiptDate, u.userName, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
- FROM cm_discern_receipt d
- left join cm_receipt_order_relation cror on d.id = cror.receiptID
- left join cm_svip_history csh on cror.vipRecordId = csh.id
- left join user u on csh.userId = u.userID
- LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
- <where>
- <if test="startTime != null and startTime != ''">
- AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
- </if>
- AND d.receiptStatus = 3
- AND d.receiptType = 6
- AND d.delFlag = '0'
- </where>
- ORDER BY d.receiptDate DESC;
- </select>
- <select id="secondReceipt" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
- SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
- FROM cm_discern_receipt d
- LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
- <where>
- <if test="startTime != null and startTime != ''">
- AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
- </if>
- <if test="endTime != null and endTime != ''">
- AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
- </if>
- AND d.receiptStatus = 3
- AND d.receiptType = 7
- AND d.delFlag = '0'
- </where>
- ORDER BY d.receiptDate DESC;
- </select>
- <select id="getCouponInfo" resultType="com.caimei.modules.order.entity.ReceipCouponInfoVo">
- SELECT c.name as clubName,cc.touchPrice,cc.couponAmount,cror.mborderId,cc.couponType,cdr.confirmDate
- FROM cm_receipt_order_relation cror
- LEFT JOIN cm_discern_receipt cdr ON cror.receiptID=cdr.id
- LEFT JOIN cm_order co ON cror.orderId=co.orderID
- LEFT JOIN club c ON co.userID=c.userID
- LEFT JOIN cm_coupon_buyrecord ccb ON ccb.id=cror.couponRecordId
- LEFT JOIN cm_coupon cc ON ccb.couponId=cc.id
- WHERE receiptID = #{receiptID}
- </select>
- <select id="getShopOrderInfos" 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>
- <if test="shopOrderId != null and shopOrderId != ''">
- and cso.shopOrderID = #{shopOrderId}
- </if>
- <if test="orderId != null and orderId != ''">
- and co.orderId = #{orderId}
- </if>
- </where>
- </select>
- </mapper>
|