OrderMapper.xml 61 KB

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