GroupRelationMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. og_title,
  232. og_description,
  233. description,
  234. og_keywords,
  235. detail_route,
  236. (
  237. case when type = 2 and ${isPayNf} then 999
  238. when category = 1 then 888
  239. when category = 2 then 777
  240. when category = 3 then 755
  241. else 666 end
  242. ) as sorted
  243. from `goods_don` where deleted is true and status is true
  244. <if test="list!=null and list.size()>0">
  245. and id not in
  246. <foreach collection="list" item="item" open="(" separator="," close=")">
  247. #{item}
  248. </foreach>
  249. </if>
  250. <if test="isPayNf">
  251. and type in (1,2)
  252. </if>
  253. <if test="!isPayNf">
  254. and type = 1
  255. </if>
  256. <if test="filterCourseGoods!=null and filterCourseGoods">
  257. and (special_type is null or special_type != 'courseware')
  258. </if>
  259. <if test="yhShopGoodsIds!=null and yhShopGoodsIds.size()>0">
  260. and id in
  261. <foreach collection="yhShopGoodsIds" item="item" open="(" separator="," close=")">
  262. #{item}
  263. </foreach>
  264. </if>
  265. ) s order by s.sorted desc,sort_by asc
  266. </select>
  267. <select id="getOutSideGroupsTripsRelationByGoodsId" resultType="java.lang.Long">
  268. select gt.id
  269. from `groups_trips` gt
  270. inner join account a on a.id = gt.account_id
  271. where gt.sku_id = #{skuId}
  272. and gt.status = 'validity'
  273. and a.expiry_time >= #{beginOfDay}
  274. and (select count(*)
  275. from groups_relation gr
  276. where gr.num > #{skuNum}
  277. and gr.num &lt;= #{maxNum}
  278. and gr.groups_id = gt.id
  279. and gr.user_id
  280. != 0)
  281. &lt; #{extraNum}
  282. and
  283. (
  284. select count(*)
  285. from groups_relation gr
  286. where gr.groups_id = gt.id
  287. and gr.user_id
  288. = #{userId}) = 0
  289. 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)
  290. order by RAND() limit 1
  291. </select>
  292. <select id="selectAvailableRelation" resultType="java.lang.Integer">
  293. select count(gr.id)
  294. from account a
  295. inner join `groups_trips` gt on gt.account_id = a.id
  296. and gt.`status` = 'validity'
  297. and gt.sku_id = #{skuId}
  298. inner join groups_relation gr on gr.groups_id = gt.id
  299. and gr.status in ('none', 'locking')
  300. and gt.available_parking_num = 0
  301. and gr.num &lt;= #{skuNum}
  302. </select>
  303. <select id="selectSpecialGroupsRelationAvailable" resultType="java.lang.Integer">
  304. select ifnull(sum(a1 + (#{extractNum} - t1)), 0)
  305. from (select gt.id,
  306. (select count(*)
  307. from groups_relation gr2
  308. where gr2.groups_id = gt.id
  309. and num > #{skuNum}
  310. and num &lt;= #{maxNum}) t1,
  311. (select count(*)
  312. from groups_relation gr2
  313. where gr2.groups_id = gt.id
  314. and num > #{skuNum}
  315. and num &lt;= #{maxNum}
  316. and (gr2.user_id = 0 or gr2.status = 'locking')) a1
  317. from account a
  318. inner join `groups_trips` gt on gt.account_id = a.id
  319. and gt.`status` = 'validity'
  320. and gt.available_parking_num = 0
  321. and gt.sku_id = #{skuId}
  322. and a.expiry_time >= #{tenExpiry}) s
  323. where (t1 = #{extractNum} and a1 = 0) = 0
  324. </select>
  325. <select id="selectNumWaitingGroups" resultType="java.lang.Integer">
  326. select count(gr.id)
  327. from `groups_trips` gt
  328. inner join groups_relation gr on gr.groups_id = gt.id
  329. and gt.`status` = 'waiting'
  330. and gt.sku_id = #{skuId}
  331. and gr.user_id != 0
  332. and gr.status in ('validity','outside')
  333. </select>
  334. <select id="selectLimitAvailableNum" resultType="java.lang.Integer">
  335. select sum(s1 - s2)
  336. from (select available_parking_num as s1,
  337. (select count(*)
  338. from groups_relation gr
  339. where gr.groups_id = gt.id
  340. and gr.status in ('validity', 'outside')
  341. and gr.num &lt;= #{maxNum}) as s2
  342. from groups_trips gt
  343. where gt.sku_id = #{skuId}
  344. and gt.status = 'validity'
  345. and gt.available_parking_num != 0) t
  346. where t.s1 >= s2
  347. </select>
  348. <select id="getGroupRelationAccountView" resultType="com.cyksj.model.manage.views.GroupsRelationBackView">
  349. select s.account, a.account as tripsAccount,a.act_code,a.act_code_url
  350. from (select groups_id, account from groups_relation where id = #{relationId} limit 1) s
  351. inner join groups_trips gt on gt.id = s.groups_id
  352. left join account a on a.id = gt.account_id
  353. </select>
  354. <select id="getAreaPhoneByUserId" resultType="com.cyksj.model.entity.PhoneCode">
  355. select s.phone, pc.cid
  356. from (select if(login_phone != '', login_phone,
  357. (select phone
  358. from user_bind_detail
  359. where user_id = u.id
  360. or email_user_id = u.id limit 1)) as phone
  361. from user u
  362. where id = #{userId} limit 1) s
  363. left join phone_code pc on pc.phone = s.phone
  364. </select>
  365. <select id="getUserHasPayGoods" resultType="com.cyksj.model.views.RenewalView">
  366. 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
  367. inner join goods_don_sku sku on sku.id = gt.sku_id inner join goods_don g on g.id = sku.goods_id
  368. where gr.status in ('validity', 'outside')
  369. and gr.cmt != 2
  370. 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)))
  371. and gr.user_id != 0
  372. and gr.user_id in
  373. <foreach collection="list" item="item" open="(" separator="," close=")">
  374. #{item}
  375. </foreach>
  376. group by g.id,g.title,g.logo
  377. order by goods_id
  378. </select>
  379. <select id="getExperienceTicket" resultType="java.lang.Long">
  380. select gr.id
  381. from (select id, groups_id from groups_relation where user_id = #{userId}) gr
  382. inner join groups_trips gt on gt.id = gr.groups_id
  383. where gt.sku_id = #{skuId} limit 1
  384. </select>
  385. <select id="selectGoodsDonQaByGoodsId" resultType="java.lang.Long">
  386. select count(1)
  387. from (select question_id from goods_don_qa_relate where goods_id = #{goodsId} and deleted is true) s
  388. inner join goods_don_qa qa on qa.id = s.question_id
  389. where qa.type = 2
  390. and qa.status is true
  391. and qa.deleted is true
  392. </select>
  393. <select id="selectRelationByAccountAndNum" resultType="com.cyksj.model.entity.GroupsRelation">
  394. select gr.id, gr.user_id, gr.num
  395. from (select id
  396. from account
  397. where account = #{account}
  398. and password = #{password}
  399. and goods_id = #{goodsId} limit 1) a
  400. inner join groups_trips gt
  401. on gt.account_id = a.id
  402. inner join groups_relation gr on gr.groups_id = gt.id
  403. where gr.num = #{num} and gr.expiry_time > now() limit 1
  404. </select>
  405. <select id="selectExtraRelation" resultType="com.cyksj.model.entity.GroupsRelation">
  406. select gr.*
  407. from (select * from groups_relation where user_id = #{userId} and id != #{relationId} and status not in ('none','locking')) gr
  408. inner join groups_trips gt on gt.id = gr.groups_id
  409. and gt.sku_id = #{skuId}
  410. 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'))
  411. </select>
  412. <select id="selectUserTickets" resultType="com.cyksj.model.views.UserTicketView">
  413. select gr.id as relation_id,
  414. gr.user_id,
  415. g.id as goods_id,
  416. gt.sku_id,
  417. g.title,
  418. gdk.spec_val,
  419. gdk.third_exchange_url,
  420. gr.expiry_time,
  421. gdk.is_mirror,
  422. gdk.gpt_limit_num as gptUserLimitNum,
  423. gdk.gpt_limit_time as gptUserLimitTime,
  424. gdk.num as skuNum,
  425. gdk.is_banned_check,
  426. gr.is_frozen,
  427. gr.unfrozen_time,
  428. gr.reserved_days
  429. from groups_relation gr left join groups_trips gt on gt.id = gr.groups_id
  430. left join goods_don_sku gdk on gdk.id = gt.sku_id left join goods_don g on g.id = gdk.goods_id
  431. where gr.user_id in
  432. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  433. #{item}
  434. </foreach>
  435. and gr.status in ('validity','outside')
  436. and gr.cmt != 2
  437. and gr.is_vip = 0
  438. and (gr.expiry_time is null or gr.expiry_time > now() or (gdk.is_mirror and gr.expiry_time >
  439. DATE_ADD(now(),interval -7 day)))
  440. <if test="goodsId != null">
  441. and g.id = #{goodsId}
  442. </if>
  443. <if test="skuId != null">
  444. and gt.sku_id = #{skuId}
  445. </if>
  446. </select>
  447. <select id="selectCountByGoodsId" resultType="java.lang.Integer">
  448. select count(1) from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id inner join
  449. goods_don_sku sku on sku.id = gt.sku_id
  450. where sku.goods_id = #{goodsId}
  451. and gr.user_id in
  452. <foreach collection="userIds" item="item" open="(" separator="," close=")">
  453. #{item}
  454. </foreach>
  455. and gr.expiry_time > #{now}
  456. </select>
  457. <select id="selectRechargeRecordNum" resultType="com.cyksj.model.response.GptRechargeStatisticsRecordResp">
  458. 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
  459. where gur.num &lt; 0
  460. and gur.operator != ''
  461. and gur.created_time between #{start} and #{end}
  462. <if test="goodsIds != null">
  463. and o.goods_id in
  464. <foreach collection="goodsIds" item="item" open="(" separator="," close=")">
  465. #{item}
  466. </foreach>
  467. </if>
  468. <if test="operator != null">
  469. and gur.operator = #{operator}
  470. </if>
  471. group by gur.operator
  472. order by num desc
  473. </select>
  474. </mapper>