OrderMapper.xml 55 KB

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