GroupRelationMapper.xml 16 KB

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