OrderMapper.xml 49 KB

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