@@ -0,0 +1 @@
|
||||
package integralexcangemod
|
||||
@@ -0,0 +1,101 @@
|
||||
package integralexcangemod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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.IntegralExchange
|
||||
|
||||
func coll(t *db.MongoTool) *db.MongoTool {
|
||||
if t == nil {
|
||||
return mdb.Coll(table)
|
||||
}
|
||||
return t.Coll(table)
|
||||
}
|
||||
|
||||
// initIndex 索引设置
|
||||
func initIndex() {
|
||||
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
|
||||
{
|
||||
Keys: bson.D{{"createdAt", -1}},
|
||||
},
|
||||
}
|
||||
_, err := coll(nil).CreateIndex(many)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("user model set index err ==>[%+v]", err))
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
mdb = db.Init(table)
|
||||
initIndex()
|
||||
}
|
||||
|
||||
func InsertOne(mt *db.MongoTool, cfg IntegralExchange) error {
|
||||
if _, err := coll(mt).InsertOne(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindOneById(id primitive.ObjectID) (IntegralExchange, error) {
|
||||
cfg := IntegralExchange{}
|
||||
err := coll(nil).FindOne(&cfg, bson.M{"_id": id})
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
// QueryAllList 分页查询文档
|
||||
func QueryAllList(filter primitive.M, opts ...*options.FindOptions) (out []*IntegralExchange, err error) {
|
||||
if err = coll(nil).Find(&out, filter, opts...); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllList", table, "Find", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("opts", opts),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// QueryAllCount 查询文档条目数
|
||||
func QueryAllCount(filter primitive.M) (int64, error) {
|
||||
if count, err := coll(nil).Count(filter); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "QueryAllCount", table, "Count", err),
|
||||
log.Any("filter", filter),
|
||||
)
|
||||
return 0, err
|
||||
} else {
|
||||
return count, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Edit 修改文档
|
||||
func Edit(filter, update primitive.M) error {
|
||||
result, err := coll(nil).UpdateOne(filter, update)
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Edit", table, "UpdateOne", err),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return err
|
||||
}
|
||||
if result.ModifiedCount == 0 {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Edit", table, "result.ModifiedCount", "ModifiedCount is zero"),
|
||||
log.Any("filter", filter),
|
||||
log.Any("update", update),
|
||||
)
|
||||
return errors.New("result is null")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package integralexcangemod
|
||||
|
||||
import (
|
||||
"91porn-server/common/db"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
var (
|
||||
mdb *db.MongoDB
|
||||
)
|
||||
var ExchangeType int
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
PENDING // 1 待发货
|
||||
PROCCESSING // 2 发货中
|
||||
PAID // 3 已发货
|
||||
REFUSE // 4 拒绝发货
|
||||
)
|
||||
|
||||
// IntegralExchange 积分兑换列表
|
||||
type IntegralExchange struct {
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // 兑换实物的唯一id
|
||||
EID primitive.ObjectID `json:"eid" bson:"eid"` // 兑换配置id
|
||||
UID uint64 `json:"uid" bson:"uid"` // 用户id
|
||||
Portrait string `json:"portrait" bson:"portrait"` // 用户头像
|
||||
Name string `json:"name" bson:"name"` // 兑换用户姓名
|
||||
Tel string `json:"tel" bson:"tel"` // 兑换用户电话
|
||||
Address string `json:"address" bson:"address"` // 兑换用户地址
|
||||
Remark string `json:"remark" bson:"remark"` // 描述
|
||||
InKindName string `json:"inKindName" bson:"inKindName"` // 兑换实物名称
|
||||
Img string `json:"img" bson:"img"` // 兑换实物图片
|
||||
Status int `json:"status" bson:"status"` // 兑换实物状态
|
||||
UpdateAct string `json:"updateAct" bson:"updateAct"` // 操作账号
|
||||
UpdateTime time.Time `json:"updateTime" bson:"updateTime"` // 更新时间
|
||||
CreateTime time.Time `json:"createTime" bson:"createTime"` // 创建时间
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package integralexcangemod
|
||||
|
||||
import (
|
||||
"91porn-server/models/commod"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// RechargeUpdateReq 修改参数
|
||||
type RechargeUpdateReq struct {
|
||||
StatusDesc *string `json:"statusDesc" bson:"statusDesc"` // 状态描述
|
||||
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
|
||||
}
|
||||
|
||||
type RchgQueryReq struct {
|
||||
ID *string `form:"id" json:"_id,omitempty" bson:"_id"` // 流水id
|
||||
UID *uint64 `form:"uid" json:"uid,omitempty" bson:"uid"` // 用户id
|
||||
Status *int `form:"status" json:"status,omitempty" bson:"status"` // 1、进行中 2、生成成功 3、生成失败 4、已经退款
|
||||
}
|
||||
|
||||
type WebListRequest struct {
|
||||
Status *int `form:"status" json:"status" bson:"status"` // 1、待发货 2、发货中 3、已发货 4、拒绝发货
|
||||
UID *uint64 `form:"uid" json:"uid,omitempty" bson:"uid"` // 用户id
|
||||
ID *string `form:"id" json:"_id,omitempty" bson:"_id"` // 流水id
|
||||
commod.Page
|
||||
}
|
||||
|
||||
type QueryAllRes struct {
|
||||
List []*IntegralExchange `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
func (receiver *WebListRequest) Filter() primitive.M {
|
||||
filter := bson.M{}
|
||||
if receiver.Status != nil {
|
||||
filter["status"] = receiver.Status
|
||||
}
|
||||
if receiver.UID != nil {
|
||||
filter["uid"] = receiver.UID
|
||||
}
|
||||
if receiver.ID != nil {
|
||||
id, _ := primitive.ObjectIDFromHex(*receiver.ID)
|
||||
filter["_id"] = id
|
||||
}
|
||||
return filter
|
||||
}
|
||||
|
||||
func (receiver *WebListRequest) Options() *options.FindOptions {
|
||||
return options.Find().SetSkip(int64(receiver.Skip())).SetLimit(int64(receiver.Limit() + 1)).SetSort(bson.M{"createTime": -1})
|
||||
}
|
||||
|
||||
type EditCond struct {
|
||||
ID string `json:"id" binding:"required"` // 文档
|
||||
Status *int `json:"status" bson:"status"` // 状态 2、发货中 3、已发货 4、拒绝发货
|
||||
Remark *string `json:"remark" bson:"remark"` // 拒绝理由
|
||||
}
|
||||
|
||||
func (receiver *EditCond) Filter() bson.M {
|
||||
objID, _ := primitive.ObjectIDFromHex(receiver.ID)
|
||||
return bson.M{"_id": objID}
|
||||
}
|
||||
|
||||
func (receiver *EditCond) Update(updateAct string) bson.M {
|
||||
var update = bson.M{}
|
||||
if receiver.Status != nil {
|
||||
update["status"] = receiver.Status
|
||||
}
|
||||
if receiver.Remark != nil {
|
||||
update["remark"] = receiver.Remark
|
||||
}
|
||||
update["updateAct"] = updateAct
|
||||
update["updateTime"] = time.Now()
|
||||
return bson.M{"$set": update}
|
||||
}
|
||||
Reference in New Issue
Block a user