GroupRelationMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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.cyksj.mapper.GroupsRelationMapper">
  4. <update id="updateExpiryTime">
  5. update groups_relation
  6. set start_time = null,
  7. expiry_time = null,
  8. status = #{entity.status},
  9. renew_status = #{entity.renewStatus},
  10. is_handle = #{entity.isHandle},
  11. user_id = #{entity.userId},
  12. account = null,
  13. customer_service = null,
  14. password = null,
  15. recharge_status = null,
  16. send_time = null,
  17. submit_time = null,
  18. operator = null,
  19. yhs_id = 0,
  20. cmt = 0,
  21. aq_type = 1,
  22. invite_link = null,
  23. contact = null,
  24. is_vip = 0,
  25. recharge_num = null,
  26. recharge_remain_num = null,
  27. card_key = null,
  28. gpt_task_id = null,
  29. recharge_error_info = null,
  30. bp_verify_code = null,
  31. gpt_token = null,
  32. is_frozen = 0,
  33. unfrozen_time = null,
  34. reserved_days = null,
  35. recharge_remark = null,
  36. is_recover = 0
  37. where id = #{entity.id}
  38. <if test="expireTime != null">
  39. and expiry_time = #{expireTime}
  40. </if>
  41. </update>
  42. <update id="incrExpiryTime">
  43. update groups_relation set expiry_time = DATE_ADD(expiry_time,interval 1 day) where id = #{relationId} and user_id = #{userId}
  44. </update>
  45. <update id="updateUserVipSkusExpiryTime">
  46. update groups_relation set expiry_time = #{expiryTime},
  47. update_time = now()
  48. where id in (select * from(
  49. select gr.id from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id
  50. where gt.sku_id in
  51. <foreach collection="vipSkuIds" item="item" open="(" separator="," close=")">
  52. #{item}
  53. </foreach>
  54. and gr.user_id in
  55. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  56. #{item}
  57. </foreach>
  58. and is_vip)s)
  59. </update>
  60. <select id="getAccountIdsByUserIdOrNickNameOrSubmitAccount" resultType="java.lang.Long">
  61. select gr.groups_id
  62. from groups_relation gr,
  63. `user` u
  64. where gr.user_id = u.id
  65. <if test="nickName != null and nickName != ''">
  66. and u.nickname like '%${nickName}%'
  67. </if>
  68. <if test="userId != null">
  69. and u.id = #{userId,jdbcType=BIGINT}
  70. </if>
  71. <if test="submitAccount != null and submitAccount != ''">
  72. and gr.account = #{submitAccount,jdbcType=VARCHAR}
  73. </if>
  74. group by gr.groups_id
  75. </select>
  76. <select id="getGroupTripsSkuIdByRelationId" resultType="java.lang.Long">
  77. select gt.sku_id from `groups_trips` gt left join `groups_relation` gr on gr.groups_id = gt.id where gr.id = #{relationId} limit 1
  78. </select>
  79. <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
  80. select s.id
  81. from (select gt.id, min(gr.expiry_time) minExpiryTime
  82. from `groups_trips` gt
  83. left join `groups_relation` gr on gr.groups_id = gt.id
  84. where gt.sku_id = #{skuId}
  85. and (gt.available_parking_num = 0 or (select count(*)
  86. from groups_relation gr
  87. where gr.groups_id = gt.id and gr.user_id != 0 and gr.num &lt;=
  88. #{maxNum}) &lt; gt.available_parking_num) and gt.available_num > 0
  89. and gt.status = 'validity'
  90. and gr.status = 'validity'
  91. and gr.user_id != 0
  92. and gr.expiry_time is not null
  93. group by gr.groups_id) s
  94. where s.minExpiryTime >= #{minExpiryTime}
  95. <if test="ip != null">
  96. and not exists (select 1 from (select id, user_id from groups_relation gnr where gnr.groups_id = s.id and gnr.user_id != 0) gr inner join
  97. order_don o on o.user_id = gr.user_id and o.relation_id = gr.id
  98. inner join order_don_location_relate ocr on ocr.order_id = o.id where ocr.ip = #{ip} limit 1)
  99. </if>
  100. order by minExpiryTime desc limit 1
  101. </select>
  102. <select id="selectRelationByGoodsId" resultType="com.cyksj.model.manage.views.GroupsRelationView">
  103. select gr.*
  104. from groups_relation gr
  105. left join groups_trips gt on gr.groups_id = gt.id
  106. left join account a on a.id = gt.account_id
  107. left join user u on gr.user_id = u.id
  108. left join goods_don g on a.goods_id = g.id
  109. where g.id = #{goodsId}
  110. and gr.user_id in
  111. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  112. #{item}
  113. </foreach>
  114. and gt.status = 'validity'
  115. and gr.status = 'validity'
  116. and gr.yhs_id = #{yhsId}
  117. and gr.expiry_time > now()
  118. </select>
  119. <select id="getGroupRelationViewByUserIdAndRelationId"
  120. resultType="com.cyksj.model.manage.views.GroupsRelationView">
  121. select gr.*,
  122. a.account as tripsAccount,
  123. g.title
  124. from groups_relation gr
  125. left join groups_trips gt on gt.id = gr.groups_id
  126. left join account a on a.id = gt.account_id
  127. left join goods_don g on g.id = a.goods_id
  128. where gr.id = #{relationId} and gr.user_id = #{userId}
  129. </select>
  130. <select id="getBindPhoneByUserId" resultType="java.lang.String">
  131. select if(login_phone != '', login_phone,
  132. (select phone from user_bind_detail where user_id = #{userId} or email_user_id = #{userId} limit 1))
  133. from user
  134. where id = #{userId} limit 1
  135. </select>
  136. <select id="selectViewPwdCount" resultType="java.lang.Integer">
  137. select count(distinct relation_id)
  138. from (select id, user_id from `groups_relation` where groups_id = #{groupsId} and `status` = 'validity') s
  139. inner join ticket_pwd_view_record cr on cr.relation_id = s.id and s.user_id = cr.user_id
  140. </select>
  141. <select id="selectRandomOneRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  142. select *
  143. from groups_relation
  144. where groups_id = #{groupsId}
  145. and user_id = 0
  146. and status = 'none'
  147. order by rand() limit 1
  148. </select>
  149. <select id="selectExpiredRelationByCondition" resultType="com.cyksj.model.entity.GroupsRelation">
  150. select gr.*
  151. from groups_relation gr
  152. inner join groups_trips gt on gt.id = gr.groups_id
  153. where gt.sku_id not in
  154. <foreach collection="list" item="item" open="(" separator="," close=")">
  155. #{item}
  156. </foreach>
  157. and gr.expiry_time &lt;= #{now}
  158. </select>
  159. <select id="selectOutsideRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
  160. select *
  161. from groups_relation
  162. where groups_id = #{groupsId}
  163. and user_id = 0
  164. and num > #{relationNum}
  165. and status = 'outside'
  166. order by rand() limit 1
  167. </select>
  168. <select id="selectExpiredChatGPTRelation" resultType="com.cyksj.model.entity.GroupsRelation">
  169. select gr.*
  170. from groups_relation gr
  171. inner join groups_trips gt on gt.id = gr.groups_id
  172. where gt.sku_id in
  173. <foreach collection="list" item="item" open="(" separator="," close=")">
  174. #{item}
  175. </foreach>
  176. and gr.expiry_time &lt;= #{nextBeginDay}
  177. </select>
  178. <select id="getUserRelationUserViews" resultType="com.cyksj.model.views.GroupsRelationUserView">
  179. select gr.*,
  180. u.nickname,
  181. u.headimgurl
  182. from (select * from (select id as relation_id,
  183. user_id,
  184. 1 as isSelf from groups_relation where id = #{relationId}
  185. and status in
  186. <foreach collection="status" item="item" open="(" separator="," close=")">
  187. #{item}
  188. </foreach>
  189. limit 1)s1
  190. union all
  191. select * from (select id as realtion_id,
  192. user_id,
  193. if(user_id = #{userId},true,false) as isSelf from groups_relation where id != #{relationId}
  194. and groups_id = #{groupsId}
  195. and status in
  196. <foreach collection="status" item="item" open="(" separator="," close=")">
  197. #{item}
  198. </foreach>
  199. limit 4)s2)gr inner join user u on u.id = gr.user_id
  200. </select>
  201. <select id="getTicketGoodsId" resultType="java.lang.Long">
  202. select distinct goods_id from (select sku.goods_id from (select * from `groups_relation` where status in
  203. <foreach collection="status" item="item" open="(" separator="," close=")">
  204. #{item}
  205. </foreach>
  206. and user_id in
  207. <foreach collection="list" item="item" open="(" separator="," close=")">
  208. #{item}
  209. </foreach>)gr left join groups_trips gt on gt.id = gr.groups_id
  210. left join goods_don_sku sku on sku.id = gt.sku_id
  211. union all
  212. select goods_id from order_don o where user_id in
  213. <foreach collection="list" item="item" open="(" separator="," close=")">
  214. #{item}
  215. </foreach>
  216. and relation_id = 0 and status not in ('close','noPayment','refund'))s
  217. </select>
  218. <select id="getRecommendGoodsViews" resultType="com.cyksj.model.views.UserRecommendGoodsFrontView">
  219. select * from (select
  220. id as goodsId,
  221. title,
  222. logo,
  223. img,
  224. tags,
  225. sort_by,
  226. `type`,
  227. min_months as months,
  228. min_days as days,
  229. min_price as price,
  230. (
  231. case when type = 2 and ${isPayNf} then 999
  232. when category = 1 then 888
  233. when category = 2 then 777
  234. when category = 3 then 755
  235. else 666 end
  236. ) as sorted
  237. from `goods_don` where deleted is true and status is true
  238. <if test="list!=null and list.size()>0">
  239. and id not in
  240. <foreach collection="list" item="item" open="(" separator="," close=")">
  241. #{item}
  242. </foreach>
  243. </if>
  244. <if test="isPayNf">
  245. and type in (1,2)
  246. </if>
  247. <if test="!isPayNf">
  248. and type = 1
  249. </if>
  250. <if test="filterCourseGoods!=null and filterCourseGoods">
  251. and (special_type is null or special_type != 'courseware')
  252. </if>
  253. <if test="yhShopGoodsIds!=null and yhShopGoodsIds.size()>0">
  254. and id in
  255. <foreach collection="yhShopGoodsIds" item="item" open="(" separator="," close=")">
  256. #{item}
  257. </foreach>
  258. </if>
  259. ) s order by s.sorted desc,sort_by asc
  260. </select>
  261. <select id="getOutSideGroupsTripsRelationByGoodsId" resultType="java.lang.Long">
  262. select gt.id
  263. from `groups_trips` gt
  264. inner join account a on a.id = gt.account_id
  265. where gt.sku_id = #{skuId}
  266. and gt.status = 'validity'
  267. and a.expiry_time >= #{beginOfDay}
  268. and (select count(*)
  269. from groups_relation gr
  270. where gr.num > #{skuNum}
  271. and gr.num &lt;= #{maxNum}
  272. and gr.groups_id = gt.id
  273. and gr.user_id
  274. != 0)
  275. &lt; #{extraNum}
  276. and
  277. (
  278. select count(*)
  279. from groups_relation gr
  280. where gr.groups_id = gt.id
  281. and gr.user_id
  282. = #{userId}) = 0
  283. and (gt.available_parking_num = 0 or (select count(*) from groups_relation gr where gr.groups_id = gt.id and gr.user_id != 0 and gr.num &lt;= #{maxNum}) &lt; gt.available_parking_num)
  284. order by RAND() limit 1
  285. </select>
  286. <select id="selectAvailableRelation" resultType="java.lang.Integer">
  287. select count(gr.id)
  288. from account a
  289. inner join `groups_trips` gt on gt.account_id = a.id
  290. and gt.`status` = 'validity'
  291. and gt.sku_id = #{skuId}
  292. inner join groups_relation gr on gr.groups_id = gt.id
  293. and gr.status in ('none', 'locking')
  294. and gt.available_parking_num = 0
  295. and gr.num &lt;= #{skuNum}
  296. </select>
  297. <select id="selectSpecialGroupsRelationAvailable" resultType="java.lang.Integer">
  298. select ifnull(sum(a1 + (#{extractNum} - t1)), 0)
  299. from (select gt.id,
  300. (select count(*)
  301. from groups_relation gr2
  302. where gr2.groups_id = gt.id
  303. and num > #{skuNum}
  304. and num &lt;= #{maxNum}) t1,
  305. (select count(*)
  306. from groups_relation gr2
  307. where gr2.groups_id = gt.id
  308. and num > #{skuNum}
  309. and num &lt;= #{maxNum}
  310. and (gr2.user_id = 0 or gr2.status = 'locking')) a1
  311. from account a
  312. inner join `groups_trips` gt on gt.account_id = a.id
  313. and gt.`status` = 'validity'
  314. and gt.available_parking_num = 0
  315. and gt.sku_id = #{skuId}
  316. and a.expiry_time >= #{tenExpiry}) s
  317. where (t1 = #{extractNum} and a1 = 0) = 0
  318. </select>
  319. <select id="selectNumWaitingGroups" resultType="java.lang.Integer">
  320. select count(gr.id)
  321. from `groups_trips` gt
  322. inner join groups_relation gr on gr.groups_id = gt.id
  323. and gt.`status` = 'waiting'
  324. and gt.sku_id = #{skuId}
  325. and gr.user_id != 0
  326. and gr.status in ('validity','outside')
  327. </select>
  328. <select id="selectLimitAvailableNum" resultType="java.lang.Integer">
  329. select sum(s1 - s2)
  330. from (select available_parking_num as s1,
  331. (select count(*)
  332. from groups_relation gr
  333. where gr.groups_id = gt.id
  334. and gr.status in ('validity', 'outside')
  335. and gr.num &lt;= #{maxNum}) as s2
  336. from groups_trips gt
  337. where gt.sku_id = #{skuId}
  338. and gt.status = 'validity'
  339. and gt.available_parking_num != 0) t
  340. where t.s1 >= s2
  341. </select>
  342. <select id="getGroupRelationAccountView" resultType="com.cyksj.model.manage.views.GroupsRelationBackView">
  343. select s.account, a.account as tripsAccount,a.act_code
  344. from (select groups_id, account from groups_relation where id = #{relationId} limit 1) s
  345. inner join groups_trips gt on gt.id = s.groups_id
  346. left join account a on a.id = gt.account_id
  347. </select>
  348. <select id="getAreaPhoneByUserId" resultType="com.cyksj.model.entity.PhoneCode">
  349. select s.phone, pc.cid
  350. from (select if(login_phone != '', login_phone,
  351. (select phone
  352. from user_bind_detail
  353. where user_id = u.id
  354. or email_user_id = u.id limit 1)) as phone
  355. from user u
  356. where id = #{userId} limit 1) s
  357. left join phone_code pc on pc.phone = s.phone
  358. </select>
  359. <select id="getUserHasPayGoods" resultType="com.cyksj.model.views.RenewalView">
  360. select g.id as goods_id,g.title,g.logo from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id
  361. inner join goods_don_sku sku on sku.id = gt.sku_id inner join goods_don g on g.id = sku.goods_id
  362. where gr.status in ('validity', 'outside')
  363. and gr.cmt != 2
  364. and (gr.expiry_time is null or gr.expiry_time > #{now} or (sku.is_mirror and gr.expiry_time > DATE_ADD(#{now},interval -7 day)))
  365. and gr.user_id != 0
  366. and gr.user_id in
  367. <foreach collection="list" item="item" open="(" separator="," close=")">
  368. #{item}
  369. </foreach>
  370. group by g.id,g.title,g.logo
  371. order by goods_id
  372. </select>
  373. <select id="getExperienceTicket" resultType="java.lang.Long">
  374. select gr.id
  375. from (select id, groups_id from groups_relation where user_id = #{userId}) gr
  376. inner join groups_trips gt on gt.id = gr.groups_id
  377. where gt.sku_id = #{skuId} limit 1
  378. </select>
  379. <select id="selectGoodsDonQaByGoodsId" resultType="java.lang.Long">
  380. select count(1)
  381. from (select question_id from goods_don_qa_relate where goods_id = #{goodsId} and deleted is true) s
  382. inner join goods_don_qa qa on qa.id = s.question_id
  383. where qa.type = 2
  384. and qa.status is true
  385. and qa.deleted is true
  386. </select>
  387. <select id="selectRelationByAccountAndNum" resultType="com.cyksj.model.entity.GroupsRelation">
  388. select gr.id, gr.user_id, gr.num
  389. from (select id
  390. from account
  391. where account = #{account}
  392. and password = #{password}
  393. and goods_id = #{goodsId} limit 1) a
  394. inner join groups_trips gt
  395. on gt.account_id = a.id
  396. inner join groups_relation gr on gr.groups_id = gt.id
  397. where gr.num = #{num} and gr.expiry_time > now() limit 1
  398. </select>
  399. <select id="selectExtraRelation" resultType="com.cyksj.model.entity.GroupsRelation">
  400. select gr.*
  401. from (select * from groups_relation where user_id = #{userId} and id != #{relationId} and status not in ('none','locking')) gr
  402. inner join groups_trips gt on gt.id = gr.groups_id
  403. and gt.sku_id = #{skuId}
  404. and not exists (select 1 from order_don o where o.user_id = gr.user_id and o.relation_id = gr.id and o.status not in ('close','noPayment','refund'))
  405. </select>
  406. <select id="selectUserTickets" resultType="com.cyksj.model.views.UserTicketView">
  407. select gr.id as relation_id,
  408. gr.user_id,
  409. g.id as goods_id,
  410. gt.sku_id,
  411. g.title,
  412. gdk.spec_val,
  413. gr.expiry_time,
  414. gdk.is_mirror,
  415. gdk.gpt_limit_num as gptUserLimitNum,
  416. gdk.gpt_limit_time as gptUserLimitTime,
  417. gdk.num as skuNum,
  418. gr.is_frozen,
  419. gr.unfrozen_time,
  420. gr.reserved_days
  421. from groups_relation gr left join groups_trips gt on gt.id = gr.groups_id
  422. left join goods_don_sku gdk on gdk.id = gt.sku_id left join goods_don g on g.id = gdk.goods_id
  423. where gr.user_id in
  424. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  425. #{item}
  426. </foreach>
  427. and gr.status in ('validity','outside')
  428. and gr.cmt != 2
  429. and gr.is_vip = 0
  430. and (gr.expiry_time is null or gr.expiry_time > now() or (gdk.is_mirror and gr.expiry_time >
  431. DATE_ADD(now(),interval -7 day)))
  432. <if test="goodsId != null">
  433. and g.id = #{goodsId}
  434. </if>
  435. <if test="skuId != null">
  436. and gt.sku_id = #{skuId}
  437. </if>
  438. </select>
  439. <select id="selectCountByGoodsId" resultType="java.lang.Integer">
  440. select count(1) from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id inner join
  441. goods_don_sku sku on sku.id = gt.sku_id
  442. where sku.goods_id = #{goodsId}
  443. and gr.user_id in
  444. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  445. #{item}
  446. </foreach>
  447. and gr.expiry_time > #{now}
  448. </select>
  449. </mapper>