退款
This commit is contained in:
@@ -92,5 +92,5 @@ func (c *FsCartModel) DeleteCartsByIds(ctx context.Context, ids []int64) ( err e
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` in (?)", ids).Delete(&FsCart{}).Error
|
||||
return c.db.Table(c.name).WithContext(ctx).Model(&FsCart{}).Where("`id` in (?)", ids).Update("status", 0).Error
|
||||
}
|
||||
|
||||
25
model/gmodel/fs_pay_event_gen.go
Normal file
25
model/gmodel/fs_pay_event_gen.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// fs_pay_event 支付回调事件日志
|
||||
type FsPayEvent struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
PayMethod *int64 `gorm:"default:0;" json:"pay_method"` // 支付方式 1 stripe 2 paypal
|
||||
EventId *string `gorm:"default:'';" json:"event_id"` // 事件ID
|
||||
EventType *string `gorm:"default:'';" json:"event_type"` // 事件类型
|
||||
EventData *string `gorm:"default:'';" json:"event_data"` // 事件数据
|
||||
EventCreated *int64 `gorm:"default:0;" json:"event_created"` // 事件时间
|
||||
Ip *string `gorm:"default:'';" json:"ip"` // 请求IP
|
||||
CreatedAt *int64 `gorm:"default:0;" json:"created_at"` // 创建时间
|
||||
}
|
||||
type FsPayEventModel struct {
|
||||
db *gorm.DB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewFsPayEventModel(db *gorm.DB) *FsPayEventModel {
|
||||
return &FsPayEventModel{db: db, name: "fs_pay_event"}
|
||||
}
|
||||
15
model/gmodel/fs_pay_event_logic.go
Normal file
15
model/gmodel/fs_pay_event_logic.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package gmodel
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (p *FsPayEventModel) CreateOrUpdate(ctx context.Context, req *FsPayEvent) (resp *FsPayEvent, err error) {
|
||||
rowBuilder := p.db.Table(p.name).WithContext(ctx)
|
||||
if req.Id > 0 {
|
||||
err = rowBuilder.Save(req).Error
|
||||
} else {
|
||||
err = rowBuilder.Create(req).Error
|
||||
}
|
||||
return req, err
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
// fs_pay 支付记录
|
||||
type FsPay struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
PayNo *string `gorm:"default:'';" json:"pay_no"` // 支付编号
|
||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户id
|
||||
OrderNumber *string `gorm:"default:'';" json:"order_number"` // 订单编号
|
||||
TradeNo *string `gorm:"index;default:'';" json:"trade_no"` // 第三方支付编号
|
||||
|
||||
@@ -3,6 +3,7 @@ package gmodel
|
||||
import (
|
||||
"context"
|
||||
"fusenapi/utils/handler"
|
||||
"reflect"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -80,6 +81,31 @@ func (m *FsPayModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, fi
|
||||
}
|
||||
}
|
||||
|
||||
func (m *FsPayModel) FindAll(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string, orderBy string) ([]*FsPay, error) {
|
||||
var resp []*FsPay
|
||||
// 过滤
|
||||
if filterMap != nil {
|
||||
rowBuilder = rowBuilder.Scopes(handler.FilterData(filterMap))
|
||||
}
|
||||
|
||||
// 排序
|
||||
if orderBy != "" {
|
||||
var fieldsMap = make(map[string]struct{})
|
||||
s := reflect.TypeOf(&FsOrder{}).Elem() //通过反射获取type定义
|
||||
for i := 0; i < s.NumField(); i++ {
|
||||
fieldsMap[s.Field(i).Tag.Get("json")] = struct{}{}
|
||||
}
|
||||
rowBuilder = rowBuilder.Scopes(handler.OrderCheck(orderBy, fieldsMap))
|
||||
}
|
||||
|
||||
result := rowBuilder.WithContext(ctx).Find(&resp)
|
||||
if result.Error != nil {
|
||||
return nil, result.Error
|
||||
} else {
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
// 事务
|
||||
func (m *FsPayModel) Trans(ctx context.Context, fn func(ctx context.Context, connGorm *gorm.DB) error) error {
|
||||
tx := m.db.Table(m.name).WithContext(ctx).Begin()
|
||||
|
||||
@@ -24,3 +24,17 @@ func (m *FsRefundReasonModel) Update(ctx context.Context, obj *FsRefundReason) e
|
||||
func (m *FsRefundReasonModel) UpdateByRefundReasonId(ctx context.Context, obj *FsRefundReason) error {
|
||||
return m.db.WithContext(ctx).Model(obj).Where("`refund_reason_id` = ?", obj.RefundReasonId).Updates(obj).Error
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) CreateOrUpdate(ctx context.Context, req *FsRefundReason) (resp *FsRefundReason, err error) {
|
||||
rowBuilder := m.db.Table(m.name).WithContext(ctx)
|
||||
if req.Id > 0 {
|
||||
err = rowBuilder.Save(req).Error
|
||||
} else {
|
||||
err = rowBuilder.Create(req).Error
|
||||
}
|
||||
return req, err
|
||||
}
|
||||
|
||||
func (m *FsRefundReasonModel) TableName() string {
|
||||
return m.name
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ type AllModelsGen struct {
|
||||
FsOrderDetailTemplate *FsOrderDetailTemplateModel // fs_order_detail_template 订单模板详细表
|
||||
FsOrderRemark *FsOrderRemarkModel // fs_order_remark 订单备注表
|
||||
FsPay *FsPayModel // fs_pay 支付记录
|
||||
FsPayEvent *FsPayEventModel // fs_pay_event 支付回调事件日志
|
||||
FsProduct *FsProductModel // fs_product 产品表
|
||||
FsProductCopy1 *FsProductCopy1Model // fs_product_copy1 产品表
|
||||
FsProductDesign *FsProductDesignModel // fs_product_design 产品设计表
|
||||
@@ -144,6 +145,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||
FsOrderDetailTemplate: NewFsOrderDetailTemplateModel(gdb),
|
||||
FsOrderRemark: NewFsOrderRemarkModel(gdb),
|
||||
FsPay: NewFsPayModel(gdb),
|
||||
FsPayEvent: NewFsPayEventModel(gdb),
|
||||
FsProduct: NewFsProductModel(gdb),
|
||||
FsProductCopy1: NewFsProductCopy1Model(gdb),
|
||||
FsProductDesign: NewFsProductDesignModel(gdb),
|
||||
|
||||
Reference in New Issue
Block a user