Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+373
View File
@@ -0,0 +1,373 @@
package statcenterctl
import (
"net/http"
"strconv"
"time"
"91porn-server/app/proto"
"91porn-server/common/log"
"91porn-server/models/l/visitlogmod"
"91porn-server/models/v/proxymod"
"91porn-server/models/v/rchgordmod"
"91porn-server/models/v/usermod"
"github.com/gin-gonic/gin"
)
// SyncAllRouterList 返回所有同步接口路由
func SyncAllRouterList(ctx *gin.Context) {
//返回实体
var resp = gin.H{
"code": 200,
"msg": "ok",
"data": gin.H{
"syncNewUser": "/services/user/newUser",
"syncUserAccess": "/services/user/userAccess",
"syncInviteRecord": "/services/user/inviteRecord",
"syncNewOrder": "/services/order/newOrder",
"syncFinishOrder": "/services/order/finishOrder",
},
}
ctx.JSON(http.StatusOK, resp)
}
// NewUserAccessList 新日活数据同步
func NewUserAccessList(ctx *gin.Context) {
//返回实体
var resp struct {
Code int `json:"code"` // 200正常 其他异常
Msg string `json:"msg"` // 错误消息
Data []proto.NewUserAccessMsg `json:"data"` // 数据
proto.AdsInfo
}
resp.Code = 200
resp.Msg = "ok"
//请求实体
var request struct {
EndTime int64 `form:"updated_at" json:"updated_at"` // 时间戳
MaxSize int64 `form:"max" json:"max" binding:"required"` // 最大条数
}
if err := ctx.ShouldBind(&request); err != nil {
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
t := time.Unix(request.EndTime, 0)
//查询
visitList, err := visitlogmod.AccessSyncByTime(t, request.MaxSize)
if err != nil {
log.Error("NewUserAccessList AccessSyncById ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
//用户id
visitListLen := len(visitList)
uidIds := make([]uint64, visitListLen)
accessList := make([]proto.NewUserAccessMsg, visitListLen)
for i, userInfo := range visitList {
accessList[i] = proto.NewUserAccessMsg{
UserId: userInfo.UID,
DeviceId: userInfo.DevID,
Platform: userInfo.SysType,
Coin: 0,
IsVip: 0,
InviteUserId: 0,
LastOnlineTime: userInfo.CreatedAt.Unix(),
}
uidIds[i] = userInfo.UID
}
if len(uidIds) > 0 {
//查询用户上级信息
invitationMap, err := proxymod.GetInvrLv1Map(uidIds)
if err != nil {
log.Error("NewUserAccessList proxymod.GetInvrLv1Map err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
//查询用户信息
usersMap, err := usermod.UserMap(uidIds)
if err != nil {
log.Error("NewUserRegisterList usermod.UserMap err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
for index, r := range accessList {
//上级id
if invitationMap != nil {
fUid := invitationMap[r.UserId]
if fUid > 0 {
accessList[index].InviteUserId = fUid
}
}
//用户信息
if usersMap != nil {
user := usersMap[r.UserId]
if user.UID > 0 {
accessList[index].RegistTime = user.CreatedAt.Unix()
accessList[index].RegisterIp = user.RegisterIP
accessList[index].ChannelCode = user.DistrictCode
if user.VipExpireDate.After(time.Now()) {
accessList[index].IsVip = 1
}
}
}
}
}
resp.Data = accessList
ctx.JSON(http.StatusOK, resp)
}
// NewUserRegisterList 新注册数据同步
func NewUserRegisterList(ctx *gin.Context) {
//返回实体
var resp struct {
Code int `json:"code"` // 200正常 其他异常
Msg string `json:"msg"` // 错误消息
Data []proto.NewUserRegisterMsg `json:"data"` // 数据
}
resp.Code = 200
resp.Msg = "ok"
//请求实体
var request struct {
UserId uint64 `form:"id" json:"id"` // 用户ID
MaxSize int64 `form:"max" json:"max" binding:"required"` // 最大条数
}
if err := ctx.ShouldBind(&request); err != nil {
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
//查询
userList, err := usermod.StatcenterSyncList(request.UserId, request.MaxSize)
if err != nil {
log.Error("NewUserRegisterList usermod.StatcenterSyncList err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
//用户id
userListLen := len(userList)
uidIds := make([]uint64, userListLen)
registerList := make([]proto.NewUserRegisterMsg, userListLen)
for i, userInfo := range userList {
registerInfo := proto.NewUserRegisterMsg{
UserId: userInfo.UID,
DeviceId: userInfo.DevID,
Platform: userInfo.SysType,
Coin: 0,
IsVip: 0,
InviteUserId: 0,
RegistTime: userInfo.CreatedAt.Unix(),
RegisterIp: userInfo.RegisterIP,
ChannelCode: userInfo.DistrictCode,
LastOnlineTime: userInfo.LastVisitAt.Unix(),
}
if userInfo.VipExpireDate.After(time.Now()) {
registerInfo.IsVip = 1
}
registerList[i] = registerInfo
uidIds[i] = userInfo.UID
}
if len(uidIds) > 0 {
//查询用户上级信息
invitationMap, err := proxymod.GetInvrLv1Map(uidIds)
if err != nil {
log.Error("NewUserRegisterList proxymod.GetInvrLv1Map err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
if invitationMap != nil {
for index, r := range registerList {
//上级id
fUid := invitationMap[r.UserId]
if fUid > 0 {
registerList[index].InviteUserId = fUid
}
}
}
}
resp.Data = registerList
ctx.JSON(http.StatusOK, resp)
}
// NewUserInviterList 新推广数据同步
func NewUserInviterList(ctx *gin.Context) {
//返回实体
var resp struct {
Code int `json:"code"` // 200正常 其他异常
Msg string `json:"msg"` // 错误消息
Data []interface{} `json:"data"` // 数据
}
resp.Code = 200
resp.Msg = "ok"
//请求实体
var request struct {
Id string `form:"id" json:"id" binding:"required"` // 记录id
MaxSize int64 `form:"max" json:"max" binding:"required"` // 最大条数
}
if err := ctx.ShouldBind(&request); err != nil {
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
//查询
data, err := proxymod.NewStatCenterSyncInviteList(request.Id, request.MaxSize)
if err != nil {
log.Error("NewUserInviterList proxymod.StatCenterSyncInviteList err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
res := make([]interface{}, len(data))
for i, v := range data {
res[i] = proto.NewUserInviteMsg{
Id: v.ID.Hex(),
UserId: v.Invitee,
InviteUserId: v.UID,
}
}
resp.Data = res
ctx.JSON(http.StatusOK, resp)
}
// NewUserRechargeList 新充值数据同步
func NewUserRechargeList(ctx *gin.Context) {
//返回实体
var resp struct {
Code int `json:"code"` // 200正常 其他异常
Msg string `json:"msg"` // 错误消息
Data []proto.NewUserRechargeMsg `json:"data"` // 数据
}
resp.Code = 200
resp.Msg = "ok"
//请求实体
var request struct {
Id string `form:"id" json:"id" binding:"required"` // 记录id
MaxSize int64 `form:"max" json:"max" binding:"required"` // 最大条数
}
if err := ctx.ShouldBind(&request); err != nil {
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
//查询
rechargeOrders, err := rchgordmod.NewStatCenterSyncRecharge(request.Id, request.MaxSize)
if err != nil {
log.Error("NewUserRechargeList rchgordmod.NewStatCenterSyncRecharge err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
data := make([]proto.NewUserRechargeMsg, len(rechargeOrders))
for i, v := range rechargeOrders {
temp := proto.NewUserRechargeMsg{
Id: v.ID.Hex(),
OID: v.OID,
OrderId: v.ID.Hex(),
UserId: v.UID,
Money: v.Money,
Channel: v.Channel,
RechargeType: v.RechargeType,
OrderType: "vip",
OrderTime: v.CreatedAt.Unix(),
PayTime: v.SuccessAt.Unix(),
PayAmount: v.PayMoney,
IsPaid: 0,
Poundage: 0,
ProductType: v.ProductType,
}
if temp.OID == "" {
temp.OID = strconv.FormatInt(int64(temp.UserId), 10) + temp.OID
}
//是否vip
if v.Category == 0 {
temp.OrderType = "coin"
}
if v.Status == 3 {
temp.IsPaid = 1
} else {
temp.PayTime = 0
}
data[i] = temp
}
resp.Data = data
ctx.JSON(http.StatusOK, resp)
}
// NewUserPaidRechargeList 新充值数据同步,已完成
func NewUserPaidRechargeList(ctx *gin.Context) {
//返回实体
var resp struct {
Code int `json:"code"` // 200正常 其他异常
Msg string `json:"msg"` // 错误消息
Data []proto.NewUserRechargeMsg `json:"data"` // 数据
}
resp.Code = 200
resp.Msg = "ok"
//请求实体
var request struct {
SuccessAt int64 `form:"success_at" json:"success_at"` // 完成时间
MaxSize int64 `form:"max" json:"max" binding:"required"` // 最大条数
}
if err := ctx.ShouldBind(&request); err != nil {
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
t := time.Unix(request.SuccessAt, 0)
//查询
rechargeOrders, err := rchgordmod.StatCenterSyncRecharge(t, request.MaxSize)
if err != nil {
log.Error("NewUserRechargeList rchgordmod.StatCenterSyncRecharge err ", log.E(err))
resp.Code = 400
resp.Msg = err.Error()
ctx.JSON(http.StatusOK, resp)
return
}
data := make([]proto.NewUserRechargeMsg, len(rechargeOrders))
for i, v := range rechargeOrders {
temp := proto.NewUserRechargeMsg{
Id: v.ID.Hex(),
OID: v.OID,
OrderId: v.ID.Hex(),
UserId: v.UID,
Money: v.Money,
Channel: v.Channel,
RechargeType: v.RechargeType,
OrderType: "vip",
OrderTime: v.CreatedAt.Unix(),
PayTime: v.SuccessAt.Unix(),
PayAmount: v.PayMoney,
IsPaid: 1,
Poundage: 0,
ProductType: v.ProductType,
}
if temp.OID == "" {
temp.OID = strconv.FormatInt(int64(temp.UserId), 10) + temp.OID
}
//是否vip
if v.Category == 0 {
temp.OrderType = "coin"
}
data[i] = temp
}
resp.Data = data
ctx.JSON(http.StatusOK, resp)
}