OrderMapper.xml 56 KB

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