CmDiscernReceiptMapper.xml 38 KB

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