TbIndentMapper.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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.sqx.modules.errand.dao.TbIndentDao">
  4. <select id="findNewIndent" resultType="com.sqx.modules.errand.entity.TbIndent">
  5. select * from (
  6. select ti.*,
  7. (st_distance (point (ti.shop_lng,ti.shop_lat),point(#{riderLng},#{riderLat}) ) *111195) AS distancess,
  8. (st_distance (point (ti.user_lng,ti.user_lat),point(#{riderLng},#{riderLat}) ) *111195) AS distancessd
  9. from tb_indent ti
  10. where ti.indent_state = 2
  11. ) a
  12. where 1=1
  13. <if test="distances!=null and distances!=''">
  14. and ((distancess is not null and distancess &lt;= #{distances}) or (distancess is null and distancessd &lt;=
  15. #{distances}))
  16. </if>
  17. <if test="indentType!=null and indentType!=''">
  18. and indent_type = #{indentType}
  19. </if>
  20. order by create_time desc
  21. </select>
  22. <select id="findNewIndentByDistances" resultType="com.sqx.modules.errand.entity.TbIndent">
  23. select * from (
  24. select ti.*,
  25. (st_distance (point (ti.shop_lng,ti.shop_lat),point(#{queryDTO.riderLng},#{queryDTO.riderLat}) ) * 111195) AS
  26. distancess,
  27. (st_distance (point (ti.user_lng,ti.user_lat),point(#{queryDTO.riderLng},#{queryDTO.riderLat}) ) * 111195) AS
  28. distancessd
  29. from tb_indent ti
  30. where ti.indent_state = 2
  31. ) a
  32. <where>
  33. <if test="queryDTO.distances!= null">
  34. and ((distancess is not null and distancess &lt;= #{queryDTO.distances}) or (distancess is null and
  35. distancessd &lt;= #{queryDTO.distances}))
  36. </if>
  37. <if test="queryDTO.indentType != null and queryDTO.indentType != ''">
  38. and indent_type = #{queryDTO.indentType}
  39. </if>
  40. <if test="queryDTO.buyType != null and queryDTO.buyType != ''">
  41. and buy_type = #{queryDTO.buyType}
  42. </if>
  43. <if test="queryDTO.shopId != null">
  44. and shop_id = #{queryDTO.shopId}
  45. </if>
  46. </where>
  47. order by create_time desc
  48. </select>
  49. <select id="findNewIndentByDistancesGroupByShop" resultType="com.sqx.modules.errand.vo.ShopWaitAcceptOrderVO">
  50. select shop_id, shop_name, count(indent_id) as countOfWaitAccept from (
  51. select
  52. shop_id, shop_name, indent_id,
  53. (st_distance(point(shop_lng,shop_lat), point(#{queryDTO.riderLng}, #{queryDTO.riderLat})) * 111195) AS
  54. distancess,
  55. (st_distance(point(user_lng,user_lat), point(#{queryDTO.riderLng}, #{queryDTO.riderLat})) * 111195) AS
  56. distancessd
  57. from
  58. tb_indent
  59. where indent_state = 2
  60. ) a
  61. <where>
  62. <if test="queryDTO.distances!= null">
  63. and ((distancess is not null and distancess &lt;= #{queryDTO.distances}) or (distancess is null and
  64. distancessd &lt;= #{queryDTO.distances}))
  65. </if>
  66. <if test="queryDTO.indentType != null and queryDTO.indentType != ''">
  67. and indent_type = #{queryDTO.indentType}
  68. </if>
  69. <if test="queryDTO.buyType != null and queryDTO.buyType != ''">
  70. and buy_type = #{queryDTO.buyType}
  71. </if>
  72. <if test="queryDTO.shopId != null">
  73. and shop_id = #{queryDTO.shopId}
  74. </if>
  75. </where>
  76. group by
  77. shop_id, shop_name
  78. order by
  79. distancess asc
  80. </select>
  81. <select id="findNewIndentcity" resultType="com.sqx.modules.errand.entity.TbIndent">
  82. select * from (
  83. select ti.*,
  84. (st_distance (point (ti.shop_lng,ti.shop_lat),point(#{riderLng},#{riderLat}) ) *111195) AS distancess,
  85. (st_distance (point (ti.user_lng,ti.user_lat),point(#{riderLng},#{riderLat}) ) *111195) AS distancessd
  86. from tb_indent ti
  87. where ti.indent_state = 2
  88. ) a
  89. where
  90. user_city like concat('%',#{address},'%')
  91. <if test="indentType!=null and indentType!=''">
  92. and indent_type = #{indentType}
  93. </if>
  94. order by distancess asc
  95. </select>
  96. <select id="findNewIndentByCity" resultType="com.sqx.modules.errand.entity.TbIndent">
  97. select * from (
  98. select ti.*,
  99. (st_distance (point (ti.shop_lng,ti.shop_lat),point(#{queryDTO.riderLng},#{queryDTO.riderLat}) ) * 111195) AS
  100. distancess,
  101. (st_distance (point (ti.user_lng,ti.user_lat),point(#{queryDTO.riderLng},#{queryDTO.riderLat}) ) * 111195) AS
  102. distancessd
  103. from tb_indent ti
  104. where ti.indent_state = 2
  105. ) a
  106. where
  107. user_city like concat('%',#{queryDTO.city},'%')
  108. <if test="queryDTO.indentType!=null and queryDTO.indentType!=''">
  109. and indent_type = #{queryDTO.indentType}
  110. </if>
  111. <if test="queryDTO.buyType != null and queryDTO.buyType != ''">
  112. and buy_type = #{queryDTO.buyType}
  113. </if>
  114. <if test="queryDTO.shopId != null">
  115. and shop_id = #{queryDTO.shopId}
  116. </if>
  117. order by distancess asc
  118. </select>
  119. <select id="findNewIndentByCityGroupByShop" resultType="com.sqx.modules.errand.vo.ShopWaitAcceptOrderVO">
  120. select
  121. shop_id, shop_name,
  122. count(indent_id) as countOfWaitAccept,
  123. st_distance_sphere(point (shop_lng, shop_lat), point(#{queryDTO.riderLng}, #{queryDTO.riderLat})) AS distancess
  124. from
  125. tb_indent
  126. where
  127. indent_state = 2
  128. and shop_city like concat('%', #{queryDTO.city}, '%')
  129. <if test="queryDTO.indentType!=null and queryDTO.indentType!=''">
  130. and indent_type = #{queryDTO.indentType}
  131. </if>
  132. <if test="queryDTO.buyType != null and queryDTO.buyType != ''">
  133. and buy_type = #{queryDTO.buyType}
  134. </if>
  135. <if test="queryDTO.shopId != null">
  136. and shop_id = #{queryDTO.shopId}
  137. </if>
  138. group by
  139. shop_id, shop_name
  140. order by
  141. distancess asc
  142. </select>
  143. <select id="findIndentByNumber" resultType="com.sqx.modules.errand.entity.TbIndent">
  144. select *
  145. from tb_indent
  146. where indent_number = #{indentNumber}
  147. </select>
  148. <select id="findIndentByOrderId" resultType="com.sqx.modules.errand.entity.TbIndent">
  149. select *
  150. from tb_indent
  151. where order_id = #{orderId}
  152. </select>
  153. <select id="selectIndentByRiderUserCount" resultType="Integer">
  154. select count(*)
  155. from tb_indent
  156. where rider_user_id=#{riderUserId} and indent_state in (3,4)
  157. </select>
  158. <update id="indentReceiv">
  159. update tb_indent
  160. set indent_state = #{state},
  161. rider_user_id = #{userId},
  162. receiving_time = #{format}
  163. where indent_number = #{indentNumber}
  164. </update>
  165. <update id="indentReceiving">
  166. update tb_indent
  167. set indent_state = 3,
  168. rider_user_id = #{userId},
  169. receiving_time = #{format}
  170. where indent_number = #{indentNumber}
  171. </update>
  172. <update id="orderIndentReceiv">
  173. update tb_indent
  174. set indent_state = #{state},
  175. rider_user_id = #{userId},
  176. receiving_time = #{format}
  177. where order_id = #{orderId}
  178. </update>
  179. <update id="orderIndentReceiving">
  180. update tb_indent
  181. set indent_state = 4,
  182. rider_user_id = #{userId},
  183. receiving_time = #{format}
  184. where order_id = #{orderId}
  185. </update>
  186. <select id="findRiderIndent" resultType="com.sqx.modules.errand.entity.TbIndent">
  187. select * from tb_indent where rider_user_id = #{userId}
  188. <if test="keyword != null and keyword != ''">
  189. and (user_phone like concat('%',#{keyword},'%') or user_address_detail like concat('%',#{keyword},'%'))
  190. </if>
  191. <if test="indentState!=''">
  192. <if test="indentState==0">
  193. and indent_state = 0
  194. </if>
  195. <if test="indentState==2">
  196. and indent_state = 2
  197. </if>
  198. <if test="indentState==3">
  199. and indent_state = 3
  200. </if>
  201. <if test="indentState==4">
  202. and indent_state = 4
  203. </if>
  204. <if test="indentState==5">
  205. and indent_state = 5
  206. </if>
  207. <if test="indentState==6">
  208. and indent_state = 6
  209. </if>
  210. <if test="indentState==8 or indentState==9 or indentState==10">
  211. and (indent_state = 8 or indent_state = 9 or indent_state = 10)
  212. </if>
  213. </if>
  214. order by receiving_time desc
  215. </select>
  216. <select id="findRiderIndentByIds" resultType="com.sqx.modules.errand.vo.queryOrderInfoVo">
  217. select indent_id,shop_name,order_pay_sequence,user_name,user_phone,user_province,user_city,user_district,user_lng,user_lat,user_address_detail
  218. from tb_indent where rider_user_id = #{userId}
  219. <if test="indentIds != null and indentIds.size() > 0">
  220. and indent_id in
  221. <foreach collection="indentIds" item="indentId" index="index" open="(" separator="," close=")">
  222. #{indentId}
  223. </foreach>
  224. </if>
  225. order by receiving_time desc
  226. </select>
  227. <select id="indentRiderMessage" resultType="com.sqx.modules.errand.entity.TbIndent">
  228. select ti.*,
  229. (st_distance(point(ti.shop_lng, ti.shop_lat), point(#{riderLng}, #{riderLat})) * 111195) AS distancess,
  230. (st_distance(point(ti.user_lng, ti.user_lat), point(#{riderLng}, #{riderLat})) * 111195) AS distancessd,
  231. u.nick_name as nickName,
  232. u.phone as phone,
  233. u.avatar as avatar
  234. from tb_indent ti
  235. left join tb_user u on ti.user_id = u.user_id
  236. where indent_number = #{indentNumber}
  237. </select>
  238. <select id="indentMessageByOrderId" resultType="com.sqx.modules.errand.entity.TbIndent">
  239. select ti.*,
  240. (st_distance(point(ti.shop_lng, ti.shop_lat), point(#{riderLng}, #{riderLat})) * 111195) AS distancess,
  241. (st_distance(point(ti.user_lng, ti.user_lat), point(#{riderLng}, #{riderLat})) * 111195) AS distancessd,
  242. u.nick_name as nickName,
  243. u.phone as phone,
  244. u.avatar as avatar
  245. from tb_indent ti
  246. left join tb_user u on ti.user_id = u.user_id
  247. where order_id = #{orderId}
  248. </select>
  249. <update id="riderCancleIndent">
  250. update tb_indent
  251. set indent_state = 2,
  252. receiving_time = null,
  253. rider_user_id = null
  254. where rider_user_id = #{riderUserId}
  255. and indent_number = #{indentNumber}
  256. </update>
  257. <update id="updateRiderCashDeposit">
  258. update tb_user
  259. set cash_deposit = #{cashDeposit}
  260. where user_id = #{userId}
  261. </update>
  262. <update id="riderDelivery">
  263. update tb_indent
  264. set indent_state = 6,
  265. finish_time = #{date}
  266. where indent_id = #{indentId}
  267. </update>
  268. <select id="selectIndentByIndentNumber" resultType="com.sqx.modules.errand.entity.TbIndent">
  269. select ti.*, t.nick_name as nickName, t.avatar
  270. from tb_indent ti
  271. LEFT JOIN tb_user t on ti.user_id = t.user_id
  272. where indent_number = #{indentNumber}
  273. </select>
  274. <select id="selectIndentByIndentNumbers" resultType="com.sqx.modules.errand.entity.TbIndent">
  275. select ti.*, t.nick_name as nickName, t.avatar
  276. from tb_indent ti
  277. LEFT JOIN tb_user t on ti.user_id = t.user_id
  278. where indent_number in
  279. <foreach collection="indentNumbers" item="indentNumber" index="index" open="(" separator="," close=")">
  280. #{indentNumber}
  281. </foreach>
  282. </select>
  283. <update id="updateRiderBalance">
  284. update tb_user
  285. set balance = #{balance}
  286. where user_id = #{userId}
  287. </update>
  288. <update id="userDelivery">
  289. update tb_indent
  290. set indent_state = 6,
  291. finish_time = #{date}
  292. where user_id = #{userId}
  293. and indent_number = #{indentNumber}
  294. </update>
  295. <select id="findallIndent" resultType="com.sqx.modules.errand.entity.TbIndent">
  296. select i.*,
  297. ru.nick_name as riderNickName, ru.phone as riderPhone
  298. from tb_indent i
  299. LEFT JOIN tb_user ru on i.rider_user_id = ru.user_id
  300. where 1 = 1
  301. <if test="riderPhone!=null and riderPhone!=''">
  302. and ru.phone = #{riderPhone}
  303. </if>
  304. <if test="userId!=null">
  305. and i.user_id = #{userId}
  306. </if>
  307. <if test="riderUserId!=null">
  308. and i.rider_user_id = #{riderUserId}
  309. </if>
  310. <if test="shopId!=null">
  311. and i.shop_id = #{shopId}
  312. </if>
  313. <if test="indentType!=null">
  314. and i.indent_type=#{indentType}
  315. </if>
  316. <if test="indentType==null">
  317. and i.indent_type in (1, 2, 3, 4)
  318. </if>
  319. <if test="ordersNo!=null and ordersNo!=''">
  320. and i.indent_number=#{ordersNo}
  321. </if>
  322. <if test="status!=null">
  323. and i.indent_state=#{status}
  324. </if>
  325. order by i.create_time desc
  326. </select>
  327. <update id="updateDefault">
  328. update errand_address
  329. set address_default = "0"
  330. where user_id = #{userId}
  331. </update>
  332. <insert id="addUserAddress" useGeneratedKeys="true" keyProperty="addressId"
  333. parameterType="com.sqx.modules.errand.entity.ErrandAddress">
  334. insert into errand_address (user_id, user_name, user_phone, address, address_detail, address_longitude,
  335. address_latitude, create_time, delete_flag, address_default)
  336. values (#{userId}, #{userName}, #{userPhone}, #{address}, #{addressDetail}, #{addressLongitude},
  337. #{addressLatitude}, #{createTime}, "0", #{addressDefault})
  338. </insert>
  339. <update id="updateAddress">
  340. update errand_address set
  341. update_time = #{updatetime},
  342. <if test="userName!=null and userName!=''">
  343. user_name= #{userName},
  344. </if>
  345. <if test="userPhone!=null and userPhone!=''">
  346. user_phone = #{userPhone},
  347. </if>
  348. <if test="address!=null and address!=''">
  349. address = #{address},
  350. </if>
  351. <if test="addressDetail!=null and addressDetail!=''">
  352. address_detail = #{addressDetail},
  353. </if>
  354. <if test="lng!=null and lng!=''">
  355. address_longitude = #{lng},
  356. </if>
  357. <if test="lat!=null and lat!=''">
  358. address_latitude = #{lat},
  359. </if>
  360. <if test="addressDefault!=null and addressDefault!=''">
  361. address_default = #{addressDefault}
  362. </if>
  363. where user_id = #{userId} and address_id = #{addressId}
  364. </update>
  365. <select id="findUserAddress" resultType="com.sqx.modules.errand.entity.ErrandAddress">
  366. select *
  367. from errand_address
  368. where user_id = #{userId}
  369. and delete_flag = "0"
  370. </select>
  371. <select id="findAddressById" resultType="com.sqx.modules.errand.entity.ErrandAddress">
  372. select *
  373. from errand_address
  374. where user_id = #{userId}
  375. and address_id = #{addressId}
  376. </select>
  377. <update id="addDefaultAddress">
  378. update errand_address
  379. set address_default = "1"
  380. where user_id = #{userId}
  381. and address_id = #{addressId}
  382. </update>
  383. <update id="delUserAddress">
  384. update errand_address
  385. set delete_flag = "1"
  386. where user_id = #{userId}
  387. and address_id = #{addressId}
  388. </update>
  389. <select id="findRed" resultType="com.sqx.modules.errand.entity.ErrandRedPacket">
  390. select *
  391. from errand_user_red_packet
  392. where red_packet_id = #{redPacketId}
  393. </select>
  394. <update id="delRedPacket">
  395. update errand_user_red_packet
  396. set delete_flag = "1"
  397. where red_packet_id = #{redPacketId}
  398. </update>
  399. <select id="findAllIndent" resultType="com.sqx.modules.errand.entity.TbIndent">
  400. select i.*, t.nick_name as nickName, t.avatar as avatar , r.red_packet_amount as redPacketAmount,
  401. ru.nick_name as riderNickName, ru.phone as riderPhone
  402. from tb_indent i
  403. LEFT JOIN tb_user t on i.user_id = t.user_id
  404. LEFT JOIN tb_user ru on i.rider_user_id = ru.user_id
  405. LEFT JOIN errand_user_red_packet r on i.red_packet_id = r.red_packet_id where indent_type = #{indentType}
  406. <if test="phone!=null and phone!=''">
  407. and user_phone = #{phone}
  408. </if>
  409. <if test="riderPhone!=null and riderPhone!=''">
  410. and ru.phone = #{riderPhone}
  411. </if>
  412. <if test="indentState==0">
  413. and indent_state in (0, 1, 2, 3 ,4 ,5 ,6 ,8 ,10)
  414. </if>
  415. <if test="indentState==1">
  416. and indent_state = 0
  417. </if>
  418. <if test="indentState==2">
  419. and indent_state = 2
  420. </if>
  421. <if test="indentState==3">
  422. and indent_state in (3, 4, 5)
  423. </if>
  424. <if test="indentState==4">
  425. and indent_state = 6
  426. </if>
  427. <if test="indentState==5">
  428. and indent_state in (1, 8, 10)
  429. </if>
  430. <if test="dateType=='day'">
  431. and date_format(i.create_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  432. </if>
  433. <if test="dateType=='month'">
  434. and date_format(i.create_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  435. </if>
  436. <if test="dateType=='year'">
  437. and date_format(i.create_time,'%Y')=date_format(#{date},'%Y')
  438. </if>
  439. order by i.create_time desc
  440. </select>
  441. <select id="findAllIndents" resultType="com.sqx.modules.errand.entity.TbIndent">
  442. select i.*, t.nick_name as nickName, t.avatar as avatar ,
  443. ru.nick_name as riderNickName, ru.phone as riderPhone,
  444. r.red_packet_amount as redPacketAmount from tb_indent i
  445. LEFT JOIN tb_user t on i.user_id = t.user_id
  446. LEFT JOIN tb_user ru on i.rider_user_id = ru.user_id
  447. LEFT JOIN errand_user_red_packet r on i.red_packet_id = r.red_packet_id where indent_type = #{indentType}
  448. <if test="phone!=null and phone!=''">
  449. and user_phone = #{phone}
  450. </if>
  451. <if test="riderPhone!=null and riderPhone!=''">
  452. and ru.phone = #{riderPhone}
  453. </if>
  454. <if test="indentState==0">
  455. and indent_state in (0, 1, 2, 3 ,4 ,5 ,6 ,8 ,10)
  456. </if>
  457. <if test="indentState!=0">
  458. and indent_state = #{indentState}
  459. </if>
  460. <if test="dateType=='day'">
  461. and date_format(i.create_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  462. </if>
  463. <if test="dateType=='month'">
  464. and date_format(i.create_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  465. </if>
  466. <if test="dateType=='year'">
  467. and date_format(i.create_time,'%Y')=date_format(#{date},'%Y')
  468. </if>
  469. order by i.create_time desc
  470. </select>
  471. <select id="IndentCenter" resultType="com.sqx.modules.errand.entity.TbIndent">
  472. select i.*, u.nick_name as nickName, u.phone as phone from tb_indent i left join tb_user u on u.user_id =
  473. i.rider_user_id where 1 = 1
  474. <if test="indentType!=null and indentType!=''">
  475. and indent_type = #{indentType}
  476. </if>
  477. <if test="indentNumber!=null and indentNumber!=''">
  478. and indent_number = #{indentNumber}
  479. </if>
  480. <if test="indentState!=null and indentState!=''">
  481. and indent_state = #{indentState}
  482. </if>
  483. <if test="indentState==null or indentState==''">
  484. and indent_state in (3,4,5,6)
  485. </if>
  486. <if test="dateType=='day'">
  487. and date_format(i.create_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  488. </if>
  489. <if test="dateType=='month'">
  490. and date_format(i.create_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  491. </if>
  492. <if test="dateType=='year'">
  493. and date_format(i.create_time,'%Y')=date_format(#{date},'%Y')
  494. </if>
  495. <if test="phone!=null and phone!=''">
  496. and u.phone like concat('%',#{phone},'%')
  497. </if>
  498. order by i.create_time desc
  499. </select>
  500. <update id="updateIndentState">
  501. update tb_indent
  502. set indent_state = #{indentState}
  503. where indent_number = #{indentNumber}
  504. </update>
  505. <update id="adminSoldOutIndent">
  506. update tb_indent
  507. set indent_state = 10
  508. where indent_number = #{indentNumber}
  509. </update>
  510. <select id="billMoney" resultType="java.math.BigDecimal">
  511. select ifnull(sum(indent_money),0) from tb_indent where indent_state in (2, 3, 4, 6)
  512. <if test="query.dateType=='day'">
  513. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  514. </if>
  515. <if test="query.dateType=='month'">
  516. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  517. </if>
  518. <if test="query.dateType=='year'">
  519. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  520. </if>
  521. <if test="query.startTime!=null and query.startTime!=''">
  522. and create_time>=#{query.startTime}
  523. </if>
  524. <if test="query.endTime!=null and query.endTime!=''">
  525. and create_time <![CDATA[<=]]> #{query.endTime}
  526. </if>
  527. </select>
  528. <select id="receivingMoney" resultType="java.math.BigDecimal">
  529. select ifnull(sum(indent_money),0) from tb_indent where indent_state in (3, 4, 6)
  530. <if test="query.dateType=='day'">
  531. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  532. </if>
  533. <if test="query.dateType=='month'">
  534. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  535. </if>
  536. <if test="query.dateType=='year'">
  537. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  538. </if>
  539. <if test="query.startTime!=null and query.startTime!=''">
  540. and create_time>=#{query.startTime}
  541. </if>
  542. <if test="query.endTime!=null and query.endTime!=''">
  543. and create_time <![CDATA[<=]]> #{query.endTime}
  544. </if>
  545. </select>
  546. <select id="billCount" resultType="int">
  547. select count(*) from tb_indent
  548. where indent_state in (2, 3, 4, 6)
  549. <if test="query.dateType=='day'">
  550. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  551. </if>
  552. <if test="query.dateType=='month'">
  553. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  554. </if>
  555. <if test="query.dateType=='year'">
  556. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  557. </if>
  558. <if test="query.startTime!=null and query.startTime!=''">
  559. and create_time>=#{query.startTime}
  560. </if>
  561. <if test="query.endTime!=null and query.endTime!=''">
  562. and create_time <![CDATA[<=]]> #{query.endTime}
  563. </if>
  564. </select>
  565. <select id="reveivingCount" resultType="int">
  566. select count(*) from tb_indent where indent_state in (3, 4, 6)
  567. <if test="query.dateType=='day'">
  568. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  569. </if>
  570. <if test="query.dateType=='month'">
  571. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  572. </if>
  573. <if test="query.dateType=='year'">
  574. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  575. </if>
  576. <if test="query.startTime!=null and query.startTime!=''">
  577. and create_time>=#{query.startTime}
  578. </if>
  579. <if test="query.endTime!=null and query.endTime!=''">
  580. and create_time <![CDATA[<=]]> #{query.endTime}
  581. </if>
  582. </select>
  583. <select id="taskAnalysisMoney" resultType="com.sqx.modules.errand.entity.TbIndent">
  584. select s.indent_type,t.nick_name as nickName,u.nick_name as riderNickName, s.create_time, s.platform_money,
  585. s.user_id, s.rider_user_id from tb_indent s
  586. left join tb_user t on s.user_id = t.user_id
  587. left join tb_user u on s.rider_user_id = u.user_id
  588. where indent_state = "6"
  589. <if test="indentState!=null and indentState!=''">
  590. and s.indent_state = #{status}
  591. </if>
  592. <if test="query.startTime!=null and query.startTime!=''">
  593. and s.create_time>=#{query.startTime}
  594. </if>
  595. <if test="query.endTime!=null and query.endTime!=''">
  596. and s.create_time <![CDATA[<=]]> #{query.endTime}
  597. </if>
  598. order by s.create_time desc
  599. </select>
  600. <select id="findAllCount" resultType="int">
  601. select count(*)
  602. from tb_user
  603. where status = "1"
  604. </select>
  605. <select id="findDayAddUser" resultType="int">
  606. select count(*)
  607. from tb_user
  608. where status = "1"
  609. and create_time &gt; #{date}
  610. </select>
  611. <select id="findMonthAddUser" resultType="int">
  612. select count(*)
  613. from tb_user
  614. where status = "1"
  615. and create_time &gt; #{date}
  616. </select>
  617. <select id="findYearAddUser" resultType="int">
  618. select count(*)
  619. from tb_user
  620. where status = "1"
  621. and create_time &gt; #{date}
  622. </select>
  623. <select id="findDayIncome" resultType="java.math.BigDecimal">
  624. select ifnull(sum(platform_money), 0)
  625. from tb_indent
  626. where indent_state = "6"
  627. and create_time &gt; #{date}
  628. </select>
  629. <select id="findMonthIncome" resultType="java.math.BigDecimal">
  630. select ifnull(sum(platform_money), 0)
  631. from tb_indent
  632. where indent_state = "6"
  633. and create_time &gt; #{date}
  634. </select>
  635. <select id="findYearIncome" resultType="java.math.BigDecimal">
  636. select ifnull(sum(platform_money), 0)
  637. from tb_indent
  638. where indent_state = "6"
  639. and create_time &gt; #{date}
  640. </select>
  641. <select id="findIndentCount" resultType="int">
  642. select count(*)
  643. from tb_indent
  644. where indent_state = "6"
  645. </select>
  646. <select id="selectOrderByStatus" resultType="int">
  647. select count(*) from tb_indent where 1 = 1
  648. <if test="status!=null">
  649. and indent_state = #{status}
  650. </if>
  651. <if test="query.startTime!=null and query.startTime!=''">
  652. and create_time>=#{query.startTime}
  653. </if>
  654. <if test="query.endTime!=null and query.endTime!=''">
  655. and create_time <![CDATA[<=]]> #{query.endTime}
  656. </if>
  657. </select>
  658. <select id="findAdminIncomeday" resultType="java.math.BigDecimal">
  659. select ifnull(sum(rider_money),0) from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  660. <if test="dateType=='day'">
  661. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  662. </if>
  663. <if test="dateType=='month'">
  664. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  665. </if>
  666. <if test="dateType=='year'">
  667. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  668. </if>
  669. </select>
  670. <select id="findPrepayMoney" resultType="java.math.BigDecimal">
  671. select ifnull(sum(prepay_money),0) from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  672. <if test="dateType=='day'">
  673. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  674. </if>
  675. <if test="dateType=='month'">
  676. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  677. </if>
  678. <if test="dateType=='year'">
  679. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  680. </if>
  681. </select>
  682. <select id="findAdminIndentCount" resultType="int">
  683. select count(*) from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  684. <if test="dateType=='day'">
  685. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  686. </if>
  687. <if test="dateType=='month'">
  688. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  689. </if>
  690. <if test="dateType=='year'">
  691. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  692. </if>
  693. </select>
  694. <select id="selectIndentById" resultType="com.sqx.modules.errand.entity.TbIndent">
  695. select * from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  696. <if test="dateType=='day'">
  697. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  698. </if>
  699. <if test="dateType=='month'">
  700. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  701. </if>
  702. <if test="dateType=='year'">
  703. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  704. </if>
  705. order by create_time desc
  706. </select>
  707. <select id="findUserIndent" resultType="com.sqx.modules.errand.entity.TbIndent">
  708. select t.*,(select count(*) from errand_evaluate e where e.user_id=#{userId} and
  709. t.indent_number=e.indent_number) as evaluateMessage
  710. from tb_indent t where t.user_id = #{userId} and t.indent_type != 5
  711. <if test="indentState==1">
  712. and t.indent_state in ("0", "2", "3", "4", "6", "8", "9", "10")
  713. </if>
  714. <if test="indentState==2">
  715. and t.indent_state = "0"
  716. </if>
  717. <if test="indentState==3">
  718. and t.indent_state = "2"
  719. </if>
  720. <if test="indentState==4">
  721. and t.indent_state = "3"
  722. </if>
  723. <if test="indentState==5">
  724. and t.indent_state = "4"
  725. </if>
  726. <if test="indentState==6">
  727. and t.indent_state = "6"
  728. </if>
  729. <if test="indentState==7">
  730. and t.indent_state in ("8", "9", "10")
  731. </if>
  732. order by t.create_time desc
  733. </select>
  734. <select id="indentMessage" resultType="com.sqx.modules.errand.entity.TbIndent">
  735. select i.*,
  736. r.red_packet_amount as redPacketAmount,
  737. u.nick_name as riderNickName,
  738. u.phone as phone,
  739. u.avatar as avatar
  740. from tb_indent i
  741. left join tb_user u on i.rider_user_id = u.user_id
  742. left join errand_user_red_packet r on i.red_packet_id = r.red_packet_id
  743. where indent_number = #{indentNumber}
  744. </select>
  745. <select id="find5KmRider" resultType="com.sqx.modules.app.entity.UserEntity">
  746. SELECT *
  747. FROM tb_user
  748. WHERE (st_distance(point(station_lng, station_lat), point(#{lng}, #{lat})) * 111195) &lt; 50000
  749. and user_type = "2"
  750. and on_line_flag = "1"
  751. </select>
  752. <update id="updateCoordinate">
  753. update tb_user
  754. set station_lng = #{lng},
  755. station_lat = #{lat}
  756. where user_id = #{userId}
  757. </update>
  758. <select id="findUserInfoById" resultType="com.sqx.modules.app.entity.UserEntity">
  759. select *
  760. from tb_user
  761. where user_id = #{userId}
  762. </select>
  763. <select id="findAllRedPacket" resultType="com.sqx.modules.errand.entity.ErrandRedPacket">
  764. select *
  765. from errand_user_red_packet
  766. where user_id = #{userId}
  767. and delete_flag = "0"
  768. and expiration_time &gt; #{expirationTime}
  769. </select>
  770. <!--获取可用红包-->
  771. <select id="findRedPacket" resultType="com.sqx.modules.errand.entity.ErrandRedPacket">
  772. select *
  773. from errand_user_red_packet
  774. where user_id = #{userId}
  775. and (red_packet_type = "0" or red_packet_type = #{indentType})
  776. and minimum_amount &lt;= #{indentBasicsMoney}
  777. and expiration_time &gt; #{expirationTime}
  778. and delete_flag = "0"
  779. order by create_time desc
  780. </select>
  781. <update id="userCancleIndent">
  782. update tb_indent
  783. set indent_state = "8",
  784. cancel_indent_time = #{cancelIndentTime}
  785. where user_id = #{userId}
  786. and indent_number = #{indentNumber}
  787. </update>
  788. <update id="updateRedPaclet">
  789. update errand_user_red_packet
  790. set delete_flag = "0"
  791. where red_packet_id = #{redPacketId}
  792. </update>
  793. <select id="selectIndentList" resultType="com.sqx.modules.errand.entity.TbIndent">
  794. select *
  795. from tb_indent
  796. where rider_user_id = #{userId}
  797. and indent_state in (3, 4)
  798. </select>
  799. <select id="selectSendOrder" resultType="com.sqx.modules.errand.entity.TbIndent">
  800. select *
  801. from tb_indent
  802. where indent_state = 2
  803. and indent_type in (1, 2, 3, 5)
  804. and create_time &lt; #{date}
  805. </select>
  806. <select id="selectRiderByDictance" resultType="Long">
  807. select user_id
  808. from (
  809. SELECT t.user_id,
  810. (select count(*) from tb_indent i
  811. where i.rider_user_id=t.user_id and i.indent_state in (3,4)) as ordersCount ,
  812. (st_distance(point(t.station_lat, t.station_lng), point(#{userLat}, #{userLng})) *
  813. 111195) AS distance
  814. FROM tb_user t
  815. WHERE t.on_line_flag = 1
  816. and t.cash_deposit &gt;= #{cashDeposit}
  817. and user_id not in (select rider_user_id from tb_indent where indent_state in (3, 4))
  818. ) a
  819. where distance &lt; #{distance} and ordersCount &lt; #{maxNum}
  820. order by distance asc limit 1
  821. </select>
  822. <!--
  823. 现在根据订单地址,查出了距离该位置最近的骑手
  824. 但是还要再加一个条件:要查出距离该订单最近的,没有进行中的订单的骑手
  825. 判断骑手是否有订单在进行中:indent_state in (3, 4)
  826. select * from (
  827. SELECT
  828. t.user_id,
  829. ti.indent_id,
  830. (st_distance (point (t.station_lat, t.station_lng),point (34.16351, 108.65161)) * 111195) AS distance
  831. FROM
  832. tb_user t
  833. LEFT JOIN tb_indent ti ON t.user_id = ti.rider_user_id
  834. WHERE
  835. ti.indent_state NOT IN (3, 4) and t.on_line_flag = 1
  836. ) a where distance<100000 order by distance asc limit 1
  837. ====================================
  838. select tu.user_id, (st_distance (point (station_lat, station_lng), point(#{userLat},#{userLng}) ) *111195) as distance
  839. from tb_user tu where ((st_distance (point (station_lat, station_lng), point(#{userLat},#{userLng}) ) *111195)) &lt; #{distance}
  840. order by distance asc limit 1
  841. -->
  842. </mapper>