OrderMapper.xml 55 KB

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