NewOrderProductMapper.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.order.dao.NewOrderProductDao">
  6. <sql id="orderProductColumns">
  7. a.`orderProductId` AS `orderProductId`,
  8. a.`orderNo` AS `orderNo`,
  9. a.`orderId` AS `orderId`,
  10. a.`shopOrderId` AS `shopOrderId`,
  11. a.`shopOrderNo` AS `shopOrderNo`,
  12. a.`shopId` AS `shopId`,
  13. a.`productId` AS `productId`,
  14. a.`num` AS `num`,
  15. a.`presentNum` AS `presentNum`,
  16. a.`outStoreType` AS `outStoreType`,
  17. a.`skuId` AS `skuId`,
  18. a.`productNo` AS `productNo`,
  19. a.`price` AS `price`,
  20. a.`normalPrice` AS `normalPrice`,
  21. a.`totalAmount` AS `totalAmount`,
  22. a.`totalFee` AS `totalFee`,
  23. a.`shouldPayFee` AS `shouldPayFee`,
  24. a.`discount` AS `discount`,
  25. a.`discountPrice` AS `discountPrice`,
  26. a.`taxRate` AS `taxRate`,
  27. a.`addedValueTax` AS `addedValueTax`,
  28. a.`totalAddedValueTax` AS `totalAddedValueTax`,
  29. IFNULL(a.`shouldPayTotalTax` ,0) AS `shouldPayTotalTax`,
  30. a.`shopFee` AS `shopFee`,
  31. a.`otherFee` AS `otherFee`,
  32. a.`cmFee` AS `cmFee`,
  33. a.`singleShopFee` AS `singleShopFee`,
  34. a.`singleOtherFee` AS `singleOtherFee`,
  35. a.`singleCmFee` AS `singleCmFee`,
  36. a.`status` AS `status`,
  37. a.`totalBeans` AS `totalBeans`,
  38. a.`useBalanceAmount` AS `useBalanceAmount`,
  39. a.`useBeanAmount` AS `useBeanAmount`,
  40. a.`notOutStore` AS `notOutStore`,
  41. a.`cmbeanPrice` AS `cmbeanPrice`,
  42. a.`isActProduct` AS `isActProduct`,
  43. a.`isGiftProduct` AS `isGiftProduct`,
  44. a.`productActInfo` AS `productActInfo`,
  45. a.`buyAgainFlag` AS `buyAgainFlag`,
  46. a.`confirmProductFlag` AS `confirmProductFlag`,
  47. a.`payStatus` AS `payStatus`,
  48. a.`name` AS `name`,
  49. cs.`unit` AS `unit`,
  50. cs.`organizeId` AS `organizeId`,
  51. a.`actType` AS `actType`,
  52. a.`actPreferential` AS `actPreferential`,
  53. a.`preferential` AS `preferential`,
  54. (select mainImage from product p where p.productId = a.productId) AS image,
  55. a.`discountFee` AS `discountFee`,
  56. a.`productUnit` AS `productUnit`,
  57. a.`productImage` AS `productImage`,
  58. a.`shopName` AS `shopName`,
  59. -- cs.costProportional AS costProportional,
  60. cs.stock AS stock,
  61. (select costCheckFlag from cm_organize_product_info where productId = cs.productId and organizeId = cs.organizeId ) as costCheckFlag,
  62. cs.costPrice AS costPrice,
  63. a.costPrice as newCostPrice,
  64. p.aliasName AS aliasName,
  65. a.singleShouldPayTotalTax AS singleShouldPayTotalTax
  66. </sql>
  67. <sql id="orderProductJoins">
  68. LEFT JOIN product p ON p.productId = a.productId
  69. left join cm_sku cs on a.skuId = cs.skuId and cs.organizeId= 4
  70. </sql>
  71. <select id="get" resultType="com.caimei.modules.order.entity.NewOrderProduct">
  72. SELECT
  73. <include refid="orderProductColumns"/>
  74. FROM cm_order_product a
  75. <include refid="orderProductJoins"/>
  76. WHERE a.orderProductId = #{orderProductId}
  77. </select>
  78. <select id="findListByShopOrderId" resultType="com.caimei.modules.order.entity.NewOrderProduct">
  79. SELECT
  80. <include refid="orderProductColumns"/>
  81. FROM cm_order_product a
  82. <include refid="orderProductJoins"/>
  83. WHERE a.shopOrderId = #{shopOrderId}
  84. </select>
  85. <select id="CountReturnedPurchaseProduct" resultType="java.lang.Integer">
  86. select SUM(crpp.actualReturnedNum) + SUM(crpp.actualCancelNum)
  87. from cm_returned_purchase_product crpp
  88. left join cm_returned_purchase rp on rp.id = crpp.returnedID
  89. where crpp.shopOrderID = #{shopOrderID}
  90. and crpp.orderProductID = #{orderProductID}
  91. and rp.status = '2'
  92. and rp.delFlag = '0'
  93. </select>
  94. <select id="getReturningNum" resultType="Integer">
  95. SELECT
  96. IFNULL(sum(a.actualReturnedNum+a.actualCancelNum),0)
  97. FROM cm_returned_purchase_product a
  98. right join cm_returned_purchase b on a.returnedId = b.id
  99. WHERE a.orderProductId = #{orderProductId}
  100. and b.status = 1
  101. and b.delFlag = 0
  102. </select>
  103. <select id="getReturnedNum" resultType="Integer">
  104. SELECT
  105. IFNULL(sum(a.actualReturnedNum+a.actualCancelNum),0)
  106. FROM cm_returned_purchase_product a
  107. right join cm_returned_purchase b on a.returnedId = b.id
  108. WHERE a.orderProductId = #{orderProductId}
  109. and b.status = 2
  110. and b.delFlag = 0
  111. </select>
  112. <select id="getReceivedNum" resultType="Integer">
  113. SELECT
  114. IFNULL(sum(a.num),0)
  115. FROM cm_logistics_record a
  116. right join cm_logistics_batch b on a.logisticsBatchId = b.id
  117. WHERE a.orderProductId = #{orderProductId}
  118. and b.status = 1
  119. </select>
  120. <select id="findListByOrderId" resultType="com.caimei.modules.order.entity.NewOrderProduct">
  121. SELECT
  122. <include refid="orderProductColumns"/>
  123. ,(SELECT ifnull(SUM(num),0)FROM cm_logistics_record WHERE orderproductId=a.orderproductId) as sendOutNum
  124. FROM cm_order_product a
  125. left join cm_logistics_record clr on a.orderProductId = clr.orderProductId
  126. <include refid="orderProductJoins"/>
  127. WHERE a.orderId = #{orderId}
  128. and clr.id is null
  129. and a.shopId != 998
  130. </select>
  131. <select id="getActualCancelNum" resultType="java.lang.Integer">
  132. select ifnull(SUM(crpp.actualCancelNum),0)
  133. from cm_returned_purchase_product crpp
  134. left join cm_returned_purchase rp on rp.id = crpp.returnedID
  135. where crpp.orderProductID = #{orderProductID}
  136. and rp.status = '2'
  137. and rp.delFlag = '0'
  138. </select>
  139. </mapper>