OrderMapper.xml 52 KB

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