CustomGoodsMapper.xml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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.gree.mall.manager.commonmapper.CustomGoodsMapper">
  4. <select id="pageList" resultType="com.gree.mall.manager.bean.goods.GoodsSpecBean">
  5. SELECT
  6. t1.*,
  7. t1.goods_name AS goodsName,
  8. ifnull(t2.share_amount,0) AS shareAmount,
  9. ifnull(t2.share_percent,0) AS sharePercent,
  10. ifnull(t2.inner_share_amount,0) AS innerShareAmount,
  11. ifnull(t2.inner_share_percent,0) AS innerSharePercent,
  12. <!--sum(if(t2.del=0 and t2.sold_num is NOT NULL,t2.sold_num,0)) AS soldNum,-->
  13. sum(if(t2.del=0 and t2.stock_num is NOT NULL,t2.stock_num,0)) AS stockNum,
  14. t3.`name` AS categoryName,
  15. t2.bar_code
  16. FROM
  17. goods t1
  18. left join goods_spec t2 on t1.goods_id = t2.goods_id and t2.del = 0
  19. left join goods_category t3 on t3.category_id = t1.category_id
  20. WHERE
  21. t1.del = 0
  22. <if test='companyWechatIds != null and companyWechatIds.size > 0' >
  23. AND t1.company_wechat_id in
  24. <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
  25. #{companyWechatId}
  26. </foreach>
  27. </if>
  28. <if test='goodsTypes != null and goodsTypes.size > 0' >
  29. AND t1.goods_type in
  30. <foreach collection="goodsTypes" open="(" close=")" item="item" separator=",">
  31. #{item}
  32. </foreach>
  33. </if>
  34. <if test="flag != null">
  35. <choose>
  36. <when test="flag == 'S'.toString()">AND t1.status = 1</when>
  37. <when test="flag == 'W'.toString()">AND t1.status = 0</when>
  38. <when test="flag == 'A'.toString()">AND t2.flag = 1</when>
  39. <otherwise/>
  40. </choose>
  41. </if>
  42. <if test="keyword != null and keyword != ''">
  43. AND
  44. (t1.goods_id like CONCAT('%', #{keyword},'%') OR t1.goods_name like CONCAT('%',#{keyword},'%') OR t3.`name`
  45. like CONCAT('%',#{keyword},'%') OR CONCAT(t1.goods_name, '(', t2.`name`,')') like
  46. CONCAT('%',#{keyword},'%'))
  47. </if>
  48. <if test="startPrice != null and endPrice != null">
  49. AND
  50. t2.price BETWEEN #{startPrice} AND #{endPrice}
  51. </if>
  52. <if test="startShare != null and endShare != null">
  53. AND
  54. t2.share_amount BETWEEN #{startShare} AND #{endShare}
  55. </if>
  56. <if test="categoryId != null and categoryId.size() != 0">
  57. AND
  58. t3.category_id in
  59. <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
  60. #{item}
  61. </foreach>
  62. </if>
  63. <if test="status != null">
  64. AND
  65. t1.status = #{status}
  66. </if>
  67. group by t1.goods_id
  68. <if test="flag == 'O'.toString()">
  69. having sum(t2.stock_num) = 0
  70. </if>
  71. <choose>
  72. <when test="sortStr == null">
  73. ORDER BY t1.sort_num desc,t1.create_time desc
  74. </when>
  75. <otherwise>
  76. ORDER BY t1.sort_num desc,${sortStr},t1.create_time desc
  77. </otherwise>
  78. </choose>
  79. </select>
  80. <select id="list" resultType="com.gree.mall.manager.bean.goods.GoodsSpecBean">
  81. SELECT t1.*,
  82. t1.goods_name AS goodsName,
  83. ifnull(t2.share_amount, 0) AS shareAmount,
  84. ifnull(t2.share_percent, 0) AS sharePercent,
  85. sum(IF(t2.del = 0 AND t2.sold_num IS NOT NULL, t2.sold_num, 0)) AS soldNum,
  86. sum(IF(t2.del = 0 AND t2.stock_num IS NOT NULL, t2.stock_num, 0)) AS stockNum
  87. FROM goods_template gt
  88. LEFT JOIN goods t1 ON gt.goods_id = t1.goods_id
  89. LEFT JOIN goods_spec t2 ON t1.goods_id = t2.goods_id
  90. WHERE gt.template_id = #{commonTemplateId}
  91. and t1.del = 0
  92. GROUP BY t1.goods_id
  93. ORDER BY t1.sort_num DESC
  94. </select>
  95. <select id="countByType" resultType="com.gree.mall.manager.bean.goods.GoodsTypeCount">
  96. select count(1) 'total', sum(if(status = true, 1, 0)) 'csz', sum(if(status = false, 1, 0)) 'ckz'
  97. from goods
  98. where del = false
  99. <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
  100. AND company_wechat_id in
  101. <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
  102. #{companyWechatId}
  103. </foreach>
  104. </if>
  105. </select>
  106. <select id="ysq" resultType="java.lang.Integer">
  107. select count(*) total
  108. from (select sum(stock_num), goods_id
  109. from goods_spec
  110. where del = false
  111. <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
  112. AND company_wechat_id in
  113. <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
  114. #{companyWechatId}
  115. </foreach>
  116. </if>
  117. group by goods_id
  118. having sum(stock_num) = 0) t
  119. </select>
  120. <select id="countByFlag" resultType="java.lang.Integer">
  121. select count(DISTINCT t1.goods_id)
  122. FROM goods t1
  123. left join goods_spec t2 on t1.goods_id = t2.goods_id
  124. WHERE t1.del = 0
  125. AND t2.flag = 1
  126. and t2.del = 0
  127. <if test=' companyWechatIds != null and companyWechatIds.size > 0' >
  128. AND t1.company_wechat_id in
  129. <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
  130. #{companyWechatId}
  131. </foreach>
  132. </if>
  133. </select>
  134. <select id="queryGoodsCategoryByGoodsId" resultType="com.gree.mall.manager.plus.entity.GoodsCategory">
  135. select a.* from goods_category a
  136. join goods b on a.category_id = b.category_id
  137. where b.goods_id=#{goodsId}
  138. </select>
  139. <update id="syncGoodsSpecInnerShareMsg" parameterType="java.lang.String">
  140. update goods_spec
  141. set inner_share_amount = share_amount , inner_share_percent = share_percent
  142. where inner_share_amount is null and inner_share_amount is null and company_wechat_id = #{companyWechatId}
  143. </update>
  144. <select id="queryGoodsPackageList" resultType="com.gree.mall.manager.bean.goods.GoodsPackageList">
  145. select
  146. a.goods_id,
  147. a.img_url,
  148. a.goods_name,
  149. a.status,
  150. (select count(DISTINCT goods_id) from goods_package_pop where goods_package_id= a.goods_id) 'goodsNums',
  151. a.package_min_amount,
  152. a.package_min_share_amount,
  153. use_coupon,
  154. count(DISTINCT c.order_id) 'orderNums',
  155. sum(c.pay_amount) 'orderPayAmount',
  156. a.package_user_type,
  157. a.company_name
  158. from goods a
  159. left join order_info c on c.promotion_package_goods_id=a.goods_id and c.order_status in ('DFH','YFH','OVER')
  160. where a.goods_type='PACKAGE'
  161. and a.del = 0
  162. <if test='companyWechatIds != null and companyWechatIds.size > 0' >
  163. AND a.company_wechat_id in
  164. <foreach collection="companyWechatIds" open="(" close=")" item="companyWechatId" separator=",">
  165. #{companyWechatId}
  166. </foreach>
  167. </if>
  168. <if test="keyword != null and keyword != ''">
  169. AND(a.goods_id like CONCAT('%', #{keyword},'%') OR a.goods_name like CONCAT('%',#{keyword},'%'))
  170. </if>
  171. <if test="startPrice != null and endPrice != null">
  172. AND
  173. a.package_min_amount BETWEEN #{startPrice} AND #{endPrice}
  174. </if>
  175. <if test="startShare != null and endShare != null">
  176. AND
  177. a.package_min_share_amount BETWEEN #{startShare} AND #{endShare}
  178. </if>
  179. <if test="categoryId != null and categoryId.size() != 0">
  180. AND
  181. a.category_id in
  182. <foreach item="item" index="index" collection="categoryId" open="(" separator="," close=")">
  183. #{item}
  184. </foreach>
  185. </if>
  186. <if test="status != null">
  187. AND
  188. a.status = #{status}
  189. </if>
  190. group by a.goods_id
  191. <choose>
  192. <when test="sortStr == null">
  193. ORDER BY a.sort_num desc,a.create_time desc
  194. </when>
  195. <otherwise>
  196. ORDER BY a.sort_num desc,${sortStr},a.create_time desc
  197. </otherwise>
  198. </choose>
  199. </select>
  200. <select id="goodsList" resultType="com.gree.mall.manager.bean.goods.GoodsVO">
  201. SELECT
  202. ${ex.selected}
  203. FROM goods a
  204. ${ex.query}
  205. <if test="ex.orderBy == null or ex.orderBy ==''">
  206. ORDER BY a.create_time DESC
  207. </if>
  208. ${ex.orderBy}
  209. </select>
  210. </mapper>