fix add
This commit is contained in:
21
app/main/api/desc/admin/admin_queue.api
Normal file
21
app/main/api/desc/admin/admin_queue.api
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
syntax = "v1"
|
||||||
|
|
||||||
|
info(
|
||||||
|
title: "Admin Queue管理"
|
||||||
|
desc: "管理员队列管理接口"
|
||||||
|
author: "team"
|
||||||
|
version: "v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
@server (
|
||||||
|
prefix: api/v1
|
||||||
|
group: admin_queue
|
||||||
|
middleware: AdminAuthInterceptor
|
||||||
|
)
|
||||||
|
service main {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -29,3 +29,4 @@ import "./admin/admin_query.api"
|
|||||||
import "./admin/admin_agent.api"
|
import "./admin/admin_agent.api"
|
||||||
import "./admin/admin_api.api"
|
import "./admin/admin_api.api"
|
||||||
import "./admin/admin_role_api.api"
|
import "./admin/admin_role_api.api"
|
||||||
|
import "./admin/admin_queue.api"
|
||||||
|
|||||||
@@ -568,6 +568,14 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
rest.WithPrefix("/api/v1/admin/query"),
|
rest.WithPrefix("/api/v1/admin/query"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
server.AddRoutes(
|
||||||
|
rest.WithMiddlewares(
|
||||||
|
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||||
|
[]rest.Route{}...,
|
||||||
|
),
|
||||||
|
rest.WithPrefix("/api/v1"),
|
||||||
|
)
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
rest.WithMiddlewares(
|
rest.WithMiddlewares(
|
||||||
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
[]rest.Middleware{serverCtx.AdminAuthInterceptor},
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package queue
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"tydata-server/app/main/api/internal/svc"
|
"tydata-server/app/main/api/internal/svc"
|
||||||
"tydata-server/app/main/api/internal/types"
|
"tydata-server/app/main/api/internal/types"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
)
|
)
|
||||||
@@ -24,17 +24,28 @@ func NewCronJob(ctx context.Context, svcCtx *svc.ServiceContext) *CronJob {
|
|||||||
func (l *CronJob) Register() *asynq.ServeMux {
|
func (l *CronJob) Register() *asynq.ServeMux {
|
||||||
redisClientOpt := asynq.RedisClientOpt{Addr: l.svcCtx.Config.CacheRedis[0].Host, Password: l.svcCtx.Config.CacheRedis[0].Pass}
|
redisClientOpt := asynq.RedisClientOpt{Addr: l.svcCtx.Config.CacheRedis[0].Host, Password: l.svcCtx.Config.CacheRedis[0].Pass}
|
||||||
scheduler := asynq.NewScheduler(redisClientOpt, nil)
|
scheduler := asynq.NewScheduler(redisClientOpt, nil)
|
||||||
|
|
||||||
|
// 注册清理查询数据任务
|
||||||
task := asynq.NewTask(types.MsgCleanQueryData, nil, nil)
|
task := asynq.NewTask(types.MsgCleanQueryData, nil, nil)
|
||||||
_, err := scheduler.Register(TASKTIME, task)
|
_, err := scheduler.Register(TASKTIME, task)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("定时任务注册失败:%v", err))
|
panic(fmt.Sprintf("定时任务注册失败:%v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 注释掉原来的佣金解冻定时任务,因为现在改为按需处理单个佣金记录
|
||||||
|
// unfreezeTask := asynq.NewTask(types.MsgUnfreezeCommission, nil, nil)
|
||||||
|
// _, err = scheduler.Register("0 4 * * *", unfreezeTask)
|
||||||
|
// if err != nil {
|
||||||
|
// panic(fmt.Sprintf("佣金解冻任务注册失败:%v", err))
|
||||||
|
// }
|
||||||
|
|
||||||
scheduler.Start()
|
scheduler.Start()
|
||||||
fmt.Println("定时任务启动!!!")
|
fmt.Println("定时任务启动!!!")
|
||||||
|
|
||||||
mux := asynq.NewServeMux()
|
mux := asynq.NewServeMux()
|
||||||
mux.Handle(types.MsgPaySuccessQuery, NewPaySuccessNotifyUserHandler(l.svcCtx))
|
mux.Handle(types.MsgPaySuccessQuery, NewPaySuccessNotifyUserHandler(l.svcCtx))
|
||||||
mux.Handle(types.MsgCleanQueryData, NewCleanQueryDataHandler(l.svcCtx))
|
mux.Handle(types.MsgCleanQueryData, NewCleanQueryDataHandler(l.svcCtx))
|
||||||
|
mux.Handle(types.MsgUnfreezeCommission, NewUnfreezeCommissionHandler(l.svcCtx))
|
||||||
|
|
||||||
return mux
|
return mux
|
||||||
}
|
}
|
||||||
|
|||||||
119
app/main/api/internal/queue/unfreezeCommission.go
Normal file
119
app/main/api/internal/queue/unfreezeCommission.go
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
package queue
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"tydata-server/app/main/api/internal/svc"
|
||||||
|
"tydata-server/app/main/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/hibiken/asynq"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 定义佣金状态常量
|
||||||
|
const (
|
||||||
|
CommissionStatusReleased = 0 // 已发放
|
||||||
|
CommissionStatusFrozen = 1 // 冻结佣金
|
||||||
|
)
|
||||||
|
|
||||||
|
// UNFREEZE_COMMISSION_DELAY_DAYS 定义延迟解冻天数
|
||||||
|
const UNFREEZE_COMMISSION_DELAY_DAYS = 3 // 三天后解冻
|
||||||
|
|
||||||
|
type UnfreezeCommissionHandler struct {
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnfreezeCommissionHandler(svcCtx *svc.ServiceContext) *UnfreezeCommissionHandler {
|
||||||
|
return &UnfreezeCommissionHandler{
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UnfreezeCommissionHandler) ProcessTask(ctx context.Context, t *asynq.Task) error {
|
||||||
|
now := time.Now()
|
||||||
|
logx.Infof("%s - 开始执行佣金解冻任务", now.Format("2006-01-02 15:04:05"))
|
||||||
|
|
||||||
|
// 解析任务payload,获取佣金ID
|
||||||
|
var payload types.MsgUnfreezeCommissionPayload
|
||||||
|
if err := json.Unmarshal(t.Payload(), &payload); err != nil {
|
||||||
|
logx.Errorf("解析佣金解冻任务payload失败: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
commissionID := payload.CommissionID
|
||||||
|
if commissionID <= 0 {
|
||||||
|
logx.Errorf("无效的佣金ID: %d", commissionID)
|
||||||
|
return fmt.Errorf("无效的佣金ID: %d", commissionID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据佣金ID查询特定佣金记录
|
||||||
|
commission, err := l.svcCtx.AgentCommissionModel.FindOne(ctx, commissionID)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("查询佣金记录ID %d 失败: %v", commissionID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查佣金状态是否为冻结状态
|
||||||
|
if commission.Status != CommissionStatusFrozen {
|
||||||
|
logx.Infof("佣金记录ID %d 状态不是冻结状态,当前状态: %d,无需处理", commissionID, commission.Status)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否已到达解冻时间(3天后)
|
||||||
|
unfreezeTime := commission.UpdateTime.AddDate(0, 0, UNFREEZE_COMMISSION_DELAY_DAYS)
|
||||||
|
if now.Before(unfreezeTime) {
|
||||||
|
logx.Infof("佣金记录ID %d 尚未到达解冻时间,解冻时间: %s", commissionID, unfreezeTime.Format("2006-01-02 15:04:05"))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用事务处理解冻操作
|
||||||
|
err = l.svcCtx.AgentCommissionModel.Trans(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
// 更新佣金状态为已发放
|
||||||
|
commission.Status = CommissionStatusReleased
|
||||||
|
commission.UpdateTime = now
|
||||||
|
|
||||||
|
// 更新佣金数据库
|
||||||
|
_, err := l.svcCtx.AgentCommissionModel.Update(ctx, session, commission)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("更新佣金记录ID %d 失败: %v", commissionID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取代理钱包记录
|
||||||
|
agentWallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(ctx, commission.AgentId)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("查询代理ID %d 的钱包记录失败: %v", commission.AgentId, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新钱包余额:增加佣金金额到balance,减少相应的frozen_balance
|
||||||
|
// 注意:这里应该转移的是当前佣金记录的金额,而不是全部冻结余额
|
||||||
|
commissionAmount := commission.Amount
|
||||||
|
agentWallet.Balance += commissionAmount
|
||||||
|
agentWallet.FrozenBalance -= commissionAmount
|
||||||
|
agentWallet.UpdateTime = now
|
||||||
|
|
||||||
|
// 更新钱包数据库
|
||||||
|
_, err = l.svcCtx.AgentWalletModel.Update(ctx, session, agentWallet)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("更新代理ID %d 的钱包记录失败: %v", commission.AgentId, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logx.Infof("成功解冻佣金记录ID %d,代理ID %d,佣金金额 %.2f,已将佣金金额从冻结余额转移到可用余额",
|
||||||
|
commissionID, commission.AgentId, commissionAmount)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("%s - 佣金解冻任务失败: %v", now.Format("2006-01-02 15:04:05"), err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logx.Infof("%s - 佣金解冻任务完成,佣金ID: %d", now.Format("2006-01-02 15:04:05"), commissionID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -2,11 +2,14 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"tydata-server/app/main/api/internal/config"
|
"tydata-server/app/main/api/internal/config"
|
||||||
"tydata-server/app/main/model"
|
"tydata-server/app/main/model"
|
||||||
|
"tydata-server/common/globalkey"
|
||||||
"tydata-server/pkg/lzkit/lzUtils"
|
"tydata-server/pkg/lzkit/lzUtils"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,6 +32,7 @@ type AgentService struct {
|
|||||||
AgentPlatformDeductionModel model.AgentPlatformDeductionModel
|
AgentPlatformDeductionModel model.AgentPlatformDeductionModel
|
||||||
AgentActiveStatModel model.AgentActiveStatModel
|
AgentActiveStatModel model.AgentActiveStatModel
|
||||||
AgentWithdrawalModel model.AgentWithdrawalModel
|
AgentWithdrawalModel model.AgentWithdrawalModel
|
||||||
|
AsynqService *AsynqService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAgentService(c config.Config, orderModel model.OrderModel, agentModel model.AgentModel, agentAuditModel model.AgentAuditModel,
|
func NewAgentService(c config.Config, orderModel model.OrderModel, agentModel model.AgentModel, agentAuditModel model.AgentAuditModel,
|
||||||
@@ -38,7 +42,7 @@ func NewAgentService(c config.Config, orderModel model.OrderModel, agentModel mo
|
|||||||
agentMembershipRechargeOrderModel model.AgentMembershipRechargeOrderModel,
|
agentMembershipRechargeOrderModel model.AgentMembershipRechargeOrderModel,
|
||||||
agentMembershipUserConfigModel model.AgentMembershipUserConfigModel,
|
agentMembershipUserConfigModel model.AgentMembershipUserConfigModel,
|
||||||
agentProductConfigModel model.AgentProductConfigModel, agentPlatformDeductionModel model.AgentPlatformDeductionModel,
|
agentProductConfigModel model.AgentProductConfigModel, agentPlatformDeductionModel model.AgentPlatformDeductionModel,
|
||||||
agentActiveStatModel model.AgentActiveStatModel, agentWithdrawalModel model.AgentWithdrawalModel) *AgentService {
|
agentActiveStatModel model.AgentActiveStatModel, agentWithdrawalModel model.AgentWithdrawalModel, asynqService *AsynqService) *AgentService {
|
||||||
|
|
||||||
return &AgentService{
|
return &AgentService{
|
||||||
config: c,
|
config: c,
|
||||||
@@ -59,6 +63,7 @@ func NewAgentService(c config.Config, orderModel model.OrderModel, agentModel mo
|
|||||||
AgentPlatformDeductionModel: agentPlatformDeductionModel,
|
AgentPlatformDeductionModel: agentPlatformDeductionModel,
|
||||||
AgentActiveStatModel: agentActiveStatModel,
|
AgentActiveStatModel: agentActiveStatModel,
|
||||||
AgentWithdrawalModel: agentWithdrawalModel,
|
AgentWithdrawalModel: agentWithdrawalModel,
|
||||||
|
AsynqService: asynqService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,34 +118,49 @@ func (l *AgentService) AgentProcess(ctx context.Context, order *model.Order) err
|
|||||||
return findAgentMembersipConfigModelErr
|
return findAgentMembersipConfigModelErr
|
||||||
}
|
}
|
||||||
// 定价
|
// 定价
|
||||||
commissionCost, commissionCostErr := l.CommissionCost(transCtx, agentID, AncestorId, AgentMembershipConfigModel, order.ProductId, session)
|
commissionCost, commissionCostErr := l.CommissionCost(transCtx, agentID, AncestorId, AgentMembershipConfigModel, order.ProductId, order.Id, session)
|
||||||
if commissionCostErr != nil {
|
if commissionCostErr != nil {
|
||||||
return commissionCostErr
|
return commissionCostErr
|
||||||
}
|
}
|
||||||
// 提价
|
// 提价
|
||||||
commissionPricing, commissionPricingErr := l.CommissionPricing(transCtx, agentID, AncestorId, AgentMembershipConfigModel, order.ProductId, order.Amount, session)
|
commissionPricing, commissionPricingErr := l.CommissionPricing(transCtx, agentID, AncestorId, AgentMembershipConfigModel, order.ProductId, order.Amount, order.Id, session)
|
||||||
if commissionPricingErr != nil {
|
if commissionPricingErr != nil {
|
||||||
return commissionPricingErr
|
return commissionPricingErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上级克扣的成本
|
// 上级克扣的成本
|
||||||
descendantDeductedAmount = commissionCost + commissionPricing
|
descendantDeductedAmount = commissionCost + commissionPricing
|
||||||
|
// 奖励
|
||||||
// 佣金
|
|
||||||
ancestorCommissionReward, ancestorCommissionErr := l.AncestorCommission(transCtx, agentID, AncestorId, session)
|
ancestorCommissionReward, ancestorCommissionErr := l.AncestorCommission(transCtx, agentID, AncestorId, session)
|
||||||
if ancestorCommissionErr != nil {
|
if ancestorCommissionErr != nil {
|
||||||
return ancestorCommissionErr
|
return ancestorCommissionErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// 给上级成本以及佣金
|
// 给上级成本以及佣金
|
||||||
ancestorCommissionAmount := commissionCost + commissionPricing + ancestorCommissionReward
|
ancestorCommissionAmount := commissionCost + commissionPricing
|
||||||
ancestorWallet, findAgentWalletModelErr := l.AgentWalletModel.FindOneByAgentId(transCtx, AncestorId)
|
ancestorWallet, findAgentWalletModelErr := l.AgentWalletModel.FindOneByAgentId(transCtx, AncestorId)
|
||||||
if findAgentWalletModelErr != nil {
|
if findAgentWalletModelErr != nil {
|
||||||
return findAgentWalletModelErr
|
return findAgentWalletModelErr
|
||||||
}
|
}
|
||||||
|
// 奖励不冻结
|
||||||
|
ancestorWallet.Balance += ancestorCommissionReward
|
||||||
|
|
||||||
ancestorWallet.Balance += ancestorCommissionAmount
|
// 冻结
|
||||||
ancestorWallet.TotalEarnings += ancestorCommissionAmount
|
ancestorWallet.FrozenBalance += ancestorCommissionAmount
|
||||||
|
|
||||||
|
// 为上级创建佣金记录(冻结金额)
|
||||||
|
ancestorCommissionRecord := model.AgentCommission{
|
||||||
|
AgentId: AncestorId,
|
||||||
|
OrderId: order.Id,
|
||||||
|
Amount: ancestorCommissionAmount,
|
||||||
|
ProductId: order.ProductId,
|
||||||
|
}
|
||||||
|
_, insertAncestorCommissionErr := l.AgentCommissionModel.Insert(transCtx, session, &ancestorCommissionRecord)
|
||||||
|
if insertAncestorCommissionErr != nil {
|
||||||
|
return insertAncestorCommissionErr
|
||||||
|
}
|
||||||
|
|
||||||
|
ancestorWallet.TotalEarnings += ancestorCommissionAmount + ancestorCommissionReward
|
||||||
updateErr := l.AgentWalletModel.UpdateWithVersion(transCtx, session, ancestorWallet)
|
updateErr := l.AgentWalletModel.UpdateWithVersion(transCtx, session, ancestorWallet)
|
||||||
if updateErr != nil {
|
if updateErr != nil {
|
||||||
return updateErr
|
return updateErr
|
||||||
@@ -161,6 +181,37 @@ func (l *AgentService) AgentProcess(ctx context.Context, order *model.Order) err
|
|||||||
return transErr
|
return transErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 在事务提交后,触发解冻任务(3天后自动解冻)
|
||||||
|
// 注意:这里发送的是任务,实际解冻将在3天后由队列处理
|
||||||
|
if l.AsynqService != nil {
|
||||||
|
// 获取刚创建的佣金记录ID
|
||||||
|
// 由于我们需要佣金记录ID来触发解冻任务,但事务中无法获取,我们可以在事务后查询
|
||||||
|
builder := l.AgentCommissionModel.SelectBuilder().
|
||||||
|
Where("order_id = ?", order.Id).
|
||||||
|
Where("del_state = ?", globalkey.DelStateNo)
|
||||||
|
|
||||||
|
commissions, findErr := l.AgentCommissionModel.FindAll(ctx, builder, "")
|
||||||
|
if findErr != nil {
|
||||||
|
logx.Errorf("查询刚创建的佣金记录失败,订单ID: %d, 错误: %v", order.Id, findErr)
|
||||||
|
return findErr
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commissions) > 0 {
|
||||||
|
// 为所有新创建的佣金记录触发解冻任务
|
||||||
|
for _, commission := range commissions {
|
||||||
|
// 发送解冻任务,将在3天后执行
|
||||||
|
sendTaskErr := l.AsynqService.SendUnfreezeCommissionTask(commission.Id)
|
||||||
|
if sendTaskErr != nil {
|
||||||
|
logx.Errorf("发送佣金解冻任务失败,佣金ID: %d, 错误: %v", commission.Id, sendTaskErr)
|
||||||
|
// 不返回错误,因为佣金记录已创建成功,只是解冻任务失败
|
||||||
|
} else {
|
||||||
|
logx.Infof("已发送佣金解冻任务,佣金ID: %d, 代理ID: %d, 金额: %.2f",
|
||||||
|
commission.Id, commission.AgentId, commission.Amount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +223,7 @@ func (l *AgentService) AgentCommission(ctx context.Context, agentID int64, order
|
|||||||
}
|
}
|
||||||
// 推广人最终获得代理佣金
|
// 推广人最终获得代理佣金
|
||||||
finalCommission := order.Amount - deductedAmount
|
finalCommission := order.Amount - deductedAmount
|
||||||
agentWalletModel.Balance += finalCommission
|
agentWalletModel.FrozenBalance += finalCommission
|
||||||
agentWalletModel.TotalEarnings += finalCommission
|
agentWalletModel.TotalEarnings += finalCommission
|
||||||
|
|
||||||
agentCommission := model.AgentCommission{
|
agentCommission := model.AgentCommission{
|
||||||
@@ -181,11 +232,18 @@ func (l *AgentService) AgentCommission(ctx context.Context, agentID int64, order
|
|||||||
Amount: finalCommission,
|
Amount: finalCommission,
|
||||||
ProductId: order.ProductId,
|
ProductId: order.ProductId,
|
||||||
}
|
}
|
||||||
_, insertAgentCommissionErr := l.AgentCommissionModel.Insert(ctx, session, &agentCommission)
|
insertResult, insertAgentCommissionErr := l.AgentCommissionModel.Insert(ctx, session, &agentCommission)
|
||||||
if insertAgentCommissionErr != nil {
|
if insertAgentCommissionErr != nil {
|
||||||
return insertAgentCommissionErr
|
return insertAgentCommissionErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取新插入的佣金记录ID(用于日志记录)
|
||||||
|
commissionID, err := insertResult.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_ = commissionID // 暂时忽略该变量,因为我们使用其他方式获取佣金记录
|
||||||
|
|
||||||
updateAgentWalletErr := l.AgentWalletModel.UpdateWithVersion(ctx, session, agentWalletModel)
|
updateAgentWalletErr := l.AgentWalletModel.UpdateWithVersion(ctx, session, agentWalletModel)
|
||||||
if updateAgentWalletErr != nil {
|
if updateAgentWalletErr != nil {
|
||||||
return updateAgentWalletErr
|
return updateAgentWalletErr
|
||||||
@@ -270,7 +328,7 @@ func (l *AgentService) PlatformPricing(ctx context.Context, agentID int64, order
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommissionCost 上级底价成本
|
// CommissionCost 上级底价成本
|
||||||
func (l *AgentService) CommissionCost(ctx context.Context, descendantId int64, AncestorId int64, agentMembershipConfigModel *model.AgentMembershipConfig, productID int64, session sqlx.Session) (float64, error) {
|
func (l *AgentService) CommissionCost(ctx context.Context, descendantId int64, AncestorId int64, agentMembershipConfigModel *model.AgentMembershipConfig, productID int64, orderId int64, session sqlx.Session) (float64, error) {
|
||||||
if agentMembershipConfigModel.PriceIncreaseAmount.Valid {
|
if agentMembershipConfigModel.PriceIncreaseAmount.Valid {
|
||||||
// 拥有则查看该上级设定的成本
|
// 拥有则查看该上级设定的成本
|
||||||
agentMembershipUserConfigModel, findAgentMembershipUserConfigModelErr := l.AgentMembershipUserConfigModel.FindOneByAgentIdProductId(ctx, AncestorId, productID)
|
agentMembershipUserConfigModel, findAgentMembershipUserConfigModelErr := l.AgentMembershipUserConfigModel.FindOneByAgentIdProductId(ctx, AncestorId, productID)
|
||||||
@@ -290,6 +348,7 @@ func (l *AgentService) CommissionCost(ctx context.Context, descendantId int64, A
|
|||||||
Amount: deductCostAmount,
|
Amount: deductCostAmount,
|
||||||
Type: model.AgentDeductionTypeCost,
|
Type: model.AgentDeductionTypeCost,
|
||||||
ProductId: productID,
|
ProductId: productID,
|
||||||
|
OrderId: sql.NullInt64{Int64: orderId, Valid: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, insertAgentCommissionDeductionModelErr := l.AgentCommissionDeductionModel.Insert(ctx, session, &agentCommissionDeductionModel)
|
_, insertAgentCommissionDeductionModelErr := l.AgentCommissionDeductionModel.Insert(ctx, session, &agentCommissionDeductionModel)
|
||||||
@@ -303,7 +362,7 @@ func (l *AgentService) CommissionCost(ctx context.Context, descendantId int64, A
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CommissionPricing 上级提价成本
|
// CommissionPricing 上级提价成本
|
||||||
func (l *AgentService) CommissionPricing(ctx context.Context, descendantId int64, AncestorId int64, agentMembershipConfigModel *model.AgentMembershipConfig, productID int64, pricing float64, session sqlx.Session) (float64, error) {
|
func (l *AgentService) CommissionPricing(ctx context.Context, descendantId int64, AncestorId int64, agentMembershipConfigModel *model.AgentMembershipConfig, productID int64, pricing float64, orderId int64, session sqlx.Session) (float64, error) {
|
||||||
//看上级代理等级否有拥有定价标准收益功能
|
//看上级代理等级否有拥有定价标准收益功能
|
||||||
if agentMembershipConfigModel.PriceIncreaseMax.Valid && agentMembershipConfigModel.PriceRatio.Valid {
|
if agentMembershipConfigModel.PriceIncreaseMax.Valid && agentMembershipConfigModel.PriceRatio.Valid {
|
||||||
// 拥有则查看该上级设定的成本
|
// 拥有则查看该上级设定的成本
|
||||||
@@ -334,6 +393,7 @@ func (l *AgentService) CommissionPricing(ctx context.Context, descendantId int64
|
|||||||
Amount: deductCostAmount,
|
Amount: deductCostAmount,
|
||||||
Type: model.AgentDeductionTypePricing,
|
Type: model.AgentDeductionTypePricing,
|
||||||
ProductId: productID,
|
ProductId: productID,
|
||||||
|
OrderId: sql.NullInt64{Int64: orderId, Valid: true},
|
||||||
}
|
}
|
||||||
_, insertAgentCommissionDeductionModelErr := l.AgentCommissionDeductionModel.Insert(ctx, session, &agentCommissionDeductionModel)
|
_, insertAgentCommissionDeductionModelErr := l.AgentCommissionDeductionModel.Insert(ctx, session, &agentCommissionDeductionModel)
|
||||||
if insertAgentCommissionDeductionModelErr != nil {
|
if insertAgentCommissionDeductionModelErr != nil {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"tydata-server/app/main/api/internal/config"
|
"tydata-server/app/main/api/internal/config"
|
||||||
"tydata-server/app/main/api/internal/types"
|
"tydata-server/app/main/api/internal/types"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
@@ -58,3 +58,32 @@ func (s *AsynqService) SendQueryTask(orderID int64) error {
|
|||||||
logx.Infof("发送异步任务成功,任务ID: %s, 队列: %s, 订单号: %d", info.ID, info.Queue, orderID)
|
logx.Infof("发送异步任务成功,任务ID: %s, 队列: %s, 订单号: %d", info.ID, info.Queue, orderID)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendUnfreezeCommissionTask 发送佣金解冻任务
|
||||||
|
func (s *AsynqService) SendUnfreezeCommissionTask(commissionID int64) error {
|
||||||
|
// 准备任务的 payload
|
||||||
|
payload := types.MsgUnfreezeCommissionPayload{
|
||||||
|
CommissionID: commissionID,
|
||||||
|
}
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("发送佣金解冻任务失败 (无法编码 payload): %v, 佣金ID: %d", err, commissionID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := []asynq.Option{
|
||||||
|
asynq.MaxRetry(5), // 设置最大重试次数
|
||||||
|
}
|
||||||
|
task := asynq.NewTask(types.MsgUnfreezeCommission, payloadBytes, options...)
|
||||||
|
|
||||||
|
// 将任务加入队列并获取任务信息
|
||||||
|
info, err := s.client.Enqueue(task)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("发送佣金解冻任务失败 (加入队列失败): %+v, 佣金ID: %d", err, commissionID)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录成功日志,带上任务 ID 和队列信息
|
||||||
|
logx.Infof("发送佣金解冻任务成功,任务ID: %s, 队列: %s, 佣金ID: %d", info.ID, info.Queue, commissionID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
agentCommissionModel, agentCommissionDeductionModel, agentWalletModel, agentLinkModel,
|
agentCommissionModel, agentCommissionDeductionModel, agentWalletModel, agentLinkModel,
|
||||||
agentOrderModel, agentRewardsModel, agentMembershipConfigModel, agentMembershipRechargeOrderModel,
|
agentOrderModel, agentRewardsModel, agentMembershipConfigModel, agentMembershipRechargeOrderModel,
|
||||||
agentMembershipUserConfigModel, agentProductConfigModel, agentPlatformDeductionModel,
|
agentMembershipUserConfigModel, agentProductConfigModel, agentPlatformDeductionModel,
|
||||||
agentActiveStatModel, agentWithdrawalModel)
|
agentActiveStatModel, agentWithdrawalModel, asynqService)
|
||||||
userService := service.NewUserService(&c, userModel, userAuthModel, userTempModel, agentModel)
|
userService := service.NewUserService(&c, userModel, userAuthModel, userTempModel, agentModel)
|
||||||
dictService := service.NewDictService(adminDictTypeModel, adminDictDataModel)
|
dictService := service.NewDictService(adminDictTypeModel, adminDictDataModel)
|
||||||
adminPromotionLinkStatsService := service.NewAdminPromotionLinkStatsService(adminPromotionLinkModel,
|
adminPromotionLinkStatsService := service.NewAdminPromotionLinkStatsService(adminPromotionLinkModel,
|
||||||
|
|||||||
@@ -3,3 +3,7 @@ package types
|
|||||||
type MsgPaySuccessQueryPayload struct {
|
type MsgPaySuccessQueryPayload struct {
|
||||||
OrderID int64 `json:"order_id"`
|
OrderID int64 `json:"order_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MsgUnfreezeCommissionPayload struct {
|
||||||
|
CommissionID int64 `json:"commission_id"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ package types
|
|||||||
|
|
||||||
const MsgPaySuccessQuery = "msg:pay_success:query"
|
const MsgPaySuccessQuery = "msg:pay_success:query"
|
||||||
const MsgCleanQueryData = "msg:clean_query_data"
|
const MsgCleanQueryData = "msg:clean_query_data"
|
||||||
|
const MsgUnfreezeCommission = "msg:unfreeze_commission"
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"tydata-server/common/globalkey"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"tydata-server/common/globalkey"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ var (
|
|||||||
agentCommissionDeductionRowsExpectAutoSet = strings.Join(stringx.Remove(agentCommissionDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
agentCommissionDeductionRowsExpectAutoSet = strings.Join(stringx.Remove(agentCommissionDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
agentCommissionDeductionRowsWithPlaceHolder = strings.Join(stringx.Remove(agentCommissionDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
agentCommissionDeductionRowsWithPlaceHolder = strings.Join(stringx.Remove(agentCommissionDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
cacheHmAgentCommissionDeductionIdPrefix = "cache:tydata:agentCommissionDeduction:id:"
|
cacheTydataAgentCommissionDeductionIdPrefix = "cache:tydata:agentCommissionDeduction:id:"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -55,18 +55,19 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
AgentCommissionDeduction struct {
|
AgentCommissionDeduction struct {
|
||||||
Id int64 `db:"id"`
|
Id int64 `db:"id"`
|
||||||
AgentId int64 `db:"agent_id"`
|
AgentId int64 `db:"agent_id"`
|
||||||
DeductedAgentId int64 `db:"deducted_agent_id"` // 被抽佣代理ID
|
DeductedAgentId int64 `db:"deducted_agent_id"` // 被抽佣代理ID
|
||||||
Amount float64 `db:"amount"`
|
Amount float64 `db:"amount"`
|
||||||
ProductId int64 `db:"product_id"` // 产品ID
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
Type string `db:"type"`
|
OrderId sql.NullInt64 `db:"order_id"` // 关联订单ID
|
||||||
Status int64 `db:"status"` // 状态
|
Type string `db:"type"`
|
||||||
CreateTime time.Time `db:"create_time"`
|
Status int64 `db:"status"` // 状态
|
||||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
CreateTime time.Time `db:"create_time"`
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
DelState int64 `db:"del_state"` // 删除状态
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
Version int64 `db:"version"` // 版本号
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
|
Version int64 `db:"version"` // 版本号
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -79,20 +80,20 @@ func newAgentCommissionDeductionModel(conn sqlx.SqlConn, c cache.CacheConf) *def
|
|||||||
|
|
||||||
func (m *defaultAgentCommissionDeductionModel) Insert(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error) {
|
func (m *defaultAgentCommissionDeductionModel) Insert(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error) {
|
||||||
data.DelState = globalkey.DelStateNo
|
data.DelState = globalkey.DelStateNo
|
||||||
hmAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheHmAgentCommissionDeductionIdPrefix, data.Id)
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
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, agentCommissionDeductionRowsExpectAutoSet)
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentCommissionDeductionRowsExpectAutoSet)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||||
}, hmAgentCommissionDeductionIdKey)
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultAgentCommissionDeductionModel) FindOne(ctx context.Context, id int64) (*AgentCommissionDeduction, error) {
|
func (m *defaultAgentCommissionDeductionModel) FindOne(ctx context.Context, id int64) (*AgentCommissionDeduction, error) {
|
||||||
hmAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheHmAgentCommissionDeductionIdPrefix, id)
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, id)
|
||||||
var resp AgentCommissionDeduction
|
var resp AgentCommissionDeduction
|
||||||
err := m.QueryRowCtx(ctx, &resp, hmAgentCommissionDeductionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
err := m.QueryRowCtx(ctx, &resp, tydataAgentCommissionDeductionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentCommissionDeductionRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentCommissionDeductionRows, m.table)
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
})
|
})
|
||||||
@@ -107,14 +108,14 @@ func (m *defaultAgentCommissionDeductionModel) FindOne(ctx context.Context, id i
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultAgentCommissionDeductionModel) Update(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error) {
|
func (m *defaultAgentCommissionDeductionModel) Update(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error) {
|
||||||
hmAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheHmAgentCommissionDeductionIdPrefix, data.Id)
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, data.Id)
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, agentCommissionDeductionRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, agentCommissionDeductionRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||||
}, hmAgentCommissionDeductionIdKey)
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *defaultAgentCommissionDeductionModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) error {
|
func (m *defaultAgentCommissionDeductionModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) error {
|
||||||
@@ -125,14 +126,14 @@ func (m *defaultAgentCommissionDeductionModel) UpdateWithVersion(ctx context.Con
|
|||||||
var sqlResult sql.Result
|
var sqlResult sql.Result
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
hmAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheHmAgentCommissionDeductionIdPrefix, data.Id)
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, data.Id)
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, agentCommissionDeductionRowsWithPlaceHolder)
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, agentCommissionDeductionRowsWithPlaceHolder)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||||
}, hmAgentCommissionDeductionIdKey)
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -350,18 +351,18 @@ func (m *defaultAgentCommissionDeductionModel) SelectBuilder() squirrel.SelectBu
|
|||||||
return squirrel.Select().From(m.table)
|
return squirrel.Select().From(m.table)
|
||||||
}
|
}
|
||||||
func (m *defaultAgentCommissionDeductionModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
func (m *defaultAgentCommissionDeductionModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
hmAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheHmAgentCommissionDeductionIdPrefix, id)
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, id)
|
||||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
_, 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)
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||||
if session != nil {
|
if session != nil {
|
||||||
return session.ExecCtx(ctx, query, id)
|
return session.ExecCtx(ctx, query, id)
|
||||||
}
|
}
|
||||||
return conn.ExecCtx(ctx, query, id)
|
return conn.ExecCtx(ctx, query, id)
|
||||||
}, hmAgentCommissionDeductionIdKey)
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (m *defaultAgentCommissionDeductionModel) formatPrimary(primary interface{}) string {
|
func (m *defaultAgentCommissionDeductionModel) formatPrimary(primary interface{}) string {
|
||||||
return fmt.Sprintf("%s%v", cacheHmAgentCommissionDeductionIdPrefix, primary)
|
return fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, primary)
|
||||||
}
|
}
|
||||||
func (m *defaultAgentCommissionDeductionModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
func (m *defaultAgentCommissionDeductionModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentCommissionDeductionRows, m.table)
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentCommissionDeductionRows, m.table)
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ $tables = @(
|
|||||||
# "agent_audit",
|
# "agent_audit",
|
||||||
# "agent_closure",
|
# "agent_closure",
|
||||||
# "agent_commission",
|
# "agent_commission",
|
||||||
# "agent_commission_deduction",
|
"agent_commission_deduction"
|
||||||
# "agent_link",
|
# "agent_link",
|
||||||
# "agent_membership_config",
|
# "agent_membership_config",
|
||||||
# "agent_membership_recharge_order"
|
# "agent_membership_recharge_order"
|
||||||
# "agent_membership_user_config",
|
# "agent_membership_user_config",
|
||||||
# "agent_order",
|
# "agent_order",
|
||||||
"agent_platform_deduction"
|
# "agent_platform_deduction"
|
||||||
# "agent_product_config",
|
# "agent_product_config",
|
||||||
# "agent_rewards",
|
# "agent_rewards",
|
||||||
# "agent_wallet",
|
# "agent_wallet",
|
||||||
|
|||||||
27
deploy/script/model/agentCommissionDeductionModel.go
Normal file
27
deploy/script/model/agentCommissionDeductionModel.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ AgentCommissionDeductionModel = (*customAgentCommissionDeductionModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// AgentCommissionDeductionModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customAgentCommissionDeductionModel.
|
||||||
|
AgentCommissionDeductionModel interface {
|
||||||
|
agentCommissionDeductionModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customAgentCommissionDeductionModel struct {
|
||||||
|
*defaultAgentCommissionDeductionModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewAgentCommissionDeductionModel returns a model for the database table.
|
||||||
|
func NewAgentCommissionDeductionModel(conn sqlx.SqlConn, c cache.CacheConf) AgentCommissionDeductionModel {
|
||||||
|
return &customAgentCommissionDeductionModel{
|
||||||
|
defaultAgentCommissionDeductionModel: newAgentCommissionDeductionModel(conn, c),
|
||||||
|
}
|
||||||
|
}
|
||||||
373
deploy/script/model/agentCommissionDeductionModel_gen.go
Normal file
373
deploy/script/model/agentCommissionDeductionModel_gen.go
Normal file
@@ -0,0 +1,373 @@
|
|||||||
|
// Code generated by goctl. DO NOT EDIT!
|
||||||
|
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stringx"
|
||||||
|
"tydata-server/common/globalkey"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
agentCommissionDeductionFieldNames = builder.RawFieldNames(&AgentCommissionDeduction{})
|
||||||
|
agentCommissionDeductionRows = strings.Join(agentCommissionDeductionFieldNames, ",")
|
||||||
|
agentCommissionDeductionRowsExpectAutoSet = strings.Join(stringx.Remove(agentCommissionDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||||
|
agentCommissionDeductionRowsWithPlaceHolder = strings.Join(stringx.Remove(agentCommissionDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cacheTydataAgentCommissionDeductionIdPrefix = "cache:tydata:agentCommissionDeduction:id:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
agentCommissionDeductionModel interface {
|
||||||
|
Insert(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*AgentCommissionDeduction, error)
|
||||||
|
Update(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error)
|
||||||
|
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) error
|
||||||
|
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||||
|
SelectBuilder() squirrel.SelectBuilder
|
||||||
|
DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) error
|
||||||
|
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||||
|
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||||
|
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AgentCommissionDeduction, error)
|
||||||
|
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommissionDeduction, error)
|
||||||
|
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommissionDeduction, int64, error)
|
||||||
|
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentCommissionDeduction, error)
|
||||||
|
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentCommissionDeduction, error)
|
||||||
|
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultAgentCommissionDeductionModel struct {
|
||||||
|
sqlc.CachedConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
AgentCommissionDeduction struct {
|
||||||
|
Id int64 `db:"id"`
|
||||||
|
AgentId int64 `db:"agent_id"`
|
||||||
|
DeductedAgentId int64 `db:"deducted_agent_id"` // 被抽佣代理ID
|
||||||
|
Amount float64 `db:"amount"`
|
||||||
|
ProductId int64 `db:"product_id"` // 产品ID
|
||||||
|
OrderId sql.NullInt64 `db:"order_id"` // 关联订单ID
|
||||||
|
Type string `db:"type"`
|
||||||
|
Status int64 `db:"status"` // 状态
|
||||||
|
CreateTime time.Time `db:"create_time"`
|
||||||
|
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||||
|
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||||
|
DelState int64 `db:"del_state"` // 删除状态
|
||||||
|
Version int64 `db:"version"` // 版本号
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newAgentCommissionDeductionModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentCommissionDeductionModel {
|
||||||
|
return &defaultAgentCommissionDeductionModel{
|
||||||
|
CachedConn: sqlc.NewConn(conn, c),
|
||||||
|
table: "`agent_commission_deduction`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) Insert(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error) {
|
||||||
|
data.DelState = globalkey.DelStateNo
|
||||||
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, 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, agentCommissionDeductionRowsExpectAutoSet)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||||
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindOne(ctx context.Context, id int64) (*AgentCommissionDeduction, error) {
|
||||||
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, id)
|
||||||
|
var resp AgentCommissionDeduction
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, tydataAgentCommissionDeductionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentCommissionDeductionRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||||
|
})
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return &resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) Update(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) (sql.Result, error) {
|
||||||
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, data.Id)
|
||||||
|
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, agentCommissionDeductionRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||||
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) error {
|
||||||
|
|
||||||
|
oldVersion := data.Version
|
||||||
|
data.Version += 1
|
||||||
|
|
||||||
|
var sqlResult sql.Result
|
||||||
|
var err error
|
||||||
|
|
||||||
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, data.Id)
|
||||||
|
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||||
|
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, agentCommissionDeductionRowsWithPlaceHolder)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, data.AgentId, data.DeductedAgentId, data.Amount, data.ProductId, data.OrderId, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||||
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
updateCount, err := sqlResult.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if updateCount == 0 {
|
||||||
|
return ErrNoRowsUpdate
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentCommissionDeduction) error {
|
||||||
|
data.DelState = globalkey.DelStateYes
|
||||||
|
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||||
|
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||||
|
return errors.Wrapf(errors.New("delete soft failed "), "AgentCommissionDeductionModel delete err : %+v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp float64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||||
|
|
||||||
|
if len(field) == 0 {
|
||||||
|
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns("COUNT(" + field + ")")
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp int64
|
||||||
|
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentCommissionDeduction, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(agentCommissionDeductionRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*AgentCommissionDeduction
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommissionDeduction, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(agentCommissionDeductionRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*AgentCommissionDeduction
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommissionDeduction, int64, error) {
|
||||||
|
|
||||||
|
total, err := m.FindCount(ctx, builder, "id")
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
builder = builder.Columns(agentCommissionDeductionRows)
|
||||||
|
|
||||||
|
if orderBy == "" {
|
||||||
|
builder = builder.OrderBy("id DESC")
|
||||||
|
} else {
|
||||||
|
builder = builder.OrderBy(orderBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * pageSize
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*AgentCommissionDeduction
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, total, nil
|
||||||
|
default:
|
||||||
|
return nil, total, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentCommissionDeduction, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(agentCommissionDeductionRows)
|
||||||
|
|
||||||
|
if preMinId > 0 {
|
||||||
|
builder = builder.Where(" id < ? ", preMinId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*AgentCommissionDeduction
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentCommissionDeduction, error) {
|
||||||
|
|
||||||
|
builder = builder.Columns(agentCommissionDeductionRows)
|
||||||
|
|
||||||
|
if preMaxId > 0 {
|
||||||
|
builder = builder.Where(" id > ? ", preMaxId)
|
||||||
|
}
|
||||||
|
|
||||||
|
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp []*AgentCommissionDeduction
|
||||||
|
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||||
|
|
||||||
|
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||||
|
return fn(ctx, session)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) SelectBuilder() squirrel.SelectBuilder {
|
||||||
|
return squirrel.Select().From(m.table)
|
||||||
|
}
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||||
|
tydataAgentCommissionDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, 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)
|
||||||
|
if session != nil {
|
||||||
|
return session.ExecCtx(ctx, query, id)
|
||||||
|
}
|
||||||
|
return conn.ExecCtx(ctx, query, id)
|
||||||
|
}, tydataAgentCommissionDeductionIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) formatPrimary(primary interface{}) string {
|
||||||
|
return fmt.Sprintf("%s%v", cacheTydataAgentCommissionDeductionIdPrefix, primary)
|
||||||
|
}
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentCommissionDeductionRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultAgentCommissionDeductionModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user