| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.cyksj.mapper.GroupsRelationMapper">
- <update id="updateExpiryTime">
- update groups_relation
- set start_time = null,
- expiry_time = null,
- status = #{entity.status},
- renew_status = #{entity.renewStatus},
- is_handle = #{entity.isHandle},
- user_id = #{entity.userId},
- account = null,
- customer_service = null,
- password = null,
- recharge_status = null,
- send_time = null,
- submit_time = null,
- operator = null,
- yhs_id = 0,
- cmt = 0,
- aq_type = 1,
- invite_link = null,
- contact = null,
- is_vip = 0,
- recharge_num = null,
- recharge_remain_num = null,
- card_key = null,
- gpt_task_id = null,
- recharge_error_info = null,
- bp_verify_code = null,
- gpt_token = null,
- is_frozen = 0,
- unfrozen_time = null,
- reserved_days = null,
- recharge_remark = null,
- is_recover = 0,
- compensation_days = 0
- where id = #{entity.id}
- <if test="expireTime != null">
- and expiry_time = #{expireTime}
- </if>
- </update>
- <update id="incrExpiryTime">
- update groups_relation set expiry_time = DATE_ADD(expiry_time,interval 1 day) where id = #{relationId} and user_id = #{userId}
- </update>
- <update id="updateUserVipSkusExpiryTime">
- update groups_relation set expiry_time = #{expiryTime},
- update_time = now()
- where id in (select * from(
- select gr.id from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id
- where gt.sku_id in
- <foreach collection="vipSkuIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and gr.user_id in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and is_vip)s)
- </update>
- <select id="getAccountIdsByUserIdOrNickNameOrSubmitAccount" resultType="java.lang.Long">
- select gr.groups_id
- from groups_relation gr,
- `user` u
- where gr.user_id = u.id
- <if test="nickName != null and nickName != ''">
- and u.nickname like '%${nickName}%'
- </if>
- <if test="userId != null">
- and u.id = #{userId,jdbcType=BIGINT}
- </if>
- <if test="submitAccount != null and submitAccount != ''">
- and gr.account = #{submitAccount,jdbcType=VARCHAR}
- </if>
- group by gr.groups_id
- </select>
- <select id="getGroupTripsSkuIdByRelationId" resultType="java.lang.Long">
- 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
- </select>
- <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
- select s.id
- from (select gt.id, min(gr.expiry_time) minExpiryTime
- from `groups_trips` gt
- left join `groups_relation` gr on gr.groups_id = gt.id
- where gt.sku_id = #{skuId}
- 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 <=
- #{maxNum}) < gt.available_parking_num) and gt.available_num > 0
- and gt.status = 'validity'
- and gr.status = 'validity'
- and gr.user_id != 0
- and gr.expiry_time is not null
- group by gr.groups_id) s
- where s.minExpiryTime >= #{minExpiryTime}
- <if test="ip != null">
- 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
- order_don o on o.user_id = gr.user_id and o.relation_id = gr.id
- inner join order_don_location_relate ocr on ocr.order_id = o.id where ocr.ip = #{ip} limit 1)
- </if>
- order by minExpiryTime desc limit 1
- </select>
- <select id="selectRelationByGoodsId" resultType="com.cyksj.model.manage.views.GroupsRelationView">
- select gr.*
- from groups_relation gr
- left join groups_trips gt on gr.groups_id = gt.id
- left join account a on a.id = gt.account_id
- left join user u on gr.user_id = u.id
- left join goods_don g on a.goods_id = g.id
- where g.id = #{goodsId}
- and gr.user_id in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and gt.status = 'validity'
- and gr.status = 'validity'
- and gr.yhs_id = #{yhsId}
- and gr.expiry_time > now()
- </select>
- <select id="getGroupRelationViewByUserIdAndRelationId"
- resultType="com.cyksj.model.manage.views.GroupsRelationView">
- select gr.*,
- a.account as tripsAccount,
- g.title
- from groups_relation gr
- left join groups_trips gt on gt.id = gr.groups_id
- left join account a on a.id = gt.account_id
- left join goods_don g on g.id = a.goods_id
- where gr.id = #{relationId} and gr.user_id = #{userId}
- </select>
- <select id="getBindPhoneByUserId" resultType="java.lang.String">
- select if(login_phone != '', login_phone,
- (select phone from user_bind_detail where user_id = #{userId} or email_user_id = #{userId} limit 1))
- from user
- where id = #{userId} limit 1
- </select>
- <select id="selectViewPwdCount" resultType="java.lang.Integer">
- select count(distinct relation_id)
- from (select id, user_id from `groups_relation` where groups_id = #{groupsId} and `status` = 'validity') s
- inner join ticket_pwd_view_record cr on cr.relation_id = s.id and s.user_id = cr.user_id
- </select>
- <select id="selectRandomOneRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
- select *
- from groups_relation
- where groups_id = #{groupsId}
- and user_id = 0
- and status = 'none'
- order by rand() limit 1
- </select>
- <select id="selectExpiredRelationByCondition" resultType="com.cyksj.model.entity.GroupsRelation">
- select gr.*
- from groups_relation gr
- inner join groups_trips gt on gt.id = gr.groups_id
- where gt.sku_id not in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and gr.expiry_time <= #{now}
- </select>
- <select id="selectOutsideRelationByGroupsId" resultType="com.cyksj.model.entity.GroupsRelation">
- select *
- from groups_relation
- where groups_id = #{groupsId}
- and user_id = 0
- and num > #{relationNum}
- and status = 'outside'
- order by rand() limit 1
- </select>
- <select id="selectExpiredChatGPTRelation" resultType="com.cyksj.model.entity.GroupsRelation">
- select gr.*
- from groups_relation gr
- inner join groups_trips gt on gt.id = gr.groups_id
- where gt.sku_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and gr.expiry_time <= #{nextBeginDay}
- </select>
- <select id="getUserRelationUserViews" resultType="com.cyksj.model.views.GroupsRelationUserView">
- select gr.*,
- u.nickname,
- u.headimgurl
- from (select * from (select id as relation_id,
- user_id,
- 1 as isSelf from groups_relation where id = #{relationId}
- and status in
- <foreach collection="status" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- limit 1)s1
- union all
- select * from (select id as realtion_id,
- user_id,
- if(user_id = #{userId},true,false) as isSelf from groups_relation where id != #{relationId}
- and groups_id = #{groupsId}
- and status in
- <foreach collection="status" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- limit 4)s2)gr inner join user u on u.id = gr.user_id
- </select>
- <select id="getTicketGoodsId" resultType="java.lang.Long">
- select distinct goods_id from (select sku.goods_id from (select * from `groups_relation` where status in
- <foreach collection="status" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and user_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>)gr left join groups_trips gt on gt.id = gr.groups_id
- left join goods_don_sku sku on sku.id = gt.sku_id
- union all
- select goods_id from order_don o where user_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and relation_id = 0 and status not in ('close','noPayment','refund'))s
- </select>
- <select id="getRecommendGoodsViews" resultType="com.cyksj.model.views.UserRecommendGoodsFrontView">
- select * from (select
- id as goodsId,
- title,
- logo,
- img,
- tags,
- sort_by,
- `type`,
- min_months as months,
- min_days as days,
- min_price as price,
- (
- case when type = 2 and ${isPayNf} then 999
- when category = 1 then 888
- when category = 2 then 777
- when category = 3 then 755
- else 666 end
- ) as sorted
- from `goods_don` where deleted is true and status is true
- <if test="list!=null and list.size()>0">
- and id not in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="isPayNf">
- and type in (1,2)
- </if>
- <if test="!isPayNf">
- and type = 1
- </if>
- <if test="filterCourseGoods!=null and filterCourseGoods">
- and (special_type is null or special_type != 'courseware')
- </if>
- <if test="yhShopGoodsIds!=null and yhShopGoodsIds.size()>0">
- and id in
- <foreach collection="yhShopGoodsIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- ) s order by s.sorted desc,sort_by asc
- </select>
- <select id="getOutSideGroupsTripsRelationByGoodsId" resultType="java.lang.Long">
- select gt.id
- from `groups_trips` gt
- inner join account a on a.id = gt.account_id
- where gt.sku_id = #{skuId}
- and gt.status = 'validity'
- and a.expiry_time >= #{beginOfDay}
- and (select count(*)
- from groups_relation gr
- where gr.num > #{skuNum}
- and gr.num <= #{maxNum}
- and gr.groups_id = gt.id
- and gr.user_id
- != 0)
- < #{extraNum}
- and
- (
- select count(*)
- from groups_relation gr
- where gr.groups_id = gt.id
- and gr.user_id
- = #{userId}) = 0
- 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 <= #{maxNum}) < gt.available_parking_num)
- order by RAND() limit 1
- </select>
- <select id="selectAvailableRelation" resultType="java.lang.Integer">
- select count(gr.id)
- from account a
- inner join `groups_trips` gt on gt.account_id = a.id
- and gt.`status` = 'validity'
- and gt.sku_id = #{skuId}
- inner join groups_relation gr on gr.groups_id = gt.id
- and gr.status in ('none', 'locking')
- and gt.available_parking_num = 0
- and gr.num <= #{skuNum}
- </select>
- <select id="selectSpecialGroupsRelationAvailable" resultType="java.lang.Integer">
- select ifnull(sum(a1 + (#{extractNum} - t1)), 0)
- from (select gt.id,
- (select count(*)
- from groups_relation gr2
- where gr2.groups_id = gt.id
- and num > #{skuNum}
- and num <= #{maxNum}) t1,
- (select count(*)
- from groups_relation gr2
- where gr2.groups_id = gt.id
- and num > #{skuNum}
- and num <= #{maxNum}
- and (gr2.user_id = 0 or gr2.status = 'locking')) a1
- from account a
- inner join `groups_trips` gt on gt.account_id = a.id
- and gt.`status` = 'validity'
- and gt.available_parking_num = 0
- and gt.sku_id = #{skuId}
- and a.expiry_time >= #{tenExpiry}) s
- where (t1 = #{extractNum} and a1 = 0) = 0
- </select>
- <select id="selectNumWaitingGroups" resultType="java.lang.Integer">
- select count(gr.id)
- from `groups_trips` gt
- inner join groups_relation gr on gr.groups_id = gt.id
- and gt.`status` = 'waiting'
- and gt.sku_id = #{skuId}
- and gr.user_id != 0
- and gr.status in ('validity','outside')
- </select>
- <select id="selectLimitAvailableNum" resultType="java.lang.Integer">
- select sum(s1 - s2)
- from (select available_parking_num as s1,
- (select count(*)
- from groups_relation gr
- where gr.groups_id = gt.id
- and gr.status in ('validity', 'outside')
- and gr.num <= #{maxNum}) as s2
- from groups_trips gt
- where gt.sku_id = #{skuId}
- and gt.status = 'validity'
- and gt.available_parking_num != 0) t
- where t.s1 >= s2
- </select>
- <select id="getGroupRelationAccountView" resultType="com.cyksj.model.manage.views.GroupsRelationBackView">
- select s.account, a.account as tripsAccount,a.act_code,a.act_code_url
- from (select groups_id, account from groups_relation where id = #{relationId} limit 1) s
- inner join groups_trips gt on gt.id = s.groups_id
- left join account a on a.id = gt.account_id
- </select>
- <select id="getAreaPhoneByUserId" resultType="com.cyksj.model.entity.PhoneCode">
- select s.phone, pc.cid
- from (select if(login_phone != '', login_phone,
- (select phone
- from user_bind_detail
- where user_id = u.id
- or email_user_id = u.id limit 1)) as phone
- from user u
- where id = #{userId} limit 1) s
- left join phone_code pc on pc.phone = s.phone
- </select>
- <select id="getUserHasPayGoods" resultType="com.cyksj.model.views.RenewalView">
- 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
- inner join goods_don_sku sku on sku.id = gt.sku_id inner join goods_don g on g.id = sku.goods_id
- where gr.status in ('validity', 'outside')
- and gr.cmt != 2
- 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)))
- and gr.user_id != 0
- and gr.user_id in
- <foreach collection="list" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- group by g.id,g.title,g.logo
- order by goods_id
- </select>
- <select id="getExperienceTicket" resultType="java.lang.Long">
- select gr.id
- from (select id, groups_id from groups_relation where user_id = #{userId}) gr
- inner join groups_trips gt on gt.id = gr.groups_id
- where gt.sku_id = #{skuId} limit 1
- </select>
- <select id="selectGoodsDonQaByGoodsId" resultType="java.lang.Long">
- select count(1)
- from (select question_id from goods_don_qa_relate where goods_id = #{goodsId} and deleted is true) s
- inner join goods_don_qa qa on qa.id = s.question_id
- where qa.type = 2
- and qa.status is true
- and qa.deleted is true
- </select>
- <select id="selectRelationByAccountAndNum" resultType="com.cyksj.model.entity.GroupsRelation">
- select gr.id, gr.user_id, gr.num
- from (select id
- from account
- where account = #{account}
- and password = #{password}
- and goods_id = #{goodsId} limit 1) a
- inner join groups_trips gt
- on gt.account_id = a.id
- inner join groups_relation gr on gr.groups_id = gt.id
- where gr.num = #{num} and gr.expiry_time > now() limit 1
- </select>
- <select id="selectExtraRelation" resultType="com.cyksj.model.entity.GroupsRelation">
- select gr.*
- from (select * from groups_relation where user_id = #{userId} and id != #{relationId} and status not in ('none','locking')) gr
- inner join groups_trips gt on gt.id = gr.groups_id
- and gt.sku_id = #{skuId}
- 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'))
- </select>
- <select id="selectUserTickets" resultType="com.cyksj.model.views.UserTicketView">
- 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,
- gdk.gpt_limit_num as gptUserLimitNum,
- gdk.gpt_limit_time as gptUserLimitTime,
- gdk.num as skuNum,
- gdk.is_banned_check,
- gr.is_frozen,
- gr.unfrozen_time,
- gr.reserved_days
- from groups_relation gr left join groups_trips gt on gt.id = gr.groups_id
- left join goods_don_sku gdk on gdk.id = gt.sku_id left join goods_don g on g.id = gdk.goods_id
- where gr.user_id in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and gr.status in ('validity','outside')
- and gr.cmt != 2
- and gr.is_vip = 0
- and (gr.expiry_time is null or gr.expiry_time > now() or (gdk.is_mirror and gr.expiry_time >
- DATE_ADD(now(),interval -7 day)))
- <if test="goodsId != null">
- and g.id = #{goodsId}
- </if>
- <if test="skuId != null">
- and gt.sku_id = #{skuId}
- </if>
- </select>
- <select id="selectCountByGoodsId" resultType="java.lang.Integer">
- select count(1) from groups_relation gr inner join groups_trips gt on gt.id = gr.groups_id inner join
- goods_don_sku sku on sku.id = gt.sku_id
- where sku.goods_id = #{goodsId}
- and gr.user_id in
- <foreach collection="userIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- and gr.expiry_time > #{now}
- </select>
- <select id="selectRechargeRecordNum" resultType="com.cyksj.model.response.GptRechargeStatisticsRecordResp">
- 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
- where gur.num < 0
- and gur.operator != ''
- and gur.created_time between #{start} and #{end}
- <if test="goodsIds != null">
- and o.goods_id in
- <foreach collection="goodsIds" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="operator != null">
- and gur.operator = #{operator}
- </if>
- group by gur.operator
- order by num desc
- </select>
- </mapper>
|