CmDiscernReceiptMapper.xml 53 KB

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