OrderMapper.xml 55 KB

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