OrderMapper.xml 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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.orderSeen AS orderSeen,
  6. a.orderID AS orderID,
  7. a.orderNo AS orderNo,
  8. a.organizeID AS organizeID,
  9. a.userID AS userID,
  10. a.buyUserID AS buyUserID,
  11. a.shopOrderIDs AS shopOrderIDs,
  12. a.orderSubmitType AS orderSubmitType,
  13. a.orderType AS orderType,
  14. a.secondHandOrderFlag AS secondHandOrderFlag,
  15. a.status AS status,
  16. a.productTotalFee AS productTotalFee,
  17. a.orderTotalFee AS orderTotalFee,
  18. a.payTotalFee AS payTotalFee,
  19. a.payableAmount AS payableAmount,
  20. a.balancePayFee AS balancePayFee ,
  21. a.discountFee AS discountFee,
  22. a.spID AS spID,
  23. a.mainSpID AS mainSpID,
  24. a.note AS note,
  25. a.clubID AS clubID,
  26. a.clubScanTime AS clubScanTime,
  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.confirmFlag AS confirmFlag,
  33. a.clauseID AS clauseID,
  34. a.clauseContent AS clauseContent,
  35. a.clauseName AS clauseName,
  36. a.updateDate AS updateDate,
  37. a.freePostFlag AS freePostFlag,
  38. a.freight AS freight,
  39. a.userBeans AS userBeans,
  40. a.delFlag AS delFlag,
  41. ifnull(a.onlinePayFlag,1) AS onlinePayFlag,
  42. a.payTime AS payTime,
  43. a.splitFlag AS splitFlag,
  44. (select sum(cop.totalAddedValueTax) from cm_order_product cop where cop.orderID = a.orderID) AS totalAddedValueTax,
  45. a.preferential AS preferential,
  46. a.closeReason AS closeReason,
  47. a.receiptStatus as receiptStatus,
  48. a.payStatus as payStatus,
  49. a.sendOutStatus as sendOutStatus,
  50. a.refundType as refundType,
  51. a.postageOrderFlag AS postageOrderFlag,
  52. a.promotionFullReduction AS promotionFullReduction,
  53. a.promotionalGiftsCount AS promotionalGiftsCount,
  54. a.affirmPaymentFlag AS affirmPaymentFlag,
  55. a.rebateFlag AS rebateFlag,
  56. a.zeroCostFlag AS zeroCostFlag,
  57. a.organizeStoreId as organizeStoreId,
  58. a.couponAmount as couponAmount,
  59. a.svipFullReduction as svipFullReduction,
  60. (a.discountFee + a.promotionFullReduction + a.couponAmount) as discountAmount,
  61. a.rebateFee,
  62. if(chcm.id is not null,1,0) as collageFlag,
  63. chc.status as collageStatus
  64. </sql>
  65. <select id="get" resultType="newOrder">
  66. SELECT
  67. <include refid="columns"/>
  68. FROM cm_order a
  69. LEFT JOIN cm_hehe_collage_member chcm on a.orderID = chcm.orderId
  70. LEFT JOIN cm_hehe_collage chc on chcm.collageId = chc.id
  71. WHERE a.orderID = #{id}
  72. </select>
  73. <resultMap id="orderDisplayList" type="com.caimei.modules.order.entity.NewOrder">
  74. <id column="orderID" property="orderID"/>
  75. <result column="orderNo" property="orderNo"/>
  76. <result column="organizeID" property="organizeID"/>
  77. <result column="orderType" property="orderType"/>
  78. <result column="shopName" property="shopName"/>
  79. <result column="receiver" property="receiver"/>
  80. <result column="buyer" property="buyer"/>
  81. <result column="orderSource" property="orderSource"/>
  82. <result column="orderTotalFee" property="orderTotalFee"/>
  83. <result column="orderTime" property="orderTime"/>
  84. <result column="productCount" property="productCount"/>
  85. <result column="alreadyReceipt" property="alreadyReceipt"/>
  86. <result column="unReceipt" property="unReceipt"/>
  87. <result column="payTotalFee" property="payTotalFee"/>
  88. <result column="status" property="status"/>
  89. <collection property="newShopOrders" ofType="com.caimei.modules.order.entity.NewShopOrder"
  90. select="loadShopOrders" column="orderNo" fetchType="eager">
  91. </collection>
  92. </resultMap>
  93. <select id="findList" resultMap="orderDisplayList" parameterType="NewOrder">
  94. SELECT DISTINCT
  95. co.orderID AS orderID,
  96. co.orderNo AS orderNo,
  97. co.organizeID AS organizeID,
  98. co.userID AS userID,
  99. co.orderType AS orderType,
  100. co.secondHandOrderFlag AS secondHandOrderFlag,
  101. co.onlinePayFlag AS onlinePayFlag,
  102. bou.shouHuoRen AS receiver,
  103. u.name AS buyer,
  104. co.orderSource AS orderSource,
  105. co.orderTotalFee AS orderTotalFee,
  106. co.payableAmount AS payableAmount,
  107. co.orderTime AS orderTime,
  108. co.confirmTime AS confirmTime,
  109. co.payTotalFee AS payTotalFee,
  110. co.payStatus AS payStatus,
  111. co.refundType AS refundType,
  112. co.sendOutStatus AS sendOutStatus,
  113. co.receiptStatus AS receiptStatus,
  114. co.productCount AS productCount,
  115. (SELECT IFNULL(sum(cop.shouldPayFee),0)
  116. FROM cm_order_product cop
  117. WHERE cop.orderId=co.orderID) AS
  118. "shouldPayProduct",
  119. co.status AS status,
  120. co.splitFlag AS splitFlag,
  121. co.postageOrderFlag AS postageOrderFlag,
  122. (case when co.orderType = '0' then
  123. (select case status when 91 then '采美默认协销经理(官方账号)' else linkMan end from serviceprovider where serviceProviderID
  124. = co.spID)
  125. else
  126. ''
  127. end) AS spName,
  128. co.rebateFlag AS rebateFlag,
  129. co.rebateFee AS rebateFee
  130. FROM cm_order co
  131. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  132. LEFT JOIN user u ON u.userID = co.userID
  133. LEFT JOIN club c ON u.userID = c.userID
  134. LEFT JOIN serviceprovider sp ON c.spID = sp.serviceProviderID and sp.status = 90
  135. LEFT JOIN cm_order_product cop ON co.orderID = cop.orderID
  136. LEFT JOIN product p ON cop.productID = p.productID
  137. left join cm_shop_order cso on co.orderid=cso.orderID
  138. <where>
  139. co.orderType != 2
  140. <if test="orderID != null and orderID != ''">
  141. AND co.orderID = #{orderID}
  142. </if>
  143. <if test="settleStatus != null">
  144. AND cso.settleStatus = #{settleStatus}
  145. </if>
  146. <if test="orderNo != null and orderNo != ''">
  147. AND co.orderNo = #{orderNo}
  148. </if>
  149. <if test="organizeID != null">
  150. AND co.organizeID = #{organizeID}
  151. </if>
  152. <if test="status != null and status != ''">
  153. <choose>
  154. <when test="status == '99'.toString()">
  155. AND co.status in (11,12,13,21,22,23,31,32,33)
  156. </when>
  157. <otherwise>
  158. AND co.status = #{status}
  159. </otherwise>
  160. </choose>
  161. </if>
  162. <if test="buyer != null and buyer != ''">
  163. AND u.name LIKE concat('%',#{buyer},'%')
  164. </if>
  165. <if test="orderType != null and orderType != ''">
  166. AND co.orderType = #{orderType}
  167. </if>
  168. <if test="secondHandOrderFlag != null and secondHandOrderFlag != ''">
  169. AND co.secondHandOrderFlag = #{secondHandOrderFlag}
  170. </if>
  171. <if test="orderSource != null and orderSource != ''">
  172. AND co.orderSource = #{orderSource}
  173. </if>
  174. <if test="orderTime != null and orderTime != ''">
  175. AND co.orderTime = #{orderTime}
  176. </if>
  177. <if test="sendOutStatus != null and sendOutStatus != ''">
  178. AND co.sendOutStatus = #{sendOutStatus}
  179. </if>
  180. <if test="startTime != null and startTime != ''">
  181. AND co.orderTime <![CDATA[ >= ]]> #{startTime}
  182. </if>
  183. <if test="endTime != null and endTime != ''">
  184. AND co.orderTime <![CDATA[ <= ]]> #{endTime}
  185. </if>
  186. <if test="startConfirmTime != null and startConfirmTime != ''">
  187. AND co.confirmTime <![CDATA[ >= ]]> #{startConfirmTime}
  188. </if>
  189. <if test="endConfirmTime != null and endConfirmTime != ''">
  190. AND co.confirmTime <![CDATA[ <= ]]> #{endConfirmTime}
  191. </if>
  192. <if test="receiver != null and receiver != ''">
  193. AND bou.shouHuoRen LIKE concat('%',#{receiver},'%')
  194. </if>
  195. <if test="receiptStatus != null and receiptStatus != ''">
  196. AND co.receiptStatus = #{receiptStatus}
  197. </if>
  198. <if test="payStatus != null and payStatus != ''">
  199. AND co.payStatus = #{payStatus}
  200. </if>
  201. <if test="sendOutStatus != null and sendOutStatus != ''">
  202. AND co.sendOutStatus = #{sendOutStatus}
  203. </if>
  204. <if test="returnedPurchaseStatus != null and returnedPurchaseStatus != ''">
  205. AND
  206. <if test="returnedPurchaseStatus == 1">
  207. exists
  208. </if>
  209. <if test="returnedPurchaseStatus == 0">
  210. not exists
  211. </if>
  212. (select 1 from cm_returned_purchase c3 where c3.status = '1' and c3.orderID = co.orderID and c3.delFlag
  213. = 0)
  214. </if>
  215. <if test="refundType != null and refundType != ''">
  216. AND
  217. <if test="refundType == 0">
  218. co.refundType is null
  219. </if>
  220. <if test="refundType == 1">
  221. co.refundType = '1'
  222. </if>
  223. <if test="refundType == 2">
  224. co.refundType = '2'
  225. </if>
  226. </if>
  227. <if test="orderRefundType != null and orderRefundType != ''">
  228. <if test="orderRefundType == 0">
  229. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.delFlag =
  230. 0) = 0
  231. </if>
  232. <if test="orderRefundType == 1">
  233. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.delFlag =
  234. 0) > 0
  235. </if>
  236. <if test="orderRefundType == 11">
  237. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 1
  238. and crp.delFlag = 0) > 0
  239. </if>
  240. <if test="orderRefundType == 12">
  241. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 2
  242. and crp.delFlag = 0
  243. <if test="startRefundTime != null and startRefundTime != ''">
  244. AND crp.confirmReturnTime <![CDATA[ >= ]]> #{startRefundTime}
  245. </if>
  246. <if test="endRefundTime != null and endRefundTime != ''">
  247. AND crp.confirmReturnTime <![CDATA[ <= ]]> #{endRefundTime}
  248. </if>
  249. ) > 0
  250. </if>
  251. <if test="orderRefundType == 13">
  252. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 3
  253. and crp.delFlag = 0) > 0
  254. </if>
  255. </if>
  256. <if test="rebateOrder != null and rebateOrder != ''">
  257. <if test="rebateOrder == 1">
  258. AND co.rebateFlag = '1'
  259. </if>
  260. <if test="rebateOrder == 0">
  261. AND co.rebateFlag = '0'
  262. </if>
  263. </if>
  264. <if test="serviceProviderId != null and serviceProviderId != 0">
  265. and (co.spID = #{serviceProviderId}
  266. or sp.serviceProviderID = #{serviceProviderId})
  267. </if>
  268. <if test="productName != null and productName != ''">
  269. and p.name like CONCAT('%',#{productName},'%')
  270. </if>
  271. <if test="productCategory == 2">
  272. and p.productCategory=2
  273. </if>
  274. <if test="productCategory == null || productCategory == 1">
  275. and p.productCategory=1
  276. </if>
  277. AND co.delFlag = 0
  278. </where>
  279. <choose>
  280. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  281. ORDER BY ${page.orderBy}
  282. </when>
  283. <otherwise>
  284. ORDER BY co.orderID DESC, co.orderTime DESC
  285. </otherwise>
  286. </choose>
  287. </select>
  288. <select id="loadShopOrders" parameterType="string" resultType="NewShopOrder">
  289. SELECT cs.shopOrderID AS shopOrderID,
  290. cs.shopOrderNo AS shopOrderNo,
  291. cs.shopOrderNo AS shopOrderNo,
  292. cs.itemCount AS itemCount,
  293. cs.needPayAmount AS needPayAmount,
  294. s.name AS shopName,
  295. cs.shopID AS shopID
  296. FROM cm_shop_order cs
  297. LEFT JOIN shop s ON cs.shopID = s.shopID
  298. WHERE cs.orderNo = #{orderNo}
  299. AND cs.delFlag = 0
  300. </select>
  301. <select id="getShopOrders" parameterType="string" resultType="NewShopOrder">
  302. SELECT (SELECT IFNULL(sum(shouldPayFee), 0)
  303. FROM cm_order_product
  304. WHERE shopOrderID = cs.shopOrderID AND payStatus = 2) AS
  305. alreadyReceipt,
  306. (SELECT IFNULL(sum(shouldPayFee), 0)
  307. FROM cm_order_product
  308. WHERE shopOrderID = cs.shopOrderID AND payStatus != 2) AS unReceipt,
  309. cs.shopOrderID AS shopOrderID,
  310. co.orderID AS orderID,
  311. cs.shopOrderNo AS shopOrderNo,
  312. co.orderNo AS orderNo,
  313. cs.shopOrderNo AS shopOrderNo,
  314. cs.itemCount AS itemCount,
  315. cs.needPayAmount AS needPayAmount,
  316. co.orderType AS orderType,
  317. s.name AS shopName,
  318. bou.shouHuoRen AS receiver,
  319. u.name AS buyer,
  320. co.orderSource AS orderSource,
  321. co.orderTotalFee AS orderTotalFee,
  322. co.orderTime AS orderTime
  323. FROM cm_shop_order cs
  324. LEFT JOIN cm_order co ON cs.orderNo = co.orderNo
  325. LEFT JOIN shop s ON cs.shopID = s.shopID
  326. LEFT JOIN user u ON cs.userID = u.userID
  327. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  328. WHERE cs.orderNo = #{orderNo}
  329. AND cs.delFlag = 0
  330. </select>
  331. <update id="updateClauseContent">
  332. UPDATE cm_order
  333. SET clauseContent = #{clauseContent},
  334. clauseName= #{clauseName}WHERE orderID = #{orderID}
  335. </update>
  336. <insert id="insert" parameterType="NewOrder" keyProperty="orderID" useGeneratedKeys="true">
  337. INSERT INTO cm_order(orderSeen,
  338. orderNo,
  339. userID,
  340. buyUserID,
  341. shopOrderIDs,
  342. orderSubmitType,
  343. orderType,
  344. secondHandOrderFlag,
  345. status,
  346. payFlag,
  347. onlinePayFlag,
  348. productTotalFee,
  349. orderTotalFee,
  350. payTotalFee,
  351. balancePayFee,
  352. discountFee,
  353. spID,
  354. mainSpID,
  355. note,
  356. clubID,
  357. clubScanTime,
  358. orderSource,
  359. orderTime,
  360. productCount,
  361. confirmFlag,
  362. clauseID,
  363. clauseContent,
  364. clauseName,
  365. updateDate,
  366. freePostFlag,
  367. freight,
  368. delFlag,
  369. payTime,
  370. splitFlag,
  371. preferential,
  372. confirmTime,
  373. invoiceFlag,
  374. postageOrderFlag,
  375. sendOutStatus,
  376. payableAmount,
  377. promotionFullReduction,
  378. promotionalGiftsCount,
  379. affirmPaymentFlag,
  380. rebateFlag,
  381. rebateFee,
  382. payStatus,
  383. zeroCostFlag,
  384. couponAmount,
  385. svipFullReduction)
  386. VALUES (#{orderSeen},
  387. #{orderNo},
  388. #{userID},
  389. #{buyUserID},
  390. #{shopOrderIDs},
  391. #{orderSubmitType},
  392. #{orderType},
  393. #{secondHandOrderFlag},
  394. #{status},
  395. #{payFlag},
  396. #{onlinePayFlag},
  397. #{productTotalFee},
  398. #{orderTotalFee},
  399. #{payTotalFee},
  400. #{balancePayFee},
  401. #{discountFee},
  402. #{spID},
  403. #{mainSpID},
  404. #{note},
  405. #{clubID},
  406. #{clubScanTime},
  407. #{orderSource},
  408. #{orderTime},
  409. #{productCount},
  410. #{confirmFlag},
  411. #{clauseID},
  412. #{clauseContent},
  413. #{clauseName},
  414. #{updateDate},
  415. #{freePostFlag},
  416. #{freight},
  417. #{delFlag},
  418. #{payTime},
  419. #{splitFlag},
  420. #{preferential},
  421. #{confirmTime},
  422. #{invoiceFlag},
  423. #{postageOrderFlag},
  424. #{sendOutStatus},
  425. #{payableAmount},
  426. #{promotionFullReduction},
  427. #{promotionalGiftsCount},
  428. #{affirmPaymentFlag},
  429. #{rebateFlag},
  430. #{rebateFee},
  431. #{payStatus},
  432. #{zeroCostFlag},
  433. #{couponAmount},
  434. #{svipFullReduction})
  435. </insert>
  436. <update id="update">
  437. update cm_order
  438. <set>
  439. <if test="orderSeen != null">
  440. orderSeen = #{orderSeen},
  441. </if>
  442. <if test="orderNo != null">
  443. orderNo = #{orderNo,jdbcType=VARCHAR},
  444. </if>
  445. <if test="userID != null">
  446. userID = #{userID,jdbcType=BIGINT},
  447. </if>
  448. <if test="organizeID != null">
  449. organizeID = #{organizeID,jdbcType=INTEGER},
  450. </if>
  451. <if test="buyUserID != null">
  452. buyUserID = #{buyUserID,jdbcType=INTEGER},
  453. </if>
  454. <if test="shopOrderIDs != null">
  455. shopOrderIDs = #{shopOrderIDs,jdbcType=VARCHAR},
  456. </if>
  457. <if test="orderSubmitType != null">
  458. orderSubmitType = #{orderSubmitType,jdbcType=CHAR},
  459. </if>
  460. <if test="orderType != null">
  461. orderType = #{orderType,jdbcType=CHAR},
  462. </if>
  463. <if test="secondHandOrderFlag != null">
  464. secondHandOrderFlag = #{secondHandOrderFlag,jdbcType=CHAR},
  465. </if>
  466. <if test="status != null">
  467. status = #{status,jdbcType=CHAR},
  468. </if>
  469. <if test="productTotalFee != null">
  470. productTotalFee = #{productTotalFee,jdbcType=DECIMAL},
  471. </if>
  472. <if test="orderTotalFee != null">
  473. orderTotalFee = #{orderTotalFee,jdbcType=DECIMAL},
  474. </if>
  475. <if test="payTotalFee != null">
  476. payTotalFee = #{payTotalFee,jdbcType=DECIMAL},
  477. </if>
  478. <if test="payableAmount != null">
  479. payableAmount = #{payableAmount,jdbcType=DECIMAL},
  480. </if>
  481. <if test="balancePayFee != null">
  482. balancePayFee = #{balancePayFee,jdbcType=DECIMAL},
  483. </if>
  484. <if test="discountFee != null">
  485. discountFee = #{discountFee,jdbcType=DECIMAL},
  486. </if>
  487. <if test="spID != null">
  488. spID = #{spID,jdbcType=BIGINT},
  489. </if>
  490. <if test="mainSpID != null">
  491. mainSpID = #{mainSpID,jdbcType=BIGINT},
  492. </if>
  493. <if test="clubID != null">
  494. clubID = #{clubID,jdbcType=BIGINT},
  495. </if>
  496. <if test="clubScanTime != null">
  497. clubScanTime = #{clubScanTime,jdbcType=VARCHAR},
  498. </if>
  499. <if test="orderSource != null">
  500. orderSource = #{orderSource,jdbcType=CHAR},
  501. </if>
  502. <if test="orderTime != null">
  503. orderTime = #{orderTime,jdbcType=TIMESTAMP},
  504. </if>
  505. <if test="productCount != null">
  506. productCount = #{productCount,jdbcType=INTEGER},
  507. </if>
  508. <if test="presentCount != null">
  509. presentCount = #{presentCount,jdbcType=INTEGER},
  510. </if>
  511. <if test="confirmFlag != null">
  512. confirmFlag = #{confirmFlag,jdbcType=CHAR},
  513. </if>
  514. <if test="clauseID != null">
  515. clauseID = #{clauseID,jdbcType=BIGINT},
  516. </if>
  517. <if test="clauseName != null">
  518. clauseName = #{clauseName,jdbcType=VARCHAR},
  519. </if>
  520. <if test="freePostFlag != null">
  521. freePostFlag = #{freePostFlag,jdbcType=CHAR},
  522. </if>
  523. <if test="freight != null">
  524. freight = #{freight,jdbcType=DECIMAL},
  525. </if>
  526. <if test="delFlag != null">
  527. delFlag = #{delFlag,jdbcType=CHAR},
  528. </if>
  529. <if test="note != null">
  530. note = #{note,jdbcType=LONGVARCHAR},
  531. </if>
  532. <if test="clauseContent != null">
  533. clauseContent = #{clauseContent,jdbcType=LONGVARCHAR},
  534. </if>
  535. <if test="payTime != null">
  536. payTime = #{payTime,jdbcType=LONGVARCHAR},
  537. </if>
  538. <if test="preferential != null">
  539. preferential = #{preferential ,jdbcType=DECIMAL},
  540. </if>
  541. <if test="discountFee != null">
  542. discountFee = #{discountFee},
  543. </if>
  544. <if test="payFlag != null">
  545. payFlag = #{payFlag},
  546. </if>
  547. <if test="onlinePayFlag != null">
  548. onlinePayFlag = #{onlinePayFlag},
  549. </if>
  550. <if test="splitFlag != null">
  551. splitFlag = #{splitFlag},
  552. </if>
  553. <if test="closeReason != null">
  554. closeReason = #{closeReason},
  555. </if>
  556. <if test="confirmTime != null">
  557. confirmTime = #{confirmTime},
  558. </if>
  559. <if test="invoiceFlag != null">
  560. invoiceFlag = #{invoiceFlag},
  561. </if>
  562. <if test="postageOrderFlag != null">
  563. postageOrderFlag = #{postageOrderFlag},
  564. </if>
  565. <if test="sendOutStatus != null">
  566. sendOutStatus = #{sendOutStatus},
  567. </if>
  568. <if test="receiptStatus != null">
  569. receiptStatus = #{receiptStatus},
  570. </if>
  571. <if test="payStatus != null">
  572. payStatus = #{payStatus},
  573. </if>
  574. <if test="refundType != null">
  575. refundType = #{refundType},
  576. </if>
  577. <if test="promotionFullReduction != null">
  578. promotionFullReduction = #{promotionFullReduction},
  579. </if>
  580. <if test="promotionalGiftsCount != null">
  581. promotionalGiftsCount = #{promotionalGiftsCount},
  582. </if>
  583. <if test="affirmPaymentFlag != null">
  584. affirmPaymentFlag = #{affirmPaymentFlag},
  585. </if>
  586. <if test="rebateFlag != null">
  587. rebateFlag = #{rebateFlag},
  588. </if>
  589. <if test="rebateFee != null">
  590. rebateFee = #{rebateFee},
  591. </if>
  592. <if test="zeroCostFlag != null">
  593. zeroCostFlag = #{zeroCostFlag},
  594. </if>
  595. <if test="couponAmount != null">
  596. couponAmount = #{couponAmount},
  597. </if>
  598. <if test="svipFullReduction != null">
  599. svipFullReduction = #{svipFullReduction}
  600. </if>
  601. </set>
  602. where orderID = #{orderID,jdbcType=BIGINT}
  603. </update>
  604. <select id="findByOrderID" resultType="NewOrder">
  605. select *
  606. from cm_order
  607. where orderID = #{orderID}
  608. </select>
  609. <update id="confirmOrder">
  610. </update>
  611. <update id="updateStatus" parameterType="NewOrder">
  612. UPDATE cm_order
  613. SET status = #{status}
  614. WHERE orderID = #{orderID}
  615. </update>
  616. <select id="getOrderByShopOrderID" resultType="NewOrder">
  617. select *
  618. from cm_order co
  619. left join cm_shop_order cso on cso.orderID = co.orderID
  620. where cso.shopOrderID = #{shopOrderID}
  621. </select>
  622. <update id="updatePayStatus">
  623. update cm_order
  624. set payStatus = #{payStatus}
  625. where orderID = #{orderID}
  626. </update>
  627. <select id="findOrderList" resultType="NewOrder" parameterType="NewOrder">
  628. SELECT co.*, bou.name AS buyer,s.name AS shopName,c.name AS clubName
  629. FROM cm_order co
  630. LEFT JOIN cm_shop_order cso ON co.orderID = cso.orderID
  631. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  632. LEFT JOIN shop s ON s.shopID = cso.shopID
  633. LEFT JOIN club c ON c.userID = co.userID
  634. <where>
  635. <if test="startTime != null and startTime != ''">
  636. AND co.orderTime <![CDATA[ >= ]]> #{startTime}
  637. </if>
  638. <if test="endTime != null and endTime != ''">
  639. AND co.orderTime <![CDATA[ <= ]]> #{endTime}
  640. </if>
  641. <if test="orderID != null and orderID != ''">
  642. AND co.orderID = #{orderID}
  643. </if>
  644. <if test="organizeID != null and organizeID != 9999">
  645. AND co.organizeID = #{organizeID}
  646. </if>
  647. <if test="organizeID == 9999">
  648. AND co.orderType = 2
  649. </if>
  650. <if test="orderNo != null and orderNo != ''">
  651. AND co.orderNo like concat('%', #{orderNo} ,'%')
  652. </if>
  653. <if test="shopName != null and shopName != ''">
  654. AND s.name like concat('%', #{shopName} ,'%')
  655. </if>
  656. <if test="buyer != null and buyer != ''">
  657. AND bou.name like concat('%', #{buyer} ,'%')
  658. </if>
  659. <if test="clubName != null and clubName != ''">
  660. AND c.name like concat('%', #{clubName} ,'%')
  661. </if>
  662. <if test="shopOrderIDs != null and shopOrderIDs != ''">
  663. AND cso.shopOrderID = #{shopOrderIDs}
  664. </if>
  665. <if test="shopOrderNo != null and shopOrderNo != ''">
  666. AND cso.shopOrderNo like concat('%', #{shopOrderNo} ,'%')
  667. </if>
  668. <if test="ps != null and ps.length>0 ">
  669. AND co.payStatus IN
  670. <foreach item="item" index="index" collection="ps" open="(" close=")" separator=",">
  671. #{item}
  672. </foreach>
  673. </if>
  674. <if test="receiptStatus != null and receiptStatus!= ''">
  675. AND receiptStatus = #{receiptStatus}
  676. </if>
  677. <if test="refundType !=null and refundType != ''">
  678. <if test="refundType == 1 or refundType == 2">
  679. AND refundType = #{refundType}
  680. </if>
  681. <if test="refundType == 0">
  682. AND refundType NOT IN (1,2)
  683. </if>
  684. </if>
  685. <if test="rebateOrder != null and rebateOrder !=''">
  686. <if test="rebateOrder == 0">
  687. AND cso.shopOrderID NOT IN (
  688. SELECT orderID FROM cm_receipt_order_relation
  689. WHERE relationType = '1' AND delFlag = '0' AND orderID IS NOT NULL)
  690. </if>
  691. <if test="rebateOrder == 1">
  692. AND cso.shopOrderID IN (
  693. SELECT orderID FROM cm_receipt_order_relation
  694. WHERE relationType = '1' AND delFlag = '0' AND orderID IS NOT NULL)
  695. </if>
  696. </if>
  697. AND co.delFlag = '0'
  698. AND cso.delFlag = '0'
  699. </where>
  700. GROUP BY co.orderID
  701. ORDER BY co.orderID DESC
  702. </select>
  703. <select id="findPaidOrderID" resultType="Double">
  704. SELECT SUM(payAmount)
  705. FROM cm_pay_shop_record cosr
  706. LEFT JOIN cm_shop_order cso ON cosr.shopOrderID = cso.shopOrderID
  707. WHERE cso.orderID = #{orderID}
  708. AND cosr.delFlag = '0'
  709. AND cosr.status = '1'
  710. AND cosr.paymentType IN (1, 2)
  711. GROUP BY cso.orderID
  712. </select>
  713. <select id="findPromotionsByIds" resultType="com.caimei.modules.product.entity.CmPromotion">
  714. select * from cm_promotions
  715. where id in
  716. <foreach collection="promotionsIds" item="promotionsId" index="index" open="(" separator="," close=")">
  717. #{promotionsId}
  718. </foreach>
  719. </select>
  720. <select id="getDbPromotionsByOrderId" resultType="com.caimei.modules.product.entity.CmPromotion">
  721. select *
  722. from cm_promotions_order
  723. where promotionsId = #{promotionsId}
  724. and orderId = #{orderId}
  725. </select>
  726. <select id="findServiceProviderList" resultType="com.caimei.modules.user.entity.NewCmSp">
  727. select s.serviceProviderID, s.linkMan
  728. from serviceprovider s
  729. join user u on s.userID = u.userID
  730. where s.status = 90
  731. and s.serviceProviderID != 1342
  732. </select>
  733. <insert id="insertPromotionsRecord" parameterType="com.caimei.modules.product.entity.CmPromotion" keyProperty="id"
  734. useGeneratedKeys="true">
  735. INSERT INTO cm_promotions_order(orderId,
  736. promotionsId,
  737. name,
  738. description,
  739. type,
  740. mode,
  741. touchPrice,
  742. reducedPrice,
  743. discount,
  744. status,
  745. beginTime,
  746. endTime)
  747. VALUES (#{orderId},
  748. #{promotionsId},
  749. #{name},
  750. #{description},
  751. #{type},
  752. #{mode},
  753. #{touchPrice},
  754. #{reducedPrice},
  755. #{discount},
  756. #{status},
  757. #{beginTime},
  758. #{endTime})
  759. </insert>
  760. <update id="updatePromotionsRecord">
  761. update cm_promotions_order
  762. <set>
  763. <if test="orderId != null and orderId !=''">
  764. orderId = #{orderId},
  765. </if>
  766. <if test="promotionsId != null and promotionsId !=''">
  767. promotionsId = #{promotionsId},
  768. </if>
  769. <if test="name != null and name !=''">
  770. name = #{name},
  771. </if>
  772. <if test="description != null and description !=''">
  773. description = #{description},
  774. </if>
  775. <if test="type != null and type !=''">
  776. type = #{type},
  777. </if>
  778. <if test="mode != null and mode !=''">
  779. mode = #{mode},
  780. </if>
  781. <if test="touchPrice != null and touchPrice !=''">
  782. touchPrice = #{touchPrice},
  783. </if>
  784. <if test="reducedPrice != null and reducedPrice !=''">
  785. reducedPrice = #{reducedPrice},
  786. </if>
  787. <if test="status != null and status !=''">
  788. status = #{status},
  789. </if>
  790. <if test="beginTime != null and beginTime !=''">
  791. beginTime = #{beginTime},
  792. </if>
  793. <if test="endTime != null and endTime !=''">
  794. endTime = #{endTime}
  795. </if>
  796. </set>
  797. where id = #{id}
  798. </update>
  799. <update id="updatePayAndReceipt">
  800. update cm_order
  801. set status = concat('3', sendOutStatus),
  802. payStatus= 3,
  803. receiptStatus= 3
  804. where orderID = #{orderId}
  805. </update>
  806. <update id="updateOrderStatus">
  807. update cm_order
  808. set payStatus = #{payStatus},
  809. zeroCostFlag = #{zeroCostFlag}
  810. where orderID = #{orderID}
  811. </update>
  812. <delete id="deleterPomotionsOrder">
  813. DELETE
  814. FROM cm_promotions_order
  815. WHERE orderId = #{orderId}
  816. </delete>
  817. <update id="updateByRebateFlag">
  818. UPDATE cm_order
  819. SET rebateFlag = 1
  820. WHERE orderID = #{orderId}
  821. </update>
  822. <select id="findQualificationFile" resultType="com.caimei.modules.order.entity.CmFile">
  823. SELECT fileName,
  824. ossName
  825. FROM cm_qualification_file
  826. WHERE recordId = #{recordId}
  827. </select>
  828. <select id="findQualificationImage" resultType="string">
  829. SELECT image
  830. FROM cm_qualification_image
  831. WHERE recordId = #{recordId}
  832. ORDER BY id
  833. </select>
  834. <delete id="deleteQualificationImage">
  835. DELETE
  836. FROM cm_qualification_image
  837. WHERE recordId = #{recordId}
  838. </delete>
  839. <insert id="insertQualificationImage">
  840. INSERT INTO `cm_qualification_image` (`recordId`, `image`)
  841. VALUES (#{recordId}, #{image});
  842. </insert>
  843. <delete id="deleteQualificationFile">
  844. DELETE
  845. FROM cm_qualification_file
  846. WHERE recordId = #{recordId}
  847. </delete>
  848. <insert id="insertQualificationFile">
  849. INSERT INTO `cm_qualification_file` (`recordId`, `fileName`, `ossName`)
  850. VALUES (#{recordId}, #{fileName}, #{ossName})
  851. </insert>
  852. <select id="findBYShortLink" resultType="integer">
  853. SELECT id
  854. FROM cm_short_link
  855. WHERE shortLink = #{shortLink}
  856. </select>
  857. <select id="getDepositOrderProductId" resultType="java.lang.Integer">
  858. SELECT productID
  859. FROM cm_order_product
  860. WHERE orderID = #{orderID}
  861. LIMIT 1
  862. </select>
  863. <insert id="insertShortLink">
  864. INSERT INTO cm_short_link (`markId`, `shortLink`, `jumpLink`,
  865. `createTime`)
  866. VALUES (#{markId}, #{shortLink}, #{url},
  867. NOW())
  868. </insert>
  869. <update id="updateSendNum">
  870. UPDATE cm_sms_statistics
  871. SET sendNum = (sendNum + #{num})
  872. WHERE markId = #{markId}
  873. </update>
  874. <update id="updateUserMoneyByUserId">
  875. UPDATE USER
  876. SET userMoney=(userMoney - #{payTotalFee}),
  877. ableUserMoney = (ableUserMoney - #{payTotalFee})
  878. WHERE userID = #{userID}
  879. </update>
  880. <select id="findOrderCouponRecord" resultType="com.caimei.modules.coupon.entity.CmCouponOrderRecord">
  881. SELECT `id`,
  882. `orderId`,
  883. `clubCouponId`,
  884. `couponType`,
  885. `couponAmount`,
  886. `touchPrice`,
  887. `createDate`
  888. FROM cm_coupon_order_record
  889. WHERE orderId = #{orderID}
  890. </select>
  891. <select id="findClubCouponById" resultType="com.caimei.modules.coupon.entity.CmCoupon">
  892. SELECT cc.`id`,
  893. cc.`couponAmount`,
  894. cc.`touchPrice`,
  895. cc.`couponType`,
  896. cc.`userId`,
  897. cc.`shopId`,
  898. cc.`productType`,
  899. cc.`categoryType`,
  900. cc.`couponsMode`
  901. FROM cm_coupon_club a
  902. LEFT JOIN cm_coupon cc ON a.couponId = cc.id
  903. WHERE a.id = #{clubCouponId}
  904. AND a.status = 1
  905. </select>
  906. <insert id="insertCouponOrderRecord">
  907. INSERT INTO `cm_coupon_order_record` (`orderId`,
  908. `clubCouponId`,
  909. `couponType`,
  910. `couponAmount`,
  911. `touchPrice`,
  912. `createDate`)
  913. VALUES (#{orderId},
  914. #{clubCouponId},
  915. #{couponType},
  916. #{couponAmount},
  917. #{touchPrice},
  918. #{createDate})
  919. </insert>
  920. <update id="updateCouponOrderRecord">
  921. UPDATE
  922. `cm_coupon_order_record`
  923. SET `clubCouponId` = #{clubCouponId},
  924. `couponType` = #{couponType},
  925. `couponAmount` = #{couponAmount},
  926. `touchPrice` = #{touchPrice}
  927. WHERE orderId = #{orderId}
  928. </update>
  929. <update id="updatePayStatusSon">
  930. UPDATE cm_shop_order
  931. SET payStatus=3
  932. WHERE orderID = #{orderId}
  933. </update>
  934. <update id="updateOnlinePayFlag">
  935. update cm_order set onlinePayFlag = #{onlinePayFlag} where orderID = #{orderId}
  936. </update>
  937. <update id="updateShopOrderByPayStatus">
  938. UPDATE cm_shop_order SET
  939. payStatus = #{payStatus}, payedShopAmount = #{paidShop}
  940. WHERE shopOrderID = #{shopOrderId}
  941. </update>
  942. <update id="updateOrderByPayStatus">
  943. UPDATE cm_order SET
  944. payStatus = #{payStatus}
  945. WHERE orderID = #{orderId}
  946. </update>
  947. <update id="updateBySplitStatus">
  948. UPDATE cm_receipt_order_relation SET splitStatus = 1 WHERE mbOrderId = #{mbOrderId}
  949. </update>
  950. <update id="updateSettleStatus">
  951. update cm_split_account
  952. set settleStatus = 1
  953. where shopOrderId = #{shopOrderId}
  954. and productType = #{productType}
  955. </update>
  956. <update id="updateShopOrderSettleStatus">
  957. update cm_shop_order set settleStatus = #{settleStatus}
  958. where shopOrderId = #{shopOrderId}
  959. </update>
  960. <delete id="deleteCouponOrderRecord">
  961. DELETE
  962. FROM cm_coupon_order_record
  963. WHERE id = #{id}
  964. </delete>
  965. <select id="getUndividedPaidReceipt" resultType="com.caimei.modules.order.entity.OrderReceiptRelationPo">
  966. SELECT cror.id,
  967. cror.relationType,
  968. cror.receiptId,
  969. cror.associateAmount,
  970. cror.orderId,
  971. cror.delFlag,
  972. cror.mbOrderId,
  973. cror.orderRequestNo,
  974. cror.splitStatus,
  975. cror.shopOrderId,
  976. cdr.payType
  977. FROM cm_receipt_order_relation cror
  978. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  979. LEFT JOIN cm_order co ON cror.orderID = co.orderID
  980. WHERE cror.relationType = 2
  981. AND a.receiptStatus=3
  982. AND cror.delFlag = 0
  983. AND cror.mbOrderId IS NOT NULL
  984. AND cror.splitStatus = 0
  985. AND cdr.payWay = 1
  986. AND cdr.receiptDate <![CDATA[ <= ]]> #{currentTime}
  987. AND co.organizeID = 0
  988. AND co.orderType != 2
  989. AND co.refundType != 2
  990. </select>
  991. <select id="getOnlineBalance" resultType="com.caimei.modules.order.entity.OrderReceiptRelationPo">
  992. SELECT DISTINCT cror.id,
  993. cror.relationType,
  994. cror.receiptId,
  995. cror.associateAmount,
  996. cror.orderId,
  997. cror.delFlag,
  998. cror.mbOrderId,
  999. cror.orderRequestNo,
  1000. cror.splitStatus,
  1001. cdr.payType
  1002. FROM cm_receipt_order_relation cror
  1003. LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
  1004. LEFT JOIN cm_order co ON cror.orderID = co.orderID
  1005. LEFT JOIN cm_user_balance_record cubr ON cubr.orderId = cror.orderID
  1006. WHERE cror.relationType = 2
  1007. AND cror.delFlag = 0
  1008. AND cror.splitStatus = 0
  1009. AND cdr.delFlag = 0
  1010. AND cdr.payWay = 3
  1011. AND cdr.receiptDate <![CDATA[ <= ]]> #{currentTime}
  1012. AND co.organizeID = 0
  1013. AND co.orderType != 2
  1014. AND co.refundType != 2
  1015. AND cubr.balanceType = 10
  1016. AND cror.associateAmount > 0.01
  1017. </select>
  1018. <select id="getOrderProductByOrderId" resultType="com.caimei.modules.order.entity.OrderProductVo">
  1019. SELECT cop.orderProductID AS orderProductId,
  1020. cop.orderID AS orderId,
  1021. cop.orderNo,
  1022. cop.shopOrderID AS shopOrderId,
  1023. cop.shopOrderNo,
  1024. cop.orderPromotionsId,
  1025. cop.productId,
  1026. cop.shopId,
  1027. cop.name,
  1028. cop.productImage AS image,
  1029. cop.price,
  1030. cop.shopName,
  1031. IF(cop.shopid = 998 AND co.freight > 0, co.freight, cop.costPrice) AS costPrice,
  1032. cop.normalPrice,
  1033. cop.ladderPriceFlag,
  1034. cop.discountPrice,
  1035. cop.discount,
  1036. cop.totalAmount,
  1037. cop.totalFee,
  1038. cop.shouldPayFee,
  1039. cop.productUnit,
  1040. cop.num,
  1041. cop.presentNum,
  1042. cop.discountFee,
  1043. cop.includedTax,
  1044. cop.invoiceType,
  1045. cop.taxRate,
  1046. cop.addedValueTax,
  1047. cop.totalAddedValueTax,
  1048. cop.singleShouldPayTotalTax,
  1049. cop.shouldPayTotalTax,
  1050. cop.shopProductAmount,
  1051. cop.singleShopFee,
  1052. cop.shopFee,
  1053. cop.singleOtherFee,
  1054. cop.otherFee,
  1055. cop.singleCmFee,
  1056. cop.cmFee,
  1057. cop.payStatus,
  1058. cop.buyAgainFlag,
  1059. cop.notOutStore,
  1060. cop.isActProduct AS actProduct,
  1061. cop.productType,
  1062. p.productCategory as productCategory,
  1063. p.splitCode
  1064. FROM cm_order_product cop
  1065. LEFT JOIN product p ON cop.productID = p.productID
  1066. LEFT JOIN cm_order co ON cop.orderId = co.orderId
  1067. WHERE co.orderID = #{orderId}
  1068. AND IF(co.userBeans = 0, 1 = 1, cop.shopid != 998)
  1069. ORDER BY cop.discountPrice DESC
  1070. </select>
  1071. <select id="getOrderProductPaidAmount" resultType="java.lang.Double">
  1072. SELECT SUM(splitAccount)
  1073. FROM cm_split_account
  1074. WHERE orderProductId = #{orderProductId}
  1075. AND payStatus = 1
  1076. AND productType = 1
  1077. </select>
  1078. <select id="getShopOrderListByOrderId" resultType="com.caimei.modules.order.entity.ShopOrderVo">
  1079. SELECT shopOrderID AS shopOrderId,
  1080. shopOrderNo,
  1081. orderID AS orderId,
  1082. orderNo,
  1083. shopID AS shopId,
  1084. note,
  1085. userID AS userId,
  1086. clubID AS clubId,
  1087. spID AS spId,
  1088. orderPromotionsId,
  1089. promotionFullReduction,
  1090. brokerage,
  1091. canRefundAmount,
  1092. itemCount,
  1093. totalAmount,
  1094. productAmount,
  1095. needPayAmount,
  1096. shopProductAmount,
  1097. shopPostFee,
  1098. shopTaxFee,
  1099. shouldPayShopAmount,
  1100. orderTime,
  1101. orderSubmitType,
  1102. payStatus,
  1103. sendOutStatus,
  1104. splitFlag,
  1105. splitCode
  1106. FROM cm_shop_order
  1107. WHERE delFlag = 0
  1108. AND shopOrderID = #{shopOrderId}
  1109. </select>
  1110. <select id="getPaidShipping" resultType="java.lang.Double">
  1111. SELECT SUM(splitAccount)
  1112. FROM cm_split_account
  1113. WHERE orderId = #{orderId}
  1114. AND shopId = #{shopId}
  1115. AND productType = 2
  1116. AND payStatus = 1
  1117. </select>
  1118. <select id="getShopCommercialCode" resultType="java.lang.String">
  1119. SELECT commercialCode
  1120. FROM cm_shop_splitcode
  1121. WHERE shopID = #{shopId}
  1122. limit 1
  1123. </select>
  1124. <select id="getOrderByOrderId" resultType="com.caimei.modules.order.entity.OrderVo">
  1125. SELECT orderID AS orderId,
  1126. shopOrderIds,
  1127. orderSource,
  1128. orderNo,
  1129. organizeID AS organizeId,
  1130. userID AS userId,
  1131. clubID AS clubId,
  1132. buyUserID AS buyUserId,
  1133. orderTime AS orderTime,
  1134. updateDate AS updateDate,
  1135. delFlag,
  1136. userBeans,
  1137. orderType,
  1138. orderSubmitType,
  1139. confirmFlag,
  1140. onlinePayFlag,
  1141. splitFlag,
  1142. payFlag,
  1143. receiptStatus,
  1144. payStatus,
  1145. zeroCostFlag,
  1146. sendOutStatus,
  1147. refundType,
  1148. affirmPaymentFlag,
  1149. productCount,
  1150. presentCount,
  1151. promotionalGiftsCount,
  1152. hasActProduct,
  1153. promotionFullReduction,
  1154. secondHandOrderFlag,
  1155. invoiceFlag,
  1156. freePostFlag AS postageFlag,
  1157. freight AS postage,
  1158. productTotalFee,
  1159. orderTotalFee,
  1160. payTotalFee,
  1161. payableAmount,
  1162. balancePayFee,
  1163. discountFee,
  1164. status,
  1165. paySuccessCounter,
  1166. confirmTime,
  1167. payTime,
  1168. rebateFlag,
  1169. clauseID AS clauseId,
  1170. clauseName
  1171. FROM cm_order
  1172. WHERE orderID = #{orderId}
  1173. </select>
  1174. <select id="findSplitTime" resultType="java.util.Date">
  1175. SELECT splitTime
  1176. FROM cm_split_account
  1177. WHERE splitTime IS NOT NULL
  1178. AND splitTime > DATE_ADD(NOW(), INTERVAL -2 MINUTE)
  1179. LIMIT 1
  1180. </select>
  1181. <select id="findSupport" resultType="java.lang.Integer">
  1182. SELECT s.chargeSupport FROM shop s
  1183. LEFT JOIN cm_shop_order cso ON cso.shopId= s.shopId
  1184. WHERE cso.shopOrderId=25059
  1185. </select>
  1186. <select id="getOrderProductByShopOrderId" resultType="com.caimei.modules.order.entity.OrderProductVo">
  1187. SELECT cop.orderProductID AS orderProductId,
  1188. cop.orderID AS orderId,
  1189. cop.orderNo,
  1190. cop.shopOrderID AS shopOrderId,
  1191. cop.shopOrderNo,
  1192. cop.orderPromotionsId,
  1193. cop.productId,
  1194. cop.shopId,
  1195. cop.name,
  1196. cop.productImage AS image,
  1197. cop.price,
  1198. cop.shopName,
  1199. IF(cop.shopid = 998 AND co.freight > 0, co.freight, cop.costPrice) AS costPrice,
  1200. cop.normalPrice,
  1201. cop.ladderPriceFlag,
  1202. cop.discountPrice,
  1203. cop.discount,
  1204. cop.totalAmount,
  1205. cop.totalFee,
  1206. cop.shouldPayFee,
  1207. cop.productUnit,
  1208. cop.num,
  1209. cop.presentNum,
  1210. cop.discountFee,
  1211. cop.includedTax,
  1212. cop.invoiceType,
  1213. cop.taxRate,
  1214. cop.addedValueTax,
  1215. cop.totalAddedValueTax,
  1216. cop.singleShouldPayTotalTax,
  1217. cop.shouldPayTotalTax,
  1218. cop.shopProductAmount,
  1219. cop.singleShopFee,
  1220. cop.shopFee,
  1221. cop.singleOtherFee,
  1222. cop.otherFee,
  1223. cop.singleCmFee,
  1224. cop.cmFee,
  1225. cop.payStatus,
  1226. cop.buyAgainFlag,
  1227. cop.notOutStore,
  1228. cop.isActProduct AS actProduct,
  1229. cop.productType,
  1230. p.productCategory as productCategory,
  1231. p.splitCode
  1232. FROM cm_order_product cop
  1233. LEFT JOIN product p ON cop.productID = p.productID
  1234. left join cm_order co on co.orderID = cop.orderID
  1235. WHERE cop.shopOrderID = #{shopOrderId}
  1236. AND IF(co.userBeans = 0, 1 = 1, cop.shopid != 998)
  1237. ORDER BY cop.discountPrice DESC
  1238. </select>
  1239. <select id="getShopOrderByOrderId" resultType="com.caimei.modules.order.entity.ShopOrderVo">
  1240. SELECT shopOrderID AS shopOrderId,
  1241. shopOrderNo,
  1242. orderID AS orderId,
  1243. orderNo,
  1244. shopID AS shopId,
  1245. note,
  1246. userID AS userId,
  1247. clubID AS clubId,
  1248. spID AS spId,
  1249. orderPromotionsId,
  1250. promotionFullReduction,
  1251. brokerage,
  1252. canRefundAmount,
  1253. itemCount,
  1254. totalAmount,
  1255. productAmount,
  1256. needPayAmount,
  1257. shopProductAmount,
  1258. shopPostFee,
  1259. shopTaxFee,
  1260. shouldPayShopAmount,
  1261. orderTime,
  1262. orderSubmitType,
  1263. payStatus,
  1264. sendOutStatus,
  1265. splitFlag,
  1266. splitCode
  1267. FROM cm_shop_order
  1268. WHERE delFlag = 0
  1269. AND orderID = #{orderId}
  1270. </select>
  1271. <select id="getSplitAccountList" resultType="com.caimei.modules.order.entity.SplitAccountPo">
  1272. SELECT
  1273. id,
  1274. orderId,
  1275. productId,
  1276. orderProductId,
  1277. shopId,
  1278. type,
  1279. subUserNo,
  1280. SUM(splitAccount) AS splitAccount,
  1281. mbOrderId,
  1282. orderRequestNo,
  1283. payStatus,
  1284. productType
  1285. FROM cm_split_account
  1286. WHERE type = 4 AND payStatus = 1 AND splitAccount > 0
  1287. AND mbOrderId = #{mbOrderId}
  1288. GROUP BY shopId
  1289. </select>
  1290. <select id="getPaidShopAmount" resultType="java.lang.Double">
  1291. SELECT SUM(payAmount)
  1292. FROM cm_pay_shop_record
  1293. WHERE STATUS = 1 AND delFlag = 0 AND shopOrderID = #{shopOrderId}
  1294. </select>
  1295. <select id="findOnlinePay" resultType="java.lang.Integer">
  1296. SELECT COUNT(*) FROM
  1297. cm_receipt_order_relation cror
  1298. LEFT JOIN cm_discern_receipt cdr ON cdr.id = receiptID
  1299. LEFT JOIN cm_order co ON cror.orderId = co.orderId
  1300. WHERE cdr.payWay=1
  1301. AND co.orderType != 2
  1302. AND cror.orderID=#{orderID}
  1303. </select>
  1304. <select id="findSplitCode" resultType="java.lang.String">
  1305. select splitCode from cm_shop_order where shopOrderID = #{shopOrderId}
  1306. </select>
  1307. <select id="findPayAmount" resultType="java.lang.Double">
  1308. SELECT SUM(splitAccount) FROM cm_split_account csa
  1309. LEFT JOIN cm_receipt_order_relation cror ON csa.shopOrderId=cror.shopOrderId
  1310. WHERE csa.shopOrderId = #{shopOrderId}
  1311. AND csa.type=5
  1312. AND csa.settleStatus = 0
  1313. AND csa.productType = 3
  1314. AND cror.splitStatus =1
  1315. AND cror.delflag=0
  1316. </select>
  1317. <select id="findShouldPayShopAmount" resultType="java.lang.Double">
  1318. select shouldPayShopAmount from cm_shop_order where shopOrderID = #{shopOrderId}
  1319. </select>
  1320. <select id="findSettleSum" resultType="java.lang.Double">
  1321. SELECT IFNULL(SUM(settleAmount),0) FROM cm_settle_record
  1322. WHERE settleType = 1
  1323. AND shopOrderId = 24665
  1324. </select>
  1325. <select id="findSettleRecord" resultType="com.caimei.modules.order.entity.SettleRecord">
  1326. select distinct
  1327. csr.settleAmount,csr.shopOrderId,csr.settleTime from cm_settle_record csr
  1328. left join cm_shop_order cso on csr.shopOrderId = cso.shopOrderID
  1329. where cso.orderID=#{orderID}
  1330. and settleType = 2
  1331. </select>
  1332. <select id="findSettleAmount" resultType="java.lang.Double">
  1333. SELECT ifnull(SUM(settleAmount),0)
  1334. FROM cm_settle_record csr
  1335. LEFT JOIN cm_shop_order cso ON csr.shopOrderId = cso.shopOrderId
  1336. WHERE settleType=1
  1337. AND cso.orderId=#{orderID}
  1338. </select>
  1339. <select id="findShopOrderSize" resultType="java.lang.Integer">
  1340. SELECT COUNT(*) FROM cm_shop_order WHERE orderId=#{orderID}
  1341. AND shopId!=998
  1342. </select>
  1343. <insert id="insertSplitAccount">
  1344. INSERT INTO cm_split_account (orderId, productId, orderProductId, shopId, couponRecordId, vipRecordId,
  1345. authVipRecordId, type, subUserNo, splitAccount,
  1346. mbOrderId, orderRequestNo, payStatus, productType, shopOrderId ,splitTime)
  1347. VALUES (#{orderId}, #{productId}, #{orderProductId}, #{shopId}, #{couponRecordId}, #{vipRecordId},
  1348. #{authVipRecordId}, #{type}, #{subUserNo}, #{splitAccount},
  1349. #{mbOrderId}, #{orderRequestNo}, #{payStatus}, #{productType},#{shopOrderId}, NOW());
  1350. </insert>
  1351. <insert id="insertPayShop" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
  1352. INSERT INTO cm_pay_shop (shopID, name, bankAccountName, bankAccount, bankName, type, totalAmount, balancePayFee,
  1353. transferPayFee, payType, wipePayment, wipeRemarks, wipeRemarkImages, wipeTime, applicant,
  1354. applyTime, reviewer, reviewTime, payTime, status, reason, delFlag)
  1355. VALUES (#{shopId}, #{name}, #{bankAccountName}, #{bankAccount}, #{bankName}, #{type}, #{totalAmount}, #{balancePayFee},
  1356. #{transferPayFee}, #{payType}, #{wipePayment}, #{wipeRemarks}, #{wipeRemarkImages}, #{wipeTime}, #{applicant},
  1357. #{applyTime}, #{reviewer}, #{reviewTime}, #{payTime}, #{status}, #{reason}, #{delFlag})
  1358. </insert>
  1359. <insert id="insertPayShopRecord" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
  1360. INSERT INTO cm_pay_shop_record (shopID, shopOrderID, shopOrderNo, payAmount, wipePayment, payType, payTime, payShopID, status, delFlag)
  1361. VALUES (#{shopId}, #{shopOrderId}, #{shopOrderNo}, #{payAmount}, #{wipePayment}, #{payType}, #{payTime}, #{payShopId}, #{status}, #{delFlag})
  1362. </insert>
  1363. <insert id="insertSettleRecord">
  1364. INSERT INTO cm_settle_record(settleamount, settletype, shoporderid, splitcode, settletime)
  1365. VALUES (#{settleAmount},#{settleType},#{shopOrderId},#{splitCode},now())
  1366. </insert>
  1367. <update id="updateBrokerage">
  1368. UPDATE cm_shop_order SET
  1369. brokerage = #{brokerage}
  1370. WHERE shopOrderID = #{shopOrderID}
  1371. </update>
  1372. </mapper>