GroupRelationMapper.xml 18 KB

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