82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
![]() |
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}
|
||
|
}
|
||
|
}
|