2021-12-29 12:03:34 +08:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"SciencesServer/app/api/enterprise/model"
|
2021-12-29 16:12:25 +08:00
|
|
|
"SciencesServer/app/basic/controller"
|
2021-12-29 12:03:34 +08:00
|
|
|
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 (
|
2022-01-04 11:59:58 +08:00
|
|
|
// WithdrawalInfo 基本信息
|
|
|
|
WithdrawalInfo struct {
|
2021-12-29 16:12:25 +08:00
|
|
|
ID string `json:"id"`
|
|
|
|
*model.UserWithdrawalInfo
|
|
|
|
}
|
2022-01-04 11:59:58 +08:00
|
|
|
// WithdrawalPageInfo 提现数据信息
|
|
|
|
WithdrawalPageInfo struct {
|
2021-12-29 16:12:25 +08:00
|
|
|
controller.ReturnPages
|
|
|
|
TotalAmount float64 `json:"total_amount"`
|
|
|
|
TotalActualAmount float64 `json:"total_actual_amount"`
|
2021-12-29 12:03:34 +08:00
|
|
|
}
|
|
|
|
// WithdrawalTransferInfo 提现转账信息
|
|
|
|
WithdrawalTransferInfo struct {
|
2022-01-13 16:50:38 +08:00
|
|
|
Images string `json:"images"`
|
|
|
|
Remark string `json:"remark"`
|
2021-12-29 12:03:34 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Instance 数据信息
|
2022-01-04 11:59:58 +08:00
|
|
|
func (c *Withdrawal) Instance(status int, createdAt string, page, pageSize int) (*WithdrawalPageInfo, error) {
|
2021-12-29 12:03:34 +08:00
|
|
|
mUserWithdrawal := model.NewUserWithdrawal()
|
|
|
|
|
2022-01-04 11:59:58 +08:00
|
|
|
out := new(WithdrawalPageInfo)
|
2021-12-29 12:03:34 +08:00
|
|
|
|
2021-12-29 16:12:25 +08:00
|
|
|
where := []*model2.ModelWhere{model2.NewWhere("w.uid", c.UID), model2.NewWhere("w.status", status)}
|
2021-12-29 12:03:34 +08:00
|
|
|
|
|
|
|
if createdAt != "" {
|
2021-12-29 16:12:25 +08:00
|
|
|
where = append(where, model2.NewWhereSectionAt("w.created_at", strings.Split(createdAt, " ~ "))...)
|
2021-12-29 12:03:34 +08:00
|
|
|
}
|
2021-12-29 16:12:25 +08:00
|
|
|
ret, err := mUserWithdrawal.Withdrawal(page, pageSize, &out.Count, &out.TotalAmount, &out.TotalActualAmount, where...)
|
2021-12-29 12:03:34 +08:00
|
|
|
|
2021-12-29 16:12:25 +08:00
|
|
|
if err != nil {
|
2021-12-29 12:03:34 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
2022-01-04 11:59:58 +08:00
|
|
|
list := make([]*WithdrawalInfo, 0)
|
2021-12-29 16:12:25 +08:00
|
|
|
|
|
|
|
for _, v := range ret {
|
2022-01-04 11:59:58 +08:00
|
|
|
list = append(list, &WithdrawalInfo{ID: v.GetEncodeID(), UserWithdrawalInfo: v})
|
2021-12-29 16:12:25 +08:00
|
|
|
}
|
|
|
|
out.Data = list
|
|
|
|
|
2021-12-29 12:03:34 +08:00
|
|
|
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}
|
|
|
|
}
|
|
|
|
}
|