@@ -0,0 +1,278 @@
|
||||
package usermod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models/l/payvidlgmod"
|
||||
"91porn-server/models/v/prdcthsomod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type UserListSelector struct {
|
||||
UID *uint64 `form:"uid,omitempty" json:"uid,omitempty" bson:"uid,omitempty"` //用户id
|
||||
DevID *string `form:"devID,omitempty" json:"devID,omitempty" bson:"devID,omitempty"` //设备id
|
||||
DevType *string `form:"devType,omitempty" json:"devType,omitempty" bson:"devType,omitempty"` //设备类型
|
||||
DevToken *string `form:"devToken,omitempty" json:"devToken,omitempty" bson:"devToken,omitempty"` //设备toke`n ios 推送用
|
||||
RegisterIP *string `form:"registerIP,omitempty" json:"registerIP,omitempty" bson:"registerIP,omitempty"` //注册IP
|
||||
Mobile *string `form:"mobile,omitempty" json:"mobile,omitempty" bson:"mobile,omitempty"` //手机号
|
||||
Gender *string `form:"gender,omitempty" json:"gender,omitempty" bson:"gender,omitempty"` //性别
|
||||
Channel *string `form:"channel,omitempty" json:"channel,omitempty" bson:"channel,omitempty"`
|
||||
Name *string `form:"name,omitempty" json:"name,omitempty" bson:"name,omitempty"`
|
||||
PromotionCode *string `form:"promotionCode,omitempty" json:"promotionCode,omitempty" bson:"promotionCode,omitempty"` //推广码
|
||||
Portrait *string `form:"portrait,omitempty" json:"portrait,omitempty" bson:"portrait,omitempty"` //头像
|
||||
Summary *string `form:"summary,omitempty" json:"summary,omitempty" bson:"summary,omitempty"` //简介
|
||||
Region *string `form:"region,omitempty" json:"region,omitempty" bson:"region,omitempty"` //地区
|
||||
Birthday *string `form:"birthday,omitempty" json:"birthday,omitempty" bson:"birthday,omitempty"` //生日
|
||||
VipLevel *int `form:"vipLevel,omitempty" json:"vipLevel,omitempty" bson:"vipLevel,omitempty"` //vip等级
|
||||
HasLocked *bool `form:"hasLocked,omitempty" json:"hasLocked,omitempty" bson:"hasLocked,omitempty"` //已禁止登陆
|
||||
HasBanned *bool `form:"hasBanned,omitempty" json:"hasBanned,omitempty" bson:"hasBanned,omitempty"` //已禁言
|
||||
Token *string `form:"token,omitempty" json:"token,omitempty" bson:"token,omitempty"` //用户令牌
|
||||
WatchCount *uint64 `from:"watchCount,omitempty" json:"watchCount,omitempty" bson:"watchCount,omitempty"` //观看次数
|
||||
BankActName *string `json:"bankActName,omitempty" bson:"bankActName,omitempty"` //银行卡绑定名字
|
||||
UpTag *string `form:"upTag" json:"upTag,omitempty" bson:"upTag,omitempty"` // 博主认证
|
||||
}
|
||||
|
||||
// ExportUser 导出的用户信息
|
||||
type ExportUser struct {
|
||||
UID uint64 `xlsx:"用户id"`
|
||||
//DevID string `xlsx:"设备id"`
|
||||
DevType string `xlsx:"设备类型"`
|
||||
RegisterIP string `xlsx:"注册IP"`
|
||||
Mobile string `xlsx:"手机号"`
|
||||
//Gender string `xlsx:"性别"`
|
||||
Channel string `xlsx:"渠道号"`
|
||||
//Name string `xlsx:"用户名"`
|
||||
PromotionCode string `xlsx:"推广码"`
|
||||
//Summary string `xlsx:"简介"`
|
||||
//Region string `xlsx:"地区"`
|
||||
//Birthday string `xlsx:"生日"`
|
||||
//VipLevel int `xlsx:"vip等级"`
|
||||
VipExpireDate time.Time `xlsx:"vip过期时间"`
|
||||
CreatedAt time.Time `xlsx:"用户创建时间"`
|
||||
LastVisitAt time.Time `xlsx:"最后活跃时间"`
|
||||
//MobileBindAt *time.Time `xlsx:"手机绑定时间"`
|
||||
//HasLocked bool `xlsx:"已禁止登陆"`
|
||||
//HasBanned bool `xlsx:"已禁言"`
|
||||
WatchCount int `xlsx:"七日观看次数"` //七日观看次数,和数据库存的不同
|
||||
//VisitCount int `xlsx:"24小时内访问数"`
|
||||
//TotalVideoCnt int `xlsx:"视频总数"`
|
||||
//UndealVideoCnt int `xlsx:"未审核视频数"`
|
||||
}
|
||||
|
||||
// 用户VIP返回数据
|
||||
type UserVipInfoRes struct {
|
||||
VideoDiscount int `json:"videoDiscount"` //视频折扣率
|
||||
VideoDiscountExpiration time.Time `json:"videoDiscountExpiration"` // 视频折扣卡到期时间
|
||||
VipExpireDate time.Time `json:"vipExpireDate"` //vip过期时间
|
||||
GoldVideoFreeExpire time.Time `json:"goldVideoFreeExpire"` //金币视频免费日期
|
||||
PayVidDiscount int `json:"payVidDiscount"` //支付视频折扣
|
||||
VideoFreeExpiration *time.Time `json:"videoFreeExpiration"` //视频免费过期时间
|
||||
GoldVideoCoupon []UserGoldVideoCoupon `json:"goldVideoCoupon"`
|
||||
}
|
||||
|
||||
func FindAgentByAccount(acc string) (user *User, err error) {
|
||||
if acc == "" {
|
||||
return
|
||||
}
|
||||
err = coll(nil).FindOne(&user, bson.M{"agentAccount": acc})
|
||||
return
|
||||
}
|
||||
|
||||
func FindAllPayableAgents() ([]string, error) {
|
||||
var p []struct {
|
||||
AgentAcc string `bson:"agentAccount"`
|
||||
}
|
||||
if err := coll(nil).Find(&p, bson.M{
|
||||
"agentAccount": bson.M{"$gt": ""},
|
||||
"deposit": bson.M{"$gt": 0},
|
||||
"payable": true,
|
||||
"userType": UserLoufengAgent,
|
||||
}, options.Find().SetProjection(bson.M{"agentAccount": 1})); err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
agents := make([]string, len(p))
|
||||
for i, agent := range p {
|
||||
agents[i] = agent.AgentAcc
|
||||
}
|
||||
return agents, nil
|
||||
}
|
||||
|
||||
// FindMany 查询所有
|
||||
func FindMany(filter bson.M, _ *options.FindOptions, skip int64, size int64) ([]*User, error) {
|
||||
sort := bson.D{{Key: "createdAt", Value: -1}}
|
||||
opts := options.FindOptions{}
|
||||
opts.SetSort(sort).SetSkip(skip).SetLimit(size)
|
||||
data := make([]*User, 0)
|
||||
if err := coll(nil).Find(&data, filter, &opts); err != nil {
|
||||
log.ZapLog.Warn("proxy FindMany Find fail", log.E(err))
|
||||
return data, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// ExportFindMany 导出的时候查询所有
|
||||
func ExportFindMany(filter bson.M, skip int64, size int64) ([]*User, error) {
|
||||
sort := bson.D{{Key: "createdAt", Value: 1}}
|
||||
filter["userType"] = bson.M{"$in": []UserType{UserUnkown, UserLoufengAgent}}
|
||||
opts := options.FindOptions{}
|
||||
opts.SetSort(sort).SetSkip(skip).SetLimit(size)
|
||||
data := make([]*User, 0)
|
||||
if err := coll(nil).Find(&data, filter, &opts); err != nil {
|
||||
log.ZapLog.Warn(" ExportFindMany Find fail", log.E(err))
|
||||
return data, err
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// GetTotalCnt 查询数量
|
||||
func GetTotalCnt(filter bson.M, _ *options.FindOptions) (total int64, err error) {
|
||||
total, err = coll(nil).Count(filter)
|
||||
if err != nil {
|
||||
log.ZapLog.Warn("GetTotalCnt fail", log.E(err))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PayUIDCountByCreatedTime 消费包括 购买VIP、付费视屏
|
||||
func PayUIDCountByCreatedTime(start time.Time, end time.Time) ([]uint64, error) {
|
||||
//购买VIP /分
|
||||
vUIDList, err := prdcthsomod.PayVipUIDSByCreatedTime(start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//付费视屏 /金币
|
||||
pUIDList, err := payvidlgmod.GetUIDListByPayTime(start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payUIDMap := make(map[uint64]byte, len(vUIDList)+len(pUIDList))
|
||||
//转载payUIDMap
|
||||
for _, uid := range vUIDList {
|
||||
payUIDMap[uid] = 1
|
||||
}
|
||||
for _, uid := range pUIDList {
|
||||
payUIDMap[uid] = 1
|
||||
}
|
||||
//取出payUID
|
||||
payUIDList := make([]uint64, len(payUIDMap))
|
||||
i := 0
|
||||
for k := range payUIDMap {
|
||||
payUIDList[i] = k
|
||||
i++
|
||||
}
|
||||
return payUIDList, nil
|
||||
}
|
||||
|
||||
// NewAndPayUIDListByCreatedTime 消费包括 购买VIP、付费视屏
|
||||
func NewAndPayUIDListByCreatedTime(start time.Time, end time.Time) ([]uint64, error) {
|
||||
uidList, err := FindUIDByCreateTime(start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vUIDList, err := prdcthsomod.PayVipUIDSByCreatedTime(start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pUIDList, err := payvidlgmod.GetUIDListByPayTime(start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payUIDMap := make(map[uint64]bool, len(uidList))
|
||||
//转载payUIDMap
|
||||
for _, uid := range pUIDList {
|
||||
payUIDMap[uid] = false
|
||||
}
|
||||
//标记消费的的UID
|
||||
for _, uid := range vUIDList {
|
||||
if _, ok := payUIDMap[uid]; ok {
|
||||
payUIDMap[uid] = true
|
||||
}
|
||||
}
|
||||
for _, uid := range pUIDList {
|
||||
if _, ok := payUIDMap[uid]; ok {
|
||||
payUIDMap[uid] = true
|
||||
}
|
||||
}
|
||||
//取出payUID
|
||||
payUIDList := make([]uint64, 0, len(payUIDMap))
|
||||
for k, v := range payUIDMap {
|
||||
if v {
|
||||
payUIDList = append(payUIDList, k)
|
||||
}
|
||||
}
|
||||
return payUIDList, nil
|
||||
}
|
||||
|
||||
type UpdateFreeTimesCond struct {
|
||||
UID uint64 `json:"uid" bson:"uid" binding:"required"` // 用户ID
|
||||
FreeTimes *int64 `json:"freeTimes" bson:"freeTimes"` // 免费次数
|
||||
Mark *string `json:"mark" bson:"mark"` // 备注
|
||||
}
|
||||
|
||||
func (receiver *UpdateFreeTimesCond) Filter() bson.M {
|
||||
return bson.M{"uid": receiver.UID, "aiUndressFreeTimes": bson.M{"$gte": receiver.FreeTimes}}
|
||||
}
|
||||
|
||||
func (receiver *UpdateFreeTimesCond) Update() bson.M {
|
||||
var update = bson.M{}
|
||||
if receiver.FreeTimes != nil {
|
||||
update["aiUndressFreeTimes"] = receiver.FreeTimes
|
||||
}
|
||||
return bson.M{"$inc": update}
|
||||
}
|
||||
|
||||
type UpdateDownloadCond struct {
|
||||
UID uint64 `json:"uid" bson:"uid" binding:"required"` // 用户ID
|
||||
Download *int64 `json:"download" bson:"download"` // 下载次数
|
||||
Mark *string `json:"mark" bson:"mark"` // 备注
|
||||
}
|
||||
|
||||
func (receiver *UpdateDownloadCond) Filter() bson.M {
|
||||
return bson.M{"uid": receiver.UID}
|
||||
}
|
||||
|
||||
func (receiver *UpdateDownloadCond) Update() bson.M {
|
||||
var update = bson.M{}
|
||||
if receiver.Download != nil {
|
||||
update["downloadCount"] = receiver.Download
|
||||
}
|
||||
return bson.M{"$inc": update}
|
||||
}
|
||||
|
||||
type SetAdvertiseCond struct {
|
||||
UId []uint64 `form:"uid" json:"uid" binding:"required"` // 用户uid
|
||||
Enable *bool `form:"enable" json:"enable" binding:"required"` // 是否开启
|
||||
}
|
||||
|
||||
type UpdateLotteryTimesCond struct {
|
||||
UID uint64 `json:"uid" bson:"uid" binding:"required"` // 用户ID
|
||||
LotteryTimes *int64 `json:"lotteryTimes" bson:"lotteryTimes"` // 抽空次数
|
||||
Mark *string `json:"mark" bson:"mark"` // 备注
|
||||
}
|
||||
|
||||
func (receiver *UpdateLotteryTimesCond) Filter() bson.M {
|
||||
return bson.M{"uid": receiver.UID}
|
||||
}
|
||||
|
||||
func (receiver *UpdateLotteryTimesCond) Update() bson.M {
|
||||
var update = bson.M{}
|
||||
if receiver.LotteryTimes != nil {
|
||||
update["lotteryTimes"] = receiver.LotteryTimes
|
||||
}
|
||||
return bson.M{"$inc": update}
|
||||
}
|
||||
|
||||
type DeleteCommentCond struct {
|
||||
UID uint64 `json:"uid" bson:"uid" binding:"required"` // 用户ID
|
||||
}
|
||||
|
||||
type QueryGameCodeCond struct {
|
||||
UID uint64 `form:"uid" json:"uid" bson:"uid,omitempty"` //用户ID
|
||||
}
|
||||
|
||||
func (receiver *DeleteCommentCond) Filter() bson.M {
|
||||
return bson.M{"uid": receiver.UID}
|
||||
}
|
||||
Reference in New Issue
Block a user