feat:完善项目信息
This commit is contained in:
@ -131,3 +131,66 @@ func (*User) BillTicketIssue(c *gin.Context) {
|
||||
})
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*User) Consume(c *gin.Context) {
|
||||
form := &struct {
|
||||
Source int `json:"source" form:"source"`
|
||||
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), "").Instance(form.Source,
|
||||
form.CreatedAt, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) ConsumeDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewConsume()(api.GetSession()(c).(*session.Enterprise), "").Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
||||
func (*User) Withdrawal(c *gin.Context) {
|
||||
form := &struct {
|
||||
Status int `json:"status" form:"status"`
|
||||
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.NewWithdrawal()(api.GetSession()(c).(*session.Enterprise)).Instance(form.Status,
|
||||
form.CreatedAt, form.Page, form.PageSize)
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) WithdrawalTransfer(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := user.NewWithdrawal()(api.GetSession()(c).(*session.Enterprise)).Transfer(form.Convert())
|
||||
api.APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (*User) WithdrawalDelete(c *gin.Context) {
|
||||
form := new(api.IDStringForm)
|
||||
|
||||
if err := api.Bind(form)(c); err != nil {
|
||||
api.APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := user.NewWithdrawal()(api.GetSession()(c).(*session.Enterprise)).Delete(form.Convert())
|
||||
api.APIResponse(err)(c)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Consume 消耗日志
|
||||
@ -16,14 +17,15 @@ type Consume struct {
|
||||
type ConsumeHandle func(session *session.Enterprise, local string) *Consume
|
||||
|
||||
type (
|
||||
// ConsumeInfo 消耗日志信息
|
||||
ConsumeInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model2.UserConsume
|
||||
}
|
||||
)
|
||||
|
||||
// List 列表信息
|
||||
func (c *Consume) List(source, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
// Instance 列表信息
|
||||
func (c *Consume) Instance(source int, createdAt string, page, pageSize int) (*controller.ReturnPages, error) {
|
||||
mUserConsume := model.NewUserConsume()
|
||||
|
||||
where := []*model2.ModelWhereOrder{
|
||||
@ -32,6 +34,18 @@ func (c *Consume) List(source, page, pageSize int) (*controller.ReturnPages, err
|
||||
Order: model2.NewOrder("id", model2.OrderModeToDesc),
|
||||
},
|
||||
}
|
||||
if source > 0 {
|
||||
where = append(where, &model2.ModelWhereOrder{Where: model2.NewWhere("source", source)})
|
||||
}
|
||||
if createdAt != "" {
|
||||
_wheres := model2.NewWhereSectionAt("created_at", strings.Split(createdAt, " ~ "))
|
||||
|
||||
where = append(where, &model2.ModelWhereOrder{
|
||||
Where: _wheres[0],
|
||||
}, &model2.ModelWhereOrder{
|
||||
Where: _wheres[1],
|
||||
})
|
||||
}
|
||||
out := make([]*model2.UserConsume, 0)
|
||||
|
||||
var count int64
|
||||
@ -39,6 +53,7 @@ func (c *Consume) List(source, page, pageSize int) (*controller.ReturnPages, err
|
||||
if err := model2.Pages(mUserConsume.UserConsume, &out, page, pageSize, &count, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := make([]*ConsumeInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
@ -50,6 +65,13 @@ func (c *Consume) List(source, page, pageSize int) (*controller.ReturnPages, err
|
||||
return &controller.ReturnPages{Data: list, Count: count}, nil
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Consume) Delete(id uint64) error {
|
||||
mUserConsume := model.NewUserConsume()
|
||||
mUserConsume.ID = id
|
||||
return model2.Delete(mUserConsume.UserConsume)
|
||||
}
|
||||
|
||||
func NewConsume() ConsumeHandle {
|
||||
return func(session *session.Enterprise, local string) *Consume {
|
||||
return &Consume{
|
||||
|
81
app/api/enterprise/controller/user/withdrawal.go
Normal file
81
app/api/enterprise/controller/user/withdrawal.go
Normal file
@ -0,0 +1,81 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/enterprise/model"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/config"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Withdrawal 提现信息
|
||||
type Withdrawal struct {
|
||||
*session.Enterprise
|
||||
}
|
||||
|
||||
type WithdrawalHandle func(session *session.Enterprise) *Withdrawal
|
||||
|
||||
type (
|
||||
// WithdrawalInfo 提现数据信息
|
||||
WithdrawalInfo struct {
|
||||
Data []*model2.UserWithdrawal `json:"data"`
|
||||
Amount float64 `json:"amount"`
|
||||
ActualAmount float64 `json:"actual_amount"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
// WithdrawalTransferInfo 提现转账信息
|
||||
WithdrawalTransferInfo struct {
|
||||
Images []string `json:"images"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
// Instance 数据信息
|
||||
func (c *Withdrawal) Instance(status int, createdAt string, page, pageSize int) (*WithdrawalInfo, error) {
|
||||
mUserWithdrawal := model.NewUserWithdrawal()
|
||||
|
||||
out := new(WithdrawalInfo)
|
||||
|
||||
where := []*model2.ModelWhere{model2.NewWhere("uid", c.UID), model2.NewWhere("status", status)}
|
||||
|
||||
if createdAt != "" {
|
||||
where = append(where, model2.NewWhereSectionAt("created_at", strings.Split(createdAt, " ~ "))...)
|
||||
}
|
||||
var err error
|
||||
|
||||
if out.Data, err = mUserWithdrawal.Withdrawal(page, pageSize, &out.Count, &out.Amount, &out.ActualAmount, where...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Transfer 转账信息
|
||||
func (c *Withdrawal) Transfer(id uint64) (*WithdrawalTransferInfo, error) {
|
||||
mUserWithdrawalTransfer := model.NewUserWithdrawalTransfer()
|
||||
|
||||
isExist, err := model2.FirstField(mUserWithdrawalTransfer.UserWithdrawalTransfer, []string{"images", "remark"},
|
||||
model2.NewWhere("withdrawal_id", id))
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !isExist {
|
||||
return nil, nil
|
||||
}
|
||||
return &WithdrawalTransferInfo{
|
||||
Images: mUserWithdrawalTransfer.Images.AnalysisSlice(config.SettingInfo.Domain),
|
||||
Remark: mUserWithdrawalTransfer.Remark,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Delete 删除操作
|
||||
func (c *Withdrawal) Delete(id uint64) error {
|
||||
mUserWithdrawal := model.NewUserWithdrawal()
|
||||
mUserWithdrawal.ID = id
|
||||
return model2.Delete(mUserWithdrawal.UserWithdrawal)
|
||||
}
|
||||
|
||||
func NewWithdrawal() WithdrawalHandle {
|
||||
return func(session *session.Enterprise) *Withdrawal {
|
||||
return &Withdrawal{session}
|
||||
}
|
||||
}
|
42
app/api/enterprise/model/user_withdrawal.go
Normal file
42
app/api/enterprise/model/user_withdrawal.go
Normal file
@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
)
|
||||
|
||||
// UserWithdrawal 用户提现模型
|
||||
type UserWithdrawal struct {
|
||||
*model.UserWithdrawal
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
if len(where) > 0 {
|
||||
for _, v := range where {
|
||||
db = db.Where(v.Condition, v.Value)
|
||||
}
|
||||
}
|
||||
out := make([]*model.UserWithdrawal, 0)
|
||||
|
||||
if err := db.Count(count).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Pluck("SUM(amount)", amount).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := db.Pluck("SUM(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 {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewUserWithdrawal() *UserWithdrawal {
|
||||
return &UserWithdrawal{model.NewUserWithdrawal()}
|
||||
}
|
11
app/api/enterprise/model/user_withdrawal_transfer.go
Normal file
11
app/api/enterprise/model/user_withdrawal_transfer.go
Normal file
@ -0,0 +1,11 @@
|
||||
package model
|
||||
|
||||
import "SciencesServer/app/common/model"
|
||||
|
||||
type UserWithdrawalTransfer struct {
|
||||
*model.UserWithdrawalTransfer
|
||||
}
|
||||
|
||||
func NewUserWithdrawalTransfer() *UserWithdrawalTransfer {
|
||||
return &UserWithdrawalTransfer{model.NewUserWithdrawalTransfer()}
|
||||
}
|
@ -4,9 +4,10 @@ package model
|
||||
type UserConsume struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
Source UserConsumeSource `gorm:"column:source;type:tinyiny(1);default:'';comment:消耗来源" json:"source"`
|
||||
Consume float64 `gorm:"column:consume;type:decimal(10,2);default:'';comment:消耗数量" json:"consume"`
|
||||
Surplus float64 `gorm:"column:surplus;type:decimal(10,2);default:'';comment:剩余数量" json:"surplus"`
|
||||
OrderNo string `gorm:"column:order_no;type:varchar(30);default:'';comment:订单号" json:"order_no"`
|
||||
Source UserConsumeSource `gorm:"column:source;type:tinyint(1);default:0;comment:消耗来源" json:"source"`
|
||||
Consume float64 `gorm:"column:consume;type:decimal(10,2);default:0;comment:消耗数量" json:"consume"`
|
||||
Surplus float64 `gorm:"column:surplus;type:decimal(10,2);default:0;comment:剩余数量" json:"surplus"`
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:'';comment:备注信息" json:"remark"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
|
24
app/common/model/user_withdrawal.go
Normal file
24
app/common/model/user_withdrawal.go
Normal file
@ -0,0 +1,24 @@
|
||||
package model
|
||||
|
||||
// UserWithdrawal 用户提现数据模型
|
||||
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"`
|
||||
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"`
|
||||
Charge float64 `gorm:"column:charge;type:decimal(10,2);default:0;comment:提现手续费" json:"charge"`
|
||||
Status int `json:"status"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *UserWithdrawal) TableName() string {
|
||||
return "user_withdrawal"
|
||||
}
|
||||
|
||||
func NewUserWithdrawal() *UserWithdrawal {
|
||||
return &UserWithdrawal{}
|
||||
}
|
20
app/common/model/user_withdrawal_transfer.go
Normal file
20
app/common/model/user_withdrawal_transfer.go
Normal file
@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
// UserWithdrawalTransfer 提现转账数据模型
|
||||
type UserWithdrawalTransfer struct {
|
||||
Model
|
||||
UID uint64 `gorm:"column:uid;type:int;default:0;comment:用户uuid" json:"-"`
|
||||
WithdrawalID uint64 `gorm:"column:withdrawal_id;type:int(11);default:0;comment:用户uuid" json:"-"`
|
||||
Images
|
||||
Remark string `gorm:"column:remark;type:varchar(255);default:'';comment:备注信息" json:"remark"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *UserWithdrawalTransfer) TableName() string {
|
||||
return "user_withdrawal_transfer"
|
||||
}
|
||||
|
||||
func NewUserWithdrawalTransfer() *UserWithdrawalTransfer {
|
||||
return &UserWithdrawalTransfer{}
|
||||
}
|
@ -267,6 +267,11 @@ func registerEnterpriseAPI(app *gin.Engine) {
|
||||
userV1.POST("/bill", _api.Bill)
|
||||
userV1.POST("/bill/ticket", _api.BillTicket)
|
||||
userV1.POST("/bill/ticket/issue", _api.BillTicketIssue)
|
||||
userV1.POST("/consume", _api.Consume)
|
||||
userV1.POST("/consume/delete", _api.ConsumeDelete)
|
||||
userV1.POST("/withdrawal", _api.Withdrawal)
|
||||
userV1.POST("/withdrawal/transfer", _api.WithdrawalTransfer)
|
||||
userV1.POST("/withdrawal/delete", _api.WithdrawalDelete)
|
||||
}
|
||||
// Home 首页管理
|
||||
homeV1 := v1.Group("/home")
|
||||
|
Reference in New Issue
Block a user