|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"git.oa00.com/supply-chain/service/client"
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
)
|
|
|
|
|
|
|
|
type wallet struct {
|
|
|
|
}
|
|
|
|
type walletType uint // 费用类型
|
|
|
|
|
|
|
|
const (
|
|
|
|
WalletTypeIncome walletType = 1 // 收入 +
|
|
|
|
WalletTypeExpend walletType = 2 // 支出 -
|
|
|
|
|
|
|
|
WalletStatusHandle = 1 // 处理中
|
|
|
|
WalletStatusSuccess = 2 // 成功
|
|
|
|
WalletStatusFail = 3 // 失败
|
|
|
|
)
|
|
|
|
|
|
|
|
type ArgsWalletDirect struct {
|
|
|
|
UserId uint // 客户id
|
|
|
|
WalletType walletType // 收支类型
|
|
|
|
Amount decimal.Decimal // 金额 正数
|
|
|
|
ServiceId uint // 服务id
|
|
|
|
TradeChannel string // 交易渠道
|
|
|
|
TradeSerialSn string // 交易渠道流水号
|
|
|
|
Title string // 收支标题
|
|
|
|
Remark string // 备注信息
|
|
|
|
}
|
|
|
|
|
|
|
|
// Direct @Title 直接消费
|
|
|
|
func (w *wallet) Direct(ctx context.Context, args ArgsWalletDirect) error {
|
|
|
|
reply := 0
|
|
|
|
xClient, err := client.GetClient(w)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return xClient.Call(ctx, "Direct", args, &reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsWalletCreate struct {
|
|
|
|
UserId uint // 客户id
|
|
|
|
WalletType walletType // 收支类型
|
|
|
|
Amount decimal.Decimal // 金额 正数
|
|
|
|
ServiceId uint // 服务id
|
|
|
|
TradeChannel string // 交易渠道
|
|
|
|
TradeSerialSn string // 交易渠道流水号
|
|
|
|
Title string // 收支标题
|
|
|
|
Remark string // 备注信息
|
|
|
|
CancelSecond int64 // 自动取消秒
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create @Title 创建消费
|
|
|
|
func (w *wallet) Create(ctx context.Context, args ArgsWalletCreate) (walletId uint, err error) {
|
|
|
|
xClient, err := client.GetClient(w)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = xClient.Call(ctx, "Create", args, &walletId)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsWalletSuccess struct {
|
|
|
|
UserId uint // 客户id
|
|
|
|
WalletId uint // 消费id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success @Title 成功
|
|
|
|
func (w *wallet) Success(ctx context.Context, args ArgsWalletSuccess) error {
|
|
|
|
reply := 0
|
|
|
|
xClient, err := client.GetClient(w)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return xClient.Call(ctx, "Success", args, &reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ArgsWalletFail struct {
|
|
|
|
UserId uint // 客户id
|
|
|
|
WalletId uint // 消费id
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail @Title 失败
|
|
|
|
func (w *wallet) Fail(ctx context.Context, args ArgsWalletFail) error {
|
|
|
|
reply := 0
|
|
|
|
xClient, err := client.GetClient(w)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return xClient.Call(ctx, "Fail", args, &reply)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Amount @Title 钱包余额
|
|
|
|
func (w *wallet) Amount(ctx context.Context, userId int64) (amount decimal.Decimal, err error) {
|
|
|
|
xClient, err := client.GetClient(w)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = xClient.Call(ctx, "Amount", userId, &amount)
|
|
|
|
return
|
|
|
|
}
|