OrderMapper.xml 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. left join tz_user d on a.user_id = d.user_id
  466. <where>
  467. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  468. and a.order_number = #{orderParam.orderNumber}
  469. </if>
  470. <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
  471. and a.channel_id in
  472. <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
  473. #{channelId}
  474. </foreach>
  475. </if>
  476. <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
  477. and a.dvy_type = #{orderParam.dvyType}
  478. </if>
  479. <if test="orderParam.userAttrType != null and orderParam.userAttrType != '' and orderParam.userAttrType != 0">
  480. AND d.user_attr_type = #{orderParam.userAttrType}
  481. </if>
  482. <if test="orderParam.shopId != null">
  483. and a.shop_id = #{orderParam.shopId}
  484. </if>
  485. <if test="orderParam.startTime != null">
  486. and a.create_time &gt; #{orderParam.startTime}
  487. </if>
  488. <if test="orderParam.endTime != null">
  489. and a.create_time &lt; #{orderParam.endTime}
  490. </if>
  491. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  492. and a.refund_status = #{orderParam.refundStatus}
  493. </if>
  494. <if test="orderParam.receiver != null">
  495. and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
  496. </if>
  497. <if test="orderParam.userMobile != null">
  498. and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
  499. </if>
  500. <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
  501. <if test="orderParam.orderStatus == 'all'">
  502. AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
  503. </if>
  504. <if test="orderParam.orderStatus == 'paddingPay'">
  505. AND a.hb_order_status in (0)
  506. </if>
  507. <if test="orderParam.orderStatus == 'paddingShipped'">
  508. AND a.hb_order_status in (1)
  509. </if>
  510. <if test="orderParam.orderStatus == 'paddingReceived'">
  511. AND a.hb_order_status in (20,30,40,70)
  512. </if>
  513. <if test="orderParam.orderStatus == 'completed'">
  514. AND a.hb_order_status in (80)
  515. </if>
  516. <if test="orderParam.orderStatus == 'cancel'">
  517. AND a.hb_order_status in (50,60)
  518. </if>
  519. </if>
  520. </where>
  521. order by a.create_time desc,a.order_id desc
  522. LIMIT #{adapter.begin} , #{adapter.size}
  523. </select>
  524. <select id="deliverListCount" resultType="integer">
  525. SELECT count(1) FROM tz_order a
  526. LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
  527. LEFT JOIN tz_shop_detail c on a.shop_id=c.shop_id
  528. left join tz_user d on a.user_id = d.user_id
  529. <where>
  530. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  531. and a.order_number = #{orderParam.orderNumber}
  532. </if>
  533. <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
  534. and a.channel_id in
  535. <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
  536. #{channelId}
  537. </foreach>
  538. </if>
  539. <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
  540. and a.dvy_type = #{orderParam.dvyType}
  541. </if>
  542. <if test="orderParam.userAttrType != null and orderParam.userAttrType != '' and orderParam.userAttrType != 0">
  543. AND d.user_attr_type = #{orderParam.userAttrType}
  544. </if>
  545. <if test="orderParam.shopId != null">
  546. and a.shop_id = #{orderParam.shopId}
  547. </if>
  548. <if test="orderParam.startTime != null">
  549. and a.create_time &gt; #{orderParam.startTime}
  550. </if>
  551. <if test="orderParam.endTime != null">
  552. and a.create_time &lt; #{orderParam.endTime}
  553. </if>
  554. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  555. and a.refund_status = #{orderParam.refundStatus}
  556. </if>
  557. <if test="orderParam.receiver != null">
  558. and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
  559. </if>
  560. <if test="orderParam.userMobile != null">
  561. and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
  562. </if>
  563. <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
  564. <if test="orderParam.orderStatus == 'all'">
  565. AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
  566. </if>
  567. <if test="orderParam.orderStatus == 'paddingPay'">
  568. AND a.hb_order_status in (0)
  569. </if>
  570. <if test="orderParam.orderStatus == 'paddingShipped'">
  571. AND a.hb_order_status in (1)
  572. </if>
  573. <if test="orderParam.orderStatus == 'paddingReceived'">
  574. AND a.hb_order_status in (20,30,40,70)
  575. </if>
  576. <if test="orderParam.orderStatus == 'completed'">
  577. AND a.hb_order_status in (80)
  578. </if>
  579. <if test="orderParam.orderStatus == 'cancel'">
  580. AND a.hb_order_status in (50,60)
  581. </if>
  582. </if>
  583. </where>
  584. </select>
  585. <select id="countOrderDetial" resultType="long">
  586. SELECT count(0)
  587. FROM tz_order o
  588. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  589. JOIN tz_user_addr_order uao
  590. ON o.addr_order_id = uao.addr_order_id
  591. <where>
  592. o.delete_status = 0
  593. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  594. and o.order_number = #{orderParam.orderNumber}
  595. </if>
  596. <if test="orderParam.hbOrderStatus != null">
  597. and o.hb_order_status = #{orderParam.hbOrderStatus}
  598. </if>
  599. <if test="orderParam.shopId != null">
  600. and o.shop_id = #{orderParam.shopId}
  601. </if>
  602. <if test="orderParam.channelId != null">
  603. and o.channel_id = #{orderParam.channelId}
  604. </if>
  605. <if test="orderParam.dvyType != null">
  606. and o.dvy_type = #{orderParam.dvyType}
  607. </if>
  608. <if test="orderParam.isPayed != null">
  609. and o.is_payed = #{orderParam.isPayed}
  610. and o.hb_order_status != 60
  611. </if>
  612. <if test="orderParam.startTime != null">
  613. and o.create_time &gt; #{orderParam.startTime}
  614. </if>
  615. <if test="orderParam.endTime != null">
  616. and o.create_time &lt; #{orderParam.endTime}
  617. </if>
  618. <if test="orderParam.orderType != null">
  619. and o.order_type = #{orderParam.orderType}
  620. </if>
  621. <if test="orderParam.orderType == null">
  622. and (o.order_type <![CDATA[ <> ]]> 3 OR o.order_type IS NULL)
  623. </if>
  624. <if test="orderParam.shopName != null">
  625. and sd.shop_name LIKE concat("%",#{orderParam.shopName},"%")
  626. </if>
  627. <if test="orderParam.refundStatus == 0">
  628. and o.refund_status IS NULL
  629. </if>
  630. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  631. and o.refund_status = #{orderParam.refundStatus}
  632. </if>
  633. <if test="orderParam.prodName != null">
  634. and o.prod_name LIKE concat("%",#{orderParam.prodName},"%")
  635. </if>
  636. <if test="orderParam.receiver != null">
  637. and uao.receiver LIKE concat("%",#{orderParam.receiver},"%")
  638. </if>
  639. <if test="orderParam.mobile != null">
  640. and uao.mobile LIKE concat("%",#{orderParam.mobile},"%")
  641. </if>
  642. </where>
  643. </select>
  644. <select id="calculateUserInShopData" resultType="com.yami.shop.bean.distribution.UserShoppingDataDto">
  645. select
  646. count(o.order_number) as expense_number,
  647. ifnull(SUM(o.actual_total),0) as expense_amount
  648. from tz_order o
  649. where o.user_id=#{userId} and o.shop_id = #{shopId} and (o.hb_order_status = 45 or o.hb_order_status = 80)
  650. </select>
  651. <select id="listMyOrderByUserIdAndStatus" resultMap="MyOrderMap">
  652. SELECT
  653. o.order_type,o.actual_total,o.order_number,o.freight_amount,o.create_time,o.order_id,
  654. o.hb_order_status,
  655. o.hb_logistic_status,
  656. o.offset_points,
  657. o.pay_time,
  658. o.dvy_type,
  659. o.comm_sts,
  660. (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,
  661. (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,
  662. 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,
  663. sd.shop_id,sd.shop_name,oi.actual_total as oi_actual_total,ad.longitude,ad.latitude
  664. FROM (
  665. SELECT temp.order_type,
  666. temp.hb_order_status,
  667. temp.hb_logistic_status,
  668. temp.offset_points,
  669. temp.pay_time,
  670. temp.dvy_type,
  671. temp.comm_sts,
  672. 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
  673. WHERE temp.user_id = #{userId} and temp.delete_status=0
  674. <if test="status != null">
  675. AND
  676. <choose>
  677. <when test="20 == status">
  678. temp.hb_order_status IN (1,20,30,40,50,70)
  679. </when>
  680. <otherwise>
  681. temp.hb_order_status = #{status}
  682. </otherwise>
  683. </choose>
  684. </if>
  685. <if test="dvyType != null">
  686. AND temp.dvy_type = #{dvyType}
  687. </if>
  688. ORDER BY temp.create_time DESC
  689. LIMIT #{adapter.begin} , #{adapter.size}
  690. )AS o
  691. JOIN tz_order_item oi ON o.order_number = oi.order_number
  692. left join tz_shop_detail sd on o.shop_id = sd.shop_id
  693. left join tz_order_refund tor on o.order_id = tor.order_id
  694. left join tz_user_addr_order ad on o.addr_order_id = ad.addr_order_id
  695. ORDER BY o.create_time DESC
  696. </select>
  697. <select id="countMyOrderByUserIdAndStatus" resultType="Long">
  698. SELECT count(*)
  699. FROM (
  700. SELECT count(*) FROM tz_order temp
  701. JOIN tz_order_item oi ON temp.order_number = oi.order_number
  702. WHERE temp.user_id = #{userId} and temp.delete_status = 0
  703. <if test="status != null and status != 0">
  704. AND temp.hb_order_status = #{status}
  705. </if>
  706. <if test="isComm != null">
  707. AND temp.hb_order_status = 80
  708. </if>
  709. <if test="isComm != null">
  710. AND oi.comm_sts = #{isComm}
  711. </if>
  712. group by temp.order_id
  713. )AS o
  714. </select>
  715. <update id="deleteOrders">
  716. UPDATE tz_order SET `delete_status`=2,update_time=NOW()
  717. WHERE order_id IN
  718. <foreach collection="orders" item="order" open="(" close=")" separator=",">
  719. #{order.orderId}
  720. </foreach>
  721. </update>
  722. <select id="getOrderCount" resultType="com.yami.shop.bean.app.dto.OrderCountData">
  723. SELECT
  724. COUNT(o.order_id) all_count,
  725. COUNT( CASE WHEN o.hb_order_status = 0 THEN o.order_id ELSE NULL END ) AS unPay,
  726. COUNT( CASE WHEN o.hb_order_status = 1 THEN o.order_id ELSE NULL END ) AS payed,
  727. COUNT( CASE WHEN o.hb_order_status in (1,20,30,40,50,70) THEN o.order_id ELSE NULL END ) AS consignment,
  728. COUNT( CASE WHEN o.hb_order_status = 40 THEN o.order_id ELSE NULL END ) AS confirm,
  729. COUNT( CASE WHEN o.hb_order_status = 80 THEN o.order_id ELSE NULL END ) AS success,
  730. COUNT( CASE WHEN o.hb_order_status = 60 THEN o.order_id ELSE NULL END ) AS `close`
  731. FROM tz_order o
  732. WHERE o.user_id =#{userId} AND o.delete_status = 0
  733. </select>
  734. <update id="cancelSeckillOrderByTime">
  735. UPDATE tz_order o JOIN (
  736. SELECT so.order_number FROM tz_seckill_order so JOIN
  737. tz_seckill s ON s.seckill_id = so.seckill_id
  738. AND (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(so.`create_time`))/60 &gt; s.`max_cancel_time` and so.state = 0 ) t
  739. ON o.order_number = t.order_number
  740. SET o.`hb_order_status`=60,o.cancel_time = NOW(),o.update_time=NOW()
  741. </update>
  742. <update id="updateToWaitGroup">
  743. UPDATE tz_order SET hb_order_status = 7,update_time=NOW() WHERE order_number = #{orderNumber}
  744. </update>
  745. <update id="updateToWaitDelivery">
  746. UPDATE tz_order SET `hb_order_status` = 20, `update_time` = NOW()
  747. WHERE `order_number` IN
  748. (
  749. SELECT order_number FROM
  750. (SELECT o.`order_number` FROM tz_order o
  751. LEFT JOIN tz_group_order go ON go.`order_number` = o.`order_number`
  752. LEFT JOIN tz_group_team gt ON gt.`group_team_id` = go.`group_team_id`
  753. WHERE gt.`group_team_id` = #{groupTeamId}) temp
  754. )
  755. </update>
  756. <select id="getOrderByOrderNumberAndUserId" resultType="com.yami.shop.bean.model.Order">
  757. select o.* from tz_order o where o.order_number = #{orderNumber} and o.user_id = #{userId}
  758. </select>
  759. <select id="getOrderAndOrderItemByOrderNumber" resultMap="orderAndOrderItemMap">
  760. select o.*,oi.*,oi.prod_name oi_prod_name,oi.actual_total as oi_actual_total from tz_order o
  761. left join tz_order_item oi on o.order_number = oi.order_number
  762. where o.order_number = #{orderNumber}
  763. </select>
  764. <select id="hasBuySuccessProd" resultType="java.lang.Integer">
  765. select count(*) from tz_order_item oi
  766. join tz_order o on o.order_number = oi.order_number
  767. where o.user_id=#{userId} and o.hb_order_status = 50 and oi.prod_id = #{prodId}
  768. </select>
  769. <select id="listMyOrderByParams" resultMap="MyOrderMap">
  770. SELECT
  771. o.order_type,o.actual_total,
  772. 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,
  773. sd.shop_id,sd.shop_name
  774. FROM (
  775. SELECT temp.order_type, temp.create_time, temp.order_number,temp.actual_total,temp.hb_order_status,temp.shop_id,prod_name
  776. FROM tz_order temp
  777. WHERE temp.user_id = #{userId} and temp.delete_status = 0
  778. <if test="status != null and status != 0">
  779. AND temp.hb_order_status = #{status}
  780. </if>
  781. <if test="orderNumber != null and orderNumber != ''">
  782. AND temp.order_number LIKE CONCAT("%",#{orderNumber},"%")
  783. </if>
  784. <if test="orderType == 0">
  785. AND (temp.order_type = 0 or temp.order_type is null)
  786. </if>
  787. <if test="orderType != null and orderType !='' and orderType != 0">
  788. AND temp.order_type = #{orderType}
  789. </if>
  790. <if test="orderTimeStatus == 1 or orderTimeStatus == 2">
  791. AND temp.create_time &gt;= #{preTime}
  792. </if>
  793. <if test="orderTimeStatus == 3">
  794. AND temp.create_time &lt;= #{preTime}
  795. </if>
  796. <if test="orderName != null and orderName != ''">
  797. AND temp.prod_name LIKE concat('%',#{orderName},'%')
  798. </if>
  799. ORDER BY temp.create_time DESC
  800. LIMIT #{adapter.begin} , #{adapter.size}
  801. )AS o
  802. JOIN tz_order_item oi ON o.order_number = oi.order_number
  803. LEFT JOIN tz_shop_detail sd on o.shop_id = sd.shop_id
  804. ORDER BY o.create_time DESC
  805. </select>
  806. <select id="countMyOrderByParams" resultType="Long">
  807. SELECT COUNT(*) FROM(
  808. SELECT
  809. count(1)
  810. FROM tz_order o
  811. JOIN tz_order_item oi ON o.order_number = oi.order_number
  812. join tz_shop_detail sd on o.shop_id = sd.shop_id
  813. WHERE o.user_id = #{userId} and o.delete_status = 0
  814. <if test="status != null and status != 0">
  815. AND o.hb_order_status = #{status}
  816. </if>
  817. <if test="orderNumber != null and orderNumber != ''">
  818. AND o.order_number LIKE CONCAT("%",#{orderNumber},"%")
  819. </if>
  820. <if test="orderType == 0">
  821. AND (o.order_type = 0 or o.order_type is null)
  822. </if>
  823. <if test="orderType != null and orderType !='' and orderType != 0">
  824. AND o.order_type = #{orderType}
  825. </if>
  826. <if test="orderTimeStatus == 1 or orderTimeStatus == 2">
  827. AND o.create_time &gt;= #{preTime}
  828. </if>
  829. <if test="orderTimeStatus == 3">
  830. AND o.create_time &lt;= #{preTime}
  831. </if>
  832. <if test="orderName != null and orderName != ''">
  833. AND (o.prod_name LIKE concat('%',#{orderName},'%') OR oi.prod_name LIKE concat('%',#{orderName},'%'))
  834. </if>
  835. GROUP BY o.order_number
  836. ) AS temp
  837. </select>
  838. <select id="listOrdersDetialByOrderInfo" resultMap="orderAndOrderItemAndUserAddrMap">
  839. 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
  840. FROM
  841. (
  842. SELECT o.*,sd.shop_name FROM tz_order o
  843. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  844. <where>
  845. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  846. and o.order_number = #{orderParam.orderNumber}
  847. </if>
  848. <if test="orderParam.status != null">
  849. and o.hb_order_status = #{orderParam.status}
  850. </if>
  851. <if test="orderParam.shopId != null">
  852. and o.shop_id = #{orderParam.shopId}
  853. </if>
  854. <if test="orderParam.isPayed != null">
  855. and o.is_payed = #{orderParam.isPayed}
  856. and o.hb_order_status != 60
  857. </if>
  858. <if test="orderParam.startTime != null">
  859. and o.create_time &gt; #{orderParam.startTime}
  860. </if>
  861. <if test="orderParam.endTime != null">
  862. and o.create_time &lt; #{orderParam.endTime}
  863. </if>
  864. <if test="orderParam.orderType != null">
  865. and o.order_type = #{orderParam.orderType}
  866. </if>
  867. <if test="orderParam.orderType == null">
  868. and (o.order_type <![CDATA[ <> ]]> 3 OR o.order_type IS NULL)
  869. </if>
  870. <if test="orderParam.shopName != null">
  871. and sd.shop_name LIKE concat("%",#{orderParam.shopName},"%")
  872. </if>
  873. <if test="orderParam.refundStatus == 0">
  874. and o.refund_status IS NULL
  875. </if>
  876. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  877. and o.refund_status = #{orderParam.refundStatus}
  878. </if>
  879. <if test="orderParam.prodName != null">
  880. and o.prod_name LIKE concat("%",#{orderParam.prodName},"%")
  881. </if>
  882. </where>
  883. ORDER BY o.create_time DESC
  884. ) AS temp
  885. LEFT JOIN tz_order_item oi
  886. ON temp.order_number = oi.order_number
  887. LEFT JOIN tz_user_addr_order uao
  888. ON temp.addr_order_id = uao.addr_order_id
  889. <where>
  890. <if test="orderParam.receiver != null">
  891. and uao.receiver LIKE concat("%",#{orderParam.receiver},"%")
  892. </if>
  893. <if test="orderParam.mobile != null">
  894. and uao.mobile LIKE concat("%",#{orderParam.mobile},"%")
  895. </if>
  896. </where>
  897. ORDER BY temp.create_time DESC
  898. </select>
  899. <select id="getOrderPayInfoByOrderNumber" resultMap="orderAndOrderItemMap">
  900. SELECT o.*,oi.prod_name as oi_prod_name,oi.actual_total as oi_actual_total,oi.use_score
  901. FROM tz_order o
  902. LEFT JOIN tz_order_item oi ON oi.order_number = o.order_number
  903. WHERE o.order_number IN
  904. <foreach collection="orderNumberList" item="orderNumber" separator="," open="(" close=")">
  905. #{orderNumber}
  906. </foreach>
  907. </select>
  908. <select id="getOrderDetailByOrderNumberAndShopId" resultMap="orderAndOrderItemAndUserAddrMap">
  909. 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,
  910. o.rms,r.return_money_sts) AS oi_return_money_sts
  911. FROM (
  912. SELECT temp.*,tr.refund_type,tr.return_money_sts rms
  913. FROM tz_order temp
  914. LEFT JOIN tz_order_refund tr ON tr.order_id = temp.order_id AND tr.return_money_sts &gt; 0 AND
  915. tr.return_money_sts &lt; 6
  916. WHERE temp.order_number =#{orderNumber}
  917. <if test="shopId != null">
  918. and temp.shop_id =#{shopId}
  919. </if>
  920. ) as o
  921. LEFT JOIN tz_order_item oi ON oi.order_number = o.order_number
  922. 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
  923. LEFT JOIN tz_user_addr_order uao ON o.addr_order_id = uao.addr_order_id
  924. LEFT JOIN tz_user u ON u.user_id = o.user_id
  925. </select>
  926. <select id="OrderCommentByUserIdAndStatus" resultMap="MyOrderMap">
  927. SELECT
  928. o.order_type,o.actual_total,o.hb_order_status,o.order_number,o.freight_amount,o.create_time,
  929. pc.rec_time,
  930. 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,
  931. sd.shop_id,sd.shop_name,oi.actual_total as oi_actual_total
  932. FROM (
  933. 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
  934. JOIN tz_order_item toi ON temp.order_number = toi.order_number AND toi.comm_sts = #{isComm}
  935. WHERE temp.user_id = #{userId} and temp.delete_status = 0 AND temp.hb_order_status = 80
  936. ORDER BY temp.create_time DESC
  937. LIMIT #{adapter.begin} , #{adapter.size}
  938. )AS o
  939. JOIN tz_order_item oi ON o.order_number = oi.order_number AND oi.comm_sts = #{isComm}
  940. left JOIN tz_prod_comm pc ON pc.order_item_id = oi.order_item_id
  941. left join tz_shop_detail sd on o.shop_id = sd.shop_id
  942. ORDER BY o.create_time DESC
  943. </select>
  944. <select id="orderItemCommentByUserIdAndStatus" resultMap="MyOrderItemMap">
  945. SELECT
  946. 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,
  947. oi.actual_total as oi_actual_total
  948. FROM tz_order o
  949. left JOIN tz_order_item oi ON o.order_number = oi.order_number
  950. left JOIN tz_prod_comm pc ON pc.order_item_id = oi.order_item_id
  951. where oi.comm_sts = #{isComm} and o.user_id = #{userId}
  952. <if test="isComm == 1">
  953. AND o.hb_order_status = 80
  954. </if>
  955. ORDER BY pc.rec_time DESC
  956. LIMIT #{adapter.begin} , #{adapter.size}
  957. </select>
  958. <select id="countOrderItemComment" resultType="long">
  959. SELECT count(*)
  960. FROM tz_order o
  961. left JOIN tz_order_item oi ON o.order_number = oi.order_number
  962. where oi.comm_sts = #{isComm} and o.user_id = #{userId}
  963. <if test="isComm == 1">
  964. AND o.hb_order_status = 80
  965. </if>
  966. </select>
  967. <select id="statusCount" resultType="integer">
  968. SELECT count(a.order_id) FROM `tz_order` a
  969. LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
  970. LEFT JOIN tz_shop_detail c on a.shop_id=c.shop_id
  971. left join tz_user d on a.user_id = d.user_id
  972. <where>
  973. hb_order_status in
  974. <foreach collection="status" item="status" separator="," open="(" close=")">
  975. #{status}
  976. </foreach>
  977. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  978. and a.order_number = #{orderParam.orderNumber}
  979. </if>
  980. <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
  981. and a.channel_id in
  982. <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
  983. #{channelId}
  984. </foreach>
  985. </if>
  986. <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
  987. and a.dvy_type = #{orderParam.dvyType}
  988. </if>
  989. <if test="orderParam.userAttrType != null and orderParam.userAttrType != '' and orderParam.userAttrType != 0">
  990. AND d.user_attr_type = #{orderParam.userAttrType}
  991. </if>
  992. <if test="orderParam.shopId != null">
  993. and a.shop_id = #{orderParam.shopId}
  994. </if>
  995. <if test="orderParam.startTime != null">
  996. and a.create_time &gt; #{orderParam.startTime}
  997. </if>
  998. <if test="orderParam.endTime != null">
  999. and a.create_time &lt; #{orderParam.endTime}
  1000. </if>
  1001. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  1002. and a.refund_status = #{orderParam.refundStatus}
  1003. </if>
  1004. <if test="orderParam.receiver != null">
  1005. and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
  1006. </if>
  1007. <if test="orderParam.userMobile != null">
  1008. and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
  1009. </if>
  1010. <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
  1011. <if test="orderParam.orderStatus == 'all'">
  1012. AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
  1013. </if>
  1014. <if test="orderParam.orderStatus == 'paddingPay'">
  1015. AND a.hb_order_status in (0)
  1016. </if>
  1017. <if test="orderParam.orderStatus == 'paddingShipped'">
  1018. AND a.hb_order_status in (1)
  1019. </if>
  1020. <if test="orderParam.orderStatus == 'paddingReceived'">
  1021. AND a.hb_order_status in (20,30,40,70)
  1022. </if>
  1023. <if test="orderParam.orderStatus == 'completed'">
  1024. AND a.hb_order_status in (80)
  1025. </if>
  1026. <if test="orderParam.orderStatus == 'cancel'">
  1027. AND a.hb_order_status in (50,60)
  1028. </if>
  1029. </if>
  1030. </where>
  1031. </select>
  1032. <select id="selectOrderCount" resultType="com.yami.shop.bean.param.OrderCountParam">
  1033. SELECT
  1034. count(1) as allCount,
  1035. count(case when hb_order_status = 0 then 1 end) as payedCount,
  1036. count(case when hb_order_status = 20 then 1 end) as readyCount,
  1037. count(case when hb_order_status = 30 then 1 end) as deliveryCount,
  1038. count(case when hb_order_status = 40 then 1 end) as shippingCount,
  1039. count(case when hb_order_status = 50 then 1 end) as cancelAuditCount,
  1040. count(case when hb_order_status = 60 then 1 end) as canceledCount,
  1041. count(case when hb_order_status = 70 then 1 end) as arrivedCount,
  1042. count(case when hb_order_status = 80 then 1 end) as completedCount
  1043. FROM tz_order
  1044. <where>
  1045. delete_status = 0
  1046. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  1047. and o.order_number = #{orderParam.orderNumber}
  1048. </if>
  1049. <if test="orderParam.hbOrderStatus != null">
  1050. and o.hb_order_status = #{orderParam.hbOrderStatus}
  1051. </if>
  1052. <if test="orderParam.dvyType != null">
  1053. and o.dvy_type = #{orderParam.dvyType}
  1054. </if>
  1055. <if test="orderParam.channelId != null">
  1056. and o.channel_id = #{orderParam.channelId}
  1057. </if>
  1058. <if test="orderParam.shopId != null">
  1059. and o.shop_id = #{orderParam.shopId}
  1060. </if>
  1061. <if test="orderParam.startTime != null">
  1062. and o.create_time &gt; #{orderParam.startTime}
  1063. </if>
  1064. <if test="orderParam.endTime != null">
  1065. and o.create_time &lt; #{orderParam.endTime}
  1066. </if>
  1067. <if test="orderParam.orderType != null">
  1068. and o.order_type = #{orderParam.orderType}
  1069. </if>
  1070. <if test="orderParam.refundStatus == 0">
  1071. and o.refund_status IS NULL
  1072. </if>
  1073. </where>
  1074. </select>
  1075. <select id="deliveryOrder" resultMap="BaseResultMap">
  1076. SELECT o.*, sd.shop_name,ch.channel_name
  1077. FROM tz_order o
  1078. LEFT JOIN tz_shop_detail sd ON o.shop_id = sd.shop_id
  1079. LEFT JOIN tz_channel ch ON o.channel_id = ch.id
  1080. join tz_user_addr_order uao ON o.addr_order_id = uao.addr_order_id
  1081. <where>
  1082. o.delete_status = 0 AND o.dvy_type = #{orderParam.dvyType}
  1083. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  1084. AND o.order_number LIKE concat('%', #{orderParam.orderNumber}, '%')
  1085. </if>
  1086. <if test="orderParam.mobile != null and orderParam.mobile != ''">
  1087. AND uao.mobile LIKE concat('%', #{orderParam.mobile}, '%')
  1088. </if>
  1089. <if test="orderParam.receiver != null and orderParam.receiver != ''">
  1090. AND uao.receiver LIKE concat('%', #{orderParam.receiver}, '%')
  1091. </if>
  1092. <if test="orderParam.startTime != null">
  1093. AND o.create_time &gt;= #{orderParam.startTime}
  1094. </if>
  1095. <if test="orderParam.endTime != null">
  1096. AND o.create_time &lt;= #{orderParam.endTime}
  1097. </if>
  1098. <if test="orderParam.channelId != null">
  1099. AND o.channel_id = #{orderParam.channelId}
  1100. </if>
  1101. <if test="orderParam.shopId != null">
  1102. AND o.shopId = #{orderParam.shopId}
  1103. </if>
  1104. <if test="orderParam.hbOrderStatus != null">
  1105. <if test="orderParam.hbOrderStatus == 0">
  1106. AND o.hb_order_status = 0
  1107. </if>
  1108. <if test="orderParam.hbOrderStatus == 20">
  1109. AND o.hb_order_status = 20
  1110. </if>
  1111. <if test="orderParam.hbOrderStatus == 70">
  1112. AND o.hb_order_status in (30,40,70)
  1113. </if>
  1114. <if test="orderParam.hbOrderStatus == 80">
  1115. AND o.hb_order_status = 80
  1116. </if>
  1117. <if test="orderParam.hbOrderStatus == 60">
  1118. AND o.hb_order_status in (50, 60)
  1119. </if>
  1120. </if>
  1121. </where>
  1122. ORDER BY o.create_time DESC
  1123. </select>
  1124. <select id="findList" resultMap="BaseResultMap">
  1125. SELECT a.*,b.receiver,b.mobile user_mobile,c.shop_name,d.channel_name FROM tz_order a
  1126. LEFT JOIN tz_user_addr_order b on a.addr_order_id=b.addr_order_id
  1127. LEFT JOIN tz_shop_detail c on a.shop_id=c.shop_id
  1128. LEFT JOIN tz_channel d on a.channel_id=d.id
  1129. left join tz_user e on a.user_id = e.user_id
  1130. <where>
  1131. <if test="orderParam.orderNumber != null and orderParam.orderNumber != ''">
  1132. and a.order_number = #{orderParam.orderNumber}
  1133. </if>
  1134. <if test="orderParam.channelIdList != null and !orderParam.channelIdList.isEmpty()">
  1135. and a.channel_id in
  1136. <foreach collection="orderParam.channelIdList" item="channelId" open="(" close=")" separator=",">
  1137. #{channelId}
  1138. </foreach>
  1139. </if>
  1140. <if test="orderParam.userAttrType != null and orderParam.userAttrType != '' and orderParam.userAttrType != 0">
  1141. AND e.user_attr_type = #{orderParam.userAttrType}
  1142. </if>
  1143. <if test="orderParam.dvyType != null and orderParam.dvyType != ''">
  1144. and a.dvy_type = #{orderParam.dvyType}
  1145. </if>
  1146. <if test="orderParam.shopId != null">
  1147. and a.shop_id = #{orderParam.shopId}
  1148. </if>
  1149. <if test="orderParam.startTime != null">
  1150. and a.create_time &gt; #{orderParam.startTime}
  1151. </if>
  1152. <if test="orderParam.endTime != null">
  1153. and a.create_time &lt; #{orderParam.endTime}
  1154. </if>
  1155. <if test="orderParam.refundStatus != null and orderParam.refundStatus != 0">
  1156. and a.refund_status = #{orderParam.refundStatus}
  1157. </if>
  1158. <if test="orderParam.receiver != null">
  1159. and b.receiver LIKE concat("%",#{orderParam.receiver},"%")
  1160. </if>
  1161. <if test="orderParam.userMobile != null">
  1162. and b.mobile LIKE concat("%",#{orderParam.userMobile},"%")
  1163. </if>
  1164. <if test="orderParam.orderStatus != null and orderParam.orderStatus != ''">
  1165. <if test="orderParam.orderStatus == 'all'">
  1166. AND a.hb_order_status in (0, 1,20,30,40,50,60,70,80)
  1167. </if>
  1168. <if test="orderParam.orderStatus == 'paddingPay'">
  1169. AND a.hb_order_status in (0)
  1170. </if>
  1171. <if test="orderParam.orderStatus == 'paddingShipped'">
  1172. AND a.hb_order_status in (1)
  1173. </if>
  1174. <if test="orderParam.orderStatus == 'paddingReceived'">
  1175. AND a.hb_order_status in (20,30,40,70)
  1176. </if>
  1177. <if test="orderParam.orderStatus == 'completed'">
  1178. AND a.hb_order_status in (80)
  1179. </if>
  1180. <if test="orderParam.orderStatus == 'cancel'">
  1181. AND a.hb_order_status in (50,60)
  1182. </if>
  1183. </if>
  1184. </where>
  1185. order by a.create_time desc,a.order_id desc
  1186. </select>
  1187. </mapper>