feat:完善项目信息
This commit is contained in:
@ -147,6 +147,21 @@ func (*User) Consume(c *gin.Context) {
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) ConsumeExchange(c *gin.Context) {
|
||||
form := &struct {
|
||||
OrderNo string `json:"order_no" form:"order_no"`
|
||||
CreatedAt string `json:"created_at" form:"created_at"`
|
||||
api.PageForm
|
||||
}{}
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewConsume()(api.GetSession()(c).(*session.Enterprise), "").Exchange(form.OrderNo,
|
||||
form.CreatedAt, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) ConsumeDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
|
@ -22,6 +22,11 @@ type (
|
||||
ID string `json:"id"`
|
||||
*model2.UserConsume
|
||||
}
|
||||
// ConsumePageInfo 消耗日志分页信息
|
||||
ConsumePageInfo struct {
|
||||
controller.ReturnPages
|
||||
TotalConsume float64 `json:"total_consume"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 列表信息
|
||||
@ -65,6 +70,39 @@ func (c *Consume) Instance(source int, createdAt string, page, pageSize int) (*c
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Exchange 兑换信息
|
||||
func (c *Consume) Exchange(orderNo string, createdAt string, page, pageSize int) (*ConsumePageInfo, error) {
|
||||
mUserConsume := model.NewUserConsume()
|
||||
|
||||
where := []*model2.ModelWhere{
|
||||
model2.NewWhere("uid", c.UID),
|
||||
model2.NewWhereIn("source", []model2.UserConsumeSource{
|
||||
model2.UserConsumeSourceForExchangeCoin,
|
||||
}),
|
||||
}
|
||||
if orderNo != "" {
|
||||
where = append(where, model2.NewWhereLike("order_no", orderNo))
|
||||
}
|
||||
if createdAt != "" {
|
||||
where = append(where, model2.NewWhereSectionAt("created_at", strings.Split(createdAt, " ~ "))...)
|
||||
}
|
||||
out := new(ConsumePageInfo)
|
||||
|
||||
res, err := mUserConsume.Exchange(page, pageSize, &out.Count, &out.TotalConsume)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*ConsumeInfo, 0)
|
||||
|
||||
for _, v := range res {
|
||||
list = append(list, &ConsumeInfo{ID: v.GetEncodeID(), UserConsume: v})
|
||||
}
|
||||
out.Data = list
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Consume) Delete(id uint64) error {
|
||||
mUserConsume := model.NewUserConsume()
|
||||
|
@ -2,6 +2,7 @@ package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
@ -16,12 +17,16 @@ type Withdrawal struct {
|
||||
type WithdrawalHandle func(session *session.Enterprise) *Withdrawal
|
||||
|
||||
type (
|
||||
// WithdrawalBasic 基本信息
|
||||
WithdrawalBasic struct {
|
||||
ID string `json:"id"`
|
||||
*model.UserWithdrawalInfo
|
||||
}
|
||||
// WithdrawalInfo 提现数据信息
|
||||
WithdrawalInfo struct {
|
||||
Data []*model2.UserWithdrawal `json:"data"`
|
||||
Amount float64 `json:"amount"`
|
||||
ActualAmount float64 `json:"actual_amount"`
|
||||
Count int64 `json:"count"`
|
||||
controller.ReturnPages
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
TotalActualAmount float64 `json:"total_actual_amount"`
|
||||
}
|
||||
// WithdrawalTransferInfo 提现转账信息
|
||||
WithdrawalTransferInfo struct {
|
||||
@ -36,16 +41,23 @@ func (c *Withdrawal) Instance(status int, createdAt string, page, pageSize int)
|
||||
|
||||
out := new(WithdrawalInfo)
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("uid", c.UID), model2.NewWhere("status", status)}
|
||||
where := []*model2.ModelWhere{model2.NewWhere("w.uid", c.UID), model2.NewWhere("w.status", status)}
|
||||
|
||||
if createdAt != "" {
|
||||
where = append(where, model2.NewWhereSectionAt("created_at", strings.Split(createdAt, " ~ "))...)
|
||||
where = append(where, model2.NewWhereSectionAt("w.created_at", strings.Split(createdAt, " ~ "))...)
|
||||
}
|
||||
var err error
|
||||
ret, err := mUserWithdrawal.Withdrawal(page, pageSize, &out.Count, &out.TotalAmount, &out.TotalActualAmount, where...)
|
||||
|
||||
if out.Data, err = mUserWithdrawal.Withdrawal(page, pageSize, &out.Count, &out.Amount, &out.ActualAmount, where...); err != nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*WithdrawalBasic, 0)
|
||||
|
||||
for _, v := range ret {
|
||||
list = append(list, &WithdrawalBasic{ID: v.GetEncodeID(), UserWithdrawalInfo: v})
|
||||
}
|
||||
out.Data = list
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,37 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
)
|
||||
|
||||
type UserConsume struct {
|
||||
*model.UserConsume
|
||||
}
|
||||
|
||||
func (m *UserConsume) Exchange(page, pageSize int, count *int64, consume *float64, where ...*model.ModelWhere) ([]*model.UserConsume, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.UserConsume, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Pluck("SUM(consume) AS consume", consume).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewUserConsume() *UserConsume {
|
||||
return &UserConsume{model.NewUserConsume()}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// UserWithdrawal 用户提现模型
|
||||
@ -10,28 +11,35 @@ type UserWithdrawal struct {
|
||||
*model.UserWithdrawal
|
||||
}
|
||||
|
||||
type UserWithdrawalInfo struct {
|
||||
*model.UserWithdrawal
|
||||
BankCard string `json:"bank_card"`
|
||||
}
|
||||
|
||||
// Withdrawal 提现记录
|
||||
func (m *UserWithdrawal) Withdrawal(page, pageSize int, count *int64, amount, actualAmount *float64, where ...*model.ModelWhere) ([]*model.UserWithdrawal, error) {
|
||||
db := orm.GetDB().Table(m.TableName()).
|
||||
Where("is_deleted = ?", model.DeleteStatusForNot)
|
||||
func (m *UserWithdrawal) Withdrawal(page, pageSize int, count *int64, amount, actualAmount *float64, where ...*model.ModelWhere) ([]*UserWithdrawalInfo, error) {
|
||||
db := orm.GetDB().Table(m.TableName()+" AS w").
|
||||
Select("w.*", "b.bank_card").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS b ON w.bank_id = b.id", model.NewUserBank().TableName())).
|
||||
Where("w.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.UserWithdrawal, 0)
|
||||
out := make([]*UserWithdrawalInfo, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Pluck("SUM(amount)", amount).Error; err != nil {
|
||||
if err := db.Pluck("SUM(w.amount) AS amount", amount).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Pluck("SUM(actual_amount)", actualAmount).Error; err != nil {
|
||||
if err := db.Pluck("SUM(w.actual_amount) AS actual_amount", actualAmount).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Order("id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
if err := db.Order("w.id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
|
@ -16,8 +16,10 @@ type UserConsume struct {
|
||||
type UserConsumeSource int
|
||||
|
||||
const (
|
||||
// UserConsumeSourceForRecharge 充值
|
||||
UserConsumeSourceForRecharge UserConsumeSource = iota + 1
|
||||
// UserConsumeSourceForRechargeCoin 充值币
|
||||
UserConsumeSourceForRechargeCoin UserConsumeSource = iota + 1
|
||||
// UserConsumeSourceForExchangeCoin 兑换币
|
||||
UserConsumeSourceForExchangeCoin
|
||||
)
|
||||
|
||||
func (m *UserConsume) TableName() string {
|
||||
|
@ -5,7 +5,7 @@ type UserWithdrawal struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:'';comment:订单号" json:"order_no"`
|
||||
BackCard string `gorm:"column:back_card;type:varchar(25);default:'';comment:银行卡号" json:"back_card"`
|
||||
BackID uint64 `gorm:"column:back_id;type:int(11);default:0;comment:银行信息" json:"-"`
|
||||
Mobile string `gorm:"column:mobile;type:varchar(15);default:'';comment:联系方式" json:"mobile"`
|
||||
Amount float64 `gorm:"column:amount;type:decimal(10,2);default:0;comment:提现金额" json:"amount"`
|
||||
ActualAmount float64 `gorm:"column:actual_amount;type:decimal(10,2);default:0;comment:实际到账金额" json:"actual_amount"`
|
||||
|
@ -268,6 +268,7 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
userV1.POST("/bill/ticket", _api.BillTicket)
|
||||
userV1.POST("/bill/ticket/issue", _api.BillTicketIssue)
|
||||
userV1.POST("/consume", _api.Consume)
|
||||
userV1.POST("/consume/exchange", _api.ConsumeExchange)
|
||||
userV1.POST("/consume/delete", _api.ConsumeDelete)
|
||||
userV1.POST("/withdrawal", _api.Withdrawal)
|
||||
userV1.POST("/withdrawal/transfer", _api.WithdrawalTransfer)
|
||||
|
Reference in New Issue
Block a user