package user import ( "SciencesServer/app/api/enterprise/model" "SciencesServer/app/basic/controller" 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 ( // WithdrawalBasic 基本信息 WithdrawalBasic struct { ID string `json:"id"` *model.UserWithdrawalInfo } // WithdrawalInfo 提现数据信息 WithdrawalInfo struct { controller.ReturnPages TotalAmount float64 `json:"total_amount"` TotalActualAmount float64 `json:"total_actual_amount"` } // 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("w.uid", c.UID), model2.NewWhere("w.status", status)} if createdAt != "" { where = append(where, model2.NewWhereSectionAt("w.created_at", strings.Split(createdAt, " ~ "))...) } ret, err := mUserWithdrawal.Withdrawal(page, pageSize, &out.Count, &out.TotalAmount, &out.TotalActualAmount, where...) 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 } // 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} } }