v1.1
This commit is contained in:
@@ -8,9 +8,11 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
@@ -23,7 +25,7 @@ import (
|
||||
var (
|
||||
agentRebateFieldNames = builder.RawFieldNames(&AgentRebate{})
|
||||
agentRebateRows = strings.Join(agentRebateFieldNames, ",")
|
||||
agentRebateRowsExpectAutoSet = strings.Join(stringx.Remove(agentRebateFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentRebateRowsExpectAutoSet = strings.Join(stringx.Remove(agentRebateFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
agentRebateRowsWithPlaceHolder = strings.Join(stringx.Remove(agentRebateFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheYccAgentRebateIdPrefix = "cache:ycc:agentRebate:id:"
|
||||
@@ -32,7 +34,7 @@ var (
|
||||
type (
|
||||
agentRebateModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentRebate) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentRebate, error)
|
||||
FindOne(ctx context.Context, id string) (*AgentRebate, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentRebate) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentRebate) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
@@ -45,7 +47,7 @@ type (
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentRebate, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentRebate, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentRebate, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
Delete(ctx context.Context, session sqlx.Session, id string) error
|
||||
}
|
||||
|
||||
defaultAgentRebateModel struct {
|
||||
@@ -54,20 +56,20 @@ type (
|
||||
}
|
||||
|
||||
AgentRebate struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
AgentId int64 `db:"agent_id"` // 获得返佣的代理ID
|
||||
SourceAgentId int64 `db:"source_agent_id"` // 来源代理ID(推广订单的代理)
|
||||
OrderId int64 `db:"order_id"` // 订单ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID
|
||||
RebateType int64 `db:"rebate_type"` // 返佣类型:1=直接上级返佣,2=钻石上级返佣,3=黄金上级返佣
|
||||
LevelBonus float64 `db:"level_bonus"` // 等级加成金额(来源代理的等级加成)
|
||||
RebateAmount float64 `db:"rebate_amount"` // 返佣金额
|
||||
Status int64 `db:"status"` // 状态:1=已发放,2=已冻结,3=已取消
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
Id string `db:"id"`
|
||||
AgentId string `db:"agent_id"`
|
||||
SourceAgentId string `db:"source_agent_id"`
|
||||
OrderId string `db:"order_id"`
|
||||
ProductId string `db:"product_id"`
|
||||
RebateType int64 `db:"rebate_type"` // 返佣类型:1=直接上级返佣,2=钻石上级返佣,3=黄金上级返佣
|
||||
LevelBonus float64 `db:"level_bonus"` // 等级加成金额(来源代理的等级加成)
|
||||
RebateAmount float64 `db:"rebate_amount"` // 返佣金额
|
||||
Status int64 `db:"status"` // 状态:1=已发放,2=已冻结,3=已取消
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -80,17 +82,34 @@ func newAgentRebateModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentReba
|
||||
|
||||
func (m *defaultAgentRebateModel) Insert(ctx context.Context, session sqlx.Session, data *AgentRebate) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
yccAgentRebateIdKey := fmt.Sprintf("%s%v", cacheYccAgentRebateIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentRebateRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentRebateRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.SourceAgentId, data.OrderId, data.ProductId, data.RebateType, data.LevelBonus, data.RebateAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
return session.ExecCtx(ctx, query, data.Id, data.AgentId, data.SourceAgentId, data.OrderId, data.ProductId, data.RebateType, data.LevelBonus, data.RebateAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.SourceAgentId, data.OrderId, data.ProductId, data.RebateType, data.LevelBonus, data.RebateAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.AgentId, data.SourceAgentId, data.OrderId, data.ProductId, data.RebateType, data.LevelBonus, data.RebateAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}, yccAgentRebateIdKey)
|
||||
}
|
||||
func (m *defaultAgentRebateModel) insertUUID(data *AgentRebate) {
|
||||
t := reflect.TypeOf(data).Elem()
|
||||
v := reflect.ValueOf(data).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
sf := t.Field(i)
|
||||
if sf.Tag.Get("db") == "id" {
|
||||
f := v.Field(i)
|
||||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
|
||||
if f.String() == "" {
|
||||
f.SetString(uuid.NewString())
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentRebateModel) FindOne(ctx context.Context, id int64) (*AgentRebate, error) {
|
||||
func (m *defaultAgentRebateModel) FindOne(ctx context.Context, id string) (*AgentRebate, error) {
|
||||
yccAgentRebateIdKey := fmt.Sprintf("%s%v", cacheYccAgentRebateIdPrefix, id)
|
||||
var resp AgentRebate
|
||||
err := m.QueryRowCtx(ctx, &resp, yccAgentRebateIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
@@ -350,7 +369,7 @@ func (m *defaultAgentRebateModel) Trans(ctx context.Context, fn func(ctx context
|
||||
func (m *defaultAgentRebateModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentRebateModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
func (m *defaultAgentRebateModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
|
||||
yccAgentRebateIdKey := fmt.Sprintf("%s%v", cacheYccAgentRebateIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
|
||||
Reference in New Issue
Block a user