CmDiscernReceiptMapper.xml 33 KB

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