CmDiscernReceiptMapper.xml 33 KB

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