feat:添加充值接口

master
howell 3 years ago
parent 01fabc1757
commit 391899c005

@ -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)
@ -183,6 +190,7 @@ func MyInfo(c *gin.Context) {
var res = MyInfoResp{
Balance: uWallet.Balance,
Deposit: uWallet2.Deposit,
AllDeposit: allDeposit[0],
Notify: Notify{
IsNotify: false,
NotifyType: "up", // 暂时只有升级类型,估计以后会加需求,保级之类的预留

@ -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),
})
}

@ -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
}

@ -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"
@ -118,7 +120,7 @@ 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"`
CreatedAt *time2.Timestamp `json:"created_at" gorm:"autoCreateTime"`
Version int `json:"version"`
}
@ -128,10 +130,10 @@ func (o UserWallet) TableName() string {
type UserWalletRecord struct {
ID int `json:"id"`
WalletID int `json:"wallet_id"`
UserID int `json:"user_id"`
WalletID int `json:"-"`
UserID int `json:"-"`
Amount decimal.Decimal `json:"amount"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
CreatedAt *time2.Timestamp `json:"created_at" gorm:"autoCreateTime"`
Current decimal.Decimal `json:"current"`
Kind int `json:"kind"`
}
@ -141,12 +143,13 @@ func (o UserWalletRecord) TableName() string {
}
type UserWalletApply struct {
ID int `json:"id"`
UserID int `json:"user_id"`
ID int `json:"id" gorm:"primaryKey;autoIncrement"`
UserID int `json:"-"`
Amount decimal.Decimal `json:"amount"`
Attach string `json:"attach"`
CreatedAt *time.Time `json:"created_at" gorm:"autoCreateTime"`
CreatedAt *time2.Timestamp `json:"created_at" gorm:"autoCreateTime"`
State int `json:"state"`
CompanyID int `json:"-"`
}
func (o UserWalletApply) TableName() string {

@ -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) // 消费记录
}
}

Loading…
Cancel
Save