GroupRelationMapper.xml 21 KB

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