GroupRelationMapper.xml 18 KB

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