CmDiscernReceiptMapper.xml 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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},'%'))
  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.relationType != '1' and cror.receiptID = #{id} AND cror.delFlag = '0'
  801. union
  802. SELECT
  803. cso.shopOrderId,
  804. cso.shopOrderNo,
  805. cso.orderId AS orderID,
  806. (CASE WHEN cror.relationType = '1'
  807. THEN (SELECT b.orderType FROM cm_shop_order b WHERE cso.shopOrderID = b.shopOrderID)
  808. ELSE (SELECT c.orderType FROM cm_order c WHERE cso.orderID = c.orderID)
  809. END) AS orderType
  810. FROM cm_receipt_order_relation cror
  811. LEFT JOIN cm_shop_order cso ON cror.orderID = cso.shopOrderID
  812. LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
  813. WHERE cror.relationType = '1' AND cror.receiptID = #{id} AND cror.delFlag = '0'
  814. </select>
  815. <select id="getOrderIDStr" parameterType="string" resultType="map">
  816. -- relationType值为1是为子订单ID,为2时为主订单ID)
  817. select
  818. cso.shopOrderId,
  819. cso.shopOrderNo,
  820. (case when cror.relationType = '1'
  821. then concat('子订单',cso.shopOrderNo,'(', cso.shopOrderID,')')
  822. else concat(cou.orderNo,'(', cou.orderID,')')
  823. end) AS orderNo,
  824. (CASE WHEN cror.relationType = '1'
  825. THEN co.orderID
  826. ELSE cou.orderID
  827. END) AS orderID ,
  828. (case when cror.relationType = '1'
  829. then (select b.orderType from cm_shop_order b where cso.shopOrderID = b.shopOrderID)
  830. else (select c.orderType from cm_order c where cou.orderID = c.orderID)
  831. end) AS orderType
  832. from cm_receipt_order_relation cror
  833. left join cm_shop_order cso on cror.orderID = cso.shopOrderID
  834. left join cm_order co on cso.orderID = co.orderID
  835. LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
  836. where cror.receiptID = #{id} and cror.delFlag = '0'
  837. </select>
  838. <select id="getInfos" parameterType="CmDiscernReceipt" resultType="com.caimei.modules.order.entity.ReceiptDetailVo">
  839. select
  840. cdr.id AS receiptID,
  841. cdr.receiptType AS receiptType,
  842. cdr.confirmType AS confirmType,
  843. cdr.payType AS payType,
  844. cof.bankAccount AS bankNameType,
  845. cdr.receiptAmount AS receiptAmount,
  846. cdr.receiptDate AS receiptDate,
  847. cdr.receiptStatus AS receiptStatus,
  848. cdr.noOrderReason AS noOrderReason,
  849. cdr.confirmDate AS confirmTime,
  850. cdr.smsContent AS smsContent,
  851. cdr.cancelReason AS cancelReason,
  852. cdr.payWay AS payWay,
  853. rup.name AS confirmer,
  854. cdr.rebateRemarks AS rebateRemarks,
  855. cdr.shopName as shopName
  856. from
  857. cm_discern_receipt cdr
  858. left join cm_receipt_user rup on cdr.confirmUserPermissionID = rup.id
  859. LEFT JOIN cm_offline_collection cof ON cdr.payType = cof.type
  860. where cdr.id = #{receiptID}
  861. </select>
  862. <select id="getOrderInfoByShopOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
  863. select
  864. cso.orderNo AS orderNo,
  865. cso.orderID AS orderID,
  866. co.payTotalFee AS orderAmount,
  867. ifnull(co.payableAmount, 0) AS payableAmount,
  868. co.onlinePayFlag,
  869. ifnull(cso.receiptAmount, 0) AS receiptAmount,
  870. ifnull(cso.accountAmount, 0) AS accountAmount,
  871. -- (select
  872. -- sum(o.needPayAmount)
  873. -- from cm_receipt_order_relation cror
  874. -- left join cm_shop_order o on cror.orderID = o.shopOrderID
  875. -- left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  876. -- where o.orderID = cso.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
  877. -- and cdr.receiptStatus = '2'
  878. -- ) AS receiptAmount,
  879. bou.name AS customerName,
  880. cso.orderStatusFlag AS orderStatusFlag,
  881. cso.receiptStatus AS receiptStatus,
  882. co.orderType AS orderType,
  883. co.orderTime AS orderTime,
  884. co.userID AS userID,
  885. cso.shopOrderNo AS shopOrderNo,
  886. cso.shopOrderID AS shopOrderID,
  887. ifnull(cso.needPayAmount, 0) AS shopOrderAmount,
  888. ifnull(cso.shouldPayShopAmount, 0) AS shouldPayShopAmount,
  889. ifnull(cso.payedShopAmount, 0) AS payedShopAmount,
  890. s.name AS shopName
  891. from cm_shop_order cso
  892. left join cm_order co on cso.orderID = co.orderID
  893. left join shop s on cso.shopID = s.shopID
  894. left join bp_order_userinfo bou on bou.orderId = cso.orderID
  895. where cso.shopOrderID = #{shopOrderID}
  896. </select>
  897. <select id="getOrderInfoByOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
  898. select
  899. co.orderNo AS orderNo,
  900. co.orderID AS orderID,
  901. co.payTotalFee AS orderAmount,
  902. co.payableAmount AS payableAmount,
  903. co.onlinePayFlag,
  904. (select
  905. sum(cror.associateAmount)
  906. from cm_receipt_order_relation cror
  907. left join cm_order o on o.orderID = cror.orderID
  908. left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  909. where o.orderID = co.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
  910. and cdr.receiptStatus = '3'
  911. ) AS receiptAmount,
  912. bou.name AS customerName,
  913. co.receiptStatus AS receiptStatus,
  914. co.orderType AS orderType,
  915. co.orderTime AS orderTime,
  916. co.organizeID AS organizeID,
  917. co.userID AS userID
  918. from cm_order co
  919. left join bp_order_userinfo bou on bou.orderId = co.orderID
  920. where co.orderID = #{orderID}
  921. </select>
  922. <select id="findReceiptRecordByOrderID" resultType="com.caimei.modules.order.entity.ReceiptRecordVo">
  923. select
  924. cror.receiptID AS receiptID,
  925. cdr.receiptDate AS receiptTime,
  926. cdr.receiptStatus AS receiptStatus,
  927. cdr.confirmType AS confirmType,
  928. cdr.receiptType AS receiptType,
  929. cdr.payType AS payType,
  930. IFNULL(cof.bankAccount,'未知')AS bankNameType,
  931. cdr.receiptAmount AS receiptAmount,
  932. cror.associationType AS associationType,
  933. cdr.payWay AS payWay,
  934. cdr.transactionNum AS transactionNum,
  935. cror.mbOrderId AS mbOrderId,
  936. cdr.confirmUserPermissionID AS confirmUserPermissionID,
  937. (select rup.name from cm_receipt_user rup where rup.id = cdr.confirmUserPermissionID) AS
  938. confirmUserName,
  939. cdr.confirmDate AS confirmDate,
  940. cdr.reviewUserPermissionID AS reviewUserPermissionID,
  941. (select rup.name from cm_receipt_user rup where rup.id = cdr.reviewUserPermissionID) AS reviewUserName,
  942. cdr.reviewDate AS reviewDate,
  943. cdr.cancelUserPermissionID AS cancelUserPermissionID,
  944. (select su.name from sys_user su where su.id = cdr.cancelUserPermissionID) AS cancelUserName,
  945. cdr.cancelDate AS cancelDate,
  946. cdr.cancelReason AS cancelReason
  947. from cm_receipt_order_relation cror
  948. left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  949. left join cm_offline_collection cof on cdr.payType = cof.type
  950. where cror.delFlag = '0' and cdr.delFlag = '0'
  951. <if test="identifying == 2">
  952. <if test="relationType == 1">
  953. and cror.orderID in (select shopOrderID from cm_shop_order where orderID = #{orderID}) and (cror.relationType = '1' or cror.relationType = '7')
  954. </if>
  955. <if test="relationType == 2">
  956. and cror.orderID = #{orderID} and (cror.relationType = '2' or cror.relationType = '7')
  957. </if>
  958. <if test="relationType == 7">
  959. and cror.shopOrderId = #{shopOrderID} and (cror.relationType = '2' or cror.relationType = '7')
  960. </if>
  961. </if>
  962. <if test="identifying == 1">
  963. and cror.shopOrderId = #{shopOrderID} and (cror.relationType = 2 or cror.relationType = 7)
  964. </if>
  965. </select>
  966. <select id="findOrderIDs" resultType="string">
  967. select orderID from cm_receipt_order_relation cror
  968. where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '2'
  969. </select>
  970. <select id="hasReceiptRecordOrder" resultType="string">
  971. select cror.receiptID
  972. from cm_receipt_order_relation cror
  973. join cm_discern_receipt cdr on cror.receiptID = cdr.id
  974. where cror.orderID = #{orderID} and cror.receiptID != #{receiptID}
  975. and cror.relationType = '2' and cror.delFlag = '0'
  976. and cdr.receiptStatus = '3' and cdr.delFlag = '0'
  977. </select>
  978. <select id="findShopOrderIDs" resultType="string">
  979. select cror.orderID from cm_receipt_order_relation cror
  980. where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '1'
  981. </select>
  982. <select id="hasReceiptRecordShopOrder" resultType="string">
  983. select cror.receiptID
  984. from cm_receipt_order_relation cror
  985. join cm_discern_receipt cdr on cror.receiptID = cdr.id
  986. where cror.orderID in
  987. (select cso2.shopOrderID
  988. from cm_shop_order cso1
  989. left join cm_shop_order cso2 on cso2.orderID = cso1.orderID
  990. where cso1.shopOrderID = #{shopOrderID} and cso2.shopOrderID != #{shopOrderID})
  991. and cror.orderID != #{shopOrderID}
  992. and cdr.receiptStatus = '2' and cdr.delFlag = '0'
  993. and cror.relationType = '1' and cror.delFlag = '0'
  994. </select>
  995. <select id="getExportInfo" resultType="com.caimei.modules.order.entity.ReceiptExportVo">
  996. -- 1订单款,2非订单款,3返佣款
  997. select
  998. (case when co.orderType = '0' then '协销' else '自主' end) AS type,
  999. (case when co.freePostFlag = '1'
  1000. then co.freight else 0 end) as freight,
  1001. (select sum(cop.totalAddedValueTax) from cm_order_product cop where cop.orderID = co.orderID) AS tax,
  1002. <if test="t == 1">
  1003. -- 1订单款
  1004. co.payTotalFee AS amount,
  1005. cror.associateAmount AS associateAmount,
  1006. co.orderNo AS no,
  1007. </if>
  1008. <if test="t == 3">
  1009. -- 3返佣款
  1010. concat(cso.needPayAmount, '(子)') AS amount,
  1011. concat(cso.needPayAmount, '(子)') AS associateAmount,
  1012. concat(cso.shopOrderNo, '(子)') AS no,
  1013. </if>
  1014. co.orderID AS id
  1015. from cm_receipt_order_relation cror
  1016. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  1017. <if test="t == 1">
  1018. left join cm_order co on cror.orderID = co.orderID
  1019. </if>
  1020. <if test="t == 3">
  1021. left join cm_shop_order cso on cror.orderID = cso.shopOrderID
  1022. left join cm_order co on cso.orderID = co.orderID
  1023. </if>
  1024. where cror.receiptID = #{id} and cror.delFlag = '0'
  1025. and cdr.delFlag = '0'
  1026. <if test="t == 1">
  1027. and cror.relationType = '2'
  1028. </if>
  1029. <if test="t == 3">
  1030. and cror.relationType = '1'
  1031. </if>
  1032. </select>
  1033. <select id="getReceiptRecords" resultType="integer">
  1034. select cror.receiptID from cm_receipt_order_relation cror
  1035. where cror.delFlag = '0' and (
  1036. (cror.orderID = #{shopOrderID} and cror.relationType = '1')
  1037. or
  1038. (cror.orderID in (select orderID from cm_shop_order where shopOrderID = #{shopOrderID}) and cror.relationType = '2')
  1039. )
  1040. </select>
  1041. <select id="findRebateOrderID" resultType="integer">
  1042. select cso.orderID AS orderID
  1043. from cm_receipt_order_relation cror left join cm_shop_order cso
  1044. on cror.orderID = cso.shopOrderID
  1045. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  1046. where cror.relationType = '1' and cror.delFlag = '0' AND cdr.receiptStatus = '2'
  1047. and cdr.receiptType = '3' and cso.orderID in
  1048. <foreach collection="orderIds" item="id" open="(" close=")" separator=",">
  1049. #{id}
  1050. </foreach>
  1051. </select>
  1052. <select id="findShopOrder" resultType="com.caimei.modules.order.entity.CmReceiptExport">
  1053. SELECT
  1054. o.orderID,
  1055. o.payStatus,
  1056. so.shopID,
  1057. so.shopOrderID,
  1058. o.orderTime,
  1059. u.userName,
  1060. p. NAME AS supplierName,
  1061. (
  1062. so.productAmount - IFNULL(so.discountAmount, 0)
  1063. ) AS productFee,
  1064. IFNULL(so.totalAddedValueTax,0) AS taxFee,
  1065. IFNULL(so.totalAmount,0) AS receiptAmount,
  1066. IFNULL(so.shopTaxFee,0) AS payTaxFee,
  1067. IFNULL(so.shopPostFee,0) AS payFreight,
  1068. IFNULL(so.shopOtherFee,0) AS payOther,
  1069. IFNULL(so.shouldPayShopAmount,0) AS payAmount,
  1070. IFNULL(so.productAmount,0) AS productAmount
  1071. FROM
  1072. cm_order o
  1073. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  1074. LEFT JOIN user u ON u.userID = o.userID
  1075. LEFT JOIN shop p ON p.shopID = so.shopID
  1076. WHERE
  1077. o.orderID = #{orderID}
  1078. AND so.delFlag = 0
  1079. AND o.delFlag = 0;
  1080. </select>
  1081. <select id="findSmoothoutInfo" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  1082. select * from cm_discern_receipt cdr
  1083. LEFT JOIN cm_receipt_order_relation cror on cror.receiptID = cdr.id
  1084. where cdr.receiptType = 1 and cror.relationType = 2 and cror.delFlag = 0
  1085. and cdr.delFlag = 0 and cdr.confirmType in (1,2,3) and cdr.receiptStatus = '3'
  1086. and cror.orderID = #{orderID} LIMIT 1;
  1087. </select>
  1088. <select id="findSmoothoutshopInfo" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  1089. select * from cm_discern_receipt cdr
  1090. LEFT JOIN cm_receipt_order_relation cror on cror.receiptID = cdr.id
  1091. where cdr.receiptType = 1 and cror.relationType = 2 and cror.delFlag = 0
  1092. and cdr.delFlag = 0 and cdr.confirmType in (1,2,3) and cdr.receiptStatus = '3'
  1093. and cror.shopOrderId = #{shopOrderId} LIMIT 1;
  1094. </select>
  1095. <select id="getPaidAmountByOrderId" resultType="com.caimei.modules.order.entity.CmReceiptOrderRelation">
  1096. SELECT receiptID, associateAmount FROM cm_receipt_order_relation WHERE shopOrderId = #{shopOrderId}
  1097. </select>
  1098. <select id="findOrderReceipt" resultType="double">
  1099. select sum(associateAmount) from cm_receipt_order_relation cror
  1100. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  1101. where cror.orderID = #{orderID} and cror.delFlag = '0' and cror.relationType = '2'
  1102. and cdr.delFlag = '0' and cdr.receiptStatus = '3' and cdr.payWay != '3'
  1103. </select>
  1104. <select id="findShoOrderIDReceipt" resultType="double">
  1105. select ifnull(sum(cror.associateAmount), 0) as associateAmount from cm_receipt_order_relation cror
  1106. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  1107. where cror.shopOrderID = #{shopOrderID} and cror.delFlag = '0' and cror.relationType = '2'
  1108. and cdr.delFlag = '0' and cdr.receiptStatus = '3' and cdr.payWay = '2'
  1109. </select>
  1110. <select id="findShopReceipt" resultType="java.lang.Double">
  1111. SELECT ifnull(SUM(associateAmount), 0) as associateAmount FROM (
  1112. SELECT
  1113. SUM(cror.associateAmount) AS associateAmount
  1114. FROM cm_receipt_order_relation cror
  1115. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  1116. WHERE cror.relationType = 2 AND cror.orderId = #{orderID}
  1117. AND cror.delFlag = '0' AND cror.relationType = '2' AND cdr.delFlag = '0'
  1118. UNION
  1119. SELECT
  1120. SUM(cror.associateAmount) AS associateAmount
  1121. FROM cm_receipt_order_relation cror
  1122. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  1123. WHERE cror.relationType = 1 AND cror.orderId = #{shopOrderID}
  1124. AND cror.delFlag = '0' AND cror.relationType = '2' AND cdr.delFlag = '0'
  1125. ) AS d
  1126. </select>
  1127. <select id="gathering" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  1128. SELECT
  1129. d.receiptDate,d.payType
  1130. FROM
  1131. cm_receipt_order_relation r
  1132. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  1133. WHERE r.orderID=#{orderID}
  1134. AND d.receiptStatus = 3
  1135. AND d.delFlag = '0'
  1136. AND r.delFlag = '0'
  1137. </select>
  1138. <select id="exportRefund" resultType="com.caimei.modules.order.entity.CmReturnedPurchase">
  1139. SELECT bou.name as userName, cof.bankAccount AS bankNameType, crp.*
  1140. FROM `cm_returned_purchase` crp
  1141. LEFT JOIN bp_order_userinfo bou ON bou.orderId = crp.orderId
  1142. LEFT JOIN cm_offline_collection cof ON crp.payType = cof.type
  1143. <where>
  1144. <if test="startTime != null and startTime != ''">
  1145. AND (crp.confirmReturnTime <![CDATA[ > ]]> #{startTime} OR crp.confirmReturnTime = #{startTime})
  1146. </if>
  1147. <if test="endTime != null and endTime != ''">
  1148. AND (crp.confirmReturnTime <![CDATA[ < ]]> #{endTime} OR crp.confirmReturnTime = #{endTime})
  1149. </if>
  1150. AND crp.status= 2
  1151. </where>
  1152. ORDER BY crp.confirmReturnTime DESC
  1153. </select>
  1154. <select id="theOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  1155. SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
  1156. FROM cm_discern_receipt d
  1157. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  1158. <where>
  1159. <if test="startTime != null and startTime != ''">
  1160. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  1161. </if>
  1162. <if test="endTime != null and endTime != ''">
  1163. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  1164. </if>
  1165. AND d.receiptStatus = 2
  1166. AND d.receiptType = 2
  1167. AND d.delFlag = '0'
  1168. </where>
  1169. ORDER BY d.receiptDate DESC;
  1170. </select>
  1171. <select id="findDiscernReceipt" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  1172. SELECT
  1173. cdr.*
  1174. FROM
  1175. cm_discern_receipt cdr
  1176. LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
  1177. WHERE
  1178. cdr.receiptType = 1
  1179. AND cror.relationType = 2
  1180. AND cdr.receiptStatus = 3
  1181. AND cror.delFlag = 0
  1182. AND cdr.delFlag = 0
  1183. AND cror.orderID = #{orderID}
  1184. ORDER BY
  1185. id DESC
  1186. LIMIT
  1187. 1
  1188. </select>
  1189. <select id="findPayType" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  1190. SELECT
  1191. cdr.*
  1192. FROM
  1193. cm_discern_receipt cdr
  1194. LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
  1195. WHERE
  1196. cdr.receiptType = 1
  1197. AND cror.relationType = 2
  1198. AND cdr.receiptStatus = 3
  1199. AND cror.delFlag = 0
  1200. AND cdr.delFlag = 0
  1201. AND cror.orderID = #{orderID}
  1202. ORDER BY
  1203. payWay ASC
  1204. LIMIT
  1205. 1
  1206. </select>
  1207. <select id="findOrderLastReceiptDetailId" resultType="java.lang.Integer">
  1208. select cdr.id
  1209. from cm_discern_receipt cdr
  1210. left join cm_receipt_order_relation cror on cdr.id = cror.receiptID
  1211. where cdr.delFlag = '0'
  1212. and cror.delFlag = '0'
  1213. and cror.orderID = #{orderID}
  1214. order by cdr.id desc
  1215. limit 1
  1216. </select>
  1217. <select id="findSplitTime" resultType="date">
  1218. SELECT
  1219. splitTime
  1220. FROM
  1221. cm_split_account
  1222. WHERE
  1223. payStatus = 1
  1224. AND orderId = #{orderID}
  1225. ORDER BY
  1226. splitTime DESC
  1227. LIMIT
  1228. 1
  1229. </select>
  1230. <select id="getVipRecordId" resultType="java.lang.Integer">
  1231. select vipRecordId from cm_receipt_order_relation where receiptID=#{receiptId}
  1232. </select>
  1233. <select id="getVipUserId" resultType="java.lang.Integer">
  1234. select userId from cm_svip_history where id=#{vipRecordId}
  1235. </select>
  1236. <select id="getUserNameByUserId" resultType="java.lang.String">
  1237. select userName from user where userID = #{userId} LIMIT 1
  1238. </select>
  1239. <select id="getReceiptVipInfo" resultType="com.caimei.modules.order.entity.ReceiptVipInfoVo">
  1240. select svipr.id,
  1241. svipr.userId,
  1242. svipr.packageId,
  1243. svipr.beginTime,
  1244. svipr.endTime,
  1245. svipr.price,
  1246. svipr.payTime,
  1247. cror.orderRequestNo,
  1248. cror.vipRecordId,
  1249. svipp.duration,
  1250. c.name as clubName
  1251. from cm_svip_history svipr
  1252. left join cm_receipt_order_relation cror on svipr.id = cror.vipRecordId
  1253. left join club c on svipr.userId = c.userId
  1254. left join cm_svip_package svipp on svipp.id = svipr.packageId
  1255. where cror.receiptID=#{receiptID}
  1256. LIMIT 1
  1257. </select>
  1258. <select id="svipReceipt" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  1259. SELECT d.receiptDate, u.userName, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
  1260. FROM cm_discern_receipt d
  1261. left join cm_receipt_order_relation cror on d.id = cror.receiptID
  1262. left join cm_svip_history csh on cror.vipRecordId = csh.id
  1263. left join user u on csh.userId = u.userID
  1264. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  1265. <where>
  1266. <if test="startTime != null and startTime != ''">
  1267. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  1268. </if>
  1269. <if test="endTime != null and endTime != ''">
  1270. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  1271. </if>
  1272. AND d.receiptStatus = 3
  1273. AND d.receiptType = 6
  1274. AND d.delFlag = '0'
  1275. </where>
  1276. ORDER BY d.receiptDate DESC;
  1277. </select>
  1278. <select id="secondReceipt" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  1279. SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount, cof.bankAccount AS bankNameType, d.receiptType
  1280. FROM cm_discern_receipt d
  1281. LEFT JOIN cm_offline_collection cof ON d.payType = cof.type
  1282. <where>
  1283. <if test="startTime != null and startTime != ''">
  1284. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  1285. </if>
  1286. <if test="endTime != null and endTime != ''">
  1287. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  1288. </if>
  1289. AND d.receiptStatus = 3
  1290. AND d.receiptType = 7
  1291. AND d.delFlag = '0'
  1292. </where>
  1293. ORDER BY d.receiptDate DESC;
  1294. </select>
  1295. <select id="getCouponInfo" resultType="com.caimei.modules.order.entity.ReceipCouponInfoVo">
  1296. SELECT c.name as clubName,cc.touchPrice,cc.couponAmount,cror.mborderId,cc.couponType,cdr.confirmDate
  1297. FROM cm_receipt_order_relation cror
  1298. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID=cdr.id
  1299. LEFT JOIN cm_order co ON cror.orderId=co.orderID
  1300. LEFT JOIN club c ON co.userID=c.userID
  1301. LEFT JOIN cm_coupon_buyrecord ccb ON ccb.id=cror.couponRecordId
  1302. LEFT JOIN cm_coupon cc ON ccb.couponId=cc.id
  1303. WHERE receiptID = #{receiptID}
  1304. </select>
  1305. <select id="getShopOrderInfos" resultType="com.caimei.modules.order.entity.NewShopOrder">
  1306. 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
  1307. <where>
  1308. <if test="shopOrderId != null and shopOrderId != ''">
  1309. and cso.shopOrderID = #{shopOrderId}
  1310. </if>
  1311. <if test="orderId != null and orderId != ''">
  1312. and co.orderId = #{orderId}
  1313. </if>
  1314. </where>
  1315. </select>
  1316. </mapper>