@@ -0,0 +1,17 @@
|
||||
package wdchannmod
|
||||
|
||||
import "91porn-server/models/v/wdtaxmod"
|
||||
|
||||
type WithdrawChannelAppRes struct {
|
||||
Channels []*AppWithdrawChannels `json:"channels"`
|
||||
wdtaxmod.WithdrawTariff
|
||||
}
|
||||
|
||||
// WithdrawChannel 提现渠道配置
|
||||
type AppWithdrawChannels struct {
|
||||
ChannelName string `json:"channelName,omitempty" bson:"channelName,omitempty"` //提现渠道名字
|
||||
CID string `json:"cid,omitempty" bson:"cid,omitempty"` //渠道id
|
||||
PayType string `json:"payType" bson:"payType"` //支付方式
|
||||
MinMoney int `json:"minMoney" bson:"minMoney"` //支持最小支付金额
|
||||
MaxMoney int `json:"maxMoney" bson:"maxMoney"` //支持最大支付金额
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package wdchannmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const table = models.WithdrawChannel
|
||||
|
||||
// initIndex 设置index
|
||||
func initIndex() {
|
||||
coll := coll(nil)
|
||||
many := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "payType", Value: 1}, {Key: "cid", Value: 1}},
|
||||
Options: options.Index().SetUnique(true),
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "createdAt", Value: 1}},
|
||||
},
|
||||
{
|
||||
Keys: bson.D{{Key: "updatedAt", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := coll.CreateIndex(many); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
|
||||
}
|
||||
}
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// InsertWithdrawChannel 插入一条数据
|
||||
func InsertWithdrawChannel(c *WithdrawChannel) error {
|
||||
if _, err := coll(nil).InsertOne(c); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertWithdrawChannel", table, "InsertOne", err),
|
||||
log.Any("c", c),
|
||||
)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteWithdrawChannel delete
|
||||
func DeleteWithdrawChannel(cond bson.M) (int64, error) {
|
||||
result, err := coll(nil).DeleteMany(cond)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DeleteWithdrawChannel", table, "DeleteMany", err),
|
||||
log.Any("cond", cond),
|
||||
)
|
||||
return 0, err
|
||||
}
|
||||
return result.DeletedCount, err
|
||||
}
|
||||
|
||||
// UpdateWithdrawChannel 金币配置更新
|
||||
func UpdateWithdrawChannel(id string, set *WithdrawChannelSelector) (int64, error) {
|
||||
oid, err := primitive.ObjectIDFromHex(id)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdateWithdrawChannel", table, "ObjectIDFromHex", err),
|
||||
log.Any("id", id),
|
||||
log.Any("set", set),
|
||||
)
|
||||
log.ZapLog.Warn("withdraw UpdateWithdrawChannel ObjectIDFromHex fail", log.E(err))
|
||||
return 0, err
|
||||
}
|
||||
result, err := coll(nil).UpdateOne(bson.M{"_id": oid}, bson.M{"$set": set})
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdateWithdrawChannel", table, "UpdateOne", err),
|
||||
log.Any("id", id),
|
||||
log.Any("set", set),
|
||||
)
|
||||
return 0, err
|
||||
}
|
||||
return result.ModifiedCount, nil
|
||||
}
|
||||
|
||||
// GetWithdrawChannels 条件获取支付渠道列表
|
||||
func GetWithdrawChannels() ([]*WithdrawChannel, error) {
|
||||
opts := options.FindOptions{}
|
||||
opts.SetSort(bson.D{{Key: "updatedAt", Value: 1}})
|
||||
var back []*WithdrawChannel
|
||||
if err := coll(nil).Find(&back, bson.M{}, &opts); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetWithdrawChannels", table, "Find", err))
|
||||
return nil, err
|
||||
}
|
||||
return back, nil
|
||||
}
|
||||
|
||||
// GetWithdrawChannel 条件获取支付渠道列表
|
||||
func GetWithdrawChannel(paytype string) (w *WithdrawChannel, err error) {
|
||||
w = &WithdrawChannel{}
|
||||
if err = coll(nil).FindOne(w, bson.M{"payType": paytype}); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetWithdrawChannel", table, "FindOne", err),
|
||||
log.Any("payType", paytype),
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetWithdrawChannel 条件获取可用的提现方式
|
||||
func GetActiveWithdrawChannels() ([]*AppWithdrawChannels, error) {
|
||||
opts := options.FindOptions{}
|
||||
opts.SetSort(bson.D{{Key: "weight", Value: -1}, {Key: "updatedAt", Value: 1}})
|
||||
var back []*AppWithdrawChannels
|
||||
if err := coll(nil).Find(&back, bson.M{"active": true}, &opts); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetActiveWithdrawChannels", table, "Find", err))
|
||||
return nil, err
|
||||
}
|
||||
return back, nil
|
||||
}
|
||||
|
||||
// GetWithdrawChannel 条件获取支付渠道列表
|
||||
func IsYinse() (bool, error) {
|
||||
w := WithdrawChannel{}
|
||||
if err := coll(nil).FindOne(&w, bson.M{"cid": "yinse", "active": true}); err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "IsYinse", table, "FindOne", err))
|
||||
return false, err
|
||||
}
|
||||
return !w.ID.IsZero(), nil
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package wdchannmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/pageopt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type WithdrawChannelSlice []WithdrawChannel
|
||||
|
||||
// 加权随机
|
||||
func (w WithdrawChannelSlice) WeightedRandom() WithdrawChannel {
|
||||
if len(w) == 0 {
|
||||
return WithdrawChannel{}
|
||||
}
|
||||
var indexs []int
|
||||
for i, v := range w {
|
||||
for j := 0; j < v.Weight; j++ {
|
||||
indexs = append(indexs, i)
|
||||
}
|
||||
}
|
||||
i := rand.Intn(len(indexs))
|
||||
if i < 0 {
|
||||
return WithdrawChannel{}
|
||||
}
|
||||
return w[indexs[i]]
|
||||
}
|
||||
|
||||
func (w WithdrawChannelSlice) ToPayTypeList() []string {
|
||||
payTypeMap := make(map[string]byte)
|
||||
for _, v := range w {
|
||||
payTypeMap[v.PayType] = 1
|
||||
}
|
||||
payTypeList := make([]string, len(payTypeMap))
|
||||
i := 0
|
||||
for p := range payTypeMap {
|
||||
payTypeList[i] = p
|
||||
i++
|
||||
}
|
||||
return payTypeList
|
||||
}
|
||||
|
||||
type Matcher = pageopt.Matcher
|
||||
|
||||
// ActiveMatch
|
||||
type ActiveMatch struct {
|
||||
Active *bool
|
||||
}
|
||||
|
||||
func (d *ActiveMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("active", d.Active)
|
||||
}
|
||||
|
||||
// PayTypeMatch
|
||||
type PayTypeMatch struct {
|
||||
PayType *string
|
||||
}
|
||||
|
||||
func (d *PayTypeMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("payType", d.PayType)
|
||||
}
|
||||
|
||||
type Sort = bson.D
|
||||
|
||||
func List(sort Sort, skip, limit *int64, matchers ...Matcher) (WithdrawChannelSlice, error) {
|
||||
filter := pageopt.MergeM(matchers)
|
||||
opt := &options.FindOptions{}
|
||||
if len(sort) != 0 {
|
||||
opt.SetSort(sort)
|
||||
}
|
||||
if skip != nil {
|
||||
opt.SetSkip(*skip)
|
||||
}
|
||||
if limit != nil {
|
||||
opt.SetLimit(*limit)
|
||||
}
|
||||
list := WithdrawChannelSlice{}
|
||||
if err := coll(nil).Find(&list, filter, opt); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "List", table, "Find", err),
|
||||
log.Any("sort", sort),
|
||||
log.Any("skip", skip),
|
||||
log.Any("limit", limit),
|
||||
log.Any("matchers", matchers),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package wdchannmod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/db"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
const (
|
||||
TypeAlipay = "alipay" //支付宝方式
|
||||
TypeBankCard = "bankcard" //银行卡方式
|
||||
)
|
||||
|
||||
var mdb *db.MongoDB
|
||||
|
||||
// WithdrawChannel 提现渠道配置
|
||||
type WithdrawChannel struct {
|
||||
ID primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
|
||||
ChannelName string `json:"channelName,omitempty" bson:"channelName"` //提现渠道名字
|
||||
CID string `json:"cid,omitempty" bson:"cid"` //渠道id
|
||||
PayType string `json:"payType,omitempty" bson:"payType"` //支付方式
|
||||
MinMoney int `json:"minMoney,omitempty" bson:"minMoney"` //支持最小支付金额
|
||||
QpMinMoney int `json:"qpMinMoney,omitempty" bson:"qpMinMoney"` //支持棋牌最小支付金额
|
||||
MaxMoney int `json:"maxMoney,omitempty" bson:"maxMoney"` //支持最大支付金额
|
||||
Weight int `json:"weight,omitempty" bson:"weight"` //权重
|
||||
Active bool `json:"active,omitempty" bson:"active"` //是否激活
|
||||
CreatedAt time.Time `json:"createdAt,omitempty" bson:"createdAt,omitempty"` //创建时间
|
||||
UpdatedAt time.Time `json:"updatedAt,omitempty" bson:"updatedAt,omitempty"` //刷新时间
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package wdchannmod
|
||||
|
||||
import "91porn-server/models/v/wdtaxmod"
|
||||
|
||||
// ChannelReq 新增提现渠道
|
||||
type ChannelReq struct {
|
||||
ChannelName string `form:"channelName" json:"channelName"` //支付渠道名字
|
||||
CID string `form:"cid" json:"cid"` //渠道id
|
||||
PayType string `form:"payType" json:"payType"` //支付方式
|
||||
MinMoney int `form:"minMoney" json:"minMoney"` //支持最小支付金额
|
||||
QpMinMoney int `form:"qpMinMoney" json:"qpMinMoney"` //支持棋牌最小支付金额
|
||||
MaxMoney int `form:"maxMoney" json:"maxMoney"` //支持最大支付金额
|
||||
Weight int `form:"weight" json:"weight"` //权重
|
||||
}
|
||||
|
||||
// WithdrawChannelSelector 提现配置修改
|
||||
type WithdrawChannelSelector struct {
|
||||
ChannelName *string `json:"channelName,omitempty" bson:"channelName,omitempty"` //提现渠道名字
|
||||
CID *string `json:"cid,omitempty" bson:"cid,omitempty"` //渠道id
|
||||
PayType *string `json:"payType,omitempty" bson:"payType,omitempty"` //支付方式
|
||||
MinMoney *int `json:"minMoney,omitempty" bson:"minMoney,omitempty"` //支持最小支付金额
|
||||
QpMinMoney *int `json:"qpMinMoney,omitempty" bson:"qpMinMoney,omitempty"` //支持棋牌最小支付金额
|
||||
QpMaxMoney *int `json:"qpMaxMoney,omitempty" bson:"qpMaxMoney,omitempty"` //支持棋牌最大支付金额
|
||||
MaxMoney *int `json:"maxMoney,omitempty" bson:"maxMoney,omitempty"` //支持最大支付金额
|
||||
Weight *int `json:"weight,omitempty" bson:"weight,omitempty"` //权重
|
||||
Active *bool `json:"active,omitempty" bson:"active,omitempty"` //是否激活
|
||||
}
|
||||
|
||||
type WithdrawChannelRes struct {
|
||||
WithdrawChannel
|
||||
wdtaxmod.WithdrawTariff
|
||||
}
|
||||
|
||||
// DelReq 删除请求
|
||||
type DelReq struct {
|
||||
IDs []string `form:"ids" json:"ids"`
|
||||
}
|
||||
|
||||
// OpeResp 操作应答
|
||||
type OpeResp struct {
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
Reference in New Issue
Block a user