ProductMapper.xml 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  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} and p.`is_delete`=0
  119. </select>
  120. <select id="doGetById" resultType="com.yami.shop.bean.model.Product">
  121. SELECT
  122. tp.*,
  123. SUM(tss.shop_sku_stocks) AS total_stocks
  124. FROM tz_prod tp
  125. INNER JOIN tz_shop_sku tss ON tp.prod_id = tss.spu_id
  126. INNER JOIN tz_channel_shop tcs ON tss.shop_id = tcs.shop_id AND tcs.channel_id = #{platform}
  127. WHERE tp.prod_id = #{prodId}
  128. AND tp.is_delete = 0
  129. AND tss.is_delete = 0
  130. GROUP BY tp.prod_id, tcs.shop_id
  131. LIMIT 1
  132. </select>
  133. <update id="returnStock">
  134. <foreach collection="prodCollect" item="changeStocks" index="prodId" separator=";">
  135. update tz_prod set total_stocks = total_stocks + #{changeStocks} where prod_id = #{prodId}
  136. </foreach>
  137. </update>
  138. <select id="pageByTagId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  139. SELECT
  140. <include refid="prodWithNoContent_SQL"/>
  141. FROM tz_prod p
  142. LEFT JOIN tz_prod_tag_reference ptr
  143. ON ptr.`prod_id` = p.`prod_id`
  144. LEFT JOIN tz_prod_tag pt
  145. ON pt.`id` = ptr.`tag_id`
  146. WHERE pt.`id` = #{tagId}
  147. AND p.status = 1 and p.`is_delete`=0
  148. ORDER BY p.`update_time` DESC
  149. </select>
  150. <select id="pageByPutawayTime" resultType="com.yami.shop.bean.app.dto.ProductDto">
  151. SELECT
  152. <include refid="prodWithNoContent_SQL"/>
  153. FROM tz_prod p
  154. WHERE p.`status` = 1 AND p.prod_type =0 and p.`is_delete`=0
  155. ORDER BY p.putaway_time DESC
  156. </select>
  157. <select id="pageByScore" resultType="com.yami.shop.bean.app.dto.ProductDto">
  158. SELECT p.*
  159. FROM tz_prod p
  160. WHERE p.`status` = 1
  161. and p.prod_type = 3 and p.`is_delete`=0
  162. ORDER BY p.putaway_time DESC
  163. </select>
  164. <select id="moreBuyProdList" resultType="com.yami.shop.bean.app.dto.ProductDto">
  165. SELECT
  166. <include refid="prodWithNoContent_SQL"/>
  167. FROM tz_prod p
  168. WHERE p.`status` = 1 AND p.prod_type =0
  169. ORDER BY p.`sold_num` DESC, p.`update_time` DESC
  170. </select>
  171. <select id="tagProdList" resultMap="tagProductMap">
  172. SELECT pt.*,
  173. <include refid="prodWithNoContent_SQL"/>
  174. FROM tz_prod_tag pt -- 获取分组信息
  175. LEFT JOIN
  176. (-- 分组获取各组前6个
  177. SELECT ptr.* FROM tz_prod_tag_reference ptr
  178. INNER JOIN tz_prod p3 ON p3.`prod_id` = ptr.`prod_id` AND p3.`status` =1
  179. WHERE
  180. (SELECT COUNT(0) FROM tz_prod_tag_reference prt2
  181. INNER JOIN tz_prod p2 ON p2.`prod_id` = prt2.`prod_id` AND p2.`status` =1
  182. WHERE prt2.`tag_id` = ptr.`tag_id` AND prt2.`create_time` > ptr.`create_time`)&lt;6
  183. ORDER BY ptr.`tag_id`,ptr.`create_time` DESC
  184. )AS temp
  185. ON temp.`tag_id` = pt.`id`
  186. LEFT JOIN tz_prod p -- 获取商品详细信息
  187. ON p.`prod_id` = temp.`prod_id`
  188. ORDER BY pt.`seq` DESC
  189. </select>
  190. <select id="pageByDiscountId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  191. SELECT p.*
  192. FROM tz_discount_prod dp
  193. LEFT JOIN tz_prod p ON dp.prod_id = p.prod_id AND p.prod_type =0
  194. WHERE p.status= 1 AND dp.discount_id = #{discountId}
  195. </select>
  196. <select id="getSearchProdDtoPageByProdName" resultType="com.yami.shop.bean.dto.SearchProdDto">
  197. select
  198. any_value(p.prod_id) as prod_id,
  199. any_value(p.pic) as pic,
  200. any_value(p.prod_name) as prod_name,
  201. any_value(p.price) as price,
  202. any_value(p.brief) as brief,
  203. any_value(p.shop_id) as shopId,
  204. count(pc.prod_comm_id) as prod_comm_number,
  205. count( CASE WHEN evaluate = 0 THEN prod_comm_id ELSE null END ) AS praise_number
  206. from
  207. tz_prod p
  208. left join tz_prod_comm pc on p.prod_id=pc.prod_id and pc.`status`=1
  209. where 1 = 1 and p.`status` = 1 and p.`is_delete`=0
  210. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  211. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  212. </if>
  213. <if test="searchParam.shopId != null">
  214. and p.shop_id = #{searchParam.shopId}
  215. </if>
  216. <if test="searchParam.categoryId != null">
  217. and p.category_id = #{searchParam.categoryId}
  218. </if>
  219. <if test="searchParam.shopCategoryId != null">
  220. and p.shop_category_id = #{searchParam.shopCategoryId}
  221. </if>
  222. <if test="searchParam.prodType != null and searchParam.isAllProdType == null">
  223. and p.prod_type = #{searchParam.prodType}
  224. </if>
  225. <if test="searchParam.isAllProdType == true">
  226. and p.prod_type in (0,1,2)
  227. </if>
  228. GROUP BY p.prod_id
  229. <if test="searchParam.sort == 0">
  230. ORDER BY any_value(p.update_time)
  231. </if>
  232. <if test="searchParam.sort == 1">
  233. ORDER BY any_value(p.sold_num)
  234. </if>
  235. <if test="searchParam.sort == 2">
  236. ORDER BY any_value(p.price)
  237. </if>
  238. <if test="searchParam.orderBy == 0">
  239. asc
  240. </if>
  241. <if test="searchParam.orderBy == 1">
  242. desc
  243. </if>
  244. <if test="searchParam.sort == 1">
  245. , any_value(p.prod_id) DESC
  246. </if>
  247. </select>
  248. <select id="listByShopId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  249. SELECT
  250. <include refid="prodWithNoContent_SQL"/>
  251. FROM tz_prod p
  252. WHERE p.`status` = 1 and p.`is_delete`=0
  253. <if test="shopId != 0">
  254. AND p.shop_id = #{shopId}
  255. </if>
  256. ORDER BY p.`sold_num` DESC, p.`update_time` DESC
  257. </select>
  258. <select id="listBySuitableProdTypeAndCouponIdAndShopId" resultType="com.yami.shop.bean.app.dto.ProductDto">
  259. SELECT
  260. <include refid="prodWithNoContent_SQL"/>
  261. FROM
  262. tz_prod p
  263. WHERE p.`status` = 1 and p.`is_delete`=0
  264. <if test="shopId != 0">
  265. AND p.shop_id = #{shopId}
  266. </if>
  267. AND p.`prod_id`
  268. <if test="suitableProdType == 1">
  269. IN
  270. </if>
  271. <if test="suitableProdType == 2">
  272. NOT IN
  273. </if>
  274. (SELECT
  275. cp.`prod_id`
  276. FROM
  277. tz_coupon_prod cp
  278. WHERE cp.`coupon_id` = #{couponId})
  279. ORDER BY p.`sold_num` DESC,p.`update_time` DESC
  280. </select>
  281. <select id="collectionProds" resultType="com.yami.shop.bean.app.dto.ProductDto">
  282. SELECT
  283. <include refid="prodWithNoContent_SQL"/>
  284. FROM tz_prod p
  285. WHERE p.`is_delete`=0 p.`prod_id` IN
  286. (SELECT uc.`prod_id` FROM tz_user_collection uc
  287. WHERE uc.user_id = #{userId})
  288. </select>
  289. <resultMap id="prodAndSkuListMap" type="com.yami.shop.bean.dto.ProdAndSkuListsDto">
  290. <result property="prodId" column="prod_id"/>
  291. <result property="prodName" column="prod_name"/>
  292. <collection property="skuDtoList" javaType="list" ofType="com.yami.shop.bean.app.dto.SkuDto">
  293. <result property="stocks" column="stocks"/>
  294. <result property="skuId" column="sku_id"/>
  295. <result property="price" column="price"/>
  296. <result property="skuName" column="sku_name"/>
  297. </collection>
  298. </resultMap>
  299. <select id="getProdAndSkuLists" resultMap="prodAndSkuListMap">
  300. SELECT
  301. p.`prod_id`,
  302. p.`prod_name`,
  303. s.`price`,
  304. s.`stocks`,
  305. s.`sku_id`,
  306. s.`sku_name`
  307. FROM
  308. tz_prod p
  309. LEFT JOIN tz_sku s ON s.`prod_id` = p.`prod_id`
  310. WHERE p.`is_delete`=0 p.`prod_id` IN
  311. <foreach collection="prodIds" item="prodId" open="(" close=")" separator=",">
  312. #{prodId}
  313. </foreach>
  314. </select>
  315. <update id="updateProductToGroup">
  316. UPDATE tz_prod p SET p.`activity_id` = #{groupActivityId},p.`prod_type`=1 WHERE p.`prod_id` IN
  317. <!--UPDATE tz_prod p SET p.`activity_id` = #{groupActivityId},p.`prod_type`=1 WHERE p.`prod_id` IN-->
  318. <foreach collection="prodIds" item="prodId" open="(" close=")" separator=",">
  319. #{prodId}
  320. </foreach>
  321. </update>
  322. <update id="updateProductToUnGroup">
  323. UPDATE tz_prod p SET p.`activity_id` = NULL,p.`prod_type`=0 WHERE p.`prod_id` =#{prodId}
  324. <!--UPDATE tz_prod p SET p.`group_activity_id` = 0 WHERE p.`prod_id` =#{prodId}-->
  325. </update>
  326. <update id="updateToUnGroupByGroupActivityId">
  327. UPDATE tz_prod p SET p.`activity_id` = NULL,p.`prod_type`=0 WHERE p.`activity_id` =#{groupActivityId}
  328. <!--UPDATE tz_prod p SET p.`group_activity_id` = 0 WHERE p.`activity_id` =#{groupActivityId}-->
  329. </update>
  330. <select id="listByActivityId" resultType="com.yami.shop.bean.model.Product">
  331. SELECT * FROM tz_prod p WHERE p.`activity_id` = 4 AND p.`prod_type` = 1 AND p.`status` = 1
  332. <!--SELECT * FROM tz_prod p WHERE p.`group_activity_id` = #{groupActivityId} AND p.`status` = 1-->
  333. </select>
  334. <update id="updateToApply">
  335. update tz_prod p set p.status = 3,p.update_time=now() where p.prod_id = #{prodId}
  336. </update>
  337. <update id="updateToShopOffline">
  338. update tz_prod p set p.status = 0,p.update_time=now() where p.prod_id = #{prodId}
  339. </update>
  340. <update id="updateToOffline">
  341. update tz_prod p set p.status = 2,p.update_time=now() where p.prod_id = #{prodId}
  342. </update>
  343. <update id="updateSoldNum">
  344. <foreach collection="orderItems" item="orderItem" separator=";">
  345. update tz_prod p set p.sold_num = p.sold_num + #{orderItem.prodCount},p.update_time=now() where p.prod_id = #{orderItem.prodId}
  346. </foreach>
  347. </update>
  348. <update id="offlineProdByShopId">
  349. UPDATE tz_prod p SET p.`status` = 0 WHERE p.`shop_id` = #{shopId} AND p.`status` = 1
  350. </update>
  351. <select id="getcouponProdList" resultMap="ProdResultMap">
  352. SELECT prod_id,prod_name,pic FROM tz_prod
  353. WHERE shop_id = #{shopId}
  354. <if test="ids != null">
  355. AND prod_id NOT IN
  356. <foreach collection="ids" item="id" open="(" close=")" separator=",">
  357. #{id}
  358. </foreach>
  359. </if>
  360. LIMIT 0,3
  361. </select>
  362. <select id="getPageAndShopName" resultType="com.yami.shop.bean.model.Product">
  363. SELECT p.*,s.shop_name FROM tz_prod p
  364. LEFT JOIN tz_shop_detail s
  365. ON p.shop_id = s.shop_id
  366. <where>
  367. p.status != -1 AND prod_type = 0 and p.`is_delete`=0
  368. <if test="product.status != null">
  369. AND p.status = #{product.status}
  370. </if>
  371. <if test="product.prodName != null">
  372. AND p.prod_name LIKE concat('%',#{product.prodName},'%')
  373. </if>
  374. <if test="product.shopName != null">
  375. AND s.shop_name LIKE concat('%',#{product.shopName},'%')
  376. </if>
  377. <if test="product.categoryId != null">
  378. AND p.category_id = #{product.categoryId}
  379. </if>
  380. </where>
  381. ORDER BY putaway_time DESC
  382. </select>
  383. <select id="getProdsByOrderNumber" resultType="com.yami.shop.bean.param.ProdOrderParam">
  384. SELECT oi.*,p.category_id FROM tz_order_item oi
  385. LEFT JOIN tz_prod p ON p.`prod_id` = oi.`prod_id`
  386. WHERE oi.order_number = #{orderNumber}
  387. </select>
  388. <select id="listProdsByProdParam" resultMap="productAndSkuListMap">
  389. 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,
  390. b.brand_name,t.trans_name,stc.category_name as shop_category_name,tc.category_name
  391. FROM
  392. tz_prod p
  393. LEFT JOIN
  394. tz_brand b ON b.`brand_id` = p.`brand_id`
  395. LEFT JOIN
  396. tz_transport t ON t.`transport_id` = p.`delivery_template_id`
  397. LEFT JOIN
  398. tz_sku s ON s.`prod_id` = p.`prod_id`
  399. LEFT JOIN
  400. tz_category tc ON tc.`category_id` = p.`category_id`
  401. LEFT JOIN
  402. tz_category stc ON stc.`category_id` = p.`shop_category_id`
  403. WHERE s.`is_delete` = 0 and p.`is_delete`=0 AND p.`status` = #{productParam.status} AND p.shop_id = #{productParam.shopId}
  404. </select>
  405. <select id="pageProducts" resultType="com.yami.shop.bean.model.Product">
  406. SELECT
  407. prod_name,prod_id,score_price,shop_category_id,pic,video,content,activity_id,delivery_mode,price,
  408. shop_id,brief,imgs,putaway_time,sold_num,total_stocks,update_time,prod_type,
  409. VERSION,ori_price,create_time,brand_id,delivery_template_id,category_id,STATUS
  410. FROM
  411. tz_prod p
  412. <where>
  413. shop_id = #{product.shopId} and STATUS = 1 AND prod_type = 0 and p.`is_delete`=0
  414. <if test="product.prodName != null">
  415. AND p.prod_name LIKE concat('%',#{product.prodName},'%')
  416. </if>
  417. <if test="product.isDistribution != null and product.isDistribution == 1">
  418. AND p.`prod_id` NOT IN (SELECT prod_id FROM `tz_distribution_prod`)
  419. </if>
  420. <if test="product.shopCategoryId != null">
  421. AND p.shop_category_id = #{product.shopCategoryId}
  422. </if>
  423. </where>
  424. ORDER BY putaway_time DESC
  425. </select>
  426. <select id="getSearchProdDtoPageByCategory" resultType="com.yami.shop.bean.dto.SearchProdDto">
  427. select
  428. any_value(p.prod_id) as prod_id,
  429. any_value(p.pic) as pic,
  430. any_value(p.prod_name) as prod_name,
  431. any_value(p.price) as price,
  432. any_value(p.brief) as brief,
  433. count(pc.prod_comm_id) as prod_comm_number,
  434. count( CASE WHEN evaluate = 0 THEN prod_comm_id ELSE null END ) AS praise_number
  435. from
  436. tz_prod p
  437. left join tz_prod_comm pc on p.prod_id=pc.prod_id and pc.`status`=1
  438. where 1 = 1 and p.`status` = 1 and prod_type = 0 and p.`is_delete`=0
  439. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  440. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  441. </if>
  442. <if test="searchParam.shopId != null">
  443. and p.shop_id = #{searchParam.shopId}
  444. </if>
  445. <if test="searchParam.categoryId != null">
  446. and p.category_id = #{searchParam.categoryId}
  447. </if>
  448. <if test="searchParam.shopCategoryId != null">
  449. and p.shop_category_id = #{searchParam.shopCategoryId}
  450. </if>
  451. <if test="searchParam.prodType != null">
  452. and p.prod_type = #{searchParam.prodType}
  453. </if>
  454. GROUP BY p.prod_id
  455. <if test="searchParam.sort == 0">
  456. ORDER BY any_value(p.update_time)
  457. </if>
  458. <if test="searchParam.sort == 1">
  459. ORDER BY any_value(p.sold_num)
  460. </if>
  461. <if test="searchParam.sort == 2">
  462. ORDER BY any_value(p.price)
  463. </if>
  464. <if test="searchParam.orderBy == 0">
  465. asc
  466. </if>
  467. <if test="searchParam.orderBy == 1">
  468. desc
  469. </if>
  470. <if test="searchParam.sort == 1">
  471. , any_value(p.prod_id) DESC
  472. </if>
  473. </select>
  474. <update id="updateProduct">
  475. UPDATE tz_prod
  476. SET shop_category_id=#{product.shopCategoryId}, pic=#{product.pic}, video=#{product.video}, content=#{product.content},
  477. delivery_mode=#{product.deliveryMode},price=#{product.price}, prod_name=#{product.prodName}, brief=#{product.brief},
  478. imgs=#{product.imgs}, total_stocks=#{product.totalStocks}, update_time=#{product.updateTime},ori_price=#{product.oriPrice},
  479. delivery_template_id=#{product.deliveryTemplateId}, category_id=#{product.categoryId}, status=#{product.status},brand_id=#{product.brandId}
  480. WHERE prod_id=#{product.prodId}
  481. </update>
  482. <update id="offlineProdByCategoryId">
  483. UPDATE
  484. tz_prod
  485. SET
  486. `status` = 0
  487. WHERE `category_id` = #{categoryId}
  488. </update>
  489. <select id="queryShop" resultType="com.yami.shop.bean.model.ShopDetail">
  490. select
  491. sd.shop_id shopId,
  492. shop_name shopName,
  493. ( 6371 * acos( cos( radians(#{lat}) ) * cos( radians( shop_lat ) ) * cos( radians( shop_lng ) - radians(#{lon}) ) + sin( radians(#{lat}) ) * sin( radians( shop_lat ) ) ) ) AS distance
  494. from
  495. tz_shop_detail sd
  496. right join tz_transport2 tp on tp.shop_id = sd.shop_id
  497. having distance <![CDATA[ <= ]]> #{distance}
  498. order by distance
  499. </select>
  500. <select id="pageByPutawayTimeNew" resultType="com.yami.shop.bean.app.dto.ProductDto">
  501. SELECT
  502. p.prod_id,
  503. p.imgs pic,
  504. p.prod_name,
  505. p.price,
  506. p.brief,
  507. p.shop_id,
  508. p.status
  509. FROM tz_prod p
  510. left join tz_shop_detail sd on p.shop_id = sd.shop_id
  511. WHERE p.`status` = 1 AND p.prod_type =0 and p.`is_delete`=0
  512. <if test="list != null">
  513. and p.shop_id in
  514. <foreach collection="list" item="item" separator="," open="(" close=")">
  515. #{item}
  516. </foreach>
  517. </if>
  518. ORDER BY p.putaway_time DESC
  519. </select>
  520. <select id="getSearchProdDtoPageByProdNameNew" resultType="com.yami.shop.bean.dto.SearchProdDto">
  521. select
  522. sum(tss.shop_sku_stocks) as stocks,
  523. any_value(p.prod_id) as prod_id,
  524. any_value(p.imgs) as pic,
  525. any_value(p.prod_name) as prod_name,
  526. MIN(tcp.channel_prod_price) as price,
  527. any_value(p.brief) as brief,
  528. any_value ( tss.shop_id ) AS shopId,
  529. ls.name as selfLabel,
  530. lr.name as returnLabel,
  531. lh.name as hotLabel,
  532. count(pc.prod_comm_id) as prod_comm_number,
  533. count( CASE WHEN evaluate = 0 THEN prod_comm_id ELSE null END ) AS praise_number,
  534. (6371 * acos(cos(radians(#{searchParam.lat})) * cos(radians(shop_lat)) * cos(radians(shop_lng) -
  535. radians(#{searchParam.lon}) ) + sin(radians(#{searchParam.lat})) * sin(radians(shop_lat)))) distance
  536. from
  537. tz_shop_sku tss
  538. LEFT JOIN tz_prod p ON p.prod_id = tss.spu_id
  539. LEFT JOIN tz_shop_detail sd ON sd.shop_id = tss.shop_id
  540. LEFT JOIN tz_prod_comm pc ON p.prod_id = pc.prod_id
  541. LEFT JOIN tz_channel_prod tcp ON tss.sku_id = tcp.sku_id
  542. LEFT JOIN tz_category_prod cp on p.prod_id = cp.prod_id
  543. LEFT JOIN tz_shop_category sc on cp.code = sc.code
  544. left join tz_label ls on ls.id = tss.self_label_id
  545. left join tz_label lr on lr.id = tss.return_label_id
  546. left join tz_label lh on lh.id = tss.hot_label_id
  547. where 1 = 1 and p.`status` = 1 and p.`is_delete`=0 and tcp.is_delete=0 and tss.shop_id in
  548. <foreach collection="list" item="item" separator="," open="(" close=")">
  549. #{item}
  550. </foreach>
  551. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  552. and prod_name like concat('%',#{searchParam.prodName} ,'%')
  553. </if>
  554. <if test="searchParam.shopId != null">
  555. and tss.shop_id = #{searchParam.shopId}
  556. </if>
  557. <if test="searchParam.categoryId != null">
  558. and sc.id = #{searchParam.categoryId}
  559. </if>
  560. <if test="searchParam.shopCategoryId != null">
  561. and p.shop_category_id = #{searchParam.shopCategoryId}
  562. </if>
  563. <if test="searchParam.channelId == null or searchParam.channelId == 0">
  564. and tcp.channel_id = 1
  565. </if>
  566. <if test="searchParam.channelId != null and searchParam.channelId != 0">
  567. and tcp.channel_id = #{searchParam.channelId}
  568. </if>
  569. <if test="searchParam.prodType != null and searchParam.isAllProdType == null">
  570. and p.prod_type = #{searchParam.prodType}
  571. </if>
  572. <if test="searchParam.isAllProdType == true">
  573. and p.prod_type in (0,1,2)
  574. </if>
  575. GROUP BY p.prod_id
  576. HAVING distance <![CDATA[<=]]> #{searchParam.distance}
  577. <if test="searchParam.sort == 0">
  578. ORDER BY any_value(p.update_time)
  579. </if>
  580. <if test="searchParam.sort == 1">
  581. ORDER BY any_value(p.sold_num)
  582. </if>
  583. <if test="searchParam.sort == 2">
  584. ORDER BY any_value(p.price)
  585. </if>
  586. <if test="searchParam.sort == 3">
  587. ORDER BY distance
  588. </if>
  589. <if test="searchParam.orderBy == 0">
  590. asc
  591. </if>
  592. <if test="searchParam.orderBy == 1">
  593. desc
  594. </if>
  595. <if test="searchParam.sort == 1">
  596. , any_value(p.prod_id) DESC
  597. </if>
  598. </select>
  599. <select id="getSalesVolume" resultType="java.lang.Integer">
  600. select ifnull(sum(oi.prod_count),0) from tz_order o
  601. join tz_order_item oi on oi.order_number=o.order_number
  602. where oi.prod_id=#{prodId} and o.hb_order_status=80
  603. </select>
  604. <select id="getSearchProdDtoPageByProdName2" resultType="com.yami.shop.bean.dto.SearchProdDto">
  605. SELECT
  606. t.*,
  607. t1.salesVolume
  608. FROM (
  609. SELECT
  610. sum(tss.shop_sku_stocks) AS stocks,
  611. ANY_VALUE(p.prod_id) AS prod_id,
  612. ANY_VALUE(p.pic) AS pic,
  613. ANY_VALUE(p.prod_name) AS prod_name,
  614. ANY_VALUE(p.price) AS price,
  615. ANY_VALUE(p.brief) AS brief,
  616. ANY_VALUE(p.shop_id) AS shopId,
  617. ANY_VALUE(p.update_time) AS update_time
  618. FROM
  619. tz_prod p
  620. LEFT JOIN tz_sku sku ON p.prod_id = sku.prod_id
  621. left join tz_shop_sku tss on sku.sku_id = tss.sku_id
  622. LEFT JOIN tz_category_prod cp on p.prod_id = cp.prod_id
  623. LEFT JOIN tz_shop_category sc on cp.code = sc.code
  624. WHERE 1 = 1
  625. AND p.`status` = 1 and p.`is_delete`=0
  626. <if test="searchParam.prodName != null and searchParam.prodName != ''">
  627. AND prod_name LIKE CONCAT('%', #{searchParam.prodName}, '%')
  628. </if>
  629. <if test="searchParam.shopId != null">
  630. AND p.shop_id = #{searchParam.shopId}
  631. </if>
  632. <if test="searchParam.categoryId != null">
  633. AND sc.id = #{searchParam.categoryId}
  634. </if>
  635. <if test="searchParam.shopCategoryId != null">
  636. AND p.shop_category_id = #{searchParam.shopCategoryId}
  637. </if>
  638. <if test="searchParam.prodType != null and searchParam.isAllProdType == null">
  639. AND p.prod_type = #{searchParam.prodType}
  640. </if>
  641. <if test="searchParam.isAllProdType == true">
  642. AND p.prod_type IN (0,1,2)
  643. </if>
  644. GROUP BY
  645. p.prod_id
  646. ) t
  647. LEFT JOIN (
  648. SELECT
  649. oi.prod_id,
  650. IFNULL(SUM(oi.prod_count), 0) AS salesVolume
  651. FROM
  652. tz_order o
  653. JOIN
  654. tz_order_item oi ON oi.order_number = o.order_number
  655. WHERE
  656. o.hb_order_status = 80
  657. GROUP BY
  658. oi.prod_id
  659. ) t1 ON t.prod_id = t1.prod_id
  660. <!-- 修改点:合并排序条件 -->
  661. <choose>
  662. <when test="searchParam.sort != null">
  663. <choose>
  664. <when test="searchParam.sort == 0">
  665. ORDER BY t.update_time
  666. <if test="searchParam.orderBy != null">
  667. <choose>
  668. <when test="searchParam.orderBy == 0">ASC</when>
  669. <when test="searchParam.orderBy == 1">DESC</when>
  670. </choose>
  671. </if>
  672. </when>
  673. <when test="searchParam.sort == 1">
  674. ORDER BY t1.salesVolume
  675. <if test="searchParam.orderBy != null">
  676. <choose>
  677. <when test="searchParam.orderBy == 0">ASC</when>
  678. <when test="searchParam.orderBy == 1">DESC</when>
  679. </choose>
  680. </if>
  681. , t.prod_id DESC
  682. </when>
  683. <when test="searchParam.sort == 2">
  684. ORDER BY t.price
  685. <if test="searchParam.orderBy != null">
  686. <choose>
  687. <when test="searchParam.orderBy == 0">ASC</when>
  688. <when test="searchParam.orderBy == 1">DESC</when>
  689. </choose>
  690. </if>
  691. </when>
  692. </choose>
  693. </when>
  694. <otherwise>
  695. <!-- 默认排序(当sort未指定时) -->
  696. ORDER BY t.update_time DESC
  697. </otherwise>
  698. </choose>
  699. </select>
  700. <select id="listProdByCategoryIdAndShopId" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
  701. SELECT
  702. p.*
  703. FROM
  704. tz_prod p
  705. INNER JOIN tz_category c ON p.shop_category_id = c.category_id
  706. WHERE
  707. c.parent_id = #{prodByCategoryIdAndShopIdDTO.categoryId}
  708. AND p.STATUS = 1 and p.`is_delete`=0
  709. AND c.STATUS = 1
  710. AND p.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
  711. ORDER BY
  712. p.create_time DESC
  713. </select>
  714. <select id="listProdByCIdAndSId" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
  715. SELECT
  716. tp.prod_id,
  717. tp.prod_name,
  718. tcp.shop_id,
  719. tp.brand_id,
  720. tp.brand_name,
  721. tp.ori_price,
  722. MIN(cp.channel_prod_price) AS price,
  723. tp.score_price,
  724. tp.brief,
  725. tp.video,
  726. tp.pic,
  727. tp.content,
  728. tp.imgs,
  729. tp.status,
  730. tp.is_delete,
  731. tp.shop_category_id,
  732. tp.category_id,
  733. tp.hb_front_category_id,
  734. tp.sold_num,
  735. COALESCE(SUM(tss.shop_sku_stocks), 0) AS total_stocks,
  736. tp.delivery_mode,
  737. tp.delivery_template_id,
  738. tp.create_time,
  739. tp.update_time,
  740. tp.putaway_time,
  741. tp.version,
  742. tp.prod_type,
  743. tp.activity_id,
  744. tp.sup_id,
  745. tp.hb_spu_id,
  746. tp.hb_status,
  747. COALESCE ((
  748. SELECT
  749. SUM( oi2.prod_count )
  750. FROM
  751. tz_order_item oi2
  752. INNER JOIN tz_order o2 ON o2.order_number = oi2.order_number
  753. WHERE
  754. oi2.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
  755. AND oi2.prod_id = tp.prod_id
  756. AND o2.hb_order_status IN ( 20, 30, 40, 70, 80 )
  757. AND o2.delete_status = 0
  758. ),
  759. 0
  760. ) AS salesVolume
  761. FROM tz_prod tp
  762. INNER JOIN tz_category_prod tcp ON tp.prod_id = tcp.prod_id
  763. AND tcp.is_delete = 0 AND tcp.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
  764. and tcp.category_id = #{prodByCategoryIdAndShopIdDTO.categoryId}
  765. LEFT JOIN tz_shop_sku tss ON tss.spu_id = tp.prod_id
  766. JOIN tz_channel_prod cp ON cp.shop_id = tcp.shop_id
  767. AND cp.sku_id = tss.sku_id
  768. AND cp.is_delete = 0
  769. <if test="prodByCategoryIdAndShopIdDTO.channelId == null or prodByCategoryIdAndShopIdDTO.channelId == 0">
  770. and cp.channel_id = 1
  771. </if>
  772. <if test="prodByCategoryIdAndShopIdDTO.channelId != null and prodByCategoryIdAndShopIdDTO.channelId != 0">
  773. and cp.channel_id = #{prodByCategoryIdAndShopIdDTO.channelId}
  774. </if>
  775. AND cp.channel_prod_price IS NOT NULL
  776. WHERE tp.STATUS = 1
  777. AND tp.`is_delete` = 0
  778. GROUP BY tp.prod_id
  779. ORDER BY MAX(tp.create_time) DESC
  780. </select>
  781. <select id="listProdByCategoryIdAndShopId2" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
  782. select t.*,t1.salesVolume from (
  783. SELECT
  784. p.*
  785. FROM
  786. tz_prod p
  787. INNER JOIN tz_category c ON p.shop_category_id = c.category_id
  788. WHERE
  789. c.category_id = #{prodByCategoryIdAndShopIdDTO.categoryId}
  790. AND p.STATUS = 1
  791. AND c.STATUS = 1
  792. AND p.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
  793. ) t left join (select oi.prod_id,ifnull(sum(oi.prod_count),0) as salesVolume from tz_order o
  794. join tz_order_item oi on oi.order_number=o.order_number
  795. where o.hb_order_status=80 GROUP BY oi.prod_id) t1 on t.prod_id = t1.prod_id
  796. <if test="prodByCategoryIdAndShopIdDTO.sort == 0">
  797. ORDER BY p.update_time
  798. </if>
  799. <if test="prodByCategoryIdAndShopIdDTO.sort == 1">
  800. ORDER BY t1.salesVolume
  801. </if>
  802. <if test="prodByCategoryIdAndShopIdDTO.sort == 2">
  803. ORDER BY p.price
  804. </if>
  805. <if test="prodByCategoryIdAndShopIdDTO.orderBy == 0">
  806. asc
  807. </if>
  808. <if test="prodByCategoryIdAndShopIdDTO.orderBy == 1">
  809. desc
  810. </if>
  811. </select>
  812. <select id="selectByHbSpuId" resultType="com.yami.shop.bean.model.Product">
  813. select * from tz_prod where hb_spu_id = #{hbSpuId} AND is_delete = 0;
  814. </select>
  815. <select id="findByProdIdAndShopId" resultType="com.yami.shop.bean.model.ChannelProd">
  816. select a.* from tz_channel_prod a
  817. INNER join tz_sku b on b.prod_id = #{prodId} and b.sku_id = a.sku_id and b.is_delete = 0
  818. where a.shop_id=#{shopId} and a.is_delete = 0 ORDER BY a.channel_prod_price LIMIT 1
  819. </select>
  820. <select id="findByProdIdAndShopIdAndPrice" resultType="com.yami.shop.bean.app.dto.ProductDto">
  821. SELECT
  822. d.prod_id,
  823. d.shop_id,
  824. IFNULL(i.count,0)
  825. FROM tz_category_prod a -- 商品类目关联表
  826. INNER JOIN tz_shop_category b ON a.`code` = b.`code` -- 商品类目表
  827. INNER JOIN tz_category_prod c ON b.`code` = c.`code` AND c.shop_id = a.shop_id and c.is_delete =0 -- 商品类目关联表
  828. INNER JOIN tz_prod d ON c.shop_id = d.shop_id AND c.prod_id = d.prod_id AND d.`status` = 1 and d.is_delete=0 -- 商品表
  829. INNER JOIN tz_sku e on d.prod_id = e.prod_id and e.is_delete=0 -- 商品规格表
  830. INNER JOIN tz_channel_prod f on d.shop_id =f.shop_id and e.sku_id =f.sku_id and f.is_delete = 0 -- 渠道商品价格表
  831. and f.channel_prod_price &gt;=#{decreased} and f.channel_prod_price &lt;=#{increased}
  832. LEFT JOIN (SELECT count(h.order_item_id) as count,h.prod_id from tz_order g LEFT JOIN tz_order_item h on g.order_number = h.order_number where g.refund_status is null and g.delete_status and g.hb_order_status = 80 GROUP BY h.prod_id) i on d.prod_id = i.prod_id -- 统计销量
  833. WHERE a.prod_id = #{prodId}
  834. AND d.shop_id = #{shopId}
  835. AND b.`level` = 2
  836. and a.is_delete =0
  837. ORDER BY i.count DESC limit 6
  838. </select>
  839. <select id="findByProdAndShop" resultType="com.yami.shop.bean.dto.SearchProdDto">
  840. SELECT
  841. SUM(tss.shop_sku_stocks) as stocks,
  842. p.prod_id,
  843. p.imgs as pic,
  844. p.prod_name,
  845. MIN(tcp.channel_prod_price) as price,
  846. p.brief,
  847. tss.shop_id AS shopId,
  848. tss.self_label_id AS selfLabelId,
  849. tss.return_label_id AS returnLabelId,
  850. tss.hot_label_id AS hotLabelId,
  851. COUNT(pc.prod_comm_id) as prod_comm_number,
  852. COUNT(CASE WHEN pc.evaluate = 0 THEN pc.prod_comm_id ELSE null END) AS praise_number,
  853. IFNULL(i.count,0)
  854. FROM tz_prod p
  855. INNER JOIN tz_shop_sku tss ON p.prod_id = tss.spu_id
  856. INNER JOIN tz_shop_detail sd ON sd.shop_id = tss.shop_id
  857. INNER JOIN tz_channel_prod tcp ON tss.sku_id = tcp.sku_id AND tcp.is_delete = 0
  858. LEFT JOIN tz_prod_comm pc ON p.prod_id = pc.prod_id
  859. LEFT JOIN tz_category_prod cp ON p.prod_id = cp.prod_id
  860. LEFT JOIN tz_shop_category sc ON cp.code = sc.code
  861. LEFT JOIN (SELECT count(h.order_item_id) as count,h.prod_id from tz_order g LEFT JOIN tz_order_item h on g.order_number = h.order_number where g.refund_status is null and g.delete_status and g.hb_order_status = 80) i on p.prod_id = i.prod_id -- 统计销量
  862. WHERE p.status = 1
  863. AND p.is_delete = 0
  864. AND (p.shop_id, p.prod_id) IN
  865. <foreach collection="list" item="item" open="(" close=")" separator=",">
  866. (#{item.shopId}, #{item.prodId})
  867. </foreach>
  868. order by i.count DESC
  869. </select>
  870. <select id="similarProdList" resultType="com.yami.shop.bean.vo.SimilarProdListVo">
  871. SELECT ss.shop_id AS shopId, p.prod_id AS prodId,p.prod_name AS prodName,p.pic,min(cha.channel_prod_price) AS channelProdPrice,sum(ss.shop_sku_stocks) shopSkuStocks FROM tz_category_prod cp INNER JOIN tz_prod p on p.prod_id = cp.prod_id
  872. LEFT JOIN tz_shop_sku ss on ss.spu_id = cp.prod_id and ss.is_delete = 0
  873. INNER JOIN tz_channel_prod cha on cha.sku_id = ss.sku_id and cha.is_delete = 0
  874. where p.is_delete = 0 and cha.channel_id = #{channelId} and
  875. cp.code in (select sc.code FROM tz_category_prod cp
  876. LEFT JOIN tz_shop_category sc on cp.code = sc.code
  877. WHERE sc.level = 2 and cp.shop_id = #{shopId} and sc.is_delete = 0 and cp.is_delete = 0
  878. and cp.prod_id = #{prodId}
  879. GROUP BY sc.code)
  880. or
  881. (
  882. p.brand_id = (SELECT brand_id FROM tz_prod WHERE prod_id = #{prodId})
  883. AND EXISTS (
  884. SELECT 1
  885. FROM tz_channel_prod base_cha
  886. INNER JOIN tz_shop_sku base_ss ON base_cha.sku_id = base_ss.sku_id
  887. WHERE base_ss.spu_id = #{prodId}
  888. AND base_cha.channel_id = 1
  889. AND base_cha.is_delete = 0
  890. AND base_ss.is_delete = 0
  891. AND cha.channel_prod_price BETWEEN
  892. base_cha.channel_prod_price * 0.9
  893. AND base_cha.channel_prod_price * 1.1
  894. )
  895. )
  896. )
  897. AND p.prod_id != #{prodId}
  898. GROUP BY p.prod_id
  899. </select>
  900. </mapper>