OrderMapper.xml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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.NewOrderDao">
  4. <sql id="columns">
  5. a.orderID AS orderID,
  6. a.orderNo AS orderNo,
  7. a.organizeID AS organizeID,
  8. a.userID AS userID,
  9. a.buyUserID AS buyUserID,
  10. a.shopOrderIDs AS shopOrderIDs,
  11. a.orderSubmitType AS orderSubmitType,
  12. a.orderType AS orderType,
  13. a.secondHandOrderFlag AS secondHandOrderFlag,
  14. a.status AS status,
  15. a.productTotalFee AS productTotalFee,
  16. a.orderTotalFee AS orderTotalFee,
  17. a.payTotalFee AS payTotalFee,
  18. a.payableAmount AS payableAmount,
  19. a.balancePayFee AS balancePayFee ,
  20. a.discountFee AS discountFee,
  21. a.spID AS spID,
  22. a.mainSpID AS mainSpID,
  23. a.note AS note,
  24. a.clubID AS clubID,
  25. a.clubScanTime AS clubScanTime,
  26. a.payWay AS payWay,
  27. a.orderSource AS orderSource,
  28. a.orderTime AS orderTime,
  29. a.confirmTime AS confirmTime,
  30. a.productCount AS productCount,
  31. a.presentCount AS presentCount,
  32. a.cooFreeFlag AS cooFreeFlag,
  33. a.cooFreeRate AS cooFreeRate,
  34. a.cooFreeAmount AS cooFreeAmount,
  35. a.confirmFlag AS confirmFlag,
  36. a.clauseID AS clauseID,
  37. a.clauseContent AS clauseContent,
  38. a.clauseName AS clauseName,
  39. a.updateDate AS updateDate,
  40. a.freePostFlag AS freePostFlag,
  41. a.freight AS freight,
  42. a.userBeans AS userBeans,
  43. a.delFlag AS delFlag,
  44. a.onlinePayFlag AS onlinePayFlag,
  45. a.payTime AS payTime,
  46. a.splitFlag AS splitFlag,
  47. (select sum(cop.totalAddedValueTax) from cm_order_product cop where cop.orderID = a.orderID) AS totalAddedValueTax,
  48. a.preferential AS preferential,
  49. a.closeReason AS closeReason,
  50. a.receiptStatus as receiptStatus,
  51. a.payStatus as payStatus,
  52. a.sendOutStatus as sendOutStatus,
  53. a.refundType as refundType,
  54. a.postageOrderFlag AS postageOrderFlag,
  55. a.promotionFullReduction AS promotionFullReduction,
  56. a.promotionalGiftsCount AS promotionalGiftsCount,
  57. a.affirmPaymentFlag AS affirmPaymentFlag,
  58. a.rebateFlag AS rebateFlag,
  59. a.zeroCostFlag AS zeroCostFlag,
  60. a.organizeStoreId as organizeStoreId,
  61. a.couponAmount as couponAmount
  62. </sql>
  63. <select id="get" resultType="newOrder">
  64. SELECT <include refid="columns"/>
  65. FROM cm_order a
  66. WHERE a.orderID = #{id}
  67. </select>
  68. <resultMap id="orderDisplayList" type="com.caimei.modules.order.entity.NewOrder">
  69. <id column="orderID" property="orderID"/>
  70. <result column="orderNo" property="orderNo"/>
  71. <result column="organizeID" property="organizeID"/>
  72. <result column="orderType" property="orderType"/>
  73. <result column="shopName" property="shopName"/>
  74. <result column="receiver" property="receiver"/>
  75. <result column="buyer" property="buyer"/>
  76. <result column="orderSource" property="orderSource"/>
  77. <result column="orderTotalFee" property="orderTotalFee"/>
  78. <result column="orderTime" property="orderTime"/>
  79. <result column="productCount" property="productCount"/>
  80. <result column="alreadyReceipt" property="alreadyReceipt"/>
  81. <result column="unReceipt" property="unReceipt"/>
  82. <result column="payTotalFee" property="payTotalFee"/>
  83. <result column="payWay" property="payWay"/>
  84. <result column="status" property="status"/>
  85. <collection property="newShopOrders" ofType="com.caimei.modules.order.entity.NewShopOrder"
  86. select="loadShopOrders" column="orderNo" fetchType="eager">
  87. </collection>
  88. </resultMap>
  89. <select id="findList" resultMap="orderDisplayList" parameterType="NewOrder">
  90. SELECT DISTINCT
  91. co.orderID AS orderID,
  92. co.orderNo AS orderNo,
  93. co.organizeID AS organizeID,
  94. co.userID AS userID,
  95. co.orderType AS orderType,
  96. co.secondHandOrderFlag AS secondHandOrderFlag,
  97. co.onlinePayFlag AS onlinePayFlag,
  98. bou.shouHuoRen AS receiver,
  99. u.name AS buyer,
  100. co.orderSource AS orderSource,
  101. co.orderTotalFee AS orderTotalFee,
  102. co.payableAmount AS payableAmount,
  103. co.orderTime AS orderTime,
  104. co.confirmTime AS confirmTime,
  105. co.payTotalFee AS payTotalFee,
  106. co.payWay AS payWay,
  107. co.payStatus AS payStatus,
  108. co.refundType AS refundType,
  109. co.sendOutStatus AS sendOutStatus,
  110. co.receiptStatus AS receiptStatus,
  111. co.productCount AS productCount,
  112. (SELECT IFNULL(sum(cop.shouldPayFee),0) FROM cm_order_product cop WHERE cop.orderId=co.orderID) AS "shouldPayProduct",
  113. co.status AS status,
  114. co.splitFlag AS splitFlag,
  115. co.postageOrderFlag AS postageOrderFlag,
  116. (case when co.orderType = '0' then
  117. (select case status when 91 then '采美默认协销经理(官方账号)' else linkMan1 end from serviceprovider where serviceProviderID = co.spID)
  118. else
  119. ''
  120. end) AS spName,
  121. co.rebateFlag AS rebateFlag
  122. FROM cm_order co
  123. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  124. LEFT JOIN user u ON u.userID = co.userID
  125. LEFT JOIN club c ON u.userID = c.userID
  126. LEFT JOIN serviceprovider sp ON c.spID = sp.serviceProviderID and sp.status = 90
  127. LEFT JOIN cm_order_product cop ON co.orderID = cop.orderID
  128. LEFT JOIN product p ON cop.productID = p.productID
  129. <where>
  130. co.orderType != 2
  131. <if test="orderID != null and orderID != ''">
  132. AND co.orderID = #{orderID}
  133. </if>
  134. <if test="orderNo != null and orderNo != ''">
  135. AND co.orderNo = #{orderNo}
  136. </if>
  137. <if test="organizeID != null">
  138. AND co.organizeID = #{organizeID}
  139. </if>
  140. <if test="status != null and status != ''">
  141. <choose>
  142. <when test="status == '99'.toString()">
  143. AND co.status in (11,12,13,21,22,23,31,32,33)
  144. </when>
  145. <otherwise>
  146. AND co.status = #{status}
  147. </otherwise>
  148. </choose>
  149. </if>
  150. <if test="buyer != null and buyer != ''">
  151. AND u.name LIKE concat('%',#{buyer},'%')
  152. </if>
  153. <if test="orderType != null and orderType != ''">
  154. AND co.orderType = #{orderType}
  155. </if>
  156. <if test="secondHandOrderFlag != null and secondHandOrderFlag != ''">
  157. AND co.secondHandOrderFlag = #{secondHandOrderFlag}
  158. </if>
  159. <if test="orderSource != null and orderSource != ''">
  160. AND co.orderSource = #{orderSource}
  161. </if>
  162. <if test="orderTime != null and orderTime != ''">
  163. AND co.orderTime = #{orderTime}
  164. </if>
  165. <if test="sendOutStatus != null and sendOutStatus != ''">
  166. AND co.sendOutStatus = #{sendOutStatus}
  167. </if>
  168. <if test="startTime != null and startTime != ''">
  169. AND co.orderTime <![CDATA[ >= ]]> #{startTime}
  170. </if>
  171. <if test="endTime != null and endTime != ''">
  172. AND co.orderTime <![CDATA[ <= ]]> #{endTime}
  173. </if>
  174. <if test="startConfirmTime != null and startConfirmTime != ''">
  175. AND co.confirmTime <![CDATA[ >= ]]> #{startConfirmTime}
  176. </if>
  177. <if test="endConfirmTime != null and endConfirmTime != ''">
  178. AND co.confirmTime <![CDATA[ <= ]]> #{endConfirmTime}
  179. </if>
  180. <if test="receiver != null and receiver != ''">
  181. AND bou.shouHuoRen LIKE concat('%',#{receiver},'%')
  182. </if>
  183. <if test="receiptStatus != null and receiptStatus != ''">
  184. AND co.receiptStatus = #{receiptStatus}
  185. </if>
  186. <if test="payStatus != null and payStatus != ''">
  187. AND co.payStatus = #{payStatus}
  188. </if>
  189. <if test="sendOutStatus != null and sendOutStatus != ''">
  190. AND co.sendOutStatus = #{sendOutStatus}
  191. </if>
  192. <if test="returnedPurchaseStatus != null and returnedPurchaseStatus != ''">
  193. AND
  194. <if test="returnedPurchaseStatus == 1">
  195. exists
  196. </if>
  197. <if test="returnedPurchaseStatus == 0">
  198. not exists
  199. </if>
  200. (select 1 from cm_returned_purchase c3 where c3.status = '1' and c3.orderID = co.orderID and c3.delFlag = 0)
  201. </if>
  202. <if test="refundType != null and refundType != ''">
  203. AND
  204. <if test="refundType == 0">
  205. co.refundType is null
  206. </if>
  207. <if test="refundType == 1">
  208. co.refundType = '1'
  209. </if>
  210. <if test="refundType == 2">
  211. co.refundType = '2'
  212. </if>
  213. </if>
  214. <if test="orderRefundType != null and orderRefundType != ''">
  215. <if test="orderRefundType == 0">
  216. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.delFlag = 0) = 0
  217. </if>
  218. <if test="orderRefundType == 1">
  219. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.delFlag = 0) > 0
  220. </if>
  221. <if test="orderRefundType == 11">
  222. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 1 and crp.delFlag = 0) > 0
  223. </if>
  224. <if test="orderRefundType == 12">
  225. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 2 and crp.delFlag = 0
  226. <if test="startRefundTime != null and startRefundTime != ''">
  227. AND crp.confirmReturnTime <![CDATA[ >= ]]> #{startRefundTime}
  228. </if>
  229. <if test="endRefundTime != null and endRefundTime != ''">
  230. AND crp.confirmReturnTime <![CDATA[ <= ]]> #{endRefundTime}
  231. </if>
  232. ) > 0
  233. </if>
  234. <if test="orderRefundType == 13">
  235. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 3 and crp.delFlag = 0) > 0
  236. </if>
  237. </if>
  238. <if test="rebateOrder != null and rebateOrder != ''">
  239. AND
  240. (<if test="rebateOrder == 1">
  241. co.rebateFlag = '1'
  242. OR exists
  243. </if>
  244. <if test="rebateOrder == 0">
  245. co.rebateFlag = '0'
  246. AND not exists
  247. </if>
  248. (select 1 from cm_receipt_order_relation c1
  249. left join cm_discern_receipt cdr ON c1.receiptID = cdr.id
  250. where c1.relationType = '1'
  251. and c1.orderID in (select c2.shopOrderID from cm_shop_order c2 where c2.orderID = co.orderID)
  252. and c1.delFlag = '0'
  253. and cdr.receiptStatus = '2'))
  254. </if>
  255. <if test="serviceProviderId != null and serviceProviderId != 0">
  256. and (co.spID = #{serviceProviderId}
  257. or sp.serviceProviderID = #{serviceProviderId})
  258. </if>
  259. <if test="productName != null and productName != ''">
  260. and p.name like CONCAT('%',#{productName},'%')
  261. </if>
  262. AND co.delFlag = 0
  263. </where>
  264. <choose>
  265. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  266. ORDER BY ${page.orderBy}
  267. </when>
  268. <otherwise>
  269. ORDER BY co.orderID DESC, co.orderTime DESC
  270. </otherwise>
  271. </choose>
  272. </select>
  273. <select id="loadShopOrders" parameterType="string" resultType="NewShopOrder">
  274. SELECT
  275. cs.shopOrderID AS shopOrderID,
  276. cs.shopOrderNo AS shopOrderNo,
  277. cs.shopOrderNo AS shopOrderNo,
  278. cs.itemCount AS itemCount,
  279. cs.needPayAmount AS needPayAmount,
  280. s.name AS shopName,
  281. cs.status AS status,
  282. cs.shopID AS shopID
  283. FROM cm_shop_order cs
  284. LEFT JOIN shop s ON cs.shopID = s.shopID
  285. WHERE cs.orderNo = #{orderNo} AND cs.delFlag = 0
  286. </select>
  287. <select id="getShopOrders" parameterType="string" resultType="NewShopOrder">
  288. SELECT
  289. (SELECT IFNULL(sum(shouldPayFee),0) FROM cm_order_product WHERE shopOrderID = cs.shopOrderID AND payStatus = 2) AS
  290. alreadyReceipt,
  291. (SELECT IFNULL(sum(shouldPayFee),0) FROM cm_order_product WHERE shopOrderID = cs.shopOrderID AND payStatus !=2) AS unReceipt,
  292. cs.shopOrderID AS shopOrderID,
  293. co.orderID AS orderID,
  294. cs.shopOrderNo AS shopOrderNo,
  295. co.orderNo AS orderNo,
  296. cs.shopOrderNo AS shopOrderNo,
  297. cs.itemCount AS itemCount,
  298. cs.needPayAmount AS needPayAmount,
  299. co.orderType AS orderType,
  300. s.name AS shopName,
  301. bou.shouHuoRen AS receiver,
  302. u.name AS buyer,
  303. co.orderSource AS orderSource,
  304. co.orderTotalFee AS orderTotalFee,
  305. co.orderTime AS orderTime,
  306. cs.status AS status
  307. FROM cm_shop_order cs
  308. LEFT JOIN cm_order co ON cs.orderNo = co.orderNo
  309. LEFT JOIN shop s ON cs.shopID = s.shopID
  310. LEFT JOIN user u ON cs.userID = u.userID
  311. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  312. WHERE cs.orderNo = #{orderNo} AND cs.delFlag = 0
  313. </select>
  314. <update id="updateClauseContent">
  315. UPDATE cm_order SET clauseContent = #{clauseContent},clauseName= #{clauseName}WHERE orderID = #{orderID}
  316. </update>
  317. <insert id="insert" parameterType="NewOrder" keyProperty="orderID" useGeneratedKeys="true">
  318. INSERT INTO cm_order(
  319. orderNo,
  320. userID,
  321. buyUserID,
  322. shopOrderIDs,
  323. orderSubmitType,
  324. orderType,
  325. secondHandOrderFlag,
  326. status,
  327. payFlag,
  328. onlinePayFlag,
  329. productTotalFee,
  330. orderTotalFee,
  331. payTotalFee,
  332. balancePayFee,
  333. discountFee,
  334. spID,
  335. mainSpID,
  336. note,
  337. clubID,
  338. clubScanTime,
  339. payWay,
  340. orderSource,
  341. orderTime,
  342. productCount,
  343. cooFreeFlag,
  344. cooFreeRate,
  345. cooFreeAmount,
  346. confirmFlag,
  347. clauseID,
  348. clauseContent,
  349. clauseName,
  350. updateDate,
  351. freePostFlag,
  352. freight,
  353. delFlag,
  354. payTime,
  355. splitFlag,
  356. preferential,
  357. confirmTime,
  358. invoiceFlag,
  359. postageOrderFlag,
  360. sendOutStatus,
  361. payableAmount,
  362. promotionFullReduction,
  363. promotionalGiftsCount,
  364. affirmPaymentFlag,
  365. rebateFlag,
  366. payStatus,
  367. zeroCostFlag,
  368. couponAmount
  369. ) VALUES (
  370. #{orderNo},
  371. #{userID},
  372. #{buyUserID},
  373. #{shopOrderIDs},
  374. #{orderSubmitType},
  375. #{orderType},
  376. #{secondHandOrderFlag},
  377. #{status},
  378. #{payFlag},
  379. #{onlinePayFlag},
  380. #{productTotalFee},
  381. #{orderTotalFee},
  382. #{payTotalFee},
  383. #{balancePayFee},
  384. #{discountFee},
  385. #{spID},
  386. #{mainSpID},
  387. #{note},
  388. #{clubID},
  389. #{clubScanTime},
  390. #{payWay},
  391. #{orderSource},
  392. #{orderTime},
  393. #{productCount},
  394. #{cooFreeFlag},
  395. #{cooFreeRate},
  396. #{cooFreeAmount},
  397. #{confirmFlag},
  398. #{clauseID},
  399. #{clauseContent},
  400. #{clauseName},
  401. #{updateDate},
  402. #{freePostFlag},
  403. #{freight},
  404. #{delFlag},
  405. #{payTime},
  406. #{splitFlag},
  407. #{preferential},
  408. #{confirmTime},
  409. #{invoiceFlag},
  410. #{postageOrderFlag},
  411. #{sendOutStatus},
  412. #{payableAmount},
  413. #{promotionFullReduction},
  414. #{promotionalGiftsCount},
  415. #{affirmPaymentFlag},
  416. #{rebateFlag},
  417. #{payStatus},
  418. #{zeroCostFlag},
  419. #{couponAmount}
  420. )
  421. </insert>
  422. <update id="update">
  423. update cm_order
  424. <set >
  425. <if test="orderNo != null" >
  426. orderNo = #{orderNo,jdbcType=VARCHAR},
  427. </if>
  428. <if test="userID != null" >
  429. userID = #{userID,jdbcType=BIGINT},
  430. </if>
  431. <if test="organizeID != null" >
  432. organizeID = #{organizeID,jdbcType=INTEGER},
  433. </if>
  434. <if test="buyUserID != null" >
  435. buyUserID = #{buyUserID,jdbcType=INTEGER},
  436. </if>
  437. <if test="shopOrderIDs != null" >
  438. shopOrderIDs = #{shopOrderIDs,jdbcType=VARCHAR},
  439. </if>
  440. <if test="orderSubmitType != null" >
  441. orderSubmitType = #{orderSubmitType,jdbcType=CHAR},
  442. </if>
  443. <if test="orderType != null" >
  444. orderType = #{orderType,jdbcType=CHAR},
  445. </if>
  446. <if test="secondHandOrderFlag != null" >
  447. secondHandOrderFlag = #{secondHandOrderFlag,jdbcType=CHAR},
  448. </if>
  449. <if test="status != null" >
  450. status = #{status,jdbcType=CHAR},
  451. </if>
  452. <if test="productTotalFee != null" >
  453. productTotalFee = #{productTotalFee,jdbcType=DECIMAL},
  454. </if>
  455. <if test="orderTotalFee != null" >
  456. orderTotalFee = #{orderTotalFee,jdbcType=DECIMAL},
  457. </if>
  458. <if test="payTotalFee != null" >
  459. payTotalFee = #{payTotalFee,jdbcType=DECIMAL},
  460. </if>
  461. <if test="payableAmount != null" >
  462. payableAmount = #{payableAmount,jdbcType=DECIMAL},
  463. </if>
  464. <if test="balancePayFee != null" >
  465. balancePayFee = #{balancePayFee,jdbcType=DECIMAL},
  466. </if>
  467. <if test="discountFee != null" >
  468. discountFee = #{discountFee,jdbcType=DECIMAL},
  469. </if>
  470. <if test="spID != null" >
  471. spID = #{spID,jdbcType=BIGINT},
  472. </if>
  473. <if test="mainSpID != null" >
  474. mainSpID = #{mainSpID,jdbcType=BIGINT},
  475. </if>
  476. <if test="clubID != null" >
  477. clubID = #{clubID,jdbcType=BIGINT},
  478. </if>
  479. <if test="clubScanTime != null" >
  480. clubScanTime = #{clubScanTime,jdbcType=VARCHAR},
  481. </if>
  482. <if test="payWay != null" >
  483. payWay = #{payWay,jdbcType=INTEGER},
  484. </if>
  485. <if test="orderSource != null" >
  486. orderSource = #{orderSource,jdbcType=CHAR},
  487. </if>
  488. <if test="orderTime != null" >
  489. orderTime = #{orderTime,jdbcType=TIMESTAMP},
  490. </if>
  491. <if test="productCount != null" >
  492. productCount = #{productCount,jdbcType=INTEGER},
  493. </if>
  494. <if test="presentCount != null" >
  495. presentCount = #{presentCount,jdbcType=INTEGER},
  496. </if>
  497. <if test="cooFreeFlag != null" >
  498. cooFreeFlag = #{cooFreeFlag,jdbcType=CHAR},
  499. </if>
  500. <if test="cooFreeRate != null" >
  501. cooFreeRate = #{cooFreeRate,jdbcType=INTEGER},
  502. </if>
  503. <if test="cooFreeAmount != null" >
  504. cooFreeAmount = #{cooFreeAmount,jdbcType=DECIMAL},
  505. </if>
  506. <if test="confirmFlag != null" >
  507. confirmFlag = #{confirmFlag,jdbcType=CHAR},
  508. </if>
  509. <if test="clauseID != null" >
  510. clauseID = #{clauseID,jdbcType=BIGINT},
  511. </if>
  512. <if test="clauseName != null" >
  513. clauseName = #{clauseName,jdbcType=VARCHAR},
  514. </if>
  515. <if test="freePostFlag != null" >
  516. freePostFlag = #{freePostFlag,jdbcType=CHAR},
  517. </if>
  518. <if test="freight != null" >
  519. freight = #{freight,jdbcType=DECIMAL},
  520. </if>
  521. <if test="delFlag != null" >
  522. delFlag = #{delFlag,jdbcType=CHAR},
  523. </if>
  524. <if test="note != null" >
  525. note = #{note,jdbcType=LONGVARCHAR},
  526. </if>
  527. <if test="clauseContent != null" >
  528. clauseContent = #{clauseContent,jdbcType=LONGVARCHAR},
  529. </if>
  530. <if test="payTime != null" >
  531. payTime = #{payTime,jdbcType=LONGVARCHAR},
  532. </if>
  533. <if test="preferential != null">
  534. preferential = #{preferential ,jdbcType=DECIMAL},
  535. </if>
  536. <if test="discountFee != null" >
  537. discountFee = #{discountFee},
  538. </if>
  539. <if test="payFlag != null" >
  540. payFlag = #{payFlag},
  541. </if>
  542. <if test="onlinePayFlag != null" >
  543. onlinePayFlag = #{onlinePayFlag},
  544. </if>
  545. <if test="splitFlag != null" >
  546. splitFlag = #{splitFlag},
  547. </if>
  548. <if test="closeReason != null" >
  549. closeReason = #{closeReason},
  550. </if>
  551. <if test="confirmTime != null" >
  552. confirmTime = #{confirmTime},
  553. </if>
  554. <if test="invoiceFlag != null" >
  555. invoiceFlag = #{invoiceFlag},
  556. </if>
  557. <if test="postageOrderFlag != null" >
  558. postageOrderFlag = #{postageOrderFlag},
  559. </if>
  560. <if test="sendOutStatus != null" >
  561. sendOutStatus = #{sendOutStatus},
  562. </if>
  563. <if test="receiptStatus != null" >
  564. receiptStatus = #{receiptStatus},
  565. </if>
  566. <if test="payStatus != null" >
  567. payStatus = #{payStatus},
  568. </if>
  569. <if test="refundType != null" >
  570. refundType = #{refundType},
  571. </if>
  572. <if test="promotionFullReduction != null" >
  573. promotionFullReduction = #{promotionFullReduction},
  574. </if>
  575. <if test="promotionalGiftsCount != null" >
  576. promotionalGiftsCount = #{promotionalGiftsCount},
  577. </if>
  578. <if test="affirmPaymentFlag != null">
  579. affirmPaymentFlag = #{affirmPaymentFlag},
  580. </if>
  581. <if test="rebateFlag != null">
  582. rebateFlag = #{rebateFlag},
  583. </if>
  584. <if test="zeroCostFlag != null">
  585. zeroCostFlag = #{zeroCostFlag},
  586. </if>
  587. <if test="couponAmount != null">
  588. couponAmount = #{couponAmount}
  589. </if>
  590. </set>
  591. where orderID = #{orderID,jdbcType=BIGINT}
  592. </update>
  593. <select id="findByOrderID" resultType="NewOrder">
  594. select * from cm_order where orderID = #{orderID}
  595. </select>
  596. <update id="confirmOrder">
  597. UPDATE cm_order_product SET
  598. confirmFlag = 1
  599. WHERE orderID = #{orderID}
  600. </update>
  601. <update id="updateStatus" parameterType="NewOrder">
  602. UPDATE cm_order SET
  603. status = #{status}
  604. WHERE orderID = #{orderID}
  605. </update>
  606. <select id="getOrderByShopOrderID" resultType="NewOrder">
  607. select * from cm_order co
  608. left join cm_shop_order cso on cso.orderID = co.orderID
  609. where cso.shopOrderID = #{shopOrderID}
  610. </select>
  611. <update id="updatePayStatus">
  612. update cm_order set payStatus = #{payStatus} where orderID = #{orderID}
  613. </update>
  614. <select id="findOrderList" resultType="NewOrder" parameterType="NewOrder">
  615. SELECT co.*, bou.name AS buyer,s.name AS shopName,c.name AS clubName
  616. FROM cm_order co
  617. LEFT JOIN cm_shop_order cso ON co.orderID = cso.orderID
  618. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  619. LEFT JOIN shop s ON s.shopID = cso.shopID
  620. LEFT JOIN club c ON c.userID = co.userID
  621. <where>
  622. <if test="startTime != null and startTime != ''">
  623. AND co.orderTime <![CDATA[ >= ]]> #{startTime}
  624. </if>
  625. <if test="endTime != null and endTime != ''">
  626. AND co.orderTime <![CDATA[ <= ]]> #{endTime}
  627. </if>
  628. <if test="orderID != null and orderID != ''">
  629. AND co.orderID = #{orderID}
  630. </if>
  631. <if test="organizeID != null and organizeID != 9999">
  632. AND co.organizeID = #{organizeID}
  633. </if>
  634. <if test="organizeID == 9999">
  635. AND co.orderType = 2
  636. </if>
  637. <if test="orderNo != null and orderNo != ''">
  638. AND co.orderNo like concat('%', #{orderNo} ,'%')
  639. </if>
  640. <if test="shopName != null and shopName != ''">
  641. AND s.name like concat('%', #{shopName} ,'%')
  642. </if>
  643. <if test="buyer != null and buyer != ''">
  644. AND bou.name like concat('%', #{buyer} ,'%')
  645. </if>
  646. <if test="clubName != null and clubName != ''">
  647. AND c.name like concat('%', #{clubName} ,'%')
  648. </if>
  649. <if test="shopOrderIDs != null and shopOrderIDs != ''">
  650. AND cso.shopOrderID = #{shopOrderIDs}
  651. </if>
  652. <if test="shopOrderNo != null and shopOrderNo != ''">
  653. AND cso.shopOrderNo like concat('%', #{shopOrderNo} ,'%')
  654. </if>
  655. <if test="ps != null and ps.length>0 " >
  656. AND co.payStatus IN
  657. <foreach item="item" index="index" collection="ps" open="(" close=")" separator=",">
  658. #{item}
  659. </foreach>
  660. </if>
  661. <if test="receiptStatus != null and receiptStatus!= ''">
  662. AND receiptStatus = #{receiptStatus}
  663. </if>
  664. <if test="refundType !=null and refundType != ''">
  665. <if test="refundType == 1 or refundType == 2">
  666. AND refundType = #{refundType}
  667. </if>
  668. <if test="refundType == 0">
  669. AND refundType NOT IN (1,2)
  670. </if>
  671. </if>
  672. <if test="rebateOrder != null and rebateOrder !=''">
  673. <if test="rebateOrder == 0">
  674. AND cso.shopOrderID NOT IN (
  675. SELECT orderID FROM cm_receipt_order_relation
  676. WHERE relationType = '1' AND delFlag = '0' AND orderID IS NOT NULL)
  677. </if>
  678. <if test="rebateOrder == 1">
  679. AND cso.shopOrderID IN (
  680. SELECT orderID FROM cm_receipt_order_relation
  681. WHERE relationType = '1' AND delFlag = '0' AND orderID IS NOT NULL)
  682. </if>
  683. </if>
  684. AND co.delFlag = '0'
  685. AND cso.delFlag = '0'
  686. </where>
  687. GROUP BY co.orderID
  688. ORDER BY co.orderID DESC
  689. </select>
  690. <select id="findPaidOrderID" resultType="Double">
  691. SELECT SUM(payAmount)
  692. FROM cm_pay_shop_record cosr
  693. LEFT JOIN cm_shop_order cso ON cosr.shopOrderID = cso.shopOrderID
  694. WHERE cso.orderID = #{orderID}
  695. AND cosr.delFlag = '0'
  696. AND cosr.status = '1'
  697. AND cosr.paymentType IN (1,2)
  698. GROUP BY cso.orderID
  699. </select>
  700. <select id="findPromotionsByIds" resultType="com.caimei.modules.product.entity.CmPromotion">
  701. select * from cm_promotions
  702. where id in
  703. <foreach collection="promotionsIds" item="promotionsId" index="index" open="(" separator="," close=")">
  704. #{promotionsId}
  705. </foreach>
  706. </select>
  707. <select id="getDbPromotionsByOrderId" resultType="com.caimei.modules.product.entity.CmPromotion">
  708. select * from cm_promotions_order
  709. where promotionsId=#{promotionsId} and orderId=#{orderId}
  710. </select>
  711. <select id="findServiceProviderList" resultType="com.caimei.modules.user.entity.NewCmSp">
  712. select s.serviceProviderID,s.linkMan1 from serviceprovider s join user u on s.userID = u.userID where s.status = 90 and s.serviceProviderID != 1342
  713. </select>
  714. <insert id="insertPromotionsRecord" parameterType="com.caimei.modules.product.entity.CmPromotion" keyProperty="id" useGeneratedKeys="true">
  715. INSERT INTO cm_promotions_order(
  716. orderId,
  717. promotionsId,
  718. name,
  719. description,
  720. type,
  721. mode,
  722. touchPrice,
  723. reducedPrice,
  724. status,
  725. beginTime,
  726. endTime
  727. ) VALUES (
  728. #{orderId},
  729. #{promotionsId},
  730. #{name},
  731. #{description},
  732. #{type},
  733. #{mode},
  734. #{touchPrice},
  735. #{reducedPrice},
  736. #{status},
  737. #{beginTime},
  738. #{endTime}
  739. )
  740. </insert>
  741. <update id="updatePromotionsRecord">
  742. update cm_promotions_order
  743. <set >
  744. <if test="orderId != null and orderId !=''" >
  745. orderId = #{orderId},
  746. </if>
  747. <if test="promotionsId != null and promotionsId !=''" >
  748. promotionsId = #{promotionsId},
  749. </if>
  750. <if test="name != null and name !=''" >
  751. name = #{name},
  752. </if>
  753. <if test="description != null and description !=''" >
  754. description = #{description},
  755. </if>
  756. <if test="type != null and type !=''" >
  757. type = #{type},
  758. </if>
  759. <if test="mode != null and mode !=''" >
  760. mode = #{mode},
  761. </if>
  762. <if test="touchPrice != null and touchPrice !=''" >
  763. touchPrice = #{touchPrice},
  764. </if>
  765. <if test="reducedPrice != null and reducedPrice !=''" >
  766. reducedPrice = #{reducedPrice},
  767. </if>
  768. <if test="status != null and status !=''" >
  769. status = #{status},
  770. </if>
  771. <if test="beginTime != null and beginTime !=''" >
  772. beginTime = #{beginTime},
  773. </if>
  774. <if test="endTime != null and endTime !=''" >
  775. endTime = #{endTime}
  776. </if>
  777. </set>
  778. where id = #{id}
  779. </update>
  780. <update id="updatePayAndReceipt">
  781. update cm_order set payStatus=3, receiptStatus=3 where orderID=#{orderID}
  782. </update>
  783. <update id="updateOrderStatus">
  784. update cm_order set payStatus = #{payStatus} ,zeroCostFlag = #{zeroCostFlag} where orderID = #{orderID}
  785. </update>
  786. <delete id="deleterPomotionsOrder">
  787. DELETE FROM cm_promotions_order WHERE orderId = #{orderId}
  788. </delete>
  789. <update id="updateByRebateFlag">
  790. UPDATE cm_order SET rebateFlag = 1 WHERE orderID = #{orderId}
  791. </update>
  792. <select id="findQualificationFile" resultType="com.caimei.modules.order.entity.CmFile">
  793. SELECT
  794. fileName,
  795. ossName
  796. FROM
  797. cm_qualification_file
  798. WHERE
  799. recordId = #{recordId}
  800. </select>
  801. <select id="findQualificationImage" resultType="string">
  802. SELECT image FROM cm_qualification_image WHERE recordId = #{recordId} ORDER BY id
  803. </select>
  804. <delete id="deleteQualificationImage">
  805. DELETE FROM cm_qualification_image WHERE recordId = #{recordId}
  806. </delete>
  807. <insert id="insertQualificationImage">
  808. INSERT INTO `cm_qualification_image` (
  809. `recordId`, `image`)
  810. VALUES
  811. (#{recordId}, #{image});
  812. </insert>
  813. <delete id="deleteQualificationFile">
  814. DELETE FROM cm_qualification_file WHERE recordId = #{recordId}
  815. </delete>
  816. <insert id="insertQualificationFile">
  817. INSERT INTO `cm_qualification_file` (
  818. `recordId`, `fileName`, `ossName`
  819. )
  820. VALUES
  821. (
  822. #{recordId}, #{fileName}, #{ossName}
  823. )
  824. </insert>
  825. <select id="findBYShortLink" resultType="integer">
  826. SELECT id FROM cm_short_link WHERE shortLink = #{shortLink}
  827. </select>
  828. <select id="getDepositOrderProductId" resultType="java.lang.Integer">
  829. SELECT productID FROM cm_order_product WHERE orderID = #{orderID} LIMIT 1
  830. </select>
  831. <insert id="insertShortLink">
  832. INSERT INTO `caimei`.`cm_short_link` (
  833. `markId`, `shortLink`, `jumpLink`,
  834. `createTime`
  835. )
  836. VALUES
  837. (
  838. #{markId}, #{shortLink}, #{url},
  839. NOW()
  840. )
  841. </insert>
  842. <update id="updateSendNum">
  843. UPDATE cm_sms_statistics SET sendNum = (sendNum + #{num}) WHERE markId = #{markId}
  844. </update>
  845. <update id="updateUserMoneyByUserId">
  846. UPDATE USER SET userMoney=(userMoney-#{payTotalFee}), ableUserMoney = (ableUserMoney-#{payTotalFee})
  847. WHERE userID = #{userID}
  848. </update>
  849. <select id="findOrderCouponRecord" resultType="com.caimei.modules.coupon.entity.CmCouponOrderRecord">
  850. SELECT
  851. `id`,
  852. `orderId`,
  853. `clubCouponId`,
  854. `couponType`,
  855. `couponAmount`,
  856. `touchPrice`,
  857. `createDate`
  858. FROM
  859. cm_coupon_order_record
  860. WHERE
  861. orderId = #{orderID}
  862. </select>
  863. <select id="findClubCouponById" resultType="com.caimei.modules.coupon.entity.CmCoupon">
  864. SELECT
  865. cc.`id`,
  866. cc.`couponAmount`,
  867. cc.`touchPrice`,
  868. cc.`couponType`,
  869. cc.`userId`,
  870. cc.`shopId`,
  871. cc.`productType`,
  872. cc.`categoryType`,
  873. cc.`couponsMode`
  874. FROM
  875. cm_coupon_club a
  876. LEFT JOIN cm_coupon cc ON a.couponId = cc.id
  877. WHERE
  878. a.id = #{clubCouponId}
  879. AND a.status = 1
  880. </select>
  881. <insert id="insertCouponOrderRecord">
  882. INSERT INTO `cm_coupon_order_record` (
  883. `orderId`,
  884. `clubCouponId`,
  885. `couponType`,
  886. `couponAmount`,
  887. `touchPrice`,
  888. `createDate`
  889. )
  890. VALUES
  891. (
  892. #{orderId},
  893. #{clubCouponId},
  894. #{couponType},
  895. #{couponAmount},
  896. #{touchPrice},
  897. #{createDate}
  898. )
  899. </insert>
  900. <update id="updateCouponOrderRecord">
  901. UPDATE
  902. `cm_coupon_order_record`
  903. SET
  904. `clubCouponId` = #{clubCouponId},
  905. `couponType` = #{couponType},
  906. `couponAmount` = #{couponAmount},
  907. `touchPrice` = #{touchPrice}
  908. WHERE
  909. orderId = #{orderId}
  910. </update>
  911. <delete id="deleteCouponOrderRecord">
  912. DELETE FROM cm_coupon_order_record WHERE id = #{id}
  913. </delete>
  914. </mapper>