by Robin at 20240913
This commit is contained in:
parent
4b086d966e
commit
60bc449313
|
@ -0,0 +1,54 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
const (
|
||||||
|
MemRoleBuyer = 1 // 买家
|
||||||
|
)
|
||||||
|
|
||||||
|
// Account 用户结构
|
||||||
|
type Account struct {
|
||||||
|
Mid *int64 `json:"mid" bson:"_id"` // 用户表Id
|
||||||
|
Name *string `json:"name" bson:"name"` // 用户名
|
||||||
|
UserId *int64 `json:"user_id" bson:"user_id"` // 业务Id
|
||||||
|
Avatar *MediaComponent `json:"avatar" bson:"avatar"` // 头像
|
||||||
|
MobilePhone *string `json:"mobile_phone" bson:"mobile_phone" jcrypto:"rsa" bcrypto:"aes_cbc|1|0"` // 手机号,数据库加密,查询不解密
|
||||||
|
PhoneHash *string `json:"phone_hash" bson:"phone_hash"` // 手机号hash值
|
||||||
|
RegionCode *string `json:"region_code" bson:"region_code"` // 地区码
|
||||||
|
Level *int64 `json:"level" bson:"level"` // 等级
|
||||||
|
Role *int64 `json:"role" bson:"role"` // 角色
|
||||||
|
CurrentExp *int64 `json:"current_exp" bson:"current_exp"` // 当前经验
|
||||||
|
CurrentLevelExp *int64 `json:"current_level_exp" bson:"current_level_exp"` // 当前等级总经验
|
||||||
|
IsDndModeEnabled *int64 `json:"is_dnd_mode_enabled" bson:"is_dnd_mode_enabled"` // 是否开启勿扰模式
|
||||||
|
GoldNum *int64 `json:"gold_num" bson:"gold_num"` // 金币数量
|
||||||
|
DiamondNum *int64 `json:"diamond_num" bson:"diamond_num"` // 钻石数量
|
||||||
|
Inviter *int64 `json:"inviter" bson:"inviter"` // 邀请人user_id
|
||||||
|
IsAMember *int64 `json:"is_a_member" bson:"is_a_member"` // 是否是会员,0-否,1-是
|
||||||
|
Status *int64 `json:"status" bson:"status"` // 账户状态,0-正常,1-账户注销中,2-账户已注销
|
||||||
|
DevType *int32 `bson:"dev_type"` // 注册来源
|
||||||
|
Latitude *float64 `bson:"latitude"` // 纬度
|
||||||
|
Longitude *float64 `bson:"longitude"` // 经度
|
||||||
|
UserIdString *string `bson:"user_id_string"` // string型user_id,为模糊匹配设置
|
||||||
|
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||||
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记,0-否,1-是
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Account) GetMid() int64 {
|
||||||
|
if p != nil && p.Mid != nil {
|
||||||
|
return *p.Mid
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Account) GetName() string {
|
||||||
|
if p != nil && p.Name != nil {
|
||||||
|
return *p.Name
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Account) GetUserId() int64 {
|
||||||
|
if p != nil && p.UserId != nil {
|
||||||
|
return *p.UserId
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
type AuditComponent struct {
|
||||||
|
AuditStatus *int64 `json:"audit_status" bson:"audit_status"` // 审核状态
|
||||||
|
AuditOpinion *string `json:"audit_opinion" bson:"audit_opinion"` // 审核意见
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *AuditComponent) GetAuditStatus() int64 {
|
||||||
|
if p == nil || p.AuditStatus == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return *p.AuditStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *AuditComponent) GetAuditOpinion() string {
|
||||||
|
if p == nil || p.AuditOpinion == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *p.AuditOpinion
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
type UserIdSeq struct {
|
||||||
|
Seq int64 //用户业务id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserIdMap struct {
|
||||||
|
Seq int64 `json:"seq" bson:"_id"` //用户业务id序列号
|
||||||
|
UserId int64 `json:"user_id" bson:"user_id"` //映射后用户业务id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type AccountIdSeq struct {
|
||||||
|
Seq int64 //用户Id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type MomentIdSeq struct {
|
||||||
|
Seq int64 //动态Id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type StreamerAuthApprovalIdSeq struct {
|
||||||
|
Seq int64 //女神认证Id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type AccountRelationIdSeq struct {
|
||||||
|
Seq int64 //用户关系Id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type StreamerLinkIdSeq struct {
|
||||||
|
Seq int64 //主播链接Id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserWxAddCheckIdSeq struct {
|
||||||
|
Seq int64 //用户微信添加审核Id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type RealNameAuthenticationIdSeq struct {
|
||||||
|
Seq int64 //实名认证ID序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContactCustomerServiceIdSeq struct {
|
||||||
|
Seq int64 //联系客服ID序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type ContactCustomerServiceSessionIdSeq struct {
|
||||||
|
Seq int64 //联系客服对话ID序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type MediaIdSeq struct {
|
||||||
|
Seq int64 `json:"seq" bson:"seq"`
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
type Login struct {
|
||||||
|
Id *int64 `json:"id" bson:"_id"` // 登录表id
|
||||||
|
Mid *int64 `json:"mid" bson:"mid"` // 用户id
|
||||||
|
Password *string `json:"password" bson:"password"` // 密码
|
||||||
|
PhoneHash *string `json:"phone_hash" bson:"phone_hash"` // 手机号hash值
|
||||||
|
RegionCode *string `json:"region_code" bson:"region_code"` // 国家区号
|
||||||
|
IsLogined *int64 `json:"is_logined" bson:"is_logined"` // 是否登陆,0-否,1-是
|
||||||
|
LastLoginTime *int64 `json:"last_login_time" bson:"last_login_time"` // 最后登陆时间
|
||||||
|
WrongPswdTimes *int64 `json:"wrong_pswd_times" bson:"wrong_pswd_times"` // 密码错误次数
|
||||||
|
IsEnabled *int64 `json:"is_enabled" bson:"is_enabled"` // 是否启用,0-否,1-是
|
||||||
|
IsLocked *int64 `json:"is_locked" bson:"is_locked"` // 是否锁定,0-否,1-是
|
||||||
|
IsBanned *int64 `json:"is_banned" bson:"is_banned"` // 是否封禁,0-否,1-是
|
||||||
|
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||||
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记,0-否,1-是
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
// 图片
|
||||||
|
type Image struct {
|
||||||
|
Id int64 `json:"id" bson:"_id"` // 图片id
|
||||||
|
Ct int64 `json:"ct" bson:"ct"` // 创建时间
|
||||||
|
Ut int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
|
SrcId string `json:"src_id" bson:"src_id"` // 源id
|
||||||
|
MD5 string `json:"md5" bson:"md5"` // 视频md5
|
||||||
|
W int64 `json:"w" bson:"w"` // 宽
|
||||||
|
H int64 `json:"h" bson:"h"` // 高
|
||||||
|
Fmt string `json:"fmt" bson:"fmt"` // 图片格式
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToCImage struct {
|
||||||
|
Id int64 `json:"id"` // 图片id
|
||||||
|
W int64 `json:"w"` // 宽
|
||||||
|
H int64 `json:"h"` // 高
|
||||||
|
Fmt string `json:"fmt"` // 图片格式
|
||||||
|
Urls []string `json:"urls"` // 图片展示地址
|
||||||
|
}
|
||||||
|
|
||||||
|
// 视频
|
||||||
|
type Video struct {
|
||||||
|
Id int64 `json:"id" bson:"_id"` // 视频id
|
||||||
|
Ct int64 `json:"ct" bson:"ct"` // 创建时间
|
||||||
|
Ut int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
|
SrcId string `json:"src_id" bson:"src_id"` // 源id
|
||||||
|
CoverSrcId string `json:"cover_src_id" bson:"cover_src_id"` // cover srcId
|
||||||
|
CoverId int64 `json:"cover_id" bson:"cover_id"` // 封面id
|
||||||
|
MD5 string `json:"md5" bson:"md5"` // 视频md5
|
||||||
|
Dur int64 `json:"dur" bson:"dur"` // 视频时长
|
||||||
|
Fmt string `json:"fmt" bson:"fmt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ToCVideo struct {
|
||||||
|
Id int64 `json:"id"` // 视频id
|
||||||
|
Dur int64 `json:"dur"` // 视频时
|
||||||
|
CoverUrls []string `json:"cover_urls"` // 视频封面地址
|
||||||
|
Urls []string `json:"urls"` // 视频地址
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
type MediaComponent struct {
|
||||||
|
ImageIds *[]int64 `json:"image_ids" bson:"image_ids"` // 图片ids
|
||||||
|
VideoIds *[]int64 `json:"video_ids" bson:"video_ids"` // 视频ids
|
||||||
|
Images []*ToCImage `json:"images"`
|
||||||
|
Videos []*ToCVideo `json:"videos"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MediaComponent) GetImageIds() []int64 {
|
||||||
|
if p != nil && p.ImageIds != nil {
|
||||||
|
return *p.ImageIds
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MediaComponent) GetVideoIds() []int64 {
|
||||||
|
if p != nil && p.VideoIds != nil {
|
||||||
|
return *p.VideoIds
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MediaComponent) SetImages(images []*ToCImage) {
|
||||||
|
if p != nil {
|
||||||
|
p.Images = make([]*ToCImage, 0)
|
||||||
|
p.Images = append(p.Images, images...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *MediaComponent) SetVideos(videos []*ToCVideo) {
|
||||||
|
if p != nil {
|
||||||
|
p.Videos = make([]*ToCVideo, 0)
|
||||||
|
p.Videos = append(p.Videos, videos...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageIds和VideoIds不可同时为空
|
||||||
|
func (p *MediaComponent) IsEmpty() bool {
|
||||||
|
if p == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return len(p.GetImageIds()) == 0 && len(p.GetVideoIds()) == 0
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
type Streamer struct {
|
||||||
|
Id *int64 `json:"id" bson:"_id"` // 主播表id
|
||||||
|
Mid *int64 `json:"mid" bson:"mid"` // 用户表id
|
||||||
|
Gender *int64 `json:"gender" bson:"gender"` // 性别
|
||||||
|
Bio *string `json:"bio" bson:"bio"` // 个性签名
|
||||||
|
Cover *MediaComponent `json:"cover" bson:"cover"` // 封面
|
||||||
|
Shorts *MediaComponent `json:"shorts" bson:"shorts"` // 展示视频
|
||||||
|
Album *MediaComponent `json:"album" bson:"album"` // 相册
|
||||||
|
Age *int64 `json:"age" bson:"age"` // 年龄
|
||||||
|
Height *int64 `json:"height" bson:"height"` // 身高
|
||||||
|
Weight *int64 `json:"weight" bson:"weight"` // 体重
|
||||||
|
Constellation *string `json:"constellation" bson:"constellation"` // 星座
|
||||||
|
City *string `json:"city" bson:"city"` // 所在城市
|
||||||
|
Tag *[]string `json:"tag" bson:"tag"` // 主播标签
|
||||||
|
Fans *int64 `json:"fans" bson:"fans"` // 全网粉丝
|
||||||
|
AutoResponseMessage *string `json:"auto_response_message" bson:"auto_response_message"` // 自动回复消息
|
||||||
|
Inviters *[]int64 `json:"inviters" bson:"inviters"` // 邀请人
|
||||||
|
IsHided *int64 `json:"is_hided" bson:"is_hided"` // 是否隐藏
|
||||||
|
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||||
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||||
|
CoverAudit *AuditComponent `bson:"cover_audit"` // 封面审核
|
||||||
|
ShortsAudit *AuditComponent `bson:"shorts_audit"` // 展示视频审核
|
||||||
|
AlbumAudit *AuditComponent `bson:"album_audit"` // 相册审核
|
||||||
|
BioAudit *AuditComponent `bson:"bio_audit"` // 个性签名审核
|
||||||
|
AutoResponseMessageAudit *AuditComponent `bson:"auto_response_message_audit"` // 自动回复消息审核
|
||||||
|
CoverReview *AuditComponent `bson:"cover_review"` // 封面人审
|
||||||
|
ShortsReview *AuditComponent `bson:"shorts_review"` // 展示视频人审
|
||||||
|
AlbumReview *AuditComponent `bson:"album_review"` // 相册人审
|
||||||
|
BioReview *AuditComponent `bson:"bio_review"` // 个性签名人审
|
||||||
|
AutoResponseMessageReview *AuditComponent `bson:"auto_response_message_review"` // 自动回复消息人审
|
||||||
|
|
||||||
|
WechatLockType *int32 `json:"wechat_lock_type"` // 微信解锁方式
|
||||||
|
WechatContact *string `json:"wechat_contact"` // 微信联系方式
|
||||||
|
WechatCoinPrice *int64 `json:"wechat_coin_price"` // 微信金币价格
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Streamer) GetMid() int64 {
|
||||||
|
if p == nil || p.Mid == nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return *p.Mid
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Streamer) GetBio() string {
|
||||||
|
if p == nil || p.Bio == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *p.Bio
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Streamer) GetAutoResponseMessage() string {
|
||||||
|
if p == nil || p.AutoResponseMessage == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *p.AutoResponseMessage
|
||||||
|
}
|
|
@ -0,0 +1,190 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"data_prep/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 用户增值信息
|
||||||
|
const (
|
||||||
|
UserVasLockTypeOpen = 0 // 公开
|
||||||
|
UserVasLockTypeLock = 1 // 私密
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserVasInfo struct {
|
||||||
|
Mid int64 `json:"mid" bson:"_id"`
|
||||||
|
WechatLockType int32 `json:"wechat_lock_type" bson:"wechat_lock_type"` // 上锁方式见:UserVasLockType*
|
||||||
|
WechatContact string `json:"wechat_contact" bson:"wechat_contact"` // 微信联系方式
|
||||||
|
WechatCoinPrice int64 `json:"wechat_coin_price" bson:"wechat_coin_price"` // 微信联系方式价格
|
||||||
|
WechatUt int64 `json:"wechat_ut" bson:"wechat_ut"` // 微信联系方式更新时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p UserVasInfo) GetH5WechatCoinPrice() int64 {
|
||||||
|
return int64(math.Ceil(float64(p.WechatCoinPrice)/9)) * 10
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p UserVasInfo) GetWechatCoinPrice() int64 {
|
||||||
|
return p.WechatCoinPrice
|
||||||
|
}
|
||||||
|
|
||||||
|
// 金币订单oplog
|
||||||
|
const (
|
||||||
|
OrderOpLogActionAdd = "add"
|
||||||
|
OrderOpLogActionUpdate = "update"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrderOpLogOperatorTypeUser = "user" // 用户
|
||||||
|
OrderOpLogOperatorTypeOp = "op" // 运营
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrderOpLogResultFail = "fail" // 结果失败
|
||||||
|
OrderOpLogResultOk = "ok" // 结果成功
|
||||||
|
)
|
||||||
|
|
||||||
|
type OplogCoinOrder struct {
|
||||||
|
OrderId string `json:"order_id" bson:"order_id"`
|
||||||
|
Mid int64 `json:"mid" bson:"mid"`
|
||||||
|
Ct int64 `json:"ct" bson:"ct"`
|
||||||
|
Action string `json:"action" bson:"action"` // 动作
|
||||||
|
OperatorType string `json:"operator_type" bson:"operator_type"` // 操作人类型,见CoinOrderOpLogOperatorType*
|
||||||
|
Operator string `json:"operator" bson:"operator"` // 操作人
|
||||||
|
Detail string `json:"detail" bson:"detail"` // 操作详情
|
||||||
|
Result string `json:"result" bson:"result"` // 结果
|
||||||
|
BeforeStatus int32 `json:"before_status" bson:"before_status"`
|
||||||
|
AfterStatus int32 `json:"after_status" bson:"after_status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type OplogOrder struct {
|
||||||
|
OrderId string `json:"order_id" bson:"order_id"`
|
||||||
|
Mid int64 `json:"mid" bson:"mid"`
|
||||||
|
Ct int64 `json:"ct" bson:"ct"`
|
||||||
|
Action string `json:"action" bson:"action"` // 动作
|
||||||
|
OperatorType string `json:"operator_type" bson:"operator_type"` // 操作人类型,见CoinOrderOpLogOperatorType*
|
||||||
|
Operator string `json:"operator" bson:"operator"` // 操作人
|
||||||
|
Detail string `json:"detail" bson:"detail"` // 操作详情
|
||||||
|
Result string `json:"result" bson:"result"` // 结果
|
||||||
|
BeforeStatus int32 `json:"before_status" bson:"before_status"`
|
||||||
|
AfterStatus int32 `json:"after_status" bson:"after_status"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
SuperfanshipValidPeriodEternal = 0 // 永久生效
|
||||||
|
SuperfanshipValidPeriodMonth = 1 // 31d
|
||||||
|
SuperfanshipValidPeriodSeason = 2 // 93d
|
||||||
|
SuperfanshipValidPeriodHalfYear = 3 // 186d
|
||||||
|
SuperfanshipValidPeriodYear = 4 // 372d
|
||||||
|
)
|
||||||
|
|
||||||
|
// 空间增值相关,空间价格等
|
||||||
|
type ZoneVas struct {
|
||||||
|
Zid int64 `json:"zid" bson:"_id"`
|
||||||
|
Mid int64 `json:"mid" bson:"mid"` // 主播mid
|
||||||
|
Ct int64 `json:"ct" bson:"ct"` //
|
||||||
|
Ut int64 `json:"ut" bson:"ut"` //
|
||||||
|
AdmissionPrice int64 `json:"admission_price" bson:"admission_price"` // 空间解锁价格, 单位: 分
|
||||||
|
IronfanshipPrice int64 `json:"ironfanship_price" bson:"ironfanship_price"` // 铁粉解锁价格, 单位: 分
|
||||||
|
IsSuperfanshipEnabled int `json:"is_superfanship_enabled" bson:"is_superfanship_enabled"` // 是否开启超粉空间 0: 关闭, 1: 开启
|
||||||
|
SuperfanshipPrice int64 `json:"superfanship_price" bson:"superfanship_price"` // 超粉价格, 单位: 分
|
||||||
|
SuperfanshipValidPeriod int `json:"superfanship_valid_period" bson:"superfanship_valid_period"` // 超粉有效期类型, SuperfanshipValidPeriod*
|
||||||
|
IsSuperfanshipGiveWechat int `json:"is_superfanship_give_wechat" bson:"is_superfanship_give_wechat"` // 是否开启超粉空间赠送微信 0: 不赠送, 1: 赠送
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ZoneVas) GetSuperfanshipDurationSecond() int64 {
|
||||||
|
switch p.SuperfanshipValidPeriod {
|
||||||
|
case SuperfanshipValidPeriodEternal:
|
||||||
|
return -1
|
||||||
|
case SuperfanshipValidPeriodMonth:
|
||||||
|
return 86400 * 31
|
||||||
|
case SuperfanshipValidPeriodSeason:
|
||||||
|
return 86400 * 31 * 3
|
||||||
|
case SuperfanshipValidPeriodHalfYear:
|
||||||
|
return 86400 * 31 * 6
|
||||||
|
case SuperfanshipValidPeriodYear:
|
||||||
|
return 86400 * 31 * 12
|
||||||
|
default:
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ZoneVas) GetSuperfanshipDurationDesc() string {
|
||||||
|
switch p.SuperfanshipValidPeriod {
|
||||||
|
case SuperfanshipValidPeriodEternal:
|
||||||
|
return "永久"
|
||||||
|
case SuperfanshipValidPeriodMonth:
|
||||||
|
return "1个月"
|
||||||
|
case SuperfanshipValidPeriodSeason:
|
||||||
|
return "3个月"
|
||||||
|
case SuperfanshipValidPeriodHalfYear:
|
||||||
|
return "6个月"
|
||||||
|
case SuperfanshipValidPeriodYear:
|
||||||
|
return "12个月"
|
||||||
|
default:
|
||||||
|
return "永久"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ZoneVas) GetAdmissionCoinPrice() int64 {
|
||||||
|
return util.RoundUp(float64(p.AdmissionPrice) / 10.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ZoneVas) GetIronfanshipCoinPrice() int64 {
|
||||||
|
return util.RoundUp(float64(p.IronfanshipPrice) / 10.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ZoneVas) GetSuperfanshipCoinPrice() int64 {
|
||||||
|
return util.RoundUp(float64(p.SuperfanshipPrice) / 10.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 空间动态价格
|
||||||
|
type ZoneMomentPrice struct {
|
||||||
|
MomentId int64 `json:"id" bson:"_id"` // 动态id
|
||||||
|
Zid int64 `json:"zid" bson:"zid"` // 空间id
|
||||||
|
Mid int64 `json:"mid" bson:"mid"` // 主播mid
|
||||||
|
Ct int64 `json:"ct" bson:"ct"` //
|
||||||
|
Ut int64 `json:"ut" bson:"ut"` //
|
||||||
|
Price int64 `json:"price" bson:"price"` // 动态价格,单位:分
|
||||||
|
}
|
||||||
|
|
||||||
|
// 空间动态数据相关
|
||||||
|
type ZoneMomentStat struct {
|
||||||
|
MomentId int64 `json:"id" bson:"_id"` // 动态id
|
||||||
|
Zid int64 `json:"zid" bson:"zid"` // 空间id
|
||||||
|
BuyerCnt int64 `json:"buyer_cnt" bson:"buyer_cnt"` // 动态购买人数
|
||||||
|
Ct int64 `json:"ct" bson:"ct"` //
|
||||||
|
Ut int64 `json:"ut" bson:"ut"` //
|
||||||
|
}
|
||||||
|
|
||||||
|
// 收入表
|
||||||
|
type WeekDashboardSt struct {
|
||||||
|
Date string `json:"date" bson:"date"` // 日期 x轴
|
||||||
|
Income int64 `json:"income" bson:"income"` // 收入 y轴
|
||||||
|
}
|
||||||
|
|
||||||
|
type IncomeFromDashboardSt struct {
|
||||||
|
Desc string `json:"desc" bson:"desc"` // 描述
|
||||||
|
Income int64 `json:"income" bson:"income"` // 收入
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserIncome struct {
|
||||||
|
Mid int64 `json:"mid" bson:"_id"`
|
||||||
|
WeekDashboard []WeekDashboardSt `json:"week_dashboard" bson:"week_dashboard"`
|
||||||
|
WeekFromDashboard []IncomeFromDashboardSt `json:"week_from_dashboard" bson:"week_from_dashboard"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提现历史
|
||||||
|
const (
|
||||||
|
WithdrawStatusOk = 1
|
||||||
|
WithdrawStatusFail = 2
|
||||||
|
)
|
||||||
|
|
||||||
|
type WithdrawHis struct {
|
||||||
|
Id string `json:"id" bson:"_id"`
|
||||||
|
Mid int64 `json:"mid" bson:"mid"`
|
||||||
|
Did string `json:"did" bson:"did"`
|
||||||
|
Status int `json:"status" bson:"status"` // 见: WithdrawStatusOk
|
||||||
|
Err string `json:"err" bson:"err"`
|
||||||
|
Ct int64 `json:"ct" bson:"ct"`
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package dbstruct
|
||||||
|
|
||||||
|
// 空间总人数统计
|
||||||
|
type ZoneMemberCount struct {
|
||||||
|
Zid *int64 `json:"zid" db:"zid"`
|
||||||
|
Num *int64 `json:"num" db:"num"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ZoneMemberCount) GetZid() int64 {
|
||||||
|
if p != nil && p.Zid != nil {
|
||||||
|
return *p.Zid
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ZoneMemberCount) GetNum() int64 {
|
||||||
|
if p != nil && p.Num != nil {
|
||||||
|
return *p.Num
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type Zone struct {
|
||||||
|
Id *int64 `json:"id" bson:"_id"` // 空间表id
|
||||||
|
Mid *int64 `json:"mid" bson:"mid"` // 用户表id
|
||||||
|
Profile *string `json:"profile" bson:"profile"` // 空间简介
|
||||||
|
LastZoneMomentCt *int64 `json:"last_zone_moment_ct" bson:"last_zone_moment_ct"` // 最后空间动态创建时间
|
||||||
|
ZoneMomentCount *int64 `json:"zone_moment_count" bson:"zone_moment_count"` // 空间内动态总数
|
||||||
|
ImageCount *int64 `json:"image_count" bson:"image_count"` // 空间内图片总数
|
||||||
|
VideoCount *int64 `json:"video_count" bson:"video_count"` // 空间内视频总数
|
||||||
|
IsZoneThirdPartnerHided *int64 `json:"is_zone_third_partner_hided" bson:"is_zone_third_partner_hided"` // 是否隐藏空间代运营
|
||||||
|
Ct *int64 `json:"ct" bson:"ct"` // 创建时间
|
||||||
|
Ut *int64 `json:"ut" bson:"ut"` // 更新时间
|
||||||
|
DelFlag *int64 `json:"del_flag" bson:"del_flag"` // 删除标记
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Zone) GetId() int64 {
|
||||||
|
if p != nil && p.Id != nil {
|
||||||
|
return *p.Id
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Zone) GetMid() int64 {
|
||||||
|
if p != nil && p.Mid != nil {
|
||||||
|
return *p.Mid
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Zone) GetZoneMomentCount() int64 {
|
||||||
|
if p != nil && p.ZoneMomentCount != nil {
|
||||||
|
return *p.ZoneMomentCount
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Zone) GetLastZoneMomentCt() int64 {
|
||||||
|
if p != nil && p.LastZoneMomentCt != nil {
|
||||||
|
return *p.LastZoneMomentCt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Zone) GetIsZoneThirdPartnerHided() int64 {
|
||||||
|
if p != nil && p.IsZoneThirdPartnerHided != nil {
|
||||||
|
return *p.IsZoneThirdPartnerHided
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
module data_prep
|
||||||
|
|
||||||
|
go 1.21.0
|
||||||
|
|
||||||
|
require github.com/qiniu/qmgo v1.1.8
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/go-playground/locales v0.13.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1 // indirect
|
||||||
|
github.com/golang/snappy v0.0.1 // indirect
|
||||||
|
github.com/klauspost/compress v1.13.6 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.0 // indirect
|
||||||
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
|
github.com/xdg-go/scram v1.1.1 // indirect
|
||||||
|
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
||||||
|
go.mongodb.org/mongo-driver v1.11.6 // indirect
|
||||||
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
|
||||||
|
golang.org/x/text v0.3.7 // indirect
|
||||||
|
google.golang.org/protobuf v1.34.2
|
||||||
|
)
|
|
@ -0,0 +1,69 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
|
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||||
|
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||||
|
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
||||||
|
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||||
|
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||||
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||||
|
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||||
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
|
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||||
|
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||||
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
|
||||||
|
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/qiniu/qmgo v1.1.8 h1:E64M+P59aqQpXKI24ClVtluYkLaJLkkeD2hTVhrdMks=
|
||||||
|
github.com/qiniu/qmgo v1.1.8/go.mod h1:QvZkzWNEv0buWPx0kdZsSs6URhESVubacxFPlITmvB8=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
|
||||||
|
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
|
||||||
|
github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E=
|
||||||
|
github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g=
|
||||||
|
github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs=
|
||||||
|
github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8=
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
|
||||||
|
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
|
||||||
|
go.mongodb.org/mongo-driver v1.11.6 h1:XM7G6PjiGAO5betLF13BIa5TlLUUE3uJ/2Ox3Lz1K+o=
|
||||||
|
go.mongodb.org/mongo-driver v1.11.6/go.mod h1:G9TgswdsWjX4tmDA5zfs2+6AEPpYJwqblyjsfuh8oXY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||||
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||||
|
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -0,0 +1,33 @@
|
||||||
|
package importfunc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GenerateUserIdMap() {
|
||||||
|
outfile, err := os.OpenFile("/Users/Caeru/dataprep/file/user_id_map.txt", os.O_WRONLY|os.O_CREATE, 0666)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Open File Err : %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer outfile.Close()
|
||||||
|
|
||||||
|
writer := bufio.NewWriter(outfile)
|
||||||
|
|
||||||
|
list := make([]int64, 0)
|
||||||
|
for i := int64(1000000); i < 100000000; i++ {
|
||||||
|
list = append(list, i)
|
||||||
|
}
|
||||||
|
rand.Shuffle(99000000, func(i, j int) {
|
||||||
|
list[i], list[j] = list[j], list[i]
|
||||||
|
})
|
||||||
|
|
||||||
|
for i := range list {
|
||||||
|
outfile.WriteString(fmt.Sprintf("%v:%v\n", 1000000+i, list[i]))
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.Flush()
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package importfunc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Leufolium/test/dbstruct"
|
||||||
|
"github.com/Leufolium/test/mongo"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ImportUserIdMap() {
|
||||||
|
|
||||||
|
mcli, err := mongo.NewMongo()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("mongo client init fail : %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
infilePath := "/app/dataprep/file/user_id_map.txt"
|
||||||
|
|
||||||
|
infile, err := os.Open(infilePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Open File Err : %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer infile.Close()
|
||||||
|
|
||||||
|
reader := bufio.NewReader(infile)
|
||||||
|
|
||||||
|
userIdMaps := make([]*dbstruct.UserIdMap, 0)
|
||||||
|
|
||||||
|
for {
|
||||||
|
str, err := reader.ReadString('\n')
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ReadString fail : %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
strs := strings.Split(str, ":")
|
||||||
|
seqStr := strs[0]
|
||||||
|
userIdStr := strs[1]
|
||||||
|
userIdStr = strings.ReplaceAll(userIdStr, "\n", "")
|
||||||
|
userIdStr = strings.ReplaceAll(userIdStr, "\r", "")
|
||||||
|
|
||||||
|
seq, err := strconv.Atoi(seqStr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("atoi fail : %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userId, err := strconv.Atoi(userIdStr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("atoi fail : %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userIdMaps = append(userIdMaps, &dbstruct.UserIdMap{
|
||||||
|
Seq: int64(seq),
|
||||||
|
UserId: int64(userId),
|
||||||
|
})
|
||||||
|
if len(userIdMaps) == 10000 {
|
||||||
|
mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||||
|
userIdMaps = make([]*dbstruct.UserIdMap, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(userIdMaps) > 0 {
|
||||||
|
mcli.CreateMappedUserIds(ctx, userIdMaps)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package mongo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/qiniu/qmgo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||||
|
goproto "google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var url = "mongodb://root:Wishpal2024@dds-bp1da1ddd62bede41.mongodb.rds.aliyuncs.com:3717,dds-bp1da1ddd62bede42.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-77304659"
|
||||||
|
|
||||||
|
func NewMongoClient() (*qmgo.Client, error) {
|
||||||
|
clientCfg := &qmgo.Config{
|
||||||
|
Uri: "mongodb://admin:Wishpal%402023@172.31.37.71:27017",
|
||||||
|
//Uri: url,
|
||||||
|
ConnectTimeoutMS: goproto.Int64(30000),
|
||||||
|
MaxPoolSize: goproto.Uint64(16),
|
||||||
|
MinPoolSize: goproto.Uint64(0),
|
||||||
|
SocketTimeoutMS: goproto.Int64(5000),
|
||||||
|
ReadPreference: &qmgo.ReadPref{Mode: readpref.PrimaryMode},
|
||||||
|
}
|
||||||
|
cli, err := qmgo.NewClient(context.Background(), clientCfg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("NewMongoClient fail, cfg: %v, err: %v", clientCfg, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return cli, nil
|
||||||
|
}
|
|
@ -0,0 +1,338 @@
|
||||||
|
package mongo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"data_prep/dbstruct"
|
||||||
|
|
||||||
|
"github.com/qiniu/qmgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserIdMap struct {
|
||||||
|
Seq int64 `json:"seq" bson:"_id"` //用户业务id序列号
|
||||||
|
UserId int64 `json:"user_id" bson:"user_id"` //映射后用户业务id序列号
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mongo struct {
|
||||||
|
clientMix *qmgo.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMongo() (mongo *Mongo, err error) {
|
||||||
|
mongo = new(Mongo)
|
||||||
|
|
||||||
|
mongo.clientMix, err = NewMongoClient()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("NewMongoClient fail, cfg: %v, err: %v", nil, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
DBUserIdSeq = "user_id_seq"
|
||||||
|
COLUserIdSeq = "user_id_seq"
|
||||||
|
COLUserIdMap = "user_id_map"
|
||||||
|
|
||||||
|
DBAccountIdSeq = "account_id_seq"
|
||||||
|
COLAccountIdSeq = "account_id_seq"
|
||||||
|
|
||||||
|
DBAccount = "account"
|
||||||
|
COLAccount = "account"
|
||||||
|
|
||||||
|
DBLogin = "login"
|
||||||
|
COLLogin = "login"
|
||||||
|
|
||||||
|
DBZone = "zone"
|
||||||
|
COLZone = "zone"
|
||||||
|
|
||||||
|
DBZoneMoment = "zone_moment"
|
||||||
|
COLZoneMoment = "zone_moment"
|
||||||
|
|
||||||
|
DBStreamer = "streamer"
|
||||||
|
COLStreamer = "streamer"
|
||||||
|
|
||||||
|
DBVas = "vas"
|
||||||
|
COLProduct = "product"
|
||||||
|
COLUserVasInfo = "user_vas_info"
|
||||||
|
COLOpLogOrder = "oplog_order_%d"
|
||||||
|
COLOpLogCoinOrder = "oplog_coin_order_%d"
|
||||||
|
COLZoneVas = "zone_vas"
|
||||||
|
COLZoneMomentPrice = "zone_moment_price"
|
||||||
|
COLZoneMomentStat = "zone_moment_stat"
|
||||||
|
COLUserIncome = "user_income"
|
||||||
|
COLWithdrawHis = "withdraw_his"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *Mongo) getColUserIdSeq() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdSeq)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) getColUserIdMap() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBUserIdSeq).Collection(COLUserIdMap)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account表
|
||||||
|
func (m *Mongo) getColAccount() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBAccount).Collection(COLAccount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录表
|
||||||
|
func (m *Mongo) getColLogin() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBLogin).Collection(COLLogin)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIdSeq序列表
|
||||||
|
func (m *Mongo) getColAccountIdSeq() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBAccountIdSeq).Collection(COLAccountIdSeq)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 空间表
|
||||||
|
func (m *Mongo) getColZone() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBZone).Collection(COLZone)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 私密圈动态表
|
||||||
|
func (m *Mongo) getColZoneMoment() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBZoneMoment).Collection(COLZoneMoment)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 主播表
|
||||||
|
func (m *Mongo) getColStreamer() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBStreamer).Collection(COLStreamer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户增值信息,微信价格等
|
||||||
|
func (m *Mongo) getColUserVasInfo() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBVas).Collection(COLUserVasInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 空间增值信息
|
||||||
|
func (m *Mongo) getColZoneVas() *qmgo.Collection {
|
||||||
|
return m.clientMix.Database(DBVas).Collection(COLZoneVas)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) CreateBatch(ctx context.Context, userIdSeqs []*UserIdMap) error {
|
||||||
|
col := m.getColUserIdMap()
|
||||||
|
_, err := col.InsertMany(ctx, userIdSeqs)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// account相关
|
||||||
|
func (m *Mongo) CreateAccount(ctx context.Context, account *dbstruct.Account) error {
|
||||||
|
col := m.getColAccount()
|
||||||
|
_, err := col.InsertOne(ctx, account)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) CreateLogin(ctx context.Context, login *dbstruct.Login) error {
|
||||||
|
col := m.getColLogin()
|
||||||
|
_, err := col.InsertOne(ctx, login)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetAndUpdateAccountIdSeq(ctx context.Context) (accountIdSeq *dbstruct.AccountIdSeq, err error) {
|
||||||
|
col := m.getColAccountIdSeq()
|
||||||
|
|
||||||
|
change := qmgo.Change{
|
||||||
|
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
|
||||||
|
Upsert: true,
|
||||||
|
ReturnNew: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
accountIdSeqInstance := dbstruct.AccountIdSeq{}
|
||||||
|
if err = col.Find(ctx, qmgo.M{"_id": "account_id_seq_id"}).Apply(change, &accountIdSeqInstance); err != nil {
|
||||||
|
fmt.Printf("change error : %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return &accountIdSeqInstance, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetAndUpdateUserIdSeq(ctx context.Context) (userIdSeq *dbstruct.UserIdSeq, err error) {
|
||||||
|
col := m.getColUserIdSeq()
|
||||||
|
|
||||||
|
change := qmgo.Change{
|
||||||
|
Update: qmgo.M{"$inc": qmgo.M{"seq": 1}},
|
||||||
|
Upsert: true,
|
||||||
|
ReturnNew: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
userIdSeqInstance := dbstruct.UserIdSeq{}
|
||||||
|
if err = col.Find(ctx, qmgo.M{"_id": "user_id_seq_id"}).Apply(change, &userIdSeqInstance); err != nil {
|
||||||
|
fmt.Printf("change error : %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return &userIdSeqInstance, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) CreateMappedUserIds(ctx context.Context, userIdMaps []*dbstruct.UserIdMap) error {
|
||||||
|
col := m.getColUserIdMap()
|
||||||
|
_, err := col.InsertMany(ctx, userIdMaps)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetMappedUserId(ctx context.Context, userIdSeq int64) (*dbstruct.UserIdMap, error) {
|
||||||
|
userIdMap := &dbstruct.UserIdMap{}
|
||||||
|
col := m.getColUserIdMap()
|
||||||
|
query := qmgo.M{
|
||||||
|
"_id": userIdSeq,
|
||||||
|
}
|
||||||
|
err := col.Find(ctx, query).One(&userIdMap)
|
||||||
|
return userIdMap, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetAccountListByMid(ctx context.Context, mid int64) (*dbstruct.Account, error) {
|
||||||
|
col := m.getColAccount()
|
||||||
|
account := &dbstruct.Account{}
|
||||||
|
|
||||||
|
query := qmgo.M{
|
||||||
|
"_id": mid,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := col.Find(ctx, query).One(account)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return account, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetAccountList(ctx context.Context) ([]*dbstruct.Account, error) {
|
||||||
|
col := m.getColAccount()
|
||||||
|
list := make([]*dbstruct.Account, 0)
|
||||||
|
|
||||||
|
query := qmgo.M{}
|
||||||
|
|
||||||
|
err := col.Find(ctx, query).All(&list)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetAccountListByMids(ctx context.Context, mids []int64) ([]*dbstruct.Account, error) {
|
||||||
|
col := m.getColAccount()
|
||||||
|
list := make([]*dbstruct.Account, 0)
|
||||||
|
|
||||||
|
query := qmgo.M{
|
||||||
|
"_id": qmgo.M{
|
||||||
|
"$in": mids,
|
||||||
|
},
|
||||||
|
"del_flag": 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := col.Find(ctx, query).All(&list)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) UpdateAccount(ctx context.Context, account *dbstruct.Account) error {
|
||||||
|
col := m.getColAccount()
|
||||||
|
set := qmgo.M{
|
||||||
|
"user_id_string": *account.UserIdString,
|
||||||
|
}
|
||||||
|
set["ut"] = time.Now().Unix()
|
||||||
|
up := qmgo.M{
|
||||||
|
"$set": set,
|
||||||
|
}
|
||||||
|
err := col.UpdateId(ctx, *account.Mid, up)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetZoneListByMids(ctx context.Context, mids []int64) ([]*dbstruct.Zone, error) {
|
||||||
|
col := m.getColZone()
|
||||||
|
list := make([]*dbstruct.Zone, 0)
|
||||||
|
query := qmgo.M{
|
||||||
|
"del_flag": 0,
|
||||||
|
"mid": qmgo.M{
|
||||||
|
"$in": mids,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := col.Find(ctx, query).All(&list)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetZoneMomentCountByMid(ctx context.Context, mid int64) (int64, error) {
|
||||||
|
col := m.getColZoneMoment()
|
||||||
|
query := qmgo.M{
|
||||||
|
"mid": mid,
|
||||||
|
"del_flag": 0,
|
||||||
|
}
|
||||||
|
return col.Find(ctx, query).Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mongo) GetStreamerList(ctx context.Context, offset, limit int) ([]*dbstruct.Streamer, error) {
|
||||||
|
list := make([]*dbstruct.Streamer, 0)
|
||||||
|
col := m.getColStreamer()
|
||||||
|
|
||||||
|
query := qmgo.M{
|
||||||
|
"del_flag": 0,
|
||||||
|
}
|
||||||
|
err := col.Find(ctx, query).Sort("_id").Skip(int64(offset)).Limit(int64(limit)).All(&list)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
return list, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户增值信息
|
||||||
|
func (m *Mongo) GetUserVasInfoByMids(ctx context.Context, mids []int64) ([]*dbstruct.UserVasInfo, error) {
|
||||||
|
list := make([]*dbstruct.UserVasInfo, 0)
|
||||||
|
col := m.getColUserVasInfo()
|
||||||
|
query := qmgo.M{
|
||||||
|
"_id": qmgo.M{
|
||||||
|
"$in": mids,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := col.Find(ctx, query).All(&list)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return list, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 空间价格信息
|
||||||
|
func (m *Mongo) GetZoneVasByIds(ctx context.Context, zids []int64) ([]*dbstruct.ZoneVas, error) {
|
||||||
|
list := make([]*dbstruct.ZoneVas, 0)
|
||||||
|
col := m.getColZoneVas()
|
||||||
|
query := qmgo.M{
|
||||||
|
"_id": qmgo.M{
|
||||||
|
"$in": zids,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := col.Find(ctx, query).All(&list)
|
||||||
|
if err == qmgo.ErrNoSuchDocuments {
|
||||||
|
err = nil
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return list, nil
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
type eface struct {
|
||||||
|
v int64
|
||||||
|
ptr unsafe.Pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultBool bool = false
|
||||||
|
DefaultString string = ""
|
||||||
|
DefaultInt int = 0
|
||||||
|
DefaultInt32 int32 = 0
|
||||||
|
DefaultInt64 int64 = 0
|
||||||
|
DefaultFloat32 float32 = 0
|
||||||
|
DefaultFloat64 float64 = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
func DerefBool(p *bool) bool {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultBool
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefString(p *string) string {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultString
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefInt(p *int) int {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultInt
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefInt32(p *int32) int32 {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultInt32
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefInt64(p *int64) int64 {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultInt64
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefFloat32(p *float32) float32 {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultFloat32
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefFloat64(p *float64) float64 {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return DefaultFloat64
|
||||||
|
}
|
||||||
|
|
||||||
|
func Int64Slice(v []int64) *[]int64 {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefInt64Slice(p *[]int64) []int64 {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return make([]int64, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DerefStringSlice(p *[]string) []string {
|
||||||
|
if p != nil {
|
||||||
|
return *p
|
||||||
|
}
|
||||||
|
return make([]string, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断转为any的指针是否为空指针
|
||||||
|
func IsElemNil(elem any) bool {
|
||||||
|
efaceptr := (*eface)(unsafe.Pointer(&elem))
|
||||||
|
if efaceptr == nil || uintptr(efaceptr.ptr) == 0x0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断转为any的切片是否为空切片
|
||||||
|
func IsSliceNil(elem any) bool {
|
||||||
|
efaceptr := (*eface)(unsafe.Pointer(&elem))
|
||||||
|
if efaceptr == nil || uintptr(efaceptr.ptr) == 0x0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var sliceInfo = *(*[3]int)(efaceptr.ptr)
|
||||||
|
|
||||||
|
return sliceInfo[1] == 0
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 获取0点时间戳
|
||||||
|
func GetDayStartTimeStamp(t time.Time) int64 {
|
||||||
|
loc, err := time.LoadLocation("Asia/Shanghai")
|
||||||
|
if err != nil {
|
||||||
|
loc = time.FixedZone("CST", 8*3600)
|
||||||
|
}
|
||||||
|
timeStr := fmt.Sprintf("%02d-%02d-%02d 00:00:00", t.Year(), t.Month(), t.Day())
|
||||||
|
duetimecst, err := time.ParseInLocation("2006-1-2 15:04:05", timeStr, loc)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("parse error : %v\n", err)
|
||||||
|
}
|
||||||
|
return duetimecst.Unix()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RoundUp(num float64) int64 {
|
||||||
|
return int64(math.Ceil(num))
|
||||||
|
}
|
Loading…
Reference in New Issue