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
+330
View File
@@ -0,0 +1,330 @@
package walletser
import (
"91porn-server/common/constant/redisconst"
"encoding/json"
"fmt"
"strconv"
"sync"
"time"
"91porn-server/app/appg"
"91porn-server/common"
"91porn-server/common/log"
"91porn-server/common/timeutil"
"91porn-server/models/commod"
"91porn-server/models/v/proxymod"
"91porn-server/models/v/txnmod"
"91porn-server/models/v/usermod"
"91porn-server/models/v/walletmod"
"github.com/shopspring/decimal"
)
// UserInviteAmountInfo 用户账户信息
type UserInviteAmountInfo struct {
TotalAmount string `json:"totalAmount" bson:"totalAmount"` // 可提现收益
TotalIncomeAmount string `json:"totalIncomeAmount" bson:"totalIncomeAmount"` // 累计收益总额
TotalPayUserCount string `json:"totalPayUserCount" bson:"totalPayUserCount"` // 累计付费用户
TotalInviteUserCount string `json:"totalInviteUserCount" bson:"totalInviteUserCount"` // 累计推广用户
TodayInviteUserCount string `json:"todayInviteUserCount" bson:"todayInviteUserCount"` // 今日推广用户
MonthInviteUserCount string `json:"monthInviteUserCount" bson:"monthInviteUserCount"` // 当月推广用户
TodayIncomeAmount string `json:"todayIncomeAmount" bson:"todayIncomeAmount"` // 今日推广收益金币
MonthIncomeAmount string `json:"monthIncomeAmount" bson:"monthIncomeAmount"` // 当月推广收益金币
}
type VideoIncomeListRes struct {
TotalVideoAmount string `json:"totalVideoAmount"`
TodayTodayAmount string `json:"todayTodayAmount"`
YesterdayAmount string `json:"yesterdayAmount"`
MounthAmount string `json:"mounthAmount"`
HasNext bool `json:"hasNext"`
List []VideoIncomeInfo `json:"list"`
}
type VideoIncomeInfo struct {
Title string `json:"Title"` // 金币
IncomeAmount string `json:"incomeAmount"` // 收入金币
IncomeType int `json:"incomeType"` // 收入类型
IncomeTime time.Time `json:"incomeTime"` // 时间
}
func GetUserAmount(uid uint64) (resp *UserInviteAmountInfo, err error) {
data := UserInviteAmountInfo{}
str, err := appg.Redis.Get(redisconst.InviteCacheKey(uid))
if err != nil {
return
}
if str != nil {
if err = json.Unmarshal([]byte(*str), &data); err == nil {
return &data, nil
}
log.Warn(fmt.Sprintf("用户ID:%d;解析缓存数据异常:%v", uid, err))
}
var (
income string
todayInviteAmount float64
monthInviteAmount float64
proxyTotalIncome float64
monthInviteUserCount int64
toadyInviteUserCount int64
totalInviteUserCount int64
totalPayUserCount int64
)
nowTime := time.Now()
startD, endD := timeutil.EarlyLastDay(nowTime)
monthStartTime, _ := timeutil.EarlyLastMonth(nowTime)
var wg sync.WaitGroup
wg.Add(7)
common.Go(func() {
defer wg.Done()
w, _ := walletmod.GetWallet(uid)
if w == nil {
return
}
income = (decimal.NewFromInt(w.Income).Add(decimal.NewFromFloat(w.IncomePot))).Div(decimal.NewFromInt(10)).String()
//vidTotalIncome = w.VidIncome
proxyTotalIncome = w.ProxyIncome
})
common.Go(func() {
defer wg.Done()
totalInviteUserCount, err = proxymod.CountByUID(uid)
if err != nil {
return
}
})
common.Go(func() {
defer wg.Done()
totalPayUserCount, err = proxymod.CountPayUserByUID(uid)
if err != nil {
return
}
})
common.Go(func() {
defer wg.Done()
monthInviteUserCount, err = proxymod.CountByUIDAndTime(uid, monthStartTime)
if err != nil {
return
}
})
common.Go(func() {
defer wg.Done()
toadyInviteUserCount, err = proxymod.CountByUIDAndTime(uid, startD)
if err != nil {
return
}
})
common.Go(func() {
defer wg.Done()
// 今日成功推广金额
todayInviteAmount, _, _ = txnmod.GetIncomeByType(uid, txnmod.ProxyIncome, startD, endD)
})
common.Go(func() {
defer wg.Done()
// 当月成功推广金额
monthInviteAmount, _, _ = txnmod.GetIncomeByType(uid, txnmod.ProxyIncome, monthStartTime, endD)
})
wg.Wait()
data.TotalAmount = income
data.TotalIncomeAmount = strconv.FormatFloat(proxyTotalIncome/10, 'f', 2, 64)
data.TotalPayUserCount = strconv.FormatInt(totalPayUserCount, 10)
data.TotalInviteUserCount = strconv.FormatInt(totalInviteUserCount, 10)
data.TodayInviteUserCount = strconv.FormatInt(toadyInviteUserCount, 10)
data.MonthInviteUserCount = strconv.FormatInt(monthInviteUserCount, 10)
data.TodayIncomeAmount = strconv.FormatFloat(todayInviteAmount/10, 'f', 2, 64)
data.MonthIncomeAmount = strconv.FormatFloat(monthInviteAmount/10, 'f', 2, 64)
// 加入缓存
common.Go(func() {
dataInfo, err := json.Marshal(&data)
if err != nil {
log.Warn(fmt.Sprintf("用户ID:%d;json序列化缓存数据异常:%v", uid, err))
return
}
if err = appg.Redis.Set(redisconst.InviteCacheKey(uid), dataInfo, 2*time.Minute); err != nil {
log.Warn(fmt.Sprintf("用户ID:%d;保存缓存数据异常:%v", uid, err))
}
})
return &data, nil
}
func GetVideoIncomelist(uid, pageNumber, pageSize uint64) (resp VideoIncomeListRes, err error) {
var vidIncomeToday float64
var vidIncomeMonth float64
var vidTotalIncome float64
var vidYesterdayIncome float64
now := time.Now()
resp = VideoIncomeListRes{
List: make([]VideoIncomeInfo, 0),
}
startM, endM := timeutil.EarlyLastMonth(now)
startD, endD := timeutil.EarlyLastDay(now)
startY, endY := timeutil.YesterdayDay(now)
var wg sync.WaitGroup
wg.Add(5)
common.Go(func() { //1
defer wg.Done()
w, _ := walletmod.GetWallet(uid)
if w == nil {
return
}
vidTotalIncome = w.VidIncome
})
common.Go(func() { //2
defer wg.Done()
vidIncomeToday, _, _ = txnmod.GetIncomeByType(uid, txnmod.WorksIncome, startD, endD)
})
common.Go(func() { //3
defer wg.Done()
vidIncomeMonth, _, _ = txnmod.GetIncomeByType(uid, txnmod.WorksIncome, startM, endM)
})
common.Go(func() { //4
defer wg.Done()
vidYesterdayIncome, _, _ = txnmod.GetIncomeByType(uid, txnmod.WorksIncome, startY, endY)
})
common.Go(func() { //5
defer wg.Done()
videoList, hasNext, _ := txnmod.WorksIncomebills(uid, pageNumber, pageSize)
resp.HasNext = hasNext
for _, videotran := range videoList {
tmp := VideoIncomeInfo{
Title: videotran.Desc,
IncomeAmount: strconv.FormatFloat(videotran.ActualAmount, 'f', 2, 64),
IncomeTime: videotran.CreatedAt,
}
resp.List = append(resp.List, tmp)
}
})
wg.Wait()
resp.TotalVideoAmount = strconv.FormatFloat(vidTotalIncome, 'f', 2, 64)
resp.TodayTodayAmount = strconv.FormatFloat(vidIncomeToday, 'f', 2, 64)
resp.YesterdayAmount = strconv.FormatFloat(vidYesterdayIncome, 'f', 2, 64)
resp.MounthAmount = strconv.FormatFloat(vidIncomeMonth, 'f', 2, 64)
return resp, nil
}
type UserInviteIncomeListRes struct {
//总邀请数
TotalInvites int64 `json:"totalInvites"`
//今日邀请
TodayInvites int64 `json:"todayInvites"`
//总邀请充值
TotalInviteAmount float64 `json:"totalInviteAmount"`
//今日充值
TodayInviteAmount float64 `json:"todayInviteAmount"`
//列表总数
Total int64 `json:"total"`
//是否还有下一页
HasNext bool `json:"hasNext"`
//列表
List []UserInviteIncomeInfo `json:"list"`
}
type UserInviteIncomeInfo struct {
// 充值用户
UserName string `json:"userName"`
// 收入金币
IncomeAmount float64 `json:"incomeAmount" bson:"incomeAmount"`
// 充值时间
RechargeAt time.Time `json:"rechargeAt"`
}
func GetInviteIncomelist(uid, pageNumber, pageSize uint64) (resp UserInviteIncomeListRes, err error) {
//分页查询收益详情
txnList, hasNext, _ := txnmod.BuyProductLogWithPage(uid, txnmod.ProxyIncome, commod.Page{
PageNumber: pageNumber,
PageSize: pageSize,
})
resp.HasNext = hasNext
txnListLen := len(txnList)
uids := make([]uint64, txnListLen)
for i, tran := range txnList {
uids[i] = tran.RechargeId
}
resList := make([]UserInviteIncomeInfo, 0)
if len(uids) > 0 {
//批量查询用户信息
m, uErr := usermod.FindUsersMapByUID(uids)
if uErr == nil && len(m) > 0 {
resList = make([]UserInviteIncomeInfo, txnListLen)
for i, tran := range txnList {
tmp := UserInviteIncomeInfo{
IncomeAmount: tran.ActualAmount / 10,
RechargeAt: tran.CreatedAt,
}
if m[tran.RechargeId] != nil {
tmp.UserName = m[tran.RechargeId].Name
}
resList[i] = tmp
}
}
}
//从缓存获取其他数据
redisKey := "Get-Invite-Income-" + strconv.FormatUint(uid, 10)
str, err := appg.Redis.Get(redisKey)
if err != nil { // redis 错误不向上报告
log.Error("GetInviteIncomelist redisc.Get", log.Any("uid", uid), log.Any("redisKey", redisKey), log.E(err))
}
if str != nil {
if err = json.Unmarshal([]byte(*str), &resp); err == nil {
resp.List = resList
resp.HasNext = hasNext
return resp, nil
}
// json.Unmarshal的错误不向上报告,而是尝试去DB获取数据
log.Error("GetInviteIncomelist json.Unmarshal", log.Any("uid", uid), log.Any("redisKey", redisKey), log.E(err))
}
resp.List = resList
resp.HasNext = hasNext
now := time.Now()
resp = UserInviteIncomeListRes{
List: make([]UserInviteIncomeInfo, 0),
}
startD, endD := timeutil.EarlyLastDay(now)
var wg sync.WaitGroup
wg.Add(4)
common.Go(func() { //1
defer wg.Done()
w, _ := walletmod.GetWallet(uid)
if w == nil {
return
}
resp.TotalInviteAmount = w.ProxyIncome / 10
})
common.Go(func() { //2
defer wg.Done()
//成功推广数
resp.TotalInvites, _ = proxymod.CountByUID(uid)
//成功推广数 = 总数
resp.Total = resp.TotalInvites
})
common.Go(func() { //3
defer wg.Done()
//今日成功推广数
resp.TodayInvites, _ = proxymod.CountByUIDAndTime(uid, startD)
})
common.Go(func() { //4
defer wg.Done()
//今日成功推广金额
resp.TodayInviteAmount, _, _ = txnmod.GetIncomeByType(uid, txnmod.ProxyIncome, startD, endD)
resp.TodayInviteAmount = resp.TodayInviteAmount / 10
})
wg.Wait()
common.Go(func() {
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Error("GetInviteIncomelist json.Marshal", log.Any("uid", uid), log.E(err))
return
}
if err := appg.Redis.Set(redisKey, string(jsonBytes), 15*time.Minute); err != nil {
log.Error("GetInviteIncomelist redisc.Set", log.Any("uid", uid), log.Any("redisKey", redisKey), log.E(err))
}
})
return resp, nil
}
+146
View File
@@ -0,0 +1,146 @@
package walletser
import (
"91porn-server/app/appg"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/stderr"
"91porn-server/models/v/txnmod"
"91porn-server/models/v/walletmod"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func debitPlan(w *walletmod.Wallet, amt int64) *walletmod.DebitPlan {
p := walletmod.DebitPlan{}
l1 := w.Amount - amt
if l1 >= 0 { //amount够了
p.Amount = amt
return &p
} else { // l1 < 0
//amount 扣完
l2 := w.Income + l1
if l2 >= 0 {
p.Amount = w.Amount
p.Income = -l1
return &p
} else {
return nil //余额不足
}
}
}
const (
StoreBuyGoods = 1
StoreBuyNudeChat = 2
StorePublishWish = 3
StoreGoodsOrderRefund = 4
StoreNudeChatOrderRefund = 5
StoreWishRefund = 6
StoreWishEdit = 7
)
// StoreDeductBalance 商城相关扣款
func StoreDeductBalance(uid uint64, amount int64, orderId primitive.ObjectID, source int, desc string) (balance int64, code stderr.Code) {
w, err := walletmod.GetWallet(uid)
if err != nil || w == nil {
return 0, stderr.ErrNetWorkBusy
}
plan := debitPlan(w, amount)
if plan == nil {
return 0, stderr.InsufficientBalance
}
var tranType txnmod.TransType
switch source {
case StoreBuyGoods:
tranType = txnmod.StoreBuyGoods
case StoreBuyNudeChat:
tranType = txnmod.StoreBuyNudeChat
case StorePublishWish:
tranType = txnmod.StorePublishWish
case StoreWishEdit:
tranType = txnmod.StoreWishEdit
default:
return 0, stderr.ErrParamError
}
err = appg.VideoDB.Trans(func(t *db.MongoTool) (err error) {
wallet, err := walletmod.Debit(t, plan, uid)
if err != nil {
log.Error("StoreDeductBalance walletmod.Debit fail", log.Any("uid", uid), log.Any("orderId", orderId), log.Any("amount", amount), log.Any("source", source))
return
}
// 写入流水
txnLog := &txnmod.TransactionLog{UID: uid,
Amount: -amount,
ActualAmount: float64(-amount),
TranType: tranType.Key(),
TranTypeInt: int64(tranType),
TransNo: orderId,
Desc: desc,
//DiscDoc: discDoc,
//SysType: u.SysType,
RealAmount: walletmod.GetRealAmount(wallet),
}
err = txnmod.InsertTransactionLog(t, txnLog)
if err != nil {
log.Error("StoreDeductBalance txnmod.InsertTransactionLog fail", log.Any("uid", uid), log.Any("orderId", orderId), log.Any("amount", amount), log.Any("source", source))
return
}
balance = wallet.Amount + wallet.Income
return nil
})
if err != nil {
log.Error("StoreDeductBalance fail", log.Any("uid", uid), log.Any("orderId", orderId), log.Any("amount", amount), log.Any("source", source))
return 0, stderr.Failure //通知消息
}
return balance, stderr.Success
}
// StoreRefund 商城相关退款
func StoreRefund(uid uint64, amount int64, orderId primitive.ObjectID, source int, desc string) (balance int64, code stderr.Code) {
w, err := walletmod.GetWallet(uid)
if err != nil || w == nil {
return 0, stderr.ErrNetWorkBusy
}
var tranType txnmod.TransType
switch source {
case StoreGoodsOrderRefund:
tranType = txnmod.StoreGoodsOrderRefund
case StoreNudeChatOrderRefund:
tranType = txnmod.StoreNudeChatOrderRefund
case StoreWishRefund:
tranType = txnmod.StoreWishRefund
default:
return 0, stderr.ErrParamError
}
err = appg.VideoDB.Trans(func(t *db.MongoTool) (err error) {
wallet, err := walletmod.CreditAmount(t, amount, uid)
if err != nil {
log.Error("StoreRefund walletmod.CreditAmount fail", log.Any("uid", uid), log.Any("orderId", orderId), log.Any("amount", amount), log.Any("source", source))
return
}
// 写入流水
txnLog := &txnmod.TransactionLog{UID: uid,
Amount: amount,
ActualAmount: float64(amount),
TranType: tranType.Key(),
TranTypeInt: int64(tranType),
TransNo: orderId,
Desc: desc,
//DiscDoc: discDoc,
//SysType: u.SysType,
RealAmount: walletmod.GetRealAmount(wallet),
}
err = txnmod.InsertTransactionLog(t, txnLog)
if err != nil {
log.Error("StoreRefund txnmod.InsertTransactionLog fail", log.Any("uid", uid), log.Any("orderId", orderId), log.Any("amount", amount), log.Any("source", source))
return
}
balance = wallet.Amount + wallet.Income
return nil
})
if err != nil {
log.Error("StoreRefund fail", log.Any("uid", uid), log.Any("orderId", orderId), log.Any("amount", amount), log.Any("source", source))
return 0, stderr.Failure //通知消息
}
return balance, stderr.Success
}
+30
View File
@@ -0,0 +1,30 @@
package walletser
import (
"91porn-server/models/commod"
"91porn-server/models/v/txnmod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
)
type FruitCoinBillCond struct {
commod.Page
}
func (cond *FruitCoinBillCond) Query(uid uint64) primitive.M {
return bson.M{
"uid": uid,
"tranTypeInt": bson.M{"$in": []txnmod.TransType{
txnmod.BuyNudeChatService, txnmod.FruitCoinRecharge, txnmod.NudeChatConsumption, txnmod.NudeChatRefund,
txnmod.FruitCoinRecharge, txnmod.CurrencyGive, txnmod.AdminCreditFruitCoin, txnmod.AdminDebitFruitCoin,
txnmod.VipCardGive, txnmod.OfficialRech,
}},
"fruitCoin": bson.M{"$ne": 0, "$exists": true},
}
}
func (cond *FruitCoinBillCond) Options() *options.FindOptions {
return options.Find().SetLimit(int64(cond.PageSize)).SetSkip(int64((cond.PageNumber - 1) * cond.PageSize)).
SetSort(bson.D{{Key: "createdAt", Value: -1}})
}
+317
View File
@@ -0,0 +1,317 @@
package walletser
import (
"fmt"
"strconv"
"sync"
"time"
"91porn-server/common"
"91porn-server/common/log"
"91porn-server/common/stderr"
"91porn-server/common/timeutil"
"91porn-server/models/v/proxymod"
"91porn-server/models/v/txnmod"
"91porn-server/models/v/usermod"
"91porn-server/models/v/walletmod"
"github.com/shopspring/decimal"
)
func GetBills(uid uint64, t int64) (data []txnmod.BillsRes, hasNext bool, timeline int64, err error) {
data = make([]txnmod.BillsRes, 0)
if t == 0 {
trans, queryErr := txnmod.LastLedgerTime(uid, time.Now())
if queryErr != nil {
return nil, false, 0, queryErr
}
if trans.ID.IsZero() {
return
}
t = trans.CreatedAt.Unix()
}
start, end := timeutil.EarlyLastMonth(time.Unix(t, 0))
var navErr error
var wg sync.WaitGroup
wg.Add(2)
common.Go(func() {
defer wg.Done()
br := txnmod.BillsRes{
Month: start.Format("2006-01"),
}
br.List, err = txnmod.FindLedgerByTime(uid, start, end)
if err != nil {
return
}
if len(br.List) > 0 {
for _, v := range br.List {
switch v.TranTypeInt {
case int64(txnmod.WithdrawTransfer):
br.Withdraw += -v.Amount
br.WithdrawStr = strconv.Itoa(int(br.Withdraw))
if br.WithdrawStr == "" {
br.WithdrawStr = "0"
}
case int64(txnmod.WorksIncome), int64(txnmod.ProxyIncome):
br.Income += v.Amount
if br.IncomeStr == "" {
br.IncomeStr = "0"
}
incomeDeci, _ := decimal.NewFromString(br.IncomeStr)
actualIncomeDeci := decimal.NewFromFloat(v.ActualAmount)
br.IncomeStr = incomeDeci.Add(actualIncomeDeci).String()
}
}
}
if len(br.List) > 0 {
data = append(data, br)
}
})
common.Go(func() {
defer wg.Done()
trans, queryErr := txnmod.LastLedgerTime(uid, start)
if queryErr != nil {
navErr = queryErr
return
}
if !trans.ID.IsZero() {
timeline = trans.CreatedAt.Unix()
hasNext = true
}
})
wg.Wait()
if err == nil {
err = navErr
}
return
}
type rechargeLevel struct {
Min int
Max int
Level int
}
var rchgLevel = []rechargeLevel{
{Min: 0, Max: 4900, Level: 0},
{Min: 5000, Max: 9900, Level: 1},
{Min: 10000, Max: 19900, Level: 2},
{Min: 20000, Max: 29900, Level: 3},
{Min: 30000, Max: 49900, Level: 4},
{Min: 50000, Max: 99900, Level: 5},
{Min: 100000, Max: 199900, Level: 6},
{Min: 200000, Max: 499900, Level: 7},
{Min: 500000, Max: 1000000, Level: 8},
}
func calRchgLevel(amount int) (level int, cur int, limit int) {
l := len(rchgLevel)
if l == 0 {
return
}
min := rchgLevel[0].Min
max := rchgLevel[l-1].Max
if amount < min {
return rchgLevel[0].Level, 0, (rchgLevel[0].Max - rchgLevel[0].Min)
}
if amount > max {
return rchgLevel[l-1].Level, (rchgLevel[l-1].Max - rchgLevel[l-1].Min), (rchgLevel[l-1].Max - rchgLevel[l-1].Min)
}
for _, v := range rchgLevel {
if amount >= v.Min && amount <= v.Max {
return v.Level, (amount - v.Min), (v.Max - v.Min)
}
}
return
}
// GetRchgLevel 获取用户充值等级
func GetRchgLevel(uid uint64) (usermod.RechargeLevel, error) {
wallet, err := walletmod.GetWallet(uid)
if err != nil {
return usermod.RechargeLevel{}, err
}
level, cur, limit := calRchgLevel(int(wallet.Consumption))
info := usermod.RechargeLevel{
Level: level,
Current: cur / 10,
Limit: limit / 10,
}
return info, err
}
// GetUidsRchgLevel 获取用户充值等级
func GetUidsRchgLevel(uids []uint64) (map[uint64]usermod.RechargeLevel, error) {
mInfo := make(map[uint64]usermod.RechargeLevel)
mWallet, err := walletmod.GetWalletMap(uids)
if err != nil {
return mInfo, err
}
for _, v := range mWallet {
level, cur, limit := calRchgLevel(int(v.Consumption))
info := usermod.RechargeLevel{
Level: level,
Current: cur / 10,
Limit: limit / 10,
}
mInfo[v.UID] = info
}
return mInfo, err
}
func GetIncome(uid uint64) (interface{}, error) {
var income string
var vidIncomeToday float64
var vidIncomeMonth float64
var vidTotalIncome float64
var proxyIncomeToday float64
var proxyIncomeMonth float64
var InviteeTotalCount int64
var proxyTotalIncome float64
var proxyTotalPer int64
var InviteedTodayCount int64
var InviteedMonthCount int64
var proxyPerMonth int64
var proxyPerToday int64
var data []txnmod.AgentIncomeRes
now := time.Now()
startM, endM := timeutil.EarlyLastMonth(now)
startD, endD := timeutil.EarlyLastDay(now)
var wg sync.WaitGroup
wg.Add(8)
common.Go(func() { //1
defer wg.Done()
w, _ := walletmod.GetWallet(uid)
if w == nil {
return
}
income = decimal.NewFromInt(w.Income).Add(decimal.NewFromFloat(w.IncomePot)).String()
vidTotalIncome = w.VidIncome
proxyTotalIncome = w.ProxyIncome
proxyTotalPer = w.Performance
})
common.Go(func() { //2
defer wg.Done()
InviteeTotalCount, _ = proxymod.NextProxyCount(uid, time.Unix(0, 0), now)
})
common.Go(func() { //3
defer wg.Done()
InviteedMonthCount, _ = proxymod.NextProxyCount(uid, startM, endM)
})
common.Go(func() { //4
defer wg.Done()
InviteedTodayCount, _ = proxymod.NextProxyCount(uid, startD, endD)
})
common.Go(func() { //5
defer wg.Done()
vidIncomeToday, _, _ = txnmod.GetIncomeByType(uid, txnmod.WorksIncome, startD, endD)
})
common.Go(func() { //6
defer wg.Done()
vidIncomeMonth, _, _ = txnmod.GetIncomeByType(uid, txnmod.WorksIncome, startM, endM)
})
common.Go(func() { //7
defer wg.Done()
proxyIncomeMonth, proxyPerMonth, _ = txnmod.GetIncomeByType(uid, txnmod.ProxyIncome, startM, endM)
})
common.Go(func() { //8
defer wg.Done()
data, _ = txnmod.GetProxyIncomeForToday(uid, startD, endD)
})
wg.Wait()
m := make(map[string]interface{})
m["income"] = income
m["vidIncomeToday"] = strconv.FormatFloat(vidIncomeToday, 'f', 2, 64)
m["vidIncomeMonth"] = strconv.FormatFloat(vidIncomeMonth, 'f', 2, 64)
m["vidIncomeTotal"] = strconv.FormatFloat(vidTotalIncome, 'f', 2, 64)
m["proxyIncomeTotal"] = strconv.FormatFloat(proxyTotalIncome, 'f', 2, 64)
m["proxyPer"] = strconv.FormatInt(proxyTotalPer, 10)
m["inviteeCountTotal"] = strconv.FormatInt(InviteeTotalCount, 10)
m["proxyIncomeLv1"] = "0"
m["proxyIncomeLv2"] = "0"
m["proxyIncomeLv3"] = "0"
m["proxyIncomeLv4"] = "0"
m["proxyIncomeLv5"] = "0"
for _, v := range data {
proxyIncomeToday += v.TotalMoney
proxyPerToday += v.TotalPerformance
m["proxyIncomeLv"+strconv.Itoa(v.AgentLevel)] = strconv.FormatFloat(v.TotalMoney, 'f', 2, 64)
}
m["proxyPerMonth"] = strconv.FormatInt(proxyPerMonth, 10)
m["proxyIncomeMonth"] = strconv.FormatFloat(proxyIncomeMonth, 'f', 2, 64)
m["inviteeCountMonth"] = strconv.FormatInt(InviteedMonthCount, 10)
m["proxyPerToday"] = strconv.FormatInt(proxyPerToday, 10)
m["proxyIncomeToday"] = strconv.FormatFloat(proxyIncomeToday, 'f', 2, 64)
m["inviteeCountToday"] = strconv.FormatInt(InviteedTodayCount, 10)
return m, nil
}
func GetBills1(uid uint64, year int, month int, pageNumber, pageSize uint64) (res txnmod.Bills1Res, err error) {
start, end := timeutil.GetTimeByMonthAndYear(month, year)
if pageNumber > 1 {
res.List, res.HasNext, err = txnmod.Ibills(uid, pageNumber, pageSize, start, end)
return
}
var incomeErr, expenditureErr, listErr, navigationErr error
var wg sync.WaitGroup
wg.Add(4)
common.Go(func() { //1
defer wg.Done()
i, queryErr := txnmod.Income(uid, start, end)
incomeErr = queryErr
res.Income = strconv.FormatFloat(i, 'f', 2, 64)
})
common.Go(func() { //2
defer wg.Done()
e, queryErr := txnmod.Expenditure(uid, start, end)
expenditureErr = queryErr
res.Expenditure = strconv.FormatFloat(e, 'f', 2, 64)
})
common.Go(func() { //3
defer wg.Done()
start, end := timeutil.GetTimeByMonthAndYear(month, year)
res.List, res.HasNext, listErr = txnmod.Ibills(uid, pageNumber, pageSize, start, end)
})
common.Go(func() { //4
defer wg.Done()
t, queryErr := txnmod.LastLedgerTime(uid, start)
navigationErr = queryErr
if !t.ID.IsZero() {
res.HasNextMonth = true
res.Year = t.CreatedAt.Year()
res.Month = int(t.CreatedAt.Month())
}
})
wg.Wait()
for _, queryErr := range []error{incomeErr, expenditureErr, listErr, navigationErr} {
if queryErr != nil {
return txnmod.Bills1Res{}, queryErr
}
}
if len(res.List) > 0 {
for i, tlog := range res.List {
if tlog.TranTypeInt == int64(txnmod.GoldCouplePayVID) {
res.List[i].ActualAmount = 0
res.List[i].Amount = 0
}
}
}
return
}
// FruitCoinBill 果币账单
func FruitCoinBill(uid uint64, in *FruitCoinBillCond) (interface{}, stderr.Code) {
var data = map[string]interface{}{
"list": []interface{}{},
}
list, err := txnmod.QueryAll(in.Query(uid), in.Options())
if err != nil {
log.Error(fmt.Sprintf("查询果币账单列表异常[%v]", err))
return data, stderr.ErrDbQueryError
}
data["list"] = list
return data, stderr.Success
}