CmDiscernReceiptMapper.xml 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.caimei.modules.order.dao.CmDiscernReceiptDao">
  4. <sql id="cmDiscernReceiptColumns">
  5. a.id AS "id",
  6. a.payWay AS "payWay",
  7. a.payType AS "payType",
  8. a.receiptType AS "receiptType",
  9. a.receiptStatus AS "receiptStatus",
  10. a.smsContent AS "smsContent",
  11. a.smsMd5Code AS "smsMd5Code",
  12. a.receiptAmount AS "receiptAmount",
  13. a.handlingFee AS "handlingFee",
  14. a.confirmType AS "confirmType",
  15. a.confirmUserPermissionID AS "confirmUserPermissionID",
  16. a.reviewUserPermissionID AS "reviewUserPermissionID",
  17. a.cancelUserPermissionID AS "cancelUserPermissionID",
  18. a.transactionNum AS "transactionNum",
  19. a.bankID AS "bankID",
  20. a.bankCode AS "bankCode",
  21. a.kuaiQianPayTypeID AS "kuaiQianPayTypeID",
  22. a.kuaiQianPayerID AS "kuaiQianPayerID",
  23. a.rePayFlag AS "rePayFlag",
  24. a.actualAmount AS "actualAmount",
  25. a.formData AS "formData",
  26. a.problem AS "problem",
  27. a.noOrderReason AS "noOrderReason",
  28. a.reviewReason AS "reviewReason",
  29. a.cancelReason AS "cancelReason",
  30. a.receiptDate AS "receiptDate",
  31. a.confirmDate AS "confirmDate",
  32. a.reviewDate AS "reviewDate",
  33. a.cancelDate AS "cancelDate",
  34. a.updateDate AS "updateDate",
  35. a.delFlag AS "delFlag",
  36. a.newReceiptType
  37. </sql>
  38. <sql id="cmDiscernReceiptJoins">
  39. </sql>
  40. <select id="get" resultType="CmDiscernReceipt">
  41. SELECT
  42. <include refid="cmDiscernReceiptColumns"/>
  43. FROM cm_discern_receipt a
  44. <include refid="cmDiscernReceiptJoins"/>
  45. WHERE a.id = #{id}
  46. </select>
  47. <select id="getAssociateAmount" resultType="double">
  48. select IFNULL(sum(cdr.receiptAmount),0) From cm_receipt_order_relation cror
  49. LEFT JOIN cm_discern_receipt cdr on cdr.id = cror.receiptID
  50. where cror.orderID = #{orderID} and cror.relationType = '2' and cdr.delFlag = 0
  51. and cror.delFlag = 0 and cdr.receiptStatus in (3) and payWay != '3';
  52. </select>
  53. <select id="getReturnBalanceAmount" resultType="double">
  54. select IFNULL(sum(amount),0) from cm_user_balance_record where balanceType = 2 and receiptId = #{receiptId} and delFlag = 0;
  55. </select>
  56. <select id="discern" resultType="String">
  57. SELECT
  58. u.userID,
  59. csp.id AS receiptID,
  60. cms.orderID,
  61. cms.shopOrderID,
  62. cms.shopOrderNo,
  63. cms.orderType as orderType,
  64. s.name AS shopName,
  65. cms.productAmount,
  66. cmo.orderNo,
  67. u.userName,
  68. u.name AS jgName,
  69. cmo.confirmTime,
  70. cms.receiptAmount,
  71. cms.needPayAmount
  72. FROM cm_shop_order cms
  73. LEFT JOIN shop s ON s.shopID = cms.shopID
  74. LEFT JOIN cm_order cmo ON cmo.orderID = cms.orderID
  75. LEFT JOIN `user` u ON u.userID = cms.userID
  76. LEFT JOIN cm_discern_receipt csp ON csp.shopOrderID = cms.shopOrderID
  77. </select>
  78. <select id="orderlist" resultType="CmDiscernReceipt">
  79. SELECT
  80. u.userID,
  81. csp.id AS receiptID,
  82. cms.orderID,
  83. cms.shopOrderID,
  84. cms.shopOrderNo,
  85. cms.orderType as orderType,
  86. s.name AS shopName,
  87. cms.productAmount,
  88. cmo.orderNo,
  89. u.userName,
  90. u.name AS jgName,
  91. cmo.confirmTime,
  92. cms.receiptAmount,
  93. cms.needPayAmount
  94. FROM cm_shop_order cms
  95. LEFT JOIN shop s ON s.shopID = cms.shopID
  96. LEFT JOIN cm_order cmo ON cmo.orderID = cms.orderID
  97. LEFT JOIN `user` u ON u.userID = cms.userID
  98. LEFT JOIN cm_discern_receipt csp ON csp.shopOrderID = cms.shopOrderID
  99. where csp.id=#{id}
  100. </select>
  101. <select id="findList" resultType="CmDiscernReceipt">
  102. -- relationType值为1是为子订单ID,为2时为主订单ID)
  103. SELECT
  104. <include refid="cmDiscernReceiptColumns"/>,
  105. cso_s.orderID AS orderID,
  106. cso_s.shopOrderNo as shopOrderNos,
  107. cso.shopOrderId as shopOrderId,
  108. cof.bankAccount AS bankNameType,
  109. s.checkMan,
  110. IF(crr.relationType = '1', s.name,IFNULL(s_a.name,'')) AS shopName,
  111. (case when crr.relationType = '1' then u_cr.userName else u.userName
  112. end) AS "userName",
  113. (case when crr.relationType = '1' then u_cr.name else u.name
  114. end) AS "name",
  115. IF(crr.relationType = '6',(SELECT NAME FROM USER mu WHERE mu.userId=ccb.userId),'') AS "backname",
  116. cr.organizeID AS organizeID
  117. FROM cm_discern_receipt a
  118. left join cm_receipt_order_relation crr on crr.receiptID = a.id and crr.delFlag = '0'
  119. LEFT JOIN cm_coupon_buyrecord ccb ON crr.couponRecordId=ccb.id
  120. -- 主订单
  121. left join cm_order cr on cr.orderID = crr.orderID
  122. left join user u on u.userID = cr.userID
  123. -- 子订单
  124. left join cm_shop_order cso on cso.shopOrderID = crr.orderID
  125. left join cm_order cso_cr on cso.orderID = cso_cr.orderID
  126. LEFT JOIN USER u_cr ON u_cr.userID = cso_cr.userID
  127. -- 供应商
  128. LEFT JOIN shop s ON s.shopID = cso.shopID
  129. LEFT JOIN cm_shop_order cso_s ON cso_s.shopOrderID = a.shopOrderID
  130. LEFT JOIN cm_shop_order cso_a ON cso_a.shopOrderID = crr.shopOrderID
  131. LEFT JOIN shop s_a ON s_a.shopID = cso_a.shopID
  132. LEFT JOIN cm_offline_collection cof ON a.payType = cof.type
  133. <where>
  134. <if test="id != null and id != '' and id != 0 ">
  135. AND a.id = #{id}
  136. </if>
  137. <if test="organizeID != null and organizeID != 9999 ">
  138. AND cr.organizeID = #{organizeID}
  139. </if>
  140. <if test="organizeID == 9999 ">
  141. AND cr.orderType = 2
  142. </if>
  143. <if test="startTime != null and startTime != ''">
  144. AND (a.receiptDate &gt; #{startTime} OR a.receiptDate = #{startTime})
  145. </if>
  146. <if test="endTime != null and endTime != ''">
  147. AND (a.receiptDate &lt; #{endTime} OR a.receiptDate = #{endTime})
  148. </if>
  149. <if test="payWay != null and payWay != ''">
  150. AND a.payWay = #{payWay}
  151. </if>
  152. <if test="payType != null and payType != ''">
  153. AND a.payType = #{payType}
  154. </if>
  155. <if test="receiptType != null and receiptType != ''">
  156. <if test="receiptType==2 and newReceiptType==3">
  157. and (a.receiptType = 9)
  158. or a.receiptType = #{receiptType}
  159. </if>
  160. <if test="receiptType!=2">
  161. AND a.receiptType = #{receiptType}
  162. </if>
  163. AND a.receiptType = #{receiptType}
  164. </if>
  165. <if test="newReceiptType !=null">
  166. <if test="newReceiptType==3">
  167. and a.newReceiptType =3
  168. </if>
  169. <if test="newReceiptType != 3">
  170. and a.newReceiptType=#{newReceiptType}
  171. </if>
  172. </if>
  173. <if test="receiptStatus != null and receiptStatus != ''">
  174. AND a.receiptStatus = #{receiptStatus}
  175. </if>
  176. <if test="orderNo != null and orderNo != ''">
  177. AND ((cr.orderNo like concat('%',#{orderNo},'%')) OR (cso.shopOrderNo like concat('%',#{orderNo},'%')))
  178. </if>
  179. <if test="orderID != null and orderID != ''">
  180. AND (cr.orderID = #{orderID} OR (crr.relationType = '1' AND cso_cr.orderID = #{orderID}))
  181. </if>
  182. <if test="userName != null and userName != ''">
  183. AND (u.userName LIKE concat('%',#{userName},'%') or u.name LIKE concat('%',#{userName},'%'))
  184. </if>
  185. <if test="receiptProgress != null and receiptProgress != ''">
  186. and (case when crr.relationType = '1' then
  187. cso_cr.receiptStatus
  188. else
  189. cr.receiptStatus
  190. end) = #{receiptProgress}
  191. </if>
  192. <if test="receiptOrderType != null and receiptOrderType != ''">
  193. and (case when crr.relationType = '1' then
  194. cso.orderType
  195. else
  196. cr.orderType
  197. end) = #{receiptOrderType}
  198. </if>
  199. <if test="associationNum != null and associationNum != ''">
  200. <if test="associationNum == 1">
  201. and (select count(1) from cm_receipt_order_relation where receiptID = a.id and delFlag = '0') = 1
  202. </if>
  203. <if test="associationNum == 2">
  204. and (select count(1) from cm_receipt_order_relation where receiptID = a.id and delFlag = '0')
  205. <![CDATA[ > ]]> 1
  206. </if>
  207. </if>
  208. <if test="paYee !=null and paYee != ''">
  209. <if test="paYee == '采美'">
  210. and a.payWay = 3
  211. OR a.payWay = 2
  212. AND a.newReceiptType != 3 AND a.payWay = 2
  213. </if>
  214. <if test="payWay==1">
  215. and s.name=#{paYee}
  216. </if>
  217. </if>
  218. and a.delFlag = '0' group by a.id
  219. </where>
  220. <choose>
  221. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  222. ORDER BY ${page.orderBy}
  223. </when>
  224. <otherwise>
  225. order by a.receiptDate desc
  226. </otherwise>
  227. </choose>
  228. </select>
  229. <select id="findAllList" resultType="CmDiscernReceipt">
  230. SELECT
  231. <include refid="cmDiscernReceiptColumns"/>
  232. FROM cm_discern_receipt a
  233. <include refid="cmDiscernReceiptJoins"/>
  234. <where>
  235. </where>
  236. <choose>
  237. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  238. ORDER BY ${page.orderBy}
  239. </when>
  240. <otherwise>
  241. </otherwise>
  242. </choose>
  243. </select>
  244. <select id="exportTest" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  245. SELECT
  246. r.orderID,
  247. (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,
  248. IF(u.userIdentity = 2,u.name,u.userName) AS userName,
  249. d.receiptDate,
  250. d.payType,
  251. IFNULL(r.associateAmount,0) as associateAmount,
  252. cof.bankAccount AS bankNameType,
  253. d.receiptType
  254. FROM
  255. cm_receipt_order_relation r
  256. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  257. LEFT JOIN cm_order o ON r.orderID = o.orderID
  258. LEFT JOIN USER u ON u.userID = o.userID
  259. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  260. <where>
  261. <if test="startTime != null and startTime != ''">
  262. AND (d.receiptDate <![CDATA[ >= ]]> #{startTime})
  263. </if>
  264. <if test="endTime != null and endTime != ''">
  265. AND (d.receiptDate <![CDATA[ <= ]]> #{endTime})
  266. </if>
  267. <if test="receiptProgress != null and receiptProgress != ''">
  268. AND o.receiptStatus = #{receiptProgress}
  269. </if>
  270. AND d.receiptType = 1
  271. AND d.receiptStatus = 3
  272. AND d.delFlag = '0'
  273. AND r.delFlag = '0'
  274. </where>
  275. ORDER BY
  276. d.receiptDate DESC;
  277. </select>
  278. <select id="exportRebate" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  279. SELECT
  280. so.orderID,
  281. (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,
  282. IF(u.userIdentity = 2,u.name,u.userName) AS userName,
  283. d.receiptDate,
  284. d.payType,
  285. IFNULL(d.receiptAmount,0) as associateAmount,
  286. cof.bankAccount AS bankNameType,
  287. d.receiptType
  288. FROM
  289. cm_receipt_order_relation r
  290. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  291. LEFT JOIN cm_shop_order so ON r.orderID = so.shopOrderID
  292. LEFT JOIN USER u ON u.userID = so.userID
  293. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  294. <where>
  295. <if test="startTime != null and startTime != ''">
  296. AND (d.receiptDate <![CDATA[ >= ]]> #{startTime})
  297. </if>
  298. <if test="endTime != null and endTime != ''">
  299. AND (d.receiptDate <![CDATA[ <= ]]> #{endTime})
  300. </if>
  301. <if test="receiptProgress != null and receiptProgress != ''">
  302. AND o.receiptStatus = #{receiptProgress}
  303. </if>
  304. AND d.receiptStatus = 2
  305. AND d.delFlag = '0'
  306. AND r.delFlag = '0'
  307. AND r.relationType='1'
  308. </where>
  309. ORDER BY
  310. d.receiptDate DESC;
  311. </select>
  312. <!--订单已付款又进行交易全退,此处需要结合订单状态导出,单纯的进账会不明确-->
  313. <select id="exportReceiptPay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  314. SELECT
  315. DISTINCT r.orderID
  316. FROM
  317. cm_receipt_order_relation r
  318. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  319. LEFT JOIN cm_order o ON r.orderID = o.orderID
  320. LEFT JOIN USER u ON u.userID = o.userID
  321. <where>
  322. <if test="startTime != null and startTime != ''">
  323. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  324. </if>
  325. <if test="endTime != null and endTime != ''">
  326. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  327. </if>
  328. <if test="receiptProgress != null and receiptProgress != ''">
  329. AND o.receiptStatus = #{receiptProgress}
  330. </if>
  331. AND d.receiptStatus = 3
  332. AND d.delFlag = '0'
  333. AND r.delFlag = '0'
  334. </where>
  335. ORDER BY
  336. d.receiptDate DESC;
  337. </select>
  338. <select id="exportOnlyBalancePay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  339. SELECT
  340. DISTINCT o.orderID
  341. FROM
  342. cm_order o
  343. <where>
  344. <if test="startTime != null and startTime != ''">
  345. AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
  346. </if>
  347. <if test="endTime != null and endTime != ''">
  348. AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
  349. </if>
  350. <if test="receiptProgress != null and receiptProgress != ''">
  351. AND o.receiptStatus = #{receiptProgress}
  352. </if>
  353. AND o.balancePayFee > 0
  354. AND o.delFlag = '0'
  355. </where>
  356. HAVING (SELECT count(a.id) as num from cm_receipt_order_relation a left JOIN cm_discern_receipt d on a.receiptID
  357. = d.id where a.orderID=o.orderID and d.receiptStatus = 3 and d.delFlag = '0') = 0
  358. ORDER BY
  359. o.orderTime DESC;
  360. </select>
  361. <select id="exportPay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  362. SELECT
  363. ps.id AS orderID,
  364. u.`name` AS userName,
  365. r.payTime AS receiptDate,
  366. ps.payType AS payType,
  367. ps.totalAmount AS associateAmount,
  368. GROUP_CONCAT(CONCAT(ss.shopOrderID , '/' ,ss.payedShopAmount , '/' , ss.`userName` )) AS shopOrderID
  369. FROM
  370. cm_pay_shop ps
  371. LEFT JOIN cm_pay_shop_record r ON ps.id = r.payShopID
  372. LEFT JOIN (select so.shopOrderID,so.payedShopAmount,o.userName from cm_shop_order so LEFT JOIN user o on
  373. o.userID = so.userID) as ss on ss.shopOrderID = r.shopOrderID
  374. LEFT JOIN shop u ON r.shopID = u.shopID
  375. <where>
  376. <if test="startTime != null and startTime != ''">
  377. AND (r.payTime <![CDATA[ > ]]> #{startTime} OR r.payTime = #{startTime})
  378. </if>
  379. <if test="endTime != null and endTime != ''">
  380. AND (r.payTime <![CDATA[ < ]]> #{endTime} OR r.payTime = #{endTime})
  381. </if>
  382. AND r. STATUS = 1
  383. AND ps. STATUS = 1
  384. </where>
  385. GROUP BY
  386. ps.id
  387. ORDER BY
  388. r.payTime DESC;
  389. </select>
  390. <select id="exportPayData" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  391. SELECT DISTINCT
  392. o.orderID
  393. FROM
  394. cm_order o
  395. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  396. LEFT JOIN cm_pay_shop_record psr ON psr.shopOrderID = so.shopOrderID
  397. <where>
  398. <if test="startTime != null and startTime != ''">
  399. AND (psr.payTime <![CDATA[ > ]]> #{startTime} OR psr.payTime = #{startTime})
  400. </if>
  401. <if test="endTime != null and endTime != ''">
  402. AND (psr.payTime <![CDATA[ < ]]> #{endTime} OR psr.payTime = #{endTime})
  403. </if>
  404. <if test="receiptProgress != null and receiptProgress != ''">
  405. AND o.payStatus = #{receiptProgress}
  406. </if>
  407. AND psr. STATUS = 1
  408. </where>
  409. ORDER BY
  410. psr.payTime DESC
  411. </select>
  412. <select id="exportOrderDate" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  413. SELECT DISTINCT
  414. o.orderID,o.status
  415. FROM
  416. cm_order o
  417. <where>
  418. <if test="startTime != null and startTime != ''">
  419. AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
  420. </if>
  421. <if test="endTime != null and endTime != ''">
  422. AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
  423. </if>
  424. AND o.delFlag='0'
  425. AND o.status!='6'
  426. AND o.orderID NOT IN (
  427. SELECT so.orderID
  428. FROM cm_shop_order so
  429. LEFT JOIN cm_receipt_order_relation ror ON ror.orderID = so.shopOrderID
  430. LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
  431. WHERE ror.relationType = '1'
  432. AND dr.receiptStatus = '2'
  433. AND so.delFlag = '0'
  434. GROUP BY so.orderID
  435. )
  436. </where>
  437. </select>
  438. <select id="getListOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  439. SELECT o.orderID, o.status, SUM(dr.receiptAmount) AS receiptAmount, ror.relationType
  440. FROM cm_order o
  441. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  442. LEFT JOIN cm_receipt_order_relation ror ON so.shopOrderID = ror.`orderID`
  443. LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
  444. <where>
  445. <if test="startTime != null and startTime != ''">
  446. AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
  447. </if>
  448. <if test="endTime != null and endTime != ''">
  449. AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
  450. </if>
  451. AND ror.`relationType` = '1'
  452. AND dr.receiptStatus = '2'
  453. AND o.delFlag='0'
  454. </where>
  455. GROUP BY o.orderID
  456. </select>
  457. <select id="exportPayment" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  458. SELECT so.orderID, ror.relationType, SUM(dr.receiptAmount) AS receiptAmount
  459. FROM cm_shop_order so
  460. LEFT JOIN cm_receipt_order_relation ror ON ror.orderID = so.shopOrderID
  461. LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
  462. <where>
  463. <if test="startTime != null and startTime != ''">
  464. AND (dr.receiptDate <![CDATA[ > ]]> #{startTime} OR dr.receiptDate = #{startTime})
  465. </if>
  466. <if test="endTime != null and endTime != ''">
  467. AND (dr.receiptDate <![CDATA[ < ]]> #{endTime} OR dr.receiptDate = #{endTime})
  468. </if>
  469. AND ror.relationType = '1'
  470. AND dr.receiptStatus = '2'
  471. AND so.delFlag = '0'
  472. </where>
  473. GROUP BY so.orderID
  474. </select>
  475. <insert id="insert" parameterType="CmDiscernReceipt" keyProperty="id" useGeneratedKeys="true">
  476. INSERT INTO cm_discern_receipt(
  477. payWay,
  478. payType,
  479. receiptType,
  480. receiptStatus,
  481. smsContent,
  482. smsMd5Code,
  483. receiptAmount,
  484. handlingFee,
  485. confirmType,
  486. confirmUserPermissionID,
  487. reviewUserPermissionID,
  488. cancelUserPermissionID,
  489. transactionNum,
  490. bankID,
  491. bankCode,
  492. kuaiQianPayTypeID,
  493. kuaiQianPayerID,
  494. rePayFlag,
  495. actualAmount,
  496. formData,
  497. problem,
  498. noOrderReason,
  499. reviewReason,
  500. cancelReason,
  501. receiptDate,
  502. confirmDate,
  503. reviewDate,
  504. cancelDate,
  505. updateDate,
  506. delFlag
  507. ) VALUES (
  508. #{payWay},
  509. #{payType},
  510. #{receiptType},
  511. #{receiptStatus},
  512. #{smsContent},
  513. #{smsMd5Code},
  514. #{receiptAmount},
  515. #{handlingFee},
  516. #{confirmType},
  517. #{confirmUserPermissionID},
  518. #{reviewUserPermissionID},
  519. #{cancelUserPermissionID},
  520. #{transactionNum},
  521. #{bankID},
  522. #{bankCode},
  523. #{kuaiQianPayTypeID},
  524. #{kuaiQianPayerID},
  525. #{rePayFlag},
  526. #{actualAmount},
  527. #{formData},
  528. #{problem},
  529. #{noOrderReason},
  530. #{reviewReason},
  531. #{cancelReason},
  532. #{receiptDate},
  533. #{confirmDate},
  534. #{reviewDate},
  535. #{cancelDate},
  536. #{cancelDate},
  537. #{delFlag}
  538. )
  539. </insert>
  540. <update id="update">
  541. UPDATE cm_discern_receipt SET
  542. payWay = #{payWay},
  543. payType = #{payType},
  544. receiptType = #{receiptType},
  545. receiptStatus = #{receiptStatus},
  546. smsContent = #{smsContent},
  547. smsMd5Code = #{smsMd5Code},
  548. receiptAmount = #{receiptAmount},
  549. handlingFee = #{handlingFee},
  550. confirmType = #{confirmType},
  551. confirmUserPermissionID = #{confirmUserPermissionID},
  552. reviewUserPermissionID = #{reviewUserPermissionID},
  553. cancelUserPermissionID = #{cancelUserPermissionID},
  554. transactionNum = #{transactionNum},
  555. bankID = #{bankID},
  556. bankCode = #{bankCode},
  557. kuaiQianPayTypeID = #{kuaiQianPayTypeID},
  558. kuaiQianPayerID = #{kuaiQianPayerID},
  559. rePayFlag = #{rePayFlag},
  560. actualAmount = #{actualAmount},
  561. formData = #{formData},
  562. problem = #{problem},
  563. noOrderReason = #{noOrderReason},
  564. reviewReason = #{reviewReason},
  565. cancelReason = #{cancelReason},
  566. receiptDate = #{receiptDate},
  567. confirmDate = #{confirmDate},
  568. reviewDate = #{reviewDate},
  569. cancelDate = #{cancelDate},
  570. updateDate = DATE_FORMAT(#{updateDate},'%Y-%m-%d %H:%i:%s'),
  571. balanceAccountsRemark = #{balanceAccountsRemark},
  572. delFlag = #{delFlag}
  573. WHERE id = #{id}
  574. </update>
  575. <delete id="delete">
  576. DELETE FROM cm_discern_receipt
  577. WHERE id = #{id}
  578. </delete>
  579. <select id="getOrderIDStr" parameterType="string" resultType="map">
  580. -- relationType值为1是为子订单ID,为2时为主订单ID)
  581. select
  582. (case when cror.relationType = '1'
  583. then concat('子订单',cso.shopOrderNo,'(', cso.shopOrderID,')')
  584. else concat(cou.orderNo,'(', cou.orderID,')')
  585. end) AS orderNo,
  586. (CASE WHEN cror.relationType = '1'
  587. THEN co.orderID
  588. ELSE cou.orderID
  589. END) AS orderID ,
  590. (case when cror.relationType = '1'
  591. then (select b.orderType from cm_shop_order b where cso.shopOrderID = b.shopOrderID)
  592. else (select c.orderType from cm_order c where cou.orderID = c.orderID)
  593. end) AS orderType
  594. from cm_receipt_order_relation cror
  595. left join cm_shop_order cso on cror.orderID = cso.shopOrderID
  596. left join cm_order co on cso.orderID = co.orderID
  597. LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
  598. where cror.receiptID = #{id} and cror.delFlag = '0'
  599. </select>
  600. <select id="getInfos" parameterType="CmDiscernReceipt" resultType="com.caimei.modules.order.entity.ReceiptDetailVo">
  601. select
  602. cdr.id AS receiptID,
  603. cdr.receiptType AS receiptType,
  604. cdr.confirmType AS confirmType,
  605. cdr.payType AS payType,
  606. cof.bankAccount AS bankNameType,
  607. cdr.receiptAmount AS receiptAmount,
  608. cdr.receiptDate AS receiptDate,
  609. cdr.receiptStatus AS receiptStatus,
  610. cdr.noOrderReason AS noOrderReason,
  611. cdr.confirmDate AS confirmTime,
  612. cdr.smsContent AS smsContent,
  613. cdr.cancelReason AS cancelReason,
  614. cdr.payWay AS payWay,
  615. rup.name AS confirmer,
  616. cdr.rebateRemarks AS rebateRemarks,
  617. cdr.shopName as shopName
  618. from
  619. cm_discern_receipt cdr
  620. left join cm_receipt_user rup on cdr.confirmUserPermissionID = rup.id
  621. LEFT JOIN cm_offline_collection cof ON cdr.payType = cof.type
  622. where cdr.id = #{receiptID}
  623. </select>
  624. <select id="getOrderInfoByShopOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
  625. select
  626. cso.orderNo AS orderNo,
  627. cso.orderID AS orderID,
  628. co.payTotalFee AS orderAmount,
  629. co.payableAmount AS payableAmount,
  630. co.onlinePayFlag,
  631. (select
  632. sum(o.needPayAmount)
  633. from cm_receipt_order_relation cror
  634. left join cm_shop_order o on cror.orderID = o.shopOrderID
  635. left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  636. where o.orderID = cso.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
  637. and cdr.receiptStatus = '2'
  638. ) AS receiptAmount,
  639. bou.name AS customerName,
  640. co.receiptStatus AS receiptStatus,
  641. co.orderType AS orderType,
  642. co.orderTime AS orderTime,
  643. co.userID AS userID,
  644. cso.shopOrderNo AS shopOrderNo,
  645. cso.shopOrderID AS shopOrderID,
  646. cso.needPayAmount AS shopOrderAmount,
  647. cso.shouldPayShopAmount AS shouldPayShopAmount,
  648. cso.payedShopAmount AS payedShopAmount,
  649. s.name AS shopName
  650. from cm_shop_order cso
  651. left join cm_order co on cso.orderID = co.orderID
  652. left join shop s on cso.shopID = s.shopID
  653. left join bp_order_userinfo bou on bou.orderId = cso.orderID
  654. where cso.shopOrderID = #{shopOrderID}
  655. </select>
  656. <select id="getOrderInfoByOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
  657. select
  658. co.orderNo AS orderNo,
  659. co.orderID AS orderID,
  660. co.payTotalFee AS orderAmount,
  661. co.payableAmount AS payableAmount,
  662. co.onlinePayFlag,
  663. (select
  664. sum(cror.associateAmount)
  665. from cm_receipt_order_relation cror
  666. left join cm_order o on o.orderID = cror.orderID
  667. left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  668. where o.orderID = co.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
  669. and cdr.receiptStatus = '3'
  670. ) AS receiptAmount,
  671. bou.name AS customerName,
  672. co.receiptStatus AS receiptStatus,
  673. co.orderType AS orderType,
  674. co.orderTime AS orderTime,
  675. co.organizeID AS organizeID,
  676. co.userID AS userID
  677. from cm_order co
  678. left join bp_order_userinfo bou on bou.orderId = co.orderID
  679. where co.orderID = #{orderID}
  680. </select>
  681. <select id="findReceiptRecordByOrderID" resultType="com.caimei.modules.order.entity.ReceiptRecordVo">
  682. select
  683. cror.receiptID AS receiptID,
  684. cdr.receiptDate AS receiptTime,
  685. cdr.receiptStatus AS receiptStatus,
  686. cdr.confirmType AS confirmType,
  687. cdr.receiptType AS receiptType,
  688. cdr.payType AS payType,
  689. cof.bankAccount AS bankNameType,
  690. cdr.receiptAmount AS receiptAmount,
  691. cror.associationType AS associationType,
  692. cdr.payWay AS payWay,
  693. cdr.transactionNum AS transactionNum,
  694. cror.mbOrderId AS mbOrderId,
  695. cdr.confirmUserPermissionID AS confirmUserPermissionID,
  696. (select rup.name from cm_receipt_user rup where rup.id = cdr.confirmUserPermissionID) AS
  697. confirmUserName,
  698. cdr.confirmDate AS confirmDate,
  699. cdr.reviewUserPermissionID AS reviewUserPermissionID,
  700. (select rup.name from cm_receipt_user rup where rup.id = cdr.reviewUserPermissionID) AS reviewUserName,
  701. cdr.reviewDate AS reviewDate,
  702. cdr.cancelUserPermissionID AS cancelUserPermissionID,
  703. (select su.name from sys_user su where su.id = cdr.cancelUserPermissionID) AS cancelUserName,
  704. cdr.cancelDate AS cancelDate,
  705. cdr.cancelReason AS cancelReason
  706. from cm_receipt_order_relation cror
  707. join cm_discern_receipt cdr on cdr.id = cror.receiptID
  708. join cm_offline_collection cof on cdr.payType = cof.type
  709. where cror.delFlag = '0' and cdr.delFlag = '0'
  710. <if test="relationType == 1">
  711. and cror.orderID in (select shopOrderID from cm_shop_order where orderID = #{orderID}) and cror.relationType
  712. = '1'
  713. </if>
  714. <if test="relationType == 2">
  715. and cror.orderID = #{orderID} and cror.relationType = '2'
  716. </if>
  717. </select>
  718. <select id="findOrderIDs" resultType="string">
  719. select orderID from cm_receipt_order_relation cror
  720. where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '2'
  721. </select>
  722. <select id="hasReceiptRecordOrder" resultType="string">
  723. select cror.receiptID
  724. from cm_receipt_order_relation cror
  725. join cm_discern_receipt cdr on cror.receiptID = cdr.id
  726. where cror.orderID = #{orderID} and cror.receiptID != #{receiptID}
  727. and cror.relationType = '2' and cror.delFlag = '0'
  728. and cdr.receiptStatus = '3' and cdr.delFlag = '0'
  729. </select>
  730. <select id="findShopOrderIDs" resultType="string">
  731. select cror.orderID from cm_receipt_order_relation cror
  732. where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '1'
  733. </select>
  734. <select id="hasReceiptRecordShopOrder" resultType="string">
  735. select cror.receiptID
  736. from cm_receipt_order_relation cror
  737. join cm_discern_receipt cdr on cror.receiptID = cdr.id
  738. where cror.orderID in
  739. (select cso2.shopOrderID
  740. from cm_shop_order cso1
  741. left join cm_shop_order cso2 on cso2.orderID = cso1.orderID
  742. where cso1.shopOrderID = #{shopOrderID} and cso2.shopOrderID != #{shopOrderID})
  743. and cror.orderID != #{shopOrderID}
  744. and cdr.receiptStatus = '2' and cdr.delFlag = '0'
  745. and cror.relationType = '1' and cror.delFlag = '0'
  746. </select>
  747. <select id="getExportInfo" resultType="com.caimei.modules.order.entity.ReceiptExportVo">
  748. -- 1订单款,2非订单款,3返佣款
  749. select
  750. (case when co.orderType = '0' then '协销' else '自主' end) AS type,
  751. (case when co.freePostFlag = '1'
  752. then co.freight else 0 end) as freight,
  753. (select sum(cop.totalAddedValueTax) from cm_order_product cop where cop.orderID = co.orderID) AS tax,
  754. <if test="t == 1">
  755. -- 1订单款
  756. co.payTotalFee AS amount,
  757. cror.associateAmount AS associateAmount,
  758. co.orderNo AS no,
  759. </if>
  760. <if test="t == 3">
  761. -- 3返佣款
  762. concat(cso.needPayAmount, '(子)') AS amount,
  763. concat(cso.needPayAmount, '(子)') AS associateAmount,
  764. concat(cso.shopOrderNo, '(子)') AS no,
  765. </if>
  766. co.orderID AS id
  767. from cm_receipt_order_relation cror
  768. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  769. <if test="t == 1">
  770. left join cm_order co on cror.orderID = co.orderID
  771. </if>
  772. <if test="t == 3">
  773. left join cm_shop_order cso on cror.orderID = cso.shopOrderID
  774. left join cm_order co on cso.orderID = co.orderID
  775. </if>
  776. where cror.receiptID = #{id} and cror.delFlag = '0'
  777. and cdr.delFlag = '0'
  778. <if test="t == 1">
  779. and cror.relationType = '2'
  780. </if>
  781. <if test="t == 3">
  782. and cror.relationType = '1'
  783. </if>
  784. </select>
  785. <select id="getReceiptRecords" resultType="integer">
  786. select cror.receiptID from cm_receipt_order_relation cror
  787. where cror.delFlag = '0' and (
  788. (cror.orderID = #{shopOrderID} and cror.relationType = '1')
  789. or
  790. (cror.orderID in (select orderID from cm_shop_order where shopOrderID = #{shopOrderID}) and cror.relationType = '2')
  791. )
  792. </select>
  793. <select id="findRebateOrderID" resultType="integer">
  794. select cso.orderID AS orderID
  795. from cm_receipt_order_relation cror left join cm_shop_order cso
  796. on cror.orderID = cso.shopOrderID
  797. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  798. where cror.relationType = '1' and cror.delFlag = '0' AND cdr.receiptStatus = '2'
  799. and cdr.receiptType = '3' and cso.orderID in
  800. <foreach collection="orderIds" item="id" open="(" close=")" separator=",">
  801. #{id}
  802. </foreach>
  803. </select>
  804. <select id="findShopOrder" resultType="com.caimei.modules.order.entity.CmReceiptExport">
  805. SELECT
  806. o.orderID,
  807. o.payStatus,
  808. so.shopID,
  809. so.shopOrderID,
  810. o.orderTime,
  811. u.userName,
  812. p. NAME AS supplierName,
  813. (
  814. so.productAmount - IFNULL(so.discountAmount, 0)
  815. ) AS productFee,
  816. IFNULL(so.totalAddedValueTax,0) AS taxFee,
  817. IFNULL(so.totalAmount,0) AS receiptAmount,
  818. IFNULL(so.shopTaxFee,0) AS payTaxFee,
  819. IFNULL(so.shopPostFee,0) AS payFreight,
  820. IFNULL(so.shopOtherFee,0) AS payOther,
  821. IFNULL(so.shouldPayShopAmount,0) AS payAmount,
  822. IFNULL(so.productAmount,0) AS productAmount
  823. FROM
  824. cm_order o
  825. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  826. LEFT JOIN user u ON u.userID = o.userID
  827. LEFT JOIN shop p ON p.shopID = so.shopID
  828. WHERE
  829. o.orderID = #{orderID}
  830. AND so.delFlag = 0
  831. AND o.delFlag = 0;
  832. </select>
  833. <select id="findSmoothoutInfo" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  834. select * from cm_discern_receipt cdr
  835. LEFT JOIN cm_receipt_order_relation cror on cror.receiptID = cdr.id
  836. where cdr.receiptType = 1 and cror.relationType = 2 and cror.delFlag = 0
  837. and cdr.delFlag = 0 and cdr.confirmType in (1,2,3) and cdr.receiptStatus = '3'
  838. and cror.orderID = #{orderID} LIMIT 1;
  839. </select>
  840. <select id="findOrderReceipt" resultType="double">
  841. select sum(associateAmount) from cm_receipt_order_relation cror
  842. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  843. where cror.orderID = #{orderID} and cror.delFlag = '0' and cror.relationType = '2'
  844. and cdr.delFlag = '0' and cdr.receiptStatus = '3' and cdr.payWay != '3'
  845. </select>
  846. <select id="gathering" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  847. SELECT
  848. d.receiptDate,d.payType
  849. FROM
  850. cm_receipt_order_relation r
  851. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  852. WHERE r.orderID=#{orderID}
  853. AND d.receiptStatus = 3
  854. AND d.delFlag = '0'
  855. AND r.delFlag = '0'
  856. </select>
  857. <select id="exportRefund" resultType="com.caimei.modules.order.entity.CmReturnedPurchase">
  858. SELECT bou.name as userName, cof.bankAccount AS bankNameType, crp.*
  859. FROM `cm_returned_purchase` crp
  860. LEFT JOIN bp_order_userinfo bou ON bou.orderId = crp.orderId
  861. LEFT JOIN cm_offline_collection cof ON crp.payType = cof.type
  862. <where>
  863. <if test="startTime != null and startTime != ''">
  864. AND (crp.confirmReturnTime <![CDATA[ > ]]> #{startTime} OR crp.confirmReturnTime = #{startTime})
  865. </if>
  866. <if test="endTime != null and endTime != ''">
  867. AND (crp.confirmReturnTime <![CDATA[ < ]]> #{endTime} OR crp.confirmReturnTime = #{endTime})
  868. </if>
  869. AND crp.status= 2
  870. </where>
  871. ORDER BY crp.confirmReturnTime DESC
  872. </select>
  873. <select id="theOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  874. SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
  875. FROM cm_discern_receipt d
  876. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  877. <where>
  878. <if test="startTime != null and startTime != ''">
  879. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  880. </if>
  881. <if test="endTime != null and endTime != ''">
  882. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  883. </if>
  884. AND d.receiptStatus = 2
  885. AND d.receiptType = 2
  886. AND d.delFlag = '0'
  887. </where>
  888. ORDER BY d.receiptDate DESC;
  889. </select>
  890. <select id="findDiscernReceipt" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  891. SELECT
  892. cdr.*
  893. FROM
  894. cm_discern_receipt cdr
  895. LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
  896. WHERE
  897. cdr.receiptType = 1
  898. AND cror.relationType = 2
  899. AND cdr.receiptStatus = 3
  900. AND cror.delFlag = 0
  901. AND cdr.delFlag = 0
  902. AND cror.orderID = #{orderID}
  903. ORDER BY
  904. id DESC
  905. LIMIT
  906. 1
  907. </select>
  908. <select id="findPayType" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  909. SELECT
  910. cdr.*
  911. FROM
  912. cm_discern_receipt cdr
  913. LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
  914. WHERE
  915. cdr.receiptType = 1
  916. AND cror.relationType = 2
  917. AND cdr.receiptStatus = 3
  918. AND cror.delFlag = 0
  919. AND cdr.delFlag = 0
  920. AND cror.orderID = #{orderID}
  921. ORDER BY
  922. payWay ASC
  923. LIMIT
  924. 1
  925. </select>
  926. <select id="findOrderLastReceiptDetailId" resultType="java.lang.Integer">
  927. select cdr.id
  928. from cm_discern_receipt cdr
  929. left join cm_receipt_order_relation cror on cdr.id = cror.receiptID
  930. where cdr.delFlag = '0'
  931. and cror.delFlag = '0'
  932. and cror.orderID = #{orderID}
  933. order by cdr.id desc
  934. limit 1
  935. </select>
  936. <select id="findSplitTime" resultType="date">
  937. SELECT
  938. splitTime
  939. FROM
  940. cm_split_account
  941. WHERE
  942. payStatus = 1
  943. AND orderId = #{orderID}
  944. ORDER BY
  945. splitTime DESC
  946. LIMIT
  947. 1
  948. </select>
  949. <select id="getVipRecordId" resultType="java.lang.Integer">
  950. select vipRecordId from cm_receipt_order_relation where receiptID=#{receiptId}
  951. </select>
  952. <select id="getVipUserId" resultType="java.lang.Integer">
  953. select userId from cm_svip_history where id=#{vipRecordId}
  954. </select>
  955. <select id="getUserNameByUserId" resultType="java.lang.String">
  956. select userName from user where userID = #{userId} LIMIT 1
  957. </select>
  958. <select id="getReceiptVipInfo" resultType="com.caimei.modules.order.entity.ReceiptVipInfoVo">
  959. select svipr.id,
  960. svipr.userId,
  961. svipr.packageId,
  962. svipr.beginTime,
  963. svipr.endTime,
  964. svipr.price,
  965. svipr.payTime,
  966. cror.orderRequestNo,
  967. cror.vipRecordId,
  968. svipp.duration,
  969. c.name as clubName
  970. from cm_svip_history svipr
  971. left join cm_receipt_order_relation cror on svipr.id = cror.vipRecordId
  972. left join club c on svipr.userId = c.userId
  973. left join cm_svip_package svipp on svipp.id = svipr.packageId
  974. where cror.receiptID=#{receiptID}
  975. LIMIT 1
  976. </select>
  977. <select id="svipReceipt" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  978. SELECT d.receiptDate, u.userName, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
  979. FROM cm_discern_receipt d
  980. left join cm_receipt_order_relation cror on d.id = cror.receiptID
  981. left join cm_svip_history csh on cror.vipRecordId = csh.id
  982. left join user u on csh.userId = u.userID
  983. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  984. <where>
  985. <if test="startTime != null and startTime != ''">
  986. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  987. </if>
  988. <if test="endTime != null and endTime != ''">
  989. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  990. </if>
  991. AND d.receiptStatus = 3
  992. AND d.receiptType = 6
  993. AND d.delFlag = '0'
  994. </where>
  995. ORDER BY d.receiptDate DESC;
  996. </select>
  997. <select id="secondReceipt" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  998. SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
  999. FROM cm_discern_receipt d
  1000. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  1001. <where>
  1002. <if test="startTime != null and startTime != ''">
  1003. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  1004. </if>
  1005. <if test="endTime != null and endTime != ''">
  1006. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  1007. </if>
  1008. AND d.receiptStatus = 3
  1009. AND d.receiptType = 7
  1010. AND d.delFlag = '0'
  1011. </where>
  1012. ORDER BY d.receiptDate DESC;
  1013. </select>
  1014. <select id="getCouponInfo" resultType="com.caimei.modules.order.entity.ReceipCouponInfoVo">
  1015. SELECT c.name as clubName,cc.touchPrice,cc.couponAmount,cror.mborderId,cc.couponType,cdr.confirmDate
  1016. FROM cm_receipt_order_relation cror
  1017. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID=cdr.id
  1018. LEFT JOIN cm_order co ON cror.orderId=co.orderID
  1019. LEFT JOIN club c ON co.userID=c.userID
  1020. LEFT JOIN cm_coupon_buyrecord ccb ON ccb.id=cror.couponRecordId
  1021. LEFT JOIN cm_coupon cc ON ccb.couponId=cc.id
  1022. WHERE receiptID = #{receiptID}
  1023. </select>
  1024. <select id="getShopOrderInfos" resultType="com.caimei.modules.order.entity.NewShopOrder">
  1025. 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
  1026. <where>
  1027. <if test="shopOrderId != null and shopOrderId != ''">
  1028. and cso.shopOrderID = #{shopOrderId}
  1029. </if>
  1030. <if test="orderId != null and orderId != ''">
  1031. and co.orderId = #{orderId}
  1032. </if>
  1033. </where>
  1034. </select>
  1035. </mapper>