CmDiscernReceiptMapper.xml 53 KB

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