SkuMapper.xml 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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.SkuMapper">
  4. <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.Sku">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="sku_id" jdbcType="BIGINT" property="skuId"/>
  9. <result column="prod_id" jdbcType="BIGINT" property="prodId"/>
  10. <result column="properties" jdbcType="VARCHAR" property="properties"/>
  11. <result column="ori_price" jdbcType="DECIMAL" property="oriPrice"/>
  12. <result column="price" jdbcType="DECIMAL" property="price"/>
  13. <result column="stocks" jdbcType="INTEGER" property="stocks"/>
  14. <result column="actual_stocks" jdbcType="INTEGER" property="actualStocks"/>
  15. <result column="status" jdbcType="TINYINT" property="status"/>
  16. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  17. <result column="rec_time" jdbcType="TIMESTAMP" property="recTime"/>
  18. <result column="party_code" jdbcType="VARCHAR" property="partyCode"/>
  19. <result column="model_id" jdbcType="VARCHAR" property="modelId"/>
  20. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  21. <result column="sku_name" jdbcType="VARCHAR" property="skuName"/>
  22. <result column="is_delete" jdbcType="INTEGER" property="isDelete"/>
  23. </resultMap>
  24. <insert id="insertBatch">
  25. INSERT INTO `tz_sku` (
  26. `prod_id`,`properties`,`ori_price`,`price`,`stocks`,`actual_stocks`,
  27. `update_time`,`rec_time`,`party_code`,`model_id`, `pic`,
  28. `sku_name`,`prod_name`,`version`,`weight`,`volume`, `status`, `is_delete`, `sku_score`
  29. )
  30. VALUES
  31. <foreach collection="skuList" item="sku" separator=",">
  32. (
  33. #{prodId},#{sku.properties},#{sku.oriPrice},#{sku.price},#{sku.stocks},
  34. #{sku.actualStocks}, NOW(),NOW(),#{sku.partyCode},#{sku.modelId}, #{sku.pic},
  35. #{sku.skuName},#{sku.prodName},0,#{sku.weight},#{sku.volume}, #{sku.status},0, #{sku.skuScore}
  36. )
  37. </foreach>
  38. </insert>
  39. <select id="listByProdId" resultType="com.yami.shop.bean.model.Sku">
  40. select *
  41. from tz_sku
  42. where prod_id = #{prodId}
  43. and is_delete = 0
  44. </select>
  45. <select id="listByProdIdAndPlatform" resultType="com.yami.shop.bean.model.Sku">
  46. SELECT ts.sku_id,
  47. ts.prod_id,
  48. ts.sku_name,
  49. ts.prod_name,
  50. ts.ori_price,
  51. tcp.channel_prod_price AS price,
  52. ts.sku_score,
  53. ts.properties,
  54. ts.stocks,
  55. tss.shop_sku_stocks AS actual_stocks,
  56. ts.update_time,
  57. ts.rec_time,
  58. ts.party_code,
  59. ts.model_id,
  60. ts.pic,
  61. ts.version,
  62. ts.weight,
  63. ts.volume,
  64. ts.`status`,
  65. ts.is_delete,
  66. ts.weight_unit,
  67. ts.sku_code,
  68. ts.hb_spu_id,
  69. ts.hb_sku_id
  70. FROM tz_shop_sku AS tss
  71. LEFT JOIN tz_sku AS ts ON ts.sku_id = tss.sku_id
  72. LEFT JOIN tz_channel_prod AS tcp ON ts.sku_id = tcp.sku_id
  73. WHERE tss.spu_id = #{prodId}
  74. AND ts.is_delete = 0
  75. AND tcp.is_delete = 0
  76. AND ts.`status` = 1
  77. AND tss.shop_id = #{shopId}
  78. AND tcp.channel_id = #{channelId}
  79. </select>
  80. <select id="listBySukIdAndPlatformShop" resultType="com.yami.shop.bean.model.Sku">
  81. SELECT ts.sku_id,
  82. ts.prod_id,
  83. ts.sku_name,
  84. ts.prod_name,
  85. ts.ori_price,
  86. tcp.channel_prod_price AS price,
  87. ts.sku_score,
  88. ts.properties,
  89. ts.stocks,
  90. tss.shop_sku_stocks AS actual_stocks,
  91. ts.update_time,
  92. ts.rec_time,
  93. ts.party_code,
  94. ts.model_id,
  95. ts.pic,
  96. ts.version,
  97. ts.weight,
  98. ts.volume,
  99. ts.`status`,
  100. ts.is_delete,
  101. ts.weight_unit,
  102. ts.sku_code,
  103. ts.hb_spu_id,
  104. ts.hb_sku_id
  105. FROM tz_sku AS ts
  106. LEFT JOIN tz_shop_sku AS tss ON ts.sku_id = tss.sku_id
  107. LEFT JOIN tz_channel_prod AS tcp ON ts.sku_id = tcp.sku_id
  108. WHERE ts.sku_id = #{skuId}
  109. AND ts.is_delete = 0
  110. AND tcp.is_delete = 0
  111. AND ts.`status` = 1
  112. AND tss.shop_id = #{shopId}
  113. AND tcp.channel_id = #{channelId}
  114. LIMIT 1
  115. </select>
  116. <select id="listBySukIdAndPlatform" resultType="com.yami.shop.bean.model.Sku">
  117. SELECT ts.sku_id,
  118. ts.prod_id,
  119. ts.sku_name,
  120. ts.prod_name,
  121. ts.ori_price,
  122. tcp.channel_prod_price AS price,
  123. ts.sku_score,
  124. ts.properties,
  125. ts.stocks,
  126. tss.shop_sku_stocks AS actual_stocks,
  127. ts.update_time,
  128. ts.rec_time,
  129. ts.party_code,
  130. ts.model_id,
  131. ts.pic,
  132. ts.version,
  133. ts.weight,
  134. ts.volume,
  135. ts.`status`,
  136. ts.is_delete,
  137. ts.weight_unit,
  138. ts.sku_code,
  139. ts.hb_spu_id,
  140. ts.hb_sku_id
  141. FROM tz_sku AS ts
  142. LEFT JOIN tz_shop_sku AS tss ON ts.sku_id = tss.sku_id
  143. LEFT JOIN tz_channel_prod AS tcp ON ts.sku_id = tcp.sku_id
  144. WHERE ts.sku_id = #{skuId}
  145. AND ts.is_delete = 0
  146. AND tcp.is_delete = 0
  147. AND ts.`status` = 1
  148. AND tcp.channel_id = #{channelId} LIMIT 1
  149. </select>
  150. <select id="selectByHbSkuId" resultType="com.yami.shop.bean.model.Sku">
  151. select *
  152. from tz_sku
  153. where hb_sku_id = #{hbSkuId}
  154. and is_delete = 0
  155. </select>
  156. <update id="updateStocks" parameterType="com.yami.shop.bean.model.Sku">
  157. update tz_sku
  158. set stocks = stocks - #{sku.stocks},
  159. version = version + 1,
  160. update_time = NOW()
  161. where sku_id = #{sku.skuId}
  162. and #{sku.stocks} &lt;= stocks
  163. </update>
  164. <update id="deleteByProdId">
  165. update tz_sku
  166. set is_delete = 1
  167. where prod_id = #{prodId}
  168. </update>
  169. <update id="returnStock">
  170. <foreach collection="skuCollect" item="changeStocks" index="skuId" separator=";">
  171. update tz_sku set stocks = stocks + #{changeStocks} where sku_id = #{skuId}
  172. </foreach>
  173. </update>
  174. <select id="buyTogetherOften" resultType="com.yami.shop.bean.vo.SkuBuyTogetherOftenVo">
  175. SELECT a.shop_id,b.sku_id, b.prod_id, b.prod_name, b.pic, c.channel_prod_price, d.shop_sku_stocks,IFNULL(e.basket_count,0) prodCount
  176. FROM tz_order_item a
  177. LEFT JOIN tz_sku b on a.sku_id = b.sku_id
  178. LEFT JOIN tz_channel_prod c on a.sku_id = c.sku_id and c.is_delete = 0
  179. LEFT JOIN tz_shop_sku d on a.sku_id = d.sku_id and d.is_delete = 0
  180. LEFT JOIN tz_basket e on a.prod_id=e.prod_id and a.sku_id=e.sku_id and a.shop_id=e.shop_id and e.user_id=#{userId}
  181. WHERE a.order_number in (SELECT a.order_number FROM tz_order_item a
  182. LEFT JOIN tz_order b on a.order_number=b.order_number
  183. WHERE a.prod_id = #{prodId} and a.shop_id = #{shopId} and b.channel_id=#{channelId})
  184. and a.prod_id!=#{prodId}
  185. and a.shop_id=#{shopId}
  186. and b.`status`=1
  187. and b.is_delete=0
  188. and d.sale_status=1
  189. and c.channel_id=#{channelId}
  190. and c.shop_id=#{shopId}
  191. GROUP BY a.sku_id
  192. ORDER BY a.rec_time desc, a.order_item_id desc
  193. </select>
  194. <select id="goodsTotalPrice" resultType="Double">
  195. SELECT (SELECT IFNULL(SUM(IFNULL(a.total,0)) ,0) goods_total_price FROM tz_order a
  196. LEFT JOIN tz_user e on a.user_id=e.user_id
  197. WHERE a.is_payed=1
  198. <if test="po.startTime != null and po.startTime != ''">
  199. and a.create_time&gt;= #{po.startTime}
  200. </if>
  201. <if test="po.endTime != null and po.endTime != ''">
  202. and a.create_time&lt;= #{po.endTime}
  203. </if>
  204. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  205. and a.order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
  206. <where>
  207. <if test="po.skuId != null">
  208. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  209. </if>
  210. <if test="po.skuName != null and po.skuName != ''">
  211. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  212. </if>
  213. <if test="po.spec != null and po.spec != ''">
  214. AND b.spec like concat('%',#{po.spec} ,'%')
  215. </if>
  216. </where>
  217. )
  218. </if>
  219. and a.channel_id in
  220. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  221. #{id}
  222. </foreach>
  223. <if test="po.userAttrType != null and po.userAttrType != 0">
  224. AND e.user_attr_type=#{po.userAttrType}
  225. </if>
  226. )
  227. -
  228. (SELECT IFNULL(SUM(a.sku_price * a.product_count),0)
  229. FROM `tz_order_refund_sku` a
  230. LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
  231. LEFT JOIN tz_order c on b.order_number=c.order_number
  232. LEFT JOIN tz_sku d on a.sku_id=d.sku_id
  233. LEFT JOIN tz_user e on b.user_id=e.user_id
  234. WHERE b.return_money_sts=70
  235. <if test="po.startTime != null and po.startTime != ''">
  236. and b.apply_time&gt;= #{po.startTime}
  237. </if>
  238. <if test="po.endTime != null and po.endTime != ''">
  239. and b.apply_time&lt;= #{po.endTime}
  240. </if>
  241. and c.channel_id in
  242. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  243. #{id}
  244. </foreach>
  245. <if test="po.skuId != null">
  246. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  247. </if>
  248. <if test="po.skuName != null and po.skuName != ''">
  249. AND d.sku_name like concat('%',#{po.skuName} ,'%')
  250. </if>
  251. <if test="po.spec != null and po.spec != ''">
  252. AND d.spec like concat('%',#{po.spec} ,'%')
  253. </if>
  254. <if test="po.userAttrType != null and po.userAttrType != 0">
  255. AND e.user_attr_type=#{po.userAttrType}
  256. </if>
  257. ) goods_total_price
  258. </select>
  259. <select id="totalPoints" resultType="Double">
  260. SELECT TRUNCATE(((SELECT SUM(IFNULL(a.offset_points,0)) FROM tz_order a
  261. LEFT JOIN tz_user e on a.user_id=e.user_id
  262. WHERE a.is_payed=1
  263. <if test="po.startTime != null and po.startTime != ''">
  264. and a.create_time&gt;= #{po.startTime}
  265. </if>
  266. <if test="po.endTime != null and po.endTime != ''">
  267. and a.create_time&lt;= #{po.endTime}
  268. </if>
  269. and a.channel_id in
  270. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  271. #{id}
  272. </foreach>
  273. <if test="po.userAttrType != null and po.userAttrType != 0">
  274. AND e.user_attr_type=#{po.userAttrType}
  275. </if>
  276. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  277. and a.order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
  278. <where>
  279. <if test="po.skuId != null">
  280. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  281. </if>
  282. <if test="po.skuName != null and po.skuName != ''">
  283. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  284. </if>
  285. <if test="po.spec != null and po.spec != ''">
  286. AND b.spec like concat('%',#{po.spec} ,'%')
  287. </if>
  288. </where>
  289. )
  290. </if>
  291. )
  292. -
  293. (SELECT IFNULL(SUM( total_offset_points ),0) FROM (SELECT
  294. CASE
  295. WHEN refund_type=1 THEN total_offset_points
  296. ELSE total_offset_points
  297. END AS total_offset_points
  298. FROM tz_order_refund a
  299. LEFT JOIN tz_user e on a.user_id=e.user_id
  300. LEFT JOIN (SELECT SUM(tor.offset_points) total_offset_points ,tor.order_number
  301. FROM tz_order_refund tor
  302. LEFT JOIN tz_user e on tor.user_id=e.user_id
  303. WHERE tor.return_money_sts=70
  304. <if test="po.startTime != null and po.startTime != ''">
  305. and tor.apply_time&gt;= #{po.startTime}
  306. </if>
  307. <if test="po.endTime != null and po.endTime != ''">
  308. and tor.apply_time&lt;= #{po.endTime}
  309. </if>
  310. <if test="po.userAttrType != null and po.userAttrType != 0">
  311. AND e.user_attr_type=#{po.userAttrType}
  312. </if>
  313. and tor.order_number in(SELECT ao.order_number FROM tz_order_item ao
  314. LEFT JOIN tz_sku b on ao.sku_id=b.sku_id
  315. LEFT JOIN tz_order c on ao.order_number=c.order_number
  316. <where>
  317. c.channel_id in
  318. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  319. #{id}
  320. </foreach>
  321. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  322. <if test="po.skuId != null">
  323. AND ao.sku_id like concat('%',#{po.skuId} ,'%')
  324. </if>
  325. <if test="po.skuName != null and po.skuName != ''">
  326. AND ao.sku_name like concat('%',#{po.skuName} ,'%')
  327. </if>
  328. <if test="po.spec != null and po.spec != ''">
  329. AND b.spec like concat('%',#{po.spec} ,'%')
  330. </if>
  331. </if>
  332. </where>
  333. )
  334. GROUP BY tor.order_number) b on a.order_number=b.order_number
  335. WHERE return_money_sts=70
  336. <if test="po.startTime != null and po.startTime != ''">
  337. and apply_time &gt;= #{po.startTime}
  338. </if>
  339. <if test="po.endTime != null and po.endTime != ''">
  340. and apply_time &lt;= #{po.endTime}
  341. </if>
  342. <if test="po.userAttrType != null and po.userAttrType != 0">
  343. AND e.user_attr_type=#{po.userAttrType}
  344. </if>
  345. and a.order_number in(SELECT ao2.order_number FROM tz_order_item ao2
  346. LEFT JOIN tz_sku b on ao2.sku_id=b.sku_id
  347. LEFT JOIN tz_order c on ao2.order_number=c.order_number
  348. <where>
  349. c.channel_id in
  350. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  351. #{id}
  352. </foreach>
  353. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  354. <if test="po.skuId != null">
  355. AND ao2.sku_id like concat('%',#{po.skuId} ,'%')
  356. </if>
  357. <if test="po.skuName != null and po.skuName != ''">
  358. AND ao2.sku_name like concat('%',#{po.skuName} ,'%')
  359. </if>
  360. <if test="po.spec != null and po.spec != ''">
  361. AND b.spec like concat('%',#{po.spec} ,'%')
  362. </if>
  363. </if>
  364. </where>
  365. )
  366. GROUP BY a.order_number) a)) /100,2) total_offset_points
  367. </select>
  368. <select id="totalCash" resultType="Double">
  369. SELECT (SELECT SUM(IFNULL(a.actual_total,0)) FROM tz_order a
  370. LEFT JOIN tz_user e on a.user_id=e.user_id
  371. WHERE a.is_payed=1
  372. <if test="po.startTime != null and po.startTime != ''">
  373. and a.create_time&gt;= #{po.startTime}
  374. </if>
  375. <if test="po.endTime != null and po.endTime != ''">
  376. and a.create_time&lt;= #{po.endTime}
  377. </if>
  378. <if test="po.userAttrType != null and po.userAttrType != 0">
  379. AND e.user_attr_type=#{po.userAttrType}
  380. </if>
  381. and a.channel_id in
  382. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  383. #{id}
  384. </foreach>
  385. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  386. and a.order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
  387. <where>
  388. <if test="po.skuId != null">
  389. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  390. </if>
  391. <if test="po.skuName != null and po.skuName != ''">
  392. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  393. </if>
  394. <if test="po.spec != null and po.spec != ''">
  395. AND b.spec like concat('%',#{po.spec} ,'%')
  396. </if>
  397. </where>
  398. )
  399. </if>
  400. )
  401. -
  402. (SELECT IFNULL(SUM( a.refund_amount ),0) FROM tz_order_refund a
  403. LEFT JOIN tz_user e on a.user_id=e.user_id
  404. WHERE a.return_money_sts=70
  405. <if test="po.startTime != null and po.startTime != ''">
  406. and a.apply_time&gt;= #{po.startTime}
  407. </if>
  408. <if test="po.endTime != null and po.endTime != ''">
  409. and a.apply_time&lt;= #{po.endTime}
  410. </if>
  411. <if test="po.userAttrType != null and po.userAttrType != 0">
  412. AND e.user_attr_type=#{po.userAttrType}
  413. </if>
  414. and a.order_number in(SELECT a.order_number FROM tz_order_item a
  415. LEFT JOIN tz_sku b on a.sku_id=b.sku_id
  416. LEFT JOIN tz_order c on a.order_number=c.order_number
  417. <where>
  418. c.channel_id in
  419. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  420. #{id}
  421. </foreach>
  422. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  423. <if test="po.skuId != null">
  424. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  425. </if>
  426. <if test="po.skuName != null and po.skuName != ''">
  427. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  428. </if>
  429. <if test="po.spec != null and po.spec != ''">
  430. AND b.spec like concat('%',#{po.spec} ,'%')
  431. </if>
  432. </if>
  433. </where>
  434. )) cash
  435. </select>
  436. <select id="totalFreight" resultType="Double">
  437. SELECT (SELECT IFNULL(SUM(a.freight_amount),0) total_freight FROM tz_order a
  438. LEFT JOIN tz_user e on a.user_id=e.user_id
  439. WHERE a.is_payed=1
  440. <if test="po.startTime != null and po.startTime != ''">
  441. and a.create_time&gt;= #{po.startTime}
  442. </if>
  443. <if test="po.endTime != null and po.endTime != ''">
  444. and a.create_time&lt;= #{po.endTime}
  445. </if>
  446. <if test="po.userAttrType != null and po.userAttrType != 0">
  447. AND e.user_attr_type=#{po.userAttrType}
  448. </if>
  449. and a.channel_id in
  450. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  451. #{id}
  452. </foreach>
  453. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  454. and a.order_number in(SELECT a.order_number FROM tz_order_item a LEFT JOIN tz_sku b on a.sku_id=b.sku_id
  455. <where>
  456. <if test="po.skuId != null">
  457. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  458. </if>
  459. <if test="po.skuName != null and po.skuName != ''">
  460. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  461. </if>
  462. <if test="po.spec != null and po.spec != ''">
  463. AND b.spec like concat('%',#{po.spec} ,'%')
  464. </if>
  465. </where>
  466. )
  467. </if>
  468. )
  469. -
  470. (SELECT IFNULL(SUM(a.freight_amount),0)
  471. FROM `tz_order_refund` a
  472. LEFT JOIN tz_user e on a.user_id=e.user_id
  473. WHERE a.return_money_sts=70
  474. <if test="po.startTime != null and po.startTime != ''">
  475. and a.apply_time&gt;= #{po.startTime}
  476. </if>
  477. <if test="po.endTime != null and po.endTime != ''">
  478. and a.apply_time&lt;= #{po.endTime}
  479. </if>
  480. <if test="po.userAttrType != null and po.userAttrType != 0">
  481. AND e.user_attr_type=#{po.userAttrType}
  482. </if>
  483. and a.refund_type=1
  484. and a.order_number in(SELECT a.order_number FROM tz_order_item a
  485. LEFT JOIN tz_sku b on a.sku_id=b.sku_id
  486. LEFT JOIN tz_order c on a.order_number=c.order_number
  487. <where>
  488. c.channel_id in
  489. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  490. #{id}
  491. </foreach>
  492. <if test="po.skuId != null or (po.skuName != null and po.skuName != '') or (po.spec != null and po.spec != '')">
  493. <if test="po.skuId != null">
  494. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  495. </if>
  496. <if test="po.skuName != null and po.skuName != ''">
  497. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  498. </if>
  499. <if test="po.spec != null and po.spec != ''">
  500. AND b.spec like concat('%',#{po.spec} ,'%')
  501. </if>
  502. </if>
  503. </where>
  504. ))
  505. </select>
  506. <select id="skuStatisticsList" resultType="com.yami.shop.bean.vo.SkuStatisticsVo">
  507. SELECT a.prod_id,a.sku_id,a.sku_name,c.spec,TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2)
  508. price,IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0) as prod_count,
  509. TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) *
  510. (IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0)) total
  511. FROM tz_order_item a
  512. LEFT JOIN tz_order b on a.order_number=b.order_number
  513. LEFT JOIN tz_sku c on a.sku_id=c.sku_id
  514. LEFT JOIN tz_user e on b.user_id=e.user_id
  515. LEFT JOIN (SELECT a.sku_id,SUM(a.product_count) product_count
  516. FROM `tz_order_refund_sku` a
  517. LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
  518. LEFT JOIN tz_order c on b.order_number=c.order_number
  519. LEFT JOIN tz_sku d on a.sku_id=d.sku_id
  520. LEFT JOIN tz_user e on b.user_id=e.user_id
  521. WHERE return_money_sts=70
  522. <if test="po.startTime != null and po.startTime != ''">
  523. and b.apply_time&gt;= #{po.startTime}
  524. </if>
  525. <if test="po.endTime != null and po.endTime != ''">
  526. and b.apply_time&lt;= #{po.endTime}
  527. </if>
  528. and c.channel_id in
  529. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  530. #{id}
  531. </foreach>
  532. <if test="po.skuId != null">
  533. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  534. </if>
  535. <if test="po.skuName != null and po.skuName != ''">
  536. AND d.sku_name like concat('%',#{po.skuName} ,'%')
  537. </if>
  538. <if test="po.spec != null and po.spec != ''">
  539. AND d.spec like concat('%',#{po.spec} ,'%')
  540. </if>
  541. <if test="po.userAttrType != null and po.userAttrType != 0">
  542. AND e.user_attr_type=#{po.userAttrType}
  543. </if>
  544. GROUP BY a.sku_id) d on a.sku_id = d.sku_id
  545. WHERE b.is_payed=1
  546. <if test="po.startTime != null and po.startTime != ''">
  547. and a.rec_time&gt;= #{po.startTime}
  548. </if>
  549. <if test="po.endTime != null and po.endTime != ''">
  550. and a.rec_time&lt;= #{po.endTime}
  551. </if>
  552. and b.channel_id in
  553. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  554. #{id}
  555. </foreach>
  556. <if test="po.skuId != null">
  557. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  558. </if>
  559. <if test="po.skuName != null and po.skuName != ''">
  560. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  561. </if>
  562. <if test="po.spec != null and po.spec != ''">
  563. AND c.spec like concat('%',#{po.spec} ,'%')
  564. </if>
  565. <if test="po.userAttrType != null and po.userAttrType != 0">
  566. AND e.user_attr_type=#{po.userAttrType}
  567. </if>
  568. GROUP BY a.sku_id HAVING prod_count>0
  569. </select>
  570. <select id="skuStatisticsList2" resultType="com.yami.shop.bean.vo.SkuStatisticsVo">
  571. SELECT a.prod_id,a.sku_id,a.sku_name,c.spec,TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2)
  572. price,IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0) as prod_count,
  573. TRUNCATE(IFNULL(SUM(a.price*a.prod_count)/SUM(a.prod_count),0),2) *
  574. (IFNULL(SUM(a.prod_count),0)-IFNULL(d.product_count,0)) total
  575. FROM tz_order_item a
  576. LEFT JOIN tz_order b on a.order_number=b.order_number
  577. LEFT JOIN tz_sku c on a.sku_id=c.sku_id
  578. LEFT JOIN tz_user e on b.user_id=e.user_id
  579. LEFT JOIN (SELECT a.sku_id,SUM(a.product_count) product_count
  580. FROM `tz_order_refund_sku` a
  581. LEFT JOIN tz_order_refund b on a.order_refund_id=b.refund_id
  582. LEFT JOIN tz_order c on b.order_number=c.order_number
  583. LEFT JOIN tz_sku d on a.sku_id=d.sku_id
  584. LEFT JOIN tz_user e on b.user_id=e.user_id
  585. WHERE return_money_sts=70
  586. <if test="po.startTime != null and po.startTime != ''">
  587. and b.apply_time&gt;= #{po.startTime}
  588. </if>
  589. <if test="po.endTime != null and po.endTime != ''">
  590. and b.apply_time&lt;= #{po.endTime}
  591. </if>
  592. and c.channel_id in
  593. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  594. #{id}
  595. </foreach>
  596. <if test="po.skuId != null">
  597. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  598. </if>
  599. <if test="po.skuName != null and po.skuName != ''">
  600. AND d.sku_name like concat('%',#{po.skuName} ,'%')
  601. </if>
  602. <if test="po.spec != null and po.spec != ''">
  603. AND d.spec like concat('%',#{po.spec} ,'%')
  604. </if>
  605. <if test="po.userAttrType != null and po.userAttrType != 0">
  606. AND e.user_attr_type=#{po.userAttrType}
  607. </if>
  608. GROUP BY a.sku_id) d on a.sku_id = d.sku_id
  609. WHERE b.is_payed=1
  610. <if test="po.startTime != null and po.startTime != ''">
  611. and a.rec_time&gt;= #{po.startTime}
  612. </if>
  613. <if test="po.endTime != null and po.endTime != ''">
  614. and a.rec_time&lt;= #{po.endTime}
  615. </if>
  616. and b.channel_id in
  617. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  618. #{id}
  619. </foreach>
  620. <if test="po.skuId != null">
  621. AND a.sku_id like concat('%',#{po.skuId} ,'%')
  622. </if>
  623. <if test="po.skuName != null and po.skuName != ''">
  624. AND a.sku_name like concat('%',#{po.skuName} ,'%')
  625. </if>
  626. <if test="po.spec != null and po.spec != ''">
  627. AND c.spec like concat('%',#{po.spec} ,'%')
  628. </if>
  629. <if test="po.userAttrType != null and po.userAttrType != 0">
  630. AND e.user_attr_type=#{po.userAttrType}
  631. </if>
  632. GROUP BY a.sku_id HAVING prod_count>0
  633. </select>
  634. <select id="freightStatisticsList" resultType="com.yami.shop.bean.vo.FreightStatisticsVo">
  635. SELECT @row_number := @row_number + 1 AS sort,a.pay_time,CONCAT(b.receiver,' ',b.mobile) receiver,a.dvy_flow_id delivery_no,b.address to_address,a.freight_amount money,a.order_number order_no,
  636. CASE WHEN a.dvy_type=1 THEN '邮政'
  637. WHEN a.dvy_type=3 THEN '麦芽田-闪送'
  638. ELSE
  639. '其他'
  640. END delivery
  641. FROM (SELECT @row_number := 0) sort,
  642. tz_order a
  643. LEFT JOIN tz_user_addr_order b on a.addr_order_id =b.addr_order_id
  644. LEFT JOIN tz_user e on a.user_id=e.user_id
  645. WHERE a.is_payed=1 and a.hb_order_status not in(0,60)
  646. and a.channel_id in
  647. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  648. #{id}
  649. </foreach>
  650. <if test="po.delivery != null">
  651. and a.dvy_type=#{po.delivery}
  652. </if>
  653. <if test="po.receiver != null and po.receiver != ''">
  654. AND b.receiver like concat('%',#{po.receiver} ,'%')
  655. </if>
  656. <if test="po.mobile != null and po.mobile != ''">
  657. AND b.mobile like concat('%',#{po.mobile} ,'%')
  658. </if>
  659. <if test="po.deliveryNo != null and po.deliveryNo != ''">
  660. AND a.dvy_flow_id like concat('%',#{po.deliveryNo} ,'%')
  661. </if>
  662. <if test="po.toAddress != null and po.toAddress != ''">
  663. AND b.address like concat('%',#{po.toAddress} ,'%')
  664. </if>
  665. <if test="po.orderNo != null and po.orderNo != ''">
  666. AND a.order_number like concat('%',#{po.orderNo} ,'%')
  667. </if>
  668. <if test="po.userAttrType != null and po.userAttrType != 0">
  669. AND e.user_attr_type=#{po.userAttrType}
  670. </if>
  671. <if test="po.startTime != null and po.startTime != ''">
  672. and a.pay_time&gt;= #{po.startTime}
  673. </if>
  674. <if test="po.endTime != null and po.endTime != ''">
  675. and a.pay_time&lt;= #{po.endTime}
  676. </if>
  677. </select>
  678. <select id="freightStatisticsList2" resultType="com.yami.shop.bean.vo.FreightStatisticsVo">
  679. SELECT @row_number := @row_number + 1 AS sort,a.pay_time,CONCAT(b.receiver,' ',b.mobile) receiver,a.dvy_flow_id delivery_no,b.address to_address,a.freight_amount money,a.order_number order_no,
  680. CASE WHEN a.dvy_type=1 THEN '邮政'
  681. WHEN a.dvy_type=3 THEN '麦芽田-闪送'
  682. ELSE
  683. '其他'
  684. END delivery
  685. FROM (SELECT @row_number := 0) sort,
  686. tz_order a
  687. LEFT JOIN tz_user_addr_order b on a.addr_order_id =b.addr_order_id
  688. LEFT JOIN tz_user e on a.user_id=e.user_id
  689. WHERE a.is_payed=1 and a.hb_order_status not in(0,60)
  690. and a.channel_id in
  691. <foreach collection="po.channelIds" item="id" open="(" separator="," close=")">
  692. #{id}
  693. </foreach>
  694. <if test="po.delivery != null">
  695. and a.dvy_type=#{po.delivery}
  696. </if>
  697. <if test="po.receiver != null and po.receiver != ''">
  698. AND b.receiver like concat('%',#{po.receiver} ,'%')
  699. </if>
  700. <if test="po.mobile != null and po.mobile != ''">
  701. AND b.mobile like concat('%',#{po.mobile} ,'%')
  702. </if>
  703. <if test="po.deliveryNo != null and po.deliveryNo != ''">
  704. AND a.dvy_flow_id like concat('%',#{po.deliveryNo} ,'%')
  705. </if>
  706. <if test="po.toAddress != null and po.toAddress != ''">
  707. AND b.address like concat('%',#{po.toAddress} ,'%')
  708. </if>
  709. <if test="po.orderNo != null and po.orderNo != ''">
  710. AND a.order_number like concat('%',#{po.orderNo} ,'%')
  711. </if>
  712. <if test="po.userAttrType != null and po.userAttrType != 0">
  713. AND e.user_attr_type=#{po.userAttrType}
  714. </if>
  715. <if test="po.startTime != null and po.startTime != ''">
  716. and a.pay_time&gt;= #{po.startTime}
  717. </if>
  718. <if test="po.endTime != null and po.endTime != ''">
  719. and a.pay_time&lt;= #{po.endTime}
  720. </if>
  721. </select>
  722. </mapper>