TbIndentMapper.xml 33 KB

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