ProductMapper.xml 43 KB

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