ApiGoodsMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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.kmall.api.dao.ApiGoodsMapper">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.kmall.api.entity.GoodsVo" id="goodsMap">
  6. <result property="id" column="id"/>
  7. <result property="category_id" column="category_id"/>
  8. <result property="goods_sn" column="goods_sn"/>
  9. <result property="name" column="name"/>
  10. <result property="brand_id" column="brand_id"/>
  11. <result property="goods_number" column="goods_number"/>
  12. <result property="keywords" column="keywords"/>
  13. <result property="goods_brief" column="goods_brief"/>
  14. <result property="goods_desc" column="goods_desc"/>
  15. <result property="is_on_sale" column="is_on_sale"/>
  16. <result property="add_time" column="add_time"/>
  17. <result property="sort_order" column="sort_order"/>
  18. <result property="is_delete" column="is_delete"/>
  19. <result property="attribute_category" column="attribute_category"/>
  20. <result property="counter_price" column="counter_price"/>
  21. <result property="extra_price" column="extra_price"/>
  22. <result property="is_new" column="is_new"/>
  23. <result property="goods_unit" column="goods_unit"/>
  24. <result property="primary_pic_url" column="primary_pic_url"/>
  25. <result property="list_pic_url" column="list_pic_url"/>
  26. <result property="retail_price" column="retail_price"/>
  27. <result property="market_price" column="market_price"/>
  28. <result property="sell_volume" column="sell_volume"/>
  29. <result property="primary_product_id" column="primary_product_id"/>
  30. <result property="unit_price" column="unit_price"/>
  31. <result property="promotion_desc" column="promotion_desc"/>
  32. <result property="promotion_tag" column="promotion_tag"/>
  33. <result property="app_exclusive_price" column="app_exclusive_price"/>
  34. <result property="is_app_exclusive" column="is_app_exclusive"/>
  35. <result property="is_limited" column="is_limited"/>
  36. <result property="is_hot" column="is_hot"/>
  37. <result property="product_id" column="product_id"/>
  38. <result property="sku" column="sku"/>
  39. <result property="goodsBizType" column="goods_biz_type"/>
  40. <result column="creater_sn" property="createrSn" jdbcType="VARCHAR" />
  41. <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
  42. <result column="moder_sn" property="moderSn" jdbcType="VARCHAR" />
  43. <result column="mod_time" property="modTime" jdbcType="TIMESTAMP" />
  44. <result column="tstm" property="tstm" jdbcType="TIMESTAMP" />
  45. <result property="goodsRate" column="goods_rate"/>
  46. <result property="stockNum" column="stock_num"/>
  47. <result property="storeId" column="store_id"/>
  48. <result property="merchSn" column="merch_sn"/>
  49. <result property="merchName" column="merch_name"/>
  50. <result column="third_party_merch_code" property="thirdPartyMerchCode" />
  51. <result column="isStockShare" property="isStockShare" />
  52. <result property="goods_sell_volume" column="goods_sell_volume"/>
  53. </resultMap>
  54. <sql id="Base_Column_List" >
  55. id, goods_sn, sku, goods_biz_type, name, goods_number, keywords,
  56. goods_brief, is_on_sale, add_time, sort_order, is_delete, counter_price,
  57. extra_price, is_new, goods_unit, primary_pic_url, list_pic_url, retail_price, sell_volume,
  58. primary_product_id, unit_price, promotion_desc, promotion_tag, app_exclusive_price,
  59. is_app_exclusive, is_limited, is_hot, market_price, creater_sn, create_time, moder_sn,
  60. mod_time, tstm,goods_desc,goods_rate,third_party_merch_code
  61. </sql>
  62. <select id="queryObject" resultMap="goodsMap">
  63. select a.id,
  64. a.goods_sn,
  65. a.name,
  66. a.goods_number,
  67. a.keywords,
  68. a.goods_brief,
  69. a.is_on_sale,
  70. a.add_time,
  71. a.sort_order,
  72. a.is_delete,
  73. a.counter_price,
  74. a.extra_price,
  75. a.is_new,
  76. a.goods_unit,
  77. a.primary_pic_url,
  78. a.list_pic_url,
  79. a.sell_volume,
  80. a.primary_product_id,
  81. a.unit_price,
  82. a.promotion_desc,
  83. a.promotion_tag,
  84. a.app_exclusive_price,
  85. a.is_app_exclusive,
  86. a.is_limited,
  87. a.is_hot,
  88. a.merch_sn,
  89. a.goods_desc,a.goods_biz_type,a.goods_rate,a.third_party_merch_code
  90. from mall_goods a
  91. where a.id = #{value}
  92. </select>
  93. <select id="queryObjectByStoreId" resultMap="goodsMap">
  94. select
  95. a.sku,
  96. a.id,
  97. psr1.category_id,
  98. a.goods_sn,
  99. a.name,
  100. psr1.brand_id,
  101. a.goods_number,
  102. a.keywords,
  103. a.goods_brief,
  104. a.is_on_sale,
  105. a.add_time,
  106. a.sort_order,
  107. a.is_delete,
  108. psr1.attribute_category,
  109. a.counter_price,
  110. a.extra_price,
  111. a.is_new,
  112. a.goods_unit,
  113. a.primary_pic_url,
  114. a.list_pic_url,
  115. psr1.retail_price,
  116. psr1.sell_volume,
  117. a.primary_product_id,
  118. a.unit_price,
  119. a.promotion_desc,
  120. a.promotion_tag,
  121. a.app_exclusive_price,
  122. a.is_app_exclusive,
  123. a.is_limited,
  124. a.is_hot,
  125. a.merch_sn,
  126. m.merch_name,
  127. psr1.store_id,
  128. psr1.market_price,
  129. psr1.stock_num,
  130. a.goods_desc,a.goods_biz_type,a.goods_rate,
  131. a.sell_volume goods_sell_volume,
  132. mb.third_party_merch_code,
  133. mb.is_stock_share isStockShare,
  134. mb.is_supplier_goods 'isSupplierGoods',
  135. mb2.third_party_merch_code 'supplierThirdMerchCode',
  136. mb2.is_stock_share 'isStockShareBySuppler',psr1.product_id
  137. from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
  138. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  139. LEFT JOIN mall_store s ON s.id = psr1.store_id
  140. LEFT JOIN third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code
  141. LEFT JOIN third_merchant_biz mb2 ON a.third_party_merch_code = mb2.third_party_merch_code
  142. where a.id = #{id} and psr1.store_id = #{storeId}
  143. </select>
  144. <select id="queryList" resultMap="goodsMap">
  145. select
  146. <if test="fields != null and fields != ''">
  147. ${fields}
  148. </if>
  149. <if test="fields == null or fields == ''">
  150. a.*
  151. </if>
  152. ,psr1.stock_num,psr1.category_id,psr1.brand_id,psr1.attribute_category,a.third_party_merch_code
  153. ,a.goods_biz_type,a.goods_number,mb.is_stock_share isStockShare,psr1.store_id
  154. from mall_goods a
  155. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  156. LEFT JOIN mall_store s ON s.id = psr1.store_id
  157. left join third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=s.merch_sn
  158. LEFT JOIN mall_product b ON b.id = psr1.product_id
  159. left join mall_category c on psr1.category_id = c.id
  160. where 1 = 1
  161. and a.is_delete != 1 and a.is_on_sale = 1
  162. <if test="is_new != null and is_new != ''">
  163. and a.is_new = #{is_new}
  164. </if>
  165. <if test="is_hot != null and is_hot != ''">
  166. and a.is_hot = #{is_hot}
  167. </if>
  168. <if test="brand_id != null and brand_id != ''">
  169. and psr1.brand_id = #{brand_id}
  170. </if>
  171. <if test="category_id != null and category_id != ''">
  172. and psr1.category_id = #{category_id}
  173. </if>
  174. <if test="keyword != null">
  175. and a.name like concat('%',#{keyword},'%')
  176. </if>
  177. <if test="is_delete != null">
  178. and a.is_delete = #{is_delete}
  179. </if>
  180. <if test="goodsBizType != null">
  181. and a.goods_biz_type = #{goodsBizType}
  182. </if>
  183. <if test="notGoodsBizType == true">
  184. and a.goods_biz_type in ('00','11')
  185. </if>
  186. <if test="categoryIds != null">
  187. and psr1.category_id in
  188. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  189. #{item}
  190. </foreach>
  191. </if>
  192. <if test="category_parent_id != null and category_parent_id != null and category_parent_id != 0">
  193. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  194. </if>
  195. <if test="category_parent_id != null and category_parent_id != null and category_parent_id == 0">
  196. and FIND_IN_SET(c.parent_id, getCategoryChildLst(#{category_parent_id}))
  197. </if>
  198. <if test="goods_ids != null">
  199. and a.id in
  200. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  201. #{item}
  202. </foreach>
  203. </if>
  204. <if test="store_id != null and store_id != ''">
  205. and psr1.store_id = #{store_id}
  206. and c.store_id = #{store_id}
  207. </if>
  208. <choose>
  209. <when test="sidx != null and sidx.trim() != ''">
  210. order by ${sidx} ${order}
  211. </when>
  212. <otherwise>
  213. order by a.id desc
  214. </otherwise>
  215. </choose>
  216. <if test="offset != null and limit != null">
  217. limit #{offset}, #{limit}
  218. </if>
  219. </select>
  220. <select id="queryHotGoodsList" resultMap="goodsMap">
  221. select
  222. <if test="fields != null and fields != ''">
  223. ${fields}
  224. </if>
  225. <if test="fields == null or fields == ''">
  226. a.*,b.id as product_id,psr1.category_id,psr1.brand_id,psr1.attribute_category
  227. </if>
  228. ,a.goods_biz_type,
  229. a.goods_number,
  230. a.third_party_merch_code third_party_merch_code,
  231. mb.is_stock_share isStockShare,psr1.store_id,
  232. ( SELECT sum( number ) FROM mall_cart WHERE goods_id = a.id AND store_id = psr1.store_id ) cart_num
  233. FROM
  234. mall_goods a
  235. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id AND a.merch_sn = psr1.merch_sn
  236. LEFT JOIN mall_store s ON psr1.store_id = s.id
  237. LEFT JOIN third_merchant_biz mb ON s.third_party_merch_code = mb.third_party_merch_code AND mb.merch_sn = s.merch_sn
  238. LEFT JOIN mall_product b ON b.id = psr1.product_id
  239. LEFT JOIN mall_category c ON psr1.category_id = c.id
  240. where 1 = 1
  241. <if test="isStockShare == 1">
  242. and (a.goods_number > 0 or psr1.stock_num > 0 )
  243. </if>
  244. <if test="isStockShare == 0">
  245. and psr1.stock_num > 0
  246. </if>
  247. and b.id is not null and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  248. <if test="is_new != null and is_new != ''">
  249. and a.is_new = #{is_new}
  250. </if>
  251. <if test="is_hot != null and is_hot != ''">
  252. and a.is_hot = #{is_hot}
  253. </if>
  254. <if test="brand_id != null and brand_id != ''">
  255. and psr1.brand_id = #{brand_id}
  256. </if>
  257. <if test="category_id != null and category_id != ''">
  258. and psr1.category_id = #{category_id}
  259. </if>
  260. <if test="keyword != null">
  261. and a.keywords like concat('%',#{keyword},'%')
  262. </if>
  263. <if test="categoryIds != null">
  264. and psr1.category_id in
  265. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  266. #{item}
  267. </foreach>
  268. </if>
  269. <if test="category_parent_id != null and category_parent_id != null and category_parent_id != 0">
  270. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  271. </if>
  272. <if test="category_parent_id != null and category_parent_id != null and category_parent_id == 0">
  273. and FIND_IN_SET(c.parent_id, getCategoryChildLst(#{category_parent_id}))
  274. </if>
  275. <if test="goods_ids != null">
  276. and a.id in
  277. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  278. #{item}
  279. </foreach>
  280. </if>
  281. <if test="store_id != null and store_id != ''">
  282. and psr1.store_id = #{store_id}
  283. </if>
  284. <choose>
  285. <when test="sidx != null and sidx.trim() != ''">
  286. order by ${sidx} ${order}
  287. </when>
  288. <otherwise>
  289. order by a.id desc
  290. </otherwise>
  291. </choose>
  292. <if test="offset != null and limit != null">
  293. limit #{offset}, #{limit}
  294. </if>
  295. </select>
  296. <select id="queryCatalogProductList" resultMap="goodsMap">
  297. select a.id, a.name, a.list_pic_url,psr1.category_id,psr1.brand_id,psr1.attribute_category , psr1.market_price, psr1.retail_price, a.goods_brief, b.id AS product_id,
  298. psr1.stock_num,a.third_party_merch_code,a.goods_biz_type,a.goods_number,
  299. mb.is_stock_share isStockShare,psr1.store_id ,
  300. ( SELECT sum( number ) FROM mall_cart WHERE goods_id = a.id AND store_id = psr1.store_id ) cart_num
  301. <if test="is_group != null and is_group == true">
  302. ,gg.id as group_id
  303. </if>
  304. FROM
  305. mall_goods a
  306. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  307. LEFT JOIN mall_store s ON s.id = psr1.store_id
  308. LEFT JOIN third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=s.merch_sn
  309. LEFT JOIN mall_product b ON b.id = psr1.product_id
  310. <if test="is_group != null and is_group == true">
  311. LEFT JOIN mall_goods_group gg on gg.goods_id = a.id
  312. </if>
  313. WHERE
  314. 1 = 1 and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  315. <if test="is_new != null and is_new != ''">
  316. and a.is_new = #{is_new}
  317. </if>
  318. <if test="is_hot != null and is_hot != ''">
  319. and a.is_hot = #{is_hot}
  320. </if>
  321. <if test="brand_id != null and brand_id != ''">
  322. and psr1.brand_id = #{brand_id}
  323. </if>
  324. <if test="name != null and name != ''">
  325. and a.'name' like concat('%',#{keyword},'%')
  326. </if>
  327. <if test="category_id != null and category_id != ''">
  328. and psr1.category_id = #{category_id}
  329. </if>
  330. <if test="keyword != null">
  331. and a.keywords like concat('%',#{keyword},'%')
  332. </if>
  333. <if test="is_group != null and is_group == true">
  334. and gg.id is not null
  335. </if>
  336. <if test="categoryIds != null">
  337. and psr1.category_id in
  338. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  339. #{item}
  340. </foreach>
  341. </if>
  342. <if test="category_parent_id != null and category_parent_id != null">
  343. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  344. </if>
  345. <if test="goods_ids != null">
  346. and a.id in
  347. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  348. #{item}
  349. </foreach>
  350. </if>
  351. <if test="store_id != null and store_id != ''">
  352. and psr1.store_id = #{store_id}
  353. </if>
  354. <if test="goodsBizType != null and goodsBizType != ''">
  355. and a.goods_biz_type = #{goodsBizType}
  356. </if>
  357. group by a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief, b.id
  358. <choose>
  359. <when test="sidx != null and sidx.trim() != ''">
  360. order by ${sidx} ${order}
  361. </when>
  362. <otherwise>
  363. order by a.id desc
  364. </otherwise>
  365. </choose>
  366. <if test="offset != null and limit != null">
  367. limit #{offset}, #{limit}
  368. </if>
  369. </select>
  370. <select id="queryTotal" resultType="int">
  371. select count(*)
  372. from mall_goods a
  373. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  374. LEFT JOIN mall_store s ON s.id = psr1.store_id
  375. left join third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=s.merch_sn
  376. LEFT JOIN mall_product b ON b.id = psr1.product_id
  377. left join mall_category c on psr1.category_id = c.id
  378. where 1 = 1
  379. and a.is_delete != 1 and a.is_on_sale = 1
  380. <if test="is_new != null and is_new != ''">
  381. and a.is_new = #{is_new}
  382. </if>
  383. <if test="is_hot != null and is_hot != ''">
  384. and a.is_hot = #{is_hot}
  385. </if>
  386. <if test="brand_id != null and brand_id != ''">
  387. and psr1.brand_id = #{brand_id}
  388. </if>
  389. <if test="category_id != null and category_id != ''">
  390. and psr1.category_id = #{category_id}
  391. </if>
  392. <if test="keyword != null">
  393. and a.name like concat('%',#{keyword},'%')
  394. </if>
  395. <if test="is_delete != null">
  396. and a.is_delete = #{is_delete}
  397. </if>
  398. <if test="goodsBizType != null">
  399. and a.goods_biz_type = #{goodsBizType}
  400. </if>
  401. <if test="notGoodsBizType == true">
  402. and a.goods_biz_type in ('00','11')
  403. </if>
  404. <if test="categoryIds != null">
  405. and psr1.category_id in
  406. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  407. #{item}
  408. </foreach>
  409. </if>
  410. <if test="category_parent_id != null and category_parent_id != null and category_parent_id != 0">
  411. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  412. </if>
  413. <if test="category_parent_id != null and category_parent_id != null and category_parent_id == 0">
  414. and FIND_IN_SET(c.parent_id, getCategoryChildLst(#{category_parent_id}))
  415. </if>
  416. <if test="goods_ids != null">
  417. and a.id in
  418. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  419. #{item}
  420. </foreach>
  421. </if>
  422. <if test="store_id != null and store_id != ''">
  423. and psr1.store_id = #{store_id}
  424. and c.store_id = #{store_id}
  425. </if>
  426. </select>
  427. <select id="selectCountByCatalogProductList" resultType="int">
  428. SELECT count(*) FROM
  429. mall_goods a
  430. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  431. LEFT JOIN mall_store s ON s.id = psr1.store_id
  432. LEFT JOIN third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code and mb.merch_sn=s.merch_sn
  433. LEFT JOIN mall_product b ON b.id = psr1.product_id
  434. <if test="is_group != null and is_group == true">
  435. LEFT JOIN mall_goods_group gg on gg.goods_id = a.id
  436. </if>
  437. WHERE
  438. 1 = 1 and b.id > 0 and a.is_delete != 1 and psr1.retail_price is not null and a.is_on_sale = 1
  439. <if test="is_new != null and is_new != ''">
  440. and a.is_new = #{is_new}
  441. </if>
  442. <if test="is_hot != null and is_hot != ''">
  443. and a.is_hot = #{is_hot}
  444. </if>
  445. <if test="brand_id != null and brand_id != ''">
  446. and psr1.brand_id = #{brand_id}
  447. </if>
  448. <if test="name != null and name != ''">
  449. and a.'name' like concat('%',#{keyword},'%')
  450. </if>
  451. <if test="category_id != null and category_id != ''">
  452. and psr1.category_id = #{category_id}
  453. </if>
  454. <if test="keyword != null">
  455. and a.keywords like concat('%',#{keyword},'%')
  456. </if>
  457. <if test="is_group != null and is_group == true">
  458. and gg.id is not null
  459. </if>
  460. <if test="categoryIds != null">
  461. and psr1.category_id in
  462. <foreach item="item" collection="categoryIds" open="(" separator="," close=")">
  463. #{item}
  464. </foreach>
  465. </if>
  466. <if test="category_parent_id != null and category_parent_id != null">
  467. and FIND_IN_SET(psr1.category_id, getCategoryChildLst(#{category_parent_id}))
  468. </if>
  469. <if test="goods_ids != null">
  470. and a.id in
  471. <foreach item="item" collection="goods_ids" open="(" separator="," close=")">
  472. #{item}
  473. </foreach>
  474. </if>
  475. <if test="store_id != null and store_id != ''">
  476. and psr1.store_id = #{store_id}
  477. </if>
  478. <if test="goodsBizType != null and goodsBizType != ''">
  479. and a.goods_biz_type = #{goodsBizType}
  480. </if>
  481. </select>
  482. <update id="updateGoodsStock" parameterType="com.kmall.api.entity.GoodsVo">
  483. update mall_goods a
  484. <set>
  485. <if test="goods_number != null">a.`goods_number` = #{goods_number},</if>
  486. <if test="sell_volume != null">a.`sell_volume` = #{sell_volume},</if>
  487. </set>
  488. where a.id = #{id}
  489. </update>
  490. </mapper>