OrderMapper.xml 58 KB

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