CmDiscernReceiptMapper.xml 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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. </sql>
  37. <sql id="cmDiscernReceiptJoins">
  38. </sql>
  39. <select id="get" resultType="CmDiscernReceipt">
  40. SELECT
  41. <include refid="cmDiscernReceiptColumns"/>
  42. FROM cm_discern_receipt a
  43. <include refid="cmDiscernReceiptJoins"/>
  44. WHERE a.id = #{id}
  45. </select>
  46. <select id="getAssociateAmount" resultType="double">
  47. select IFNULL(sum(cdr.receiptAmount),0) From cm_receipt_order_relation cror
  48. LEFT JOIN cm_discern_receipt cdr on cdr.id = cror.receiptID
  49. where cror.orderID = #{orderID} and cror.relationType = '2' and cdr.delFlag = 0
  50. and cror.delFlag = 0 and cdr.receiptStatus in (3) and payWay != '3';
  51. </select>
  52. <select id="getReturnBalanceAmount" resultType="double">
  53. select IFNULL(sum(amount),0) from cm_user_balance_record where balanceType = 2 and receiptId = #{receiptId} and delFlag = 0;
  54. </select>
  55. <select id="findList" resultType="CmDiscernReceipt">
  56. SELECT
  57. <include refid="cmDiscernReceiptColumns"/>
  58. ,IF(a.receiptType='3',u_cr.userName,u.userName) AS "userName",IF(a.receiptType='3',u_cr.name,u.name) AS "name",
  59. cr.organizeID AS organizeID
  60. FROM cm_discern_receipt a
  61. left join cm_receipt_order_relation crr on crr.receiptID = a.id and crr.delFlag = '0'
  62. left join cm_order cr on cr.orderID = crr.orderID
  63. left join cm_shop_order cso on cso.shopOrderID = crr.orderID
  64. left join cm_order cso_cr on cso.orderID = cso_cr.orderID
  65. left join user u on u.userID = cr.userID
  66. LEFT JOIN USER u_cr ON u_cr.userID = cso_cr.userID
  67. <where>
  68. <if test="id != null and id != '' and id != 0 ">
  69. AND a.id = #{id}
  70. </if>
  71. <if test="organizeID != null and organizeID != 9999 ">
  72. AND cr.organizeID = #{organizeID}
  73. </if>
  74. <if test="organizeID == 9999 ">
  75. AND cr.orderType = 2
  76. </if>
  77. <if test="startTime != null and startTime != ''">
  78. AND (a.receiptDate &gt; #{startTime} OR a.receiptDate = #{startTime})
  79. </if>
  80. <if test="endTime != null and endTime != ''">
  81. AND (a.receiptDate &lt; #{endTime} OR a.receiptDate = #{endTime})
  82. </if>
  83. <if test="payWay != null and payWay != ''">
  84. AND a.payWay = #{payWay}
  85. </if>
  86. <if test="payType != null and payType != ''">
  87. AND a.payType = #{payType}
  88. </if>
  89. <if test="receiptType != null and receiptType != ''">
  90. AND a.receiptType = #{receiptType}
  91. </if>
  92. <if test="receiptStatus != null and receiptStatus != ''">
  93. AND a.receiptStatus = #{receiptStatus}
  94. </if>
  95. <if test="orderNo != null and orderNo != ''">
  96. AND ((cr.orderNo like concat('%',#{orderNo},'%')) OR (cso.shopOrderNo like concat('%',#{orderNo},'%')))
  97. </if>
  98. <if test="orderID != null and orderID != ''">
  99. AND (cr.orderID = #{orderID} OR (crr.relationType = '1' AND cso_cr.orderID = #{orderID}))
  100. </if>
  101. <if test="userName != null and userName != ''">
  102. AND (u.userName LIKE concat('%',#{userName},'%') or u.name LIKE concat('%',#{userName},'%'))
  103. </if>
  104. <if test="receiptProgress != null and receiptProgress != ''">
  105. and (case when crr.relationType = '1' then
  106. cso_cr.receiptStatus
  107. else
  108. cr.receiptStatus
  109. end) = #{receiptProgress}
  110. </if>
  111. <if test="receiptOrderType != null and receiptOrderType != ''">
  112. and (case when crr.relationType = '1' then
  113. cso.orderType
  114. else
  115. cr.orderType
  116. end) = #{receiptOrderType}
  117. </if>
  118. <if test="associationNum != null and associationNum != ''">
  119. <if test="associationNum == 1">
  120. and (select count(1) from cm_receipt_order_relation where receiptID = a.id and delFlag = '0') = 1
  121. </if>
  122. <if test="associationNum == 2">
  123. and (select count(1) from cm_receipt_order_relation where receiptID = a.id and delFlag = '0')
  124. <![CDATA[ > ]]> 1
  125. </if>
  126. </if>
  127. and a.delFlag = '0' group by a.id
  128. </where>
  129. <choose>
  130. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  131. ORDER BY ${page.orderBy}
  132. </when>
  133. <otherwise>
  134. order by a.receiptDate desc
  135. </otherwise>
  136. </choose>
  137. </select>
  138. <select id="findAllList" resultType="CmDiscernReceipt">
  139. SELECT
  140. <include refid="cmDiscernReceiptColumns"/>
  141. FROM cm_discern_receipt a
  142. <include refid="cmDiscernReceiptJoins"/>
  143. <where>
  144. </where>
  145. <choose>
  146. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  147. ORDER BY ${page.orderBy}
  148. </when>
  149. <otherwise>
  150. </otherwise>
  151. </choose>
  152. </select>
  153. <select id="exportTest" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  154. SELECT
  155. r.orderID,
  156. (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,
  157. IF(u.userIdentity = 2,u.name,u.userName) AS userName,
  158. d.receiptDate,
  159. d.payType,
  160. IFNULL(r.associateAmount,0) as associateAmount,
  161. d.receiptType
  162. FROM
  163. cm_receipt_order_relation r
  164. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  165. LEFT JOIN cm_order o ON r.orderID = o.orderID
  166. LEFT JOIN USER u ON u.userID = o.userID
  167. <where>
  168. <if test="startTime != null and startTime != ''">
  169. AND (d.receiptDate <![CDATA[ >= ]]> #{startTime})
  170. </if>
  171. <if test="endTime != null and endTime != ''">
  172. AND (d.receiptDate <![CDATA[ <= ]]> #{endTime})
  173. </if>
  174. <if test="receiptProgress != null and receiptProgress != ''">
  175. AND o.receiptStatus = #{receiptProgress}
  176. </if>
  177. AND d.receiptStatus = 3
  178. AND d.delFlag = '0'
  179. AND r.delFlag = '0'
  180. </where>
  181. ORDER BY
  182. d.receiptDate DESC;
  183. </select>
  184. <select id="exportRebate" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  185. SELECT
  186. so.orderID,
  187. (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,
  188. IF(u.userIdentity = 2,u.name,u.userName) AS userName,
  189. d.receiptDate,
  190. d.payType,
  191. IFNULL(d.receiptAmount,0) as associateAmount,
  192. d.receiptType
  193. FROM
  194. cm_receipt_order_relation r
  195. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  196. LEFT JOIN cm_shop_order so ON r.orderID = so.shopOrderID
  197. LEFT JOIN USER u ON u.userID = so.userID
  198. <where>
  199. <if test="startTime != null and startTime != ''">
  200. AND (d.receiptDate <![CDATA[ >= ]]> #{startTime})
  201. </if>
  202. <if test="endTime != null and endTime != ''">
  203. AND (d.receiptDate <![CDATA[ <= ]]> #{endTime})
  204. </if>
  205. <if test="receiptProgress != null and receiptProgress != ''">
  206. AND o.receiptStatus = #{receiptProgress}
  207. </if>
  208. AND d.receiptStatus = 2
  209. AND d.delFlag = '0'
  210. AND r.delFlag = '0'
  211. AND r.relationType='1'
  212. </where>
  213. ORDER BY
  214. d.receiptDate DESC;
  215. </select>
  216. <!--订单已付款又进行交易全退,此处需要结合订单状态导出,单纯的进账会不明确-->
  217. <select id="exportReceiptPay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  218. SELECT
  219. DISTINCT r.orderID
  220. FROM
  221. cm_receipt_order_relation r
  222. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  223. LEFT JOIN cm_order o ON r.orderID = o.orderID
  224. LEFT JOIN USER u ON u.userID = o.userID
  225. <where>
  226. <if test="startTime != null and startTime != ''">
  227. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  228. </if>
  229. <if test="endTime != null and endTime != ''">
  230. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  231. </if>
  232. <if test="receiptProgress != null and receiptProgress != ''">
  233. AND o.receiptStatus = #{receiptProgress}
  234. </if>
  235. AND d.receiptStatus = 3
  236. AND d.delFlag = '0'
  237. AND r.delFlag = '0'
  238. </where>
  239. ORDER BY
  240. d.receiptDate DESC;
  241. </select>
  242. <select id="exportOnlyBalancePay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  243. SELECT
  244. DISTINCT o.orderID
  245. FROM
  246. cm_order o
  247. <where>
  248. <if test="startTime != null and startTime != ''">
  249. AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
  250. </if>
  251. <if test="endTime != null and endTime != ''">
  252. AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
  253. </if>
  254. <if test="receiptProgress != null and receiptProgress != ''">
  255. AND o.receiptStatus = #{receiptProgress}
  256. </if>
  257. AND o.balancePayFee > 0
  258. AND o.delFlag = '0'
  259. </where>
  260. HAVING (SELECT count(a.id) as num from cm_receipt_order_relation a left JOIN cm_discern_receipt d on a.receiptID
  261. = d.id where a.orderID=o.orderID and d.receiptStatus = 3 and d.delFlag = '0') = 0
  262. ORDER BY
  263. o.orderTime DESC;
  264. </select>
  265. <select id="exportPay" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  266. SELECT
  267. ps.id AS orderID,
  268. u.`name` AS userName,
  269. r.payTime AS receiptDate,
  270. ps.payType AS payType,
  271. ps.totalAmount AS associateAmount,
  272. GROUP_CONCAT(CONCAT(ss.shopOrderID , '/' ,ss.payedShopAmount , '/' , ss.`userName` )) AS shopOrderID
  273. FROM
  274. cm_pay_shop ps
  275. LEFT JOIN cm_pay_shop_record r ON ps.id = r.payShopID
  276. LEFT JOIN (select so.shopOrderID,so.payedShopAmount,o.userName from cm_shop_order so LEFT JOIN user o on
  277. o.userID = so.userID) as ss on ss.shopOrderID = r.shopOrderID
  278. LEFT JOIN shop u ON r.shopID = u.shopID
  279. <where>
  280. <if test="startTime != null and startTime != ''">
  281. AND (r.payTime <![CDATA[ > ]]> #{startTime} OR r.payTime = #{startTime})
  282. </if>
  283. <if test="endTime != null and endTime != ''">
  284. AND (r.payTime <![CDATA[ < ]]> #{endTime} OR r.payTime = #{endTime})
  285. </if>
  286. AND r. STATUS = 1
  287. AND ps. STATUS = 1
  288. </where>
  289. GROUP BY
  290. ps.id
  291. ORDER BY
  292. r.payTime DESC;
  293. </select>
  294. <select id="exportPayData" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  295. SELECT DISTINCT
  296. o.orderID
  297. FROM
  298. cm_order o
  299. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  300. LEFT JOIN cm_pay_shop_record psr ON psr.shopOrderID = so.shopOrderID
  301. <where>
  302. <if test="startTime != null and startTime != ''">
  303. AND (psr.payTime <![CDATA[ > ]]> #{startTime} OR psr.payTime = #{startTime})
  304. </if>
  305. <if test="endTime != null and endTime != ''">
  306. AND (psr.payTime <![CDATA[ < ]]> #{endTime} OR psr.payTime = #{endTime})
  307. </if>
  308. <if test="receiptProgress != null and receiptProgress != ''">
  309. AND o.payStatus = #{receiptProgress}
  310. </if>
  311. AND psr. STATUS = 1
  312. </where>
  313. ORDER BY
  314. psr.payTime DESC
  315. </select>
  316. <select id="exportOrderDate" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  317. SELECT DISTINCT
  318. o.orderID,o.status
  319. FROM
  320. cm_order o
  321. <where>
  322. <if test="startTime != null and startTime != ''">
  323. AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
  324. </if>
  325. <if test="endTime != null and endTime != ''">
  326. AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
  327. </if>
  328. AND o.delFlag='0'
  329. AND o.status!='6'
  330. AND o.orderID NOT IN (
  331. SELECT so.orderID
  332. FROM cm_shop_order so
  333. LEFT JOIN cm_receipt_order_relation ror ON ror.orderID = so.shopOrderID
  334. LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
  335. WHERE ror.relationType = '1'
  336. AND dr.receiptStatus = '2'
  337. AND so.delFlag = '0'
  338. GROUP BY so.orderID
  339. )
  340. </where>
  341. </select>
  342. <select id="getListOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  343. SELECT o.orderID, o.status, SUM(dr.receiptAmount) AS receiptAmount, ror.relationType
  344. FROM cm_order o
  345. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  346. LEFT JOIN cm_receipt_order_relation ror ON so.shopOrderID = ror.`orderID`
  347. LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
  348. <where>
  349. <if test="startTime != null and startTime != ''">
  350. AND (o.orderTime <![CDATA[ > ]]> #{startTime} OR o.orderTime = #{startTime})
  351. </if>
  352. <if test="endTime != null and endTime != ''">
  353. AND (o.orderTime <![CDATA[ < ]]> #{endTime} OR o.orderTime = #{endTime})
  354. </if>
  355. AND ror.`relationType` = '1'
  356. AND dr.receiptStatus = '2'
  357. AND o.delFlag='0'
  358. </where>
  359. GROUP BY o.orderID
  360. </select>
  361. <select id="exportPayment" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  362. SELECT so.orderID, ror.relationType, SUM(dr.receiptAmount) AS receiptAmount
  363. FROM cm_shop_order so
  364. LEFT JOIN cm_receipt_order_relation ror ON ror.orderID = so.shopOrderID
  365. LEFT JOIN cm_discern_receipt dr ON dr.id = ror.receiptID
  366. <where>
  367. <if test="startTime != null and startTime != ''">
  368. AND (dr.receiptDate <![CDATA[ > ]]> #{startTime} OR dr.receiptDate = #{startTime})
  369. </if>
  370. <if test="endTime != null and endTime != ''">
  371. AND (dr.receiptDate <![CDATA[ < ]]> #{endTime} OR dr.receiptDate = #{endTime})
  372. </if>
  373. AND ror.relationType = '1'
  374. AND dr.receiptStatus = '2'
  375. AND so.delFlag = '0'
  376. </where>
  377. GROUP BY so.orderID
  378. </select>
  379. <insert id="insert" parameterType="CmDiscernReceipt" keyProperty="id" useGeneratedKeys="true">
  380. INSERT INTO cm_discern_receipt(
  381. payWay,
  382. payType,
  383. receiptType,
  384. receiptStatus,
  385. smsContent,
  386. smsMd5Code,
  387. receiptAmount,
  388. handlingFee,
  389. confirmType,
  390. confirmUserPermissionID,
  391. reviewUserPermissionID,
  392. cancelUserPermissionID,
  393. transactionNum,
  394. bankID,
  395. bankCode,
  396. kuaiQianPayTypeID,
  397. kuaiQianPayerID,
  398. rePayFlag,
  399. actualAmount,
  400. formData,
  401. problem,
  402. noOrderReason,
  403. reviewReason,
  404. cancelReason,
  405. receiptDate,
  406. confirmDate,
  407. reviewDate,
  408. cancelDate,
  409. updateDate,
  410. delFlag
  411. ) VALUES (
  412. #{payWay},
  413. #{payType},
  414. #{receiptType},
  415. #{receiptStatus},
  416. #{smsContent},
  417. #{smsMd5Code},
  418. #{receiptAmount},
  419. #{handlingFee},
  420. #{confirmType},
  421. #{confirmUserPermissionID},
  422. #{reviewUserPermissionID},
  423. #{cancelUserPermissionID},
  424. #{transactionNum},
  425. #{bankID},
  426. #{bankCode},
  427. #{kuaiQianPayTypeID},
  428. #{kuaiQianPayerID},
  429. #{rePayFlag},
  430. #{actualAmount},
  431. #{formData},
  432. #{problem},
  433. #{noOrderReason},
  434. #{reviewReason},
  435. #{cancelReason},
  436. #{receiptDate},
  437. #{confirmDate},
  438. #{reviewDate},
  439. #{cancelDate},
  440. #{cancelDate},
  441. #{delFlag}
  442. )
  443. </insert>
  444. <update id="update">
  445. UPDATE cm_discern_receipt SET
  446. payWay = #{payWay},
  447. payType = #{payType},
  448. receiptType = #{receiptType},
  449. receiptStatus = #{receiptStatus},
  450. smsContent = #{smsContent},
  451. smsMd5Code = #{smsMd5Code},
  452. receiptAmount = #{receiptAmount},
  453. handlingFee = #{handlingFee},
  454. confirmType = #{confirmType},
  455. confirmUserPermissionID = #{confirmUserPermissionID},
  456. reviewUserPermissionID = #{reviewUserPermissionID},
  457. cancelUserPermissionID = #{cancelUserPermissionID},
  458. transactionNum = #{transactionNum},
  459. bankID = #{bankID},
  460. bankCode = #{bankCode},
  461. kuaiQianPayTypeID = #{kuaiQianPayTypeID},
  462. kuaiQianPayerID = #{kuaiQianPayerID},
  463. rePayFlag = #{rePayFlag},
  464. actualAmount = #{actualAmount},
  465. formData = #{formData},
  466. problem = #{problem},
  467. noOrderReason = #{noOrderReason},
  468. reviewReason = #{reviewReason},
  469. cancelReason = #{cancelReason},
  470. receiptDate = #{receiptDate},
  471. confirmDate = #{confirmDate},
  472. reviewDate = #{reviewDate},
  473. cancelDate = #{cancelDate},
  474. updateDate = DATE_FORMAT(#{updateDate},'%Y-%m-%d %H:%i:%s'),
  475. balanceAccountsRemark = #{balanceAccountsRemark},
  476. delFlag = #{delFlag}
  477. WHERE id = #{id}
  478. </update>
  479. <delete id="delete">
  480. DELETE FROM cm_discern_receipt
  481. WHERE id = #{id}
  482. </delete>
  483. <select id="getOrderIDStr" parameterType="string" resultType="map">
  484. -- relationType值为1是为子订单ID,为2时为主订单ID)
  485. select
  486. (case when cror.relationType = '1'
  487. then concat('子订单',cso.shopOrderNo,'(', cso.shopOrderID,')')
  488. else concat(cou.orderNo,'(', cou.orderID,')')
  489. end) AS orderNo,
  490. (CASE WHEN cror.relationType = '1'
  491. THEN co.orderID
  492. ELSE cou.orderID
  493. END) AS orderID ,
  494. (case when cror.relationType = '1'
  495. then (select b.orderType from cm_shop_order b where cso.shopOrderID = b.shopOrderID)
  496. else (select c.orderType from cm_order c where cou.orderID = c.orderID)
  497. end) AS orderType
  498. from cm_receipt_order_relation cror
  499. left join cm_shop_order cso on cror.orderID = cso.shopOrderID
  500. left join cm_order co on cso.orderID = co.orderID
  501. LEFT JOIN cm_order cou ON cror.orderID = cou.orderID
  502. where cror.receiptID = #{id} and cror.delFlag = '0'
  503. </select>
  504. <select id="getInfos" parameterType="CmDiscernReceipt" resultType="com.caimei.modules.order.entity.ReceiptDetailVo">
  505. select
  506. cdr.id AS receiptID,
  507. cdr.receiptType AS receiptType,
  508. cdr.confirmType AS confirmType,
  509. cdr.payType AS payType,
  510. cdr.receiptAmount AS receiptAmount,
  511. cdr.receiptDate AS receiptDate,
  512. cdr.receiptStatus AS receiptStatus,
  513. cdr.noOrderReason AS noOrderReason,
  514. cdr.confirmDate AS confirmTime,
  515. cdr.smsContent AS smsContent,
  516. cdr.cancelReason AS cancelReason,
  517. cdr.payWay AS payWay,
  518. rup.name AS confirmer,
  519. cdr.rebateRemarks AS rebateRemarks
  520. from
  521. cm_discern_receipt cdr
  522. left join receipt_user_permission rup on cdr.confirmUserPermissionID = rup.id
  523. where cdr.id = #{receiptID}
  524. </select>
  525. <select id="getOrderInfoByShopOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
  526. select
  527. cso.orderNo AS orderNo,
  528. cso.orderID AS orderID,
  529. co.payTotalFee AS orderAmount,
  530. co.payableAmount AS payableAmount,
  531. (select
  532. sum(o.needPayAmount)
  533. from cm_receipt_order_relation cror
  534. left join cm_shop_order o on cror.orderID = o.shopOrderID
  535. left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  536. where o.orderID = cso.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
  537. and cdr.receiptStatus = '2'
  538. ) AS receiptAmount,
  539. bou.name AS customerName,
  540. co.receiptStatus AS receiptStatus,
  541. co.orderType AS orderType,
  542. co.orderTime AS orderTime,
  543. co.userID AS userID,
  544. cso.shopOrderNo AS shopOrderNo,
  545. cso.shopOrderID AS shopOrderID,
  546. cso.needPayAmount AS shopOrderAmount,
  547. cso.shouldPayShopAmount AS shouldPayShopAmount,
  548. cso.payedShopAmount AS payedShopAmount,
  549. s.name AS shopName
  550. from cm_shop_order cso
  551. left join cm_order co on cso.orderID = co.orderID
  552. left join shop s on cso.shopID = s.shopID
  553. left join bp_order_userinfo bou on bou.orderId = cso.orderID
  554. where cso.shopOrderID = #{shopOrderID}
  555. </select>
  556. <select id="getOrderInfoByOrderID" resultType="com.caimei.modules.order.entity.ReceiptOrderInfoVo">
  557. select
  558. co.orderNo AS orderNo,
  559. co.orderID AS orderID,
  560. co.payTotalFee AS orderAmount,
  561. co.payableAmount AS payableAmount,
  562. (select
  563. sum(cror.associateAmount)
  564. from cm_receipt_order_relation cror
  565. left join cm_order o on o.orderID = cror.orderID
  566. left join cm_discern_receipt cdr on cdr.id = cror.receiptID
  567. where o.orderID = co.orderID and cror.delFlag = '0' and cdr.delFlag = '0'
  568. and cdr.receiptStatus = '3'
  569. ) AS receiptAmount,
  570. bou.name AS customerName,
  571. co.receiptStatus AS receiptStatus,
  572. co.orderType AS orderType,
  573. co.orderTime AS orderTime,
  574. co.organizeID AS organizeID,
  575. co.userID AS userID
  576. from cm_order co
  577. left join bp_order_userinfo bou on bou.orderId = co.orderID
  578. where co.orderID = #{orderID}
  579. </select>
  580. <select id="findReceiptRecordByOrderID" resultType="com.caimei.modules.order.entity.ReceiptRecordVo">
  581. select
  582. cror.receiptID AS receiptID,
  583. cdr.receiptDate AS receiptTime,
  584. cdr.receiptStatus AS receiptStatus,
  585. cdr.confirmType AS confirmType,
  586. cdr.receiptType AS receiptType,
  587. cdr.payType AS payType,
  588. cdr.receiptAmount AS receiptAmount,
  589. cror.associationType AS associationType,
  590. cdr.payWay AS payWay,
  591. cdr.transactionNum AS transactionNum,
  592. cror.mbOrderId AS mbOrderId,
  593. cdr.confirmUserPermissionID AS confirmUserPermissionID,
  594. (select rup.name from receipt_user_permission rup where rup.id = cdr.confirmUserPermissionID) AS
  595. confirmUserName,
  596. cdr.confirmDate AS confirmDate,
  597. cdr.reviewUserPermissionID AS reviewUserPermissionID,
  598. (select rup.name from receipt_user_permission rup where rup.id = cdr.reviewUserPermissionID) AS reviewUserName,
  599. cdr.reviewDate AS reviewDate,
  600. cdr.cancelUserPermissionID AS cancelUserPermissionID,
  601. (select su.name from sys_user su where su.id = cdr.cancelUserPermissionID) AS cancelUserName,
  602. cdr.cancelDate AS cancelDate,
  603. cdr.cancelReason AS cancelReason
  604. from cm_receipt_order_relation cror
  605. join cm_discern_receipt cdr on cdr.id = cror.receiptID
  606. where cror.delFlag = '0' and cdr.delFlag = '0'
  607. <if test="relationType == 1">
  608. and cror.orderID in (select shopOrderID from cm_shop_order where orderID = #{orderID}) and cror.relationType
  609. = '1'
  610. </if>
  611. <if test="relationType == 2">
  612. and cror.orderID = #{orderID} and cror.relationType = '2'
  613. </if>
  614. </select>
  615. <select id="findOrderIDs" resultType="string">
  616. select orderID from cm_receipt_order_relation cror
  617. where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '2'
  618. </select>
  619. <select id="hasReceiptRecordOrder" resultType="string">
  620. select cror.receiptID
  621. from cm_receipt_order_relation cror
  622. join cm_discern_receipt cdr on cror.receiptID = cdr.id
  623. where cror.orderID = #{orderID} and cror.receiptID != #{receiptID}
  624. and cror.relationType = '2' and cror.delFlag = '0'
  625. and cdr.receiptStatus = '3' and cdr.delFlag = '0'
  626. </select>
  627. <select id="findShopOrderIDs" resultType="string">
  628. select cror.orderID from cm_receipt_order_relation cror
  629. where cror.receiptID = #{receiptID} and cror.delFlag = '0' and cror.relationType = '1'
  630. </select>
  631. <select id="hasReceiptRecordShopOrder" resultType="string">
  632. select cror.receiptID
  633. from cm_receipt_order_relation cror
  634. join cm_discern_receipt cdr on cror.receiptID = cdr.id
  635. where cror.orderID in
  636. (select cso2.shopOrderID
  637. from cm_shop_order cso1
  638. left join cm_shop_order cso2 on cso2.orderID = cso1.orderID
  639. where cso1.shopOrderID = #{shopOrderID} and cso2.shopOrderID != #{shopOrderID})
  640. and cror.orderID != #{shopOrderID}
  641. and cdr.receiptStatus = '2' and cdr.delFlag = '0'
  642. and cror.relationType = '1' and cror.delFlag = '0'
  643. </select>
  644. <select id="getExportInfo" resultType="com.caimei.modules.order.entity.ReceiptExportVo">
  645. -- 1订单款,2非订单款,3返佣款
  646. select
  647. (case when co.orderType = '0' then '协销' else '自主' end) AS type,
  648. (case when co.freePostFlag = '1'
  649. then co.freight else 0 end) as freight,
  650. (select sum(cop.totalAddedValueTax) from cm_order_product cop where cop.orderID = co.orderID) AS tax,
  651. <if test="t == 1">
  652. -- 1订单款
  653. co.payTotalFee AS amount,
  654. cror.associateAmount AS associateAmount,
  655. co.orderNo AS no,
  656. </if>
  657. <if test="t == 3">
  658. -- 3返佣款
  659. concat(cso.needPayAmount, '(子)') AS amount,
  660. concat(cso.needPayAmount, '(子)') AS associateAmount,
  661. concat(cso.shopOrderNo, '(子)') AS no,
  662. </if>
  663. co.orderID AS id
  664. from cm_receipt_order_relation cror
  665. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  666. <if test="t == 1">
  667. left join cm_order co on cror.orderID = co.orderID
  668. </if>
  669. <if test="t == 3">
  670. left join cm_shop_order cso on cror.orderID = cso.shopOrderID
  671. left join cm_order co on cso.orderID = co.orderID
  672. </if>
  673. where cror.receiptID = #{id} and cror.delFlag = '0'
  674. and cdr.delFlag = '0'
  675. <if test="t == 1">
  676. and cror.relationType = '2'
  677. </if>
  678. <if test="t == 3">
  679. and cror.relationType = '1'
  680. </if>
  681. </select>
  682. <select id="getReceiptRecords" resultType="integer">
  683. select cror.receiptID from cm_receipt_order_relation cror
  684. where cror.delFlag = '0' and (
  685. (cror.orderID = #{shopOrderID} and cror.relationType = '1')
  686. or
  687. (cror.orderID in (select orderID from cm_shop_order where shopOrderID = #{shopOrderID}) and cror.relationType = '2')
  688. )
  689. </select>
  690. <select id="findRebateOrderID" resultType="integer">
  691. select cso.orderID AS orderID
  692. from cm_receipt_order_relation cror left join cm_shop_order cso
  693. on cror.orderID = cso.shopOrderID
  694. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  695. where cror.relationType = '1' and cror.delFlag = '0' AND cdr.receiptStatus = '2'
  696. and cso.orderID in
  697. <foreach collection="orderIds" item="id" open="(" close=")" separator=",">
  698. #{id}
  699. </foreach>
  700. </select>
  701. <select id="findShopOrder" resultType="com.caimei.modules.order.entity.CmReceiptExport">
  702. SELECT
  703. o.orderID,
  704. o.payStatus,
  705. so.shopID,
  706. so.shopOrderID,
  707. o.orderTime,
  708. u.userName,
  709. p. NAME AS supplierName,
  710. (
  711. so.productAmount - IFNULL(so.discountAmount, 0)
  712. ) AS productFee,
  713. IFNULL(so.totalAddedValueTax,0) AS taxFee,
  714. IFNULL(so.totalAmount,0) AS receiptAmount,
  715. IFNULL(so.shopTaxFee,0) AS payTaxFee,
  716. IFNULL(so.shopPostFee,0) AS payFreight,
  717. IFNULL(so.shopOtherFee,0) AS payOther,
  718. IFNULL(so.shouldPayShopAmount,0) AS payAmount,
  719. IFNULL(so.productAmount,0) AS productAmount
  720. FROM
  721. cm_order o
  722. LEFT JOIN cm_shop_order so ON so.orderID = o.orderID
  723. LEFT JOIN user u ON u.userID = o.userID
  724. LEFT JOIN shop p ON p.shopID = so.shopID
  725. WHERE
  726. o.orderID = #{orderID}
  727. AND so.delFlag = 0
  728. AND o.delFlag = 0;
  729. </select>
  730. <select id="findSmoothoutInfo" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  731. select * from cm_discern_receipt cdr
  732. LEFT JOIN cm_receipt_order_relation cror on cror.receiptID = cdr.id
  733. where cdr.receiptType = 1 and cror.relationType = 2 and cror.delFlag = 0
  734. and cdr.delFlag = 0 and cdr.confirmType in (1,2,3) and cdr.receiptStatus = '3'
  735. and cror.orderID = #{orderID} LIMIT 1;
  736. </select>
  737. <select id="findOrderReceipt" resultType="double">
  738. select sum(associateAmount) from cm_receipt_order_relation cror
  739. left join cm_discern_receipt cdr on cror.receiptID = cdr.id
  740. where cror.orderID = #{orderID} and cror.delFlag = '0' and cror.relationType = '2'
  741. and cdr.delFlag = '0' and cdr.receiptStatus = '3' and cdr.payWay != '3'
  742. </select>
  743. <select id="gathering" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  744. SELECT
  745. d.receiptDate,d.payType
  746. FROM
  747. cm_receipt_order_relation r
  748. LEFT JOIN cm_discern_receipt d ON d.id = r.receiptID
  749. WHERE r.orderID=#{orderID}
  750. AND d.receiptStatus = 3
  751. AND d.delFlag = '0'
  752. AND r.delFlag = '0'
  753. </select>
  754. <select id="exportRefund" resultType="com.caimei.modules.order.entity.CmReturnedPurchase">
  755. SELECT bou.name as userName, crp.*
  756. FROM `cm_returned_purchase` crp
  757. LEFT JOIN bp_order_userinfo bou ON bou.orderId = crp.orderId
  758. <where>
  759. <if test="startTime != null and startTime != ''">
  760. AND (crp.confirmReturnTime <![CDATA[ > ]]> #{startTime} OR crp.confirmReturnTime = #{startTime})
  761. </if>
  762. <if test="endTime != null and endTime != ''">
  763. AND (crp.confirmReturnTime <![CDATA[ < ]]> #{endTime} OR crp.confirmReturnTime = #{endTime})
  764. </if>
  765. AND crp.status= 2
  766. </where>
  767. ORDER BY crp.confirmReturnTime DESC
  768. </select>
  769. <select id="theOrder" resultType="com.caimei.modules.order.entity.CmMainReceiptExport">
  770. SELECT d.receiptDate, d.payType, IFNULL(d.receiptAmount, 0) AS associateAmount
  771. , d.receiptType
  772. FROM cm_discern_receipt d
  773. <where>
  774. <if test="startTime != null and startTime != ''">
  775. AND (d.receiptDate <![CDATA[ > ]]> #{startTime} OR d.receiptDate = #{startTime})
  776. </if>
  777. <if test="endTime != null and endTime != ''">
  778. AND (d.receiptDate <![CDATA[ < ]]> #{endTime} OR d.receiptDate = #{endTime})
  779. </if>
  780. AND d.receiptStatus = 2
  781. AND d.receiptType = 2
  782. AND d.delFlag = '0'
  783. </where>
  784. ORDER BY d.receiptDate DESC;
  785. </select>
  786. <select id="findDiscernReceipt" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  787. SELECT
  788. cdr.*
  789. FROM
  790. cm_discern_receipt cdr
  791. LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
  792. WHERE
  793. cdr.receiptType = 1
  794. AND cror.relationType = 2
  795. AND cdr.receiptStatus = 3
  796. AND cror.delFlag = 0
  797. AND cdr.delFlag = 0
  798. AND cror.orderID = #{orderID}
  799. ORDER BY
  800. id DESC
  801. LIMIT
  802. 1
  803. </select>
  804. <select id="findPayType" resultType="com.caimei.modules.order.entity.CmDiscernReceipt">
  805. SELECT
  806. cdr.*
  807. FROM
  808. cm_discern_receipt cdr
  809. LEFT JOIN cm_receipt_order_relation cror ON cror.receiptID = cdr.id
  810. WHERE
  811. cdr.receiptType = 1
  812. AND cror.relationType = 2
  813. AND cdr.receiptStatus = 3
  814. AND cror.delFlag = 0
  815. AND cdr.delFlag = 0
  816. AND cror.orderID = #{orderID}
  817. ORDER BY
  818. payWay ASC
  819. LIMIT
  820. 1
  821. </select>
  822. <select id="findOrderLastReceiptDetailId" resultType="java.lang.Integer">
  823. select cdr.id
  824. from cm_discern_receipt cdr
  825. left join cm_receipt_order_relation cror on cdr.id = cror.receiptID
  826. where cdr.delFlag = '0'
  827. and cror.delFlag = '0'
  828. and cror.orderID = #{orderID}
  829. order by cdr.id desc
  830. limit 1
  831. </select>
  832. <select id="findSplitTime" resultType="date">
  833. SELECT
  834. splitTime
  835. FROM
  836. cm_split_account
  837. WHERE
  838. payStatus = 1
  839. AND orderId = #{orderID}
  840. ORDER BY
  841. splitTime DESC
  842. LIMIT
  843. 1
  844. </select>
  845. </mapper>