OrderMapper.xml 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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.OrderMapper">
  4. <resultMap id="BaseResultMap" type="com.yami.shop.bean.model.Order">
  5. <id column="order_id" jdbcType="BIGINT" property="orderId"/>
  6. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  7. <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
  8. <result column="channel_id" jdbcType="BIGINT" property="channelId"/>
  9. <result column="channel_name" jdbcType="VARCHAR" property="channelName"/>
  10. <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
  11. <result column="user_id" jdbcType="VARCHAR" property="userId"/>
  12. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  13. <result column="total" jdbcType="DECIMAL" property="total"/>
  14. <result column="actual_total" jdbcType="DECIMAL" property="actualTotal"/>
  15. <result column="pay_type" jdbcType="INTEGER" property="payType"/>
  16. <result column="remarks" jdbcType="VARCHAR" property="remarks"/>
  17. <result column="hb_order_status" jdbcType="INTEGER" property="hbOrderStatus"/>
  18. <result column="dvy_status" jdbcType="VARCHAR" property="dvyStatus"/>
  19. <result column="dvy_type" jdbcType="VARCHAR" property="dvyType"/>
  20. <result column="dvy_id" jdbcType="BIGINT" property="dvyId"/>
  21. <result column="dvy_flow_id" jdbcType="VARCHAR" property="dvyFlowId"/>
  22. <result column="freight_amount" jdbcType="DECIMAL" property="freightAmount"/>
  23. <result column="addr_order_id" jdbcType="BIGINT" property="addrOrderId"/>
  24. <result column="product_nums" jdbcType="INTEGER" property="productNums"/>
  25. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  26. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  27. <result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/>
  28. <result column="dvy_time" jdbcType="TIMESTAMP" property="dvyTime"/>
  29. <result column="finally_time" jdbcType="TIMESTAMP" property="finallyTime"/>
  30. <result column="cancel_time" jdbcType="TIMESTAMP" property="cancelTime"/>
  31. <result column="is_payed" jdbcType="BIT" property="isPayed"/>
  32. <result column="delete_status" jdbcType="INTEGER" property="deleteStatus"/>
  33. <result column="refund_status" jdbcType="INTEGER" property="refundStatus"/>
  34. <result column="close_type" jdbcType="INTEGER" property="closeType"/>
  35. <result column="user_mobile" jdbcType="VARCHAR" property="userMobile"/>
  36. <result column="receiver" jdbcType="VARCHAR" property="receiver"/>
  37. <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
  38. </resultMap>
  39. <resultMap id="MyOrderMap" type="com.yami.shop.bean.app.dto.MyOrderDto">
  40. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  41. <result column="actual_total" jdbcType="DECIMAL" property="actualTotal"/>
  42. <result column="order_type" jdbcType="VARCHAR" property="orderType"/>
  43. <result column="refund_type" jdbcType="INTEGER" property="refundType"/>
  44. <result column="return_money_sts" jdbcType="INTEGER" property="returnMoneySts"/>
  45. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  46. <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
  47. <result column="latitude" property="latitude"/>
  48. <result column="longitude" property="longitude"/>
  49. <result column="create_time" property="createTime"/>
  50. <result column="hb_order_status" property="hbOrderStatus"/>
  51. <result column="hb_logistic_status" property="hbLogisticStatus"/>
  52. <result column="offset_points" property="offsetPoints"/>
  53. <result column="pay_time" property="payTime"/>
  54. <result column="dvy_type" property="dvyType"/>
  55. <collection property="orderItemDtos" ofType="com.yami.shop.bean.app.dto.MyOrderItemDto">
  56. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  57. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  58. <result column="prod_id" jdbcType="BIGINT" property="prodId"/>
  59. <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
  60. <result column="prod_count" jdbcType="INTEGER" property="prodCount"/>
  61. <result column="use_score" jdbcType="INTEGER" property="useScore"/>
  62. <result column="price" jdbcType="DECIMAL" property="price"/>
  63. <result column="sku_name" jdbcType="VARCHAR" property="skuName"/>
  64. <result column="order_item_id" property="orderItemId"/>
  65. <result column="comm_sts" property="commSts"/>
  66. <result column="rec_time" property="recTime"/>
  67. </collection>
  68. </resultMap>
  69. <resultMap id="MyOrderItemMap" type="com.yami.shop.bean.app.dto.MyOrderItemDto">
  70. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  71. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  72. <result column="prod_id" jdbcType="BIGINT" property="prodId"/>
  73. <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
  74. <result column="prod_count" jdbcType="INTEGER" property="prodCount"/>
  75. <result column="use_score" jdbcType="INTEGER" property="useScore"/>
  76. <result column="price" jdbcType="DECIMAL" property="price"/>
  77. <result column="sku_name" jdbcType="VARCHAR" property="skuName"/>
  78. <result column="order_item_id" property="orderItemId"/>
  79. <result column="comm_sts" property="commSts"/>
  80. <result column="rec_time" property="recTime"/>
  81. </resultMap>
  82. <resultMap type="com.yami.shop.bean.model.Order" id="orderAndOrderItemMap">
  83. <id column="order_id" jdbcType="BIGINT" property="orderId"/>
  84. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  85. <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
  86. <result column="channel_id" jdbcType="BIGINT" property="channelId"/>
  87. <result column="channel_name" jdbcType="VARCHAR" property="channelName"/>
  88. <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
  89. <result column="user_id" jdbcType="VARCHAR" property="userId"/>
  90. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  91. <result column="hb_order_status" jdbcType="VARCHAR" property="hbOrderStatus"/>
  92. <result column="dvy_status" jdbcType="VARCHAR" property="dvyStatus"/>
  93. <result column="total" jdbcType="DECIMAL" property="total"/>
  94. <result column="actual_total" jdbcType="DECIMAL" property="actualTotal"/>
  95. <result column="pay_type" jdbcType="INTEGER" property="payType"/>
  96. <result column="remarks" jdbcType="VARCHAR" property="remarks"/>
  97. <result column="dvy_type" jdbcType="VARCHAR" property="dvyType"/>
  98. <result column="dvy_id" jdbcType="BIGINT" property="dvyId"/>
  99. <result column="dvy_flow_id" jdbcType="VARCHAR" property="dvyFlowId"/>
  100. <result column="freight_amount" jdbcType="DECIMAL" property="freightAmount"/>
  101. <result column="platform_amount" jdbcType="DECIMAL" property="platformAmount"/>
  102. <result column="addr_order_id" jdbcType="BIGINT" property="addrOrderId"/>
  103. <result column="product_nums" jdbcType="INTEGER" property="productNums"/>
  104. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  105. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  106. <result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/>
  107. <result column="dvy_time" jdbcType="TIMESTAMP" property="dvyTime"/>
  108. <result column="finally_time" jdbcType="TIMESTAMP" property="finallyTime"/>
  109. <result column="cancel_time" jdbcType="TIMESTAMP" property="cancelTime"/>
  110. <result column="is_payed" jdbcType="BIT" property="isPayed"/>
  111. <result column="hb_order_status" jdbcType="INTEGER" property="hbOrderStatus"/>
  112. <result column="delete_status" jdbcType="INTEGER" property="deleteStatus"/>
  113. <result column="refund_status" jdbcType="INTEGER" property="refundStatus"/>
  114. <result column="order_type" jdbcType="INTEGER" property="orderType"/>
  115. <result column="close_type" jdbcType="INTEGER" property="closeType"/>
  116. <collection property="orderItems" ofType="com.yami.shop.bean.model.OrderItem">
  117. <id column="order_item_id" jdbcType="BIGINT" property="orderItemId"/>
  118. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  119. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  120. <result column="prod_id" jdbcType="BIGINT" property="prodId"/>
  121. <result column="sku_id" jdbcType="BIGINT" property="skuId"/>
  122. <result column="prod_count" jdbcType="INTEGER" property="prodCount"/>
  123. <result column="use_score" jdbcType="INTEGER" property="useScore"/>
  124. <result column="oi_prod_name" jdbcType="VARCHAR" property="prodName"/>
  125. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  126. <result column="price" jdbcType="DECIMAL" property="price"/>
  127. <result column="user_id" jdbcType="VARCHAR" property="userId"/>
  128. <result column="product_total_amount" jdbcType="DECIMAL" property="productTotalAmount"/>
  129. <!--<result column="platform_amount" jdbcType="DECIMAL" property="platformAmount"/>-->
  130. <result column="rec_time" jdbcType="TIMESTAMP" property="recTime"/>
  131. <result column="comm_sts" jdbcType="INTEGER" property="commSts"/>
  132. <result column="distribution_card_no" property="distributionCardNo"/>
  133. <result column="basket_date" property="basketDate"/>
  134. <result column="share_reduce" property="shareReduce"/>
  135. <result column="distribution_amount" property="distributionAmount"/>
  136. <result column="distribution_parent_amount" property="distributionParentAmount"/>
  137. <result column="return_money_sts" property="returnMoneySts"/>
  138. <result column="oi_actual_total" property="actualTotal"/>
  139. </collection>
  140. </resultMap>
  141. <resultMap type="com.yami.shop.bean.model.Order" id="orderAndOrderItemAndUserAddrMap">
  142. <id column="order_id" jdbcType="BIGINT" property="orderId"/>
  143. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  144. <result column="order_prod_name" jdbcType="VARCHAR" property="prodName"/>
  145. <result column="user_id" jdbcType="VARCHAR" property="userId"/>
  146. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  147. <result column="total" jdbcType="DECIMAL" property="total"/>
  148. <result column="actual_total" jdbcType="DECIMAL" property="actualTotal"/>
  149. <result column="pay_type" jdbcType="INTEGER" property="payType"/>
  150. <result column="remarks" jdbcType="VARCHAR" property="remarks"/>
  151. <result column="hb_order_status" jdbcType="INTEGER" property="hbOrderStatus"/>
  152. <result column="dvy_type" jdbcType="VARCHAR" property="dvyType"/>
  153. <result column="dvy_id" jdbcType="BIGINT" property="dvyId"/>
  154. <result column="nick_name" jdbcType="BIGINT" property="nickName"/>
  155. <result column="dvy_flow_id" jdbcType="VARCHAR" property="dvyFlowId"/>
  156. <result column="freight_amount" jdbcType="DECIMAL" property="freightAmount"/>
  157. <result column="order_type" jdbcType="INTEGER" property="orderType"/>
  158. <result column="addr_order_id" jdbcType="BIGINT" property="addrOrderId"/>
  159. <result column="product_nums" jdbcType="INTEGER" property="productNums"/>
  160. <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
  161. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  162. <result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/>
  163. <result column="dvy_time" jdbcType="TIMESTAMP" property="dvyTime"/>
  164. <result column="finally_time" jdbcType="TIMESTAMP" property="finallyTime"/>
  165. <result column="cancel_time" jdbcType="TIMESTAMP" property="cancelTime"/>
  166. <result column="is_payed" jdbcType="BIT" property="isPayed"/>
  167. <result column="delete_status" jdbcType="INTEGER" property="deleteStatus"/>
  168. <result column="pay_score" jdbcType="INTEGER" property="score"/>
  169. <result column="refund_status" jdbcType="INTEGER" property="refundStatus"/>
  170. <result column="close_type" jdbcType="INTEGER" property="closeType"/>
  171. <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
  172. <result column="pay_score" jdbcType="INTEGER" property="payScore"/>
  173. <result column="user_mobile" jdbcType="VARCHAR" property="userMobile"/>
  174. <result column="receiver" jdbcType="VARCHAR" property="receiver"/>
  175. <result column="qnh_order_id" jdbcType="VARCHAR" property="qnhOrderId"/>
  176. <result column="qnh_order_status" jdbcType="VARCHAR" property="qnhOrderStatus"/>
  177. <result column="dvy_status" jdbcType="INTEGER" property="dvyStatus"/>
  178. <association property="userAddrOrder" javaType="com.yami.shop.bean.model.UserAddrOrder">
  179. <id column="addr_order_id" jdbcType="BIGINT" property="addrOrderId"/>
  180. <result column="province" jdbcType="VARCHAR" property="province"/>
  181. <result column="city" jdbcType="VARCHAR" property="city"/>
  182. <result column="area" jdbcType="VARCHAR" property="area"/>
  183. <result column="addr" jdbcType="VARCHAR" property="addr"/>
  184. <result column="mobile" jdbcType="VARCHAR" property="mobile"/>
  185. <result column="receiver" jdbcType="VARCHAR" property="receiver"/>
  186. <result column="address" jdbcType="VARCHAR" property="address"/>
  187. <result column="address_name" jdbcType="VARCHAR" property="addressName"/>
  188. <result column="address_detail" jdbcType="VARCHAR" property="addrDetail"/>
  189. </association>
  190. <collection property="orderItems" ofType="com.yami.shop.bean.model.OrderItem">
  191. <id column="order_item_id" jdbcType="BIGINT" property="orderItemId"/>
  192. <result column="shop_id" jdbcType="BIGINT" property="shopId"/>
  193. <result column="order_number" jdbcType="VARCHAR" property="orderNumber"/>
  194. <result column="prod_id" jdbcType="BIGINT" property="prodId"/>
  195. <!-- <result column="prod_name" jdbcType="BIGINT" property="prodName"/>-->
  196. <result column="sku_id" jdbcType="BIGINT" property="skuId"/>
  197. <result column="prod_count" jdbcType="INTEGER" property="prodCount"/>
  198. <result column="use_score" jdbcType="INTEGER" property="useScore"/>
  199. <result column="prod_name" jdbcType="VARCHAR" property="prodName"/>
  200. <result column="pic" jdbcType="VARCHAR" property="pic"/>
  201. <result column="price" jdbcType="DECIMAL" property="price"/>
  202. <result column="user_id" jdbcType="VARCHAR" property="userId"/>
  203. <result column="oi_actual_total" jdbcType="DECIMAL" property="actualTotal"/>
  204. <result column="product_total_amount" jdbcType="DECIMAL" property="productTotalAmount"/>
  205. <result column="rec_time" jdbcType="TIMESTAMP" property="recTime"/>
  206. <result column="comm_sts" jdbcType="INTEGER" property="commSts"/>
  207. <result column="item_status" jdbcType="INTEGER" property="status"/>
  208. <result column="distribution_card_no" property="distributionCardNo"/>
  209. <result column="basket_date" property="basketDate"/>
  210. <result column="share_reduce" property="shareReduce"/>
  211. <result column="platform_share_reduce" property="platformShareReduce"/>
  212. <result column="oi_return_money_sts" property="returnMoneySts"/>
  213. <result column="oi_status" property="status"/>
  214. </collection>
  215. </resultMap>
  216. <select id="getOrderByOrderNumber" resultType="com.yami.shop.bean.model.Order">
  217. select * from tz_order o where o.order_number = #{orderNumber}
  218. </select>
  219. <select id="listUnRefundOrderAndOrderItems" resultMap="orderAndOrderItemMap">
  220. select o.*,oi.*,tor.return_money_sts,oi.prod_name oi_prod_name,oi.actual_total as oi_actual_total from tz_order o
  221. join tz_order_item oi on o.order_number = oi.order_number
  222. left join tz_order_refund tor on tor.order_id = o.order_id
  223. where o.hb_order_status = #{orderStatus} and (refund_status IS NULL OR o.refund_status &lt;&gt; 1)
  224. and o.dvy_time &lt; #{lessThanUpdateTime}
  225. </select>
  226. <select id="selectCancelOrders" resultMap="orderAndOrderItemMap">
  227. select o.*,oi.*,oi.prod_name oi_prod_name,oi.actual_total as oi_actual_total from tz_order o
  228. join tz_order_item oi on o.order_number = oi.order_number
  229. where o.hb_order_status = #{orderStatus} and o.create_time &lt; #{lessThanUpdateTime}
  230. </select>
  231. <update id="cancelOrders">
  232. update tz_order set `hb_order_status`=60,close_type = 1,cancel_reason = #{cancelReason}, cancel_time = NOW(),update_time=NOW(),close_type=4 where order_id in
  233. <foreach collection="orders" item="order" open="(" close=")" separator=",">
  234. #{order.orderId}
  235. </foreach>
  236. </update>
  237. <update id="receiptOrder">
  238. update tz_order set `hb_order_status`= 80,finally_time = NOW(),update_time=NOW() where order_id in
  239. <foreach collection="orders" item="order" open="(" close=")" separator=",">
  240. #{order.orderId}
  241. </foreach>
  242. </update>
  243. <update id="updateByToPaySuccess">
  244. update tz_order set `hb_order_status` = 20,is_payed =1,update_time=NOW(),pay_time=NOW(),pay_type =#{payType} where dvy_type=3 and
  245. order_number in
  246. <foreach collection="orderNumbers" item="orderNumber" separator="," open="(" close=")">
  247. #{orderNumber}
  248. </foreach>
  249. </update>
  250. <update id="updateByToPaySuccessDelivery">
  251. update tz_order set `hb_order_status` = 1,is_payed =1,update_time=NOW(),pay_time=NOW(),pay_type =#{payType} where dvy_type=1 and
  252. order_number in
  253. <foreach collection="orderNumbers" item="orderNumber" separator="," open="(" close=")">
  254. #{orderNumber}
  255. </foreach>
  256. </update>
  257. <select id="listOrdersDetialByOrder" resultMap="orderAndOrderItemAndUserAddrMap">
  258. select o.*,oi.*,oi.prod_name as item_prod_name,o.prod_name as order_prod_name,uao.* ,o.hb_order_status as oi_status
  259. from tz_order o
  260. left join tz_order_item oi on o.order_number = oi.order_number
  261. left join tz_user_addr_order uao on o.addr_order_id = uao.addr_order_id
  262. where o.order_id in (
  263. select * from (
  264. select o.order_id from tz_order o
  265. left join tz_shop_detail sd on o.shop_id = sd.shop_id
  266. where 1=1
  267. <if test="order.orderNumber != null and order.orderNumber != ''">
  268. and o.order_number like concat('%',#{order.orderNumber},'%')
  269. </if>
  270. <if test="order.hb_order_status != null">
  271. and o.hb_order_status = #{order.orderStatus}
  272. </if>
  273. <if test="order.shopId != null">
  274. and o.shop_id = #{order.shopId}
  275. </if>
  276. <if test="order.isPayed != null">
  277. and o.is_payed = #{order.isPayed}
  278. and o.hb_order_status != 60
  279. </if>
  280. <if test="startTime != null">
  281. and o.create_time &gt; #{startTime}
  282. </if>
  283. <if test="endTime != null">
  284. and o.create_time &lt; #{endTime}
  285. </if>
  286. <if test="order.shopName != null">
  287. and sd.shop_name like concat("%",#{order.shopName},"%")
  288. </if>
  289. ORDER BY o.create_time DESC
  290. )
  291. AS limittable) ORDER BY o.create_time DESC
  292. </select>
  293. <select id="getOrderCountByShopId" resultType="com.yami.shop.bean.param.OrderPayParam">
  294. SELECT SUM(actual_total) as payActualTotal,COUNT(DISTINCT user_id) as payUserCount,
  295. COUNT(*) as payOrderCount
  296. FROM tz_order o
  297. <where>
  298. <if test="shopId != null">
  299. and o.shop_id = #{shopId}
  300. </if>
  301. <if test="startTime != null">
  302. and o.pay_time &gt;= #{startTime}
  303. </if>
  304. <if test="endTime != null">
  305. and o.pay_time &lt;= #{endTime}
  306. </if>
  307. AND o.is_payed =1
  308. </where>
  309. </select>
  310. <select id="getPayOrderByTime" resultType="com.yami.shop.bean.param.OrderPayParam">
  311. SELECT dates, MAX(orderCount) AS payOrderCount,MAX(payActualTotal) as payActualTotal FROM(
  312. SELECT @cdate := DATE_ADD(@cdate,INTERVAL - 1 DAY) dates ,0 AS 'orderCount',0 AS 'payActualTotal'
  313. FROM (SELECT @cdate :=DATE_ADD(CURDATE(),INTERVAL + 1 DAY) FROM tz_user) t1
  314. <where>
  315. <if test="startTime != null">
  316. and @cdate >= #{startTime}
  317. </if>
  318. </where>
  319. UNION ALL
  320. SELECT DATE_FORMAT(o.pay_time, '%Y-%m-%d') AS dates,COUNT(*) AS orderCount,SUM(actual_total) AS payActualTotal
  321. FROM tz_order o
  322. <where>
  323. <if test="shopId != null">
  324. and o.shop_id = #{shopId}
  325. </if>
  326. <if test="startTime != null">
  327. and o.pay_time &gt;= #{startTime}
  328. </if>
  329. <if test="endTime != null">
  330. and o.pay_time &lt;= #{endTime}
  331. </if>
  332. AND o.is_payed =1
  333. </where>
  334. GROUP BY dates) _tmpAllTable GROUP BY dates
  335. ORDER BY dates
  336. </select>
  337. <select id="getActualTotalByHour" resultType="com.yami.shop.bean.param.OrderPayParam">
  338. SELECT DATE_FORMAT(o.pay_time, '%k') AS dates,SUM(actual_total) as payActualTotal
  339. FROM tz_order o
  340. <where>
  341. <if test="shopId != null">
  342. and o.shop_id = #{shopId}
  343. </if>
  344. <if test="startTime != null">
  345. and o.pay_time &gt;= #{startTime}
  346. </if>
  347. <if test="endTime != null">
  348. and o.pay_time &lt;= #{endTime}
  349. </if>
  350. AND o.is_payed =1
  351. </where>
  352. GROUP BY dates
  353. </select>
  354. <select id="getActualTotalByDay" resultType="com.yami.shop.bean.param.OrderPayParam">
  355. SELECT DATE_FORMAT(o.pay_time, '%Y-%m-%d') AS payDay,SUM(actual_total) as payActualTotal
  356. FROM tz_order o
  357. <where>
  358. <if test="shopId != null">
  359. and o.shop_id = #{shopId}
  360. </if>
  361. <if test="startTime != null">
  362. and o.pay_time &gt;= #{startTime}
  363. </if>
  364. <if test="endTime != null">
  365. and o.pay_time &lt;= #{endTime}
  366. </if>
  367. AND o.is_payed =1
  368. </where>
  369. GROUP BY payDay
  370. </select>
  371. <select id="listOrdersDetialByOrderParam" resultMap="orderAndOrderItemAndUserAddrMap">
  372. SELECT *,oi.prod_name as item_prod_name,oi.actual_total as oi_actual_total,IF(r.refund_type = 2,r.return_money_sts,IF(ar.refund_type = 1,ar.return_money_sts,NULL)) AS oi_return_money_sts,
  373. temp.prod_name as order_prod_name,temp.hb_order_status as oi_status, IF(os.pay_score IS NULL,0,os.pay_score) as pay_score
  374. FROM
  375. (
  376. SELECT o.*,sd.shop_name,uao.receiver,uao.mobile,u.user_mobile,u.nick_name FROM tz_order o
  377. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  378. LEFT JOIN tz_user_addr_order uao ON o.addr_order_id = uao.addr_order_id
  379. LEFT JOIN tz_user u on u.user_id=o.user_id
  380. <where>
  381. <!-- <if test="orderParam.type!=null and orderParam.type==1 and orderParam.content != null and orderParam.content != ''">-->
  382. <!-- and o.order_number = #{orderParam.content}-->
  383. <!-- </if>-->
  384. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  385. and o.order_number = #{orderParam.orderNumber}
  386. </if>
  387. <!-- <if test="orderParam.type!=null and orderParam.type==2 and orderParam.orderNumber != null and orderParam.orderNumber != ''">-->
  388. <!-- and o.order_number = #{orderParam.orderNumber}-->
  389. <!-- </if>-->
  390. <!-- <if test="orderParam.type!=null and orderParam.type==4 and orderParam.content != null and orderParam.content != ''">-->
  391. <!-- and u.nick_name LIKE concat("%",#{orderParam.content},"%")-->
  392. <!-- </if>-->
  393. <!-- <if test="orderParam.type!=null and orderParam.type==5 and orderParam.content != null and orderParam.content != ''">-->
  394. <!-- and u.user_mobile LIKE concat("%",#{orderParam.content},"%")-->
  395. <!-- </if>-->
  396. <!-- <if test="orderParam.type!=null and orderParam.type==6 and orderParam.content != null and orderParam.content != ''">-->
  397. <!-- and u.dvy_flow_id = #{orderParam.content}-->
  398. <!-- </if>-->
  399. <if test="orderParam.hbOrderStatus != null">
  400. and o.hb_order_status = #{orderParam.hbOrderStatus}
  401. </if>
  402. <!-- <if test="orderParam.payType != null">-->
  403. <!-- and o.pay_type = #{orderParam.payType}-->
  404. <!-- </if>-->
  405. <if test="orderParam.dvyType != null">
  406. and o.dvy_type = #{orderParam.dvyType}
  407. </if>
  408. <if test="orderParam.channelId != null">
  409. and o.channel_id = #{orderParam.channelId}
  410. </if>
  411. <if test="orderParam.shopId != null">
  412. and o.shop_id = #{orderParam.shopId}
  413. </if>
  414. <if test="orderParam.isPayed != null">
  415. and o.is_payed = #{orderParam.isPayed}
  416. and o.hb_order_status != 60
  417. </if>
  418. <if test="orderParam.startTime != null">
  419. and o.create_time &gt; #{orderParam.startTime}
  420. </if>
  421. <if test="orderParam.endTime != null">
  422. and o.create_time &lt; #{orderParam.endTime}
  423. </if>
  424. <if test="orderParam.orderType != null">
  425. and o.order_type = #{orderParam.orderType}
  426. </if>
  427. <if test="orderParam.orderType == null">
  428. and (o.order_type <![CDATA[ <> ]]> 3 OR o.order_type IS NULL)
  429. </if>
  430. <if test="orderParam.shopName != null">
  431. and sd.shop_name LIKE concat("%",#{orderParam.shopName},"%")
  432. </if>
  433. <if test="orderParam.refundStatus == 0">
  434. and o.refund_status IS NULL
  435. </if>
  436. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  437. and o.refund_status = #{orderParam.refundStatus}
  438. </if>
  439. <if test="orderParam.prodName != null">
  440. and o.prod_name LIKE concat("%",#{orderParam.prodName},"%")
  441. </if>
  442. <!-- <if test="orderParam.type!=null and orderParam.type==2 and orderParam.content != null and orderParam.content != ''">-->
  443. <!-- and uao.receiver LIKE concat("%",#{orderParam.content},"%")-->
  444. <!-- </if>-->
  445. <!-- <if test="orderParam.type!=null and orderParam.type==3 and orderParam.content != null and orderParam.content != ''">-->
  446. <!-- and uao.mobile LIKE concat("%",#{orderParam.content},"%")-->
  447. <!-- </if>-->
  448. </where>
  449. ORDER BY o.create_time DESC
  450. LIMIT #{adapter.begin} , #{adapter.size}
  451. ) AS temp
  452. LEFT JOIN tz_order_item oi ON temp.order_number = oi.order_number
  453. <!--连接单个物品退款的退款信息-->
  454. LEFT JOIN tz_order_refund r ON r.order_item_id = oi.order_item_id AND r.refund_type = 2 AND r.return_money_sts &gt; 0 AND r.return_money_sts &lt; 6
  455. <!--连接整单退款的退款信息-->
  456. LEFT JOIN tz_order_refund ar ON ar.order_id = temp.order_id AND ar.refund_type = 1 AND ar.return_money_sts &gt; 0 AND ar.return_money_sts &lt; 6
  457. LEFT JOIN tz_order_settlement os ON temp.order_number = os.order_number
  458. ORDER BY temp.create_time DESC
  459. </select>
  460. <select id="deliverList" resultMap="BaseResultMap">
  461. SELECT a.*,b.receiver,b.mobile user_mobile,c.shop_name FROM tz_order a
  462. LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
  463. LEFT JOIN tz_shop_detail c on a.shop_id=c.shop_id
  464. <where>
  465. a.dvy_type=1
  466. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  467. and a.order_number = #{orderParam.orderNumber}
  468. </if>
  469. <if test="orderParam.shopId != null">
  470. and a.shop_id = #{orderParam.shopId}
  471. </if>
  472. <if test="orderParam.startTime != null">
  473. and a.create_time &gt; #{orderParam.startTime}
  474. </if>
  475. <if test="orderParam.endTime != null">
  476. and a.create_time &lt; #{orderParam.endTime}
  477. </if>
  478. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  479. and a.refund_status = #{orderParam.refundStatus}
  480. </if>
  481. <if test="orderParam.receiver != null">
  482. and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
  483. </if>
  484. <if test="orderParam.userMobile != null">
  485. and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
  486. </if>
  487. <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
  488. <if test="orderParam.orderStatus == 'all'">
  489. AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
  490. </if>
  491. <if test="orderParam.orderStatus == 'paddingPay'">
  492. AND a.hb_order_status in (0)
  493. </if>
  494. <if test="orderParam.orderStatus == 'paddingShipped'">
  495. AND a.hb_order_status in (1)
  496. </if>
  497. <if test="orderParam.orderStatus == 'paddingReceived'">
  498. AND a.hb_order_status in (20,30,40,70)
  499. </if>
  500. <if test="orderParam.orderStatus == 'completed'">
  501. AND a.hb_order_status in (80)
  502. </if>
  503. <if test="orderParam.orderStatus == 'cancel'">
  504. AND a.hb_order_status in (50,60)
  505. </if>
  506. </if>
  507. </where>
  508. order by a.create_time desc,a.order_id desc
  509. LIMIT #{adapter.begin} , #{adapter.size}
  510. </select>
  511. <select id="deliverListCount" resultType="integer">
  512. SELECT count(1) FROM tz_order a
  513. LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
  514. LEFT JOIN tz_shop_detail c on a.shop_id=c.shop_id
  515. <where>
  516. a.dvy_type=1
  517. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  518. and a.order_number = #{orderParam.orderNumber}
  519. </if>
  520. <if test="orderParam.shopId != null">
  521. and a.shop_id = #{orderParam.shopId}
  522. </if>
  523. <if test="orderParam.startTime != null">
  524. and a.create_time &gt; #{orderParam.startTime}
  525. </if>
  526. <if test="orderParam.endTime != null">
  527. and a.create_time &lt; #{orderParam.endTime}
  528. </if>
  529. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  530. and a.refund_status = #{orderParam.refundStatus}
  531. </if>
  532. <if test="orderParam.receiver != null">
  533. and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
  534. </if>
  535. <if test="orderParam.userMobile != null">
  536. and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
  537. </if>
  538. <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
  539. <if test="orderParam.orderStatus == 'all'">
  540. AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
  541. </if>
  542. <if test="orderParam.orderStatus == 'paddingPay'">
  543. AND a.hb_order_status in (0)
  544. </if>
  545. <if test="orderParam.orderStatus == 'paddingShipped'">
  546. AND a.hb_order_status in (1)
  547. </if>
  548. <if test="orderParam.orderStatus == 'paddingReceived'">
  549. AND a.hb_order_status in (20,30,40,70)
  550. </if>
  551. <if test="orderParam.orderStatus == 'completed'">
  552. AND a.hb_order_status in (80)
  553. </if>
  554. <if test="orderParam.orderStatus == 'cancel'">
  555. AND a.hb_order_status in (50,60)
  556. </if>
  557. </if>
  558. </where>
  559. </select>
  560. <select id="countOrderDetial" resultType="long">
  561. SELECT count(0)
  562. FROM tz_order o
  563. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  564. JOIN tz_user_addr_order uao
  565. ON o.addr_order_id = uao.addr_order_id
  566. <where>
  567. o.delete_status = 0
  568. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  569. and o.order_number = #{orderParam.orderNumber}
  570. </if>
  571. <if test="orderParam.hbOrderStatus != null">
  572. and o.hb_order_status = #{orderParam.hbOrderStatus}
  573. </if>
  574. <if test="orderParam.shopId != null">
  575. and o.shop_id = #{orderParam.shopId}
  576. </if>
  577. <if test="orderParam.channelId != null">
  578. and o.channel_id = #{orderParam.channelId}
  579. </if>
  580. <if test="orderParam.dvyType != null">
  581. and o.dvy_type = #{orderParam.dvyType}
  582. </if>
  583. <if test="orderParam.isPayed != null">
  584. and o.is_payed = #{orderParam.isPayed}
  585. and o.hb_order_status != 60
  586. </if>
  587. <if test="orderParam.startTime != null">
  588. and o.create_time &gt; #{orderParam.startTime}
  589. </if>
  590. <if test="orderParam.endTime != null">
  591. and o.create_time &lt; #{orderParam.endTime}
  592. </if>
  593. <if test="orderParam.orderType != null">
  594. and o.order_type = #{orderParam.orderType}
  595. </if>
  596. <if test="orderParam.orderType == null">
  597. and (o.order_type <![CDATA[ <> ]]> 3 OR o.order_type IS NULL)
  598. </if>
  599. <if test="orderParam.shopName != null">
  600. and sd.shop_name LIKE concat("%",#{orderParam.shopName},"%")
  601. </if>
  602. <if test="orderParam.refundStatus == 0">
  603. and o.refund_status IS NULL
  604. </if>
  605. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  606. and o.refund_status = #{orderParam.refundStatus}
  607. </if>
  608. <if test="orderParam.prodName != null">
  609. and o.prod_name LIKE concat("%",#{orderParam.prodName},"%")
  610. </if>
  611. <if test="orderParam.receiver != null">
  612. and uao.receiver LIKE concat("%",#{orderParam.receiver},"%")
  613. </if>
  614. <if test="orderParam.mobile != null">
  615. and uao.mobile LIKE concat("%",#{orderParam.mobile},"%")
  616. </if>
  617. </where>
  618. </select>
  619. <select id="calculateUserInShopData" resultType="com.yami.shop.bean.distribution.UserShoppingDataDto">
  620. select
  621. count(o.order_number) as expense_number,
  622. ifnull(SUM(o.actual_total),0) as expense_amount
  623. from tz_order o
  624. where o.user_id=#{userId} and o.shop_id = #{shopId} and (o.hb_order_status = 45 or o.hb_order_status = 80)
  625. </select>
  626. <select id="listMyOrderByUserIdAndStatus" resultMap="MyOrderMap">
  627. SELECT
  628. o.order_type,o.actual_total,o.order_number,o.freight_amount,o.create_time,o.order_id,
  629. o.hb_order_status,
  630. o.hb_logistic_status,
  631. o.offset_points,
  632. o.pay_time,
  633. o.dvy_type,
  634. o.comm_sts AS commSts,
  635. (SELECT r.refund_type FROM tz_order_refund r WHERE r.order_id =o.order_id ORDER BY r.update_time DESC LIMIT 0,1) AS refund_type,
  636. (SELECT r.return_money_sts FROM tz_order_refund r WHERE r.order_id =o.order_id ORDER BY r.update_time DESC LIMIT 0,1) AS return_money_sts,
  637. oi.pic,oi.price,oi.prod_name,oi.pic,oi.sku_name,ifnull(oi.use_score,0) as use_score,oi.prod_id,oi.rec_time,oi.prod_count,oi.order_item_id,oi.comm_sts,
  638. sd.shop_id,sd.shop_name,oi.actual_total as oi_actual_total,ad.longitude,ad.latitude
  639. FROM (
  640. SELECT temp.order_type,
  641. temp.hb_order_status,
  642. temp.hb_logistic_status,
  643. temp.offset_points,
  644. temp.pay_time,
  645. temp.dvy_type,
  646. temp.comm_sts,
  647. temp.order_id, temp.create_time, temp.freight_amount,temp.order_number,temp.actual_total,temp.shop_id,temp.addr_order_id FROM tz_order temp
  648. WHERE temp.user_id = #{userId} and temp.delete_status=0
  649. <if test="status != null">
  650. AND
  651. <choose>
  652. <when test="20 == status">
  653. temp.hb_order_status IN (1,20,30,40,50,70)
  654. </when>
  655. <otherwise>
  656. temp.hb_order_status = #{status}
  657. </otherwise>
  658. </choose>
  659. </if>
  660. <if test="dvyType != null">
  661. AND temp.dvy_type = #{dvyType}
  662. </if>
  663. ORDER BY temp.create_time DESC
  664. LIMIT #{adapter.begin} , #{adapter.size}
  665. )AS o
  666. JOIN tz_order_item oi ON o.order_number = oi.order_number
  667. left join tz_shop_detail sd on o.shop_id = sd.shop_id
  668. left join tz_order_refund tor on o.order_id = tor.order_id
  669. left join tz_user_addr_order ad on o.addr_order_id = ad.addr_order_id
  670. ORDER BY o.create_time DESC
  671. </select>
  672. <select id="countMyOrderByUserIdAndStatus" resultType="Long">
  673. SELECT count(*)
  674. FROM (
  675. SELECT count(*) FROM tz_order temp
  676. JOIN tz_order_item oi ON temp.order_number = oi.order_number
  677. WHERE temp.user_id = #{userId} and temp.delete_status = 0
  678. <if test="status != null and status != 0">
  679. AND temp.hb_order_status = #{status}
  680. </if>
  681. <if test="isComm != null">
  682. AND temp.hb_order_status = 80
  683. </if>
  684. <if test="isComm != null">
  685. AND oi.comm_sts = #{isComm}
  686. </if>
  687. group by temp.order_id
  688. )AS o
  689. </select>
  690. <update id="deleteOrders">
  691. UPDATE tz_order SET `delete_status`=2,update_time=NOW()
  692. WHERE order_id IN
  693. <foreach collection="orders" item="order" open="(" close=")" separator=",">
  694. #{order.orderId}
  695. </foreach>
  696. </update>
  697. <select id="getOrderCount" resultType="com.yami.shop.bean.app.dto.OrderCountData">
  698. SELECT
  699. COUNT(o.order_id) all_count,
  700. COUNT( CASE WHEN o.hb_order_status = 0 THEN o.order_id ELSE NULL END ) AS unPay,
  701. COUNT( CASE WHEN o.hb_order_status = 1 THEN o.order_id ELSE NULL END ) AS payed,
  702. COUNT( CASE WHEN o.hb_order_status in (1,20,30,40,50,70) THEN o.order_id ELSE NULL END ) AS consignment,
  703. COUNT( CASE WHEN o.hb_order_status = 40 THEN o.order_id ELSE NULL END ) AS confirm,
  704. COUNT( CASE WHEN o.hb_order_status = 80 THEN o.order_id ELSE NULL END ) AS success,
  705. COUNT( CASE WHEN o.hb_order_status = 60 THEN o.order_id ELSE NULL END ) AS `close`
  706. FROM tz_order o
  707. WHERE o.user_id =#{userId} AND o.delete_status = 0
  708. </select>
  709. <update id="cancelSeckillOrderByTime">
  710. UPDATE tz_order o JOIN (
  711. SELECT so.order_number FROM tz_seckill_order so JOIN
  712. tz_seckill s ON s.seckill_id = so.seckill_id
  713. AND (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(so.`create_time`))/60 &gt; s.`max_cancel_time` and so.state = 0 ) t
  714. ON o.order_number = t.order_number
  715. SET o.`hb_order_status`=60,o.cancel_time = NOW(),o.update_time=NOW()
  716. </update>
  717. <update id="updateToWaitGroup">
  718. UPDATE tz_order SET hb_order_status = 7,update_time=NOW() WHERE order_number = #{orderNumber}
  719. </update>
  720. <update id="updateToWaitDelivery">
  721. UPDATE tz_order SET `hb_order_status` = 20, `update_time` = NOW()
  722. WHERE `order_number` IN
  723. (
  724. SELECT order_number FROM
  725. (SELECT o.`order_number` FROM tz_order o
  726. LEFT JOIN tz_group_order go ON go.`order_number` = o.`order_number`
  727. LEFT JOIN tz_group_team gt ON gt.`group_team_id` = go.`group_team_id`
  728. WHERE gt.`group_team_id` = #{groupTeamId}) temp
  729. )
  730. </update>
  731. <select id="getOrderByOrderNumberAndUserId" resultType="com.yami.shop.bean.model.Order">
  732. select o.* from tz_order o where o.order_number = #{orderNumber} and o.user_id = #{userId}
  733. </select>
  734. <select id="getOrderAndOrderItemByOrderNumber" resultMap="orderAndOrderItemMap">
  735. select o.*,oi.*,oi.prod_name oi_prod_name,oi.actual_total as oi_actual_total from tz_order o
  736. left join tz_order_item oi on o.order_number = oi.order_number
  737. where o.order_number = #{orderNumber}
  738. </select>
  739. <select id="hasBuySuccessProd" resultType="java.lang.Integer">
  740. select count(*) from tz_order_item oi
  741. join tz_order o on o.order_number = oi.order_number
  742. where o.user_id=#{userId} and o.hb_order_status = 50 and oi.prod_id = #{prodId}
  743. </select>
  744. <select id="listMyOrderByParams" resultMap="MyOrderMap">
  745. SELECT
  746. o.order_type,o.actual_total,
  747. oi.pic,oi.price,oi.prod_id,oi.prod_name,oi.sku_name,ifnull(oi.use_score,0) as use_score,oi.prod_count,oi.order_item_id,o.hb_order_status,o.order_number,oi.comm_sts,
  748. sd.shop_id,sd.shop_name
  749. FROM (
  750. SELECT temp.order_type, temp.create_time, temp.order_number,temp.actual_total,temp.hb_order_status,temp.shop_id,prod_name
  751. FROM tz_order temp
  752. WHERE temp.user_id = #{userId} and temp.delete_status = 0
  753. <if test="status != null and status != 0">
  754. AND temp.hb_order_status = #{status}
  755. </if>
  756. <if test="orderNumber != null and orderNumber != ''">
  757. AND temp.order_number LIKE CONCAT("%",#{orderNumber},"%")
  758. </if>
  759. <if test="orderType == 0">
  760. AND (temp.order_type = 0 or temp.order_type is null)
  761. </if>
  762. <if test="orderType != null and orderType !='' and orderType != 0">
  763. AND temp.order_type = #{orderType}
  764. </if>
  765. <if test="orderTimeStatus == 1 or orderTimeStatus == 2">
  766. AND temp.create_time &gt;= #{preTime}
  767. </if>
  768. <if test="orderTimeStatus == 3">
  769. AND temp.create_time &lt;= #{preTime}
  770. </if>
  771. <if test="orderName != null and orderName != ''">
  772. AND temp.prod_name LIKE concat('%',#{orderName},'%')
  773. </if>
  774. ORDER BY temp.create_time DESC
  775. LIMIT #{adapter.begin} , #{adapter.size}
  776. )AS o
  777. JOIN tz_order_item oi ON o.order_number = oi.order_number
  778. LEFT JOIN tz_shop_detail sd on o.shop_id = sd.shop_id
  779. ORDER BY o.create_time DESC
  780. </select>
  781. <select id="countMyOrderByParams" resultType="Long">
  782. SELECT COUNT(*) FROM(
  783. SELECT
  784. count(1)
  785. FROM tz_order o
  786. JOIN tz_order_item oi ON o.order_number = oi.order_number
  787. join tz_shop_detail sd on o.shop_id = sd.shop_id
  788. WHERE o.user_id = #{userId} and o.delete_status = 0
  789. <if test="status != null and status != 0">
  790. AND o.hb_order_status = #{status}
  791. </if>
  792. <if test="orderNumber != null and orderNumber != ''">
  793. AND o.order_number LIKE CONCAT("%",#{orderNumber},"%")
  794. </if>
  795. <if test="orderType == 0">
  796. AND (o.order_type = 0 or o.order_type is null)
  797. </if>
  798. <if test="orderType != null and orderType !='' and orderType != 0">
  799. AND o.order_type = #{orderType}
  800. </if>
  801. <if test="orderTimeStatus == 1 or orderTimeStatus == 2">
  802. AND o.create_time &gt;= #{preTime}
  803. </if>
  804. <if test="orderTimeStatus == 3">
  805. AND o.create_time &lt;= #{preTime}
  806. </if>
  807. <if test="orderName != null and orderName != ''">
  808. AND (o.prod_name LIKE concat('%',#{orderName},'%') OR oi.prod_name LIKE concat('%',#{orderName},'%'))
  809. </if>
  810. GROUP BY o.order_number
  811. ) AS temp
  812. </select>
  813. <select id="listOrdersDetialByOrderInfo" resultMap="orderAndOrderItemAndUserAddrMap">
  814. SELECT *,oi.prod_name,uao.address,uao.address_name,uao.addr_detail as item_prod_name,oi.actual_total as oi_actual_total,temp.prod_name as order_prod_name,temp.hb_order_status as oi_status
  815. FROM
  816. (
  817. SELECT o.*,sd.shop_name FROM tz_order o
  818. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  819. <where>
  820. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  821. and o.order_number = #{orderParam.orderNumber}
  822. </if>
  823. <if test="orderParam.status != null">
  824. and o.hb_order_status = #{orderParam.status}
  825. </if>
  826. <if test="orderParam.shopId != null">
  827. and o.shop_id = #{orderParam.shopId}
  828. </if>
  829. <if test="orderParam.isPayed != null">
  830. and o.is_payed = #{orderParam.isPayed}
  831. and o.hb_order_status != 60
  832. </if>
  833. <if test="orderParam.startTime != null">
  834. and o.create_time &gt; #{orderParam.startTime}
  835. </if>
  836. <if test="orderParam.endTime != null">
  837. and o.create_time &lt; #{orderParam.endTime}
  838. </if>
  839. <if test="orderParam.orderType != null">
  840. and o.order_type = #{orderParam.orderType}
  841. </if>
  842. <if test="orderParam.orderType == null">
  843. and (o.order_type <![CDATA[ <> ]]> 3 OR o.order_type IS NULL)
  844. </if>
  845. <if test="orderParam.shopName != null">
  846. and sd.shop_name LIKE concat("%",#{orderParam.shopName},"%")
  847. </if>
  848. <if test="orderParam.refundStatus == 0">
  849. and o.refund_status IS NULL
  850. </if>
  851. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  852. and o.refund_status = #{orderParam.refundStatus}
  853. </if>
  854. <if test="orderParam.prodName != null">
  855. and o.prod_name LIKE concat("%",#{orderParam.prodName},"%")
  856. </if>
  857. </where>
  858. ORDER BY o.create_time DESC
  859. ) AS temp
  860. LEFT JOIN tz_order_item oi
  861. ON temp.order_number = oi.order_number
  862. LEFT JOIN tz_user_addr_order uao
  863. ON temp.addr_order_id = uao.addr_order_id
  864. <where>
  865. <if test="orderParam.receiver != null">
  866. and uao.receiver LIKE concat("%",#{orderParam.receiver},"%")
  867. </if>
  868. <if test="orderParam.mobile != null">
  869. and uao.mobile LIKE concat("%",#{orderParam.mobile},"%")
  870. </if>
  871. </where>
  872. ORDER BY temp.create_time DESC
  873. </select>
  874. <select id="getOrderPayInfoByOrderNumber" resultMap="orderAndOrderItemMap">
  875. SELECT o.*,oi.prod_name as oi_prod_name,oi.actual_total as oi_actual_total,oi.use_score
  876. FROM tz_order o
  877. LEFT JOIN tz_order_item oi ON oi.order_number = o.order_number
  878. WHERE o.order_number IN
  879. <foreach collection="orderNumberList" item="orderNumber" separator="," open="(" close=")">
  880. #{orderNumber}
  881. </foreach>
  882. </select>
  883. <select id="getOrderDetailByOrderNumberAndShopId" resultMap="orderAndOrderItemAndUserAddrMap">
  884. SELECT o.*,oi.prod_name as item_prod_name,oi.*,uao.*,u.`nick_name`,u.user_mobile,o.hb_order_status as oi_status, IF(o.refund_type = 1,
  885. o.rms,r.return_money_sts) AS oi_return_money_sts
  886. FROM (
  887. SELECT temp.*,tr.refund_type,tr.return_money_sts rms
  888. FROM tz_order temp
  889. LEFT JOIN tz_order_refund tr ON tr.order_id = temp.order_id AND tr.return_money_sts &gt; 0 AND
  890. tr.return_money_sts &lt; 6
  891. WHERE temp.order_number =#{orderNumber}
  892. <if test="shopId != null">
  893. and temp.shop_id =#{shopId}
  894. </if>
  895. ) as o
  896. LEFT JOIN tz_order_item oi ON oi.order_number = o.order_number
  897. LEFT JOIN tz_order_refund r ON r.order_item_id = oi.order_item_id AND r.return_money_sts &gt; 0 AND r.return_money_sts &lt; 6
  898. LEFT JOIN tz_user_addr_order uao ON o.addr_order_id = uao.addr_order_id
  899. LEFT JOIN tz_user u ON u.user_id = o.user_id
  900. </select>
  901. <select id="OrderCommentByUserIdAndStatus" resultMap="MyOrderMap">
  902. SELECT
  903. o.order_type,o.actual_total,o.hb_order_status,o.order_number,o.freight_amount,o.create_time,
  904. pc.rec_time,
  905. oi.pic,oi.price,oi.prod_name,oi.pic,oi.sku_name,oi.use_score,oi.prod_id,oi.rec_time,oi.prod_count,oi.order_item_id,oi.comm_sts,
  906. sd.shop_id,sd.shop_name,oi.actual_total as oi_actual_total
  907. FROM (
  908. SELECT DISTINCT temp.order_type, temp.create_time, temp.freight_amount,temp.order_number,temp.actual_total,temp.hb_order_status,temp.shop_id FROM tz_order temp
  909. JOIN tz_order_item toi ON temp.order_number = toi.order_number AND toi.comm_sts = #{isComm}
  910. WHERE temp.user_id = #{userId} and temp.delete_status = 0 AND temp.hb_order_status = 80
  911. ORDER BY temp.create_time DESC
  912. LIMIT #{adapter.begin} , #{adapter.size}
  913. )AS o
  914. JOIN tz_order_item oi ON o.order_number = oi.order_number AND oi.comm_sts = #{isComm}
  915. left JOIN tz_prod_comm pc ON pc.order_item_id = oi.order_item_id
  916. left join tz_shop_detail sd on o.shop_id = sd.shop_id
  917. ORDER BY o.create_time DESC
  918. </select>
  919. <select id="orderItemCommentByUserIdAndStatus" resultMap="MyOrderItemMap">
  920. SELECT
  921. pc.rec_time,oi.pic,oi.price,oi.prod_name,oi.order_number,oi.pic,oi.sku_name,oi.use_score,oi.prod_id,oi.rec_time,oi.prod_count,oi.order_item_id,oi.comm_sts,
  922. oi.actual_total as oi_actual_total
  923. FROM tz_order o
  924. left JOIN tz_order_item oi ON o.order_number = oi.order_number
  925. left JOIN tz_prod_comm pc ON pc.order_item_id = oi.order_item_id
  926. where oi.comm_sts = #{isComm} and o.user_id = #{userId}
  927. <if test="isComm == 1">
  928. AND o.hb_order_status = 80
  929. </if>
  930. ORDER BY pc.rec_time DESC
  931. LIMIT #{adapter.begin} , #{adapter.size}
  932. </select>
  933. <select id="countOrderItemComment" resultType="long">
  934. SELECT count(*)
  935. FROM tz_order o
  936. left JOIN tz_order_item oi ON o.order_number = oi.order_number
  937. where oi.comm_sts = #{isComm} and o.user_id = #{userId}
  938. <if test="isComm == 1">
  939. AND o.hb_order_status = 80
  940. </if>
  941. </select>
  942. <select id="statusCount" resultType="integer">
  943. SELECT count(1) FROM `tz_order` WHERE dvy_type=1 and hb_order_status in
  944. <foreach collection="status" item="status" separator="," open="(" close=")">
  945. #{status}
  946. </foreach>
  947. </select>
  948. <select id="selectOrderCount" resultType="com.yami.shop.bean.param.OrderCountParam">
  949. SELECT
  950. count(1) as allCount,
  951. count(case when hb_order_status = 0 then 1 end) as payedCount,
  952. count(case when hb_order_status = 20 then 1 end) as readyCount,
  953. count(case when hb_order_status = 30 then 1 end) as deliveryCount,
  954. count(case when hb_order_status = 40 then 1 end) as shippingCount,
  955. count(case when hb_order_status = 50 then 1 end) as cancelAuditCount,
  956. count(case when hb_order_status = 60 then 1 end) as canceledCount,
  957. count(case when hb_order_status = 70 then 1 end) as arrivedCount,
  958. count(case when hb_order_status = 80 then 1 end) as completedCount
  959. FROM tz_order
  960. <where>
  961. delete_status = 0
  962. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  963. and o.order_number = #{orderParam.orderNumber}
  964. </if>
  965. <if test="orderParam.hbOrderStatus != null">
  966. and o.hb_order_status = #{orderParam.hbOrderStatus}
  967. </if>
  968. <if test="orderParam.dvyType != null">
  969. and o.dvy_type = #{orderParam.dvyType}
  970. </if>
  971. <if test="orderParam.channelId != null">
  972. and o.channel_id = #{orderParam.channelId}
  973. </if>
  974. <if test="orderParam.shopId != null">
  975. and o.shop_id = #{orderParam.shopId}
  976. </if>
  977. <if test="orderParam.startTime != null">
  978. and o.create_time &gt; #{orderParam.startTime}
  979. </if>
  980. <if test="orderParam.endTime != null">
  981. and o.create_time &lt; #{orderParam.endTime}
  982. </if>
  983. <if test="orderParam.orderType != null">
  984. and o.order_type = #{orderParam.orderType}
  985. </if>
  986. <if test="orderParam.refundStatus == 0">
  987. and o.refund_status IS NULL
  988. </if>
  989. </where>
  990. </select>
  991. <select id="deliveryOrder" resultMap="BaseResultMap">
  992. SELECT o.*, sd.shop_name,ch.channel_name
  993. FROM tz_order o
  994. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  995. LEFT JOIN tz_channel ch ON o.channel_id = ch.id
  996. join tz_user_addr_order uao ON o.addr_order_id = uao.addr_order_id
  997. <where>
  998. o.delete_status = 0 AND o.dvy_type = #{orderParam.dvyType}
  999. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  1000. AND o.order_number LIKE concat('%', #{orderParam.orderNumber}, '%')
  1001. </if>
  1002. <if test="orderParam.mobile != null and orderParam.mobile != ''">
  1003. AND uao.mobile LIKE concat('%', #{orderParam.mobile}, '%')
  1004. </if>
  1005. <if test="orderParam.receiver != null and orderParam.receiver != ''">
  1006. AND uao.receiver LIKE concat('%', #{orderParam.receiver}, '%')
  1007. </if>
  1008. <if test="orderParam.startTime != null">
  1009. AND o.create_time &gt;= #{orderParam.startTime}
  1010. </if>
  1011. <if test="orderParam.endTime != null">
  1012. AND o.create_time &lt;= #{orderParam.endTime}
  1013. </if>
  1014. <if test="orderParam.channelId != null">
  1015. AND o.channel_id = #{orderParam.channelId}
  1016. </if>
  1017. <if test="orderParam.shopId != null">
  1018. AND o.shopId = #{orderParam.shopId}
  1019. </if>
  1020. <if test="orderParam.hbOrderStatus != null">
  1021. <if test="orderParam.hbOrderStatus == 0">
  1022. AND o.hb_order_status = 0
  1023. </if>
  1024. <if test="orderParam.hbOrderStatus == 20">
  1025. AND o.hb_order_status = 20
  1026. </if>
  1027. <if test="orderParam.hbOrderStatus == 70">
  1028. AND o.hb_order_status in (30,40,70)
  1029. </if>
  1030. <if test="orderParam.hbOrderStatus == 80">
  1031. AND o.hb_order_status = 80
  1032. </if>
  1033. <if test="orderParam.hbOrderStatus == 60">
  1034. AND o.hb_order_status in (50, 60)
  1035. </if>
  1036. </if>
  1037. </where>
  1038. ORDER BY o.create_time DESC
  1039. </select>
  1040. </mapper>