ProductMapper.xml 43 KB

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