OrdersProductDao.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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.znyun.commons.dao.OrdersProductDao">
  4. <select id="getOrdersRemind" resultType="Integer">
  5. SELECT count(*)
  6. FROM zny_orders_product o
  7. WHERE o.product_id IN (SELECT id FROM zny_product p WHERE p.user_id = #{userId}) AND o.is_remind = 0
  8. </select>
  9. <update id="updateOrdersIsRemind">
  10. UPDATE zny_orders
  11. SET is_remind = 1
  12. WHERE product_id IN (SELECT id FROM zny_product p WHERE user_id = #{userId})
  13. </update>
  14. <select id="getUserOrdersList" resultType="com.znyun.commons.response.OrdersProductResponse">
  15. SELECT
  16. o.id as ordersId,
  17. o.orders_no,
  18. o.state,
  19. o.service_mode,
  20. o.province,
  21. o.city,
  22. o.district,
  23. o.address,
  24. o.update_time,
  25. o.create_time,
  26. o.rate,
  27. o.shop_rate,
  28. o.zhi_rate,
  29. o.zhi_user_id,
  30. o.fei_user_id,
  31. o.fei_rate,
  32. o.ping_rate,
  33. o.order_number,
  34. o.pay_money,
  35. o.code,
  36. o.traffic_money,
  37. o.pay_type,
  38. p.id AS productId,
  39. p.name AS productName,
  40. p.image AS productImage,
  41. p.describes,
  42. p.category_def,
  43. p.unit,
  44. p.details_address AS productAddress,
  45. s.business_name as shopName,
  46. s.business_short_name as shopShortName,
  47. u.uid AS productUserId,
  48. u.user_name AS productUserName,
  49. u.avatar AS productUserAvatar,
  50. (SELECT count(*) FROM zny_comment_reply c WHERE c.orders_id = o.id AND c.user_id = #{userId}) AS commentCount
  51. FROM zny_orders_product o
  52. LEFT JOIN zny_product p ON o.product_id = p.id
  53. LEFT JOIN zny_user_shop s ON s.id = o.shop_id
  54. LEFT JOIN zny_user u ON u.uid = p.user_id
  55. WHERE o.orders_type = 1 AND o.is_del = 0 AND o.order_user_id = #{userId}
  56. <if test="status != null">
  57. AND o.state = #{status}
  58. </if>
  59. order BY o.create_time DESC
  60. </select>
  61. <select id="getWorkerTakeOrdersList" resultType="com.znyun.commons.response.OrdersProductResponse">
  62. SELECT
  63. o.id AS ordersId,
  64. o.orders_no,
  65. o.state,
  66. o.service_mode,
  67. o.province,
  68. o.city,
  69. o.district,
  70. o.address,
  71. o.update_time,
  72. o.create_time,
  73. o.rate,
  74. o.shop_rate,
  75. o.zhi_rate,
  76. o.zhi_user_id,
  77. o.fei_user_id,
  78. o.fei_rate,
  79. o.ping_rate,
  80. o.order_number,
  81. o.pay_money,
  82. o.code,
  83. o.traffic_money,
  84. o.pay_type,
  85. p.id AS productId,
  86. p.name AS productName,
  87. p.image AS productImage,
  88. p.describes,
  89. p.category_def,
  90. p.unit,
  91. u.uid AS productUserId,
  92. u.user_name AS productUserName,
  93. u.avatar AS productUserAvatar
  94. FROM zny_orders_product o
  95. LEFT JOIN zny_product p ON o.product_id = p.id
  96. LEFT JOIN zny_user u ON u.uid = p.user_id
  97. WHERE o.orders_type = 1 AND o.is_del = 0
  98. <if test="userId != null">
  99. AND o.worker_user_id = #{userId}
  100. </if>
  101. <if test="status != null">
  102. AND o.state = #{status}
  103. </if>
  104. order BY o.create_time DESC
  105. </select>
  106. <select id="getTeamOrdersList" resultType="Map">
  107. SELECT
  108. o.id AS ordersId,
  109. o.state,
  110. o.service_mode,
  111. o.create_time AS createTime,
  112. o.pay_money AS payMoney,
  113. o.order_user_id AS ordersUserId,
  114. o.code,
  115. o.order_number AS orderNumber,
  116. o.remarks,
  117. o.orders_no AS ordersNo,
  118. o.zhi_rate AS zhiRate,
  119. o.fei_rate AS feiRate,
  120. o.shop_rate AS shopRate,
  121. o.rate AS rate,
  122. p.id AS productId,
  123. p.unit,
  124. p.old_price AS oldPrice,
  125. u.user_name AS orderUserName,
  126. u.avatar AS orderUserAvatar,
  127. c.name AS categoryName,
  128. c.category_img
  129. FROM zny_orders_product o
  130. LEFT JOIN zny_product p ON p.id = o.product_id
  131. LEFT JOIN zny_user u ON u.uid = o.order_user_id
  132. LEFT JOIN zny_category c ON c.name LIKE p.category_def
  133. WHERE o.orders_type = 1
  134. <if test="status != null and status != 0">
  135. AND o.state = #{status}
  136. </if>
  137. <if test="type == 1">
  138. AND o.zhi_user_id = #{userId}
  139. </if>
  140. <if test="type == 2">
  141. AND o.fei_user_id = #{userId}
  142. </if>
  143. ORDER BY o.create_time DESC
  144. </select>
  145. <select id="getOrdersAllList" resultType="com.znyun.commons.response.OrdersProductResponse">
  146. SELECT
  147. o.id AS ordersId,
  148. o.orders_no,
  149. o.state,
  150. o.service_mode,
  151. o.province,
  152. o.city,
  153. o.district,
  154. o.address,
  155. o.address_user_name,
  156. o.address_phone,
  157. o.rate,
  158. o.shop_rate,
  159. o.zhi_rate,
  160. o.zhi_user_id,
  161. o.fei_rate,
  162. o.fei_user_id,
  163. o.ping_rate,
  164. o.order_number,
  165. o.pay_money,
  166. o.price_money,
  167. o.less_money,
  168. o.refund_content,
  169. o.orders_type,
  170. o.remarks,
  171. o.start_time,
  172. o.`code`,
  173. o.update_time,
  174. o.create_time,
  175. o.traffic_money,
  176. o.pay_type,
  177. p.id AS productId,
  178. p.name AS productName,
  179. p.image AS productImage,
  180. p.category_def,
  181. p.unit,
  182. p.member_price,
  183. u.uid AS productUserId,
  184. u.user_name AS productUserName,
  185. u.avatar AS productUserAvatar,
  186. u2.uid AS orderUserId,
  187. u2.user_name AS orderUserName,
  188. u2.avatar AS orderUserAvatar,
  189. u3.uid AS shareUserId,
  190. u3.user_name AS shareUserName,
  191. u3.avatar as shareUserAvatar,
  192. u4.uid AS workerUserId,
  193. u4.user_name AS workerUserName,
  194. u4.avatar AS workerUserAvatar,
  195. u5.user_name AS zhiUserName,
  196. u6.user_name AS feiUserName,
  197. cu.id AS couponUserId,
  198. cu.money AS couponMoney,
  199. s.business_name as shopName,
  200. s.business_short_name as shopShortName
  201. FROM zny_orders_product o
  202. LEFT JOIN zny_product p ON o.product_id = p.id
  203. LEFT JOIN zny_user u ON u.uid = p.user_id
  204. LEFT JOIN zny_user u2 ON u2.uid = o.order_user_id
  205. LEFT JOIN zny_user u3 ON u3.invitation_code = o.inviter_code
  206. LEFT JOIN zny_user u4 ON u4.uid = o.worker_user_id
  207. LEFT JOIN zny_user u5 ON u5.uid = o.zhi_user_id
  208. LEFT JOIN zny_user u6 ON u6.uid = o.fei_user_id
  209. LEFT JOIN zny_coupon_user cu ON cu.id = o.coupon_user_id
  210. LEFT JOIN zny_user_shop s ON s.id = o.shop_id
  211. WHERE o.orders_type = 1 AND o.is_del = 0
  212. <if test="shopId != null">
  213. AND o.shop_id = #{shopId}
  214. </if>
  215. <if test="orderUserId != null">
  216. AND o.order_user_id = #{orderUserId}
  217. </if>
  218. <if test="workerUserId != null">
  219. AND o.worker_user_id = #{workerUserId}
  220. </if>
  221. <if test="serviceMode != null">
  222. AND o.service_mode = #{serviceMode}
  223. </if>
  224. <if test="status != null">
  225. AND o.state = #{status}
  226. </if>
  227. <if test="orderUserName != null and orderUserName != ''">
  228. AND u2.user_name LIKE concat('%',#{orderUserName},'%')
  229. </if>
  230. <if test="shareUserName != null and shareUserName != ''">
  231. AND u3.user_name LIKE concat('%',#{shareUserName},'%')
  232. </if>
  233. <if test="workerUserName != null and workerUserName != ''">
  234. AND u4.user_name LIKE concat('%',#{workerUserName},'%')
  235. </if>
  236. <if test="ordersNo != null and ordersNo != ''">
  237. AND o.orders_no LIKE concat('%',#{ordersNo},'%')
  238. </if>
  239. <if test="startTime != null and startTime != ''">
  240. AND date_format(o.create_time,'%Y-%m-%d') >= date_format(#{startTime},'%Y-%m-%d')
  241. </if>
  242. <if test="endTime != null and endTime != ''">
  243. AND date_format(o.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  244. </if>
  245. ORDER BY o.create_time DESC
  246. </select>
  247. <select id="getUnDispatchOrdersList" resultType="com.znyun.commons.response.OrdersProductResponse">
  248. SELECT
  249. o.id as ordersId,
  250. o.*,
  251. p.id AS productId,
  252. p.name AS productName,
  253. p.image AS productImage,
  254. p.describes,
  255. p.category_def,
  256. p.unit,
  257. p.details_address AS productAddress,
  258. s.business_name as shopName,
  259. s.business_short_name as shopShortName
  260. FROM zny_orders_product o
  261. LEFT JOIN zny_product p ON o.product_id = p.id
  262. LEFT JOIN zny_user_shop s ON s.id = o.shop_id
  263. WHERE o.orders_type = 1 AND o.is_del = 0 AND o.shop_id = #{shopId}
  264. AND o.state = 1 and o.worker_user_id is null
  265. order BY o.create_time DESC
  266. </select>
  267. <select id="sumUserOrdersMoney" resultType="BigDecimal">
  268. SELECT ifnull(sum(money),0.00) FROM zny_user_money_details
  269. WHERE `type` = 1 AND (title LIKE '%订单完成%' OR title LIKE '%接单完成%') AND user_id = #{userId}
  270. <if test="startTime != null and startTime!=''">
  271. AND date_format(create_time,'%Y-%m-%d') >= date_format(#{startTime},'%Y-%m-%d')
  272. </if>
  273. <if test="endTime != null and endTime != ''">
  274. AND date_format(create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  275. </if>
  276. </select>
  277. <select id="sumUserOrdersCount" resultType="Integer">
  278. SELECT count(*) FROM zny_orders_product
  279. WHERE worker_user_id = #{userId} AND state IN (1,2,3)
  280. <if test="startTime != null and startTime != ''">
  281. AND date_format(create_time,'%Y-%m-%d')>=date_format(#{startTime},'%Y-%m-%d')
  282. </if>
  283. <if test="endTime != null and endTime != '' ">
  284. AND date_format(create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  285. </if>
  286. </select>
  287. <select id="avgUserOrdersScore" resultType="Float">
  288. SELECT
  289. IFNULL(AVG(c.score), 0)
  290. FROM zny_comment_reply c
  291. LEFT JOIN zny_orders_product o ON c.orders_id = o.id
  292. WHERE c.orders_id IS NOT NULL AND o.worker_user_id = #{userId}
  293. </select>
  294. <select id="sumUserOrdersStateCount" resultType="Integer">
  295. SELECT count(*) FROM zny_orders_product
  296. WHERE worker_user_id = #{userId} AND state = #{status}
  297. <if test="startTime != null and startTime != ''">
  298. AND date_format(create_time,'%Y-%m-%d') >= date_format(#{startTime},'%Y-%m-%d')
  299. </if>
  300. <if test="endTime != null and endTime != ''">
  301. AND date_format(create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  302. </if>
  303. </select>
  304. <select id="sumUserOrdersRefundMoney" resultType="BigDecimal">
  305. SELECT ifnull(sum(o.refund_price), 0.00) FROM zny_orders_product o
  306. WHERE o.worker_user_id = #{userId} AND o.refund_status = 2
  307. <if test="startTime!=null and startTime!=''">
  308. AND date_format(o.create_time,'%Y-%m-%d')>=date_format(#{startTime},'%Y-%m-%d')
  309. </if>
  310. <if test="endTime!=null and endTime!=''">
  311. AND date_format(o.create_time,'%Y-%m-%d')&lt;=date_format(#{endTime},'%Y-%m-%d')
  312. </if>
  313. </select>
  314. <select id="queryOrdersCount" resultType="Integer">
  315. SELECT count(*) FROM zny_orders_product WHERE state = 2
  316. <if test="type == 1">
  317. AND date_format(update_time,'%Y-%m-%d')=date_format(#{time},'%Y-%m-%d')
  318. </if>
  319. <if test="type == 2">
  320. AND date_format(update_time,'%Y-%m')=date_format(#{time},'%Y-%m')
  321. </if>
  322. <if test="type == 3">
  323. AND date_format(update_time,'%Y')=date_format(#{time},'%Y')
  324. </if>
  325. </select>
  326. <select id="sumTeamUserOrdersMoney" resultType="Double">
  327. SELECT
  328. <if test="type == 1">
  329. ifnull(sum(zhi_rate), 0.00)
  330. </if>
  331. <if test="type == 2">
  332. ifnull(sum(fei_rate), 0.00)
  333. </if>
  334. FROM zny_orders_product WHERE state = 2
  335. <if test="type == 1">
  336. AND zhi_user_id = #{userId}
  337. </if>
  338. <if test="type == 2">
  339. AND fei_user_id = #{userId}
  340. </if>
  341. </select>
  342. <select id="listOrderGroupByDate" resultType="Map">
  343. SELECT
  344. count(o.id) AS 'count',
  345. sum(o.pay_money) AS payMoney,
  346. LEFT(o.create_time, #{dateLen}) AS payTime
  347. FROM zny_orders_product o
  348. WHERE 1= 1 AND (o.state = 1 OR o.state = 2)
  349. <if test="startTime != null and startTime != ''">
  350. AND date_format(o.create_time,'%Y-%m-%d') >= date_format(#{startTime},'%Y-%m-%d')
  351. </if>
  352. <if test="endTime != null and endTime != ''">
  353. AND date_format(o.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  354. </if>
  355. GROUP BY payTime
  356. ORDER BY payTime ASC
  357. </select>
  358. </mapper>