ProductMapper.xml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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.yami.shop.dao.ProductMapper">
  4. <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.Product">
  5. <id property="prodId" column="prod_id"/>
  6. <result property="prodName" column="prod_name"/>
  7. <result property="shopId" column="shop_id"/>
  8. <result property="oriPrice" column="ori_price"/>
  9. <result property="price" column="price"/>
  10. <result property="brief" column="brief"/>
  11. <result property="content" column="content"/>
  12. <result property="imgs" column="imgs"/>
  13. <result property="status" column="status"/>
  14. <result property="scorePrice" column="score_price"/>
  15. <result property="prodType" column="prod_type"/>
  16. <result property="activityId" column="activity_id"/>
  17. <result property="categoryId" column="category_id"/>
  18. <result property="soldNum" column="sold_num"/>
  19. <result property="totalStocks" column="total_stocks"/>
  20. <result property="pic" column="pic"/>
  21. <result property="deliveryMode" column="delivery_mode"/>
  22. <result property="deliveryTemplateId" column="delivery_template_id"/>
  23. <result property="createTime" column="create_time"/>
  24. <result property="updateTime" column="update_time"/>
  25. <result property="putawayTime" column="putaway_time"/>
  26. <result property="version" column="version"/>
  27. </resultMap>
  28. <resultMap id="tagProductMap" type="com.yami.shop.bean.app.dto.TagProductDto">
  29. <result property="id" column="id"/>
  30. <result property="title" column="title"/>
  31. <result property="seq" column="seq"/>
  32. <result property="style" column="style"/>
  33. <collection property="productDtoList" javaType="list" ofType="com.yami.shop.bean.app.dto.ProductDto">
  34. <result property="prodId" column="prod_id"/>
  35. <result property="prodName" column="prod_name"/>
  36. <result property="shopId" column="shop_id"/>
  37. <result property="price" column="price"/>
  38. <result property="brief" column="brief"/>
  39. <result property="imgs" column="imgs"/>
  40. <result property="oriPrice" column="ori_price"/>
  41. <result property="categoryId" column="category_id"/>
  42. <result property="totalStocks" column="total_stocks"/>
  43. <result property="pic" column="pic"/>
  44. </collection>
  45. </resultMap>
  46. <resultMap id="productAndSkuListMap" type="com.yami.shop.bean.param.ProductExportParam">
  47. <id property="prodId" column="prod_id"/>
  48. <result property="prodName" column="prod_name"/>
  49. <result property="shopId" column="shop_id"/>
  50. <result property="oriPrice" column="ori_price"/>
  51. <result property="transName" column="trans_name"/>
  52. <result property="brandName" column="brand_name"/>
  53. <result property="price" column="price"/>
  54. <result property="brief" column="brief"/>
  55. <result property="content" column="content"/>
  56. <result property="imgs" column="imgs"/>
  57. <result property="status" column="status"/>
  58. <result property="categoryName" column="category_name"/>
  59. <result property="shopCategoryName" column="shop_category_name"/>
  60. <result property="soldNum" column="sold_num"/>
  61. <result property="totalStocks" column="total_stocks"/>
  62. <result property="pic" column="pic"/>
  63. <result property="deliveryMode" column="delivery_mode"/>
  64. <result property="putawayTime" column="putaway_time"/>
  65. <collection property="skuList" javaType="list" ofType="com.yami.shop.bean.model.Sku">
  66. <id column="sku_id" jdbcType="BIGINT" property="skuId" />
  67. <result column="prod_id" jdbcType="BIGINT" property="prodId" />
  68. <result column="properties" jdbcType="VARCHAR" property="properties" />
  69. <result column="sku_prod_name" jdbcType="VARCHAR" property="prodName" />
  70. <result column="sku_ori_price" jdbcType="DECIMAL" property="oriPrice" />
  71. <result column="sku_price" jdbcType="DECIMAL" property="price" />
  72. <result column="weight" jdbcType="DECIMAL" property="weight" />
  73. <result column="volume" jdbcType="DECIMAL" property="volume" />
  74. <result column="stocks" jdbcType="INTEGER" property="stocks" />
  75. <result column="sku_score" jdbcType="INTEGER" property="skuScore" />
  76. <result column="actual_stocks" jdbcType="INTEGER" property="actualStocks" />
  77. <result column="status" jdbcType="TINYINT" property="status" />
  78. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  79. <result column="rec_time" jdbcType="TIMESTAMP" property="recTime" />
  80. <result column="party_code" jdbcType="VARCHAR" property="partyCode" />
  81. <result column="model_id" jdbcType="VARCHAR" property="modelId" />
  82. <result column="sku_pic" jdbcType="VARCHAR" property="pic" />
  83. <result column="sku_name" jdbcType="VARCHAR" property="skuName" />
  84. <result column="is_delete" jdbcType="INTEGER" property="isDelete"/>
  85. </collection>
  86. </resultMap>
  87. <resultMap id="ProdResultMap" type="com.yami.shop.bean.app.dto.ProductDto">
  88. <id column="prod_id" jdbcType="BIGINT" property="prodId"/>
  89. <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
  90. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  91. </resultMap>
  92. <sql id="productDtoWithNoContent_SQL">
  93. p.`prod_id`,
  94. p.`shop_id`,
  95. p.`prod_name`,
  96. p.`pic`,
  97. p.`price`,
  98. p.`ori_price`,
  99. p.`brief`,
  100. p.`imgs`,
  101. p.`category_id`,
  102. p.`total_stocks`,
  103. p.status
  104. </sql>
  105. <sql id="prodWithNoContent_SQL">
  106. p.prod_id,
  107. p.pic,
  108. p.prod_name,
  109. p.price,
  110. p.brief,
  111. p.shop_id,
  112. p.status
  113. </sql>
  114. <update id="updateStocks" parameterType="com.yami.shop.bean.model.Product">
  115. update tz_prod set total_stocks = total_stocks - #{prod.totalStocks} ,version = version + 1 where prod_id = #{prod.prodId} and #{prod.totalStocks} &lt;= total_stocks
  116. </update>
  117. <select id="getProductByProdNameAndShopId" resultType="com.yami.shop.bean.model.Product">
  118. select * from tz_prod where prod_name = #{prodName} and shop_id = #{shopId}
  119. </select>
  120. <select id="doGetById" resultType="com.yami.shop.bean.model.Product">
  121. SELECT
  122. tp.prod_id,
  123. MAX(tp.prod_name) AS prod_name,
  124. tcs.shop_id AS shop_id,
  125. MAX(tp.brand_id) AS brand_id,
  126. MAX(tp.brand_name) AS brand_name,
  127. MAX(tp.ori_price) AS ori_price,
  128. MAX(tss.shop_sku_price) AS price,
  129. MAX(tp.score_price) AS score_price,
  130. MAX(tp.brief) AS brief,
  131. MAX(tp.video) AS video,
  132. MAX(tp.pic) AS pic,
  133. MAX(tp.content) AS content,
  134. MAX(tp.imgs) AS imgs,
  135. MAX(tp.status) AS status,
  136. MAX(tp.is_delete) AS is_delete,
  137. MAX(tp.shop_category_id) AS shop_category_id,
  138. MAX(tp.category_id) AS category_id,
  139. MAX(tp.hb_front_category_id) AS hb_front_category_id,
  140. MAX(tp.sold_num) AS sold_num,
  141. SUM(tss.shop_sku_stocks) AS total_stocks,
  142. MAX(tp.delivery_mode) AS delivery_mode,
  143. MAX(tp.delivery_template_id) AS delivery_template_id,
  144. MAX(tp.create_time) AS create_time,
  145. MAX(tp.update_time) AS update_time,
  146. MAX(tp.putaway_time) AS putaway_time,
  147. MAX(tp.version) AS version,
  148. MAX(tp.prod_type) AS prod_type,
  149. MAX(tp.activity_id) AS activity_id,
  150. MAX(tp.sup_id) AS sup_id,
  151. MAX(tp.hb_spu_id) AS hb_spu_id,
  152. MAX(tp.hb_status) AS hb_status
  153. FROM tz_prod AS tp
  154. LEFT JOIN tz_shop_sku AS tss ON tp.prod_id = tss.spu_id
  155. LEFT JOIN tz_channel_shop AS tcs ON tss.shop_id = tcs.shop_id
  156. WHERE tp.prod_id = #{prodId}
  157. AND tcs.channel_id = #{platform}
  158. GROUP BY
  159. tp.prod_id,
  160. tcs.shop_id
  161. LIMIT 1
  162. </select>
  163. <update id="returnStock">
  164. <foreach collection="prodCollect" item="changeStocks" index="prodId" separator=";">
  165. update tz_prod set total_stocks = total_stocks + #{changeStocks} where prod_id = #{prodId}
  166. </foreach>
  167. </update>
  168. <select id="pageByTagId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  169. SELECT
  170. <include refid="prodWithNoContent_SQL"/>
  171. FROM tz_prod p
  172. LEFT JOIN tz_prod_tag_reference ptr
  173. ON ptr.`prod_id` = p.`prod_id`
  174. LEFT JOIN tz_prod_tag pt
  175. ON pt.`id` = ptr.`tag_id`
  176. WHERE pt.`id` = #{tagId}
  177. AND p.status = 1
  178. ORDER BY p.`update_time` DESC
  179. </select>
  180. <select id="pageByPutawayTime" resultType="com.yami.shop.bean.app.dto.ProductDto">
  181. SELECT
  182. <include refid="prodWithNoContent_SQL"/>
  183. FROM tz_prod p
  184. WHERE p.`status` = 1 AND p.prod_type =0
  185. ORDER BY p.putaway_time DESC
  186. </select>
  187. <select id="pageByScore" resultType="com.yami.shop.bean.app.dto.ProductDto">
  188. SELECT p.*
  189. FROM tz_prod p
  190. WHERE p.`status` = 1
  191. and p.prod_type = 3
  192. ORDER BY p.putaway_time DESC
  193. </select>
  194. <select id="moreBuyProdList" resultType="com.yami.shop.bean.app.dto.ProductDto">
  195. SELECT
  196. <include refid="prodWithNoContent_SQL"/>
  197. FROM tz_prod p
  198. WHERE p.`status` = 1 AND p.prod_type =0
  199. ORDER BY p.`sold_num` DESC, p.`update_time` DESC
  200. </select>
  201. <select id="tagProdList" resultMap="tagProductMap">
  202. SELECT pt.*,
  203. <include refid="prodWithNoContent_SQL"/>
  204. FROM tz_prod_tag pt -- 获取分组信息
  205. LEFT JOIN
  206. (-- 分组获取各组前6个
  207. SELECT ptr.* FROM tz_prod_tag_reference ptr
  208. INNER JOIN tz_prod p3 ON p3.`prod_id` = ptr.`prod_id` AND p3.`status` =1
  209. WHERE
  210. (SELECT COUNT(0) FROM tz_prod_tag_reference prt2
  211. INNER JOIN tz_prod p2 ON p2.`prod_id` = prt2.`prod_id` AND p2.`status` =1
  212. WHERE prt2.`tag_id` = ptr.`tag_id` AND prt2.`create_time` > ptr.`create_time`)&lt;6
  213. ORDER BY ptr.`tag_id`,ptr.`create_time` DESC
  214. )AS temp
  215. ON temp.`tag_id` = pt.`id`
  216. LEFT JOIN tz_prod p -- 获取商品详细信息
  217. ON p.`prod_id` = temp.`prod_id`
  218. ORDER BY pt.`seq` DESC
  219. </select>
  220. <select id="pageByDiscountId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  221. SELECT p.*
  222. FROM tz_discount_prod dp
  223. LEFT JOIN tz_prod p ON dp.prod_id = p.prod_id AND p.prod_type =0
  224. WHERE p.status= 1 AND dp.discount_id = #{discountId}
  225. </select>
  226. <select id="getSearchProdDtoPageByProdName" resultType="com.yami.shop.bean.dto.SearchProdDto">
  227. select
  228. any_value(p.prod_id) as prod_id,
  229. any_value(p.pic) as pic,
  230. any_value(p.prod_name) as prod_name,
  231. any_value(p.price) as price,
  232. any_value(p.brief) as brief,
  233. any_value(p.shop_id) as shopId,
  234. count(pc.prod_comm_id) as prod_comm_number,
  235. count( CASE WHEN evaluate = 0 THEN prod_comm_id ELSE null END ) AS praise_number
  236. from
  237. tz_prod p
  238. left join tz_prod_comm pc on p.prod_id=pc.prod_id and pc.`status`=1
  239. where 1 = 1 and p.`status` = 1
  240. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  241. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  242. </if>
  243. <if test="searchParam.shopId != null">
  244. and p.shop_id = #{searchParam.shopId}
  245. </if>
  246. <if test="searchParam.categoryId != null">
  247. and p.category_id = #{searchParam.categoryId}
  248. </if>
  249. <if test="searchParam.shopCategoryId != null">
  250. and p.shop_category_id = #{searchParam.shopCategoryId}
  251. </if>
  252. <if test="searchParam.prodType != null and searchParam.isAllProdType == null">
  253. and p.prod_type = #{searchParam.prodType}
  254. </if>
  255. <if test="searchParam.isAllProdType == true">
  256. and p.prod_type in (0,1,2)
  257. </if>
  258. GROUP BY p.prod_id
  259. <if test="searchParam.sort == 0">
  260. ORDER BY any_value(p.update_time)
  261. </if>
  262. <if test="searchParam.sort == 1">
  263. ORDER BY any_value(p.sold_num)
  264. </if>
  265. <if test="searchParam.sort == 2">
  266. ORDER BY any_value(p.price)
  267. </if>
  268. <if test="searchParam.orderBy == 0">
  269. asc
  270. </if>
  271. <if test="searchParam.orderBy == 1">
  272. desc
  273. </if>
  274. <if test="searchParam.sort == 1">
  275. , any_value(p.prod_id) DESC
  276. </if>
  277. </select>
  278. <select id="listByShopId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  279. SELECT
  280. <include refid="prodWithNoContent_SQL"/>
  281. FROM tz_prod p
  282. WHERE p.`status` = 1
  283. <if test="shopId != 0">
  284. AND p.shop_id = #{shopId}
  285. </if>
  286. ORDER BY p.`sold_num` DESC, p.`update_time` DESC
  287. </select>
  288. <select id="listBySuitableProdTypeAndCouponIdAndShopId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  289. SELECT
  290. <include refid="prodWithNoContent_SQL"/>
  291. FROM
  292. tz_prod p
  293. WHERE p.`status` = 1
  294. <if test="shopId != 0">
  295. AND p.shop_id = #{shopId}
  296. </if>
  297. AND p.`prod_id`
  298. <if test="suitableProdType == 1">
  299. IN
  300. </if>
  301. <if test="suitableProdType == 2">
  302. NOT IN
  303. </if>
  304. (SELECT
  305. cp.`prod_id`
  306. FROM
  307. tz_coupon_prod cp
  308. WHERE cp.`coupon_id` = #{couponId})
  309. ORDER BY p.`sold_num` DESC,p.`update_time` DESC
  310. </select>
  311. <select id="collectionProds" resultType="com.yami.shop.bean.app.dto.ProductDto">
  312. SELECT
  313. <include refid="prodWithNoContent_SQL"/>
  314. FROM tz_prod p
  315. WHERE p.`prod_id` IN
  316. (SELECT uc.`prod_id` FROM tz_user_collection uc
  317. WHERE uc.user_id = #{userId})
  318. </select>
  319. <resultMap id="prodAndSkuListMap" type="com.yami.shop.bean.dto.ProdAndSkuListsDto">
  320. <result property="prodId" column="prod_id"/>
  321. <result property="prodName" column="prod_name"/>
  322. <collection property="skuDtoList" javaType="list" ofType="com.yami.shop.bean.app.dto.SkuDto">
  323. <result property="stocks" column="stocks"/>
  324. <result property="skuId" column="sku_id"/>
  325. <result property="price" column="price"/>
  326. <result property="skuName" column="sku_name"/>
  327. </collection>
  328. </resultMap>
  329. <select id="getProdAndSkuLists" resultMap="prodAndSkuListMap">
  330. SELECT
  331. p.`prod_id`,
  332. p.`prod_name`,
  333. s.`price`,
  334. s.`stocks`,
  335. s.`sku_id`,
  336. s.`sku_name`
  337. FROM
  338. tz_prod p
  339. LEFT JOIN tz_sku s ON s.`prod_id` = p.`prod_id`
  340. WHERE p.`prod_id` IN
  341. <foreach collection="prodIds" item="prodId" open="(" close=")" separator=",">
  342. #{prodId}
  343. </foreach>
  344. </select>
  345. <update id="updateProductToGroup">
  346. UPDATE tz_prod p SET p.`activity_id` = #{groupActivityId},p.`prod_type`=1 WHERE p.`prod_id` IN
  347. <!--UPDATE tz_prod p SET p.`activity_id` = #{groupActivityId},p.`prod_type`=1 WHERE p.`prod_id` IN-->
  348. <foreach collection="prodIds" item="prodId" open="(" close=")" separator=",">
  349. #{prodId}
  350. </foreach>
  351. </update>
  352. <update id="updateProductToUnGroup">
  353. UPDATE tz_prod p SET p.`activity_id` = NULL,p.`prod_type`=0 WHERE p.`prod_id` =#{prodId}
  354. <!--UPDATE tz_prod p SET p.`group_activity_id` = 0 WHERE p.`prod_id` =#{prodId}-->
  355. </update>
  356. <update id="updateToUnGroupByGroupActivityId">
  357. UPDATE tz_prod p SET p.`activity_id` = NULL,p.`prod_type`=0 WHERE p.`activity_id` =#{groupActivityId}
  358. <!--UPDATE tz_prod p SET p.`group_activity_id` = 0 WHERE p.`activity_id` =#{groupActivityId}-->
  359. </update>
  360. <select id="listByActivityId" resultType="com.yami.shop.bean.model.Product">
  361. SELECT * FROM tz_prod p WHERE p.`activity_id` = 4 AND p.`prod_type` = 1 AND p.`status` = 1
  362. <!--SELECT * FROM tz_prod p WHERE p.`group_activity_id` = #{groupActivityId} AND p.`status` = 1-->
  363. </select>
  364. <update id="updateToApply">
  365. update tz_prod p set p.status = 3,p.update_time=now() where p.prod_id = #{prodId}
  366. </update>
  367. <update id="updateToShopOffline">
  368. update tz_prod p set p.status = 0,p.update_time=now() where p.prod_id = #{prodId}
  369. </update>
  370. <update id="updateToOffline">
  371. update tz_prod p set p.status = 2,p.update_time=now() where p.prod_id = #{prodId}
  372. </update>
  373. <update id="updateSoldNum">
  374. <foreach collection="orderItems" item="orderItem" separator=";">
  375. update tz_prod p set p.sold_num = p.sold_num + #{orderItem.prodCount},p.update_time=now() where p.prod_id = #{orderItem.prodId}
  376. </foreach>
  377. </update>
  378. <update id="offlineProdByShopId">
  379. UPDATE tz_prod p SET p.`status` = 0 WHERE p.`shop_id` = #{shopId} AND p.`status` = 1
  380. </update>
  381. <select id="getcouponProdList" resultMap="ProdResultMap">
  382. SELECT prod_id,prod_name,pic FROM tz_prod
  383. WHERE shop_id = #{shopId}
  384. <if test="ids != null">
  385. AND prod_id NOT IN
  386. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  387. #{id}
  388. </foreach>
  389. </if>
  390. LIMIT 0,3
  391. </select>
  392. <select id="getPageAndShopName" resultType="com.yami.shop.bean.model.Product">
  393. SELECT p.*,s.shop_name FROM tz_prod p
  394. LEFT JOIN tz_shop_detail s
  395. ON p.shop_id = s.shop_id
  396. <where>
  397. p.status != -1 AND prod_type = 0
  398. <if test="product.status != null">
  399. AND p.status = #{product.status}
  400. </if>
  401. <if test="product.prodName != null">
  402. AND p.prod_name LIKE concat('%',#{product.prodName},'%')
  403. </if>
  404. <if test="product.shopName != null">
  405. AND s.shop_name LIKE concat('%',#{product.shopName},'%')
  406. </if>
  407. <if test="product.categoryId != null">
  408. AND p.category_id = #{product.categoryId}
  409. </if>
  410. </where>
  411. ORDER BY putaway_time DESC
  412. </select>
  413. <select id="getProdsByOrderNumber" resultType="com.yami.shop.bean.param.ProdOrderParam">
  414. SELECT oi.*,p.category_id FROM tz_order_item oi
  415. LEFT JOIN tz_prod p ON p.`prod_id` = oi.`prod_id`
  416. WHERE oi.order_number = #{orderNumber}
  417. </select>
  418. <select id="listProdsByProdParam" resultMap="productAndSkuListMap">
  419. SELECT p.*,s.*,s.prod_name AS sku_prod_name,s.pic AS sku_pic,s.ori_price AS sku_ori_price,s.price AS sku_price,
  420. b.brand_name,t.trans_name,stc.category_name as shop_category_name,tc.category_name
  421. FROM
  422. tz_prod p
  423. LEFT JOIN
  424. tz_brand b ON b.`brand_id` = p.`brand_id`
  425. LEFT JOIN
  426. tz_transport t ON t.`transport_id` = p.`delivery_template_id`
  427. LEFT JOIN
  428. tz_sku s ON s.`prod_id` = p.`prod_id`
  429. LEFT JOIN
  430. tz_category tc ON tc.`category_id` = p.`category_id`
  431. LEFT JOIN
  432. tz_category stc ON stc.`category_id` = p.`shop_category_id`
  433. WHERE s.`is_delete` = 0 AND p.`status` = #{productParam.status} AND p.shop_id = #{productParam.shopId}
  434. </select>
  435. <select id="pageProducts" resultType="com.yami.shop.bean.model.Product">
  436. SELECT
  437. prod_name,prod_id,score_price,shop_category_id,pic,video,content,activity_id,delivery_mode,price,
  438. shop_id,brief,imgs,putaway_time,sold_num,total_stocks,update_time,prod_type,
  439. VERSION,ori_price,create_time,brand_id,delivery_template_id,category_id,STATUS
  440. FROM
  441. tz_prod p
  442. <where>
  443. shop_id = #{product.shopId} and STATUS = 1 AND prod_type = 0
  444. <if test="product.prodName != null">
  445. AND p.prod_name LIKE concat('%',#{product.prodName},'%')
  446. </if>
  447. <if test="product.isDistribution != null and product.isDistribution == 1">
  448. AND p.`prod_id` NOT IN (SELECT prod_id FROM `tz_distribution_prod`)
  449. </if>
  450. <if test="product.shopCategoryId != null">
  451. AND p.shop_category_id = #{product.shopCategoryId}
  452. </if>
  453. </where>
  454. ORDER BY putaway_time DESC
  455. </select>
  456. <select id="getSearchProdDtoPageByCategory" resultType="com.yami.shop.bean.dto.SearchProdDto">
  457. select
  458. any_value(p.prod_id) as prod_id,
  459. any_value(p.pic) as pic,
  460. any_value(p.prod_name) as prod_name,
  461. any_value(p.price) as price,
  462. any_value(p.brief) as brief,
  463. count(pc.prod_comm_id) as prod_comm_number,
  464. count( CASE WHEN evaluate = 0 THEN prod_comm_id ELSE null END ) AS praise_number
  465. from
  466. tz_prod p
  467. left join tz_prod_comm pc on p.prod_id=pc.prod_id and pc.`status`=1
  468. where 1 = 1 and p.`status` = 1 and prod_type = 0
  469. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  470. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  471. </if>
  472. <if test="searchParam.shopId != null">
  473. and p.shop_id = #{searchParam.shopId}
  474. </if>
  475. <if test="searchParam.categoryId != null">
  476. and p.category_id = #{searchParam.categoryId}
  477. </if>
  478. <if test="searchParam.shopCategoryId != null">
  479. and p.shop_category_id = #{searchParam.shopCategoryId}
  480. </if>
  481. <if test="searchParam.prodType != null">
  482. and p.prod_type = #{searchParam.prodType}
  483. </if>
  484. GROUP BY p.prod_id
  485. <if test="searchParam.sort == 0">
  486. ORDER BY any_value(p.update_time)
  487. </if>
  488. <if test="searchParam.sort == 1">
  489. ORDER BY any_value(p.sold_num)
  490. </if>
  491. <if test="searchParam.sort == 2">
  492. ORDER BY any_value(p.price)
  493. </if>
  494. <if test="searchParam.orderBy == 0">
  495. asc
  496. </if>
  497. <if test="searchParam.orderBy == 1">
  498. desc
  499. </if>
  500. <if test="searchParam.sort == 1">
  501. , any_value(p.prod_id) DESC
  502. </if>
  503. </select>
  504. <update id="updateProduct">
  505. UPDATE tz_prod
  506. SET shop_category_id=#{product.shopCategoryId}, pic=#{product.pic}, video=#{product.video}, content=#{product.content},
  507. delivery_mode=#{product.deliveryMode},price=#{product.price}, prod_name=#{product.prodName}, brief=#{product.brief},
  508. imgs=#{product.imgs}, total_stocks=#{product.totalStocks}, update_time=#{product.updateTime},ori_price=#{product.oriPrice},
  509. delivery_template_id=#{product.deliveryTemplateId}, category_id=#{product.categoryId}, status=#{product.status},brand_id=#{product.brandId}
  510. WHERE prod_id=#{product.prodId}
  511. </update>
  512. <update id="offlineProdByCategoryId">
  513. UPDATE
  514. tz_prod
  515. SET
  516. `status` = 0
  517. WHERE `category_id` = #{categoryId}
  518. </update>
  519. <select id="queryShop" resultType="com.yami.shop.bean.model.ShopDetail">
  520. select
  521. sd.shop_id shopId,
  522. shop_name shopName,
  523. ( 6371 * acos( cos( radians(#{lat}) ) * cos( radians( shop_lat ) ) * cos( radians( shop_lng ) - radians(#{lon}) ) + sin( radians(#{lat}) ) * sin( radians( shop_lat ) ) ) ) AS distance
  524. from
  525. tz_shop_detail sd
  526. right join tz_transport2 tp on tp.shop_id = sd.shop_id
  527. having distance <![CDATA[ <= ]]> #{distance}
  528. order by distance
  529. </select>
  530. <select id="pageByPutawayTimeNew" resultType="com.yami.shop.bean.app.dto.ProductDto">
  531. SELECT
  532. p.prod_id,
  533. p.imgs pic,
  534. p.prod_name,
  535. p.price,
  536. p.brief,
  537. p.shop_id,
  538. p.status
  539. FROM tz_prod p
  540. left join tz_shop_detail sd on p.shop_id = sd.shop_id
  541. WHERE p.`status` = 1 AND p.prod_type =0
  542. <if test="list != null">
  543. and p.shop_id in
  544. <foreach collection="list" item="item" separator="," open="(" close=")">
  545. #{item}
  546. </foreach>
  547. </if>
  548. ORDER BY p.putaway_time DESC
  549. </select>
  550. <select id="getSearchProdDtoPageByProdNameNew" resultType="com.yami.shop.bean.dto.SearchProdDto">
  551. select
  552. any_value(p.prod_id) as prod_id,
  553. any_value(p.imgs) as pic,
  554. any_value(p.prod_name) as prod_name,
  555. MIN(tcp.channel_prod_price) as price,
  556. any_value(p.brief) as brief,
  557. any_value ( tss.shop_id ) AS shopId,
  558. any_value ( tss.self_label_id ) AS selfLabelId,
  559. any_value ( tss.return_label_id ) AS returnLabelId,
  560. any_value ( tss.hot_label_id ) AS hotLabelId,
  561. count(pc.prod_comm_id) as prod_comm_number,
  562. count( CASE WHEN evaluate = 0 THEN prod_comm_id ELSE null END ) AS praise_number,
  563. (6371 * acos(cos(radians(#{searchParam.lat})) * cos(radians(shop_lat)) * cos(radians(shop_lng) -
  564. radians(#{searchParam.lon}) ) + sin(radians(#{searchParam.lat})) * sin(radians(shop_lat)))) distance
  565. from
  566. tz_shop_sku tss
  567. LEFT JOIN tz_prod p ON p.prod_id = tss.spu_id
  568. LEFT JOIN tz_shop_detail sd ON sd.shop_id = tss.shop_id
  569. LEFT JOIN tz_prod_comm pc ON p.prod_id = pc.prod_id
  570. LEFT JOIN tz_channel_prod tcp ON tss.sku_id = tcp.sku_id
  571. where 1 = 1 and p.`status` = 1 and tcp.is_delete=0 and tss.shop_id in
  572. <foreach collection="list" item="item" separator="," open="(" close=")">
  573. #{item}
  574. </foreach>
  575. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  576. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  577. </if>
  578. <if test="searchParam.shopId != null">
  579. and tss.shop_id = #{searchParam.shopId}
  580. </if>
  581. <if test="searchParam.platform != null">
  582. and tcp.channel_id = #{searchParam.platform}
  583. </if>
  584. <if test="searchParam.categoryId != null">
  585. and p.category_id = #{searchParam.categoryId}
  586. </if>
  587. <if test="searchParam.shopCategoryId != null">
  588. and p.shop_category_id = #{searchParam.shopCategoryId}
  589. </if>
  590. <if test="searchParam.prodType != null and searchParam.isAllProdType == null">
  591. and p.prod_type = #{searchParam.prodType}
  592. </if>
  593. <if test="searchParam.isAllProdType == true">
  594. and p.prod_type in (0,1,2)
  595. </if>
  596. GROUP BY p.prod_id
  597. HAVING distance <![CDATA[<=]]> #{searchParam.distance}
  598. <if test="searchParam.sort == 0">
  599. ORDER BY any_value(p.update_time)
  600. </if>
  601. <if test="searchParam.sort == 1">
  602. ORDER BY any_value(p.sold_num)
  603. </if>
  604. <if test="searchParam.sort == 2">
  605. ORDER BY any_value(p.price)
  606. </if>
  607. <if test="searchParam.sort == 3">
  608. ORDER BY distance
  609. </if>
  610. <if test="searchParam.orderBy == 0">
  611. asc
  612. </if>
  613. <if test="searchParam.orderBy == 1">
  614. desc
  615. </if>
  616. <if test="searchParam.sort == 1">
  617. , any_value(p.prod_id) DESC
  618. </if>
  619. </select>
  620. <select id="getSalesVolume" resultType="java.lang.Integer">
  621. select ifnull(sum(oi.prod_count),0) from tz_order o
  622. join tz_order_item oi on oi.order_number=o.order_number
  623. where oi.prod_id=#{prodId} and o.hb_order_status=80
  624. </select>
  625. <select id="getSearchProdDtoPageByProdName2" resultType="com.yami.shop.bean.dto.SearchProdDto">
  626. select t.*,t1.salesVolume from (
  627. select
  628. any_value(p.prod_id) as prod_id,
  629. any_value(p.pic) as pic,
  630. any_value(p.prod_name) as prod_name,
  631. any_value(p.price) as price,
  632. any_value(p.brief) as brief,
  633. any_value(p.shop_id) as shopId,
  634. any_value(p.update_time) as update_time
  635. from
  636. tz_prod p
  637. where 1 = 1 and p.`status` = 1
  638. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  639. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  640. </if>
  641. <if test="searchParam.shopId != null">
  642. and p.shop_id = #{searchParam.shopId}
  643. </if>
  644. <if test="searchParam.categoryId != null">
  645. and p.shop_category_id = #{searchParam.categoryId}
  646. </if>
  647. <if test="searchParam.shopCategoryId != null">
  648. and p.shop_category_id = #{searchParam.shopCategoryId}
  649. </if>
  650. <if test="searchParam.prodType != null and searchParam.isAllProdType == null">
  651. and p.prod_type = #{searchParam.prodType}
  652. </if>
  653. <if test="searchParam.isAllProdType == true">
  654. and p.prod_type in (0,1,2)
  655. </if>
  656. GROUP BY p.prod_id
  657. ) t left JOIN (
  658. select oi.prod_id,ifnull(sum(oi.prod_count),0) as salesVolume from tz_order o
  659. join tz_order_item oi on oi.order_number=o.order_number
  660. where o.hb_order_status=80 GROUP BY oi.prod_id) t1 on t.prod_id = t1.prod_id
  661. <if test="searchParam.sort == 0">
  662. ORDER BY t.update_time
  663. </if>
  664. <if test="searchParam.sort == 1">
  665. ORDER BY t1.salesVolume
  666. </if>
  667. <if test="searchParam.sort == 2">
  668. ORDER BY t.price
  669. </if>
  670. <if test="searchParam.orderBy == 0">
  671. asc
  672. </if>
  673. <if test="searchParam.orderBy == 1">
  674. desc
  675. </if>
  676. <if test="searchParam.sort == 1">
  677. , t.prod_id DESC
  678. </if>
  679. </select>
  680. <select id="listProdByCategoryIdAndShopId" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
  681. SELECT
  682. p.*
  683. FROM
  684. tz_prod p
  685. INNER JOIN tz_category c ON p.shop_category_id = c.category_id
  686. WHERE
  687. c.parent_id = #{prodByCategoryIdAndShopIdDTO.categoryId}
  688. AND p.STATUS = 1
  689. AND c.STATUS = 1
  690. AND p.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
  691. ORDER BY
  692. p.create_time DESC
  693. </select>
  694. <select id="listProdByCIdAndSId" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
  695. SELECT
  696. p.*
  697. FROM
  698. tz_prod p
  699. LEFT JOIN tz_category_prod tcp ON p.prod_id=tcp.prod_id
  700. LEFT JOIN tz_shop_category tsc ON tcp.`code`=tsc.`code`
  701. WHERE
  702. p.STATUS = 1
  703. AND tcp.is_delete = 0
  704. AND tsc.is_delete = 0
  705. AND p.shop_id=#{prodByCategoryIdAndShopIdDTO.shopId}
  706. AND tsc.id=#{prodByCategoryIdAndShopIdDTO.categoryId}
  707. ORDER BY
  708. p.create_time DESC
  709. </select>
  710. <select id="listProdByCategoryIdAndShopId2" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
  711. select t.*,t1.salesVolume from (
  712. SELECT
  713. p.*
  714. FROM
  715. tz_prod p
  716. INNER JOIN tz_category c ON p.shop_category_id = c.category_id
  717. WHERE
  718. c.category_id = #{prodByCategoryIdAndShopIdDTO.categoryId}
  719. AND p.STATUS = 1
  720. AND c.STATUS = 1
  721. AND p.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
  722. ) t left join (select oi.prod_id,ifnull(sum(oi.prod_count),0) as salesVolume from tz_order o
  723. join tz_order_item oi on oi.order_number=o.order_number
  724. where o.hb_order_status=80 GROUP BY oi.prod_id) t1 on t.prod_id = t1.prod_id
  725. <if test="prodByCategoryIdAndShopIdDTO.sort == 0">
  726. ORDER BY p.update_time
  727. </if>
  728. <if test="prodByCategoryIdAndShopIdDTO.sort == 1">
  729. ORDER BY t1.salesVolume
  730. </if>
  731. <if test="prodByCategoryIdAndShopIdDTO.sort == 2">
  732. ORDER BY p.price
  733. </if>
  734. <if test="prodByCategoryIdAndShopIdDTO.orderBy == 0">
  735. asc
  736. </if>
  737. <if test="prodByCategoryIdAndShopIdDTO.orderBy == 1">
  738. desc
  739. </if>
  740. </select>
  741. <select id="selectByHbSpuId" resultType="com.yami.shop.bean.model.Product">
  742. select * from tz_prod where hb_spu_id = #{hbSpuId} AND is_delete = 0;
  743. </select>
  744. </mapper>