TbIndentMapper.xml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  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 = 4,
  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="query.dateType=='day'">
  481. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  482. </if>
  483. <if test="query.dateType=='month'">
  484. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  485. </if>
  486. <if test="query.dateType=='year'">
  487. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  488. </if>
  489. <if test="query.startTime!=null and query.startTime!=''">
  490. and create_time>=#{query.startTime}
  491. </if>
  492. <if test="query.endTime!=null and query.endTime!=''">
  493. and create_time <![CDATA[<=]]> #{query.endTime}
  494. </if>
  495. </select>
  496. <select id="receivingMoney" resultType="java.math.BigDecimal">
  497. select ifnull(sum(indent_money),0) from tb_indent where indent_state in (3, 4, 6)
  498. <if test="query.dateType=='day'">
  499. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  500. </if>
  501. <if test="query.dateType=='month'">
  502. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  503. </if>
  504. <if test="query.dateType=='year'">
  505. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  506. </if>
  507. <if test="query.startTime!=null and query.startTime!=''">
  508. and create_time>=#{query.startTime}
  509. </if>
  510. <if test="query.endTime!=null and query.endTime!=''">
  511. and create_time <![CDATA[<=]]> #{query.endTime}
  512. </if>
  513. </select>
  514. <select id="billCount" resultType="int">
  515. select count(*) from tb_indent
  516. where indent_state in (2, 3, 4, 6)
  517. <if test="query.dateType=='day'">
  518. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  519. </if>
  520. <if test="query.dateType=='month'">
  521. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  522. </if>
  523. <if test="query.dateType=='year'">
  524. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  525. </if>
  526. <if test="query.startTime!=null and query.startTime!=''">
  527. and create_time>=#{query.startTime}
  528. </if>
  529. <if test="query.endTime!=null and query.endTime!=''">
  530. and create_time <![CDATA[<=]]> #{query.endTime}
  531. </if>
  532. </select>
  533. <select id="reveivingCount" resultType="int">
  534. select count(*) from tb_indent where indent_state in (3, 4, 6)
  535. <if test="query.dateType=='day'">
  536. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  537. </if>
  538. <if test="query.dateType=='month'">
  539. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  540. </if>
  541. <if test="query.dateType=='year'">
  542. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  543. </if>
  544. <if test="query.startTime!=null and query.startTime!=''">
  545. and create_time>=#{query.startTime}
  546. </if>
  547. <if test="query.endTime!=null and query.endTime!=''">
  548. and create_time <![CDATA[<=]]> #{query.endTime}
  549. </if>
  550. </select>
  551. <select id="taskAnalysisMoney" resultType="com.sqx.modules.errand.entity.TbIndent">
  552. select s.indent_type,t.nick_name as nickName,u.nick_name as riderNickName, s.create_time, s.platform_money,
  553. s.user_id, s.rider_user_id from tb_indent s
  554. left join tb_user t on s.user_id = t.user_id
  555. left join tb_user u on s.rider_user_id = u.user_id
  556. where indent_state = "6"
  557. <if test="query.dateType=='day'">
  558. and date_format(s.create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  559. </if>
  560. <if test="query.dateType=='month'">
  561. and date_format(s.create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  562. </if>
  563. <if test="query.dateType=='year'">
  564. and date_format(s.create_time,'%Y')=date_format(#{query.date},'%Y')
  565. </if>
  566. <if test="indentState!=null and indentState!=''">
  567. and s.indent_state = #{status}
  568. </if>
  569. <if test="query.startTime!=null and query.startTime!=''">
  570. and s.create_time>=#{query.startTime}
  571. </if>
  572. <if test="query.endTime!=null and query.endTime!=''">
  573. and s.create_time <![CDATA[<=]]> #{query.endTime}
  574. </if>
  575. order by s.create_time desc
  576. </select>
  577. <select id="findAllCount" resultType="int">
  578. select count(*)
  579. from tb_user
  580. where status = "1"
  581. </select>
  582. <select id="findDayAddUser" resultType="int">
  583. select count(*)
  584. from tb_user
  585. where status = "1"
  586. and create_time &gt; #{date}
  587. </select>
  588. <select id="findMonthAddUser" resultType="int">
  589. select count(*)
  590. from tb_user
  591. where status = "1"
  592. and create_time &gt; #{date}
  593. </select>
  594. <select id="findYearAddUser" resultType="int">
  595. select count(*)
  596. from tb_user
  597. where status = "1"
  598. and create_time &gt; #{date}
  599. </select>
  600. <select id="findDayIncome" resultType="java.math.BigDecimal">
  601. select ifnull(sum(platform_money), 0)
  602. from tb_indent
  603. where indent_state = "6"
  604. and create_time &gt; #{date}
  605. </select>
  606. <select id="findMonthIncome" resultType="java.math.BigDecimal">
  607. select ifnull(sum(platform_money), 0)
  608. from tb_indent
  609. where indent_state = "6"
  610. and create_time &gt; #{date}
  611. </select>
  612. <select id="findYearIncome" resultType="java.math.BigDecimal">
  613. select ifnull(sum(platform_money), 0)
  614. from tb_indent
  615. where indent_state = "6"
  616. and create_time &gt; #{date}
  617. </select>
  618. <select id="findIndentCount" resultType="int">
  619. select count(*)
  620. from tb_indent
  621. where indent_state = "6"
  622. </select>
  623. <select id="selectOrderByStatus" resultType="int">
  624. select count(*) from tb_indent where 1 = 1
  625. <if test="status!=null">
  626. and indent_state = #{status}
  627. </if>
  628. <if test="query.dateType=='day'">
  629. and date_format(create_time,'%Y-%m-%d')=date_format(#{query.date},'%Y-%m-%d')
  630. </if>
  631. <if test="query.dateType=='month'">
  632. and date_format(create_time,'%Y-%m')=date_format(#{query.date},'%Y-%m')
  633. </if>
  634. <if test="query.dateType=='year'">
  635. and date_format(create_time,'%Y')=date_format(#{query.date},'%Y')
  636. </if>
  637. <if test="query.startTime!=null and query.startTime!=''">
  638. and create_time>=#{query.startTime}
  639. </if>
  640. <if test="query.endTime!=null and query.endTime!=''">
  641. and create_time <![CDATA[<=]]> #{query.endTime}
  642. </if>
  643. </select>
  644. <select id="findAdminIncomeday" resultType="java.math.BigDecimal">
  645. select ifnull(sum(rider_money),0) 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. </select>
  656. <select id="findPrepayMoney" resultType="java.math.BigDecimal">
  657. select ifnull(sum(prepay_money),0) from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  658. <if test="dateType=='day'">
  659. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  660. </if>
  661. <if test="dateType=='month'">
  662. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  663. </if>
  664. <if test="dateType=='year'">
  665. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  666. </if>
  667. </select>
  668. <select id="findAdminIndentCount" resultType="int">
  669. select count(*) from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  670. <if test="dateType=='day'">
  671. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  672. </if>
  673. <if test="dateType=='month'">
  674. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  675. </if>
  676. <if test="dateType=='year'">
  677. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  678. </if>
  679. </select>
  680. <select id="selectIndentById" resultType="com.sqx.modules.errand.entity.TbIndent">
  681. select * from tb_indent where rider_user_id = #{userId} and indent_state = "6"
  682. <if test="dateType=='day'">
  683. and date_format(finish_time,'%Y-%m-%d')=date_format(#{date},'%Y-%m-%d')
  684. </if>
  685. <if test="dateType=='month'">
  686. and date_format(finish_time,'%Y-%m')=date_format(#{date},'%Y-%m')
  687. </if>
  688. <if test="dateType=='year'">
  689. and date_format(finish_time,'%Y')=date_format(#{date},'%Y')
  690. </if>
  691. order by create_time desc
  692. </select>
  693. <select id="findUserIndent" resultType="com.sqx.modules.errand.entity.TbIndent">
  694. select t.*,(select count(*) from errand_evaluate e where e.user_id=#{userId} and t.indent_number=e.indent_number) as evaluateMessage
  695. from tb_indent t where t.user_id = #{userId} and t.indent_type != 5
  696. <if test="indentState==1">
  697. and t.indent_state in ("0", "2", "3", "4", "6", "8", "9", "10")
  698. </if>
  699. <if test="indentState==2">
  700. and t.indent_state = "0"
  701. </if>
  702. <if test="indentState==3">
  703. and t.indent_state = "2"
  704. </if>
  705. <if test="indentState==4">
  706. and t.indent_state = "3"
  707. </if>
  708. <if test="indentState==5">
  709. and t.indent_state = "4"
  710. </if>
  711. <if test="indentState==6">
  712. and t.indent_state = "6"
  713. </if>
  714. <if test="indentState==7">
  715. and t.indent_state in ("8", "9", "10")
  716. </if>
  717. order by t.create_time desc
  718. </select>
  719. <select id="indentMessage" resultType="com.sqx.modules.errand.entity.TbIndent">
  720. select i.*,
  721. r.red_packet_amount as redPacketAmount,
  722. u.nick_name as riderNickName,
  723. u.phone as phone,
  724. u.avatar as avatar
  725. from tb_indent i
  726. left join tb_user u on i.rider_user_id = u.user_id
  727. left join errand_user_red_packet r on i.red_packet_id = r.red_packet_id
  728. where indent_number = #{indentNumber}
  729. </select>
  730. <select id="find5KmRider" resultType="com.sqx.modules.app.entity.UserEntity">
  731. SELECT *
  732. FROM tb_user
  733. WHERE (st_distance(point(station_lng, station_lat), point(#{lng}, #{lat})) * 111195) &lt; 50000
  734. and user_type = "2"
  735. and on_line_flag = "1"
  736. </select>
  737. <update id="updateCoordinate">
  738. update tb_user
  739. set station_lng = #{lng},
  740. station_lat = #{lat}
  741. where user_id = #{userId}
  742. </update>
  743. <select id="findUserInfoById" resultType="com.sqx.modules.app.entity.UserEntity">
  744. select *
  745. from tb_user
  746. where user_id = #{userId}
  747. </select>
  748. <select id="findAllRedPacket" resultType="com.sqx.modules.errand.entity.ErrandRedPacket">
  749. select *
  750. from errand_user_red_packet
  751. where user_id = #{userId}
  752. and delete_flag = "0"
  753. and expiration_time &gt; #{expirationTime}
  754. </select>
  755. <!--获取可用红包-->
  756. <select id="findRedPacket" resultType="com.sqx.modules.errand.entity.ErrandRedPacket">
  757. select *
  758. from errand_user_red_packet
  759. where user_id = #{userId}
  760. and (red_packet_type = "0" or red_packet_type = #{indentType})
  761. and minimum_amount &lt;= #{indentBasicsMoney}
  762. and expiration_time &gt; #{expirationTime}
  763. and delete_flag = "0"
  764. order by create_time desc
  765. </select>
  766. <update id="userCancleIndent">
  767. update tb_indent
  768. set indent_state = "8",
  769. cancel_indent_time = #{cancelIndentTime}
  770. where user_id = #{userId}
  771. and indent_number = #{indentNumber}
  772. </update>
  773. <update id="updateRedPaclet">
  774. update errand_user_red_packet
  775. set delete_flag = "0"
  776. where red_packet_id = #{redPacketId}
  777. </update>
  778. <select id="selectIndentList" resultType="com.sqx.modules.errand.entity.TbIndent">
  779. select *
  780. from tb_indent
  781. where rider_user_id = #{userId}
  782. and indent_state in (3, 4)
  783. </select>
  784. <select id="selectSendOrder" resultType="com.sqx.modules.errand.entity.TbIndent">
  785. select *
  786. from tb_indent
  787. where indent_state = 2
  788. and indent_type in (1, 2, 3, 5)
  789. and create_time &lt; #{date}
  790. </select>
  791. <select id="selectRiderByDictance" resultType="Long">
  792. select user_id
  793. from (
  794. SELECT t.user_id,
  795. (select count(*) from tb_indent i
  796. where i.rider_user_id=t.user_id and i.indent_state in (3,4)) as ordersCount ,
  797. (st_distance(point(t.station_lat, t.station_lng), point(#{userLat}, #{userLng})) *
  798. 111195) AS distance
  799. FROM tb_user t
  800. WHERE t.on_line_flag = 1
  801. and t.cash_deposit &gt;= #{cashDeposit}
  802. and user_id not in (select rider_user_id from tb_indent where indent_state in (3, 4))
  803. ) a
  804. where distance &lt; #{distance} and ordersCount &lt; #{maxNum}
  805. order by distance asc limit 1
  806. </select>
  807. <!--
  808. 现在根据订单地址,查出了距离该位置最近的骑手
  809. 但是还要再加一个条件:要查出距离该订单最近的,没有进行中的订单的骑手
  810. 判断骑手是否有订单在进行中:indent_state in (3, 4)
  811. select * from (
  812. SELECT
  813. t.user_id,
  814. ti.indent_id,
  815. (st_distance (point (t.station_lat, t.station_lng),point (34.16351, 108.65161)) * 111195) AS distance
  816. FROM
  817. tb_user t
  818. LEFT JOIN tb_indent ti ON t.user_id = ti.rider_user_id
  819. WHERE
  820. ti.indent_state NOT IN (3, 4) and t.on_line_flag = 1
  821. ) a where distance<100000 order by distance asc limit 1
  822. ====================================
  823. select tu.user_id, (st_distance (point (station_lat, station_lng), point(#{userLat},#{userLng}) ) *111195) as distance
  824. from tb_user tu where ((st_distance (point (station_lat, station_lng), point(#{userLat},#{userLng}) ) *111195)) &lt; #{distance}
  825. order by distance asc limit 1
  826. -->
  827. </mapper>