GroupRelationMapper.xml 17 KB

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