GroupRelationMapper.xml 15 KB

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