diff --git a/internal/api/mobile/users/my_info.go b/internal/api/mobile/users/my_info.go index 51e5629..a7a5db8 100644 --- a/internal/api/mobile/users/my_info.go +++ b/internal/api/mobile/users/my_info.go @@ -48,6 +48,7 @@ type MyInfoResp struct { End *time.Time `json:"end"` Deposit decimal.Decimal `json:"deposit"` IsEnterprise bool `json:"is_enterprise"` + AllDeposit decimal.Decimal `json:"all_deposit"` } type Notify struct { @@ -132,6 +133,12 @@ func MyInfo(c *gin.Context) { var uWallet2 jyy.UserWallet dbc.DB.Where("user_id = ?", p.UserID).First(&uWallet2) + allDeposit := make([]decimal.Decimal, 0) + dbc.DB.Table((&jyy.UserWalletApply{}).TableName()).Select("IFNULL(SUM(amount), 0) as total"). + Where("user_id = ?", p.UserID). + Where("state = 2"). + Pluck("total", &allDeposit) + // 优惠券是 未使用和未过期的 var couponNum int dbc.DB.Model(&coupon.ReceiverMid{}).Where("user_id = ? and status = 0 and end_time > ?", p.UserID, time.Now()).Count(&couponNum) @@ -181,8 +188,9 @@ func MyInfo(c *gin.Context) { // 组装返回 var res = MyInfoResp{ - Balance: uWallet.Balance, - Deposit: uWallet2.Deposit, + Balance: uWallet.Balance, + Deposit: uWallet2.Deposit, + AllDeposit: allDeposit[0], Notify: Notify{ IsNotify: false, NotifyType: "up", // 暂时只有升级类型,估计以后会加需求,保级之类的预留 diff --git a/internal/v2/controller/app/jyy/jyy.go b/internal/v2/controller/app/jyy/jyy.go index 7a9b89f..6a162ab 100644 --- a/internal/v2/controller/app/jyy/jyy.go +++ b/internal/v2/controller/app/jyy/jyy.go @@ -212,3 +212,33 @@ func (o Proxy) CompanyDespoit(c *gin.Context) { back.Suc(c, "ok", "") } } + +func (o Proxy) DespoitInfo(c *gin.Context) { + var args jyy.DespoitInfo + if err := tools.ParseParams(&args, c); err != nil { + back.Fail(c, err.Error()) + return + } + id, _ := common.GetAppUserId(c) + args.UserID = int(id) + data, total := jyy.Logic.DespoitInfo(args) + back.Suc(c, "ok", bean.ResultLists{ + List: data, + Total: int(total), + }) +} + +func (o Proxy) RecordInfo(c *gin.Context) { + var args jyy.Record + if err := tools.ParseParams(&args, c); err != nil { + back.Fail(c, err.Error()) + return + } + id, _ := common.GetAppUserId(c) + args.UserID = int(id) + data, total := jyy.Logic.RecordInfo(args) + back.Suc(c, "ok", bean.ResultLists{ + List: data, + Total: int(total), + }) +} diff --git a/internal/v2/logic/app/jyy/wallet.go b/internal/v2/logic/app/jyy/wallet.go index 89f9df9..05953c0 100644 --- a/internal/v2/logic/app/jyy/wallet.go +++ b/internal/v2/logic/app/jyy/wallet.go @@ -1,11 +1,68 @@ package jyy -import "recook/internal/v2/model/jyy" +import ( + "recook/internal/libs/bean" + "recook/internal/v2/model/company" + "recook/internal/v2/model/jyy" + + "git.oa00.com/go/mysql" +) type Despoit struct { jyy.UserWalletApply } func (o logic) CompanyDespoit(args Despoit) error { - return nil + var company company.Info + mysql.Db.First(&company, "user_id = ?", args.UserID) + args.CompanyID = int(company.ID) + return mysql.Db.Create(&args).Error +} + +type Record struct { + bean.Page + Kind int `json:"kind"` + UserID int `json:"-"` + Start string `json:"start"` + End string `json:"end"` +} + +func (o logic) RecordInfo(args Record) (data []jyy.UserWalletRecord, total int64) { + query := mysql.Db.Table((&jyy.UserWalletRecord{}).TableName()).Where("user_id = ?", args.UserID) + { + if args.Kind != 0 { + query = query.Where("kind = ?", args.Kind) + } + if args.Start != "" { + query = query.Where("created_at > ?", args.Start) + } + if args.Start != "" { + query = query.Where("created_at < ?", args.End) + } + } + query.Count(&total) + query.Order("id desc").Offset(args.GetStart()).Limit(args.GetLimit()).Find(&data) + return +} + +type DespoitInfo struct { + bean.Page + UserID int `json:"-"` + Start string `json:"start"` + End string `json:"end"` +} + +func (o logic) DespoitInfo(args DespoitInfo) (data []Despoit, total int64) { + query := mysql.Db.Table((Despoit{}).TableName()).Where("user_id = ?", args.UserID) + { + if args.Start != "" { + query = query.Where("created_at > ?", args.Start) + } + if args.Start != "" { + query = query.Where("created_at < ?", args.End) + } + } + query.Count(&total) + query.Order("id desc").Offset(args.GetStart()).Limit(args.GetLimit()).Find(&data) + return } diff --git a/internal/v2/model/jyy/jyy.go b/internal/v2/model/jyy/jyy.go index 86c630c..44db134 100644 --- a/internal/v2/model/jyy/jyy.go +++ b/internal/v2/model/jyy/jyy.go @@ -4,6 +4,8 @@ import ( "recook/internal/v2/model/recook/goods" "time" + time2 "recook/internal/v2/lib/time" + "github.com/golangkit/formatime" "github.com/shopspring/decimal" "gorm.io/gorm" @@ -115,11 +117,11 @@ func (o AppUserMessage) TableName() string { } type UserWallet struct { - ID int `json:"id"` - Deposit decimal.Decimal `json:"deposit"` - UserID int `json:"user_id"` - CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"` - Version int `json:"version"` + ID int `json:"id"` + Deposit decimal.Decimal `json:"deposit"` + UserID int `json:"user_id"` + CreatedAt *time2.Timestamp `json:"created_at" gorm:"autoCreateTime"` + Version int `json:"version"` } func (o UserWallet) TableName() string { @@ -127,13 +129,13 @@ func (o UserWallet) TableName() string { } type UserWalletRecord struct { - ID int `json:"id"` - WalletID int `json:"wallet_id"` - UserID int `json:"user_id"` - Amount decimal.Decimal `json:"amount"` - CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"` - Current decimal.Decimal `json:"current"` - Kind int `json:"kind"` + ID int `json:"id"` + WalletID int `json:"-"` + UserID int `json:"-"` + Amount decimal.Decimal `json:"amount"` + CreatedAt *time2.Timestamp `json:"created_at" gorm:"autoCreateTime"` + Current decimal.Decimal `json:"current"` + Kind int `json:"kind"` } func (o UserWalletRecord) TableName() string { @@ -141,12 +143,13 @@ func (o UserWalletRecord) TableName() string { } type UserWalletApply struct { - ID int `json:"id"` - UserID int `json:"user_id"` - Amount decimal.Decimal `json:"amount"` - Attach string `json:"attach"` - CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"` - State int `json:"state"` + ID int `json:"id" gorm:"primaryKey;autoIncrement"` + UserID int `json:"-"` + Amount decimal.Decimal `json:"amount"` + Attach string `json:"attach"` + CreatedAt *time2.Timestamp `json:"created_at" gorm:"autoCreateTime"` + State int `json:"state"` + CompanyID int `json:"-"` } func (o UserWalletApply) TableName() string { diff --git a/internal/v2/router/app.go b/internal/v2/router/app.go index c764791..0a04fcf 100644 --- a/internal/v2/router/app.go +++ b/internal/v2/router/app.go @@ -296,9 +296,11 @@ func routerApp(appRouter *gin.RouterGroup) { proxy := jyy.Proxy{} { companyController.POST("info", proxy.CompanyInfo) - companyController.POST("apply/list", proxy.CompanyApplyList) - companyController.POST("apply", proxy.CompanyApply) - companyController.POST("despoit", proxy.CompanyDespoit) + companyController.POST("apply/list", proxy.CompanyApplyList) // 提现列表 + companyController.POST("apply", proxy.CompanyApply) // 提现 + companyController.POST("deposit", proxy.CompanyDespoit) // 充值 + companyController.POST("deposit/list", proxy.DespoitInfo) // 充值列表 + companyController.POST("record/list", proxy.RecordInfo) // 消费记录 } }