HeHeNewOrderMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.caimei.modules.hehe.dao.HeHeNewOrderDao">
  6. <sql id="columns">
  7. a.orderID AS orderID,
  8. a.orderNo AS orderNo,
  9. a.organizeID AS organizeID,
  10. a.userID AS userID,
  11. a.buyUserID AS buyUserID,
  12. a.shopOrderIDs AS shopOrderIDs,
  13. a.orderSubmitType AS orderSubmitType,
  14. a.orderType AS orderType,
  15. a.secondHandOrderFlag AS secondHandOrderFlag,
  16. a.status AS status,
  17. a.productTotalFee AS productTotalFee,
  18. a.orderTotalFee AS orderTotalFee,
  19. a.payTotalFee AS payTotalFee,
  20. a.payableAmount AS payableAmount,
  21. a.balancePayFee AS balancePayFee ,
  22. a.discountFee AS discountFee,
  23. a.spID AS spID,
  24. a.mainSpID AS mainSpID,
  25. a.note AS note,
  26. a.clubID AS clubID,
  27. a.clubScanTime AS clubScanTime,
  28. a.orderSource AS orderSource,
  29. a.orderTime AS orderTime,
  30. a.confirmTime AS confirmTime,
  31. a.productCount AS productCount,
  32. a.presentCount AS presentCount,
  33. a.confirmFlag AS confirmFlag,
  34. a.clauseID AS clauseID,
  35. a.clauseContent AS clauseContent,
  36. a.clauseName AS clauseName,
  37. a.updateDate AS updateDate,
  38. a.freePostFlag AS freePostFlag,
  39. a.freight AS freight,
  40. a.delFlag AS delFlag,
  41. a.onlinePayFlag 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.couponAmount,
  58. a.reductionAmount,
  59. if(chcm.id is not null,1,0) as collageFlag,
  60. chc.status as collageStatus
  61. </sql>
  62. <select id="get" resultType="newOrder">
  63. SELECT <include refid="columns"/>
  64. FROM cm_order a
  65. LEFT JOIN cm_hehe_collage_member chcm on a.orderID = chcm.orderId
  66. LEFT JOIN cm_hehe_collage chc on chcm.collageId = chc.id
  67. WHERE a.orderID = #{id}
  68. </select>
  69. <resultMap id="orderDisplayList" type="com.caimei.modules.order.entity.NewOrder">
  70. <id column="orderID" property="orderID"/>
  71. <result column="orderNo" property="orderNo"/>
  72. <result column="organizeID" property="organizeID"/>
  73. <result column="orderType" property="orderType"/>
  74. <result column="shopName" property="shopName"/>
  75. <result column="receiver" property="receiver"/>
  76. <result column="buyer" property="buyer"/>
  77. <result column="orderSource" property="orderSource"/>
  78. <result column="orderTotalFee" property="orderTotalFee"/>
  79. <result column="orderTime" property="orderTime"/>
  80. <result column="productCount" property="productCount"/>
  81. <result column="alreadyReceipt" property="alreadyReceipt"/>
  82. <result column="unReceipt" property="unReceipt"/>
  83. <result column="payTotalFee" property="payTotalFee"/>
  84. <result column="status" property="status"/>
  85. <collection property="newShopOrders" ofType="com.caimei.modules.order.entity.NewShopOrder"
  86. select="loadShopOrders" column="orderNo" fetchType="eager">
  87. </collection>
  88. </resultMap>
  89. <select id="findList" resultMap="orderDisplayList" parameterType="com.caimei.modules.order.entity.NewOrder">
  90. SELECT DISTINCT
  91. co.orderID AS orderID,
  92. co.orderNo AS orderNo,
  93. co.organizeID AS organizeID,
  94. co.userID AS userID,
  95. co.orderType AS orderType,
  96. co.secondHandOrderFlag AS secondHandOrderFlag,
  97. co.onlinePayFlag AS onlinePayFlag,
  98. bou.shouHuoRen AS receiver,
  99. IFNULL(c.name,c.nickName) AS buyer,
  100. co.orderSource AS orderSource,
  101. co.orderTotalFee AS orderTotalFee,
  102. co.payableAmount AS payableAmount,
  103. co.orderTime AS orderTime,
  104. co.confirmTime AS confirmTime,
  105. co.payTotalFee AS payTotalFee,
  106. co.payStatus AS payStatus,
  107. co.refundType AS refundType,
  108. co.sendOutStatus AS sendOutStatus,
  109. co.receiptStatus AS receiptStatus,
  110. co.productCount AS productCount,
  111. (SELECT IFNULL(sum(cop.shouldPayFee),0) FROM cm_order_product cop WHERE cop.orderId=co.orderID) AS
  112. "shouldPayProduct",
  113. co.status AS status,
  114. co.splitFlag AS splitFlag,
  115. co.postageOrderFlag AS postageOrderFlag,
  116. (case when co.orderType = '0' then
  117. (select case status when 91 then '采美默认协销经理(官方账号)' else linkMan end from serviceprovider where serviceProviderID
  118. = co.spID)
  119. else
  120. ''
  121. end) AS spName,
  122. co.rebateFlag AS rebateFlag,
  123. if(chcm.id is not null,1,0) as collageFlag,
  124. chc.status as collageStatus
  125. FROM cm_order co
  126. LEFT JOIN bp_order_userinfo bou ON bou.orderId = co.orderID
  127. LEFT JOIN user u ON u.userID = co.userID
  128. LEFT JOIN cm_hehe_user c ON u.userID = c.userId
  129. LEFT JOIN cm_order_product cop ON co.orderID = cop.orderID
  130. LEFT JOIN product p ON cop.productID = p.productID
  131. LEFT JOIN cm_hehe_collage_member chcm on co.orderID = chcm.orderId
  132. LEFT JOIN cm_hehe_collage chc on chcm.collageId = chc.id
  133. <where>
  134. co.orderType = 2
  135. <if test="orderID != null and orderID != ''">
  136. AND co.orderID = #{orderID}
  137. </if>
  138. <if test="orderNo != null and orderNo != ''">
  139. AND co.orderNo = #{orderNo}
  140. </if>
  141. <if test="status != null and status != ''">
  142. <choose>
  143. <when test="status == '99'.toString()">
  144. AND co.status in (11,12,13,21,22,23,31,32,33)
  145. </when>
  146. <otherwise>
  147. AND co.status = #{status}
  148. </otherwise>
  149. </choose>
  150. </if>
  151. <if test="buyer != null and buyer != ''">
  152. AND (c.name LIKE concat('%',#{buyer},'%') or c.nickName LIKE concat('%',#{buyer},'%'))
  153. </if>
  154. <if test="orderTime != null and orderTime != ''">
  155. AND co.orderTime = #{orderTime}
  156. </if>
  157. <if test="sendOutStatus != null and sendOutStatus != ''">
  158. AND co.sendOutStatus = #{sendOutStatus}
  159. </if>
  160. <if test="startTime != null and startTime != ''">
  161. AND co.orderTime <![CDATA[ >= ]]> #{startTime}
  162. </if>
  163. <if test="endTime != null and endTime != ''">
  164. AND co.orderTime <![CDATA[ <= ]]> #{endTime}
  165. </if>
  166. <if test="receiver != null and receiver != ''">
  167. AND bou.shouHuoRen LIKE concat('%',#{receiver},'%')
  168. </if>
  169. <if test="receiptStatus != null and receiptStatus != ''">
  170. AND co.receiptStatus = #{receiptStatus}
  171. </if>
  172. <if test="payStatus != null and payStatus != ''">
  173. AND co.payStatus = #{payStatus}
  174. </if>
  175. <if test="sendOutStatus != null and sendOutStatus != ''">
  176. AND co.sendOutStatus = #{sendOutStatus}
  177. </if>
  178. <if test="returnedPurchaseStatus != null and returnedPurchaseStatus != ''">
  179. AND
  180. <if test="returnedPurchaseStatus == 1">
  181. exists
  182. </if>
  183. <if test="returnedPurchaseStatus == 0">
  184. not exists
  185. </if>
  186. (select 1 from cm_returned_purchase c3 where c3.status = '1' and c3.orderID = co.orderID and c3.delFlag = 0)
  187. </if>
  188. <if test="refundType != null and refundType != ''">
  189. AND
  190. <if test="refundType == 0">
  191. co.refundType is null
  192. </if>
  193. <if test="refundType == 1">
  194. co.refundType = '1'
  195. </if>
  196. <if test="refundType == 2">
  197. co.refundType = '2'
  198. </if>
  199. </if>
  200. <if test="orderRefundType != null and orderRefundType != ''">
  201. <if test="orderRefundType == 0">
  202. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.delFlag = 0) = 0
  203. </if>
  204. <if test="orderRefundType == 1">
  205. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.delFlag = 0) > 0
  206. </if>
  207. <if test="orderRefundType == 11">
  208. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 1 and crp.delFlag = 0) > 0
  209. </if>
  210. <if test="orderRefundType == 12">
  211. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 2 and crp.delFlag = 0
  212. <if test="startRefundTime != null and startRefundTime != ''">
  213. AND crp.confirmReturnTime <![CDATA[ >= ]]> #{startRefundTime}
  214. </if>
  215. <if test="endRefundTime != null and endRefundTime != ''">
  216. AND crp.confirmReturnTime <![CDATA[ <= ]]> #{endRefundTime}
  217. </if>
  218. ) > 0
  219. </if>
  220. <if test="orderRefundType == 13">
  221. AND (select count(1) from cm_returned_purchase crp where co.orderID = crp.orderID and crp.status = 3 and crp.delFlag = 0) > 0
  222. </if>
  223. </if>
  224. <if test="collageFlag != null">
  225. <if test="collageFlag == 1">
  226. and chcm.id is not null
  227. </if>
  228. <if test="collageFlag == 0">
  229. and chcm.id is null
  230. </if>
  231. </if>
  232. <if test="collageStatus != null">
  233. and chc.status = #{collageStatus}
  234. </if>
  235. AND co.delFlag = 0
  236. </where>
  237. <choose>
  238. <when test="page !=null and page.orderBy != null and page.orderBy != ''">
  239. ORDER BY ${page.orderBy}
  240. </when>
  241. <otherwise>
  242. ORDER BY co.orderID DESC, co.orderTime DESC
  243. </otherwise>
  244. </choose>
  245. </select>
  246. <select id="loadShopOrders" parameterType="string" resultType="NewShopOrder">
  247. SELECT
  248. cs.shopOrderID AS shopOrderID,
  249. cs.shopOrderNo AS shopOrderNo,
  250. cs.shopOrderNo AS shopOrderNo,
  251. cs.itemCount AS itemCount,
  252. cs.needPayAmount AS needPayAmount,
  253. s.name AS shopName,
  254. cs.shopID AS shopID
  255. FROM cm_shop_order cs
  256. LEFT JOIN shop s ON cs.shopID = s.shopID
  257. WHERE cs.orderNo = #{orderNo} AND cs.delFlag = 0
  258. </select>
  259. <select id="findHeUser" resultType="string">
  260. SELECT IFNULL(name,nickName) FROM cm_hehe_user WHERE userId = #{heUserId}
  261. </select>
  262. <select id="findOrderCouponRecord" resultType="com.caimei.modules.hehe.entity.CmHeheCouponOrderRecord">
  263. SELECT
  264. `id`,
  265. `orderId`,
  266. `receiveCouponId`,
  267. `couponType`,
  268. `couponAmount`,
  269. `touchPrice`,
  270. `createDate`
  271. FROM
  272. cm_hehe_coupon_order_record
  273. WHERE
  274. orderId = #{orderID}
  275. </select>
  276. <select id="findReductionTouchPrice" resultType="java.lang.Double">
  277. select touchPrice from cm_hehe_reduction_user where orderId = #{orderID}
  278. </select>
  279. </mapper>