GroupRelationMapper.xml 20 KB

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