Compare commits
2 Commits
main
...
feat-hjj-U
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb8305f83b | ||
|
|
c4ec01846f |
10
cmd/app.go
10
cmd/app.go
@ -34,6 +34,16 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // 一次性执行任务余额同步(幂等):若已执行或存在数据则跳过
|
||||||
|
// if syncErr := dao.RunInitialTaskBalanceSync(); syncErr != nil {
|
||||||
|
// app.ModuleClients.Lg.Warn("initial task-balance sync failed", zap.Error(syncErr))
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 增量同步:每次服务重启时执行,同步套餐余额表中的新数据到任务余额表
|
||||||
|
// if incrementalSyncErr := dao.RunIncrementalTaskBalanceSync(); incrementalSyncErr != nil {
|
||||||
|
// app.ModuleClients.Lg.Warn("incremental task-balance sync failed", zap.Error(incrementalSyncErr))
|
||||||
|
// }
|
||||||
|
|
||||||
//l, err := net.Listen("tcp", ":8883")
|
//l, err := net.Listen("tcp", ":8883")
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// fmt.Printf("failed to listen: %v", err)
|
// fmt.Printf("failed to listen: %v", err)
|
||||||
|
|||||||
@ -54,10 +54,6 @@ func (b *BundleProvider) OrderRecordsDetail(_ context.Context, req *bundle.Order
|
|||||||
return logic.OrderRecordsDetail(req)
|
return logic.OrderRecordsDetail(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BundleProvider) GetInEffectOrderRecord(_ context.Context, req *bundle.GetInEffectOrderRecordRequest) (res *bundle.OrderRecord, err error) {
|
|
||||||
return logic.GetInEffectOrderRecord(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 增值套餐相关
|
// 增值套餐相关
|
||||||
func (b *BundleProvider) CreateValueAddBundle(_ context.Context, req *bundle.CreateValueAddBundleRequest) (res *bundle.CreateValueAddBundleResponse, err error) {
|
func (b *BundleProvider) CreateValueAddBundle(_ context.Context, req *bundle.CreateValueAddBundleRequest) (res *bundle.CreateValueAddBundleResponse, err error) {
|
||||||
if err = req.Validate(); err != nil {
|
if err = req.Validate(); err != nil {
|
||||||
@ -134,10 +130,3 @@ func (b *BundleProvider) SoftDeleteUnfinishedInfo(_ context.Context, req *bundle
|
|||||||
func (b *BundleProvider) ReSignTheContract(_ context.Context, req *bundle.ReSignTheContractRequest) (res *bundle.CommonResponse, err error) {
|
func (b *BundleProvider) ReSignTheContract(_ context.Context, req *bundle.ReSignTheContractRequest) (res *bundle.CommonResponse, err error) {
|
||||||
return logic.ReSignTheContract(req)
|
return logic.ReSignTheContract(req)
|
||||||
}
|
}
|
||||||
func (b *BundleProvider) OrderListByOrderUuid(_ context.Context, req *bundle.OrderInfoByOrderUuidRequest) (res *bundle.OrderInfoByOrderNoResp, err error) {
|
|
||||||
return logic.OrderListByOrderUuid(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BundleProvider) UpdateOrderRecordByOrderUuid(_ context.Context, req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
|
||||||
return logic.UpdateOrderRecordByOrderUuid(req)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"micro-bundle/internal/logic"
|
"micro-bundle/internal/logic"
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
)
|
)
|
||||||
@ -26,17 +27,6 @@ func (b *BundleProvider) GetBundleBalanceByUserId(_ context.Context, req *bundle
|
|||||||
return logic.GetBundleBalanceByUserId(req)
|
return logic.GetBundleBalanceByUserId(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BundleProvider) GetBundleBalanceByOrderUUID(_ context.Context, req *bundle.GetBundleBalanceByOrderUUIDReq) (*bundle.GetBundleBalanceByOrderUUIDResp, error) {
|
|
||||||
startTime, status, err := logic.GetBundleBalanceByOrderUUID(req.OrderUUID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &bundle.GetBundleBalanceByOrderUUIDResp{
|
|
||||||
StartTime: startTime.Unix(),
|
|
||||||
Status: int32(status),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建套餐余额
|
// 创建套餐余额
|
||||||
func (b *BundleProvider) CreateBundleBalance(_ context.Context, req *bundle.CreateBundleBalanceReq) (*bundle.CreateBundleBalanceResp, error) {
|
func (b *BundleProvider) CreateBundleBalance(_ context.Context, req *bundle.CreateBundleBalanceReq) (*bundle.CreateBundleBalanceResp, error) {
|
||||||
return logic.CreateBundleBalance(req)
|
return logic.CreateBundleBalance(req)
|
||||||
@ -95,3 +85,13 @@ func (b *BundleProvider) GetBundleBalanceLayout(_ context.Context, req *bundle.G
|
|||||||
func (b *BundleProvider) SetBundleBalanceLayout(_ context.Context, req *bundle.SetBundleBalanceLayoutReq) (*bundle.SetBundleBalanceLayoutResp, error) {
|
func (b *BundleProvider) SetBundleBalanceLayout(_ context.Context, req *bundle.SetBundleBalanceLayoutReq) (*bundle.SetBundleBalanceLayoutResp, error) {
|
||||||
return logic.SetBundleBalanceLayout(req)
|
return logic.SetBundleBalanceLayout(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新余量表数据
|
||||||
|
func (b *BundleProvider) UpdateBundleBalance(_ context.Context, req *bundle.UpdateBundleBalanceReq) (*bundle.UpdateBundleBalanceResp, error) {
|
||||||
|
var resp bundle.UpdateBundleBalanceResp
|
||||||
|
err := logic.UpdateBundleBalance()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("更新余量表数据失败")
|
||||||
|
}
|
||||||
|
return &resp, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -29,7 +29,3 @@ func (b *BundleProvider) MetricsArtistAccountExport(_ context.Context, req *bund
|
|||||||
func (b *BundleProvider) MetricsVideoSubmitExport(_ context.Context, req *bundle.MetricsVideoSubmitExportReq) (*bundle.MetricsVideoSubmitExportResp, error) {
|
func (b *BundleProvider) MetricsVideoSubmitExport(_ context.Context, req *bundle.MetricsVideoSubmitExportReq) (*bundle.MetricsVideoSubmitExportResp, error) {
|
||||||
return logic.MetricsVideoSubmitExport(req)
|
return logic.MetricsVideoSubmitExport(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BundleProvider) ExportWorkCastInfo(_ context.Context, req *bundle.ExportWorkCastInfoReq) (*bundle.ExportWorkCastInfoResp, error) {
|
|
||||||
return logic.ExportWorkCastInfo(req)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,34 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"micro-bundle/internal/logic"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 合同管理相关接口
|
|
||||||
|
|
||||||
// UpdateContract 合同更新接口(根据action判断新增/更新/删除)
|
|
||||||
func (b *BundleProvider) UpdateContract(_ context.Context, req *bundle.ContractUpdateRequest) (res *bundle.ComResponse, err error) {
|
|
||||||
return logic.UpdateContract(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetContractList 查询合同列表
|
|
||||||
func (b *BundleProvider) GetContractList(_ context.Context, req *bundle.ContractListRequest) (res *bundle.ContractListResponse, err error) {
|
|
||||||
return logic.GetContractList(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetContractDetail 根据合同UUID查询详情
|
|
||||||
func (b *BundleProvider) GetContractDetail(_ context.Context, req *bundle.ContractDetailRequest) (res *bundle.ContractDetailResponse, err error) {
|
|
||||||
return logic.GetContractDetail(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDevelopmentCyclesByContractUUID 根据合同UUID查询开发周期
|
|
||||||
func (b *BundleProvider) GetDevelopmentCyclesByContractUUID(_ context.Context, req *bundle.GetDevelopmentCyclesByContractUUIDRequest) (res *bundle.GetDevelopmentCyclesByContractUUIDResponse, err error) {
|
|
||||||
return logic.GetDevelopmentCyclesByContractUUID(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPaymentCyclesByContractUUID 根据合同UUID查询支付周期
|
|
||||||
func (b *BundleProvider) GetPaymentCyclesByContractUUID(_ context.Context, req *bundle.GetPaymentCyclesByContractUUIDRequest) (res *bundle.GetPaymentCyclesByContractUUIDResponse, err error) {
|
|
||||||
return logic.GetPaymentCyclesByContractUUID(req)
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"micro-bundle/internal/logic"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 客户管理相关接口
|
|
||||||
|
|
||||||
// GetCustomerList 多条件查询客户列表
|
|
||||||
func (b *BundleProvider) GetCustomerList(_ context.Context, req *bundle.CustomerListRequest) (res *bundle.CustomerListResponse, err error) {
|
|
||||||
return logic.GetCustomerList(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCustomerDetail 根据客户ID查询客户详情
|
|
||||||
func (b *BundleProvider) GetCustomerDetail(_ context.Context, req *bundle.CustomerDetailRequest) (res *bundle.CustomerDetailResponse, err error) {
|
|
||||||
return logic.GetCustomerDetail(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateCustomer 更新客户接口(根据action判断新增/更新/删除)
|
|
||||||
func (b *BundleProvider) UpdateCustomer(_ context.Context, req *bundle.CustomerUpdateRequest) (res *bundle.ComResponse, err error) {
|
|
||||||
// 调用logic层,logic层返回CommonResponse,需要转换为ComResponse
|
|
||||||
commonRes, err := logic.UpdateCustomer(req)
|
|
||||||
if err != nil {
|
|
||||||
return &bundle.ComResponse{Msg: err.Error()}, err
|
|
||||||
}
|
|
||||||
return &bundle.ComResponse{Msg: commonRes.Msg}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetReferralPersonList 查询所有不重复的推荐人列表
|
|
||||||
func (b *BundleProvider) GetReferralPersonList(_ context.Context, req *bundle.ReferralPersonListRequest) (res *bundle.ReferralPersonListResponse, err error) {
|
|
||||||
return logic.GetReferralPersonList(req)
|
|
||||||
}
|
|
||||||
@ -1,88 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"micro-bundle/internal/logic"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 创建电子发票
|
|
||||||
func (b *BundleProvider) CreateInvoice(_ context.Context, req *bundle.CreateInvoiceReq) (*bundle.CreateInvoiceResp, error) {
|
|
||||||
res, err := logic.CreateInvoice(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建纸质发票地址
|
|
||||||
func (b *BundleProvider) CreatePaperInvoiceAddress(_ context.Context, req *bundle.CreatePaperInvoiceAddressReq) (*bundle.CreatePaperInvoiceAddressResp, error) {
|
|
||||||
res, err := logic.CreatePaperInvoiceAddress(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取发票列表
|
|
||||||
func (b *BundleProvider) GetInvoiceList(_ context.Context, req *bundle.GetInvoiceListReq) (*bundle.GetInvoiceListResp, error) {
|
|
||||||
res, err := logic.GetInvoiceList(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新发票快递信息
|
|
||||||
func (b *BundleProvider) UpdateInvoiceExpressInfo(_ context.Context, req *bundle.UpdateInvoiceExpressInfoReq) (*bundle.UpdateInvoiceExpressInfoResp, error) {
|
|
||||||
res, err := logic.UpdateInvoiceExpressInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查看快递信息
|
|
||||||
func (b *BundleProvider) GetInvoiceExpressInfo(_ context.Context, req *bundle.GetInvoiceExpressInfoReq) (*bundle.GetInvoiceExpressInfoResp, error) {
|
|
||||||
res, err := logic.GetInvoiceExpressInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取订单信息
|
|
||||||
func (b *BundleProvider) GetOrderInfoByOrderNo(_ context.Context, req *bundle.GetOrderInfoByOrderNoReq) (*bundle.GetOrderInfoByOrderNoResp, error) {
|
|
||||||
res, err := logic.GetOrderInfoByOrderNo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取对应用户发票列表
|
|
||||||
func (b *BundleProvider) GetInvoiceInfoByOrderNo(_ context.Context, req *bundle.GetInvoiceInfoByOrderNoReq) (*bundle.GetInvoiceInfoByOrderNoResp, error) {
|
|
||||||
res, err := logic.GetInvoiceInfoByOrderNo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取最后一张发票编号
|
|
||||||
func (b *BundleProvider) GetLastInvoiceNo(_ context.Context, req *bundle.GetLastInvoiceNoReq) (*bundle.GetLastInvoiceNoResp, error) {
|
|
||||||
res, err := logic.GetLastInvoiceNo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新发票url
|
|
||||||
func (b *BundleProvider) UpdataInvoiceInfo(_ context.Context, req *bundle.UpdataInvoiceInfoReq) (*bundle.UpdataInvoiceInfoResp, error) {
|
|
||||||
res, err := logic.UpdataInvoiceInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
package controller
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"micro-bundle/internal/logic"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (b *BundleProvider) SendQuestionnaireSurvey(_ context.Context, req *bundle.SendQuestionnaireSurveyRequest) (*bundle.SendQuestionnaireSurveyResponse, error) {
|
|
||||||
return logic.SendQuestionnaireSurvey(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BundleProvider) GetQuestionnaireSurveyInfo(_ context.Context, req *bundle.GetQuestionnaireSurveyInfoRequest) (*bundle.GetQuestionnaireSurveyInfoResponse, error) {
|
|
||||||
return logic.GetQuestionnaireSurveyInfo(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BundleProvider) CreateQuestionnaireSurveyAnswer(_ context.Context, req *bundle.CreateQuestionnaireSurveyAnswerRequest) (*bundle.CreateQuestionnaireSurveyAnswerResponse, error) {
|
|
||||||
return logic.CreateQuestionnaireSurveyAnswer(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *BundleProvider) GetQuestionnaireSurveyList(_ context.Context, req *bundle.GetQuestionnaireSurveyListRequest) (*bundle.GetQuestionnaireSurveyListResponse, error) {
|
|
||||||
return logic.GetQuestionnaireSurveyList(req)
|
|
||||||
}
|
|
||||||
@ -3,7 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"micro-bundle/internal/dto"
|
"micro-bundle/internal/dao"
|
||||||
"micro-bundle/internal/logic"
|
"micro-bundle/internal/logic"
|
||||||
"micro-bundle/internal/model"
|
"micro-bundle/internal/model"
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
@ -13,12 +13,57 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetPendingTaskList 查询待指派任务记录
|
||||||
|
func (b *BundleProvider) GetPendingTaskList(_ context.Context, req *bundle.TaskQueryRequest) (*bundle.TaskQueryResponse, error) {
|
||||||
|
// 转换请求参数
|
||||||
|
daoReq := &dao.TaskQueryRequest{
|
||||||
|
Keyword: req.Keyword,
|
||||||
|
Page: int(req.Page),
|
||||||
|
PageSize: int(req.PageSize),
|
||||||
|
SortBy: req.SortBy,
|
||||||
|
SortType: req.SortType,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用logic层
|
||||||
|
tasks, total, err := logic.GetPendingTaskList(daoReq)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换响应数据
|
||||||
|
var taskInfos []*bundle.TaskManagementInfo
|
||||||
|
for _, task := range tasks {
|
||||||
|
taskInfo := &bundle.TaskManagementInfo{
|
||||||
|
SubNum: task.SubNum,
|
||||||
|
TelNum: task.TelNum,
|
||||||
|
ArtistName: task.ArtistName,
|
||||||
|
PendingVideoCount: int32(task.PendingVideoCount),
|
||||||
|
PendingPostCount: int32(task.PendingPostCount),
|
||||||
|
PendingDataCount: int32(task.PendingDataCount),
|
||||||
|
ProgressTaskCount: int32(task.ProgressTaskCount),
|
||||||
|
CompleteTaskCount: int32(task.CompleteTaskCount),
|
||||||
|
LastTaskAssignee: task.LastTaskAssignee,
|
||||||
|
TaskAssigneeNum: task.TaskAssigneeNum,
|
||||||
|
PendingVideoScriptCount: 0,
|
||||||
|
}
|
||||||
|
taskInfos = append(taskInfos, taskInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &bundle.TaskQueryResponse{
|
||||||
|
Tasks: taskInfos,
|
||||||
|
Total: total,
|
||||||
|
Page: req.Page,
|
||||||
|
PageSize: req.PageSize,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// AssignTask 指派某位员工完成某个艺人的任务
|
// AssignTask 指派某位员工完成某个艺人的任务
|
||||||
func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignRequest) (*bundle.CommonResponse, error) {
|
||||||
daoReq := &dto.TaskAssignRequest{
|
// 转换请求参数
|
||||||
|
daoReq := &dao.TaskAssignRequest{
|
||||||
SubNum: req.SubNum,
|
SubNum: req.SubNum,
|
||||||
TelNum: req.TelNum,
|
TelNum: req.TelNum,
|
||||||
ArtistName: req.ArtistName,
|
ArtistName: req.ArtistName, // 添加缺失的ArtistName字段
|
||||||
TaskAssignee: req.TaskAssignee,
|
TaskAssignee: req.TaskAssignee,
|
||||||
TaskAssigneeNum: req.TaskAssigneeNum,
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
||||||
Operator: req.Operator,
|
Operator: req.Operator,
|
||||||
@ -28,10 +73,9 @@ func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignReq
|
|||||||
AssignPostCount: int(req.AssignPostCount),
|
AssignPostCount: int(req.AssignPostCount),
|
||||||
AssignDataCount: int(req.AssignDataCount),
|
AssignDataCount: int(req.AssignDataCount),
|
||||||
AssignVideoScriptCount: int(req.AssignVideoScriptCount),
|
AssignVideoScriptCount: int(req.AssignVideoScriptCount),
|
||||||
AssignReportCount: int(req.AssignReportCount),
|
|
||||||
UserID: int(req.UserID),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用logic层
|
||||||
err := logic.AssignTask(daoReq)
|
err := logic.AssignTask(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.CommonResponse{
|
return &bundle.CommonResponse{
|
||||||
@ -44,6 +88,35 @@ func (b *BundleProvider) AssignTask(_ context.Context, req *bundle.TaskAssignReq
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatePendingCount 修改待发数量
|
||||||
|
func (b *BundleProvider) UpdatePendingCount(_ context.Context, req *bundle.UpdatePendingCountRequest) (*bundle.CommonResponse, error) {
|
||||||
|
// 转换请求参数
|
||||||
|
daoReq := &dao.UpdatePendingCountRequest{
|
||||||
|
SubNum: req.SubNum,
|
||||||
|
TelNum: req.TelNum,
|
||||||
|
ArtistName: req.ArtistName, // 添加缺失的ArtistName字段
|
||||||
|
PendingVideoCount: int(req.PendingVideoCount),
|
||||||
|
PendingPostCount: int(req.PendingPostCount),
|
||||||
|
PendingDataCount: int(req.PendingDataCount),
|
||||||
|
Operator: req.Operator,
|
||||||
|
OperatorNum: req.OperatorNum,
|
||||||
|
TaskAssignee: req.TaskAssignee,
|
||||||
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用logic层
|
||||||
|
err := logic.UpdatePendingCount(daoReq)
|
||||||
|
if err != nil {
|
||||||
|
return &bundle.CommonResponse{
|
||||||
|
Msg: err.Error(),
|
||||||
|
}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &bundle.CommonResponse{
|
||||||
|
Msg: "待发数量修改成功",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetRecentAssignRecords 查询最近被指派记录
|
// GetRecentAssignRecords 查询最近被指派记录
|
||||||
func (b *BundleProvider) GetRecentAssignRecords(_ context.Context, req *bundle.RecentAssignRecordsRequest) (*bundle.RecentAssignRecordsResponse, error) {
|
func (b *BundleProvider) GetRecentAssignRecords(_ context.Context, req *bundle.RecentAssignRecordsRequest) (*bundle.RecentAssignRecordsResponse, error) {
|
||||||
limit := int(req.Limit)
|
limit := int(req.Limit)
|
||||||
@ -69,7 +142,8 @@ func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle
|
|||||||
if int(req.Status) == 2 {
|
if int(req.Status) == 2 {
|
||||||
req.SortBy = "complete_time"
|
req.SortBy = "complete_time"
|
||||||
}
|
}
|
||||||
daoReq := &dto.EmployeeTaskQueryRequest{
|
// 转换请求参数
|
||||||
|
daoReq := &dao.EmployeeTaskQueryRequest{
|
||||||
TaskAssigneeNum: req.TaskAssigneeNum,
|
TaskAssigneeNum: req.TaskAssigneeNum,
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
Operator: req.Operator,
|
Operator: req.Operator,
|
||||||
@ -84,11 +158,13 @@ func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle
|
|||||||
TaskBatch: req.TaskBatch,
|
TaskBatch: req.TaskBatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用logic层
|
||||||
records, total, err := logic.GetEmployeeAssignedTasks(daoReq)
|
records, total, err := logic.GetEmployeeAssignedTasks(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 转换响应数据
|
||||||
var recordInfos []*bundle.TaskAssignRecordInfo
|
var recordInfos []*bundle.TaskAssignRecordInfo
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
recordInfo := convertToTaskAssignRecordInfo(record)
|
recordInfo := convertToTaskAssignRecordInfo(record)
|
||||||
@ -105,6 +181,7 @@ func (b *BundleProvider) GetEmployeeAssignedTasks(_ context.Context, req *bundle
|
|||||||
|
|
||||||
// CompleteTaskManually 员工手动点击完成任务
|
// CompleteTaskManually 员工手动点击完成任务
|
||||||
func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.CompleteTaskManuallyRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.CompleteTaskManuallyRequest) (*bundle.CommonResponse, error) {
|
||||||
|
// 调用logic层
|
||||||
err := logic.CompleteTaskManually(req.AssignRecordsUUID, req.TaskAssigneeNum)
|
err := logic.CompleteTaskManually(req.AssignRecordsUUID, req.TaskAssigneeNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.CommonResponse{
|
return &bundle.CommonResponse{
|
||||||
@ -119,7 +196,8 @@ func (b *BundleProvider) CompleteTaskManually(_ context.Context, req *bundle.Com
|
|||||||
|
|
||||||
// UpdateTaskProgress 员工实际完成任务状态更新
|
// UpdateTaskProgress 员工实际完成任务状态更新
|
||||||
func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.UpdateTaskProgressRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.UpdateTaskProgressRequest) (*bundle.CommonResponse, error) {
|
||||||
daoReq := &dto.CompleteTaskRequest{
|
// 转换请求参数
|
||||||
|
daoReq := &dao.CompleteTaskRequest{
|
||||||
AssignRecordsUUID: req.AssignRecordsUUID,
|
AssignRecordsUUID: req.AssignRecordsUUID,
|
||||||
EmployeeName: req.EmployeeName,
|
EmployeeName: req.EmployeeName,
|
||||||
EmployeeNum: req.EmployeeNum,
|
EmployeeNum: req.EmployeeNum,
|
||||||
@ -128,6 +206,7 @@ func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.Updat
|
|||||||
UUID: req.Uuid,
|
UUID: req.Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用logic层
|
||||||
err := logic.UpdateTaskProgress(daoReq)
|
err := logic.UpdateTaskProgress(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.CommonResponse{
|
return &bundle.CommonResponse{
|
||||||
@ -140,8 +219,9 @@ func (b *BundleProvider) UpdateTaskProgress(_ context.Context, req *bundle.Updat
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerminateTaskByUUID 根据指派记录UUID终止任务
|
// TerminateTaskByUUID 根据指派记录UUID终止任务(实际状态置为已中止)
|
||||||
func (b *BundleProvider) TerminateTaskByUUID(_ context.Context, req *bundle.TerminateTaskByUUIDRequest) (*bundle.ComResponse, error) {
|
func (b *BundleProvider) TerminateTaskByUUID(_ context.Context, req *bundle.TerminateTaskByUUIDRequest) (*bundle.ComResponse, error) {
|
||||||
|
// 调用logic层
|
||||||
err := logic.TerminateTaskByUUID(req.AssignRecordsUUID)
|
err := logic.TerminateTaskByUUID(req.AssignRecordsUUID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &bundle.ComResponse{Msg: err.Error()}, err
|
return &bundle.ComResponse{Msg: err.Error()}, err
|
||||||
@ -194,7 +274,8 @@ func (b *BundleProvider) GetTaskAssignRecordsList(_ context.Context, req *bundle
|
|||||||
if sortBy, ok := model.OrderByPending[req.SortBy]; ok {
|
if sortBy, ok := model.OrderByPending[req.SortBy]; ok {
|
||||||
req.SortBy = sortBy
|
req.SortBy = sortBy
|
||||||
}
|
}
|
||||||
daoReq := &dto.TaskAssignRecordsQueryRequest{
|
// 转换请求参数
|
||||||
|
daoReq := &dao.TaskAssignRecordsQueryRequest{
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
TaskAssignee: req.TaskAssignee,
|
TaskAssignee: req.TaskAssignee,
|
||||||
Operator: req.Operator,
|
Operator: req.Operator,
|
||||||
@ -216,6 +297,7 @@ func (b *BundleProvider) GetTaskAssignRecordsList(_ context.Context, req *bundle
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 转换响应数据
|
||||||
var recordInfos []*bundle.TaskAssignRecordInfo
|
var recordInfos []*bundle.TaskAssignRecordInfo
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
recordInfo := convertToTaskAssignRecordInfo(record)
|
recordInfo := convertToTaskAssignRecordInfo(record)
|
||||||
@ -232,7 +314,7 @@ func (b *BundleProvider) GetTaskAssignRecordsList(_ context.Context, req *bundle
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convertToTaskAssignRecordInfo 转换TaskAssignRecords模型为proto消息
|
// convertToTaskAssignRecordInfo 转换TaskAssignRecords模型为proto消息
|
||||||
func convertToTaskAssignRecordInfo(record *dto.TaskAssignRecordsResponse) *bundle.TaskAssignRecordInfo {
|
func convertToTaskAssignRecordInfo(record *dao.TaskAssignRecordsResponse) *bundle.TaskAssignRecordInfo {
|
||||||
var completeTime string
|
var completeTime string
|
||||||
if record.CompleteTime != nil {
|
if record.CompleteTime != nil {
|
||||||
completeTime = record.CompleteTime.Format("2006-01-02 15:04:05")
|
completeTime = record.CompleteTime.Format("2006-01-02 15:04:05")
|
||||||
@ -262,13 +344,11 @@ func convertToTaskAssignRecordInfo(record *dto.TaskAssignRecordsResponse) *bundl
|
|||||||
CompleteVideoCount: int32(record.CompleteVideoCount),
|
CompleteVideoCount: int32(record.CompleteVideoCount),
|
||||||
CompletePostCount: int32(record.CompletePostCount),
|
CompletePostCount: int32(record.CompletePostCount),
|
||||||
CompleteDataCount: int32(record.CompleteDataCount),
|
CompleteDataCount: int32(record.CompleteDataCount),
|
||||||
PendingReportCount: int32(record.PendingReportCount),
|
|
||||||
CompleteReportCount: int32(record.CompleteReportCount),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// convertToTaskAssignRecordsSummary 转换汇总结构到proto
|
// convertToTaskAssignRecordsSummary 转换汇总结构到proto
|
||||||
func convertToTaskAssignRecordsSummary(s *dto.TaskAssignRecordsSummary) *bundle.TaskAssignRecordsSummary {
|
func convertToTaskAssignRecordsSummary(s *dao.TaskAssignRecordsSummary) *bundle.TaskAssignRecordsSummary {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
return &bundle.TaskAssignRecordsSummary{}
|
return &bundle.TaskAssignRecordsSummary{}
|
||||||
}
|
}
|
||||||
@ -277,29 +357,71 @@ func convertToTaskAssignRecordsSummary(s *dto.TaskAssignRecordsSummary) *bundle.
|
|||||||
TotalPendingVideoCount: int32(s.TotalPendingVideoCount),
|
TotalPendingVideoCount: int32(s.TotalPendingVideoCount),
|
||||||
TotalPendingPostCount: int32(s.TotalPendingPostCount),
|
TotalPendingPostCount: int32(s.TotalPendingPostCount),
|
||||||
TotalPendingDataCount: int32(s.TotalPendingDataCount),
|
TotalPendingDataCount: int32(s.TotalPendingDataCount),
|
||||||
TotalPendingReportCount: int32(s.TotalPendingReportCount),
|
|
||||||
TotalCompleteVideoScriptCount: int32(s.TotalCompleteVideoScriptCount),
|
TotalCompleteVideoScriptCount: int32(s.TotalCompleteVideoScriptCount),
|
||||||
TotalCompleteVideoCount: int32(s.TotalCompleteVideoCount),
|
TotalCompleteVideoCount: int32(s.TotalCompleteVideoCount),
|
||||||
TotalCompletePostCount: int32(s.TotalCompletePostCount),
|
TotalCompletePostCount: int32(s.TotalCompletePostCount),
|
||||||
TotalCompleteDataCount: int32(s.TotalCompleteDataCount),
|
TotalCompleteDataCount: int32(s.TotalCompleteDataCount),
|
||||||
TotalCompleteReportCount: int32(s.TotalCompleteReportCount),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchAssignTask 批量指派
|
// GetArtistBundleBalance 查询艺人的当前任务余额与待发数量(区分套餐/增值两类)
|
||||||
|
// 说明:
|
||||||
|
// - 查询条件优先使用艺人编号(customerNum),为空时使用手机号(telNum)
|
||||||
|
// - 返回同时包含“套餐类型”和“增值类型”的余额与待发数量,均按视频/图文/数据分析三类区分
|
||||||
|
func (b *BundleProvider) GetArtistBundleBalance(_ context.Context, req *bundle.ArtistBundleBalanceRequest) (*bundle.ArtistBundleBalanceResponse, error) {
|
||||||
|
// 参数校验:艺人编号与手机号不能同时为空
|
||||||
|
if req.CustomerNum == "" && req.TelNum == "" {
|
||||||
|
return nil, fmt.Errorf("艺人编号和手机号不能同时为空")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 仅使用艺人编号进行查询(与DAO层 GetRemainingPendingBySubNum 一致)
|
||||||
|
subNum := req.CustomerNum
|
||||||
|
if subNum == "" {
|
||||||
|
// 暂不支持通过手机号查询剩余待发数据
|
||||||
|
return nil, fmt.Errorf("暂不支持通过手机号查询剩余待发数据,请传入艺人编号")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调用逻辑层:仅查询剩余待发数量(区分套餐/增值)
|
||||||
|
resp, err := logic.GetArtistRemainingPending(subNum)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组装proto响应:非DAO返回字段统一置为0
|
||||||
|
return &bundle.ArtistBundleBalanceResponse{
|
||||||
|
// 套餐类型余额(暂置0)
|
||||||
|
BundleVideoBalance: 0,
|
||||||
|
BundleImageBalance: 0,
|
||||||
|
BundleDataAnalysisBalance: 0,
|
||||||
|
// 增值类型余额(暂置0)
|
||||||
|
IncreaseVideoBalance: 0,
|
||||||
|
IncreaseImageBalance: 0,
|
||||||
|
IncreaseDataAnalysisBalance: 0,
|
||||||
|
// 套餐类型待发数量
|
||||||
|
BundlePendingVideoCount: int32(resp.PendingBundleVideoCount),
|
||||||
|
BundlePendingImageCount: int32(resp.PendingBundleImageCount),
|
||||||
|
BundlePendingDataAnalysisCount: int32(resp.PendingBundleDataAnalysisCount),
|
||||||
|
// 增值类型待发数量
|
||||||
|
IncreasePendingVideoCount: int32(resp.PendingIncreaseVideoCount),
|
||||||
|
IncreasePendingImageCount: int32(resp.PendingIncreaseImageCount),
|
||||||
|
IncreasePendingDataAnalysisCount: int32(resp.PendingIncreaseDataAnalysisCount),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BatchAssignTask 批量指派(仅写入指派记录,不更新任务管理表)
|
||||||
func (b *BundleProvider) BatchAssignTask(_ context.Context, req *bundle.BatchAssignTaskRequest) (*bundle.ComResponse, error) {
|
func (b *BundleProvider) BatchAssignTask(_ context.Context, req *bundle.BatchAssignTaskRequest) (*bundle.ComResponse, error) {
|
||||||
if req == nil || len(req.Items) == 0 {
|
if req == nil || len(req.Items) == 0 {
|
||||||
return &bundle.ComResponse{Msg: "批量指派项不能为空"}, fmt.Errorf("批量指派项不能为空")
|
return &bundle.ComResponse{Msg: "批量指派项不能为空"}, fmt.Errorf("批量指派项不能为空")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换请求项为DAO层结构
|
// 转换请求项为DAO层结构
|
||||||
var items []*dto.BatchAssignItem
|
var items []*dao.BatchAssignItem
|
||||||
items = make([]*dto.BatchAssignItem, 0, len(req.Items))
|
items = make([]*dao.BatchAssignItem, 0, len(req.Items))
|
||||||
for _, it := range req.Items {
|
for _, it := range req.Items {
|
||||||
if it == nil {
|
if it == nil {
|
||||||
return &bundle.ComResponse{Msg: "存在空的指派项"}, fmt.Errorf("存在空的指派项")
|
return &bundle.ComResponse{Msg: "存在空的指派项"}, fmt.Errorf("存在空的指派项")
|
||||||
}
|
}
|
||||||
items = append(items, &dto.BatchAssignItem{
|
items = append(items, &dao.BatchAssignItem{
|
||||||
SubNum: it.SubNum,
|
SubNum: it.SubNum,
|
||||||
TelNum: it.TelNum,
|
TelNum: it.TelNum,
|
||||||
ArtistName: it.ArtistName,
|
ArtistName: it.ArtistName,
|
||||||
@ -311,9 +433,7 @@ func (b *BundleProvider) BatchAssignTask(_ context.Context, req *bundle.BatchAss
|
|||||||
AssignPostCount: int(it.AssignPostCount),
|
AssignPostCount: int(it.AssignPostCount),
|
||||||
AssignDataCount: int(it.AssignDataCount),
|
AssignDataCount: int(it.AssignDataCount),
|
||||||
AssignVideoScriptCount: int(it.AssignVideoScriptCount),
|
AssignVideoScriptCount: int(it.AssignVideoScriptCount),
|
||||||
AssignReportCount: int(it.AssignReportCount),
|
|
||||||
TaskBatch: it.TaskBatch,
|
TaskBatch: it.TaskBatch,
|
||||||
UserID: int(it.UserID),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +451,8 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
if sortBy, ok := model.OrderByDataAnalysis[req.SortBy]; ok {
|
if sortBy, ok := model.OrderByDataAnalysis[req.SortBy]; ok {
|
||||||
req.SortBy = sortBy
|
req.SortBy = sortBy
|
||||||
}
|
}
|
||||||
daoReq := &dto.TaskQueryRequest{
|
// 构造 DAO 请求参数
|
||||||
|
daoReq := &dao.TaskQueryRequest{
|
||||||
Keyword: req.Keyword,
|
Keyword: req.Keyword,
|
||||||
Page: int(req.Page),
|
Page: int(req.Page),
|
||||||
PageSize: int(req.PageSize),
|
PageSize: int(req.PageSize),
|
||||||
@ -341,11 +462,13 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
SubNums: req.SubNums,
|
SubNums: req.SubNums,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 调用逻辑层
|
||||||
items, total, err := logic.GetArtistUploadStatsList(daoReq)
|
items, total, err := logic.GetArtistUploadStatsList(daoReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 转换响应数据
|
||||||
formatTime := func(s string) string {
|
formatTime := func(s string) string {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return ""
|
return ""
|
||||||
@ -381,11 +504,6 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
IncreaseDataAnalysisTotal: int32(it.IncreaseDataAnalysisTotal),
|
IncreaseDataAnalysisTotal: int32(it.IncreaseDataAnalysisTotal),
|
||||||
ReleasedDataAnalysisTotal: int32(it.ReleasedDataAnalysisTotal),
|
ReleasedDataAnalysisTotal: int32(it.ReleasedDataAnalysisTotal),
|
||||||
PendingDataAnalysisCount: int32(it.PendingDataAnalysisCount),
|
PendingDataAnalysisCount: int32(it.PendingDataAnalysisCount),
|
||||||
UploadedReportCount: int32(it.UploadedReportCount),
|
|
||||||
BundleReportTotal: int32(it.BundleReportTotal),
|
|
||||||
IncreaseReportTotal: int32(it.IncreaseReportTotal),
|
|
||||||
ReleasedReportTotal: int32(it.ReleasedReportTotal),
|
|
||||||
PendingReportCount: int32(it.PendingReportCount),
|
|
||||||
LastTaskAssignee: it.LastTaskAssignee,
|
LastTaskAssignee: it.LastTaskAssignee,
|
||||||
TaskAssigneeNum: it.TaskAssigneeNum,
|
TaskAssigneeNum: it.TaskAssigneeNum,
|
||||||
ProgressTaskCount: int32(it.ProgressTaskCount),
|
ProgressTaskCount: int32(it.ProgressTaskCount),
|
||||||
@ -396,7 +514,6 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
AllowVideoCount: int32(it.AllowVideoCount),
|
AllowVideoCount: int32(it.AllowVideoCount),
|
||||||
AllowPostCount: int32(it.AllowPostCount),
|
AllowPostCount: int32(it.AllowPostCount),
|
||||||
AllowDataCount: int32(it.AllowDataCount),
|
AllowDataCount: int32(it.AllowDataCount),
|
||||||
AllowReportCount: int32(it.AllowReportCount),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,6 +525,29 @@ func (b *BundleProvider) GetArtistUploadStatsList(_ context.Context, req *bundle
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *BundleProvider) GetPendingUploadBreakdown(_ context.Context, req *bundle.PendingUploadBreakdownRequest) (*bundle.PendingUploadBreakdownResponse, error) {
|
||||||
|
items, total, err := logic.GetPendingUploadBreakdownBySubNums(req.SubNums, int(req.Page), int(req.PageSize))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
respItems := make([]*bundle.PendingUploadBreakdownItem, 0, len(items))
|
||||||
|
for _, it := range items {
|
||||||
|
respItems = append(respItems, &bundle.PendingUploadBreakdownItem{
|
||||||
|
SubNum: it.SubNum,
|
||||||
|
TelNum: it.TelNum,
|
||||||
|
ArtistName: it.UserName,
|
||||||
|
PendingVideoScriptCount: int32(it.PendingVideoScriptCount),
|
||||||
|
PendingBundleVideoCount: int32(it.PendingBundleVideoCount),
|
||||||
|
PendingIncreaseVideoCount: int32(it.PendingIncreaseVideoCount),
|
||||||
|
PendingBundlePostCount: int32(it.PendingBundlePostCount),
|
||||||
|
PendingIncreasePostCount: int32(it.PendingIncreasePostCount),
|
||||||
|
PendingBundleDataCount: int32(it.PendingBundleDataCount),
|
||||||
|
PendingIncreaseDataCount: int32(it.PendingIncreaseDataCount),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &bundle.PendingUploadBreakdownResponse{Items: respItems, Total: total, Page: req.Page, PageSize: req.PageSize}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetPendingAssign 查询艺人可指派数量
|
// GetPendingAssign 查询艺人可指派数量
|
||||||
func (b *BundleProvider) GetPendingAssign(_ context.Context, req *bundle.PendingAssignRequest) (*bundle.PendingAssignResponse, error) {
|
func (b *BundleProvider) GetPendingAssign(_ context.Context, req *bundle.PendingAssignRequest) (*bundle.PendingAssignResponse, error) {
|
||||||
items, total, err := logic.GetPendingAssignBySubNums(req.SubNums, int(req.Page), int(req.PageSize))
|
items, total, err := logic.GetPendingAssignBySubNums(req.SubNums, int(req.Page), int(req.PageSize))
|
||||||
@ -424,7 +564,6 @@ func (b *BundleProvider) GetPendingAssign(_ context.Context, req *bundle.Pending
|
|||||||
AllowVideoCount: int32(it.AllowVideoCount),
|
AllowVideoCount: int32(it.AllowVideoCount),
|
||||||
AllowPostCount: int32(it.AllowPostCount),
|
AllowPostCount: int32(it.AllowPostCount),
|
||||||
AllowDataCount: int32(it.AllowDataCount),
|
AllowDataCount: int32(it.AllowDataCount),
|
||||||
AllowReportCount: int32(it.AllowReportCount),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &bundle.PendingAssignResponse{Items: respItems, Total: total, Page: req.Page, PageSize: req.PageSize}, nil
|
return &bundle.PendingAssignResponse{Items: respItems, Total: total, Page: req.Page, PageSize: req.PageSize}, nil
|
||||||
@ -452,58 +591,10 @@ func (b *BundleProvider) AddHiddenTaskAssignee(_ context.Context, req *bundle.Ad
|
|||||||
return &bundle.ComResponse{Msg: "删除该指派人成功"}, nil
|
return &bundle.ComResponse{Msg: "删除该指派人成功"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BundleProvider) GetTaskWorkLogList(_ context.Context, req *bundle.TaskWorkLogQueryRequest) (*bundle.TaskWorkLogQueryResponse, error) {
|
|
||||||
daoReq := &dto.TaskWorkLogQueryRequest{
|
|
||||||
AssignRecordsUUID: req.AssignRecordsUUID,
|
|
||||||
OperationType: int(req.OperationType),
|
|
||||||
TaskType: int(req.TaskType),
|
|
||||||
ArtistUUID: req.ArtistUUID,
|
|
||||||
SubNum: req.SubNum,
|
|
||||||
ArtistName: req.ArtistName,
|
|
||||||
Page: int(req.Page),
|
|
||||||
PageSize: int(req.PageSize),
|
|
||||||
}
|
|
||||||
|
|
||||||
records, total, err := logic.GetTaskWorkLogList(daoReq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
respItems := make([]*bundle.TaskWorkLogInfo, 0, len(records))
|
|
||||||
for _, record := range records {
|
|
||||||
respItems = append(respItems, &bundle.TaskWorkLogInfo{
|
|
||||||
WorkLogUUID: record.WorkLogUUID,
|
|
||||||
AssignRecordsUUID: record.AssignRecordsUUID,
|
|
||||||
WorkUUID: record.WorkUUID,
|
|
||||||
Title: record.Title,
|
|
||||||
ArtistUUID: record.ArtistUUID,
|
|
||||||
SubNum: record.SubNum,
|
|
||||||
TelNum: record.TelNum,
|
|
||||||
ArtistName: record.ArtistName,
|
|
||||||
OperationType: int32(record.OperationType),
|
|
||||||
TaskType: int32(record.TaskType),
|
|
||||||
TaskCount: int32(record.TaskCount),
|
|
||||||
Remark: record.Remark,
|
|
||||||
OperatorName: record.OperatorName,
|
|
||||||
OperatorNum: record.OperatorNum,
|
|
||||||
OperationTime: int64(record.OperationTime),
|
|
||||||
CreatedAt: int64(record.CreatedAt),
|
|
||||||
UpdatedAt: int64(record.UpdatedAt),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return &bundle.TaskWorkLogQueryResponse{
|
|
||||||
Records: respItems,
|
|
||||||
Total: total,
|
|
||||||
Page: req.Page,
|
|
||||||
PageSize: req.PageSize,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTaskWorkLog 创建任务日志记录
|
// CreateTaskWorkLog 创建任务日志记录
|
||||||
func (b *BundleProvider) CreateTaskWorkLog(_ context.Context, req *bundle.CreateTaskWorkLogRequest) (*bundle.CommonResponse, error) {
|
func (b *BundleProvider) CreateTaskWorkLog(_ context.Context, req *bundle.CreateTaskWorkLogRequest) (*bundle.CommonResponse, error) {
|
||||||
// 转换请求参数
|
// 转换请求参数
|
||||||
daoReq := &dto.CreateTaskWorkLogRequest{
|
daoReq := &dao.CreateTaskWorkLogRequest{
|
||||||
AssignRecordsUUID: req.AssignRecordsUUID,
|
AssignRecordsUUID: req.AssignRecordsUUID,
|
||||||
WorkUUID: req.WorkUUID,
|
WorkUUID: req.WorkUUID,
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
"micro-bundle/pkg/utils"
|
"micro-bundle/pkg/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/clause"
|
"gorm.io/gorm/clause"
|
||||||
)
|
)
|
||||||
@ -83,7 +84,7 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
|||||||
WHEN bb.expired_at > NOW() THEN 2
|
WHEN bb.expired_at > NOW() THEN 2
|
||||||
ELSE 1
|
ELSE 1
|
||||||
END AS balance_status`).
|
END AS balance_status`).
|
||||||
Joins("LEFT JOIN `micro-account`.real_name rn ON u.real_name_id = rn.id and rn.deleted_at = 0").
|
Joins("LEFT JOIN `micro-account`.real_name rn ON u.real_name_id = rn.id").
|
||||||
Joins("LEFT JOIN (?) as bor ON bor.customer_id = u.id", subQuery).
|
Joins("LEFT JOIN (?) as bor ON bor.customer_id = u.id", subQuery).
|
||||||
Joins("LEFT JOIN bundle_balance bb ON u.id = bb.user_id AND bb.order_uuid = bor.uuid and bb.deleted_at is null").
|
Joins("LEFT JOIN bundle_balance bb ON u.id = bb.user_id AND bb.order_uuid = bor.uuid and bb.deleted_at is null").
|
||||||
Joins("LEFT JOIN bundle_activate bc on bc.user_id = u.id").
|
Joins("LEFT JOIN bundle_activate bc on bc.user_id = u.id").
|
||||||
@ -96,7 +97,7 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
|||||||
if utils.IsPhoneNumber(req.UserName) {
|
if utils.IsPhoneNumber(req.UserName) {
|
||||||
session = session.Where("u.tel_num = ?", req.UserName)
|
session = session.Where("u.tel_num = ?", req.UserName)
|
||||||
} else {
|
} else {
|
||||||
session = session.Where("rn.name LIKE ? OR bor.customer_num LIKE ?", "%"+req.UserName+"%", "%"+req.UserName+"%")
|
session = session.Where("rn.name like ?", "%"+req.UserName+"%")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if req.BundleName != "" {
|
if req.BundleName != "" {
|
||||||
@ -120,26 +121,25 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (data []model.Bun
|
|||||||
if req.Bought == 1 {
|
if req.Bought == 1 {
|
||||||
session = session.Where("bb.user_id IS NULL")
|
session = session.Where("bb.user_id IS NULL")
|
||||||
}
|
}
|
||||||
t := time.Now()
|
|
||||||
if req.StatusType != 0 {
|
if req.StatusType != 0 {
|
||||||
if req.ExpiredTimeStart > time.Now().UnixMilli() {
|
if req.ExpiredTimeStart > time.Now().UnixMilli() {
|
||||||
if req.StatusType == 1 {
|
if req.StatusType == 1 {
|
||||||
session = session.Where("bb.expired_at <= ?", t.Format("2006-01-02 15:04:05"))
|
session = session.Where("bb.expired_at <= ?", time.Now().UnixMilli())
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if req.StatusType == 1 {
|
if req.StatusType == 1 {
|
||||||
session = session.Where("bb.expired_at <= ?", t.Format("2006-01-02 15:04:05"))
|
session = session.Where("bb.expired_at <= ?", time.Now().UnixMilli())
|
||||||
} else {
|
} else {
|
||||||
session = session.Where("bb.expired_at >= ?", t.Format("2006-01-02 15:04:05"))
|
session = session.Where("bb.expired_at >= ?", time.Now().UnixMilli())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(req.Month) == 0 {
|
if req.Month == "" {
|
||||||
newestMonthQuery := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).Select("max(month) as month,user_id").Group("user_id")
|
newestMonthQuery := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).Select("max(month) as month,user_id").Group("user_id")
|
||||||
session.Joins("LEFT JOIN (?) as newest_month on newest_month.user_id = bb.user_id", newestMonthQuery).Where("")
|
session.Joins("LEFT JOIN (?) as newest_month on newest_month.user_id = bb.user_id", newestMonthQuery).Where("")
|
||||||
} else {
|
} else {
|
||||||
session = session.Where("bb.month in (?)", req.Month)
|
session = session.Where("bb.month = ?", req.Month)
|
||||||
}
|
}
|
||||||
err = session.Count(&total).Error
|
err = session.Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -158,13 +158,12 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (data mod
|
|||||||
Joins(`INNER JOIN (
|
Joins(`INNER JOIN (
|
||||||
SELECT customer_id, MAX(created_at) AS max_created_time
|
SELECT customer_id, MAX(created_at) AS max_created_time
|
||||||
FROM bundle_order_records
|
FROM bundle_order_records
|
||||||
WHERE status = 2 AND deleted_at is NULL
|
|
||||||
GROUP BY customer_id
|
GROUP BY customer_id
|
||||||
) bor2 ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time`)
|
) bor2 ON bor1.customer_id = bor2.customer_id AND bor1.created_at = bor2.max_created_time`)
|
||||||
session := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u").Unscoped().
|
session := app.ModuleClients.BundleDB.Table("`micro-account`.`user` AS u").Unscoped().
|
||||||
Select(`bb.*, bor.bundle_name, bor.status,bor.amount AS payment_amount,bor.amount_type AS payment_type,bor.customer_num,
|
Select(`bb.*, bor.bundle_name, bor.status,bor.amount AS payment_amount,bor.amount_type AS payment_type,bor.customer_num,
|
||||||
bor.uuid as order_uuid, rn.name as user_name,bc.activate,bor.created_at as pay_time,
|
bor.uuid as order_uuid, rn.name as user_name,bc.activate,bor.created_at as pay_time,
|
||||||
u.tel_num as user_phone_number, u.id as user_id,bor.renewal_order_uuid,bor.purchase_type`).
|
u.tel_num as user_phone_number, u.id as user_id`).
|
||||||
Joins("LEFT JOIN `micro-account`.real_name rn ON u.real_name_id = rn.id").
|
Joins("LEFT JOIN `micro-account`.real_name rn ON u.real_name_id = rn.id").
|
||||||
Joins("LEFT JOIN (?) as bor ON bor.customer_id = u.id", subQuery).
|
Joins("LEFT JOIN (?) as bor ON bor.customer_id = u.id", subQuery).
|
||||||
Joins("LEFT JOIN bundle_balance bb ON u.id = bb.user_id AND bb.order_uuid = bor.uuid").
|
Joins("LEFT JOIN bundle_balance bb ON u.id = bb.user_id AND bb.order_uuid = bor.uuid").
|
||||||
@ -178,14 +177,6 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (data mod
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBundleBalanceByOrderUuid(orderUuid string) (data model.BundleBalance, err error) {
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).Where("order_uuid = ?", orderUuid).First(&data).Error
|
|
||||||
if err != nil {
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err error) {
|
func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err error) {
|
||||||
err = app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) (err error) {
|
err = app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) (err error) {
|
||||||
ba := model.BundleActivate{}
|
ba := model.BundleActivate{}
|
||||||
@ -211,7 +202,7 @@ func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err
|
|||||||
if oldData.ManualAccountConsumptionNumber < oldData.ManualAccountNumber { // 最后消耗手动扩展的
|
if oldData.ManualAccountConsumptionNumber < oldData.ManualAccountNumber { // 最后消耗手动扩展的
|
||||||
oldData.ManualAccountConsumptionNumber++
|
oldData.ManualAccountConsumptionNumber++
|
||||||
oldData.MonthlyManualAccountConsumptionNumber++
|
oldData.MonthlyManualAccountConsumptionNumber++
|
||||||
usedType = 2
|
usedType = 3
|
||||||
goto Over
|
goto Over
|
||||||
}
|
}
|
||||||
return errors.New("账号数不足")
|
return errors.New("账号数不足")
|
||||||
@ -219,7 +210,7 @@ func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err
|
|||||||
if oldData.ManualAccountConsumptionNumber > 0 { // 最后消耗手动扩展的
|
if oldData.ManualAccountConsumptionNumber > 0 { // 最后消耗手动扩展的
|
||||||
oldData.ManualAccountConsumptionNumber--
|
oldData.ManualAccountConsumptionNumber--
|
||||||
oldData.MonthlyManualAccountConsumptionNumber--
|
oldData.MonthlyManualAccountConsumptionNumber--
|
||||||
usedType = 2
|
usedType = 3
|
||||||
goto Over
|
goto Over
|
||||||
}
|
}
|
||||||
if oldData.IncreaseAccountConsumptionNumber > 0 {
|
if oldData.IncreaseAccountConsumptionNumber > 0 {
|
||||||
@ -278,13 +269,14 @@ func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err
|
|||||||
if oldData.ManualVideoConsumptionNumber < oldData.ManualVideoNumber { // 手动扩展类型充足
|
if oldData.ManualVideoConsumptionNumber < oldData.ManualVideoNumber { // 手动扩展类型充足
|
||||||
oldData.ManualVideoConsumptionNumber++
|
oldData.ManualVideoConsumptionNumber++
|
||||||
oldData.MonthlyManualVideoConsumptionNumber++ // 记录本月使用的手动扩展
|
oldData.MonthlyManualVideoConsumptionNumber++ // 记录本月使用的手动扩展
|
||||||
usedType = 2
|
usedType = 3
|
||||||
goto Over
|
goto Over
|
||||||
}
|
}
|
||||||
return errors.New("可用视频数不足")
|
return errors.New("可用视频数不足")
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.ImageNumber > 0 {
|
if data.ImageNumber > 0 {
|
||||||
|
// 当月可使用的会过期的限制类型充足
|
||||||
// 当月可使用的会过期的限制类型充足
|
// 当月可使用的会过期的限制类型充足
|
||||||
if oldData.MonthlyBundleLimitExpiredImageConsumptionNumber < oldData.MonthlyBundleLimitExpiredImageNumber { // 套餐内会过期的限制类型图片充足
|
if oldData.MonthlyBundleLimitExpiredImageConsumptionNumber < oldData.MonthlyBundleLimitExpiredImageNumber { // 套餐内会过期的限制类型图片充足
|
||||||
oldData.MonthlyBundleLimitExpiredImageConsumptionNumber++
|
oldData.MonthlyBundleLimitExpiredImageConsumptionNumber++
|
||||||
@ -335,6 +327,7 @@ func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
if data.DataAnalysisNumber > 0 {
|
if data.DataAnalysisNumber > 0 {
|
||||||
|
// 当月可使用的会过期的限制类型充足
|
||||||
// 当月可使用的会过期的限制类型充足
|
// 当月可使用的会过期的限制类型充足
|
||||||
if oldData.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber < oldData.MonthlyBundleLimitExpiredDataAnalysisNumber { // 套餐内会过期的限制类型数据分析充足
|
if oldData.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber < oldData.MonthlyBundleLimitExpiredDataAnalysisNumber { // 套餐内会过期的限制类型数据分析充足
|
||||||
oldData.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber++
|
oldData.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber++
|
||||||
@ -383,52 +376,6 @@ func AddBundleBalanceByUserId(data model.BundleBalanceUsePo) (usedType int, err
|
|||||||
}
|
}
|
||||||
return errors.New("可用数据分析数不足")
|
return errors.New("可用数据分析数不足")
|
||||||
}
|
}
|
||||||
if data.CompetitiveNumber > 0 {
|
|
||||||
// 当月可使用的会过期的限制类型充足
|
|
||||||
if oldData.MonthlyBundleLimitExpiredCompetitiveConsumptionNumber < oldData.MonthlyBundleLimitExpiredCompetitiveNumber { // 套餐内会过期的限制类型竞品数充足
|
|
||||||
oldData.MonthlyBundleLimitExpiredCompetitiveConsumptionNumber++
|
|
||||||
oldData.BundleLimitCompetitiveExpiredConsumptionNumber++
|
|
||||||
usedType = 1
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
if oldData.MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber < oldData.MonthlyIncreaseLimitExpiredCompetitiveNumber { // 增值服务会过期的限制类型竞品数充足
|
|
||||||
oldData.MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber++
|
|
||||||
oldData.IncreaseLimitCompetitiveExpiredConsumptionNumber++
|
|
||||||
usedType = 2
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
if oldData.MonthlyBundleLimitCompetitiveConsumptionNumber < oldData.MonthlyBundleLimitCompetitiveNumber { // 套餐内限制类型竞品数充足
|
|
||||||
oldData.MonthlyBundleLimitCompetitiveConsumptionNumber++
|
|
||||||
oldData.BundleLimitCompetitiveConsumptionNumber++
|
|
||||||
usedType = 1
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
if oldData.MonthlyIncreaseLimitCompetitiveConsumptionNumber < oldData.MonthlyIncreaseLimitCompetitiveNumber { // 增值服务限制类型竞品数充足
|
|
||||||
oldData.MonthlyIncreaseLimitCompetitiveConsumptionNumber++
|
|
||||||
oldData.IncreaseLimitCompetitiveConsumptionNumber++
|
|
||||||
usedType = 2
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
if oldData.BundleLimitCompetitiveNumber < oldData.BundleCompetitiveNumber { //套餐内非限制类型的竞品数充足
|
|
||||||
oldData.BundleLimitCompetitiveConsumptionNumber++
|
|
||||||
oldData.MonthlyBundleCompetitiveConsumptionNumber++
|
|
||||||
usedType = 1
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
if oldData.IncreaseCompetitiveConsumptionNumber < oldData.IncreaseCompetitiveNumber { //增值服务非限制类型的竞品数充足
|
|
||||||
oldData.IncreaseCompetitiveConsumptionNumber++
|
|
||||||
oldData.MonthlyIncreaseCompetitiveConsumptionNumber++
|
|
||||||
usedType = 2
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
if oldData.ManualCompetitiveConsumptionNumber < oldData.ManualCompetitiveNumber { // 手动扩展类型充足
|
|
||||||
oldData.ManualCompetitiveConsumptionNumber++
|
|
||||||
oldData.MonthlyManualCompetitiveConsumptionNumber++ // 记录本月使用的手动扩展
|
|
||||||
usedType = 2
|
|
||||||
goto Over
|
|
||||||
}
|
|
||||||
return errors.New("可用竞品数不足")
|
|
||||||
}
|
|
||||||
Over:
|
Over:
|
||||||
return tx.Model(&model.BundleBalance{}).Where("id = ?", oldData.ID).Save(&oldData).Error
|
return tx.Model(&model.BundleBalance{}).Where("id = ?", oldData.ID).Save(&oldData).Error
|
||||||
})
|
})
|
||||||
@ -442,7 +389,7 @@ func CreateUsedRecord(tx *gorm.DB, data model.BundleUsedRecord) error {
|
|||||||
func ExtendBundleBalanceByUserId(data model.BundleBalanceExtendPo) error {
|
func ExtendBundleBalanceByUserId(data model.BundleBalanceExtendPo) error {
|
||||||
err := app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) error {
|
err := app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) error {
|
||||||
oldData := model.BundleBalance{}
|
oldData := model.BundleBalance{}
|
||||||
if err := tx.Model(&model.BundleBalance{}).Where("user_id = ?", data.UserId).Where("deleted_at is null").Order("month desc,created_at desc").First(&oldData).Error; err != nil {
|
if err := tx.Model(&model.BundleBalance{}).Where("user_id = ?", data.UserId).Where("deleted_at is null").Order("created_at desc").First(&oldData).Error; err != nil {
|
||||||
return errors.New("用户还没有套餐信息")
|
return errors.New("用户还没有套餐信息")
|
||||||
}
|
}
|
||||||
oldData.ManualAccountNumber += data.AccountNumber
|
oldData.ManualAccountNumber += data.AccountNumber
|
||||||
@ -453,8 +400,6 @@ func ExtendBundleBalanceByUserId(data model.BundleBalanceExtendPo) error {
|
|||||||
oldData.MonthlyNewManualDataAnalysisNumber += data.DataAnalysisNumber
|
oldData.MonthlyNewManualDataAnalysisNumber += data.DataAnalysisNumber
|
||||||
oldData.ManualVideoNumber += data.VideoNumber
|
oldData.ManualVideoNumber += data.VideoNumber
|
||||||
oldData.MonthlyNewManualVideoNumber += data.VideoNumber
|
oldData.MonthlyNewManualVideoNumber += data.VideoNumber
|
||||||
oldData.ManualCompetitiveNumber += data.CompetitiveNumber
|
|
||||||
oldData.MonthlyNewManualCompetitiveNumber += data.CompetitiveNumber
|
|
||||||
oldData.MonthlyNewDurationNumber += data.DurationNumber // 记录本月新增手动扩展时长
|
oldData.MonthlyNewDurationNumber += data.DurationNumber // 记录本月新增手动扩展时长
|
||||||
oldData.ExpiredAt = oldData.ExpiredAt.Add(time.Hour * 24 * time.Duration(data.DurationNumber))
|
oldData.ExpiredAt = oldData.ExpiredAt.Add(time.Hour * 24 * time.Duration(data.DurationNumber))
|
||||||
return tx.Model(&model.BundleBalance{}).Where("id = ?", oldData.ID).Save(&oldData).Error
|
return tx.Model(&model.BundleBalance{}).Where("id = ?", oldData.ID).Save(&oldData).Error
|
||||||
@ -463,6 +408,14 @@ func ExtendBundleBalanceByUserId(data model.BundleBalanceExtendPo) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 套餐余额更新成功后,同步增量更新任务余额
|
||||||
|
// 如果任务余额更新失败,只记录错误日志,不影响主流程
|
||||||
|
if taskErr := ExtendTaskBalanceByUserId(data.UserId, data.ImageNumber, data.DataAnalysisNumber, data.VideoNumber, data.DurationNumber); taskErr != nil {
|
||||||
|
// 记录错误日志但不返回错误,避免影响主流程
|
||||||
|
logger.Errorf("任务余额同步失败,用户ID: %d, 错误: %v", data.UserId, taskErr)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,6 +423,13 @@ func CreateBundleBalance(data model.BundleBalance) error {
|
|||||||
if err := app.ModuleClients.BundleDB.Save(&data).Error; err != nil {
|
if err := app.ModuleClients.BundleDB.Save(&data).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// 同步任务余额(新建套餐余额时)
|
||||||
|
// 如果任务余额同步失败,只记录错误日志,不影响主流程
|
||||||
|
if taskErr := SyncTaskBalanceFromBundleBalance(data); taskErr != nil {
|
||||||
|
// 记录错误日志但不返回错误,避免影响主流程
|
||||||
|
logger.Errorf("新建套餐余额时任务余额同步失败,更新数据: %v, 错误 %v", data, taskErr)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,108 +499,38 @@ func GetVedioWorkDetail(req *bundle.GetVedioWorkDetailReq) (data model.CastWorkV
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ToBeComfirmedWorks(req *bundle.ToBeComfirmedWorksReq) (data []model.CastWorkLog, total int64, unconfirmed int64, err error) {
|
func ToBeComfirmedWorks(req *bundle.ToBeComfirmedWorksReq) (data []model.CastWorkLog, total int64, unconfirmed int64, err error) {
|
||||||
var bundleTimeInfo model.BundleBalanceTimeInfo
|
unConfirmSubQuery := app.ModuleClients.BundleDB.
|
||||||
//获取套餐信息
|
Table("cast_work_log").
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).
|
Select("work_uuid, MAX(update_time) AS max_update_time").
|
||||||
Select("bundle_balance.user_id,bundle_balance.order_uuid,bundle_balance.month,bundle_balance.expired_at,bundle_balance.start_at").
|
Where("cast_work_log.deleted_at = 0").
|
||||||
Joins("left join micro-account.user u on bundle_balance.user_id = u.id and u.deleted_at = 0").
|
Group("work_uuid").Where("work_status = ?", 4)
|
||||||
Where("bundle_balance.deleted_at is null").
|
|
||||||
Where("u.sub_num = ?", req.ArtistUuid).
|
err = app.ModuleClients.BundleDB.
|
||||||
Where("bundle_balance.month = ?", time.Now().Format("2006-01")).
|
Table("cast_work_log AS cwl").
|
||||||
Order("bundle_balance.start_at desc").
|
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", unConfirmSubQuery).
|
||||||
First(&bundleTimeInfo).Error
|
Where("artist_uuid = ?", req.ArtistUuid).Where("cwl.deleted_at = 0").Where("confirmed_at = ?", 0).Count(&unconfirmed).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//查询当前套餐为新购还是续费
|
subQuery := app.ModuleClients.BundleDB.
|
||||||
orderReq := &bundle.OrderRecordsDetailRequest{}
|
Table("cast_work_log").
|
||||||
orderReq.Uuid = bundleTimeInfo.OrderUUID
|
Select("work_uuid, MAX(update_time) AS max_update_time").
|
||||||
orderInfo, err := OrderRecordDetail(orderReq)
|
Where("cast_work_log.deleted_at = 0").
|
||||||
|
Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7, 9})
|
||||||
|
session := app.ModuleClients.BundleDB.
|
||||||
|
Table("cast_work_log AS cwl").
|
||||||
|
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", subQuery).
|
||||||
|
Where("artist_uuid = ?", req.ArtistUuid).
|
||||||
|
Where("cwl.deleted_at = 0")
|
||||||
|
err = session.Count(&total).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("获取用户订单信息失败:", err)
|
|
||||||
return nil, 0, 0, errors.New("获取用户订单信息失败")
|
|
||||||
}
|
|
||||||
|
|
||||||
if orderInfo.PurchaseType == 1 {
|
|
||||||
//新购,只显示当前套餐的待确认作品
|
|
||||||
//获取待确认列表
|
|
||||||
unConfirmSubQuery := app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log").
|
|
||||||
Select("work_uuid, MAX(update_time) AS max_update_time").
|
|
||||||
Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0").
|
|
||||||
Where("cast_work_log.deleted_at = 0").
|
|
||||||
Where("cwe.bundle_order_uuid = ?", bundleTimeInfo.OrderUUID).
|
|
||||||
Group("work_uuid").Where("work_status = ?", 4)
|
|
||||||
|
|
||||||
err = app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log AS cwl").
|
|
||||||
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", unConfirmSubQuery).
|
|
||||||
Where("artist_uuid = ?", req.ArtistUuid).Where("cwl.deleted_at = 0").Where("confirmed_at = ?", 0).Count(&unconfirmed).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subQuery := app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log").
|
|
||||||
Select("work_uuid, MAX(update_time) AS max_update_time").
|
|
||||||
Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0").
|
|
||||||
Where("cast_work_log.deleted_at = 0").
|
|
||||||
Where("cwe.bundle_order_uuid = ?", bundleTimeInfo.OrderUUID).
|
|
||||||
Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7, 9})
|
|
||||||
session := app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log AS cwl").
|
|
||||||
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", subQuery).
|
|
||||||
Where("artist_uuid = ?", req.ArtistUuid).
|
|
||||||
Where("cwl.deleted_at = 0")
|
|
||||||
err = session.Count(&total).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.Page != 0 && req.PageSize != 0 {
|
|
||||||
session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
|
|
||||||
}
|
|
||||||
err = session.Order("created_at desc").Find(&data).Error
|
|
||||||
return
|
|
||||||
} else if orderInfo.PurchaseType == 2 {
|
|
||||||
//续费,显示当前套餐和旧套餐的待确认作品
|
|
||||||
//获取待确认列表
|
|
||||||
unConfirmSubQuery := app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log").
|
|
||||||
Select("work_uuid, MAX(update_time) AS max_update_time").
|
|
||||||
Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0").
|
|
||||||
Where("cast_work_log.deleted_at = 0").
|
|
||||||
Where("cwe.bundle_order_uuid in ?", []string{bundleTimeInfo.OrderUUID, orderInfo.RenewalOrderUUID}).
|
|
||||||
Group("work_uuid").Where("work_status = ?", 4)
|
|
||||||
|
|
||||||
err = app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log AS cwl").
|
|
||||||
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", unConfirmSubQuery).
|
|
||||||
Where("artist_uuid = ?", req.ArtistUuid).Where("cwl.deleted_at = 0").Where("confirmed_at = ?", 0).Count(&unconfirmed).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
subQuery := app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log").
|
|
||||||
Select("work_uuid, MAX(update_time) AS max_update_time").
|
|
||||||
Joins("left join cast_work_extra cwe on cwe.work_uuid = cast_work_log.work_uuid and cwe.deleted_at = 0").
|
|
||||||
Where("cast_work_log.deleted_at = 0").
|
|
||||||
Where("cwe.bundle_order_uuid in ?", []string{bundleTimeInfo.OrderUUID, orderInfo.RenewalOrderUUID}).
|
|
||||||
Group("work_uuid").Where("work_status in ?", []int{4, 5, 6, 7, 9})
|
|
||||||
session := app.ModuleClients.BundleDB.
|
|
||||||
Table("cast_work_log AS cwl").
|
|
||||||
Joins("INNER JOIN (?) AS t ON cwl.work_uuid = t.work_uuid AND cwl.update_time = t.max_update_time", subQuery).
|
|
||||||
Where("artist_uuid = ?", req.ArtistUuid).
|
|
||||||
Where("cwl.deleted_at = 0")
|
|
||||||
err = session.Count(&total).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.Page != 0 && req.PageSize != 0 {
|
|
||||||
session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
|
|
||||||
}
|
|
||||||
err = session.Order("created_at desc").Find(&data).Error
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return nil, 0, 0, errors.New("订单购买类型错误")
|
if req.Page != 0 && req.PageSize != 0 {
|
||||||
|
session.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
|
||||||
|
}
|
||||||
|
err = session.Order("created_at desc").Find(&data).Error
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfirmWork(req *bundle.ConfirmWorkReq) error {
|
func ConfirmWork(req *bundle.ConfirmWorkReq) error {
|
||||||
@ -757,26 +647,6 @@ inner join (
|
|||||||
return min(limit, remaining)
|
return min(limit, remaining)
|
||||||
}
|
}
|
||||||
|
|
||||||
//计算每个季度发放的数目
|
|
||||||
qua := func(total, limit int) int {
|
|
||||||
var released int // 已释放的次数
|
|
||||||
if v.StartAt.Month() == now.Month() && v.StartAt.Year() == now.Year() {
|
|
||||||
} else {
|
|
||||||
released += limit
|
|
||||||
}
|
|
||||||
interval := max((now.Year()*12+int(now.Month())-(v.StartAt.Year()*12+int(v.StartAt.Month())))/3, 1) // 释放了多少个季度
|
|
||||||
released += max(interval-1, 0) * limit // 已经释放的数量
|
|
||||||
remaining := max(total-released, 0) // 还剩余多少次没有发放
|
|
||||||
if v.StartAt.Month() == now.Month() && v.StartAt.Year() == now.Year() { // 本月为第一个月后购买
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
monthDiff := now.Year()*12 + int(now.Month()) - (v.StartAt.Year()*12 + int(v.StartAt.Month()))
|
|
||||||
if monthDiff%3 == 0 && v.ExpiredAt.Month() != now.Month() {
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当月过期的视频数
|
// 当月过期的视频数
|
||||||
v.MonthlyInvalidBundleVideoNumber = v.MonthlyBundleLimitExpiredVideoNumber - v.MonthlyBundleLimitExpiredVideoConsumptionNumber
|
v.MonthlyInvalidBundleVideoNumber = v.MonthlyBundleLimitExpiredVideoNumber - v.MonthlyBundleLimitExpiredVideoConsumptionNumber
|
||||||
// 历史失效的套餐权益视频总数
|
// 历史失效的套餐权益视频总数
|
||||||
@ -789,10 +659,6 @@ inner join (
|
|||||||
v.MonthlyInvalidBundleDataAnalysisNumber = v.MonthlyBundleLimitExpiredDataAnalysisNumber - v.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber // 当月过期的数据分析数
|
v.MonthlyInvalidBundleDataAnalysisNumber = v.MonthlyBundleLimitExpiredDataAnalysisNumber - v.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber // 当月过期的数据分析数
|
||||||
// 历史失效的套餐权益数据分析总数
|
// 历史失效的套餐权益数据分析总数
|
||||||
v.InvalidBundleDataAnalysisNumber += v.MonthlyInvalidBundleDataAnalysisNumber
|
v.InvalidBundleDataAnalysisNumber += v.MonthlyInvalidBundleDataAnalysisNumber
|
||||||
// 当月过期的竞品数
|
|
||||||
v.MonthlyInvalidBundleCompetitiveNumber = v.MonthlyBundleLimitExpiredCompetitiveNumber - v.MonthlyBundleLimitExpiredCompetitiveConsumptionNumber
|
|
||||||
// 历史失效的套餐权益竞品数总数
|
|
||||||
v.InvalidBundleCompetitiveNumber += v.MonthlyInvalidBundleCompetitiveNumber
|
|
||||||
|
|
||||||
// 当月失效的增值权益视频总数
|
// 当月失效的增值权益视频总数
|
||||||
v.MonthlyInvalidIncreaseVideoNumber = v.MonthlyIncreaseLimitExpiredVideoNumber - v.MonthlyIncreaseLimitExpiredVideoConsumptionNumber
|
v.MonthlyInvalidIncreaseVideoNumber = v.MonthlyIncreaseLimitExpiredVideoNumber - v.MonthlyIncreaseLimitExpiredVideoConsumptionNumber
|
||||||
@ -806,10 +672,6 @@ inner join (
|
|||||||
v.MonthlyInvalidIncreaseDataAnalysisNumber = v.MonthlyIncreaseLimitExpiredDataAnalysisNumber - v.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber
|
v.MonthlyInvalidIncreaseDataAnalysisNumber = v.MonthlyIncreaseLimitExpiredDataAnalysisNumber - v.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber
|
||||||
// 历史失效的增值权益数据分析总数
|
// 历史失效的增值权益数据分析总数
|
||||||
v.InvalidIncreaseDataAnalysisNumber += v.MonthlyInvalidIncreaseDataAnalysisNumber
|
v.InvalidIncreaseDataAnalysisNumber += v.MonthlyInvalidIncreaseDataAnalysisNumber
|
||||||
// 当月失效的增值权益竞品数总数
|
|
||||||
v.MonthlyInvalidIncreaseCompetitiveNumber = v.MonthlyIncreaseLimitExpiredCompetitiveNumber - v.MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber
|
|
||||||
// 历史失效的增值权益竞品数总数
|
|
||||||
v.InvalidIncreaseCompetitiveNumber += v.MonthlyInvalidIncreaseCompetitiveNumber
|
|
||||||
|
|
||||||
// 当月套餐限制类会过期型视频可使用额度
|
// 当月套餐限制类会过期型视频可使用额度
|
||||||
v.MonthlyBundleLimitExpiredVideoNumber = cal(v.BundleLimitVideoExpiredNumber, v.MonthlyLimitVideoQuotaNumber)
|
v.MonthlyBundleLimitExpiredVideoNumber = cal(v.BundleLimitVideoExpiredNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
@ -819,7 +681,6 @@ inner join (
|
|||||||
v.MonthlyBundleLimitVideoNumber = v.MonthlyBundleLimitVideoNumber - v.MonthlyBundleLimitVideoConsumptionNumber + cal(v.BundleLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
v.MonthlyBundleLimitVideoNumber = v.MonthlyBundleLimitVideoNumber - v.MonthlyBundleLimitVideoConsumptionNumber + cal(v.BundleLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
// 当月增值限制类型视频可使用额度
|
// 当月增值限制类型视频可使用额度
|
||||||
v.MonthlyIncreaseLimitVideoNumber = v.MonthlyIncreaseLimitVideoNumber - v.MonthlyIncreaseLimitVideoConsumptionNumber + cal(v.IncreaseLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
v.MonthlyIncreaseLimitVideoNumber = v.MonthlyIncreaseLimitVideoNumber - v.MonthlyIncreaseLimitVideoConsumptionNumber + cal(v.IncreaseLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
|
|
||||||
// 当月套餐限制类会过期型图片可使用额度
|
// 当月套餐限制类会过期型图片可使用额度
|
||||||
v.MonthlyBundleLimitExpiredImageNumber = cal(v.BundleLimitImageExpiredNumber, v.MonthlyLimitImageQuotaNumber)
|
v.MonthlyBundleLimitExpiredImageNumber = cal(v.BundleLimitImageExpiredNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
// 当月增值限制类会过期型图片可使用额度
|
// 当月增值限制类会过期型图片可使用额度
|
||||||
@ -828,7 +689,6 @@ inner join (
|
|||||||
v.MonthlyBundleLimitImageNumber = v.MonthlyBundleLimitImageNumber - v.MonthlyBundleLimitImageConsumptionNumber + cal(v.BundleLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
v.MonthlyBundleLimitImageNumber = v.MonthlyBundleLimitImageNumber - v.MonthlyBundleLimitImageConsumptionNumber + cal(v.BundleLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
// 当月增值限制类型图片可使用额度
|
// 当月增值限制类型图片可使用额度
|
||||||
v.MonthlyIncreaseLimitImageNumber = v.MonthlyIncreaseLimitImageNumber - v.MonthlyIncreaseLimitImageConsumptionNumber + cal(v.IncreaseLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
v.MonthlyIncreaseLimitImageNumber = v.MonthlyIncreaseLimitImageNumber - v.MonthlyIncreaseLimitImageConsumptionNumber + cal(v.IncreaseLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
|
|
||||||
// 当月套餐限制类会过期型数据分析可使用额度
|
// 当月套餐限制类会过期型数据分析可使用额度
|
||||||
v.MonthlyBundleLimitExpiredDataAnalysisNumber = cal(v.BundleLimitDataAnalysisExpiredNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
v.MonthlyBundleLimitExpiredDataAnalysisNumber = cal(v.BundleLimitDataAnalysisExpiredNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
||||||
// 当月增值限制类会过期型数据分析可使用额度
|
// 当月增值限制类会过期型数据分析可使用额度
|
||||||
@ -838,17 +698,7 @@ inner join (
|
|||||||
// 当月增值限制类型数据分析可使用额度
|
// 当月增值限制类型数据分析可使用额度
|
||||||
v.MonthlyIncreaseLimitDataAnalysisNumber = v.MonthlyIncreaseLimitDataAnalysisNumber - v.MonthlyIncreaseLimitDataAnalysisConsumptionNumber + cal(v.IncreaseLimitDataAnalysisNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
v.MonthlyIncreaseLimitDataAnalysisNumber = v.MonthlyIncreaseLimitDataAnalysisNumber - v.MonthlyIncreaseLimitDataAnalysisConsumptionNumber + cal(v.IncreaseLimitDataAnalysisNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
||||||
|
|
||||||
// 当月套餐限制类会过期型竞品数可使用额度
|
|
||||||
v.MonthlyBundleLimitExpiredCompetitiveNumber = qua(v.BundleLimitCompetitiveExpiredNumber, v.MonthlyLimitCompetitiveQuotaNumber)
|
|
||||||
// 当月增值限制类会过期型竞品数可使用额度
|
|
||||||
v.MonthlyIncreaseLimitExpiredCompetitiveNumber = qua(v.IncreaseLimitCompetitiveExpiredNumber, v.MonthlyLimitCompetitiveQuotaNumber)
|
|
||||||
// 当月套餐限制类型竞品数可使用额度
|
|
||||||
v.MonthlyBundleLimitCompetitiveNumber = v.MonthlyBundleLimitCompetitiveNumber - v.MonthlyBundleLimitCompetitiveConsumptionNumber + qua(v.BundleLimitCompetitiveNumber, v.MonthlyLimitCompetitiveQuotaNumber)
|
|
||||||
// 当月增值限制类型竞品数可使用额度
|
|
||||||
v.MonthlyIncreaseLimitCompetitiveNumber = v.MonthlyIncreaseLimitCompetitiveNumber - v.MonthlyIncreaseLimitCompetitiveConsumptionNumber + qua(v.IncreaseLimitCompetitiveNumber, v.MonthlyLimitCompetitiveQuotaNumber)
|
|
||||||
|
|
||||||
// 重置单月消耗数量
|
// 重置单月消耗数量
|
||||||
//视频
|
|
||||||
v.MonthlyBundleVideoConsumptionNumber = 0
|
v.MonthlyBundleVideoConsumptionNumber = 0
|
||||||
v.MonthlyIncreaseVideoConsumptionNumber = 0
|
v.MonthlyIncreaseVideoConsumptionNumber = 0
|
||||||
v.MonthlyBundleLimitVideoConsumptionNumber = 0
|
v.MonthlyBundleLimitVideoConsumptionNumber = 0
|
||||||
@ -857,7 +707,6 @@ inner join (
|
|||||||
v.MonthlyIncreaseLimitExpiredVideoConsumptionNumber = 0
|
v.MonthlyIncreaseLimitExpiredVideoConsumptionNumber = 0
|
||||||
v.MonthlyNewManualVideoNumber = 0
|
v.MonthlyNewManualVideoNumber = 0
|
||||||
v.MonthlyManualVideoConsumptionNumber = 0
|
v.MonthlyManualVideoConsumptionNumber = 0
|
||||||
//图文
|
|
||||||
v.MonthlyBundleImageConsumptionNumber = 0
|
v.MonthlyBundleImageConsumptionNumber = 0
|
||||||
v.MonthlyIncreaseImageConsumptionNumber = 0
|
v.MonthlyIncreaseImageConsumptionNumber = 0
|
||||||
v.MonthlyBundleLimitImageConsumptionNumber = 0
|
v.MonthlyBundleLimitImageConsumptionNumber = 0
|
||||||
@ -866,7 +715,6 @@ inner join (
|
|||||||
v.MonthlyIncreaseLimitExpiredImageConsumptionNumber = 0
|
v.MonthlyIncreaseLimitExpiredImageConsumptionNumber = 0
|
||||||
v.MonthlyNewManualImageNumber = 0
|
v.MonthlyNewManualImageNumber = 0
|
||||||
v.MonthlyManualImageConsumptionNumber = 0
|
v.MonthlyManualImageConsumptionNumber = 0
|
||||||
//数据分析
|
|
||||||
v.MonthlyBundleDataAnalysisConsumptionNumber = 0
|
v.MonthlyBundleDataAnalysisConsumptionNumber = 0
|
||||||
v.MonthlyIncreaseDataAnalysisConsumptionNumber = 0
|
v.MonthlyIncreaseDataAnalysisConsumptionNumber = 0
|
||||||
v.MonthlyBundleLimitDataAnalysisConsumptionNumber = 0
|
v.MonthlyBundleLimitDataAnalysisConsumptionNumber = 0
|
||||||
@ -875,20 +723,9 @@ inner join (
|
|||||||
v.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber = 0
|
v.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber = 0
|
||||||
v.MonthlyNewManualDataAnalysisNumber = 0
|
v.MonthlyNewManualDataAnalysisNumber = 0
|
||||||
v.MonthlyManualDataAnalysisConsumptionNumber = 0
|
v.MonthlyManualDataAnalysisConsumptionNumber = 0
|
||||||
//竞品数
|
|
||||||
v.MonthlyBundleCompetitiveConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseCompetitiveConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitCompetitiveConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitCompetitiveConsumptionNumber = 0
|
|
||||||
v.MonthlyBundleLimitExpiredCompetitiveConsumptionNumber = 0
|
|
||||||
v.MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber = 0
|
|
||||||
v.MonthlyNewManualCompetitiveNumber = 0
|
|
||||||
v.MonthlyManualCompetitiveConsumptionNumber = 0
|
|
||||||
|
|
||||||
v.Month = month
|
v.Month = month
|
||||||
v.ID = 0
|
v.ID = 0
|
||||||
v.CreatedAt = time.Time{}
|
|
||||||
v.UpdatedAt = time.Time{}
|
|
||||||
app.ModuleClients.BundleDB.Create(&v)
|
app.ModuleClients.BundleDB.Create(&v)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -923,7 +760,7 @@ left join (
|
|||||||
where r.deleted_at is null
|
where r.deleted_at is null
|
||||||
group by
|
group by
|
||||||
r.bundle_order_on
|
r.bundle_order_on
|
||||||
) r on r.bundle_order_on COLLATE utf8mb4_general_ci = bor.order_no COLLATE utf8mb4_general_ci
|
) r on r.bundle_order_on = bor.order_no
|
||||||
`).Scan(&data).Error
|
`).Scan(&data).Error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import (
|
|||||||
"micro-bundle/internal/model"
|
"micro-bundle/internal/model"
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
"micro-bundle/pkg/app"
|
"micro-bundle/pkg/app"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/duke-git/lancet/v2/datetime"
|
"github.com/duke-git/lancet/v2/datetime"
|
||||||
@ -21,7 +20,7 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
// ---------- 总金额统计 ----------
|
// ---------- 总金额统计 ----------
|
||||||
subQuery := app.ModuleClients.BundleDB.Model(&model.Reconciliation{}).
|
subQuery := app.ModuleClients.BundleDB.Model(&model.Reconciliation{}).
|
||||||
Select("TRUNCATE(COALESCE(SUM(CAST(handling_fee AS DECIMAL(12,3))), 0), 3) as total_fee_payment_amount").
|
Select("TRUNCATE(COALESCE(SUM(CAST(handling_fee AS DECIMAL(12,3))), 0), 3) as total_fee_payment_amount").
|
||||||
Joins("LEFT JOIN bundle_order_records bor ON bor.order_no COLLATE utf8mb4_general_ci = reconciliation.bundle_order_on COLLATE utf8mb4_general_ci").
|
Joins("LEFT JOIN bundle_order_records bor ON bor.order_no = bundle_order_on").
|
||||||
Where("bor.deleted_at is null and bor.status=2")
|
Where("bor.deleted_at is null and bor.status=2")
|
||||||
// if req.BundleUuid != "" {
|
// if req.BundleUuid != "" {
|
||||||
// subQuery = subQuery.Where("bor.bundle_uuid = ?", req.BundleUuid)
|
// subQuery = subQuery.Where("bor.bundle_uuid = ?", req.BundleUuid)
|
||||||
@ -67,12 +66,12 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
// ---------- 新增金额统计 ----------
|
// ---------- 新增金额统计 ----------
|
||||||
|
|
||||||
var NewFeePaymentAmount struct {
|
var NewFeePaymentAmount struct {
|
||||||
NewFeePaymentAmount string `gorm:"column:new_fee_payment_amount"`
|
NewFeePaymentAmount float32 `gorm:"column:new_fee_payment_amount"`
|
||||||
NewPaymentAmount string `gorm:"column:new_payment_amount"`
|
NewPaymentAmount float32 `gorm:"column:new_payment_amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
subQuery = app.ModuleClients.BundleDB.Model(&model.Reconciliation{}).
|
subQuery = app.ModuleClients.BundleDB.Model(&model.Reconciliation{}).
|
||||||
Select("TRUNCATE(COALESCE(SUM(CAST(handling_fee AS DECIMAL(12,3))), 0), 3) AS new_fee_payment_amount,TRUNCATE(COALESCE(SUM(CAST(pay_amount AS DECIMAL(12,3))), 0), 3) AS new_payment_amount").
|
Select("SUM(handling_fee) as new_fee_payment_amount, SUM(pay_amount) as new_payment_amount").
|
||||||
Joins("LEFT JOIN bundle_order_records bor ON bor.order_no COLLATE utf8mb4_general_ci = reconciliation.bundle_order_on COLLATE utf8mb4_general_ci").
|
Joins("LEFT JOIN bundle_order_records bor ON bor.order_no COLLATE utf8mb4_general_ci = reconciliation.bundle_order_on COLLATE utf8mb4_general_ci").
|
||||||
Where("`reconciliation`.pay_time >= ?", req.Start+" 00:00:00").
|
Where("`reconciliation`.pay_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("`reconciliation`.pay_time <= ?", req.End+" 23:59:59").
|
Where("`reconciliation`.pay_time <= ?", req.End+" 23:59:59").
|
||||||
@ -103,16 +102,7 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 使用 decimal 计算新增结算金额,避免精度丢失
|
result.NewFinalPaymentAmount = result.NewPaymentAmount - result.NewFeePaymentAmount
|
||||||
newPayDecimal, err := decimal.NewFromString(result.NewPaymentAmount)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("解析实收金额失败: %v", err)
|
|
||||||
}
|
|
||||||
newFeeDecimal, err := decimal.NewFromString(result.NewFeePaymentAmount)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("解析手续费失败: %v", err)
|
|
||||||
}
|
|
||||||
result.NewFinalPaymentAmount = newPayDecimal.Sub(newFeeDecimal).Truncate(3).StringFixed(2)
|
|
||||||
|
|
||||||
// ---------- 新套餐数统计 ----------
|
// ---------- 新套餐数统计 ----------
|
||||||
var newBundleCount int64
|
var newBundleCount int64
|
||||||
@ -199,11 +189,10 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Joins("left join cast_cost_log ccl on ccl.work_uuid = cast_work.uuid").
|
Joins("left join cast_cost_log ccl on ccl.work_uuid = cast_work.uuid").
|
||||||
Joins("INNER JOIN cast_work_log cwl on cwl.work_uuid = cast_work.uuid and cwl.work_status = 9").
|
Joins("INNER JOIN cast_work_log cwl on cwl.work_uuid = cast_work.uuid and cwl.work_status = 9").
|
||||||
Where("cwe.cost_type = 1").
|
Where("cwe.cost_type = 1").
|
||||||
Where("cast_work.work_category = 2").
|
|
||||||
Where("cwl.update_time >= ?", req.Start+" 00:00:00").
|
Where("cwl.update_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("cwl.update_time <= ?", req.End+" 23:59:59").
|
Where("cwl.update_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and ccl.deleted_at = 0 and cwe.deleted_at = 0 and cwl.deleted_at = 0")
|
Where("cast_work.deleted_at = 0 and ccl.deleted_at = 0 and cwe.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
query = query.Where("ccl.bundle_uuid = ?", req.BundleUuid)
|
query = query.Where("ccl.bundle_uuid = ?", req.BundleUuid)
|
||||||
}
|
}
|
||||||
@ -219,11 +208,10 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Joins("left join cast_cost_log ccl on ccl.work_uuid = cast_work.uuid").
|
Joins("left join cast_cost_log ccl on ccl.work_uuid = cast_work.uuid").
|
||||||
Joins("INNER JOIN cast_work_log cwl on cwl.work_uuid = cast_work.uuid and cwl.work_status = 9").
|
Joins("INNER JOIN cast_work_log cwl on cwl.work_uuid = cast_work.uuid and cwl.work_status = 9").
|
||||||
Where("cwe.cost_type != 1").
|
Where("cwe.cost_type != 1").
|
||||||
Where("cast_work.work_category = 2").
|
|
||||||
Where("cwl.update_time >= ?", req.Start+" 00:00:00").
|
Where("cwl.update_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("cwl.update_time <= ?", req.End+" 23:59:59").
|
Where("cwl.update_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and ccl.deleted_at = 0 and cwe.deleted_at = 0 and cwl.deleted_at = 0")
|
Where("cast_work.deleted_at = 0 and ccl.deleted_at = 0 and cwe.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
query = query.Where("ccl.bundle_uuid = ?", req.BundleUuid)
|
query = query.Where("ccl.bundle_uuid = ?", req.BundleUuid)
|
||||||
}
|
}
|
||||||
@ -251,7 +239,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Joins("LEFT JOIN cast_work_log AS cwl ON cwl.work_uuid = cw.uuid and cwl.work_status = 9").
|
Joins("LEFT JOIN cast_work_log AS cwl ON cwl.work_uuid = cw.uuid and cwl.work_status = 9").
|
||||||
Where("cwl.work_status = 9").
|
Where("cwl.work_status = 9").
|
||||||
Where("cwe.cost_type in ?", []int{1, 2}).
|
Where("cwe.cost_type in ?", []int{1, 2}).
|
||||||
Where("cw.work_category = ?", 2).
|
|
||||||
Where("cw.status in ?", []int{7, 6, 9}).
|
Where("cw.status in ?", []int{7, 6, 9}).
|
||||||
Where("cwl.update_time >= ?", req.Start+" 00:00:00").
|
Where("cwl.update_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("cwl.update_time <= ?", req.End+" 23:59:59").
|
Where("cwl.update_time <= ?", req.End+" 23:59:59").
|
||||||
@ -334,13 +321,13 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
newVideoUsed = videoCountInfo.VideoUsed + videoCountInfo.UnUsedVideo
|
newVideoUsed = videoCountInfo.VideoUsed + videoCountInfo.UnUsedVideo
|
||||||
} else {
|
} else {
|
||||||
query = app.ModuleClients.BundleDB.Model(&model.CastWork{}).
|
query = app.ModuleClients.BundleDB.Model(&model.CastWork{}).
|
||||||
Joins("LEFT JOIN cast_work_extra cwe ON cwe.work_uuid = cast_work.uuid").
|
Joins("left join bundle_balance bb ON CAST(bb.user_id AS CHAR) COLLATE utf8mb4_general_ci = cast_work.artist_uuid COLLATE utf8mb4_general_ci AND cast_work.submit_time >= bb.start_at AND cast_work.submit_time <= bb.expired_at and bb.month = DATE_FORMAT(cast_work.submit_time, '%Y-%m')").
|
||||||
Joins("left join bundle_order_records bor ON bor.uuid COLLATE utf8mb4_general_ci = cwe.bundle_order_uuid COLLATE utf8mb4_general_ci").
|
Joins("left join bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Where("cast_work.work_category = 2").
|
Where("cast_work.work_category = 2").
|
||||||
Where("cast_work.submit_time >= ?", req.Start+" 00:00:00").
|
Where("cast_work.submit_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and bor.deleted_at IS NULL and cwe.deleted_at = 0").
|
Where("cast_work.deleted_at = 0 and bor.deleted_at IS NULL and bb.deleted_at IS NULL").
|
||||||
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
||||||
err = query.Count(&newVideoUsed).Error
|
err = query.Count(&newVideoUsed).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -355,7 +342,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.work_category = 2"). // 视频类型
|
Where("cast_work.work_category = 2"). // 视频类型
|
||||||
Where("cwe.cost_type = 1"). // 套餐类型
|
Where("cwe.cost_type = 1"). // 套餐类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0")
|
Where("cast_work.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
@ -373,7 +359,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.work_category = 2"). // 视频类型
|
Where("cast_work.work_category = 2"). // 视频类型
|
||||||
Where("cwe.cost_type in ?", []int{2, 3}). // 增值类型
|
Where("cwe.cost_type in ?", []int{2, 3}). // 增值类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0")
|
Where("cast_work.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
@ -473,13 +458,13 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
newImageUsed = imageCountInfo.ImageUsed + imageCountInfo.UnUsedImage
|
newImageUsed = imageCountInfo.ImageUsed + imageCountInfo.UnUsedImage
|
||||||
} else {
|
} else {
|
||||||
query = app.ModuleClients.BundleDB.Model(&model.CastWork{}).
|
query = app.ModuleClients.BundleDB.Model(&model.CastWork{}).
|
||||||
Joins("LEFT JOIN cast_work_extra cwe ON cwe.work_uuid = cast_work.uuid ").
|
Joins("left join bundle_balance bb ON CAST(bb.user_id AS CHAR) COLLATE utf8mb4_general_ci = cast_work.artist_uuid COLLATE utf8mb4_general_ci AND cast_work.submit_time >= bb.start_at AND cast_work.submit_time <= bb.expired_at and bb.month = DATE_FORMAT(cast_work.submit_time, '%Y-%m')").
|
||||||
Joins("left join bundle_order_records bor ON bor.uuid COLLATE utf8mb4_general_ci = cwe.bundle_order_uuid COLLATE utf8mb4_general_ci").
|
Joins("left join bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Where("cast_work.work_category = 1").
|
Where("cast_work.work_category = 1").
|
||||||
Where("cast_work.submit_time >= ?", req.Start+" 00:00:00").
|
Where("cast_work.submit_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and bor.deleted_at IS NULL and cwe.deleted_at = 0").
|
Where("cast_work.deleted_at = 0 and bor.deleted_at IS NULL and bb.deleted_at IS NULL").
|
||||||
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
||||||
err = query.Count(&newImageUsed).Error
|
err = query.Count(&newImageUsed).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -494,7 +479,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.work_category = 1"). // 图文类型
|
Where("cast_work.work_category = 1"). // 图文类型
|
||||||
Where("cwe.cost_type = 1 "). // 套餐类型
|
Where("cwe.cost_type = 1 "). // 套餐类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0")
|
Where("cast_work.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
@ -512,7 +496,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cast_work.work_category = 1"). // 图文类型
|
Where("cast_work.work_category = 1"). // 图文类型
|
||||||
Where("cwe.cost_type in ?", []int{2, 3}). // 增值类型
|
Where("cwe.cost_type in ?", []int{2, 3}). // 增值类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0")
|
Where("cast_work.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
@ -540,7 +523,7 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
Where("cwa.submit_time <= ?", req.End+" 23:59:59").
|
Where("cwa.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cwa.deleted_at = 0")
|
Where("cwa.deleted_at = 0")
|
||||||
if req.BundleUuid != "" {
|
if req.BundleUuid != "" {
|
||||||
query = query.Where("ccal.bundle_uuid = ?", req.BundleUuid)
|
query = query.Where("ccl.bundle_uuid = ?", req.BundleUuid)
|
||||||
}
|
}
|
||||||
err = query.Scan(&dataAnalysisCountInfo).Error
|
err = query.Scan(&dataAnalysisCountInfo).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -551,11 +534,11 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
newDataAnalysisUsed = dataAnalysisCountInfo.DataAnalysisUsed + dataAnalysisCountInfo.UnUsedDataAnalysis
|
newDataAnalysisUsed = dataAnalysisCountInfo.DataAnalysisUsed + dataAnalysisCountInfo.UnUsedDataAnalysis
|
||||||
} else {
|
} else {
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_work_analysis as cwa").
|
query = app.ModuleClients.BundleDB.Table("cast_work_analysis as cwa").
|
||||||
Joins("LEFT JOIN cast_work_analysis_extra cwae ON cwae.analysis_uuid = cwa.uuid").
|
Joins("left join bundle_balance bb ON CAST(bb.user_id AS CHAR) COLLATE utf8mb4_general_ci = cwa.artist_id COLLATE utf8mb4_general_ci AND cwa.submit_time >= bb.start_at AND cwa.submit_time <= bb.expired_at and bb.month = DATE_FORMAT(cwa.submit_time, '%Y-%m')").
|
||||||
Joins("left join bundle_order_records bor ON bor.uuid COLLATE utf8mb4_general_ci = cwae.bundle_order_uuid COLLATE utf8mb4_general_ci").
|
Joins("left join bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Where("cwa.submit_time >= ?", req.Start+" 00:00:00").
|
Where("cwa.submit_time >= ?", req.Start+" 00:00:00").
|
||||||
Where("cwa.submit_time <= ?", req.End+" 23:59:59").
|
Where("cwa.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cwa.deleted_at = 0 and bor.deleted_at IS NULL and cwae.deleted_at = 0").
|
Where("cwa.deleted_at = 0 and bor.deleted_at IS NULL and bb.deleted_at IS NULL").
|
||||||
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
||||||
err = query.Count(&newDataAnalysisUsed).Error
|
err = query.Count(&newDataAnalysisUsed).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -593,78 +576,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//==================竞品数====================
|
|
||||||
var newConpetitiveUsed int64
|
|
||||||
type ConpetitiveResult struct {
|
|
||||||
ConpetitiveUsed int64 `gorm:"column:conpetitive_used"`
|
|
||||||
UnUsedConpetitive int64 `gorm:"column:un_used_conpetitive"`
|
|
||||||
}
|
|
||||||
var conpetitiveCountInfo ConpetitiveResult
|
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Select(`
|
|
||||||
SUM(CASE WHEN cccrl.uuid IS NOT NULL AND cccrl.deleted_at = 0 THEN 1 ELSE 0 END) AS conpetitive_used,
|
|
||||||
SUM(CASE WHEN cccrl.uuid IS NULL THEN 1 ELSE 0 END) AS un_used_conpetitive
|
|
||||||
`).
|
|
||||||
Joins("left join cast_cost_competitive_report_log cccrl on cccrl.report_uuid = ccr.uuid").
|
|
||||||
Where("ccr.submit_time >= ?", req.Start+" 00:00:00").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccr.deleted_at = 0")
|
|
||||||
if req.BundleUuid != "" {
|
|
||||||
query = query.Where("cccrl.bundle_uuid = ?", req.BundleUuid)
|
|
||||||
}
|
|
||||||
err = query.Scan(&conpetitiveCountInfo).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.BundleUuid == "" {
|
|
||||||
newConpetitiveUsed = conpetitiveCountInfo.ConpetitiveUsed + conpetitiveCountInfo.UnUsedConpetitive
|
|
||||||
} else {
|
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("LEFT JOIN cast_competitive_report_extra ccrpe ON ccrpe.report_uuid = ccr.uuid").
|
|
||||||
Joins("left join bundle_order_records bor ON bor.uuid COLLATE utf8mb4_general_ci = ccrpe.bundle_order_uuid COLLATE utf8mb4_general_ci").
|
|
||||||
Where("ccr.submit_time >= ?", req.Start+" 00:00:00").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccr.deleted_at = 0 and bor.deleted_at IS NULL and ccrpe.deleted_at = 0").
|
|
||||||
Where("bor.bundle_uuid = ?", req.BundleUuid)
|
|
||||||
err = query.Count(&newConpetitiveUsed).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//竞品数套餐总已上传数
|
|
||||||
var totalUploadedBundleConpetitiveCount int64
|
|
||||||
queryBundleConpetitive := app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("left join cast_cost_competitive_report_log cccrl on cccrl.report_uuid = ccr.uuid AND cccrl.deleted_at = 0").
|
|
||||||
Joins("left join cast_competitive_report_extra ccrpe on ccrpe.report_uuid = ccr.uuid AND ccrpe.deleted_at = 0").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccrpe.cost_type = 1"). // 套餐类型
|
|
||||||
Where("ccr.deleted_at = 0")
|
|
||||||
if req.BundleUuid != "" {
|
|
||||||
queryBundleConpetitive = queryBundleConpetitive.Where("cccrl.bundle_uuid = ?", req.BundleUuid)
|
|
||||||
}
|
|
||||||
err = queryBundleConpetitive.Count(&totalUploadedBundleConpetitiveCount).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//竞品数增值总已上传数
|
|
||||||
var totalUploadedIncreaseConpetitiveCount int64
|
|
||||||
queryIncreaseConpetitive := app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("left join cast_cost_competitive_report_log cccrl on cccrl.report_uuid = ccr.uuid AND cccrl.deleted_at = 0").
|
|
||||||
Joins("left join cast_competitive_report_extra ccrpe on ccrpe.report_uuid = ccr.uuid AND ccrpe.deleted_at = 0").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccrpe.cost_type in ?", []int{2, 3}). // 增值类型
|
|
||||||
Where("ccr.deleted_at = 0")
|
|
||||||
if req.BundleUuid != "" {
|
|
||||||
queryIncreaseConpetitive = queryIncreaseConpetitive.Where("cccrl.bundle_uuid = ?", req.BundleUuid)
|
|
||||||
}
|
|
||||||
err = queryIncreaseConpetitive.Count(&totalUploadedIncreaseConpetitiveCount).Error
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取手动增加套餐额度
|
//获取手动增加套餐额度
|
||||||
manualIncreaseBalance, err := manualIncreaseBundleBalance(req.Start+" 00:00:00", req.End+" 23:59:59", req.BundleUuid)
|
manualIncreaseBalance, err := manualIncreaseBundleBalance(req.Start+" 00:00:00", req.End+" 23:59:59", req.BundleUuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -683,8 +594,6 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
result.NewUploadedImageCount = newImageUsed
|
result.NewUploadedImageCount = newImageUsed
|
||||||
//----------数据分析---------
|
//----------数据分析---------
|
||||||
result.NewUploadedDataAnalysisCount = newDataAnalysisUsed
|
result.NewUploadedDataAnalysisCount = newDataAnalysisUsed
|
||||||
//----------竞品数---------
|
|
||||||
result.NewUploadedCompetitiveCount = newConpetitiveUsed
|
|
||||||
|
|
||||||
// ==============数据分析暂时没数据============
|
// ==============数据分析暂时没数据============
|
||||||
|
|
||||||
@ -715,9 +624,7 @@ func MetricsBusiness(req *bundle.MetricsBusinessReq) (result *bundle.MetricsBusi
|
|||||||
//数据分析
|
//数据分析
|
||||||
result.NewPendingUploadDataAnalysisCount = int64(BundleRelease.DataAnalysis) + int64(BundleAutoRelease.DataAnalysis) + int64(IncreaseRelease.DataAnalysis) + int64(IncreaseAutoRelease.DataAnalysis) + int64(manualIncreaseBalance.TotalDataAnalysisAdditional)
|
result.NewPendingUploadDataAnalysisCount = int64(BundleRelease.DataAnalysis) + int64(BundleAutoRelease.DataAnalysis) + int64(IncreaseRelease.DataAnalysis) + int64(IncreaseAutoRelease.DataAnalysis) + int64(manualIncreaseBalance.TotalDataAnalysisAdditional)
|
||||||
result.TotalPendingUploadDataAnalysisCount = int64(endBundleRelease.DataAnalysis) + int64(endIncreaseRelease.DataAnalysis) - int64(totalUploadedBundleDataAnalysisCount) - int64(totalUploadedIncreaseDataAnalysisCount) + int64(totalManualIncreaseBalance.TotalDataAnalysisAdditional)
|
result.TotalPendingUploadDataAnalysisCount = int64(endBundleRelease.DataAnalysis) + int64(endIncreaseRelease.DataAnalysis) - int64(totalUploadedBundleDataAnalysisCount) - int64(totalUploadedIncreaseDataAnalysisCount) + int64(totalManualIncreaseBalance.TotalDataAnalysisAdditional)
|
||||||
//竞品数
|
|
||||||
result.NewPendingUploadCompetitiveCount = int64(BundleRelease.Competitive) + int64(BundleAutoRelease.Competitive) + int64(IncreaseRelease.Competitive) + int64(IncreaseAutoRelease.Competitive) + int64(manualIncreaseBalance.TotalCompetitiveAdditional)
|
|
||||||
result.TotalPendingUploadCompetitiveCount = int64(endBundleRelease.Competitive) + int64(endIncreaseRelease.Competitive) - int64(totalUploadedBundleConpetitiveCount) - int64(totalUploadedIncreaseConpetitiveCount) + int64(totalManualIncreaseBalance.TotalCompetitiveAdditional)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -734,7 +641,6 @@ type BalanceInfo struct {
|
|||||||
Video int
|
Video int
|
||||||
Image int
|
Image int
|
||||||
DataAnalysis int
|
DataAnalysis int
|
||||||
Competitive int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bundle.MetricsOperatingCreateResp, err error) {
|
func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bundle.MetricsOperatingCreateResp, err error) {
|
||||||
@ -779,7 +685,6 @@ func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bund
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("work_category = 2"). // 视频类型
|
Where("work_category = 2"). // 视频类型
|
||||||
Where("cwe.cost_type = 1"). // 套餐类型
|
Where("cwe.cost_type = 1"). // 套餐类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and cwe.deleted_at = 0").
|
Where("cast_work.deleted_at = 0 and cwe.deleted_at = 0").
|
||||||
Count(&totalUploadedBundleVideoCount)
|
Count(&totalUploadedBundleVideoCount)
|
||||||
@ -790,7 +695,6 @@ func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bund
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("work_category = 2"). // 视频类型
|
Where("work_category = 2"). // 视频类型
|
||||||
Where("cwe.cost_type in ?", []int{2, 3}). // 增值类型或扩展类型
|
Where("cwe.cost_type in ?", []int{2, 3}). // 增值类型或扩展类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and cwe.deleted_at = 0").
|
Where("cast_work.deleted_at = 0 and cwe.deleted_at = 0").
|
||||||
Count(&totalUploadedIncreaseVideoCount)
|
Count(&totalUploadedIncreaseVideoCount)
|
||||||
@ -840,7 +744,6 @@ func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bund
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("work_category = 1"). // 图文类型
|
Where("work_category = 1"). // 图文类型
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.status != 8").
|
|
||||||
// Where("cwe.cost_type = 2"). // 套餐类型
|
// Where("cwe.cost_type = 2"). // 套餐类型
|
||||||
Where("deleted_at = 0").
|
Where("deleted_at = 0").
|
||||||
Count(&totalUploadedImageCount)
|
Count(&totalUploadedImageCount)
|
||||||
@ -852,7 +755,6 @@ func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bund
|
|||||||
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
Where("cast_work.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("work_category = 1"). // 图文类型
|
Where("work_category = 1"). // 图文类型
|
||||||
Where("cwe.cost_type = 1"). // 套餐类型
|
Where("cwe.cost_type = 1"). // 套餐类型
|
||||||
Where("cast_work.status != 8").
|
|
||||||
Where("cast_work.origin_uuid = ''").
|
Where("cast_work.origin_uuid = ''").
|
||||||
Where("cast_work.deleted_at = 0 and cwe.deleted_at = 0").
|
Where("cast_work.deleted_at = 0 and cwe.deleted_at = 0").
|
||||||
Count(&totalUploadedBundleImageCount)
|
Count(&totalUploadedBundleImageCount)
|
||||||
@ -896,41 +798,9 @@ func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bund
|
|||||||
Joins("left join cast_work_analysis_extra cwae on cwae.analysis_uuid = cwa.uuid AND cwae.deleted_at = 0").
|
Joins("left join cast_work_analysis_extra cwae on cwae.analysis_uuid = cwa.uuid AND cwae.deleted_at = 0").
|
||||||
Where("cwa.submit_time <= ?", req.End+" 23:59:59").
|
Where("cwa.submit_time <= ?", req.End+" 23:59:59").
|
||||||
Where("cwae.cost_type in ?", []int{2, 3}). // 增值类型
|
Where("cwae.cost_type in ?", []int{2, 3}). // 增值类型
|
||||||
Where("cwa.deleted_at = 0 and cwae.deleted_at = 0").
|
Where("cwa.deleted_at = 0 and cwe.deleted_at = 0").
|
||||||
Count(&totalUploadedIncreaseDataAnalysisCount)
|
Count(&totalUploadedIncreaseDataAnalysisCount)
|
||||||
|
|
||||||
//====================竞品数=======================
|
|
||||||
var newUploadedBundleCompetitiveCount int64
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Where("ccr.submit_time >= ?", req.Start+" 00:00:00").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccr.deleted_at = 0").
|
|
||||||
Count(&newUploadedBundleCompetitiveCount)
|
|
||||||
result.NewUploadedBundleCompetitiveCount = newUploadedBundleCompetitiveCount
|
|
||||||
|
|
||||||
var totalUploadedCompetitiveCount int64
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccr.deleted_at = 0").
|
|
||||||
Count(&totalUploadedCompetitiveCount)
|
|
||||||
result.TotalUploadedBundleCompetitiveCount = totalUploadedCompetitiveCount
|
|
||||||
|
|
||||||
var totalUploadedBundleCompetitiveCount int64
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("left join cast_competitive_report_extra ccre on ccre.report_uuid = ccr.uuid AND ccre.deleted_at = 0").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccre.cost_type = 1"). // 套餐类型
|
|
||||||
Where("ccr.deleted_at = 0 and ccre.deleted_at = 0").
|
|
||||||
Count(&totalUploadedBundleCompetitiveCount)
|
|
||||||
|
|
||||||
var totalUploadedIncreaseCompetitiveCount int64
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("left join cast_competitive_report_extra ccre on ccre.report_uuid = ccr.uuid AND ccre.deleted_at = 0").
|
|
||||||
Where("ccr.submit_time <= ?", req.End+" 23:59:59").
|
|
||||||
Where("ccre.cost_type in ?", []int{2, 3}). // 增值类型
|
|
||||||
Where("ccr.deleted_at = 0 and ccre.deleted_at = 0").
|
|
||||||
Count(&totalUploadedIncreaseCompetitiveCount)
|
|
||||||
|
|
||||||
endMonth := timeParse(req.End + " 23:59:59").Format("2006-01")
|
endMonth := timeParse(req.End + " 23:59:59").Format("2006-01")
|
||||||
startMonth := timeParse(req.Start + " 00:00:00").Format("2006-01")
|
startMonth := timeParse(req.Start + " 00:00:00").Format("2006-01")
|
||||||
|
|
||||||
@ -970,18 +840,14 @@ func MetricsOperatingCreate(req *bundle.MetricsOperatingCreateReq) (result *bund
|
|||||||
result.NewPendingUploadIncreaseDataAnalysisCount = int64(IncreaseRelease.DataAnalysis) + int64(IncreaseAutoRelease.DataAnalysis) + int64(manualIncreaseBalance.TotalDataAnalysisAdditional)
|
result.NewPendingUploadIncreaseDataAnalysisCount = int64(IncreaseRelease.DataAnalysis) + int64(IncreaseAutoRelease.DataAnalysis) + int64(manualIncreaseBalance.TotalDataAnalysisAdditional)
|
||||||
result.TotalPendingUploadBundleDataAnalysisCount = int64(endBundleRelease.DataAnalysis) - int64(totalUploadedBundleDataAnalysisCount)
|
result.TotalPendingUploadBundleDataAnalysisCount = int64(endBundleRelease.DataAnalysis) - int64(totalUploadedBundleDataAnalysisCount)
|
||||||
result.TotalPendingUploadIncreaseDataAnalysisCount = int64(endIncreaseRelease.DataAnalysis) - int64(totalUploadedIncreaseDataAnalysisCount) + int64(totalManualIncreaseBalance.TotalDataAnalysisAdditional)
|
result.TotalPendingUploadIncreaseDataAnalysisCount = int64(endIncreaseRelease.DataAnalysis) - int64(totalUploadedIncreaseDataAnalysisCount) + int64(totalManualIncreaseBalance.TotalDataAnalysisAdditional)
|
||||||
//竞品数
|
|
||||||
result.NewPendingUploadBundleCompetitiveCount = int64(BundleRelease.Competitive) + int64(BundleAutoRelease.Competitive)
|
|
||||||
result.NewPendingUploadIncreaseCompetitiveCount = int64(IncreaseRelease.Competitive) + int64(IncreaseAutoRelease.Competitive) + int64(manualIncreaseBalance.TotalCompetitiveAdditional)
|
|
||||||
result.TotalPendingUploadBundleCompetitiveCount = int64(endBundleRelease.Competitive) - int64(totalUploadedBundleCompetitiveCount)
|
|
||||||
result.TotalPendingUploadIncreaseCompetitiveCount = int64(endIncreaseRelease.Competitive) - int64(totalUploadedIncreaseCompetitiveCount) + int64(totalManualIncreaseBalance.TotalCompetitiveAdditional)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 手动扩套餐总数统计
|
// 手动扩套餐总数统计
|
||||||
func manualIncreaseBundleBalance(startTime string, endTime string, bundleUUID string) (data model.ManualIncreaseBundleBalance, err error) {
|
func manualIncreaseBundleBalance(startTime string, endTime string, bundleUUID string) (data model.ManualIncreaseBundleBalance, err error) {
|
||||||
quary := app.ModuleClients.BundleDB.Model(&model.BundleExtensionRecords{}).
|
quary := app.ModuleClients.BundleDB.Model(&model.BundleExtensionRecords{}).
|
||||||
Select("SUM(account_additional) as total_account_additional, SUM(video_additional) as total_video_additional, SUM(images_additional) as total_image_additional, SUM(data_additional) as total_data_analysis_additional, SUM(competitive_additional) as total_competitive_additional").
|
Select("SUM(account_additional) as total_account_additional, SUM(video_additional) as total_video_additional, SUM(images_additional) as total_image_additional, SUM(data_additional) as total_data_analysis_additional").
|
||||||
Where("bundle_extension_records.type = 1").
|
Where("bundle_extension_records.type = 1").
|
||||||
Where("bundle_extension_records.deleted_at is null")
|
Where("bundle_extension_records.deleted_at is null")
|
||||||
if startTime != "" {
|
if startTime != "" {
|
||||||
@ -1024,12 +890,7 @@ func balanceInfoWithShop(startMonth string, endMonth string, startTime string, e
|
|||||||
bb.bundle_data_analysis_number +
|
bb.bundle_data_analysis_number +
|
||||||
bb.monthly_bundle_limit_data_analysis_number +
|
bb.monthly_bundle_limit_data_analysis_number +
|
||||||
bb.monthly_bundle_limit_expired_data_analysis_number
|
bb.monthly_bundle_limit_expired_data_analysis_number
|
||||||
) AS data_analysis,
|
) AS data_analysis
|
||||||
(
|
|
||||||
bb.bundle_competitive_number +
|
|
||||||
bb.monthly_bundle_limit_competitive_number +
|
|
||||||
bb.monthly_bundle_limit_expired_competitive_number
|
|
||||||
) AS competitive
|
|
||||||
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 = 新增待上传数量
|
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 = 新增待上传数量
|
||||||
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Joins(`INNER JOIN (
|
Joins(`INNER JOIN (
|
||||||
@ -1058,8 +919,7 @@ func balanceInfoWithShop(startMonth string, endMonth string, startTime string, e
|
|||||||
SUM(statistic.account) AS account,
|
SUM(statistic.account) AS account,
|
||||||
SUM(statistic.video) AS video,
|
SUM(statistic.video) AS video,
|
||||||
SUM(statistic.image) AS image,
|
SUM(statistic.image) AS image,
|
||||||
SUM(statistic.data_analysis) AS data_analysis,
|
SUM(statistic.data_analysis) AS data_analysis
|
||||||
SUM(statistic.competitive) AS competitive
|
|
||||||
`).
|
`).
|
||||||
Scan(&data)
|
Scan(&data)
|
||||||
return
|
return
|
||||||
@ -1085,12 +945,7 @@ func IncreasealanceInfoWithShop(startMonth string, endMonth string, startTime st
|
|||||||
bb.increase_data_analysis_number +
|
bb.increase_data_analysis_number +
|
||||||
bb.monthly_increase_limit_data_analysis_number +
|
bb.monthly_increase_limit_data_analysis_number +
|
||||||
bb.monthly_increase_limit_expired_data_analysis_number
|
bb.monthly_increase_limit_expired_data_analysis_number
|
||||||
) AS data_analysis,
|
) AS data_analysis
|
||||||
(
|
|
||||||
bb.increase_competitive_number +
|
|
||||||
bb.monthly_increase_limit_competitive_number +
|
|
||||||
bb.monthly_increase_limit_expired_competitive_number
|
|
||||||
) AS competitive
|
|
||||||
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 = 新增待上传数量
|
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 = 新增待上传数量
|
||||||
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Joins(`INNER JOIN (
|
Joins(`INNER JOIN (
|
||||||
@ -1118,8 +973,7 @@ func IncreasealanceInfoWithShop(startMonth string, endMonth string, startTime st
|
|||||||
SUM(statistic.account) AS account,
|
SUM(statistic.account) AS account,
|
||||||
SUM(statistic.video) AS video,
|
SUM(statistic.video) AS video,
|
||||||
SUM(statistic.image) AS image,
|
SUM(statistic.image) AS image,
|
||||||
SUM(statistic.data_analysis) AS data_analysis,
|
SUM(statistic.data_analysis) AS data_analysis
|
||||||
SUM(statistic.competitive) AS competitive
|
|
||||||
`).
|
`).
|
||||||
Scan(&data)
|
Scan(&data)
|
||||||
return
|
return
|
||||||
@ -1133,7 +987,6 @@ func getBalanceInfo(month string, bundleUUID string) (data BalanceInfo) { // 获
|
|||||||
data.Video = bundle.Video + increase.Video
|
data.Video = bundle.Video + increase.Video
|
||||||
data.Image = bundle.Image + increase.Image
|
data.Image = bundle.Image + increase.Image
|
||||||
data.DataAnalysis = bundle.DataAnalysis + increase.DataAnalysis
|
data.DataAnalysis = bundle.DataAnalysis + increase.DataAnalysis
|
||||||
data.Competitive = bundle.Competitive + increase.Competitive
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1171,17 +1024,7 @@ func getBundleBalanceInfo(month string, bundleUUID string, endTime string) (data
|
|||||||
bb.bundle_limit_data_analysis_expired_consumption_number -
|
bb.bundle_limit_data_analysis_expired_consumption_number -
|
||||||
bb.monthly_bundle_limit_expired_data_analysis_consumption_number -
|
bb.monthly_bundle_limit_expired_data_analysis_consumption_number -
|
||||||
bb.monthly_bundle_limit_data_analysis_consumption_number
|
bb.monthly_bundle_limit_data_analysis_consumption_number
|
||||||
) AS data_analysis,
|
) AS data_analysis
|
||||||
(
|
|
||||||
bb.bundle_competitive_number +
|
|
||||||
bb.monthly_bundle_limit_competitive_number +
|
|
||||||
bb.monthly_bundle_limit_expired_competitive_number +
|
|
||||||
bb.invalid_bundle_competitive_number +
|
|
||||||
bb.bundle_limit_competitive_consumption_number +
|
|
||||||
bb.bundle_limit_competitive_expired_consumption_number -
|
|
||||||
bb.monthly_bundle_limit_expired_competitive_consumption_number -
|
|
||||||
bb.monthly_bundle_limit_competitive_consumption_number
|
|
||||||
) AS competitive
|
|
||||||
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 + 限制不过期类型的总共已用 + 限制过期类型的总共已用 + 已过期的数量 = 总发放数
|
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 + 限制不过期类型的总共已用 + 限制过期类型的总共已用 + 已过期的数量 = 总发放数
|
||||||
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Where("bor.deleted_at is null and bor.status=2").
|
Where("bor.deleted_at is null and bor.status=2").
|
||||||
@ -1216,8 +1059,7 @@ func getBundleBalanceInfo(month string, bundleUUID string, endTime string) (data
|
|||||||
SUM(statistic.account) AS account,
|
SUM(statistic.account) AS account,
|
||||||
SUM(statistic.video) AS video,
|
SUM(statistic.video) AS video,
|
||||||
SUM(statistic.image) AS image,
|
SUM(statistic.image) AS image,
|
||||||
SUM(statistic.data_analysis) AS data_analysis,
|
SUM(statistic.data_analysis) AS data_analysis
|
||||||
SUM(statistic.competitive) AS competitive
|
|
||||||
`).
|
`).
|
||||||
Scan(&data)
|
Scan(&data)
|
||||||
return
|
return
|
||||||
@ -1257,17 +1099,7 @@ func getIncreaseBalanceInfo(month string, bundleUUID string, endTime string) (da
|
|||||||
bb.increase_limit_data_analysis_expired_consumption_number -
|
bb.increase_limit_data_analysis_expired_consumption_number -
|
||||||
bb.monthly_increase_limit_expired_data_analysis_consumption_number -
|
bb.monthly_increase_limit_expired_data_analysis_consumption_number -
|
||||||
bb.monthly_increase_limit_data_analysis_consumption_number
|
bb.monthly_increase_limit_data_analysis_consumption_number
|
||||||
) AS data_analysis,
|
) AS data_analysis
|
||||||
(
|
|
||||||
bb.increase_competitive_number +
|
|
||||||
bb.monthly_increase_limit_competitive_number +
|
|
||||||
bb.monthly_increase_limit_expired_competitive_number +
|
|
||||||
bb.invalid_increase_competitive_number +
|
|
||||||
bb.increase_limit_competitive_consumption_number +
|
|
||||||
bb.increase_limit_competitive_expired_consumption_number -
|
|
||||||
bb.monthly_increase_limit_expired_competitive_consumption_number -
|
|
||||||
bb.monthly_increase_limit_competitive_consumption_number
|
|
||||||
) AS competitive
|
|
||||||
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 + 限制不过期类型的总共已用 + 限制过期类型的总共已用 + 已过期的数量 = 总发放数
|
`). // 不限制类型的总数 + 限制不过期类型的当月可用 + 限制过期类型的当月可用 + 限制不过期类型的总共已用 + 限制过期类型的总共已用 + 已过期的数量 = 总发放数
|
||||||
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
Joins("LEFT JOIN bundle_order_records bor ON bor.uuid = bb.order_uuid").
|
||||||
Joins(`INNER JOIN (
|
Joins(`INNER JOIN (
|
||||||
@ -1302,8 +1134,7 @@ func getIncreaseBalanceInfo(month string, bundleUUID string, endTime string) (da
|
|||||||
SUM(statistic.account) AS account,
|
SUM(statistic.account) AS account,
|
||||||
SUM(statistic.video) AS video,
|
SUM(statistic.video) AS video,
|
||||||
SUM(statistic.image) AS image,
|
SUM(statistic.image) AS image,
|
||||||
SUM(statistic.data_analysis) AS data_analysis,
|
SUM(statistic.data_analysis) AS data_analysis
|
||||||
SUM(statistic.competitive) AS competitive
|
|
||||||
`).
|
`).
|
||||||
Scan(&data)
|
Scan(&data)
|
||||||
return
|
return
|
||||||
@ -1390,32 +1221,7 @@ func MetricsOperatingStatus(req *bundle.MetricsOperatingStatusReq) (data *bundle
|
|||||||
Where("ccal.operator_name = '系统自动确定'").
|
Where("ccal.operator_name = '系统自动确定'").
|
||||||
Where("cast_work_analysis.submit_time <= ?", req.Date+" 23:59:59").
|
Where("cast_work_analysis.submit_time <= ?", req.Date+" 23:59:59").
|
||||||
Count(&data.AutoConfirmDataAnalysisCount)
|
Count(&data.AutoConfirmDataAnalysisCount)
|
||||||
//================竞品数==================
|
|
||||||
var competitiveStatistic = func(status int8) (i int64) {
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").Where("ccr.work_report_status = ?", status).Where("deleted_at = 0 and submit_time <= ?", req.Date+" 23:59:59").Count(&i)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data.ReviewingCompetitiveCount = competitiveStatistic(2)
|
|
||||||
data.RejectCompetitiveCount = competitiveStatistic(3)
|
|
||||||
data.WaitConfirmCompetitiveCount = competitiveStatistic(4)
|
|
||||||
data.PendingUploadCompetitiveCount = competitiveStatistic(6)
|
|
||||||
data.UploadSuccessCompetitiveCount = competitiveStatistic(7)
|
|
||||||
data.UploadFailedCompetitiveCount = competitiveStatistic(5)
|
|
||||||
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("left join cast_cost_competitive_report_log cccrl on cccrl.report_uuid = ccr.uuid AND cccrl.deleted_at = 0").
|
|
||||||
Where("ccr.work_report_status in ?", []int{6, 7}).
|
|
||||||
Where("ccr.submit_time <= ?", req.Date+" 23:59:59").
|
|
||||||
Where("cccrl.operator_name != '系统自动确定'").
|
|
||||||
Where("ccr.deleted_at = 0").
|
|
||||||
Count(&data.ArtistConfirmCompetitiveCount)
|
|
||||||
app.ModuleClients.BundleDB.Table("cast_competitive_report as ccr").
|
|
||||||
Joins("left join cast_cost_competitive_report_log cccrl on cccrl.report_uuid = ccr.uuid AND cccrl.deleted_at = 0").
|
|
||||||
Where("ccr.work_report_status in ?", []int{6, 7}).
|
|
||||||
Where("ccr.submit_time <= ?", req.Date+" 23:59:59").
|
|
||||||
Where("cccrl.operator_name = '系统自动确定'").
|
|
||||||
Where("ccr.deleted_at = 0").
|
|
||||||
Count(&data.AutoConfirmCompetitiveCount)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1510,38 +1316,22 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
var start time.Time
|
var start time.Time
|
||||||
var end time.Time
|
var end time.Time
|
||||||
var err error
|
var err error
|
||||||
|
if req.Month != "" {
|
||||||
subQuery := app.ModuleClients.BundleDB.Table("cast_media_account").
|
t, err := time.Parse("2006-01", req.Month)
|
||||||
Select("artist_uuid,any_value(artist_name) as artist_name,any_value(created_at) as created_at").
|
if err != nil {
|
||||||
Group("artist_uuid").
|
return nil, err
|
||||||
Where("deleted_at = 0 and expired != 2")
|
|
||||||
//如果选择了月份
|
|
||||||
if len(req.Month) > 0 {
|
|
||||||
// 构建多个月份的时间范围条件(使用 OR 连接)
|
|
||||||
var conditions []string
|
|
||||||
var args []interface{}
|
|
||||||
for _, month := range req.Month {
|
|
||||||
t, err := time.Parse("2006-01", month)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
start = datetime.BeginOfMonth(t)
|
|
||||||
end = datetime.EndOfMonth(t)
|
|
||||||
// 为每个月添加时间范围条件
|
|
||||||
conditions = append(conditions, "(created_at >= ? AND created_at <= ?)")
|
|
||||||
args = append(args, start.Unix(), end.Unix())
|
|
||||||
}
|
|
||||||
// 使用 OR 连接所有月份条件
|
|
||||||
if len(conditions) > 0 {
|
|
||||||
subQuery = subQuery.Where(strings.Join(conditions, " OR "), args...)
|
|
||||||
}
|
}
|
||||||
|
start = datetime.BeginOfMonth(t)
|
||||||
|
end = datetime.EndOfMonth(t)
|
||||||
} else {
|
} else {
|
||||||
start = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) // Unix 时间戳起始时间
|
start = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC) // Unix 时间戳起始时间
|
||||||
end = time.Date(2099, 12, 31, 23, 59, 59, 0, time.UTC) // 设置一个很远的未来日期
|
end = time.Date(2099, 12, 31, 23, 59, 59, 0, time.UTC) // 设置一个很远的未来日期
|
||||||
subQuery = subQuery.Where("created_at >= ?", start.Unix()).
|
|
||||||
Where("created_at <= ?", end.Unix())
|
|
||||||
}
|
}
|
||||||
|
subQuery := app.ModuleClients.BundleDB.Table("cast_media_account").
|
||||||
|
Select("artist_uuid,any_value(artist_name) as artist_name,any_value(created_at) as created_at").
|
||||||
|
Group("artist_uuid").
|
||||||
|
Where("created_at >= ?", start.Unix()).Where("created_at <= ?", end.Unix()).
|
||||||
|
Where("deleted_at = 0")
|
||||||
query := app.ModuleClients.BundleDB.Table("( ? ) cma", subQuery).
|
query := app.ModuleClients.BundleDB.Table("( ? ) cma", subQuery).
|
||||||
Select(`tiktok.platform_user_id as tiktok_account,
|
Select(`tiktok.platform_user_id as tiktok_account,
|
||||||
tiktok.platform_user_name as tiktok_nickname,
|
tiktok.platform_user_name as tiktok_nickname,
|
||||||
@ -1561,18 +1351,21 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
cma.artist_name,
|
cma.artist_name,
|
||||||
bor.customer_num as user_num
|
bor.customer_num as user_num
|
||||||
`).
|
`).
|
||||||
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 1 and deleted_at = 0 and expired != 2) tiktok on tiktok.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 1 and deleted_at = 0) tiktok on tiktok.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 1 and deleted_at = 0 ) tiktok_auth on tiktok_auth.user_id = tiktok.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 1 and deleted_at = 0) tiktok_auth on tiktok_auth.user_id = tiktok.user_id`).
|
||||||
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 4 and deleted_at = 0 and expired != 2) dm on dm.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 4 and deleted_at = 0) dm on dm.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 4 and deleted_at = 0) dm_auth on dm_auth.user_id = dm.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 4 and deleted_at = 0) dm_auth on dm_auth.user_id = dm.user_id`).
|
||||||
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 3 and deleted_at = 0 and expired != 2) ins on ins.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (SELECT * FROM cast_media_account where platform_id = 3 and deleted_at = 0) ins on ins.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 3 and deleted_at = 0) ins_auth on ins_auth.user_id = ins.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 3 and deleted_at = 0) ins_auth on ins_auth.user_id = ins.user_id`).
|
||||||
Joins(`left join (Select * from cast_media_account where platform_id = 2 and deleted_at = 0 and expired != 2) youtube on youtube.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (Select * from cast_media_account where platform_id = 2 and deleted_at = 0) youtube on youtube.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 2 and deleted_at = 0) youtube_auth on youtube_auth.user_id = youtube.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 2 and deleted_at = 0) youtube_auth on youtube_auth.user_id = youtube.user_id`).
|
||||||
Joins(`left join (Select * from cast_media_account where platform_id = 5 and deleted_at = 0 and expired != 2) bluesky on bluesky.artist_uuid = cma.artist_uuid`).
|
Joins(`left join (Select * from cast_media_account where platform_id = 5 and deleted_at = 0) bluesky on bluesky.artist_uuid = cma.artist_uuid`).
|
||||||
Joins(`left join (Select * from cast_media_auth where platform_id = 5 and deleted_at = 0) bluesky_auth on bluesky_auth.user_id = bluesky.user_id`).
|
Joins(`left join (Select * from cast_media_auth where platform_id = 5 and deleted_at = 0) bluesky_auth on bluesky_auth.user_id = bluesky.user_id`).
|
||||||
Joins(`left join bundle_order_records bor on bor.customer_id COLLATE utf8mb4_general_ci= cma.artist_uuid COLLATE utf8mb4_general_ci`).
|
Joins(`left join bundle_order_records bor on bor.customer_id COLLATE utf8mb4_general_ci= cma.artist_uuid COLLATE utf8mb4_general_ci`).
|
||||||
Where("bor.deleted_at is null")
|
Where("bor.deleted_at is null")
|
||||||
|
if req.Month != "" {
|
||||||
|
query = query.Where("cma.created_at >= ?", start.Unix()).Where("cma.created_at <= ?", end.Unix())
|
||||||
|
}
|
||||||
err = query.Find(&data.Data).Error
|
err = query.Find(&data.Data).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1583,14 +1376,14 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *bundle.MetricsVideoSubmitExportResp, err error) {
|
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *bundle.MetricsVideoSubmitExportResp, err error) {
|
||||||
result = &bundle.MetricsVideoSubmitExportResp{}
|
result = &bundle.MetricsVideoSubmitExportResp{}
|
||||||
var query *gorm.DB
|
var query *gorm.DB
|
||||||
if len(req.Month) == 0 {
|
if req.Month == "" {
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
||||||
Select(`cw.artist_name ,
|
Select(`cw.artist_name ,
|
||||||
cw.title as video_title,
|
cw.title as video_title,
|
||||||
tiktok.created_at as tiktok_upload_time,
|
tiktok.created_at as tiktok_upload_time,
|
||||||
dm.created_at as dm_upload_time,
|
dm.created_at as dm_upload_time,
|
||||||
ins.created_at as instagram_upload_time,
|
ins.created_at as instagram_upload_time,
|
||||||
bor.customer_num as user_num`).
|
bor.customer_num as user_num`).
|
||||||
Joins("left join (select created_at,work_uuid from cast_work_platform_info cwi where cwi.platform_id = 1) tiktok on tiktok.work_uuid = cw.uuid").
|
Joins("left join (select created_at,work_uuid from cast_work_platform_info cwi where cwi.platform_id = 1) tiktok on tiktok.work_uuid = cw.uuid").
|
||||||
Joins("left join (select created_at,work_uuid from cast_work_platform_info cwi where cwi.platform_id = 4) dm on dm.work_uuid = cw.uuid").
|
Joins("left join (select created_at,work_uuid from cast_work_platform_info cwi where cwi.platform_id = 4) dm on dm.work_uuid = cw.uuid").
|
||||||
Joins("left join (select created_at,work_uuid from cast_work_platform_info cwi where cwi.platform_id = 3) ins on ins.work_uuid = cw.uuid").
|
Joins("left join (select created_at,work_uuid from cast_work_platform_info cwi where cwi.platform_id = 3) ins on ins.work_uuid = cw.uuid").
|
||||||
@ -1598,61 +1391,22 @@ func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (result *
|
|||||||
Where("(tiktok.created_at is not null or dm.created_at is not null or ins.created_at is not null) and cw.deleted_at = 0 and bor.deleted_at is null and cw.origin_uuid = ''").
|
Where("(tiktok.created_at is not null or dm.created_at is not null or ins.created_at is not null) and cw.deleted_at = 0 and bor.deleted_at is null and cw.origin_uuid = ''").
|
||||||
Order("cw.artist_name")
|
Order("cw.artist_name")
|
||||||
} else {
|
} else {
|
||||||
// 构建多个月份的时间范围参数
|
|
||||||
var timeRanges []struct {
|
|
||||||
Start int64
|
|
||||||
End int64
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, month := range req.Month {
|
t, err := time.Parse("2006-01", req.Month)
|
||||||
t, err := time.Parse("2006-01", month)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
start := datetime.BeginOfMonth(t)
|
|
||||||
end := datetime.EndOfMonth(t)
|
|
||||||
timeRanges = append(timeRanges, struct {
|
|
||||||
Start int64
|
|
||||||
End int64
|
|
||||||
}{Start: start.Unix(), End: end.Unix()})
|
|
||||||
}
|
|
||||||
// 构建时间筛选 SQL 条件的辅助函数
|
|
||||||
buildTimeFilterSQL := func(tableAlias string) (string, []interface{}) {
|
|
||||||
if len(timeRanges) == 0 {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
var conditions []string
|
|
||||||
var args []interface{}
|
|
||||||
for _, tr := range timeRanges {
|
|
||||||
// 明确指定表别名,避免字段歧义
|
|
||||||
conditions = append(conditions, fmt.Sprintf("(%s.created_at >= ? AND %s.created_at <= ?)", tableAlias, tableAlias))
|
|
||||||
args = append(args, tr.Start, tr.End)
|
|
||||||
}
|
|
||||||
return "(" + strings.Join(conditions, " OR ") + ")", args
|
|
||||||
}
|
}
|
||||||
|
start := datetime.BeginOfMonth(t)
|
||||||
|
end := datetime.EndOfMonth(t)
|
||||||
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
query = app.ModuleClients.BundleDB.Table("cast_work AS cw").
|
||||||
Select(`cw.artist_name, cw.title AS video_title, tiktok.created_at AS tiktok_upload_time, dm.created_at AS dm_upload_time, ins.created_at AS instagram_upload_time, bor.customer_num AS user_num`)
|
Select(`cw.artist_name, cw.title AS video_title, tiktok.created_at AS tiktok_upload_time, dm.created_at AS dm_upload_time, ins.created_at AS instagram_upload_time, bor.customer_num AS user_num`).
|
||||||
|
Joins(`LEFT JOIN cast_work_platform_info tiktok ON tiktok.work_uuid = cw.uuid AND tiktok.platform_id = 1 AND tiktok.created_at >= ? AND tiktok.created_at <= ?`, start.Unix(), end.Unix()).
|
||||||
// 为每个平台添加时间筛选条件
|
Joins(`LEFT JOIN cast_work_platform_info dm ON dm.work_uuid = cw.uuid AND dm.platform_id = 4 AND dm.created_at >= ? AND dm.created_at <= ?`, start.Unix(), end.Unix()).
|
||||||
if len(timeRanges) > 0 {
|
Joins(`LEFT JOIN cast_work_platform_info ins ON ins.work_uuid = cw.uuid AND ins.platform_id = 3 AND ins.created_at >= ? AND ins.created_at <= ?`, start.Unix(), end.Unix()).
|
||||||
// TikTok JOIN
|
Joins(`LEFT JOIN bundle_order_records bor ON bor.customer_id COLLATE utf8mb4_general_ci = cw.artist_uuid COLLATE utf8mb4_general_ci AND bor.deleted_at IS NULL`).
|
||||||
tiktokTimeSQL, tiktokArgs := buildTimeFilterSQL("tiktok")
|
Where(`cw.origin_uuid = '' and cw.deleted_at = 0 AND (tiktok.created_at IS NOT NULL OR dm.created_at IS NOT NULL OR ins.created_at IS NOT NULL)`).
|
||||||
joinSQL := `LEFT JOIN cast_work_platform_info tiktok ON tiktok.work_uuid = cw.uuid AND tiktok.platform_id = 1 AND ` + tiktokTimeSQL
|
|
||||||
query = query.Joins(joinSQL, tiktokArgs...)
|
|
||||||
|
|
||||||
// DM JOIN
|
|
||||||
dmTimeSQL, dmArgs := buildTimeFilterSQL("dm")
|
|
||||||
joinSQL = `LEFT JOIN cast_work_platform_info dm ON dm.work_uuid = cw.uuid AND dm.platform_id = 4 AND ` + dmTimeSQL
|
|
||||||
query = query.Joins(joinSQL, dmArgs...)
|
|
||||||
|
|
||||||
// Instagram JOIN
|
|
||||||
insTimeSQL, insArgs := buildTimeFilterSQL("ins")
|
|
||||||
joinSQL = `LEFT JOIN cast_work_platform_info ins ON ins.work_uuid = cw.uuid AND ins.platform_id = 3 AND ` + insTimeSQL
|
|
||||||
query = query.Joins(joinSQL, insArgs...)
|
|
||||||
}
|
|
||||||
query = query.Joins(`LEFT JOIN bundle_order_records bor ON bor.customer_id COLLATE utf8mb4_general_ci = cw.artist_uuid COLLATE utf8mb4_general_ci AND bor.deleted_at IS NULL`).
|
|
||||||
Where(`cw.deleted_at = 0 AND (tiktok.created_at IS NOT NULL OR dm.created_at IS NOT NULL OR ins.created_at IS NOT NULL)`).
|
|
||||||
Order("cw.artist_name")
|
Order("cw.artist_name")
|
||||||
|
|
||||||
}
|
}
|
||||||
err = query.Find(&result.Data).Error
|
err = query.Find(&result.Data).Error
|
||||||
return
|
return
|
||||||
@ -1665,12 +1419,10 @@ func getRangeMonthlyRelease(startTime time.Time, endTime time.Time, bundleUuid s
|
|||||||
bundleBalanceInfo.Video += b.Video
|
bundleBalanceInfo.Video += b.Video
|
||||||
bundleBalanceInfo.Image += b.Image
|
bundleBalanceInfo.Image += b.Image
|
||||||
bundleBalanceInfo.DataAnalysis += b.DataAnalysis
|
bundleBalanceInfo.DataAnalysis += b.DataAnalysis
|
||||||
bundleBalanceInfo.Competitive += b.Competitive
|
|
||||||
// increaseBalanceInfo.Account += i.Account
|
// increaseBalanceInfo.Account += i.Account
|
||||||
increaseBalanceInfo.Video += i.Video
|
increaseBalanceInfo.Video += i.Video
|
||||||
increaseBalanceInfo.Image += i.Image
|
increaseBalanceInfo.Image += i.Image
|
||||||
increaseBalanceInfo.DataAnalysis += i.DataAnalysis
|
increaseBalanceInfo.DataAnalysis += i.DataAnalysis
|
||||||
increaseBalanceInfo.Competitive += i.Competitive
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1714,8 +1466,6 @@ func getMonthlyRelease(month string, bundleUuid string) (bundleBalanceInfo Balan
|
|||||||
increaseBalanceInfo.Image += (cal(item, item.IncreaseLimitImageNumber, item.MonthlyLimitImageQuotaNumber, t) + cal(item, item.IncreaseLimitImageExpiredNumber, item.MonthlyLimitImageQuotaNumber, t))
|
increaseBalanceInfo.Image += (cal(item, item.IncreaseLimitImageNumber, item.MonthlyLimitImageQuotaNumber, t) + cal(item, item.IncreaseLimitImageExpiredNumber, item.MonthlyLimitImageQuotaNumber, t))
|
||||||
bundleBalanceInfo.DataAnalysis += (cal(item, item.BundleLimitDataAnalysisNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t) + cal(item, item.BundleLimitDataAnalysisExpiredNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t))
|
bundleBalanceInfo.DataAnalysis += (cal(item, item.BundleLimitDataAnalysisNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t) + cal(item, item.BundleLimitDataAnalysisExpiredNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t))
|
||||||
increaseBalanceInfo.DataAnalysis += (cal(item, item.IncreaseLimitDataAnalysisNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t) + cal(item, item.IncreaseLimitDataAnalysisExpiredNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t))
|
increaseBalanceInfo.DataAnalysis += (cal(item, item.IncreaseLimitDataAnalysisNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t) + cal(item, item.IncreaseLimitDataAnalysisExpiredNumber, item.MonthlyLimitDataAnalysisQuotaNumber, t))
|
||||||
bundleBalanceInfo.Competitive += (qua(item, item.BundleLimitCompetitiveNumber, item.MonthlyLimitCompetitiveQuotaNumber, t) + qua(item, item.BundleLimitCompetitiveExpiredNumber, item.MonthlyLimitCompetitiveQuotaNumber, t))
|
|
||||||
increaseBalanceInfo.Competitive += (qua(item, item.IncreaseLimitCompetitiveNumber, item.MonthlyLimitCompetitiveQuotaNumber, t) + qua(item, item.IncreaseLimitCompetitiveExpiredNumber, item.MonthlyLimitCompetitiveQuotaNumber, t))
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1742,68 +1492,3 @@ func cal(data model.BundleBalance, total, limit int, date time.Time) int {
|
|||||||
}
|
}
|
||||||
return min(limit, remaining)
|
return min(limit, remaining)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算每个季度发放的数目
|
|
||||||
func qua(data model.BundleBalance, total, limit int, date time.Time) int {
|
|
||||||
var released int // 已释放的次数
|
|
||||||
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() {
|
|
||||||
} else {
|
|
||||||
released += limit
|
|
||||||
}
|
|
||||||
interval := max((date.Year()*12+int(date.Month())-(data.StartAt.Year()*12+int(data.StartAt.Month())))/3, 1) // 释放了多少个季度
|
|
||||||
released += max(interval-1, 0) * limit // 已经释放的数量
|
|
||||||
remaining := max(total-released, 0) // 还剩余多少次没有发放
|
|
||||||
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() { // 本月为第一个月购买
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
monthDiff := date.Year()*12 + int(date.Month()) - (data.StartAt.Year()*12 + int(data.StartAt.Month()))
|
|
||||||
if monthDiff%3 == 0 && data.ExpiredAt.Month() != date.Month() {
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func ExportWorkCastInfo(req *bundle.ExportWorkCastInfoReq) (*bundle.ExportWorkCastInfoResp, error) {
|
|
||||||
result := &bundle.ExportWorkCastInfoResp{}
|
|
||||||
query := app.ModuleClients.BundleDB.Raw(`
|
|
||||||
SELECT
|
|
||||||
bor.customer_name,
|
|
||||||
bor.customer_num,
|
|
||||||
bor.bundle_name,
|
|
||||||
bor.signed_time,
|
|
||||||
cw.title,
|
|
||||||
cwe.cost_type,
|
|
||||||
cw.work_category,
|
|
||||||
cw.submit_time,
|
|
||||||
cwl_wating.update_time AS waiting_time,
|
|
||||||
cwl_confirm.update_time AS confirm_time,
|
|
||||||
cwe.confirm_type AS confirm_type
|
|
||||||
FROM bundle_balance bb
|
|
||||||
LEFT JOIN bundle_order_records bor
|
|
||||||
ON bor.uuid = bb.order_uuid AND bor.deleted_at IS NULL
|
|
||||||
LEFT JOIN cast_work cw
|
|
||||||
ON cw.artist_uuid = bb.user_id AND cw.deleted_at = 0
|
|
||||||
LEFT JOIN cast_work_extra cwe
|
|
||||||
ON cwe.work_uuid = cw.uuid AND cwe.deleted_at = 0
|
|
||||||
LEFT JOIN cast_work_log cwl_confirm
|
|
||||||
ON cwl_confirm.work_uuid = cw.uuid
|
|
||||||
AND cwl_confirm.work_status = 9
|
|
||||||
AND cwl_confirm.deleted_at = 0
|
|
||||||
LEFT JOIN cast_work_log cwl_wating
|
|
||||||
ON cwl_wating.work_uuid = cw.uuid
|
|
||||||
AND cwl_wating.work_status = 4
|
|
||||||
AND cwl_wating.deleted_at = 0
|
|
||||||
WHERE bb.deleted_at IS NULL
|
|
||||||
AND bb.month = '2026-01'
|
|
||||||
AND bor.deleted_at IS NULL
|
|
||||||
AND cw.title IS NOT NULL
|
|
||||||
AND cw.submit_time < ?
|
|
||||||
AND cw.submit_time > ?
|
|
||||||
ORDER BY cw.uuid;
|
|
||||||
`, req.EndTime, req.StartTime)
|
|
||||||
err := query.Scan(&result.Data).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,288 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pkg/app"
|
|
||||||
commonErr "micro-bundle/pkg/err"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ContractQueryRequest 合同查询请求参数
|
|
||||||
type ContractQueryRequest struct {
|
|
||||||
ContractName string `json:"contractName"` // 合同名称(模糊查询)
|
|
||||||
ProjectName string `json:"projectName"` // 项目名称(模糊查询)
|
|
||||||
CustomerName string `json:"customerName"` // 客户名称(模糊查询)
|
|
||||||
Page int `json:"page"` // 页码
|
|
||||||
PageSize int `json:"pageSize"` // 每页数量
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateContract 创建合同(包括支付周期和开发周期子表)
|
|
||||||
func CreateContract(contract *model.Contract) error {
|
|
||||||
// 如果未提供 ContractUUID,则生成 UUID
|
|
||||||
if contract.ContractUUID == "" {
|
|
||||||
contract.ContractUUID = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置创建时间和更新时间
|
|
||||||
now := time.Now()
|
|
||||||
contract.CreatedAt = now
|
|
||||||
contract.UpdatedAt = now
|
|
||||||
|
|
||||||
contract.OperatorTime = now
|
|
||||||
|
|
||||||
// 使用事务创建合同及其子表
|
|
||||||
err := app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) error {
|
|
||||||
// 创建主表(Omit 跳过关联,避免 GORM 自动创建子表导致与后面显式 Create 重复插入)
|
|
||||||
if err := tx.Model(&model.Contract{}).Omit("PaymentCycles", "DevelopmentCycles").Create(contract).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "创建合同失败", "创建合同失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建支付周期子表
|
|
||||||
if len(contract.PaymentCycles) > 0 {
|
|
||||||
if len(contract.PaymentCycles) > 10 {
|
|
||||||
return commonErr.ReturnError(errors.New("支付周期不能超过10期"), "创建支付周期失败", "创建支付周期失败:")
|
|
||||||
}
|
|
||||||
for i := range contract.PaymentCycles {
|
|
||||||
if contract.PaymentCycles[i].ContractPaymentCycleUUID == "" {
|
|
||||||
contract.PaymentCycles[i].ContractPaymentCycleUUID = uuid.New().String()
|
|
||||||
}
|
|
||||||
contract.PaymentCycles[i].ContractUUID = contract.ContractUUID
|
|
||||||
contract.PaymentCycles[i].PaymentCyclePeriod = contract.PaymentCycles[i].PaymentCyclePeriod
|
|
||||||
contract.PaymentCycles[i].CreatedAt = now
|
|
||||||
contract.PaymentCycles[i].UpdatedAt = now
|
|
||||||
}
|
|
||||||
if err := tx.Model(&model.ContractPaymentCycle{}).Create(&contract.PaymentCycles).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "创建支付周期失败", "创建支付周期失败: ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建开发周期子表
|
|
||||||
if len(contract.DevelopmentCycles) > 0 {
|
|
||||||
if len(contract.DevelopmentCycles) > 10 {
|
|
||||||
return commonErr.ReturnError(errors.New("开发周期不能超过10期"), "创建开发周期失败", "创建开发周期失败:")
|
|
||||||
}
|
|
||||||
for i := range contract.DevelopmentCycles {
|
|
||||||
if contract.DevelopmentCycles[i].DevelopmentCycleUUID == "" {
|
|
||||||
contract.DevelopmentCycles[i].DevelopmentCycleUUID = uuid.New().String()
|
|
||||||
}
|
|
||||||
contract.DevelopmentCycles[i].ContractUUID = contract.ContractUUID
|
|
||||||
contract.DevelopmentCycles[i].DevelopmentPeriod = contract.DevelopmentCycles[i].DevelopmentPeriod
|
|
||||||
contract.DevelopmentCycles[i].CreatedAt = now
|
|
||||||
contract.DevelopmentCycles[i].UpdatedAt = now
|
|
||||||
}
|
|
||||||
if err := tx.Model(&model.DevelopmentCycle{}).Create(&contract.DevelopmentCycles).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "创建开发周期失败", "创建开发周期失败: ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateContract 更新合同信息(包括支付周期和开发周期子表)
|
|
||||||
func UpdateContract(contractUUID string, contract *model.Contract) error {
|
|
||||||
// 设置更新时间
|
|
||||||
now := time.Now()
|
|
||||||
contract.UpdatedAt = now
|
|
||||||
|
|
||||||
contract.OperatorTime = now
|
|
||||||
|
|
||||||
// 使用事务更新合同及其子表
|
|
||||||
err := app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) error {
|
|
||||||
// 更新主表(Omit 跳过关联,子表由下面先删后建单独处理)
|
|
||||||
if err := tx.Model(&model.Contract{}).
|
|
||||||
Where("contract_uuid = ?", contractUUID).
|
|
||||||
Omit("PaymentCycles", "DevelopmentCycles").
|
|
||||||
Updates(contract).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "更新合同失败", "更新合同失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除旧的支付周期子表数据(软删除)
|
|
||||||
if err := tx.Where("contract_uuid = ?", contractUUID).
|
|
||||||
Delete(&model.ContractPaymentCycle{}).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "删除支付周期失败", "删除支付周期失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新的支付周期子表数据
|
|
||||||
if len(contract.PaymentCycles) > 0 {
|
|
||||||
now := time.Now()
|
|
||||||
for i := range contract.PaymentCycles {
|
|
||||||
if contract.PaymentCycles[i].ContractPaymentCycleUUID == "" {
|
|
||||||
contract.PaymentCycles[i].ContractPaymentCycleUUID = uuid.New().String()
|
|
||||||
}
|
|
||||||
contract.PaymentCycles[i].ContractUUID = contractUUID
|
|
||||||
contract.PaymentCycles[i].PaymentCyclePeriod = contract.PaymentCycles[i].PaymentCyclePeriod
|
|
||||||
contract.PaymentCycles[i].CreatedAt = now
|
|
||||||
contract.PaymentCycles[i].UpdatedAt = now
|
|
||||||
}
|
|
||||||
if err := tx.Model(&model.ContractPaymentCycle{}).Create(&contract.PaymentCycles).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "创建支付周期失败", "创建支付周期失败: ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除旧的开发周期子表数据(软删除)
|
|
||||||
if err := tx.Where("contract_uuid = ?", contractUUID).
|
|
||||||
Delete(&model.DevelopmentCycle{}).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "删除开发周期失败", "删除开发周期失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建新的开发周期子表数据
|
|
||||||
if len(contract.DevelopmentCycles) > 0 {
|
|
||||||
now := time.Now()
|
|
||||||
for i := range contract.DevelopmentCycles {
|
|
||||||
if contract.DevelopmentCycles[i].DevelopmentCycleUUID == "" {
|
|
||||||
contract.DevelopmentCycles[i].DevelopmentCycleUUID = uuid.New().String()
|
|
||||||
}
|
|
||||||
contract.DevelopmentCycles[i].ContractUUID = contractUUID
|
|
||||||
contract.DevelopmentCycles[i].DevelopmentPeriod = contract.DevelopmentCycles[i].DevelopmentPeriod
|
|
||||||
contract.DevelopmentCycles[i].CreatedAt = now
|
|
||||||
contract.DevelopmentCycles[i].UpdatedAt = now
|
|
||||||
}
|
|
||||||
if err := tx.Model(&model.DevelopmentCycle{}).Create(&contract.DevelopmentCycles).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "创建开发周期失败", "创建开发周期失败: ")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteContract 删除合同(软删除,包括子表)
|
|
||||||
func DeleteContract(contractUUID string) error {
|
|
||||||
// 使用事务删除合同及其子表
|
|
||||||
err := app.ModuleClients.BundleDB.Transaction(func(tx *gorm.DB) error {
|
|
||||||
// 删除主表
|
|
||||||
if err := tx.Where("contract_uuid = ?", contractUUID).
|
|
||||||
Delete(&model.Contract{}).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "删除合同失败", "删除合同失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除支付周期子表
|
|
||||||
if err := tx.Where("contract_uuid = ?", contractUUID).
|
|
||||||
Delete(&model.ContractPaymentCycle{}).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "删除支付周期失败", "删除支付周期失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除开发周期子表
|
|
||||||
if err := tx.Where("contract_uuid = ?", contractUUID).
|
|
||||||
Delete(&model.DevelopmentCycle{}).Error; err != nil {
|
|
||||||
return commonErr.ReturnError(err, "删除开发周期失败", "删除开发周期失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetContractList 多条件分页查询合同列表
|
|
||||||
func GetContractList(req *ContractQueryRequest) ([]*model.Contract, int64, error) {
|
|
||||||
var contracts []*model.Contract
|
|
||||||
var total int64
|
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.Contract{}).
|
|
||||||
Where("deleted_at = 0")
|
|
||||||
|
|
||||||
// 合同名称模糊查询
|
|
||||||
if req.ContractName != "" {
|
|
||||||
query = query.Where("contract_name LIKE ?", "%"+req.ContractName+"%")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 项目名称模糊查询
|
|
||||||
if req.ProjectName != "" {
|
|
||||||
query = query.Where("project_name LIKE ?", "%"+req.ProjectName+"%")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 客户名称模糊查询
|
|
||||||
if req.CustomerName != "" {
|
|
||||||
query = query.Where("customer_name LIKE ?", "%"+req.CustomerName+"%")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算总数
|
|
||||||
err := query.Count(&total).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询合同总数失败", "查询合同总数失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
if req.PageSize > 0 && req.Page > 0 {
|
|
||||||
offset := (req.Page - 1) * req.PageSize
|
|
||||||
query = query.Limit(req.PageSize).Offset(offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按创建时间倒序排列
|
|
||||||
err = query.Order("created_at DESC").Find(&contracts).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return []*model.Contract{}, 0, nil
|
|
||||||
}
|
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询合同列表失败", "查询合同列表失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
return contracts, total, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetContractByUUID 根据合同UUID查询合同信息(包括子表)
|
|
||||||
func GetContractByUUID(contractUUID string) (*model.Contract, error) {
|
|
||||||
var contract model.Contract
|
|
||||||
err := app.ModuleClients.BundleDB.
|
|
||||||
Where("contract_uuid = ?", contractUUID).
|
|
||||||
Where("deleted_at = 0").
|
|
||||||
Preload("PaymentCycles", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Where("deleted_at = 0").Order("payment_cycle_period ASC")
|
|
||||||
}).
|
|
||||||
Preload("DevelopmentCycles", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Where("deleted_at = 0").Order("development_period ASC")
|
|
||||||
}).
|
|
||||||
First(&contract).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return nil, commonErr.ReturnError(err, "查询失败", "查询失败: ")
|
|
||||||
}
|
|
||||||
return &contract, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPaymentCyclesByContractUUID 根据合同UUID查询支付周期列表
|
|
||||||
func GetPaymentCyclesByContractUUID(contractUUID string) ([]*model.ContractPaymentCycle, error) {
|
|
||||||
var paymentCycles []*model.ContractPaymentCycle
|
|
||||||
err := app.ModuleClients.BundleDB.Model(&model.ContractPaymentCycle{}).
|
|
||||||
Where("contract_uuid = ?", contractUUID).
|
|
||||||
Where("deleted_at = 0").
|
|
||||||
Order("payment_cycle_period ASC").
|
|
||||||
Find(&paymentCycles).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return []*model.ContractPaymentCycle{}, nil
|
|
||||||
}
|
|
||||||
return nil, commonErr.ReturnError(err, "查询支付周期失败", "查询支付周期失败: ")
|
|
||||||
}
|
|
||||||
return paymentCycles, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDevelopmentCyclesByContractUUID 根据合同UUID查询开发周期列表
|
|
||||||
func GetDevelopmentCyclesByContractUUID(contractUUID string) ([]*model.DevelopmentCycle, error) {
|
|
||||||
var developmentCycles []*model.DevelopmentCycle
|
|
||||||
err := app.ModuleClients.BundleDB.Model(&model.DevelopmentCycle{}).
|
|
||||||
Where("contract_uuid = ?", contractUUID).
|
|
||||||
Where("deleted_at = 0").
|
|
||||||
Order("development_period ASC").
|
|
||||||
Find(&developmentCycles).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return []*model.DevelopmentCycle{}, nil
|
|
||||||
}
|
|
||||||
return nil, commonErr.ReturnError(err, "查询开发周期失败", "查询开发周期失败: ")
|
|
||||||
}
|
|
||||||
return developmentCycles, nil
|
|
||||||
}
|
|
||||||
@ -1,167 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pkg/app"
|
|
||||||
commonErr "micro-bundle/pkg/err"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// CustomerQueryRequest 客户查询请求参数
|
|
||||||
type CustomerQueryRequest struct {
|
|
||||||
CustomerName string `json:"customerName"` // 客户名称(模糊查询)
|
|
||||||
ReferralPerson string `json:"referralPerson"` // 推荐人(模糊查询)
|
|
||||||
Page int `json:"page"` // 页码
|
|
||||||
PageSize int `json:"pageSize"` // 每页数量
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateCustomer 创建客户
|
|
||||||
func CreateCustomer(customer *model.Customer) error {
|
|
||||||
// 如果未提供 CustomerID,则生成 UUID
|
|
||||||
if customer.CustomerID == "" {
|
|
||||||
customer.CustomerID = uuid.New().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置创建时间和更新时间
|
|
||||||
now := time.Now()
|
|
||||||
customer.CreatedAt = now
|
|
||||||
customer.UpdatedAt = now
|
|
||||||
|
|
||||||
err := app.ModuleClients.BundleDB.Model(&model.Customer{}).Create(customer).Error
|
|
||||||
if err != nil {
|
|
||||||
return commonErr.ReturnError(err, "创建失败", "创建失败: ")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateCustomer 更新客户信息
|
|
||||||
func UpdateCustomer(customerID string, customer *model.Customer) error {
|
|
||||||
err := app.ModuleClients.BundleDB.Model(&model.Customer{}).
|
|
||||||
Where("customer_id = ?", customerID).
|
|
||||||
Updates(customer).Error
|
|
||||||
if err != nil {
|
|
||||||
return commonErr.ReturnError(err, "更新失败", "更新失败: ")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteCustomer 删除客户(软删除)
|
|
||||||
func DeleteCustomer(customerID string) error {
|
|
||||||
err := app.ModuleClients.BundleDB.
|
|
||||||
Where("customer_id = ?", customerID).
|
|
||||||
Delete(&model.Customer{}).Error
|
|
||||||
if err != nil {
|
|
||||||
return commonErr.ReturnError(err, "删除失败", "删除失败: ")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCustomerList 多条件分页查询客户列表
|
|
||||||
func GetCustomerList(req *CustomerQueryRequest) ([]*model.Customer, int64, error) {
|
|
||||||
var customers []*model.Customer
|
|
||||||
var total int64
|
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.Customer{})
|
|
||||||
|
|
||||||
// 客户名称模糊查询
|
|
||||||
if req.CustomerName != "" {
|
|
||||||
query = query.Where("customer_name LIKE ?", "%"+req.CustomerName+"%")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 推荐人模糊查询
|
|
||||||
if req.ReferralPerson != "" {
|
|
||||||
query = query.Where("referral_person LIKE ?", "%"+req.ReferralPerson+"%")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算总数
|
|
||||||
err := query.Count(&total).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询客户总数失败", "查询客户总数失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分页查询
|
|
||||||
if req.PageSize > 0 && req.Page > 0 {
|
|
||||||
offset := (req.Page - 1) * req.PageSize
|
|
||||||
query = query.Limit(req.PageSize).Offset(offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按创建时间倒序排列
|
|
||||||
err = query.Order("created_at DESC").Find(&customers).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return []*model.Customer{}, 0, nil
|
|
||||||
}
|
|
||||||
return nil, 0, commonErr.ReturnError(err, "查询客户列表失败", "查询客户列表失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
return customers, total, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCustomerByID 根据客户ID查询客户信息
|
|
||||||
func GetCustomerByID(customerID string) (*model.Customer, error) {
|
|
||||||
var customer model.Customer
|
|
||||||
err := app.ModuleClients.BundleDB.
|
|
||||||
Where("customer_id = ?", customerID).
|
|
||||||
Where("deleted_at = 0").
|
|
||||||
First(&customer).Error
|
|
||||||
if err != nil {
|
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
return nil, commonErr.ReturnError(err, "查询客户信息失败", "查询客户信息失败: ")
|
|
||||||
}
|
|
||||||
return &customer, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckCustomerNameExists(customerName string, excludeCustomerID string) (bool, error) {
|
|
||||||
if customerName == "" {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.Customer{}).
|
|
||||||
Where("customer_name = ?", customerName).
|
|
||||||
Where("deleted_at = 0")
|
|
||||||
|
|
||||||
if excludeCustomerID != "" {
|
|
||||||
query = query.Where("customer_id != ?", excludeCustomerID)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := query.Count(&count).Error
|
|
||||||
if err != nil {
|
|
||||||
return false, commonErr.ReturnError(err, "查询客户名称失败", "查询客户名称失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
return count > 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDistinctReferralPersons 查询所有不重复的推荐人
|
|
||||||
// keyword: 推荐人关键字,支持模糊查询,为空则查询所有
|
|
||||||
func GetDistinctReferralPersons(keyword string) ([]string, error) {
|
|
||||||
var referralPersons []string
|
|
||||||
|
|
||||||
// 构建查询条件
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.Customer{}).
|
|
||||||
Where("deleted_at = 0").
|
|
||||||
Where("referral_person != ''").
|
|
||||||
Where("referral_person IS NOT NULL")
|
|
||||||
|
|
||||||
// 如果提供了关键字,进行模糊查询
|
|
||||||
if keyword != "" {
|
|
||||||
query = query.Where("referral_person LIKE ?", "%"+keyword+"%")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询所有不重复的推荐人
|
|
||||||
err := query.Distinct("referral_person").
|
|
||||||
Pluck("referral_person", &referralPersons).Error
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, commonErr.ReturnError(err, "查询推荐人列表失败", "查询推荐人列表失败: ")
|
|
||||||
}
|
|
||||||
|
|
||||||
return referralPersons, nil
|
|
||||||
}
|
|
||||||
@ -1,275 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
"micro-bundle/pkg/app"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateInvoice(req *bundle.CreateInvoiceReq) (res *bundle.CreateInvoiceResp, err error) {
|
|
||||||
res = new(bundle.CreateInvoiceResp)
|
|
||||||
userId, err := strconv.Atoi(req.UserId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
fmt.Println("创建发票信息:applyTime=", req.ApplyTime)
|
|
||||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
||||||
applyTime, err := time.ParseInLocation("20060102 15:04:05", req.ApplyTime, loc)
|
|
||||||
if err != nil {
|
|
||||||
applyTime, err = time.ParseInLocation(time.DateTime, req.ApplyTime, loc)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("创建发票信息失败:", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
inv := &model.Invoice{
|
|
||||||
UserId: userId,
|
|
||||||
UserNum: req.UserNum,
|
|
||||||
UserName: req.UserName,
|
|
||||||
OrderNo: req.OrderNo,
|
|
||||||
ApplyTime: applyTime,
|
|
||||||
InvoiceType: int(req.InvoiceType),
|
|
||||||
InvoiceNo: req.InvoiceNo,
|
|
||||||
InvoiceUrl: req.InvoiceUrl,
|
|
||||||
PaperInvocieStatus: int(req.PaperInvocieStatus),
|
|
||||||
Remark: req.Remark,
|
|
||||||
}
|
|
||||||
//打印信息
|
|
||||||
fmt.Println("创建发票信息:userId=", inv.UserId, "userNum=", inv.UserNum, "userName=", inv.UserName, "orderNo=", inv.OrderNo, "applyTime=", inv.ApplyTime, "invoiceType=", inv.InvoiceType, "invoiceNo=", inv.InvoiceNo, "invoiceUrl=", inv.InvoiceUrl, "paperInvocieStatus=", inv.PaperInvocieStatus, "remark=", inv.Remark)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.Invoice{}).Create(inv).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
fmt.Println("创建发票信息成功")
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreatePaperInvoiceAddress(req *bundle.CreatePaperInvoiceAddressReq) (res *bundle.CreatePaperInvoiceAddressResp, err error) {
|
|
||||||
res = new(bundle.CreatePaperInvoiceAddressResp)
|
|
||||||
userId, err := strconv.Atoi(req.UserId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
loc, _ := time.LoadLocation("Asia/Shanghai")
|
|
||||||
applyTime, err := time.ParseInLocation("20060102 15:04:05", req.ApplyTime, loc)
|
|
||||||
if err != nil {
|
|
||||||
applyTime, err = time.ParseInLocation(time.DateTime, req.ApplyTime, loc)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("创建发票信息失败:", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pia := &model.PaperInvoiceAddress{
|
|
||||||
UserId: userId,
|
|
||||||
ApplyTime: applyTime,
|
|
||||||
OrderNo: req.OrderNo,
|
|
||||||
InvoiceNo: req.InvoiceNo,
|
|
||||||
Name: req.Name,
|
|
||||||
TelAreaCode: req.TelAreaCode,
|
|
||||||
Phone: req.Phone,
|
|
||||||
PostalCode: req.PostalCode,
|
|
||||||
Country: req.Country,
|
|
||||||
Address: req.Address,
|
|
||||||
Remark: req.Remark,
|
|
||||||
}
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.PaperInvoiceAddress{}).Create(pia).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
//更新主表状态
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.Invoice{}).Where("order_no = ?", req.OrderNo).Updates(
|
|
||||||
&map[string]interface{}{
|
|
||||||
"paper_invocie_status": 2,
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInvoiceList(req *bundle.GetInvoiceListReq) (data []*model.InvoiceInfo, total int64, err error) {
|
|
||||||
data = make([]*model.InvoiceInfo, 0)
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.Invoice{}).
|
|
||||||
Select(`
|
|
||||||
COALESCE(pia.name, rn.name) AS name,
|
|
||||||
COALESCE(pia.tel_area_code, user.tel_area_code) AS tel_area_code,
|
|
||||||
COALESCE(pia.phone, user.tel_num) AS phone,
|
|
||||||
COALESCE(pia.country, rn.nationality) AS country,
|
|
||||||
COALESCE(pia.address, rn.place_of_residence) AS address,
|
|
||||||
pia.apply_time AS apply_time,
|
|
||||||
invoice.user_name AS user_name,
|
|
||||||
invoice.user_num AS user_num,
|
|
||||||
invoice.order_no AS order_no,
|
|
||||||
invoice.invoice_no AS invoice_no,
|
|
||||||
invoice.invoice_url AS invoice_url,
|
|
||||||
invoice.paper_invocie_status AS paper_invocie_status
|
|
||||||
`).
|
|
||||||
Joins("LEFT JOIN paper_invoice_address as pia ON invoice.order_no = pia.order_no and pia.deleted_at = 0").
|
|
||||||
Joins("LEFT JOIN `micro-account`.`user` AS user ON invoice.user_id = user.id and user.deleted_at = 0").
|
|
||||||
Joins("LEFT JOIN `micro-account`.real_name AS rn ON user.real_name_id = rn.id and rn.deleted_at = 0")
|
|
||||||
|
|
||||||
if req.IsExpress != 0 {
|
|
||||||
if req.IsExpress == 2 && req.IsApplyInvocice == 1 {
|
|
||||||
query = query.Where("invoice.paper_invocie_status = ?", req.IsApplyInvocice)
|
|
||||||
} else {
|
|
||||||
query = query.Where("invoice.paper_invocie_status = ?", req.IsExpress)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if req.IsApplyInvocice == 2 {
|
|
||||||
query = query.Where("invoice.paper_invocie_status >= ?", req.IsApplyInvocice)
|
|
||||||
} else if req.IsApplyInvocice == 1 {
|
|
||||||
query = query.Where("invoice.paper_invocie_status = ?", req.IsApplyInvocice)
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if req.ApplyTimeStart != "" {
|
|
||||||
// 使用 COALESCE 后的 apply_time 进行筛选
|
|
||||||
query = query.Where("pia.apply_time >= ?", req.ApplyTimeStart)
|
|
||||||
}
|
|
||||||
if req.ApplyTimeEnd != "" {
|
|
||||||
query = query.Where("pia.apply_time <= ?", req.ApplyTimeEnd)
|
|
||||||
}
|
|
||||||
if req.Name != "" {
|
|
||||||
// 使用 COALESCE 后的 name 进行模糊筛选,统一 collation 避免 Illegal mix of collations
|
|
||||||
query = query.Where("COALESCE(pia.name, rn.name) COLLATE utf8mb4_general_ci LIKE ?", "%"+req.Name+"%")
|
|
||||||
}
|
|
||||||
if req.Phone != "" {
|
|
||||||
query = query.Where("COALESCE(pia.phone, user.tel_num) COLLATE utf8mb4_general_ci LIKE ?", "%"+req.Phone+"%")
|
|
||||||
}
|
|
||||||
if req.Country != "" {
|
|
||||||
query = query.Where("COALESCE(pia.country, rn.nationality) COLLATE utf8mb4_general_ci LIKE ?", "%"+req.Country+"%")
|
|
||||||
}
|
|
||||||
if req.UserName != "" {
|
|
||||||
query = query.Where("invoice.user_name LIKE ?", "%"+req.UserName+"%")
|
|
||||||
}
|
|
||||||
query.Order("pia.apply_time DESC")
|
|
||||||
query = query.Count(&total)
|
|
||||||
err = query.Offset(int(req.Page-1) * int(req.Size)).Limit(int(req.Size)).Find(&data).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
return data, total, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateInvoiceExpressInfo(req *bundle.UpdateInvoiceExpressInfoReq) (res *bundle.UpdateInvoiceExpressInfoResp, err error) {
|
|
||||||
res = new(bundle.UpdateInvoiceExpressInfoResp)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.PaperInvoiceAddress{}).Where("order_no = ?", req.OrderNo).Updates(
|
|
||||||
&map[string]interface{}{
|
|
||||||
"express_company": req.ExpressCompany,
|
|
||||||
"express_no": req.ExpressNo,
|
|
||||||
"remark": req.Remark,
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
//更新主表状态
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.Invoice{}).Where("order_no = ?", req.OrderNo).Updates(
|
|
||||||
&map[string]interface{}{
|
|
||||||
"paper_invocie_status": 3,
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInvoiceExpressInfo(req *bundle.GetInvoiceExpressInfoReq) (res *bundle.GetInvoiceExpressInfoResp, err error) {
|
|
||||||
res = new(bundle.GetInvoiceExpressInfoResp)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.PaperInvoiceAddress{}).Where("order_no = ?", req.OrderNo).First(&res).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetOrderInfoByOrderNo(req *bundle.GetOrderInfoByOrderNoReq) (orderRecord *model.InvoiceOrderInfo, err error) {
|
|
||||||
orderRecord = new(model.InvoiceOrderInfo)
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).
|
|
||||||
Select(`
|
|
||||||
bundle_order_records.customer_name AS user_name,
|
|
||||||
user.id AS user_id,
|
|
||||||
bundle_order_records.order_no AS order_no,
|
|
||||||
bundle_order_records.customer_num AS user_num,
|
|
||||||
bundle_order_records.amount_type AS amount_type,
|
|
||||||
ROUND(bundle_order_records.total_amount, 2) AS total_amount,
|
|
||||||
bundle_order_records.bundle_name AS bundle_name,
|
|
||||||
rn.place_of_residence AS address,
|
|
||||||
user.tel_num AS phone,
|
|
||||||
bundle_order_records.pay_time AS pay_time
|
|
||||||
`).
|
|
||||||
Joins("left join `micro-account`.`user` as user on user.id = bundle_order_records.customer_id and user.deleted_at = 0").
|
|
||||||
Joins("left join `micro-account`.`real_name` as rn on rn.id = user.real_name_id and rn.deleted_at = 0").
|
|
||||||
Where("bundle_order_records.deleted_at is null")
|
|
||||||
if req.Uuid != "" {
|
|
||||||
query = query.Where("bundle_order_records.uuid = ?", req.Uuid)
|
|
||||||
}
|
|
||||||
if req.OrderNo != "" {
|
|
||||||
query = query.Where("bundle_order_records.order_no = ?", req.OrderNo)
|
|
||||||
}
|
|
||||||
query = query.Order("bundle_order_records.created_at DESC")
|
|
||||||
err = query.First(&orderRecord).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return orderRecord, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInvoiceInfoByOrderNo(req *bundle.GetInvoiceInfoByOrderNoReq) (data []*model.InvoiceInfoByOrderNo, err error) {
|
|
||||||
data = make([]*model.InvoiceInfoByOrderNo, 0)
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.Invoice{}).
|
|
||||||
Select(`
|
|
||||||
invoice.order_no AS order_no,
|
|
||||||
invoice.invoice_no AS invoice_no,
|
|
||||||
invoice.invoice_url AS invoice_url,
|
|
||||||
bor.bundle_name AS bundle_name,
|
|
||||||
bor.amount_type AS amount_type,
|
|
||||||
bor.total_amount AS total_amount,
|
|
||||||
bor.pay_time AS pay_time,
|
|
||||||
invoice.paper_invocie_status AS paper_invocie_status
|
|
||||||
`).
|
|
||||||
Joins("left join bundle_order_records bor on invoice.order_no COLLATE utf8mb4_general_ci = bor.order_no COLLATE utf8mb4_general_ci and bor.deleted_at is null").
|
|
||||||
Where("invoice.user_id = ?", req.UserId)
|
|
||||||
if req.OrderNo != "" {
|
|
||||||
query = query.Where("invoice.order_no COLLATE utf8mb4_general_ci = ?", req.OrderNo)
|
|
||||||
}
|
|
||||||
query = query.Order("bor.pay_time DESC")
|
|
||||||
err = query.Find(&data).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetLastInvoiceNo() (lastNo model.Invoice, err error) {
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.Invoice{}).
|
|
||||||
Order("id DESC").
|
|
||||||
Where("deleted_at = 0").
|
|
||||||
Limit(1).
|
|
||||||
First(&lastNo).Error
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
// 没有记录时返回空值,不返回错误
|
|
||||||
return model.Invoice{}, nil
|
|
||||||
}
|
|
||||||
return model.Invoice{}, err
|
|
||||||
}
|
|
||||||
return lastNo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdataInvoiceInfo(req *bundle.UpdataInvoiceInfoReq) (res *bundle.UpdataInvoiceInfoResp, err error) {
|
|
||||||
res = new(bundle.UpdataInvoiceInfoResp)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.Invoice{}).Where("order_no = ?", req.OrderNo).Updates(
|
|
||||||
&map[string]interface{}{
|
|
||||||
"invoice_url": req.Url,
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
"micro-bundle/internal/model"
|
"micro-bundle/internal/model"
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
"micro-bundle/pkg/app"
|
"micro-bundle/pkg/app"
|
||||||
@ -13,8 +14,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/shopspring/decimal"
|
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@ -280,8 +279,6 @@ func OrderRecordsList(req *bundle.OrderRecordsRequest) (res *bundle.OrderRecords
|
|||||||
AddBundleCommonUid: record.AddBundleCommonUid,
|
AddBundleCommonUid: record.AddBundleCommonUid,
|
||||||
FinancialConfirmation: record.FinancialConfirmation,
|
FinancialConfirmation: record.FinancialConfirmation,
|
||||||
ExpirationTime: record.ExpirationTime,
|
ExpirationTime: record.ExpirationTime,
|
||||||
PurchaseType: record.PurchaseType,
|
|
||||||
RenewalOrderUUID: record.RenewalOrderUUID,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +352,6 @@ func OrderRecordDetail(req *bundle.OrderRecordsDetailRequest) (res *bundle.Order
|
|||||||
Num: addBundle.Num,
|
Num: addBundle.Num,
|
||||||
ValueAddUUID: addBundle.ValueAddUUID,
|
ValueAddUUID: addBundle.ValueAddUUID,
|
||||||
EquityType: addBundle.EquityType,
|
EquityType: addBundle.EquityType,
|
||||||
ServiceType: addBundle.ServiceType,
|
|
||||||
}
|
}
|
||||||
addInfos = append(addInfos, addInfo)
|
addInfos = append(addInfos, addInfo)
|
||||||
}
|
}
|
||||||
@ -385,8 +381,6 @@ func OrderRecordDetail(req *bundle.OrderRecordsDetailRequest) (res *bundle.Order
|
|||||||
TotalAmount: orderRecord.TotalAmount,
|
TotalAmount: orderRecord.TotalAmount,
|
||||||
ExpirationTime: orderRecord.ExpirationTime,
|
ExpirationTime: orderRecord.ExpirationTime,
|
||||||
ReSignature: int32(orderRecord.ReSignature),
|
ReSignature: int32(orderRecord.ReSignature),
|
||||||
PurchaseType: orderRecord.PurchaseType,
|
|
||||||
RenewalOrderUUID: orderRecord.RenewalOrderUUID,
|
|
||||||
}
|
}
|
||||||
res.AddInfos = make([]*bundle.AddInfo, 0)
|
res.AddInfos = make([]*bundle.AddInfo, 0)
|
||||||
res.AddInfos = addInfos
|
res.AddInfos = addInfos
|
||||||
@ -501,9 +495,6 @@ func OrderRecordsListV2(req *bundle.OrderRecordsRequestV2) (res *bundle.OrderRec
|
|||||||
if req.PayStatus != 0 {
|
if req.PayStatus != 0 {
|
||||||
modelObj = modelObj.Where("bundle_order_records.status = ?", req.PayStatus)
|
modelObj = modelObj.Where("bundle_order_records.status = ?", req.PayStatus)
|
||||||
}
|
}
|
||||||
if req.PurchaseType != 0 {
|
|
||||||
modelObj = modelObj.Where("bundle_order_records.purchase_type = ?", req.PurchaseType)
|
|
||||||
}
|
|
||||||
if req.AddPayStatus != 0 {
|
if req.AddPayStatus != 0 {
|
||||||
modelObj = modelObj.Where("exists (select 1 from bundle_order_value_add where bundle_order_value_add.order_uuid = bundle_order_records.uuid and bundle_order_value_add.payment_status = ?)", req.AddPayStatus)
|
modelObj = modelObj.Where("exists (select 1 from bundle_order_value_add where bundle_order_value_add.order_uuid = bundle_order_records.uuid and bundle_order_value_add.payment_status = ?)", req.AddPayStatus)
|
||||||
}
|
}
|
||||||
@ -539,18 +530,15 @@ func OrderRecordsListV2(req *bundle.OrderRecordsRequestV2) (res *bundle.OrderRec
|
|||||||
customerID, _ := strconv.ParseInt(record.CustomerID, 10, 64)
|
customerID, _ := strconv.ParseInt(record.CustomerID, 10, 64)
|
||||||
|
|
||||||
orderItem := &bundle.OrderBundleRecordInfo{
|
orderItem := &bundle.OrderBundleRecordInfo{
|
||||||
OrderNo: record.OrderNo,
|
OrderNo: record.OrderNo,
|
||||||
BundleName: record.BundleName,
|
BundleName: record.BundleName,
|
||||||
PayStatus: int32(record.Status),
|
PayStatus: int32(record.Status),
|
||||||
TelNum: "",
|
TelNum: "",
|
||||||
CustomerName: record.CustomerName,
|
CustomerName: record.CustomerName,
|
||||||
BundleCreateAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
|
BundleCreateAt: record.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||||
Amount: record.Amount,
|
Amount: record.Amount,
|
||||||
CustomerId: customerID,
|
CustomerId: customerID,
|
||||||
PayTime: record.PayTime,
|
PayTime: record.PayTime,
|
||||||
InviterId: record.InviterID,
|
|
||||||
PurchaseType: record.PurchaseType,
|
|
||||||
RenewalOrderUUID: record.RenewalOrderUUID,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 聚合子订单
|
// 聚合子订单
|
||||||
@ -608,7 +596,6 @@ func OrderListByOrderNo(req *bundle.OrderInfoByOrderNoRequest) (*bundle.OrderInf
|
|||||||
return nil, errors.New("invalid request")
|
return nil, errors.New("invalid request")
|
||||||
}
|
}
|
||||||
var addOrder []*model.BundleOrderValueAdd
|
var addOrder []*model.BundleOrderValueAdd
|
||||||
var orderInfo *model.BundleOrderRecords
|
|
||||||
if err := app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
if err := app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
||||||
Where("order_no = ?", req.OrderNo).
|
Where("order_no = ?", req.OrderNo).
|
||||||
Find(&addOrder).Error; err != nil {
|
Find(&addOrder).Error; err != nil {
|
||||||
@ -617,22 +604,16 @@ func OrderListByOrderNo(req *bundle.OrderInfoByOrderNoRequest) (*bundle.OrderInf
|
|||||||
if len(addOrder) == 0 {
|
if len(addOrder) == 0 {
|
||||||
return &bundle.OrderInfoByOrderNoResp{}, nil
|
return &bundle.OrderInfoByOrderNoResp{}, nil
|
||||||
}
|
}
|
||||||
if err := app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).
|
|
||||||
Where("order_no = ?", req.OrderNo).
|
|
||||||
First(&orderInfo).Error; err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
//订单类型 1:套餐 2:单独购买
|
//订单类型 1:套餐 2:单独购买
|
||||||
userID, err := strconv.ParseInt(addOrder[0].CustomerID, 10, 64)
|
userID, err := strconv.ParseInt(addOrder[0].CustomerID, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
res := &bundle.OrderInfoByOrderNoResp{
|
res := &bundle.OrderInfoByOrderNoResp{
|
||||||
Type: int32(addOrder[0].Source),
|
Type: int32(addOrder[0].Source),
|
||||||
UserId: uint64(userID),
|
UserId: uint64(userID),
|
||||||
OrderUUID: addOrder[0].OrderUUID,
|
OrderUUID: addOrder[0].OrderUUID,
|
||||||
UserName: addOrder[0].CustomerName,
|
UserName: addOrder[0].CustomerName,
|
||||||
PurchaseType: int32(orderInfo.PurchaseType),
|
|
||||||
}
|
}
|
||||||
for _, item := range addOrder {
|
for _, item := range addOrder {
|
||||||
switch item.ServiceType {
|
switch item.ServiceType {
|
||||||
@ -647,8 +628,6 @@ func OrderListByOrderNo(req *bundle.OrderInfoByOrderNoRequest) (*bundle.OrderInf
|
|||||||
case 5:
|
case 5:
|
||||||
res.Duration += item.Num
|
res.Duration += item.Num
|
||||||
res.Unit = item.Unit // 如果有多个duration记录,最后一个unit会覆盖前面的
|
res.Unit = item.Unit // 如果有多个duration记录,最后一个unit会覆盖前面的
|
||||||
case 6:
|
|
||||||
res.CompetitiveAdditional += item.Num //添加竞品数
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
@ -838,17 +817,7 @@ func DeleteValueAddService(req *bundle.DeleteValueAddServiceRequest) (res *bundl
|
|||||||
|
|
||||||
func UpdateReconciliationStatusBySerialNumber(req *bundle.UpdateStatusAndPayTimeBySerialNumber) (res *bundle.CommonResponse, err error) {
|
func UpdateReconciliationStatusBySerialNumber(req *bundle.UpdateStatusAndPayTimeBySerialNumber) (res *bundle.CommonResponse, err error) {
|
||||||
var existing model.Reconciliation
|
var existing model.Reconciliation
|
||||||
|
if err := app.ModuleClients.BundleDB.Where("serial_number = ?", req.SerialNumber).First(&existing).Error; err != nil {
|
||||||
//req.SerialNumber现在是orderuuid
|
|
||||||
var order model.BundleOrderRecords
|
|
||||||
if err := app.ModuleClients.BundleDB.Where("uuid = ?", req.SerialNumber).First(&order).Error; err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return nil, errors.New("订单记录不存在")
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("查询订单失败: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.ModuleClients.BundleDB.Where("bundle_order_on = ?", order.OrderNo).First(&existing).Error; err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, errors.New("对账单记录不存在")
|
return nil, errors.New("对账单记录不存在")
|
||||||
}
|
}
|
||||||
@ -857,7 +826,7 @@ func UpdateReconciliationStatusBySerialNumber(req *bundle.UpdateStatusAndPayTime
|
|||||||
updates := model.Reconciliation{
|
updates := model.Reconciliation{
|
||||||
PayTime: req.PayTime,
|
PayTime: req.PayTime,
|
||||||
PayStatus: int(req.PaymentStatus),
|
PayStatus: int(req.PaymentStatus),
|
||||||
SerialNumber: order.OrderNo,
|
SerialNumber: req.SerialNumber,
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.PaymentStatus == 2 && existing.CurrencyType == 2 && existing.PayAmount > 0 {
|
if req.PaymentStatus == 2 && existing.CurrencyType == 2 && existing.PayAmount > 0 {
|
||||||
@ -1009,138 +978,3 @@ func ReSignTheContract(req *bundle.ReSignTheContractRequest) (*bundle.CommonResp
|
|||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateOrderRecordByOrderUuid(orderRecord *model.BundleOrderRecords) (res *bundle.CommonResponse, err error) {
|
|
||||||
res = new(bundle.CommonResponse)
|
|
||||||
// Step 1: 先更新子订单(增值服务)的支付状态
|
|
||||||
valueAdd := &model.BundleOrderValueAdd{
|
|
||||||
PaymentStatus: int(orderRecord.Status),
|
|
||||||
PaymentTime: orderRecord.PayTime,
|
|
||||||
}
|
|
||||||
if orderRecord.CheckoutSessionId != "" {
|
|
||||||
valueAdd.CheckoutSessionId = orderRecord.CheckoutSessionId
|
|
||||||
valueAdd.CheckoutSessionUrl = orderRecord.CheckoutSessionUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
if orderRecord.Status == 2 {
|
|
||||||
tempValues := make([]*model.BundleOrderValueAdd, 0)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
|
||||||
Where("order_uuid = ?", orderRecord.UUID).
|
|
||||||
Find(&tempValues).Error
|
|
||||||
if len(tempValues) > 0 {
|
|
||||||
for _, value := range tempValues {
|
|
||||||
if value.PaymentStatus == 2 {
|
|
||||||
fmt.Println("====================已经付过了")
|
|
||||||
return nil, errors.New("已付款了")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tempRecord := new(model.BundleOrderRecords)
|
|
||||||
if err := app.ModuleClients.BundleDB.Where("deleted_at is null and uuid = ?", orderRecord.UUID).First(&tempRecord).Error; err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return nil, errors.New("订单记录不存在")
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("查询订单失败: %v", err)
|
|
||||||
}
|
|
||||||
if orderRecord.Status == 2 && tempRecord.AmountType == 2 && tempRecord.TotalAmount > 0 {
|
|
||||||
// 当回调支付成功,币种是美元,且订单金额大于0,计算美元手续费:订单金额*0.019(四舍五入保留两位小数字)+0.1
|
|
||||||
amount := decimal.NewFromFloat32(tempRecord.TotalAmount)
|
|
||||||
rate, _ := decimal.NewFromString("0.019")
|
|
||||||
fee := amount.Mul(rate)
|
|
||||||
// 4. 四舍五入保留两位小数
|
|
||||||
feeRounded := fee.Round(2)
|
|
||||||
addition, _ := decimal.NewFromString("0.1")
|
|
||||||
result := feeRounded.Add(addition)
|
|
||||||
valueAdd.HandlingFee = result.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
|
||||||
Where("order_uuid = ?", orderRecord.UUID).
|
|
||||||
Updates(valueAdd).Error
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = msg.ErrorUpdateOrderInfo
|
|
||||||
return res, commonErr.ReturnError(err, msg.ErrorUpdateOrderInfo, "更新增值服务支付状态失败: ")
|
|
||||||
}
|
|
||||||
// Step 2: 再更新主订单信息(如果存在)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).
|
|
||||||
Where("uuid = ?", orderRecord.UUID).
|
|
||||||
Updates(orderRecord).Error
|
|
||||||
// Step 3: 返回结果(即使主订单更新失败,也视为成功)
|
|
||||||
res.Uuid = orderRecord.UUID
|
|
||||||
res.Msg = msg.SuccessUpdateOrderInfo
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
func OrderListByOrderUuid(req *bundle.OrderInfoByOrderUuidRequest) (*bundle.OrderInfoByOrderNoResp, error) {
|
|
||||||
if req == nil || req.OrderUuid == "" {
|
|
||||||
return nil, errors.New("invalid request")
|
|
||||||
}
|
|
||||||
var addOrder []*model.BundleOrderValueAdd
|
|
||||||
if err := app.ModuleClients.BundleDB.Model(&model.BundleOrderValueAdd{}).
|
|
||||||
Where("order_uuid = ?", req.OrderUuid).
|
|
||||||
Find(&addOrder).Error; err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(addOrder) == 0 {
|
|
||||||
return &bundle.OrderInfoByOrderNoResp{}, nil
|
|
||||||
}
|
|
||||||
//订单类型 1:套餐 2:单独购买
|
|
||||||
userID, err := strconv.ParseInt(addOrder[0].CustomerID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res := &bundle.OrderInfoByOrderNoResp{
|
|
||||||
Type: int32(addOrder[0].Source),
|
|
||||||
UserId: uint64(userID),
|
|
||||||
OrderUUID: addOrder[0].OrderUUID,
|
|
||||||
UserName: addOrder[0].CustomerName,
|
|
||||||
}
|
|
||||||
for _, item := range addOrder {
|
|
||||||
switch item.ServiceType {
|
|
||||||
case 1:
|
|
||||||
res.VideoNumber += item.Num // 使用 += 而不是直接赋值
|
|
||||||
case 2:
|
|
||||||
res.ImageNumber += item.Num
|
|
||||||
case 3:
|
|
||||||
res.DataNumber += item.Num
|
|
||||||
case 4:
|
|
||||||
res.AccountNumber += item.Num
|
|
||||||
case 5:
|
|
||||||
res.Duration += item.Num
|
|
||||||
res.Unit = item.Unit // 如果有多个duration记录,最后一个unit会覆盖前面的
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetOriginalOrderUUID 传入订单UUID,追溯续费链,返回最初非续费的订单UUID
|
|
||||||
func GetOriginalOrderUUID(orderUUID string) (string, error) {
|
|
||||||
if orderUUID == "" {
|
|
||||||
return "", errors.New("订单UUID不能为空")
|
|
||||||
}
|
|
||||||
visited := make(map[string]struct{})
|
|
||||||
current := orderUUID
|
|
||||||
for {
|
|
||||||
if _, seen := visited[current]; seen {
|
|
||||||
return orderUUID, nil
|
|
||||||
}
|
|
||||||
visited[current] = struct{}{}
|
|
||||||
|
|
||||||
var rec model.BundleOrderRecords
|
|
||||||
err := app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).
|
|
||||||
Where("uuid = ?", current).
|
|
||||||
First(&rec).Error
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return "", errors.New("订单记录不存在")
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("查询订单失败: %v", err)
|
|
||||||
}
|
|
||||||
if rec.PurchaseType != 2 || rec.RenewalOrderUUID == "" {
|
|
||||||
return rec.UUID, nil
|
|
||||||
}
|
|
||||||
current = rec.RenewalOrderUUID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,228 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
"micro-bundle/pkg/app"
|
|
||||||
"micro-bundle/pkg/msg"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/samber/lo"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 电话号码映射表:原始号码 -> 目标号码
|
|
||||||
var phoneMapping = map[string]string{
|
|
||||||
"15863272183": "15624971336", //毕德瑞
|
|
||||||
"15039229900": "18803928946", //陈春芳
|
|
||||||
"13832480736": "17746107444", //程宝江
|
|
||||||
"19290778586": "13196080727", //董跃亭
|
|
||||||
"18710227028": "13954838868", //方民
|
|
||||||
"17801586080": "15233398990", //韩玉玲
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用示例:仅当号码在白名单中时才返回映射结果,否则返回原号码
|
|
||||||
func MapPhoneIfInList(phone string) string {
|
|
||||||
if phoneMapping[phone] != "" {
|
|
||||||
return phoneMapping[phone]
|
|
||||||
}
|
|
||||||
return phone
|
|
||||||
}
|
|
||||||
|
|
||||||
func SendQuestionnaireSurvey(req *bundle.SendQuestionnaireSurveyRequest) (resp *bundle.SendQuestionnaireSurveyResponse, err error) {
|
|
||||||
resp = new(bundle.SendQuestionnaireSurveyResponse)
|
|
||||||
phone := MapPhoneIfInList(req.UserTel)
|
|
||||||
userInfo := &model.UserInfo{}
|
|
||||||
err = app.ModuleClients.BundleDB.Raw(`
|
|
||||||
SELECT
|
|
||||||
mau.id as user_id,
|
|
||||||
mau.sub_num as user_num,
|
|
||||||
mau.tel_num as user_tel,
|
|
||||||
marn.name as user_name
|
|
||||||
from `+"`micro-account`.`user`"+` as mau
|
|
||||||
left join `+"`micro-account`.`real_name`"+` as marn on marn.id = mau.real_name_id and marn.deleted_at = 0
|
|
||||||
where mau.deleted_at = 0 and mau.tel_num = ?
|
|
||||||
`, phone).Scan(&userInfo).Error
|
|
||||||
if err != nil {
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
if userInfo.UserId == 0 {
|
|
||||||
resp.Status = 1
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
//判断是否在指定id列表中
|
|
||||||
userIds := []int{76, 77, 80, 82, 83, 98, 110, 119, 121, 137, 138, 140, 149, 152, 155, 156, 157, 163, 171, 178, 179, 183, 184, 187, 189, 195, 210, 212, 221, 223, 224, 225, 227, 229, 232, 233, 249, 279, 311, 274, 268, 314, 327, 291, 326, 320, 273, 319, 278, 264, 313, 296, 393, 395, 387, 371, 391, 366, 398, 400, 410, 411, 412, 419, 421, 430, 432, 540, 592, 630, 1015}
|
|
||||||
if lo.Contains(userIds, userInfo.UserId) {
|
|
||||||
resp.Status = 0
|
|
||||||
} else {
|
|
||||||
resp.Status = 1
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
questionnaireInfo := &model.QuestionnaireSurvey{}
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.QuestionnaireSurvey{}).
|
|
||||||
Where("user_tel = ? and deleted_at is null", phone).
|
|
||||||
Order("created_at desc").
|
|
||||||
First(&questionnaireInfo).Error
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
resp.Status = 0
|
|
||||||
} else {
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if questionnaireInfo.UserId != 0 {
|
|
||||||
if questionnaireInfo.SurveyStatus == msg.QuestionnaireSent {
|
|
||||||
resp.Status = 0
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
resp.Status = 2
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
orderRecord := &model.BundleOrderRecords{}
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).
|
|
||||||
Where("customer_num = ? and deleted_at is null", userInfo.UserNum).
|
|
||||||
Order("created_at desc").
|
|
||||||
First(&orderRecord).Error
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
resp.Status = 1
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
bundleBalance := &model.BundleBalance{}
|
|
||||||
month := timeParse(req.EndTime + " 23:59:59").Format("2006-01")
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).
|
|
||||||
Where("order_uuid = ? and deleted_at is null", orderRecord.UUID).
|
|
||||||
Where("month = ?", month).
|
|
||||||
First(&bundleBalance).Error
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
resp.Status = 1
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if bundleBalance.ID == 0 {
|
|
||||||
resp.Status = 1
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
bundleInfo := &model.BundleInfo{
|
|
||||||
BundleName: orderRecord.BundleName,
|
|
||||||
StartAt: bundleBalance.StartAt,
|
|
||||||
ExpiredAt: bundleBalance.ExpiredAt,
|
|
||||||
BundleAccountNumber: 3,
|
|
||||||
BundleVideoNumber: bundleBalance.BundleLimitVideoConsumptionNumber,
|
|
||||||
IncreaseVideoNumber: bundleBalance.IncreaseVideoConsumptionNumber,
|
|
||||||
BundleImageNumber: bundleBalance.BundleLimitImageConsumptionNumber,
|
|
||||||
BundleDataNumber: bundleBalance.BundleLimitDataAnalysisConsumptionNumber,
|
|
||||||
BundleCompetitiveNumber: bundleBalance.BundleLimitCompetitiveConsumptionNumber,
|
|
||||||
}
|
|
||||||
bundleInfoJSON, err := json.Marshal(bundleInfo)
|
|
||||||
if err != nil {
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
data := &model.QuestionnaireSurvey{
|
|
||||||
SurveyUUID: uuid.New().String(),
|
|
||||||
UserId: userInfo.UserId,
|
|
||||||
UserNum: userInfo.UserNum,
|
|
||||||
UserName: userInfo.UserName,
|
|
||||||
UserTel: userInfo.UserTel,
|
|
||||||
OrderUUID: orderRecord.UUID,
|
|
||||||
SendTime: timeParse(time.Now().Format("2006-01-02 15:04:05")),
|
|
||||||
SubmitTime: timeParse(time.Now().Format("2006-01-02 15:04:05")),
|
|
||||||
SurveyStatus: msg.QuestionnaireSent,
|
|
||||||
BundleInfo: string(bundleInfoJSON),
|
|
||||||
SurveyTitle: req.SurveyTitle,
|
|
||||||
}
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.QuestionnaireSurvey{}).Create(data).Error
|
|
||||||
if err != nil {
|
|
||||||
return resp, err
|
|
||||||
}
|
|
||||||
resp.Status = 0
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetQuestionnaireSurveyInfo(req *bundle.GetQuestionnaireSurveyInfoRequest) (data *model.QuestionnaireSurvey, err error) {
|
|
||||||
data = &model.QuestionnaireSurvey{}
|
|
||||||
phone := MapPhoneIfInList(req.UserTel)
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.QuestionnaireSurvey{}).
|
|
||||||
Where("user_tel = ? and deleted_at is null", phone).
|
|
||||||
Order("created_at desc").
|
|
||||||
First(&data).Error
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
||||||
return nil, errors.New("问卷信息不存在")
|
|
||||||
}
|
|
||||||
return data, err
|
|
||||||
}
|
|
||||||
return data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateQuestionnaireSurveyAnswer(req *bundle.CreateQuestionnaireSurveyAnswerRequest) (err error) {
|
|
||||||
phone := MapPhoneIfInList(req.UserTel)
|
|
||||||
surveyAnswer := &model.SurveyAnswer{
|
|
||||||
BundleAccountScore: req.SurveyAnswer.BundleAccountScore,
|
|
||||||
BundleVideoScore: req.SurveyAnswer.BundleVideoScore,
|
|
||||||
IncreaseVideoScore: req.SurveyAnswer.IncreaseVideoScore,
|
|
||||||
BundleImageScore: req.SurveyAnswer.BundleImageScore,
|
|
||||||
BundleDataScore: req.SurveyAnswer.BundleDataScore,
|
|
||||||
BundleCompetitiveScore: req.SurveyAnswer.BundleCompetitiveScore,
|
|
||||||
ServiceResponseSpeed: req.SurveyAnswer.ServiceResponseSpeed,
|
|
||||||
ServiceStaffProfessionalism: req.SurveyAnswer.ServiceStaffProfessionalism,
|
|
||||||
}
|
|
||||||
surveyAnswerJSON, err := json.Marshal(surveyAnswer)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = app.ModuleClients.BundleDB.Model(&model.QuestionnaireSurvey{}).
|
|
||||||
Where("user_tel = ? and deleted_at is null", phone).
|
|
||||||
Updates(map[string]interface{}{
|
|
||||||
"survey_answer": string(surveyAnswerJSON),
|
|
||||||
"merits_review": req.SurveyFeedback.MeritsReview,
|
|
||||||
"suggestionsor_improvements": req.SurveyFeedback.SuggestionsorImprovements,
|
|
||||||
"additional_comments": req.SurveyFeedback.AdditionalComments,
|
|
||||||
"submit_time": timeParse(time.Now().Format("2006-01-02 15:04:05")),
|
|
||||||
"survey_status": msg.QuestionnaireSubmitted,
|
|
||||||
"survey_url": req.SurveyUrl,
|
|
||||||
"submit_by": req.SubmitBy,
|
|
||||||
}).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetQuestionnaireSurveyList(req *bundle.GetQuestionnaireSurveyListRequest) (data []*model.QuestionnaireSurvey, total int64, err error) {
|
|
||||||
if req.Page == 0 {
|
|
||||||
req.Page = 1
|
|
||||||
}
|
|
||||||
if req.PageSize == 0 {
|
|
||||||
req.PageSize = 10
|
|
||||||
}
|
|
||||||
query := app.ModuleClients.BundleDB.Model(&model.QuestionnaireSurvey{})
|
|
||||||
if req.UserName != "" {
|
|
||||||
query = query.Where("user_name = ?", req.UserName)
|
|
||||||
}
|
|
||||||
if req.SurveyTitle != "" {
|
|
||||||
query = query.Where("survey_title = ?", req.SurveyTitle)
|
|
||||||
}
|
|
||||||
if req.SurveyStatus != 0 {
|
|
||||||
query = query.Where("survey_status = ?", req.SurveyStatus)
|
|
||||||
}
|
|
||||||
query = query.Order("created_at desc")
|
|
||||||
query.Count(&total)
|
|
||||||
query = query.Limit(int(req.PageSize)).Offset(int(req.Page-1) * int(req.PageSize))
|
|
||||||
err = query.Find(&data).Error
|
|
||||||
if err != nil {
|
|
||||||
return data, total, err
|
|
||||||
}
|
|
||||||
return data, total, nil
|
|
||||||
}
|
|
||||||
570
internal/dao/taskBalanceSync.go
Normal file
570
internal/dao/taskBalanceSync.go
Normal file
@ -0,0 +1,570 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"micro-bundle/internal/model"
|
||||||
|
"micro-bundle/pkg/app"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunInitialTaskBalanceSync 一次性将 BundleBalance 同步到 TaskBalance
|
||||||
|
// 仅在未执行过且任务余额表为空时运行;执行成功后写入标记,避免再次执行
|
||||||
|
func RunInitialTaskBalanceSync() error {
|
||||||
|
// 确保标记表存在
|
||||||
|
_ = app.ModuleClients.TaskBenchDB.AutoMigrate(&model.TaskSyncStatus{})
|
||||||
|
|
||||||
|
// 已执行标记检查
|
||||||
|
var markerCount int64
|
||||||
|
if err := app.ModuleClients.TaskBenchDB.Model(&model.TaskSyncStatus{}).
|
||||||
|
Where("sync_key = ?", model.InitialSyncKey).Count(&markerCount).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if markerCount > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 安全检查:如果任务余额表已存在数据,则不再执行,同样写入标记
|
||||||
|
var existing int64
|
||||||
|
if err := app.ModuleClients.TaskBenchDB.Model(&model.TaskBalance{}).Count(&existing).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if existing > 0 {
|
||||||
|
_ = app.ModuleClients.TaskBenchDB.Create(&model.TaskSyncStatus{
|
||||||
|
SyncKey: model.InitialSyncKey,
|
||||||
|
ExecutedAt: time.Now(),
|
||||||
|
Remark: "skipped: task_balance already has data",
|
||||||
|
}).Error
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前有效(未过期且已支付)的艺人及其最新订单
|
||||||
|
validArtists, err := GetValidArtistList()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(validArtists)
|
||||||
|
if len(validArtists) == 0 {
|
||||||
|
// 不写入已执行标记,留待后续有数据时再次执行
|
||||||
|
fmt.Println("无数据更新")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造待插入的 TaskBalance 列表
|
||||||
|
tasks := make([]model.TaskBalance, 0, len(validArtists))
|
||||||
|
for _, a := range validArtists {
|
||||||
|
// 根据 user_id + order_uuid 获取 BundleBalance 明细
|
||||||
|
var bb model.BundleBalance
|
||||||
|
if err := app.ModuleClients.BundleDB.Where("user_id = ? AND order_uuid = ?", a.UserID, a.OrderUUID).First(&bb).Error; err != nil {
|
||||||
|
// 若未查到则跳过该条
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
subNum, telNum, err := fetchIdentityForBundle(&bb)
|
||||||
|
if err != nil {
|
||||||
|
// 无法获取身份信息则跳过该条
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
tb := model.TaskBalance{
|
||||||
|
SubNum: subNum,
|
||||||
|
TelNum: telNum,
|
||||||
|
Month: bb.Month,
|
||||||
|
StartAt: bb.StartAt,
|
||||||
|
ExpiredAt: bb.ExpiredAt,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
}
|
||||||
|
copyBundleToTaskBalance(&tb, &bb)
|
||||||
|
tasks = append(tasks, tb)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 原子写入:插入 TaskBalance + 插入标记(确保有插入才写标记)
|
||||||
|
tx := app.ModuleClients.TaskBenchDB.Begin()
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if len(tasks) == 0 {
|
||||||
|
// 没有可插入的数据,不写标记,直接返回
|
||||||
|
tx.Rollback()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tx.Create(&tasks).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Create(&model.TaskSyncStatus{
|
||||||
|
SyncKey: model.InitialSyncKey,
|
||||||
|
ExecutedAt: time.Now(),
|
||||||
|
Remark: "initial sync executed",
|
||||||
|
}).Error; err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Commit().Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunIncrementalTaskBalanceSync 增量同步:每次服务重启时执行
|
||||||
|
// 将套餐余额表中的新数据同步到任务余额表,跳过已存在的记录
|
||||||
|
func RunIncrementalTaskBalanceSync() error {
|
||||||
|
// 获取当前有效(未过期且已支付)的艺人及其最新订单
|
||||||
|
validArtists, err := GetValidArtistList()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(validArtists) == 0 {
|
||||||
|
fmt.Println("增量同步:无有效艺人数据")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造待插入的 TaskBalance 列表(仅包含不存在的记录)
|
||||||
|
tasks := make([]model.TaskBalance, 0)
|
||||||
|
skippedCount := 0
|
||||||
|
|
||||||
|
for _, a := range validArtists {
|
||||||
|
// 根据 user_id + order_uuid 获取 BundleBalance 明细
|
||||||
|
var bb model.BundleBalance
|
||||||
|
if err := app.ModuleClients.BundleDB.Where("user_id = ? AND order_uuid = ?", a.UserID, a.OrderUUID).First(&bb).Error; err != nil {
|
||||||
|
// 若未查到则跳过该条
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
subNum, telNum, err := fetchIdentityForBundle(&bb)
|
||||||
|
if err != nil {
|
||||||
|
// 无法获取身份信息则跳过该条
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查任务余额表中是否已存在该记录(按 sub_num + tel_num + month 唯一)
|
||||||
|
var existingCount int64
|
||||||
|
if err := app.ModuleClients.TaskBenchDB.Model(&model.TaskBalance{}).
|
||||||
|
Where("sub_num = ? AND tel_num = ? AND month = ?", subNum, telNum, bb.Month).
|
||||||
|
Count(&existingCount).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if existingCount > 0 {
|
||||||
|
// 记录已存在,跳过
|
||||||
|
skippedCount++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构造新的 TaskBalance 记录
|
||||||
|
tb := model.TaskBalance{
|
||||||
|
SubNum: subNum,
|
||||||
|
TelNum: telNum,
|
||||||
|
Month: bb.Month,
|
||||||
|
StartAt: bb.StartAt,
|
||||||
|
ExpiredAt: bb.ExpiredAt,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
}
|
||||||
|
copyBundleToTaskBalance(&tb, &bb)
|
||||||
|
tasks = append(tasks, tb)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("增量同步:跳过已存在记录 %d 条,准备插入新记录 %d 条\n", skippedCount, len(tasks))
|
||||||
|
|
||||||
|
// 如果没有新记录需要插入,直接返回
|
||||||
|
if len(tasks) == 0 {
|
||||||
|
fmt.Println("增量同步:无新记录需要同步")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量插入新记录
|
||||||
|
if err := app.ModuleClients.TaskBenchDB.Create(&tasks).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("增量同步:成功插入 %d 条新记录\n", len(tasks))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 用户新买套餐时使用
|
||||||
|
// SyncTaskBalanceFromBundleBalance 增量/每月:根据单条 BundleBalance 同步或更新 TaskBalance(按 sub_num + tel_num + month 唯一)
|
||||||
|
func SyncTaskBalanceFromBundleBalance(bb model.BundleBalance) error {
|
||||||
|
// 获取身份信息(sub_num, tel_num)
|
||||||
|
subNum, telNum, err := fetchIdentityForBundle(&bb)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 组装 TaskBalance
|
||||||
|
tb := model.TaskBalance{
|
||||||
|
SubNum: subNum,
|
||||||
|
TelNum: telNum,
|
||||||
|
Month: bb.Month,
|
||||||
|
ExpiredAt: bb.ExpiredAt,
|
||||||
|
StartAt: bb.StartAt,
|
||||||
|
UpdatedAt: time.Now(),
|
||||||
|
CreatedAt: time.Now(),
|
||||||
|
}
|
||||||
|
copyBundleToTaskBalance(&tb, &bb)
|
||||||
|
|
||||||
|
// 查询是否已存在(唯一:sub_num + tel_num + month)
|
||||||
|
var existing model.TaskBalance
|
||||||
|
err = app.ModuleClients.TaskBenchDB.
|
||||||
|
Where("sub_num = ? AND tel_num = ? AND month = ?", subNum, telNum, bb.Month).
|
||||||
|
First(&existing).Error
|
||||||
|
if err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
// 不存在则创建
|
||||||
|
return app.ModuleClients.TaskBenchDB.Create(&tb).Error
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 已存在则更新所有映射字段与时间
|
||||||
|
tb.ID = existing.ID
|
||||||
|
return app.ModuleClients.TaskBenchDB.Save(&tb).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchIdentityForBundle 根据 BundleBalance 拿到 sub_num 与 tel_num
|
||||||
|
func fetchIdentityForBundle(bb *model.BundleBalance) (string, string, error) {
|
||||||
|
// tel_num 来自 micro-account.user
|
||||||
|
type userRow struct {
|
||||||
|
Tel string
|
||||||
|
}
|
||||||
|
var ur userRow
|
||||||
|
if err := app.ModuleClients.BundleDB.Table("`micro-account`.`user`").Unscoped().
|
||||||
|
Select("tel_num AS tel").Where("id = ?", bb.UserId).Limit(1).Scan(&ur).Error; err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
// customer_num 来自 bundle_order_records(按 order_uuid)
|
||||||
|
type orderRow struct {
|
||||||
|
Customer string
|
||||||
|
}
|
||||||
|
var or orderRow
|
||||||
|
if bb.OrderUUID == "" {
|
||||||
|
return "", "", errors.New("bundle order_uuid missing")
|
||||||
|
}
|
||||||
|
if err := app.ModuleClients.BundleDB.Table("bundle_order_records").
|
||||||
|
Select("customer_num AS customer").Where("uuid = ?", bb.OrderUUID).Limit(1).Scan(&or).Error; err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
return or.Customer, ur.Tel, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTaskBalance 每月批量更新任务余额
|
||||||
|
// 类似于 UpdateBundleBalance 的逻辑,但针对任务余额表
|
||||||
|
func UpdateTaskBalanceEveryMon() error {
|
||||||
|
// 查询需要更新的任务余额记录(最新月份且未过期的记录)
|
||||||
|
tl := []model.TaskBalance{}
|
||||||
|
if err := app.ModuleClients.TaskBenchDB.Raw(`select
|
||||||
|
*
|
||||||
|
from
|
||||||
|
task_balance tb
|
||||||
|
inner join (
|
||||||
|
select
|
||||||
|
max(tb.month) as month ,
|
||||||
|
sub_num,
|
||||||
|
tel_num
|
||||||
|
from
|
||||||
|
task_balance tb
|
||||||
|
group by
|
||||||
|
tb.sub_num, tb.tel_num
|
||||||
|
) newest on
|
||||||
|
newest.month = tb.month
|
||||||
|
and (tb.sub_num = newest.sub_num OR tb.tel_num = newest.tel_num)
|
||||||
|
and tb.expired_at > now()`).Find(&tl).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
month := time.Now().Format("2006-01")
|
||||||
|
|
||||||
|
for _, v := range tl {
|
||||||
|
if v.Month == month {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cal := func(total, limit int) int { // 计算本月发放的限制类型数量
|
||||||
|
var released int // 已释放的次数
|
||||||
|
if v.StartAt.Month() == now.Month() && v.StartAt.Year() == now.Year() {
|
||||||
|
} else if v.StartAt.Day() >= 16 { //第一个月释放的
|
||||||
|
released += (limit + 1) / 2
|
||||||
|
} else {
|
||||||
|
released += limit
|
||||||
|
}
|
||||||
|
interval := now.Year()*12 + int(now.Month()) - (v.StartAt.Year()*12 + int(v.StartAt.Month())) // 释放了多少个月
|
||||||
|
released += max(interval-1, 0) * limit // 后续月份释放的
|
||||||
|
remaining := max(total-released, 0) // 还剩余多少次没有发放
|
||||||
|
|
||||||
|
if v.StartAt.Month() == now.Month() && v.StartAt.Year() == now.Year() && v.StartAt.Day() >= 16 { // 本月为第一个月并且16号后购买只给一半(向上取整)
|
||||||
|
return min((limit+1)/2, remaining)
|
||||||
|
}
|
||||||
|
if v.ExpiredAt.Month() == now.Month() && v.ExpiredAt.Year() == now.Year() && v.ExpiredAt.Day() < 16 { // 本月为最后一个月并且16号前到期只给一半(向下取整)
|
||||||
|
return min(limit/2, remaining)
|
||||||
|
}
|
||||||
|
return min(limit, remaining)
|
||||||
|
}
|
||||||
|
|
||||||
|
v.MonthlyInvalidBundleVideoNumber = v.MonthlyBundleLimitExpiredVideoNumber - v.MonthlyBundleLimitExpiredVideoConsumptionNumber // 当月过期的视频数
|
||||||
|
v.InvalidBundleVideoNumber += v.MonthlyInvalidBundleVideoNumber
|
||||||
|
v.MonthlyInvalidBundleImageNumber = v.MonthlyBundleLimitExpiredImageNumber - v.MonthlyBundleLimitExpiredImageConsumptionNumber // 当月过期的图片数
|
||||||
|
v.InvalidBundleImageNumber += v.MonthlyInvalidBundleImageNumber
|
||||||
|
v.MonthlyInvalidBundleDataAnalysisNumber = v.MonthlyBundleLimitExpiredDataAnalysisNumber - v.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber // 当月过期的数据分析数
|
||||||
|
v.InvalidBundleDataAnalysisNumber += v.MonthlyInvalidBundleDataAnalysisNumber
|
||||||
|
|
||||||
|
// 当月可用的限制类型数等于本月方法的套餐和增值两种类型的总和
|
||||||
|
v.MonthlyBundleLimitExpiredVideoNumber = cal(v.BundleLimitVideoExpiredNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
|
v.MonthlyIncreaseLimitExpiredVideoNumber = cal(v.IncreaseLimitVideoExpiredNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
|
v.MonthlyBundleLimitVideoNumber = v.MonthlyBundleLimitVideoNumber - v.MonthlyBundleLimitVideoConsumptionNumber + cal(v.BundleLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
|
v.MonthlyIncreaseLimitVideoNumber = v.MonthlyIncreaseLimitVideoNumber - v.MonthlyIncreaseLimitVideoConsumptionNumber + cal(v.IncreaseLimitVideoNumber, v.MonthlyLimitVideoQuotaNumber)
|
||||||
|
v.MonthlyBundleLimitExpiredImageNumber = cal(v.BundleLimitImageExpiredNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
|
v.MonthlyIncreaseLimitExpiredImageNumber = cal(v.IncreaseLimitImageExpiredNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
|
v.MonthlyBundleLimitImageNumber = v.MonthlyBundleLimitImageNumber - v.MonthlyBundleLimitImageConsumptionNumber + cal(v.BundleLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
|
v.MonthlyIncreaseLimitImageNumber = v.MonthlyIncreaseLimitImageNumber - v.MonthlyIncreaseLimitImageConsumptionNumber + cal(v.IncreaseLimitImageNumber, v.MonthlyLimitImageQuotaNumber)
|
||||||
|
v.MonthlyBundleLimitExpiredDataAnalysisNumber = cal(v.BundleLimitDataAnalysisExpiredNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
||||||
|
v.MonthlyIncreaseLimitExpiredDataAnalysisNumber = cal(v.IncreaseLimitDataAnalysisExpiredNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
||||||
|
v.MonthlyBundleLimitDataAnalysisNumber = v.MonthlyBundleLimitDataAnalysisNumber - v.MonthlyBundleLimitDataAnalysisConsumptionNumber + cal(v.BundleLimitDataAnalysisNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
||||||
|
v.MonthlyIncreaseLimitDataAnalysisNumber = v.MonthlyIncreaseLimitDataAnalysisNumber - v.MonthlyIncreaseLimitDataAnalysisConsumptionNumber + cal(v.IncreaseLimitDataAnalysisNumber, v.MonthlyLimitDataAnalysisQuotaNumber)
|
||||||
|
// 重置单月消耗数量
|
||||||
|
v.MonthlyBundleVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleLimitVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseLimitVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleLimitExpiredVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseLimitExpiredVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyNewManualVideoNumber = 0
|
||||||
|
v.MonthlyManualVideoConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleImageConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseImageConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleLimitImageConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseLimitImageConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleLimitExpiredImageConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseLimitExpiredImageConsumptionNumber = 0
|
||||||
|
v.MonthlyNewManualImageNumber = 0
|
||||||
|
v.MonthlyManualImageConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleDataAnalysisConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseDataAnalysisConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleLimitDataAnalysisConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseLimitDataAnalysisConsumptionNumber = 0
|
||||||
|
v.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber = 0
|
||||||
|
v.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber = 0
|
||||||
|
v.MonthlyNewManualDataAnalysisNumber = 0
|
||||||
|
v.MonthlyManualDataAnalysisConsumptionNumber = 0
|
||||||
|
|
||||||
|
// 设置新月份和重置ID
|
||||||
|
v.Month = month
|
||||||
|
v.ID = 0
|
||||||
|
|
||||||
|
// 创建新的任务余额记录
|
||||||
|
if err := app.ModuleClients.TaskBenchDB.Create(&v).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// updateTaskBalanceExpiredAt 更新任务余额表的ExpiredAt字段
|
||||||
|
func updateTaskBalanceExpiredAt(subNum, telNum string, durationNumber int) error {
|
||||||
|
return app.ModuleClients.TaskBenchDB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
var taskBalance model.TaskBalance
|
||||||
|
query := tx.Model(&model.TaskBalance{})
|
||||||
|
|
||||||
|
// 构建查询条件,优先使用 subNum
|
||||||
|
if subNum != "" {
|
||||||
|
query = query.Where("sub_num = ?", subNum)
|
||||||
|
} else {
|
||||||
|
query = query.Where("tel_num = ?", telNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询当前有效的任务余额记录,按最新的开始时间排序
|
||||||
|
now := time.Now()
|
||||||
|
err := query.Where("start_at <= ? AND expired_at >= ?", now, now).Order("start_at DESC").First(&taskBalance).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加过期时间
|
||||||
|
taskBalance.ExpiredAt = taskBalance.ExpiredAt.Add(time.Hour * 24 * time.Duration(durationNumber))
|
||||||
|
|
||||||
|
return tx.Save(&taskBalance).Error
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// copyBundleToTaskBalance 将 BundleBalance 的图片、视频、数据分析相关字段映射到 TaskBalance
|
||||||
|
func copyBundleToTaskBalance(tb *model.TaskBalance, bb *model.BundleBalance) {
|
||||||
|
// ===== 视频类 =====
|
||||||
|
tb.BundleVideoNumber = bb.BundleVideoNumber
|
||||||
|
tb.IncreaseVideoNumber = bb.IncreaseVideoNumber
|
||||||
|
tb.BundleLimitVideoNumber = bb.BundleLimitVideoNumber
|
||||||
|
tb.IncreaseLimitVideoNumber = bb.IncreaseLimitVideoNumber
|
||||||
|
tb.BundleLimitVideoExpiredNumber = bb.BundleLimitVideoExpiredNumber
|
||||||
|
tb.IncreaseLimitVideoExpiredNumber = bb.IncreaseLimitVideoExpiredNumber
|
||||||
|
tb.MonthlyInvalidBundleVideoNumber = bb.MonthlyInvalidBundleVideoNumber
|
||||||
|
tb.InvalidBundleVideoNumber = bb.InvalidBundleVideoNumber
|
||||||
|
tb.MonthlyInvalidIncreaseVideoNumber = bb.MonthlyInvalidIncreaseVideoNumber
|
||||||
|
tb.InvalidIncreaseVideoNumber = bb.InvalidIncreaseVideoNumber
|
||||||
|
tb.BundleVideoConsumptionNumber = bb.BundleVideoConsumptionNumber
|
||||||
|
tb.IncreaseVideoConsumptionNumber = bb.IncreaseVideoConsumptionNumber
|
||||||
|
tb.BundleLimitVideoConsumptionNumber = bb.BundleLimitVideoConsumptionNumber
|
||||||
|
tb.IncreaseLimitVideoConsumptionNumber = bb.IncreaseLimitVideoConsumptionNumber
|
||||||
|
tb.BundleLimitVideoExpiredConsumptionNumber = bb.BundleLimitVideoExpiredConsumptionNumber
|
||||||
|
tb.IncreaseLimitVideoExpiredConsumptionNumber = bb.IncreaseLimitVideoExpiredConsumptionNumber
|
||||||
|
tb.MonthlyBundleVideoConsumptionNumber = bb.MonthlyBundleVideoConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseVideoConsumptionNumber = bb.MonthlyIncreaseVideoConsumptionNumber
|
||||||
|
tb.MonthlyBundleLimitVideoNumber = bb.MonthlyBundleLimitVideoNumber
|
||||||
|
tb.MonthlyIncreaseLimitVideoNumber = bb.MonthlyIncreaseLimitVideoNumber
|
||||||
|
tb.MonthlyBundleLimitVideoConsumptionNumber = bb.MonthlyBundleLimitVideoConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseLimitVideoConsumptionNumber = bb.MonthlyIncreaseLimitVideoConsumptionNumber
|
||||||
|
tb.MonthlyBundleLimitExpiredVideoNumber = bb.MonthlyBundleLimitExpiredVideoNumber
|
||||||
|
tb.MonthlyIncreaseLimitExpiredVideoNumber = bb.MonthlyIncreaseLimitExpiredVideoNumber
|
||||||
|
tb.MonthlyBundleLimitExpiredVideoConsumptionNumber = bb.MonthlyBundleLimitExpiredVideoConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseLimitExpiredVideoConsumptionNumber = bb.MonthlyIncreaseLimitExpiredVideoConsumptionNumber
|
||||||
|
tb.MonthlyLimitVideoQuotaNumber = bb.MonthlyLimitVideoQuotaNumber
|
||||||
|
// 手动扩展(视频)
|
||||||
|
tb.ManualVideoNumber = bb.ManualVideoNumber
|
||||||
|
tb.ManualVideoConsumptionNumber = bb.ManualVideoConsumptionNumber
|
||||||
|
tb.MonthlyNewManualVideoNumber = bb.MonthlyNewManualVideoNumber
|
||||||
|
tb.MonthlyManualVideoConsumptionNumber = bb.MonthlyManualVideoConsumptionNumber
|
||||||
|
|
||||||
|
// ===== 图片类 =====
|
||||||
|
tb.BundleImageNumber = bb.BundleImageNumber
|
||||||
|
tb.IncreaseImageNumber = bb.IncreaseImageNumber
|
||||||
|
tb.BundleLimitImageNumber = bb.BundleLimitImageNumber
|
||||||
|
tb.IncreaseLimitImageNumber = bb.IncreaseLimitImageNumber
|
||||||
|
tb.BundleLimitImageExpiredNumber = bb.BundleLimitImageExpiredNumber
|
||||||
|
tb.IncreaseLimitImageExpiredNumber = bb.IncreaseLimitImageExpiredNumber
|
||||||
|
tb.MonthlyInvalidBundleImageNumber = bb.MonthlyInvalidBundleImageNumber
|
||||||
|
tb.InvalidBundleImageNumber = bb.InvalidBundleImageNumber
|
||||||
|
tb.MonthlyInvalidIncreaseImageNumber = bb.MonthlyInvalidIncreaseImageNumber
|
||||||
|
tb.InvalidIncreaseImageNumber = bb.InvalidIncreaseImageNumber
|
||||||
|
tb.BundleImageConsumptionNumber = bb.BundleImageConsumptionNumber
|
||||||
|
tb.IncreaseImageConsumptionNumber = bb.IncreaseImageConsumptionNumber
|
||||||
|
tb.BundleLimitImageConsumptionNumber = bb.BundleLimitImageConsumptionNumber
|
||||||
|
tb.IncreaseLimitImageConsumptionNumber = bb.IncreaseLimitImageConsumptionNumber
|
||||||
|
tb.BundleLimitImageExpiredConsumptionNumber = bb.BundleLimitImageExpiredConsumptionNumber
|
||||||
|
tb.IncreaseLimitImageExpiredConsumptionNumber = bb.IncreaseLimitImageExpiredConsumptionNumber
|
||||||
|
tb.MonthlyBundleImageConsumptionNumber = bb.MonthlyBundleImageConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseImageConsumptionNumber = bb.MonthlyIncreaseImageConsumptionNumber
|
||||||
|
tb.MonthlyBundleLimitImageNumber = bb.MonthlyBundleLimitImageNumber
|
||||||
|
tb.MonthlyIncreaseLimitImageNumber = bb.MonthlyIncreaseLimitImageNumber
|
||||||
|
tb.MonthlyBundleLimitImageConsumptionNumber = bb.MonthlyBundleLimitImageConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseLimitImageConsumptionNumber = bb.MonthlyIncreaseLimitImageConsumptionNumber
|
||||||
|
tb.MonthlyBundleLimitExpiredImageNumber = bb.MonthlyBundleLimitExpiredImageNumber
|
||||||
|
tb.MonthlyIncreaseLimitExpiredImageNumber = bb.MonthlyIncreaseLimitExpiredImageNumber
|
||||||
|
tb.MonthlyBundleLimitExpiredImageConsumptionNumber = bb.MonthlyBundleLimitExpiredImageConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseLimitExpiredImageConsumptionNumber = bb.MonthlyIncreaseLimitExpiredImageConsumptionNumber
|
||||||
|
tb.MonthlyLimitImageQuotaNumber = bb.MonthlyLimitImageQuotaNumber
|
||||||
|
// 手动扩展(图片)
|
||||||
|
tb.ManualImageNumber = bb.ManualImageNumber
|
||||||
|
tb.ManualImageConsumptionNumber = bb.ManualImageConsumptionNumber
|
||||||
|
tb.MonthlyNewManualImageNumber = bb.MonthlyNewManualImageNumber
|
||||||
|
tb.MonthlyManualImageConsumptionNumber = bb.MonthlyManualImageConsumptionNumber
|
||||||
|
|
||||||
|
// ===== 数据分析类 =====
|
||||||
|
tb.BundleDataAnalysisNumber = bb.BundleDataAnalysisNumber
|
||||||
|
tb.IncreaseDataAnalysisNumber = bb.IncreaseDataAnalysisNumber
|
||||||
|
tb.BundleLimitDataAnalysisNumber = bb.BundleLimitDataAnalysisNumber
|
||||||
|
tb.IncreaseLimitDataAnalysisNumber = bb.IncreaseLimitDataAnalysisNumber
|
||||||
|
tb.BundleLimitDataAnalysisExpiredNumber = bb.BundleLimitDataAnalysisExpiredNumber
|
||||||
|
tb.IncreaseLimitDataAnalysisExpiredNumber = bb.IncreaseLimitDataAnalysisExpiredNumber
|
||||||
|
tb.MonthlyInvalidBundleDataAnalysisNumber = bb.MonthlyInvalidBundleDataAnalysisNumber
|
||||||
|
tb.InvalidBundleDataAnalysisNumber = bb.InvalidBundleDataAnalysisNumber
|
||||||
|
tb.MonthlyInvalidIncreaseDataAnalysisNumber = bb.MonthlyInvalidIncreaseDataAnalysisNumber
|
||||||
|
tb.InvalidIncreaseDataAnalysisNumber = bb.InvalidIncreaseDataAnalysisNumber
|
||||||
|
tb.BundleDataAnalysisConsumptionNumber = bb.BundleDataAnalysisConsumptionNumber
|
||||||
|
tb.IncreaseDataAnalysisConsumptionNumber = bb.IncreaseDataAnalysisConsumptionNumber
|
||||||
|
tb.BundleLimitDataAnalysisConsumptionNumber = bb.BundleLimitDataAnalysisConsumptionNumber
|
||||||
|
tb.IncreaseLimitDataAnalysisConsumptionNumber = bb.IncreaseLimitDataAnalysisConsumptionNumber
|
||||||
|
tb.BundleLimitDataAnalysisExpiredConsumptionNumber = bb.BundleLimitDataAnalysisExpiredConsumptionNumber
|
||||||
|
tb.IncreaseLimitDataAnalysisExpiredConsumptionNumber = bb.IncreaseLimitDataAnalysisExpiredConsumptionNumber
|
||||||
|
tb.MonthlyBundleDataAnalysisConsumptionNumber = bb.MonthlyBundleDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseDataAnalysisConsumptionNumber = bb.MonthlyIncreaseDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyBundleLimitDataAnalysisNumber = bb.MonthlyBundleLimitDataAnalysisNumber
|
||||||
|
tb.MonthlyIncreaseLimitDataAnalysisNumber = bb.MonthlyIncreaseLimitDataAnalysisNumber
|
||||||
|
tb.MonthlyBundleLimitDataAnalysisConsumptionNumber = bb.MonthlyBundleLimitDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseLimitDataAnalysisConsumptionNumber = bb.MonthlyIncreaseLimitDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyBundleLimitExpiredDataAnalysisNumber = bb.MonthlyBundleLimitExpiredDataAnalysisNumber
|
||||||
|
tb.MonthlyIncreaseLimitExpiredDataAnalysisNumber = bb.MonthlyIncreaseLimitExpiredDataAnalysisNumber
|
||||||
|
tb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber = bb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber = bb.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyLimitDataAnalysisQuotaNumber = bb.MonthlyLimitDataAnalysisQuotaNumber
|
||||||
|
// 手动扩展(数据分析)
|
||||||
|
tb.ManualDataAnalysisNumber = bb.ManualDataAnalysisNumber
|
||||||
|
tb.ManualDataAnalysisConsumptionNumber = bb.ManualDataAnalysisConsumptionNumber
|
||||||
|
tb.MonthlyNewManualDataAnalysisNumber = bb.MonthlyNewManualDataAnalysisNumber
|
||||||
|
tb.MonthlyManualDataAnalysisConsumptionNumber = bb.MonthlyManualDataAnalysisConsumptionNumber
|
||||||
|
|
||||||
|
// 其他字段
|
||||||
|
tb.MonthlyNewDurationNumber = bb.MonthlyNewDurationNumber
|
||||||
|
tb.ExpansionPacksNumber = bb.ExpansionPacksNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExtendTaskBalanceByUserId(userId int, imageNumber int, dataAnalysisNumber int, videoNumber int, durationNumber int) error {
|
||||||
|
// 根据用户ID获取其最新套餐记录,进而获取 sub_num、tel_num
|
||||||
|
oldBundle := model.BundleBalance{}
|
||||||
|
if err := app.ModuleClients.BundleDB.Model(&model.BundleBalance{}).
|
||||||
|
Where("user_id = ?", userId).
|
||||||
|
Order("created_at desc").
|
||||||
|
First(&oldBundle).Error; err != nil {
|
||||||
|
return errors.New("用户还没有套餐信息")
|
||||||
|
}
|
||||||
|
|
||||||
|
subNum, telNum, err := fetchIdentityForBundle(&oldBundle)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 事务更新当前有效的任务余额记录(按 start_at 最近的一条)
|
||||||
|
err = app.ModuleClients.TaskBenchDB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
var tb model.TaskBalance
|
||||||
|
now := time.Now()
|
||||||
|
query := tx.Model(&model.TaskBalance{}).
|
||||||
|
Where("sub_num = ? AND tel_num = ? AND start_at <= ? AND expired_at >= ?", subNum, telNum, now, now).
|
||||||
|
Order("start_at DESC")
|
||||||
|
|
||||||
|
if err := query.First(&tb).Error; err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
return errors.New("用户还没有任务余额信息")
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手动扩展额度与当月新增记录
|
||||||
|
tb.ManualImageNumber += imageNumber
|
||||||
|
tb.MonthlyNewManualImageNumber += imageNumber
|
||||||
|
|
||||||
|
tb.ManualDataAnalysisNumber += dataAnalysisNumber
|
||||||
|
tb.MonthlyNewManualDataAnalysisNumber += dataAnalysisNumber
|
||||||
|
|
||||||
|
tb.ManualVideoNumber += videoNumber
|
||||||
|
tb.MonthlyNewManualVideoNumber += videoNumber
|
||||||
|
|
||||||
|
tb.MonthlyNewDurationNumber += durationNumber
|
||||||
|
|
||||||
|
return tx.Model(&model.TaskBalance{}).Where("id = ?", tb.ID).Save(&tb).Error
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 增加过期时间(按天)
|
||||||
|
if durationNumber > 0 {
|
||||||
|
if err := updateTaskBalanceExpiredAt(subNum, telNum, durationNumber); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,259 +0,0 @@
|
|||||||
package dto
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// TaskQueryRequest 查询待指派任务记录请求参数
|
|
||||||
type TaskQueryRequest struct {
|
|
||||||
Keyword string `json:"keyword"` // 艺人姓名、编号、手机号搜索关键词
|
|
||||||
LastTaskAssignee string `json:"lastTaskAssignee"` // 最近一次指派人筛选(模糊匹配)
|
|
||||||
Page int `json:"page"` // 页码
|
|
||||||
PageSize int `json:"pageSize"` // 每页数量
|
|
||||||
SortBy string `json:"sortBy"` // 排序字段(支持白名单字段)
|
|
||||||
SortType string `json:"sortType"` // 排序类型 asc/desc
|
|
||||||
SubNums []string `json:"subNums"` // 选中导出的艺人编号集合(可选)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TaskAssignRequest 指派任务请求参数
|
|
||||||
type TaskAssignRequest struct {
|
|
||||||
SubNum string `json:"subNum"` // 艺人编号
|
|
||||||
TelNum string `json:"telNum"` // 艺人手机号
|
|
||||||
ArtistName string `json:"artistName"` // 艺人姓名
|
|
||||||
TaskAssignee string `json:"taskAssignee"` // 任务指派人
|
|
||||||
TaskAssigneeNum string `json:"taskAssigneeNum"` // 任务指派人账号
|
|
||||||
Operator string `json:"operator"` // 操作人
|
|
||||||
OperatorNum string `json:"operatorNum"` // 操作人账号
|
|
||||||
AssignVideoCount int `json:"assignVideoCount"` // 指派视频数
|
|
||||||
AssignPostCount int `json:"assignPostCount"` // 指派图文数
|
|
||||||
AssignDataCount int `json:"assignDataCount"` // 指派数据数
|
|
||||||
AssignVideoScriptCount int `json:"assignVideoScriptCount"` // 指派视频脚本数
|
|
||||||
AssignReportCount int `json:"assignReportCount"` // 指派竞品报告数
|
|
||||||
TaskBatch string `json:"taskBatch"` // 任务批次
|
|
||||||
UserID int `json:"userID"` // 用户ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// BatchAssignItem 批量指派项(仅写入指派记录,不更新任务管理表)
|
|
||||||
type BatchAssignItem struct {
|
|
||||||
SubNum string `json:"subNum"` // 艺人编号
|
|
||||||
TelNum string `json:"telNum"` // 艺人手机号
|
|
||||||
ArtistName string `json:"artistName"` // 艺人姓名
|
|
||||||
TaskAssignee string `json:"taskAssignee"` // 任务指派人
|
|
||||||
TaskAssigneeNum string `json:"taskAssigneeNum"` // 任务指派人账号
|
|
||||||
Operator string `json:"operator"` // 操作人
|
|
||||||
OperatorNum string `json:"operatorNum"` // 操作人账号
|
|
||||||
AssignVideoCount int `json:"assignVideoCount"` // 指派视频数
|
|
||||||
AssignPostCount int `json:"assignPostCount"` // 指派图文数
|
|
||||||
AssignDataCount int `json:"assignDataCount"` // 指派数据数
|
|
||||||
AssignVideoScriptCount int `json:"assignVideoScriptCount"` // 指派视频脚本数
|
|
||||||
AssignReportCount int `json:"assignReportCount"` // 指派竞品报告数
|
|
||||||
TaskBatch string `json:"taskBatch"` // 任务批次
|
|
||||||
UserID int `json:"userID"` // 用户ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// EmployeeTaskQueryRequest 员工任务查询请求参数
|
|
||||||
type EmployeeTaskQueryRequest struct {
|
|
||||||
TaskAssigneeNum string `json:"taskAssigneeNum"` // 被指派人账号
|
|
||||||
Keyword string `json:"keyword"` // 艺人姓名、编号、手机号搜索关键词
|
|
||||||
Operator string `json:"operator"` // 操作人
|
|
||||||
SortBy string `json:"sortBy"` // 排序字段
|
|
||||||
StartTime string `json:"startTime"` // 指派开始时间
|
|
||||||
EndTime string `json:"endTime"` // 指派结束时间
|
|
||||||
StartCompleteTime string `json:"startCompleteTime"` // 开始完成时间
|
|
||||||
EndCompleteTime string `json:"endCompleteTime"` // 结束完成时间
|
|
||||||
Status int `json:"status"` // 反馈完成状态
|
|
||||||
TaskBatch string `json:"taskBatch"` // 任务批次
|
|
||||||
|
|
||||||
Page int `json:"page"` // 页码
|
|
||||||
PageSize int `json:"pageSize"` // 每页数量
|
|
||||||
}
|
|
||||||
|
|
||||||
// CompleteTaskRequest 完成任务请求参数
|
|
||||||
type CompleteTaskRequest struct {
|
|
||||||
AssignRecordsUUID string `json:"assignRecordsUUID,omitempty"` // 指派记录UUID(可选)
|
|
||||||
EmployeeName string `json:"employeeName"` // 员工姓名(必要)
|
|
||||||
EmployeeNum string `json:"employeeNum"` // 员工工号(必要)
|
|
||||||
TaskType string `json:"taskType"` // 任务类型: video/post/data/script/report
|
|
||||||
UUID string `json:"uuid"` // 任务UUID
|
|
||||||
CompleteCount int `json:"completeCount"` // 完成数量
|
|
||||||
}
|
|
||||||
|
|
||||||
// TaskAssignRecordsQueryRequest 多条件查询操作记录表请求参数
|
|
||||||
type TaskAssignRecordsQueryRequest struct {
|
|
||||||
Keyword string `json:"keyword"` // 艺人姓名、编号、手机号搜索关键词
|
|
||||||
TaskAssignee string `json:"taskAssignee"` // 指派人姓名
|
|
||||||
Operator string `json:"operator"` // 操作人姓名
|
|
||||||
OperatorNum string `json:"operatorNum"` // 操作人手机号
|
|
||||||
StartTime string `json:"startTime"` // 操作开始时间
|
|
||||||
EndTime string `json:"endTime"` // 操作结束时间
|
|
||||||
Status int `json:"status"` // 反馈完成状态 0:全部 1:未完成 2:完成
|
|
||||||
ActualStatus int `json:"actualStatus"` // 实际完成状态 0:全部 1:未完成 2:完成
|
|
||||||
TaskBatch string `json:"taskBatch"` // 任务批次
|
|
||||||
Page int `json:"page"` // 页码
|
|
||||||
PageSize int `json:"pageSize"` // 每页数量
|
|
||||||
SortBy string `json:"sortBy"` // 排序字段(白名单)
|
|
||||||
SortType string `json:"sortType"` // 排序方式
|
|
||||||
}
|
|
||||||
|
|
||||||
// 任务记录表返回结构体
|
|
||||||
type TaskAssignRecordsResponse struct {
|
|
||||||
AssignRecordsUUID string `gorm:"column:assign_records_uuid;comment:指派记录UUID" json:"assignRecordsUUID"`
|
|
||||||
SubNum string `gorm:"column:sub_num;comment:艺人编号" json:"subNum"`
|
|
||||||
TelNum string `gorm:"column:tel_num;comment:艺人手机号" json:"telNum"`
|
|
||||||
ArtistName string `gorm:"column:artist_name;comment:艺人名称" json:"artistName"`
|
|
||||||
Status int `gorm:"column:status;comment:反馈完成状态 1:未完成 2:完成" json:"status"`
|
|
||||||
ActualStatus int `gorm:"column:actual_status;comment:实际完成状态 1:未完成 2:完成" json:"actualStatus"`
|
|
||||||
CompleteTime *time.Time `gorm:"column:complete_time;comment:反馈完成时间" json:"completeTime"`
|
|
||||||
OperatorType int `gorm:"column:operator_type;comment:操作类型 1:修改待发数量 2:指派" json:"operatorType"`
|
|
||||||
Operator string `gorm:"column:operator;comment:操作人" json:"operator"`
|
|
||||||
OperatorNum string `gorm:"column:operator_num;comment:操作人账号" json:"operatorNum"`
|
|
||||||
OperatorTime time.Time `gorm:"column:operator_time;comment:操作时间" json:"operatorTime"`
|
|
||||||
TaskAssignee string `gorm:"column:task_assignee;comment:任务指派人" json:"taskAssignee"`
|
|
||||||
TaskAssigneeNum string `gorm:"column:task_assignee_num;comment:任务指派人账号" json:"taskAssigneeNum"`
|
|
||||||
TaskBatch string `gorm:"column:task_batch;comment:任务批次" json:"taskBatch"`
|
|
||||||
PendingVideoCount int `gorm:"column:pending_video_count;comment:待发视频数量" json:"pendingVideoCount"`
|
|
||||||
PendingPostCount int `gorm:"column:pending_post_count;comment:待发图文数量" json:"pendingPostCount"`
|
|
||||||
PendingDataCount int `gorm:"column:pending_data_count;comment:待发数据数量" json:"pendingDataCount"`
|
|
||||||
PendingVideoScriptCount int `gorm:"column:pending_video_script_count;comment:待发视频脚本数量" json:"pendingVideoScriptCount"`
|
|
||||||
PendingReportCount int `gorm:"column:pending_report_count;comment:待发竞品报告数量" json:"pendingReportCount"`
|
|
||||||
// 已完成统计
|
|
||||||
CompleteVideoScriptCount int `gorm:"column:complete_video_script_count;comment:已完成视频脚本数" json:"completeVideoScriptCount"`
|
|
||||||
CompleteVideoCount int `gorm:"column:complete_video_count;comment:已完成视频数" json:"completeVideoCount"`
|
|
||||||
CompletePostCount int `gorm:"column:complete_post_count;comment:已完成图文数" json:"completePostCount"`
|
|
||||||
CompleteDataCount int `gorm:"column:complete_data_count;comment:已完成数据数" json:"completeDataCount"`
|
|
||||||
CompleteReportCount int `gorm:"column:complete_report_count;comment:已完成竞品报告数" json:"completeReportCount"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 多条件查询后分页前的艺人数量汇总
|
|
||||||
type TaskAssignRecordsSummary struct {
|
|
||||||
TotalPendingVideoScriptCount int `json:"totalPendingVideoScriptCount"`
|
|
||||||
TotalPendingVideoCount int `json:"totalPendingVideoCount"`
|
|
||||||
TotalPendingPostCount int `json:"totalPendingPostCount"`
|
|
||||||
TotalPendingDataCount int `json:"totalPendingDataCount"`
|
|
||||||
TotalPendingReportCount int `json:"totalPendingReportCount"`
|
|
||||||
TotalCompleteVideoScriptCount int `json:"totalCompleteVideoScriptCount"`
|
|
||||||
TotalCompleteVideoCount int `json:"totalCompleteVideoCount"`
|
|
||||||
TotalCompletePostCount int `json:"totalCompletePostCount"`
|
|
||||||
TotalCompleteDataCount int `json:"totalCompleteDataCount"`
|
|
||||||
TotalCompleteReportCount int `json:"totalCompleteReportCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidArtistInfo 有效艺人信息结构体
|
|
||||||
type ValidArtistInfo struct {
|
|
||||||
UserID int `json:"userId"` // 用户ID
|
|
||||||
CustomerNum string `json:"customerNum"` // 艺人编号
|
|
||||||
UserName string `json:"userName"` // 艺人姓名
|
|
||||||
UserPhoneNumber string `json:"userPhoneNumber"` // 艺人手机号
|
|
||||||
BundleName string `json:"bundleName"` // 套餐名称
|
|
||||||
ExpirationTime string `json:"expirationTime"` // 过期时间
|
|
||||||
Status int `json:"status"` // 套餐状态
|
|
||||||
OrderUUID string `json:"orderUUID"` // 订单UUID
|
|
||||||
AccountNumber int `json:"accountNumber"` // 账号数量
|
|
||||||
AccountConsumptionNumber int `json:"accountConsumptionNumber"` // 账号消耗数量
|
|
||||||
VideoNumber int `json:"videoNumber"` // 视频数量
|
|
||||||
VideoConsumptionNumber int `json:"videoConsumptionNumber"` // 视频消耗数量
|
|
||||||
ImageNumber int `json:"imageNumber"` // 图片数量
|
|
||||||
ImageConsumptionNumber int `json:"imageConsumptionNumber"` // 图片消耗数量
|
|
||||||
DataAnalysisNumber int `json:"dataAnalysisNumber"` // 数据分析数量
|
|
||||||
DataAnalysisConsumptionNumber int `json:"dataAnalysisConsumptionNumber"` // 数据分析消耗数量
|
|
||||||
ExpansionPacksNumber int `json:"expansionPacksNumber"` // 扩展套餐数量
|
|
||||||
}
|
|
||||||
|
|
||||||
// ArtistUploadStatsItem 艺人上传与额度统计(视频/图文/数据分析)
|
|
||||||
type ArtistUploadStatsItem struct {
|
|
||||||
// 身份信息
|
|
||||||
SubNum string `json:"subNum" gorm:"column:customer_num"`
|
|
||||||
UserName string `json:"userName" gorm:"column:user_name"`
|
|
||||||
UserPhoneNumber string `json:"userPhoneNumber" gorm:"column:user_phone_number"`
|
|
||||||
StartAt string `json:"startAt" gorm:"column:start_at"`
|
|
||||||
ExpiredAt string `json:"expiredAt" gorm:"column:expired_at"`
|
|
||||||
|
|
||||||
// 视频
|
|
||||||
UploadedVideoCount int `json:"uploadedVideoCount" gorm:"column:uploaded_video_count"`
|
|
||||||
BundleVideoTotal int `json:"bundleVideoTotal" gorm:"column:bundle_video_total"`
|
|
||||||
IncreaseVideoTotal int `json:"increaseVideoTotal" gorm:"column:increase_video_total"`
|
|
||||||
ReleasedVideoTotal int `json:"releasedVideoTotal" gorm:"column:released_video_total"`
|
|
||||||
PendingVideoCount int `json:"pendingVideoCount" gorm:"column:pending_video_count"`
|
|
||||||
|
|
||||||
// 图文
|
|
||||||
UploadedPostCount int `json:"uploadedPostCount" gorm:"column:uploaded_post_count"`
|
|
||||||
BundlePostTotal int `json:"bundlePostTotal" gorm:"column:bundle_post_total"`
|
|
||||||
IncreasePostTotal int `json:"increasePostTotal" gorm:"column:increase_post_total"`
|
|
||||||
ReleasedPostTotal int `json:"releasedPostTotal" gorm:"column:released_post_total"`
|
|
||||||
PendingPostCount int `json:"pendingPostCount" gorm:"column:pending_post_count"`
|
|
||||||
|
|
||||||
// 数据分析
|
|
||||||
UploadedDataAnalysisCount int `json:"uploadedDataAnalysisCount" gorm:"column:uploaded_data_count"`
|
|
||||||
BundleDataAnalysisTotal int `json:"bundleDataAnalysisTotal" gorm:"column:bundle_data_total"`
|
|
||||||
IncreaseDataAnalysisTotal int `json:"increaseDataAnalysisTotal" gorm:"column:increase_data_total"`
|
|
||||||
ReleasedDataAnalysisTotal int `json:"releasedDataAnalysisTotal" gorm:"column:released_data_total"`
|
|
||||||
PendingDataAnalysisCount int `json:"pendingDataAnalysisCount" gorm:"column:pending_data_count"`
|
|
||||||
|
|
||||||
// 竞品报告
|
|
||||||
UploadedReportCount int `json:"uploadedReportCount" gorm:"column:uploaded_report_count"`
|
|
||||||
BundleReportTotal int `json:"bundleReportTotal" gorm:"column:bundle_report_total"`
|
|
||||||
IncreaseReportTotal int `json:"increaseReportTotal" gorm:"column:increase_report_total"`
|
|
||||||
ReleasedReportTotal int `json:"releasedReportTotal" gorm:"column:released_report_total"`
|
|
||||||
PendingReportCount int `json:"pendingReportCount" gorm:"column:pending_report_count"`
|
|
||||||
|
|
||||||
// 任务管理
|
|
||||||
LastTaskAssignee string `json:"lastTaskAssignee" gorm:"column:last_task_assignee"`
|
|
||||||
TaskAssigneeNum string `json:"taskAssigneeNum" gorm:"column:task_assignee_num"`
|
|
||||||
ProgressTaskCount int `json:"progressTaskCount" gorm:"column:progress_task_count"`
|
|
||||||
CompleteTaskCount int `json:"completeTaskCount" gorm:"column:complete_task_count"`
|
|
||||||
|
|
||||||
// 脚本
|
|
||||||
UploadedVideoScriptCount int `json:"uploadedVideoScriptCount" gorm:"column:uploaded_video_script_count"`
|
|
||||||
PendingVideoScriptCount int `json:"pendingVideoScriptCount" gorm:"column:pending_video_script_count"`
|
|
||||||
|
|
||||||
// 可指派数(可上传数 - 已指派且未完成的数量)
|
|
||||||
AllowVideoScriptCount int `json:"allowVideoScriptCount" gorm:"column:allow_video_script_count"`
|
|
||||||
AllowVideoCount int `json:"allowVideoCount" gorm:"column:allow_video_count"`
|
|
||||||
AllowPostCount int `json:"allowPostCount" gorm:"column:allow_post_count"`
|
|
||||||
AllowDataCount int `json:"allowDataCount" gorm:"column:allow_data_count"`
|
|
||||||
AllowReportCount int `json:"allowReportCount" gorm:"column:allow_report_count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ArtistPendingAssignItem 艺人可指派数量(可上传数 - 已指派且未完成的数量)
|
|
||||||
type ArtistPendingAssignItem struct {
|
|
||||||
SubNum string `json:"subNum" gorm:"column:customer_num"`
|
|
||||||
TelNum string `json:"telNum" gorm:"column:tel_num"`
|
|
||||||
UserName string `json:"userName" gorm:"column:user_name"`
|
|
||||||
AllowVideoScriptCount int `json:"allowVideoScriptCount" gorm:"column:allow_video_script_count"`
|
|
||||||
AllowVideoCount int `json:"allowVideoCount" gorm:"column:allow_video_count"`
|
|
||||||
AllowPostCount int `json:"allowPostCount" gorm:"column:allow_post_count"`
|
|
||||||
AllowDataCount int `json:"allowDataCount" gorm:"column:allow_data_count"`
|
|
||||||
AllowReportCount int `json:"allowReportCount" gorm:"column:allow_report_count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTaskWorkLogRequest 创建任务日志请求参数
|
|
||||||
type CreateTaskWorkLogRequest struct {
|
|
||||||
AssignRecordsUUID string `json:"assignRecordsUUID"` // 任务指派记录UUID(必填)
|
|
||||||
WorkUUID string `json:"workUUID"` // 任务作品UUID(必填)
|
|
||||||
Title string `json:"title"` // 任务作品标题
|
|
||||||
|
|
||||||
ArtistUUID string `json:"artistUUID"` // 任务艺人UUID
|
|
||||||
SubNum string `json:"subNum"` // 任务用户编号(必填)
|
|
||||||
TelNum string `json:"telNum"` // 任务用户手机号(必填)
|
|
||||||
ArtistName string `json:"artistName"` // 任务艺人名称
|
|
||||||
|
|
||||||
// 操作信息
|
|
||||||
OperationType int `json:"operationType"` // 任务操作类型 1:加任务 2:消耗任务 3:完成任务 4:任务过期(必填)
|
|
||||||
TaskType int `json:"taskType"` // 任务类型 1:视频 2:图片 3:数据分析 4: 视频脚本 5: 竞品报告
|
|
||||||
TaskCount int `json:"taskCount"` // 任务数量(必填)
|
|
||||||
Remark string `json:"remark"` // 任务备注
|
|
||||||
|
|
||||||
// 操作人信息
|
|
||||||
OperatorName string `json:"operatorName"` // 任务操作人姓名
|
|
||||||
OperatorNum string `json:"operatorNum"` // 任务操作人账号
|
|
||||||
}
|
|
||||||
|
|
||||||
type TaskWorkLogQueryRequest struct {
|
|
||||||
AssignRecordsUUID string `json:"assignRecordsUUID"`
|
|
||||||
OperationType int `json:"operationType"`
|
|
||||||
TaskType int `json:"taskType"`
|
|
||||||
ArtistUUID string `json:"artistUUID"`
|
|
||||||
SubNum string `json:"subNum"`
|
|
||||||
ArtistName string `json:"artistName"`
|
|
||||||
Page int `json:"page"`
|
|
||||||
PageSize int `json:"pageSize"`
|
|
||||||
}
|
|
||||||
@ -16,7 +16,6 @@ import (
|
|||||||
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
"dubbo.apache.org/dubbo-go/v3/common/logger"
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/shopspring/decimal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse, error) {
|
||||||
@ -37,14 +36,12 @@ func BundleExtend(req *bundle.BundleExtendRequest) (*bundle.BundleExtendResponse
|
|||||||
|
|
||||||
if req.Type == 1 {
|
if req.Type == 1 {
|
||||||
if err := dao.ExtendBundleBalanceByUserId(model.BundleBalanceExtendPo{
|
if err := dao.ExtendBundleBalanceByUserId(model.BundleBalanceExtendPo{
|
||||||
UserId: int(req.UserId),
|
UserId: int(req.UserId),
|
||||||
VideoNumber: int(req.VideoAdditional),
|
VideoNumber: int(req.VideoAdditional),
|
||||||
ImageNumber: int(req.ImagesAdditional),
|
ImageNumber: int(req.ImagesAdditional),
|
||||||
DataAnalysisNumber: int(req.DataAdditional),
|
DataAnalysisNumber: int(req.DataAdditional),
|
||||||
AccountNumber: int(req.AccountAdditional),
|
AccountNumber: int(req.AccountAdditional),
|
||||||
CompetitiveNumber: int(req.CompetitiveAdditional),
|
DurationNumber: durationNumber,
|
||||||
DurationNumber: durationNumber,
|
|
||||||
CompetitiveAdditional: int(req.CompetitiveAdditional),
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, errors.New("用户没有余量信息")
|
return nil, errors.New("用户没有余量信息")
|
||||||
}
|
}
|
||||||
@ -149,21 +146,6 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (*bundle.GetBundl
|
|||||||
MonthlyIncreaseDataAnalysisNumber: int32(m.IncreaseDataAnalysisNumber) - int32(m.IncreaseDataAnalysisConsumptionNumber) + int32(m.MonthlyIncreaseLimitDataAnalysisNumber) + int32(m.MonthlyIncreaseLimitExpiredDataAnalysisNumber),
|
MonthlyIncreaseDataAnalysisNumber: int32(m.IncreaseDataAnalysisNumber) - int32(m.IncreaseDataAnalysisConsumptionNumber) + int32(m.MonthlyIncreaseLimitDataAnalysisNumber) + int32(m.MonthlyIncreaseLimitExpiredDataAnalysisNumber),
|
||||||
MonthlyInvalidBundleDataAnalysisNumber: int32(m.MonthlyInvalidBundleDataAnalysisNumber),
|
MonthlyInvalidBundleDataAnalysisNumber: int32(m.MonthlyInvalidBundleDataAnalysisNumber),
|
||||||
MonthlyInvalidIncreaseDataAnalysisNumber: int32(m.MonthlyInvalidIncreaseDataAnalysisNumber),
|
MonthlyInvalidIncreaseDataAnalysisNumber: int32(m.MonthlyInvalidIncreaseDataAnalysisNumber),
|
||||||
//竞品数
|
|
||||||
BundleCompetitiveNumber: int32(m.BundleCompetitiveNumber) + int32(m.BundleLimitCompetitiveNumber) + int32(m.BundleLimitCompetitiveExpiredNumber),
|
|
||||||
IncreaseCompetitiveNumber: int32(m.IncreaseCompetitiveNumber) + int32(m.IncreaseLimitCompetitiveNumber) + int32(m.IncreaseLimitCompetitiveExpiredNumber),
|
|
||||||
BundleCompetitiveConsumptionNumber: int32(m.BundleCompetitiveConsumptionNumber) + int32(m.BundleLimitCompetitiveConsumptionNumber) + int32(m.BundleLimitCompetitiveExpiredConsumptionNumber),
|
|
||||||
IncreaseCompetitiveConsumptionNumber: int32(m.IncreaseCompetitiveConsumptionNumber) + int32(m.IncreaseLimitCompetitiveConsumptionNumber) + int32(m.IncreaseLimitCompetitiveExpiredConsumptionNumber),
|
|
||||||
InvalidBundleCompetitiveNumber: int32(m.InvalidBundleCompetitiveNumber),
|
|
||||||
InvalidIncreaseCompetitiveNumber: int32(m.InvalidIncreaseCompetitiveNumber),
|
|
||||||
MonthlyNewBundleCompetitiveNumber: int32(qua(m.BundleBalance, m.BundleLimitCompetitiveNumber, m.MonthlyLimitCompetitiveQuotaNumber, date) + cal(m.BundleBalance, m.BundleLimitCompetitiveExpiredNumber, m.MonthlyLimitCompetitiveQuotaNumber, date)),
|
|
||||||
MonthlyNewIncreaseCompetitiveNumber: int32(qua(m.BundleBalance, m.IncreaseLimitCompetitiveNumber, m.MonthlyLimitCompetitiveQuotaNumber, date) + cal(m.BundleBalance, m.IncreaseLimitCompetitiveExpiredNumber, m.MonthlyLimitCompetitiveQuotaNumber, date)),
|
|
||||||
MonthBundleCompetitiveConsumptionNumber: int32(m.MonthlyBundleCompetitiveConsumptionNumber) + int32(m.MonthlyBundleLimitCompetitiveConsumptionNumber) + int32(m.MonthlyBundleLimitExpiredCompetitiveConsumptionNumber),
|
|
||||||
MonthIncreaseCompetitiveConsumptionNumber: int32(m.MonthlyIncreaseCompetitiveConsumptionNumber) + int32(m.MonthlyIncreaseLimitCompetitiveConsumptionNumber) + int32(m.MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber),
|
|
||||||
MonthlyBundleCompetitiveNumber: int32(m.BundleCompetitiveNumber) - int32(m.BundleCompetitiveConsumptionNumber) + int32(m.MonthlyBundleLimitCompetitiveNumber) + int32(m.MonthlyBundleLimitExpiredCompetitiveNumber) - int32(m.MonthlyBundleLimitCompetitiveConsumptionNumber),
|
|
||||||
MonthlyIncreaseCompetitiveNumber: int32(m.IncreaseCompetitiveNumber) - int32(m.IncreaseCompetitiveConsumptionNumber) + int32(m.MonthlyIncreaseLimitCompetitiveNumber) + int32(m.MonthlyIncreaseLimitExpiredCompetitiveNumber),
|
|
||||||
MonthlyInvalidBundleCompetitiveNumber: int32(m.MonthlyInvalidBundleCompetitiveNumber),
|
|
||||||
MonthlyInvalidIncreaseCompetitiveNumber: int32(m.MonthlyInvalidIncreaseCompetitiveNumber),
|
|
||||||
// 手动扩展类
|
// 手动扩展类
|
||||||
MonthlyNewManualAccountNumber: int32(m.MonthlyNewAccountNumber),
|
MonthlyNewManualAccountNumber: int32(m.MonthlyNewAccountNumber),
|
||||||
MonthlyNewManualVideoNumber: int32(m.MonthlyNewManualVideoNumber),
|
MonthlyNewManualVideoNumber: int32(m.MonthlyNewManualVideoNumber),
|
||||||
@ -191,8 +173,6 @@ func GetBundleBalanceList(req *bundle.GetBundleBalanceListReq) (*bundle.GetBundl
|
|||||||
result.MonthlyNewIncreaseImageNumber += int32(m.IncreaseImageNumber)
|
result.MonthlyNewIncreaseImageNumber += int32(m.IncreaseImageNumber)
|
||||||
result.MonthlyNewBundleDataAnalysisNumber += int32(m.BundleDataAnalysisNumber)
|
result.MonthlyNewBundleDataAnalysisNumber += int32(m.BundleDataAnalysisNumber)
|
||||||
result.MonthlyNewIncreaseDataAnalysisNumber += int32(m.IncreaseDataAnalysisNumber)
|
result.MonthlyNewIncreaseDataAnalysisNumber += int32(m.IncreaseDataAnalysisNumber)
|
||||||
result.MonthlyNewBundleCompetitiveNumber += int32(m.BundleCompetitiveNumber)
|
|
||||||
result.MonthlyNewIncreaseCompetitiveNumber += int32(m.IncreaseCompetitiveNumber)
|
|
||||||
}
|
}
|
||||||
if result.Activate != 2 { // 除了等于0的情况
|
if result.Activate != 2 { // 除了等于0的情况
|
||||||
result.Activate = 1
|
result.Activate = 1
|
||||||
@ -222,13 +202,11 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (*bundle.
|
|||||||
} else {
|
} else {
|
||||||
IsExpired = msg.NotExpired //未过期
|
IsExpired = msg.NotExpired //未过期
|
||||||
}
|
}
|
||||||
|
|
||||||
result := &bundle.GetBundleBalanceByUserIdResp{
|
result := &bundle.GetBundleBalanceByUserIdResp{
|
||||||
OrderUUID: data.OrderUUID,
|
OrderUUID: data.OrderUUID,
|
||||||
BundleName: data.BundleName,
|
BundleName: data.BundleName,
|
||||||
BundleStatus: IsExpired,
|
BundleStatus: IsExpired,
|
||||||
PayTime: data.PayTime.UnixMilli(),
|
PayTime: data.StartAt.UnixMilli(),
|
||||||
StartTime: data.StartAt.UnixMilli(),
|
|
||||||
ExpiredTime: data.ExpiredAt.UnixMilli(),
|
ExpiredTime: data.ExpiredAt.UnixMilli(),
|
||||||
PaymentAmount: data.PaymentAmount,
|
PaymentAmount: data.PaymentAmount,
|
||||||
PaymentType: data.PaymentType,
|
PaymentType: data.PaymentType,
|
||||||
@ -251,38 +229,10 @@ func GetBundleBalanceByUserId(req *bundle.GetBundleBalanceByUserIdReq) (*bundle.
|
|||||||
DataAnalysisExtendConsumptionNumber: int32(data.MonthlyBundleLimitDataAnalysisConsumptionNumber) + int32(data.MonthlyIncreaseLimitDataAnalysisConsumptionNumber) + int32(data.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber) + int32(data.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber) + int32(data.ManualDataAnalysisConsumptionNumber) + int32(data.IncreaseDataAnalysisConsumptionNumber) + int32(data.BundleDataAnalysisConsumptionNumber),
|
DataAnalysisExtendConsumptionNumber: int32(data.MonthlyBundleLimitDataAnalysisConsumptionNumber) + int32(data.MonthlyIncreaseLimitDataAnalysisConsumptionNumber) + int32(data.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber) + int32(data.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber) + int32(data.ManualDataAnalysisConsumptionNumber) + int32(data.IncreaseDataAnalysisConsumptionNumber) + int32(data.BundleDataAnalysisConsumptionNumber),
|
||||||
DataAnalysisAdditional: int32(data.ManualDataAnalysisNumber),
|
DataAnalysisAdditional: int32(data.ManualDataAnalysisNumber),
|
||||||
DataAnalysisConsumptionNumber: int32(data.BundleDataAnalysisConsumptionNumber) + int32(data.BundleLimitDataAnalysisConsumptionNumber) + int32(data.BundleLimitDataAnalysisExpiredConsumptionNumber) + int32(data.IncreaseDataAnalysisConsumptionNumber) + int32(data.IncreaseLimitDataAnalysisConsumptionNumber) + int32(data.IncreaseLimitDataAnalysisExpiredConsumptionNumber) + int32(data.ManualDataAnalysisConsumptionNumber),
|
DataAnalysisConsumptionNumber: int32(data.BundleDataAnalysisConsumptionNumber) + int32(data.BundleLimitDataAnalysisConsumptionNumber) + int32(data.BundleLimitDataAnalysisExpiredConsumptionNumber) + int32(data.IncreaseDataAnalysisConsumptionNumber) + int32(data.IncreaseLimitDataAnalysisConsumptionNumber) + int32(data.IncreaseLimitDataAnalysisExpiredConsumptionNumber) + int32(data.ManualDataAnalysisConsumptionNumber),
|
||||||
CompetitiveNumber: int32(data.BundleCompetitiveNumber) + int32(data.BundleLimitCompetitiveNumber) + int32(data.BundleLimitCompetitiveExpiredNumber) + int32(data.IncreaseCompetitiveNumber) + int32(data.IncreaseLimitCompetitiveNumber) + int32(data.IncreaseLimitCompetitiveExpiredNumber) + int32(data.ManualCompetitiveNumber),
|
|
||||||
CompetitiveExtendNumber: int32(data.MonthlyBundleLimitCompetitiveNumber) + int32(data.MonthlyIncreaseLimitCompetitiveNumber) + int32(data.MonthlyBundleLimitExpiredCompetitiveNumber) + int32(data.MonthlyIncreaseLimitExpiredCompetitiveNumber) + int32(data.ManualCompetitiveNumber) + int32(data.IncreaseCompetitiveNumber) + int32(data.BundleCompetitiveNumber),
|
|
||||||
CompetitiveExtendConsumptionNumber: int32(data.MonthlyBundleLimitCompetitiveConsumptionNumber) + int32(data.MonthlyIncreaseLimitCompetitiveConsumptionNumber) + int32(data.MonthlyBundleLimitExpiredCompetitiveConsumptionNumber) + int32(data.MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber) + int32(data.ManualCompetitiveConsumptionNumber) + int32(data.IncreaseCompetitiveConsumptionNumber) + int32(data.BundleCompetitiveConsumptionNumber),
|
|
||||||
CompetitiveAdditional: int32(data.ManualCompetitiveNumber),
|
|
||||||
CompetitiveConsumptionNumber: int32(data.BundleCompetitiveConsumptionNumber) + int32(data.BundleLimitCompetitiveConsumptionNumber) + int32(data.BundleLimitCompetitiveExpiredConsumptionNumber) + int32(data.IncreaseCompetitiveConsumptionNumber) + int32(data.IncreaseLimitCompetitiveConsumptionNumber) + int32(data.IncreaseLimitCompetitiveExpiredConsumptionNumber) + int32(data.ManualCompetitiveConsumptionNumber),
|
|
||||||
PurchaseType: int64(data.PurchaseType),
|
|
||||||
RenewalOrderUuid: data.RenewalOrderUUID,
|
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取最初非续费套餐订单的开始时间
|
|
||||||
// 查询失败返回2 和 默认事件
|
|
||||||
func GetBundleBalanceByOrderUUID(orderUUID string) (time.Time, int, error) {
|
|
||||||
defaultStart := time.Date(2024, 1, 1, 0, 0, 0, 0, time.Local)
|
|
||||||
if orderUUID == "" {
|
|
||||||
return defaultStart, 1, nil
|
|
||||||
}
|
|
||||||
originalOrderUUID, err := dao.GetOriginalOrderUUID(orderUUID)
|
|
||||||
if err != nil {
|
|
||||||
return defaultStart, 1, nil
|
|
||||||
}
|
|
||||||
data, err := dao.GetBundleBalanceByOrderUuid(originalOrderUUID)
|
|
||||||
if err != nil {
|
|
||||||
return defaultStart, 1, nil
|
|
||||||
}
|
|
||||||
if data.StartAt.IsZero() {
|
|
||||||
return defaultStart, 1, nil
|
|
||||||
}
|
|
||||||
return data.StartAt, 2, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddBundleBalance(req *bundle.AddBundleBalanceReq) (*bundle.AddBundleBalanceResp, error) {
|
func AddBundleBalance(req *bundle.AddBundleBalanceReq) (*bundle.AddBundleBalanceResp, error) {
|
||||||
data := model.BundleBalanceUsePo{
|
data := model.BundleBalanceUsePo{
|
||||||
UserId: int(req.UserId),
|
UserId: int(req.UserId),
|
||||||
@ -290,7 +240,6 @@ func AddBundleBalance(req *bundle.AddBundleBalanceReq) (*bundle.AddBundleBalance
|
|||||||
ImageNumber: int(req.ImageConsumptionNumber),
|
ImageNumber: int(req.ImageConsumptionNumber),
|
||||||
VideoNumber: int(req.VideoConsumptionNumber),
|
VideoNumber: int(req.VideoConsumptionNumber),
|
||||||
DataAnalysisNumber: int(req.DataAnalysisConsumptionNumber),
|
DataAnalysisNumber: int(req.DataAnalysisConsumptionNumber),
|
||||||
CompetitiveNumber: int(req.CompetitiveConsumptionNumber),
|
|
||||||
}
|
}
|
||||||
uesdType, err := dao.AddBundleBalanceByUserId(data)
|
uesdType, err := dao.AddBundleBalanceByUserId(data)
|
||||||
return &bundle.AddBundleBalanceResp{
|
return &bundle.AddBundleBalanceResp{
|
||||||
@ -316,65 +265,19 @@ func cal(data model.BundleBalance, total, limit int, date time.Time) int {
|
|||||||
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() && data.StartAt.Day() >= 16 { // 本月为第一个月并且16号后购买只给一半(向上取整)
|
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() && data.StartAt.Day() >= 16 { // 本月为第一个月并且16号后购买只给一半(向上取整)
|
||||||
return min((limit+1)/2, remaining)
|
return min((limit+1)/2, remaining)
|
||||||
}
|
}
|
||||||
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() && data.StartAt.Day() < 16 { // 本月为第一个月并且16号前购买
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
if data.ExpiredAt.Month() == date.Month() && data.ExpiredAt.Year() == date.Year() && data.ExpiredAt.Day() < 16 { // 本月为最后一个月并且16号前到期只给一半(向下取整)
|
if data.ExpiredAt.Month() == date.Month() && data.ExpiredAt.Year() == date.Year() && data.ExpiredAt.Day() < 16 { // 本月为最后一个月并且16号前到期只给一半(向下取整)
|
||||||
return min(limit/2, remaining)
|
return min(limit/2, remaining)
|
||||||
}
|
}
|
||||||
return min(limit, remaining)
|
return min(limit, remaining)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算每个季度发放的数目
|
|
||||||
func qua(data model.BundleBalance, total, limit int, date time.Time) int {
|
|
||||||
var released int // 已释放的次数
|
|
||||||
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() {
|
|
||||||
} else {
|
|
||||||
released += limit
|
|
||||||
}
|
|
||||||
interval := max((date.Year()*12+int(date.Month())-(data.StartAt.Year()*12+int(data.StartAt.Month())))/3, 1) // 释放了多少个季度
|
|
||||||
released += max(interval-1, 0) * limit // 已经释放的数量
|
|
||||||
remaining := max(total-released, 0) // 还剩余多少次没有发放
|
|
||||||
if data.StartAt.Month() == date.Month() && data.StartAt.Year() == date.Year() { // 本月为第一个月购买
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
monthDiff := date.Year()*12 + int(date.Month()) - (data.StartAt.Year()*12 + int(data.StartAt.Month()))
|
|
||||||
if monthDiff%3 == 0 && data.ExpiredAt.Month() != date.Month() {
|
|
||||||
return min(limit, remaining)
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateBundleBalance(req *bundle.CreateBundleBalanceReq) (*bundle.CreateBundleBalanceResp, error) {
|
func CreateBundleBalance(req *bundle.CreateBundleBalanceReq) (*bundle.CreateBundleBalanceResp, error) {
|
||||||
var data model.BundleBalance
|
var data model.BundleBalance
|
||||||
orderReq := &bundle.OrderRecordsDetailRequest{}
|
|
||||||
var addValues []model.BundleOrderValueAdd
|
|
||||||
var oldValues model.BundleBalance
|
|
||||||
fmt.Println("开始创建套餐OrderUuid:", req.OrderUUID)
|
|
||||||
orderReq.Uuid = req.OrderUUID
|
|
||||||
orderInfo, err := dao.OrderRecordDetail(orderReq)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("获取用户订单信息失败:", err)
|
|
||||||
return nil, errors.New("获取用户订单信息失败")
|
|
||||||
}
|
|
||||||
if orderInfo.PurchaseType == 1 {
|
|
||||||
//新购
|
|
||||||
addValues, err = dao.GetValueAddByOrderUUID(req.OrderUUID)
|
|
||||||
if err != nil || len(addValues) == 0 {
|
|
||||||
return nil, errors.New("获取增值服务失败")
|
|
||||||
}
|
|
||||||
} else if orderInfo.PurchaseType == 2 {
|
|
||||||
//续费
|
|
||||||
addValues, err = dao.GetValueAddByOrderUUID(req.OrderUUID)
|
|
||||||
if err != nil || len(addValues) == 0 {
|
|
||||||
return nil, errors.New("获取增值服务失败")
|
|
||||||
}
|
|
||||||
oldValues, err = dao.GetBundleBalanceByOrderUuid(orderInfo.RenewalOrderUUID)
|
|
||||||
if err != nil || len(addValues) == 0 {
|
|
||||||
return nil, errors.New("获取旧套餐数据失败失败")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
addValues, err := dao.GetValueAddByOrderUUID(req.OrderUUID)
|
||||||
|
if err != nil || len(addValues) == 0 {
|
||||||
|
return nil, errors.New("获取增值服务失败")
|
||||||
|
}
|
||||||
data.StartAt = time.Now()
|
data.StartAt = time.Now()
|
||||||
data.ExpiredAt = time.Now()
|
data.ExpiredAt = time.Now()
|
||||||
userId, err := strconv.Atoi(addValues[0].CustomerID)
|
userId, err := strconv.Atoi(addValues[0].CustomerID)
|
||||||
@ -455,35 +358,15 @@ func CreateBundleBalance(req *bundle.CreateBundleBalanceReq) (*bundle.CreateBund
|
|||||||
data.IncreaseLimitDataAnalysisNumber += int(v.Num)
|
data.IncreaseLimitDataAnalysisNumber += int(v.Num)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
data.IncreaseDataAnalysisNumber += int(v.Num)
|
data.IncreaseDataAnalysisNumber += int(v.Num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 4: // 账号数
|
case 4: // 账号数
|
||||||
if orderInfo.PurchaseType == 1 {
|
if v.EquityType == 1 { // 套餐权益
|
||||||
//新购
|
data.BundleAccountNumber += int(v.Num)
|
||||||
if v.EquityType == 1 { // 套餐权益
|
|
||||||
data.BundleAccountNumber += int(v.Num)
|
|
||||||
} else {
|
|
||||||
data.IncreaseAccountNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//续费
|
data.IncreaseAccountNumber += int(v.Num)
|
||||||
if v.EquityType == 1 { // 套餐权益
|
|
||||||
data.BundleAccountNumber += int(v.Num)
|
|
||||||
if int(v.Num) >= oldValues.BundleAccountConsumptionNumber {
|
|
||||||
data.BundleAccountConsumptionNumber += oldValues.BundleAccountConsumptionNumber
|
|
||||||
} else {
|
|
||||||
data.BundleAccountConsumptionNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
data.IncreaseAccountNumber += int(v.Num)
|
|
||||||
if int(v.Num) >= oldValues.IncreaseAccountConsumptionNumber {
|
|
||||||
data.IncreaseAccountConsumptionNumber += oldValues.IncreaseAccountConsumptionNumber
|
|
||||||
} else {
|
|
||||||
data.IncreaseAccountConsumptionNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case 5: // 可用时长
|
case 5: // 可用时长
|
||||||
switch v.Unit {
|
switch v.Unit {
|
||||||
@ -494,30 +377,6 @@ func CreateBundleBalance(req *bundle.CreateBundleBalanceReq) (*bundle.CreateBund
|
|||||||
case "年":
|
case "年":
|
||||||
data.ExpiredAt = data.ExpiredAt.Add(time.Hour * 24 * 365 * time.Duration(v.Num))
|
data.ExpiredAt = data.ExpiredAt.Add(time.Hour * 24 * 365 * time.Duration(v.Num))
|
||||||
}
|
}
|
||||||
case 6: // 竞品数
|
|
||||||
if v.EquityType == 1 { // 套餐权益
|
|
||||||
if v.QuotaType == 2 { // 限制额度
|
|
||||||
data.MonthlyLimitCompetitiveQuotaNumber = int(v.QuotaValue)
|
|
||||||
if v.IsExpired { // 会过期的限制类型
|
|
||||||
data.BundleLimitCompetitiveExpiredNumber += int(v.Num)
|
|
||||||
} else {
|
|
||||||
data.BundleLimitCompetitiveNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data.BundleCompetitiveNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if v.QuotaType == 2 { // 限制额度
|
|
||||||
data.MonthlyLimitCompetitiveQuotaNumber = int(v.QuotaValue)
|
|
||||||
if v.IsExpired { // 会过期的限制类型
|
|
||||||
data.IncreaseLimitCompetitiveExpiredNumber += int(v.Num)
|
|
||||||
} else {
|
|
||||||
data.IncreaseLimitCompetitiveNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
data.IncreaseCompetitiveNumber += int(v.Num)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -536,17 +395,11 @@ func CreateBundleBalance(req *bundle.CreateBundleBalanceReq) (*bundle.CreateBund
|
|||||||
data.MonthlyBundleLimitDataAnalysisNumber = cal(data, data.BundleLimitDataAnalysisNumber, data.MonthlyLimitDataAnalysisQuotaNumber, now)
|
data.MonthlyBundleLimitDataAnalysisNumber = cal(data, data.BundleLimitDataAnalysisNumber, data.MonthlyLimitDataAnalysisQuotaNumber, now)
|
||||||
data.MonthlyIncreaseLimitDataAnalysisNumber = cal(data, data.IncreaseLimitDataAnalysisNumber, data.MonthlyLimitDataAnalysisQuotaNumber, now)
|
data.MonthlyIncreaseLimitDataAnalysisNumber = cal(data, data.IncreaseLimitDataAnalysisNumber, data.MonthlyLimitDataAnalysisQuotaNumber, now)
|
||||||
|
|
||||||
data.MonthlyBundleLimitExpiredCompetitiveNumber = cal(data, data.BundleLimitCompetitiveExpiredNumber, data.MonthlyLimitCompetitiveQuotaNumber, now)
|
|
||||||
data.MonthlyIncreaseLimitExpiredCompetitiveNumber = cal(data, data.IncreaseLimitCompetitiveExpiredNumber, data.MonthlyLimitCompetitiveQuotaNumber, now)
|
|
||||||
data.MonthlyBundleLimitCompetitiveNumber = cal(data, data.BundleLimitCompetitiveNumber, data.MonthlyLimitCompetitiveQuotaNumber, now)
|
|
||||||
data.MonthlyIncreaseLimitCompetitiveNumber = cal(data, data.IncreaseLimitCompetitiveNumber, data.MonthlyLimitCompetitiveQuotaNumber, now)
|
|
||||||
|
|
||||||
err = dao.CreateBundleBalance(data)
|
err = dao.CreateBundleBalance(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
return nil, errors.New("创建余量信息失败")
|
return nil, errors.New("创建余量信息失败")
|
||||||
}
|
}
|
||||||
fmt.Println("创建套餐成功")
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -632,8 +485,12 @@ func BundleActivate(req *bundle.BundleActivateReq) error {
|
|||||||
return dao.BundleActivate(req.Ids)
|
return dao.BundleActivate(req.Ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateBundleBalance() {
|
func UpdateBundleBalance() error {
|
||||||
dao.UpdateBundleBalance()
|
err := dao.UpdateBundleBalance()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func BundleBalanceExport(req *bundle.BundleBalanceExportReq) (*bundle.BundleBalanceExportResp, error) {
|
func BundleBalanceExport(req *bundle.BundleBalanceExportReq) (*bundle.BundleBalanceExportResp, error) {
|
||||||
@ -678,8 +535,6 @@ func BundleBalanceExport(req *bundle.BundleBalanceExportReq) (*bundle.BundleBala
|
|||||||
item.MonthlyIncreaseImageConsumptionNumber = v.MonthIncreaseImageConsumptionNumber
|
item.MonthlyIncreaseImageConsumptionNumber = v.MonthIncreaseImageConsumptionNumber
|
||||||
item.MonthlyBundleDataAnalysisConsumptionNumber = v.MonthBundleDataAnalysisConsumptionNumber
|
item.MonthlyBundleDataAnalysisConsumptionNumber = v.MonthBundleDataAnalysisConsumptionNumber
|
||||||
item.MonthlyIncreaseDataAnalysisConsumptionNumber = v.MonthIncreaseDataAnalysisConsumptionNumber
|
item.MonthlyIncreaseDataAnalysisConsumptionNumber = v.MonthIncreaseDataAnalysisConsumptionNumber
|
||||||
item.MonthlyBundleCompetitiveConsumptionNumber = v.MonthBundleCompetitiveConsumptionNumber
|
|
||||||
item.MonthlyIncreaseCompetitiveConsumptionNumber = v.MonthIncreaseCompetitiveConsumptionNumber
|
|
||||||
item.Currency = "USD"
|
item.Currency = "USD"
|
||||||
f, _ := strconv.ParseFloat(prefixItem.Fee, 64)
|
f, _ := strconv.ParseFloat(prefixItem.Fee, 64)
|
||||||
item.Fee = fmt.Sprintf("%.2f", f)
|
item.Fee = fmt.Sprintf("%.2f", f)
|
||||||
@ -693,14 +548,6 @@ func BundleBalanceExport(req *bundle.BundleBalanceExportReq) (*bundle.BundleBala
|
|||||||
} else {
|
} else {
|
||||||
item.IncreaseVideoUnitPrice = float32(math.Round(float64(item.IncreaseAmount/float32(v.IncreaseVideoNumber))*100) / 100)
|
item.IncreaseVideoUnitPrice = float32(math.Round(float64(item.IncreaseAmount/float32(v.IncreaseVideoNumber))*100) / 100)
|
||||||
}
|
}
|
||||||
bundleUnitPrice := decimal.NewFromFloat32(item.BundleVideoUnitPrice)
|
|
||||||
increaseUnitPrice := decimal.NewFromFloat32(item.IncreaseVideoUnitPrice)
|
|
||||||
|
|
||||||
bundlePriceTotal := bundleUnitPrice.Mul(decimal.NewFromInt32(v.MonthBundleVideoConsumptionNumber))
|
|
||||||
increasePriceTotal := increaseUnitPrice.Mul(decimal.NewFromInt32(v.MonthIncreaseVideoConsumptionNumber))
|
|
||||||
|
|
||||||
item.MonthlyBundleVideoConsumptionPrice = bundlePriceTotal.StringFixed(2)
|
|
||||||
item.MonthlyIncreaseVideoConsumptionPrice = increasePriceTotal.StringFixed(2)
|
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
return &bundle.BundleBalanceExportResp{Total: int64(len(items)), Data: items}, nil
|
return &bundle.BundleBalanceExportResp{Total: int64(len(items)), Data: items}, nil
|
||||||
@ -775,8 +622,6 @@ func buildDefaultBalanceLayout() string {
|
|||||||
{"增值数据总数", "increaseDataAnalysisNumber", 2},
|
{"增值数据总数", "increaseDataAnalysisNumber", 2},
|
||||||
{"当前已用套餐数据数", "bundleDataAnalysisConsumptionNumber", 2},
|
{"当前已用套餐数据数", "bundleDataAnalysisConsumptionNumber", 2},
|
||||||
{"当前已用增值数据数", "increaseDataAnalysisConsumptionNumber", 2},
|
{"当前已用增值数据数", "increaseDataAnalysisConsumptionNumber", 2},
|
||||||
{"当前可用套餐数据数", "monthlyBundleDataAnalysisNumber", 2},
|
|
||||||
{"当前可用增值数据数", "monthlyIncreaseDataAnalysisNumber", 2},
|
|
||||||
{"当前作废套餐数据数", "invalidBundleDataAnalysisNumber", 2},
|
{"当前作废套餐数据数", "invalidBundleDataAnalysisNumber", 2},
|
||||||
{"当前作废增值数据数", "invalidIncreaseDataAnalysisNumber", 2},
|
{"当前作废增值数据数", "invalidIncreaseDataAnalysisNumber", 2},
|
||||||
{"当月新增套餐数据数", "monthlyNewBundleDataAnalysisNumber", 2},
|
{"当月新增套餐数据数", "monthlyNewBundleDataAnalysisNumber", 2},
|
||||||
@ -787,33 +632,15 @@ func buildDefaultBalanceLayout() string {
|
|||||||
{"当月可用增值数据数", "monthlyIncreaseDataAnalysisNumber", 2},
|
{"当月可用增值数据数", "monthlyIncreaseDataAnalysisNumber", 2},
|
||||||
{"当月作废套餐数据数", "monthlyInvalidBundleDataAnalysisNumber", 2},
|
{"当月作废套餐数据数", "monthlyInvalidBundleDataAnalysisNumber", 2},
|
||||||
{"当月作废增值数据数", "monthlyInvalidIncreaseDataAnalysisNumber", 2},
|
{"当月作废增值数据数", "monthlyInvalidIncreaseDataAnalysisNumber", 2},
|
||||||
{"套餐竞品总数", "bundleCompetitiveNumber", 2},
|
|
||||||
{"增值竞品总数", "increaseCompetitiveNumber", 2},
|
|
||||||
{"当前已用套餐竞品数", "bundleCompetitiveConsumptionNumber", 2},
|
|
||||||
{"当前已用增值竞品数", "increaseCompetitiveConsumptionNumber", 2},
|
|
||||||
{"当前可用套餐竞品数", "monthlyBundleCompetitiveNumber", 2},
|
|
||||||
{"当前可用增值竞品数", "monthlyIncreaseCompetitiveNumber", 2},
|
|
||||||
{"当前作废套餐竞品数", "invalidBundleCompetitiveNumber", 2},
|
|
||||||
{"当前作废增值竞品数", "invalidIncreaseCompetitiveNumber", 2},
|
|
||||||
{"当月新增套餐竞品数", "monthlyNewBundleCompetitiveNumber", 2},
|
|
||||||
{"当月新增增值竞品数", "monthlyNewIncreaseCompetitiveNumber", 2},
|
|
||||||
{"当月使用套餐竞品数", "monthBundleCompetitiveConsumptionNumber", 2},
|
|
||||||
{"当月使用增值竞品数", "monthIncreaseCompetitiveConsumptionNumber", 2},
|
|
||||||
{"当月可用套餐竞品数", "monthlyBundleCompetitiveNumber", 2},
|
|
||||||
{"当月可用增值竞品数", "monthlyIncreaseCompetitiveNumber", 2},
|
|
||||||
{"当月作废套餐竞品数", "monthlyInvalidBundleCompetitiveNumber", 2},
|
|
||||||
{"当月作废增值竞品数", "monthlyInvalidIncreaseCompetitiveNumber", 2},
|
|
||||||
{"当月新增手动扩展账号数", "monthlyNewManualAccountNumber", 2},
|
{"当月新增手动扩展账号数", "monthlyNewManualAccountNumber", 2},
|
||||||
{"当月新增手动扩展视频数", "monthlyNewManualVideoNumber", 2},
|
{"当月新增手动扩展视频数", "monthlyNewManualVideoNumber", 2},
|
||||||
{"当月新增手动扩展图文数", "monthlyNewManualImageNumber", 2},
|
{"当月新增手动扩展图文数", "monthlyNewManualImageNumber", 2},
|
||||||
{"当月新增手动扩展数据数", "monthlyNewManualDataAnalysisNumber", 2},
|
{"当月新增手动扩展数据数", "monthlyNewManualDataAnalysisNumber", 2},
|
||||||
{"当月新增手动扩展竞品数", "monthlyNewManualCompetitiveNumber", 2},
|
|
||||||
{"当月新增手动扩展时长(日)", "monthlyNewDurationNumber", 2},
|
{"当月新增手动扩展时长(日)", "monthlyNewDurationNumber", 2},
|
||||||
{"当月已用手动扩展账号数", "monthlyManualAccountConsumptionNumber", 2},
|
{"当月已用手动扩展账号数", "monthlyManualAccountConsumptionNumber", 2},
|
||||||
{"当月已用手动扩展视频数", "monthlyManualVideoConsumptionNumber", 2},
|
{"当月已用手动扩展视频数", "monthlyManualVideoConsumptionNumber", 2},
|
||||||
{"当月已用手动扩展图文数", "monthlyManualImageConsumptionNumber", 2},
|
{"当月已用手动扩展图文数", "monthlyManualImageConsumptionNumber", 2},
|
||||||
{"当月已用手动扩展数据数", "monthlyManualDataAnalysisConsumptionNumber", 2},
|
{"当月已用手动扩展数据数", "monthlyManualDataAnalysisConsumptionNumber", 2},
|
||||||
{"当月已用手动扩展竞品数", "monthlyManualCompetitiveConsumptionNumber", 2},
|
|
||||||
}
|
}
|
||||||
jsonMap := []map[string]any{}
|
jsonMap := []map[string]any{}
|
||||||
for _, v := range data {
|
for _, v := range data {
|
||||||
|
|||||||
@ -26,7 +26,3 @@ func MetricsArtistAccountExport(req *bundle.MetricsArtistAccountExportReq) (*bun
|
|||||||
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (*bundle.MetricsVideoSubmitExportResp, error) {
|
func MetricsVideoSubmitExport(req *bundle.MetricsVideoSubmitExportReq) (*bundle.MetricsVideoSubmitExportResp, error) {
|
||||||
return dao.MetricsVideoSubmitExport(req)
|
return dao.MetricsVideoSubmitExport(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExportWorkCastInfo(req *bundle.ExportWorkCastInfoReq) (*bundle.ExportWorkCastInfoResp, error) {
|
|
||||||
return dao.ExportWorkCastInfo(req)
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,617 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"micro-bundle/internal/dao"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
"time"
|
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
|
||||||
|
|
||||||
// attachmentsToJSON 将附件列表(url+fileName)序列化为 JSON 字符串存入 DB
|
|
||||||
func attachmentsToJSON(items []*bundle.AttachmentItem) string {
|
|
||||||
if len(items) == 0 {
|
|
||||||
return "[]"
|
|
||||||
}
|
|
||||||
list := make([]model.AttachmentItem, 0, len(items))
|
|
||||||
for _, it := range items {
|
|
||||||
list = append(list, model.AttachmentItem{URL: it.GetUrl(), FileName: it.GetFileName()})
|
|
||||||
}
|
|
||||||
b, _ := json.Marshal(list)
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// jsonToAttachments 将 DB 中的 JSON 反序列化为附件列表(格式:[{"url":"","fileName":""},...])
|
|
||||||
func jsonToAttachments(s string) []*bundle.AttachmentItem {
|
|
||||||
if s == "" || s == "[]" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var list []model.AttachmentItem
|
|
||||||
_ = json.Unmarshal([]byte(s), &list)
|
|
||||||
out := make([]*bundle.AttachmentItem, 0, len(list))
|
|
||||||
for i := range list {
|
|
||||||
out = append(out, &bundle.AttachmentItem{Url: list[i].URL, FileName: list[i].FileName})
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// validateContractBody 校验合同主体字段(create/update 共用)
|
|
||||||
func validateContractBody(c *bundle.Contract) (string, error) {
|
|
||||||
// 1. 合同名称:必填;最多50个字
|
|
||||||
if c.ContractName == "" {
|
|
||||||
return "合同名称不能为空", errors.New("合同名称不能为空")
|
|
||||||
}
|
|
||||||
if utf8.RuneCountInString(c.ContractName) > 50 {
|
|
||||||
return "合同名称最多50个字", errors.New("合同名称最多50个字")
|
|
||||||
}
|
|
||||||
// 2. 项目名称:必填;最多50个字
|
|
||||||
if c.ProjectName == "" {
|
|
||||||
return "项目名称不能为空", errors.New("项目名称不能为空")
|
|
||||||
}
|
|
||||||
if utf8.RuneCountInString(c.ProjectName) > 50 {
|
|
||||||
return "项目名称最多50个字", errors.New("项目名称最多50个字")
|
|
||||||
}
|
|
||||||
if c.CustomerName == "" {
|
|
||||||
return "客户名称不能为空", errors.New("客户名称不能为空")
|
|
||||||
}
|
|
||||||
if c.ContractorName == "" {
|
|
||||||
return "承办商名称不能为空", errors.New("承办商名称不能为空")
|
|
||||||
}
|
|
||||||
if c.SigningDate == "" {
|
|
||||||
return "签署日期不能为空", errors.New("签署日期不能为空")
|
|
||||||
}
|
|
||||||
if c.EffectiveDate == "" {
|
|
||||||
return "生效日期不能为空", errors.New("生效日期不能为空")
|
|
||||||
}
|
|
||||||
if c.ContractAmount <= 0 {
|
|
||||||
return "合同金额不能为空", errors.New("合同金额不能为空")
|
|
||||||
}
|
|
||||||
if c.ContractCurrencyType == 0 {
|
|
||||||
return "合同货币类型不能为空", errors.New("合同货币类型不能为空")
|
|
||||||
}
|
|
||||||
if c.ContractPaymentCycle == "" {
|
|
||||||
return "支付周期不能为空", errors.New("支付周期不能为空")
|
|
||||||
}
|
|
||||||
if c.DevelopmentCycle == "" {
|
|
||||||
return "开发周期不能为空", errors.New("开发周期不能为空")
|
|
||||||
}
|
|
||||||
if c.MaintenanceCycleType == 0 {
|
|
||||||
return "维护周期类型不能为空", errors.New("维护周期类型不能为空")
|
|
||||||
}
|
|
||||||
if c.MaintenanceFee <= 0 {
|
|
||||||
return "维护费用不能为空", errors.New("维护费用不能为空")
|
|
||||||
}
|
|
||||||
if c.MaintenanceCurrencyType == 0 {
|
|
||||||
return "维护货币类型不能为空", errors.New("维护货币类型不能为空")
|
|
||||||
}
|
|
||||||
if c.QualityAssuranceFee <= 0 {
|
|
||||||
return "质量保证金额不能为空", errors.New("质量保证金额不能为空")
|
|
||||||
}
|
|
||||||
if c.QualityAssuranceCurrencyType == 0 {
|
|
||||||
return "质量保证金货币类型不能为空", errors.New("质量保证金货币类型不能为空")
|
|
||||||
}
|
|
||||||
if len(c.ContractAttachments) > 5 {
|
|
||||||
return "合同附件不能超过5个", errors.New("合同附件不能超过5个")
|
|
||||||
}
|
|
||||||
if len(c.OtherAttachments) > 5 {
|
|
||||||
return "其他附件不能超过5个", errors.New("其他附件不能超过5个")
|
|
||||||
}
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// validateCyclePeriods 验证周期期数是否从1开始连续递增
|
|
||||||
func validateCyclePeriods(periods []int32, cycleName string) (string, error) {
|
|
||||||
if len(periods) > 10 {
|
|
||||||
msg := cycleName + "不能超过10期"
|
|
||||||
return msg, errors.New(msg)
|
|
||||||
}
|
|
||||||
if len(periods) == 0 {
|
|
||||||
msg := cycleName + "至少有1期"
|
|
||||||
return msg, errors.New(msg)
|
|
||||||
}
|
|
||||||
periodSet := make(map[int32]bool)
|
|
||||||
for _, p := range periods {
|
|
||||||
periodSet[p] = true
|
|
||||||
}
|
|
||||||
count := int32(len(periods))
|
|
||||||
for i := int32(1); i <= count; i++ {
|
|
||||||
if !periodSet[i] {
|
|
||||||
msg := cycleName + "不是递增"
|
|
||||||
return msg, errors.New(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// convertPaymentCycles 转换支付周期子表
|
|
||||||
// isUpdate: true 时保留前端传入的 UUID,false 时生成新 UUID
|
|
||||||
func convertPaymentCycles(cycles []*bundle.ContractPaymentCycle, contractUUID string, isUpdate bool) ([]model.ContractPaymentCycle, string, error) {
|
|
||||||
if len(cycles) == 0 {
|
|
||||||
return nil, "", nil
|
|
||||||
}
|
|
||||||
result := make([]model.ContractPaymentCycle, 0, len(cycles))
|
|
||||||
for _, pc := range cycles {
|
|
||||||
// 交付时间点:最多200个字
|
|
||||||
if utf8.RuneCountInString(pc.DeliveryTime) > 200 {
|
|
||||||
return nil, "交付时间点最多200个字", errors.New("交付时间点最多200个字")
|
|
||||||
}
|
|
||||||
cycleUUID := uuid.New().String()
|
|
||||||
if isUpdate && pc.ContractPaymentCycleUUID != "" {
|
|
||||||
cycleUUID = pc.ContractPaymentCycleUUID
|
|
||||||
}
|
|
||||||
result = append(result, model.ContractPaymentCycle{
|
|
||||||
ContractPaymentCycleUUID: cycleUUID,
|
|
||||||
ContractUUID: contractUUID,
|
|
||||||
PaymentCyclePeriod: int(pc.PaymentCyclePeriod),
|
|
||||||
DeliveryTime: pc.DeliveryTime,
|
|
||||||
ContractPaymentCycleAmount: pc.ContractPaymentCycleAmount,
|
|
||||||
PaymentCycleCurrencyType: int(pc.PaymentCycleCurrencyType),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result, "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// convertDevelopmentCycles 转换开发周期子表
|
|
||||||
// isUpdate: true 时保留前端传入的 UUID,false 时生成新 UUID
|
|
||||||
func convertDevelopmentCycles(cycles []*bundle.DevelopmentCycle, contractUUID string, isUpdate bool) ([]model.DevelopmentCycle, string, error) {
|
|
||||||
if len(cycles) == 0 {
|
|
||||||
return nil, "", nil
|
|
||||||
}
|
|
||||||
result := make([]model.DevelopmentCycle, 0, len(cycles))
|
|
||||||
for _, dc := range cycles {
|
|
||||||
if len(dc.Attachments) > 5 {
|
|
||||||
return nil, "附件URLs不能超过5个", errors.New("附件URLs不能超过5个")
|
|
||||||
}
|
|
||||||
// 开发时间:最多50个字
|
|
||||||
if utf8.RuneCountInString(dc.DevelopmentTime) > 50 {
|
|
||||||
return nil, "开发时间最多50个字", errors.New("开发时间最多50个字")
|
|
||||||
}
|
|
||||||
// 交付内容:最多200个字
|
|
||||||
if utf8.RuneCountInString(dc.DeliveryContent) > 200 {
|
|
||||||
return nil, "交付内容最多200个字", errors.New("交付内容最多200个字")
|
|
||||||
}
|
|
||||||
cycleUUID := uuid.New().String()
|
|
||||||
if isUpdate && dc.DevelopmentCycleUUID != "" {
|
|
||||||
cycleUUID = dc.DevelopmentCycleUUID
|
|
||||||
}
|
|
||||||
result = append(result, model.DevelopmentCycle{
|
|
||||||
DevelopmentCycleUUID: cycleUUID,
|
|
||||||
ContractUUID: contractUUID,
|
|
||||||
DevelopmentPeriod: int(dc.DevelopmentPeriod),
|
|
||||||
DevelopmentTime: dc.DevelopmentTime,
|
|
||||||
AttachmentURLs: attachmentsToJSON(dc.Attachments),
|
|
||||||
DeliveryContent: dc.DeliveryContent,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result, "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateContract 合同更新接口(根据action判断新增/更新/删除)
|
|
||||||
func UpdateContract(req *bundle.ContractUpdateRequest) (res *bundle.ComResponse, err error) {
|
|
||||||
res = new(bundle.ComResponse)
|
|
||||||
|
|
||||||
if req.Contract == nil {
|
|
||||||
res.Msg = "合同信息不能为空"
|
|
||||||
return res, errors.New("合同信息不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch req.Action {
|
|
||||||
case "create": // 新增
|
|
||||||
if msg, e := validateContractBody(req.Contract); e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建model对象
|
|
||||||
contract := &model.Contract{
|
|
||||||
ContractUUID: req.Contract.ContractUUID,
|
|
||||||
ContractName: req.Contract.ContractName,
|
|
||||||
ProjectName: req.Contract.ProjectName,
|
|
||||||
CustomerName: req.Contract.CustomerName,
|
|
||||||
ContractorName: req.Contract.ContractorName,
|
|
||||||
SigningDate: req.Contract.SigningDate,
|
|
||||||
EffectiveDate: req.Contract.EffectiveDate,
|
|
||||||
ContractAmount: req.Contract.ContractAmount,
|
|
||||||
ContractCurrencyType: int(req.Contract.ContractCurrencyType),
|
|
||||||
ContractPaymentCycle: req.Contract.ContractPaymentCycle,
|
|
||||||
DevelopmentCycle: req.Contract.DevelopmentCycle,
|
|
||||||
MaintenanceCycleType: int(req.Contract.MaintenanceCycleType),
|
|
||||||
MaintenanceFee: req.Contract.MaintenanceFee,
|
|
||||||
MaintenanceCurrencyType: int(req.Contract.MaintenanceCurrencyType),
|
|
||||||
QualityAssuranceFee: req.Contract.QualityAssuranceFee,
|
|
||||||
QualityAssuranceCurrencyType: int(req.Contract.QualityAssuranceCurrencyType),
|
|
||||||
ContractAttachmentURLs: attachmentsToJSON(req.Contract.ContractAttachments),
|
|
||||||
OtherAttachmentURLs: attachmentsToJSON(req.Contract.OtherAttachments),
|
|
||||||
Operator: req.Contract.Operator,
|
|
||||||
OperatorID: req.Contract.OperatorID,
|
|
||||||
OperatorNum: req.Contract.OperatorNum,
|
|
||||||
}
|
|
||||||
contract.OperatorTime = time.Now()
|
|
||||||
|
|
||||||
// 支付周期:前端传 -1 表示不保存该条,过滤掉
|
|
||||||
paymentCyclesFiltered := make([]*bundle.ContractPaymentCycle, 0, len(req.Contract.PaymentCycles))
|
|
||||||
for _, pc := range req.Contract.PaymentCycles {
|
|
||||||
if pc.PaymentCyclePeriod != -1 {
|
|
||||||
paymentCyclesFiltered = append(paymentCyclesFiltered, pc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 验证并转换支付周期子表
|
|
||||||
paymentPeriods := make([]int32, 0, len(paymentCyclesFiltered))
|
|
||||||
for _, pc := range paymentCyclesFiltered {
|
|
||||||
paymentPeriods = append(paymentPeriods, pc.PaymentCyclePeriod)
|
|
||||||
}
|
|
||||||
if msg, e := validateCyclePeriods(paymentPeriods, "支付周期"); e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
paymentCycles, msg, e := convertPaymentCycles(paymentCyclesFiltered, contract.ContractUUID, false)
|
|
||||||
if e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
contract.PaymentCycles = paymentCycles
|
|
||||||
|
|
||||||
// 开发周期:前端传 -1 表示不保存该条,过滤掉
|
|
||||||
devCyclesFiltered := make([]*bundle.DevelopmentCycle, 0, len(req.Contract.DevelopmentCycles))
|
|
||||||
for _, dc := range req.Contract.DevelopmentCycles {
|
|
||||||
if dc.DevelopmentPeriod != -1 {
|
|
||||||
devCyclesFiltered = append(devCyclesFiltered, dc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 验证并转换开发周期子表
|
|
||||||
devPeriods := make([]int32, 0, len(devCyclesFiltered))
|
|
||||||
for _, dc := range devCyclesFiltered {
|
|
||||||
devPeriods = append(devPeriods, dc.DevelopmentPeriod)
|
|
||||||
}
|
|
||||||
if msg, e := validateCyclePeriods(devPeriods, "开发周期"); e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
devCycles, msg, e := convertDevelopmentCycles(devCyclesFiltered, contract.ContractUUID, false)
|
|
||||||
if e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
contract.DevelopmentCycles = devCycles
|
|
||||||
|
|
||||||
// 调用dao层创建
|
|
||||||
err = dao.CreateContract(contract)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "创建失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Msg = "创建成功"
|
|
||||||
|
|
||||||
case "update": // 更新
|
|
||||||
// 参数校验
|
|
||||||
if req.Contract.ContractUUID == "" {
|
|
||||||
res.Msg = "合同UUID不能为空"
|
|
||||||
return res, errors.New("合同UUID不能为空")
|
|
||||||
}
|
|
||||||
if msg, e := validateContractBody(req.Contract); e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建model对象
|
|
||||||
contract := &model.Contract{
|
|
||||||
ContractName: req.Contract.ContractName,
|
|
||||||
ProjectName: req.Contract.ProjectName,
|
|
||||||
CustomerName: req.Contract.CustomerName,
|
|
||||||
ContractorName: req.Contract.ContractorName,
|
|
||||||
SigningDate: req.Contract.SigningDate,
|
|
||||||
EffectiveDate: req.Contract.EffectiveDate,
|
|
||||||
ContractAmount: req.Contract.ContractAmount,
|
|
||||||
ContractCurrencyType: int(req.Contract.ContractCurrencyType),
|
|
||||||
ContractPaymentCycle: req.Contract.ContractPaymentCycle,
|
|
||||||
DevelopmentCycle: req.Contract.DevelopmentCycle,
|
|
||||||
MaintenanceCycleType: int(req.Contract.MaintenanceCycleType),
|
|
||||||
MaintenanceFee: req.Contract.MaintenanceFee,
|
|
||||||
MaintenanceCurrencyType: int(req.Contract.MaintenanceCurrencyType),
|
|
||||||
QualityAssuranceFee: req.Contract.QualityAssuranceFee,
|
|
||||||
QualityAssuranceCurrencyType: int(req.Contract.QualityAssuranceCurrencyType),
|
|
||||||
ContractAttachmentURLs: attachmentsToJSON(req.Contract.ContractAttachments),
|
|
||||||
OtherAttachmentURLs: attachmentsToJSON(req.Contract.OtherAttachments),
|
|
||||||
Operator: req.Contract.Operator,
|
|
||||||
OperatorID: req.Contract.OperatorID,
|
|
||||||
OperatorNum: req.Contract.OperatorNum,
|
|
||||||
}
|
|
||||||
contract.OperatorTime = time.Now()
|
|
||||||
|
|
||||||
// 支付周期:前端传 -1 表示不保存该条,过滤掉
|
|
||||||
paymentCyclesFiltered := make([]*bundle.ContractPaymentCycle, 0, len(req.Contract.PaymentCycles))
|
|
||||||
for _, pc := range req.Contract.PaymentCycles {
|
|
||||||
if pc.PaymentCyclePeriod != -1 {
|
|
||||||
paymentCyclesFiltered = append(paymentCyclesFiltered, pc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 验证并转换支付周期子表
|
|
||||||
paymentPeriods := make([]int32, 0, len(paymentCyclesFiltered))
|
|
||||||
for _, pc := range paymentCyclesFiltered {
|
|
||||||
paymentPeriods = append(paymentPeriods, pc.PaymentCyclePeriod)
|
|
||||||
}
|
|
||||||
if msg, e := validateCyclePeriods(paymentPeriods, "支付周期"); e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
paymentCycles, msg, e := convertPaymentCycles(paymentCyclesFiltered, req.Contract.ContractUUID, true)
|
|
||||||
if e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
contract.PaymentCycles = paymentCycles
|
|
||||||
|
|
||||||
// 开发周期:前端传 -1 表示不保存该条,过滤掉
|
|
||||||
devCyclesFiltered := make([]*bundle.DevelopmentCycle, 0, len(req.Contract.DevelopmentCycles))
|
|
||||||
for _, dc := range req.Contract.DevelopmentCycles {
|
|
||||||
if dc.DevelopmentPeriod != -1 {
|
|
||||||
devCyclesFiltered = append(devCyclesFiltered, dc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 验证并转换开发周期子表
|
|
||||||
devPeriods := make([]int32, 0, len(devCyclesFiltered))
|
|
||||||
for _, dc := range devCyclesFiltered {
|
|
||||||
devPeriods = append(devPeriods, dc.DevelopmentPeriod)
|
|
||||||
}
|
|
||||||
if msg, e := validateCyclePeriods(devPeriods, "开发周期"); e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
devCycles, msg, e := convertDevelopmentCycles(devCyclesFiltered, req.Contract.ContractUUID, true)
|
|
||||||
if e != nil {
|
|
||||||
res.Msg = msg
|
|
||||||
return res, e
|
|
||||||
}
|
|
||||||
contract.DevelopmentCycles = devCycles
|
|
||||||
|
|
||||||
// 调用dao层更新
|
|
||||||
err = dao.UpdateContract(req.Contract.ContractUUID, contract)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "更新失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Msg = "更新成功"
|
|
||||||
|
|
||||||
case "delete": // 删除
|
|
||||||
// 参数校验
|
|
||||||
if req.Contract.ContractUUID == "" {
|
|
||||||
res.Msg = "合同UUID不能为空"
|
|
||||||
return res, errors.New("合同UUID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层删除
|
|
||||||
err = dao.DeleteContract(req.Contract.ContractUUID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "删除失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Msg = "删除成功"
|
|
||||||
|
|
||||||
default:
|
|
||||||
res.Msg = "未知操作"
|
|
||||||
return res, errors.New("未知操作")
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetContractList 查询合同列表
|
|
||||||
func GetContractList(req *bundle.ContractListRequest) (res *bundle.ContractListResponse, err error) {
|
|
||||||
res = new(bundle.ContractListResponse)
|
|
||||||
|
|
||||||
// 构建dao层查询请求
|
|
||||||
daoReq := &dao.ContractQueryRequest{
|
|
||||||
ContractName: req.ContractName,
|
|
||||||
ProjectName: req.ProjectName,
|
|
||||||
CustomerName: req.CustomerName,
|
|
||||||
Page: int(req.Page),
|
|
||||||
PageSize: int(req.PageSize),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层查询
|
|
||||||
contracts, total, err := dao.GetContractList(daoReq)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换model到proto响应
|
|
||||||
contractInfoList := make([]*bundle.ContractInfo, 0, len(contracts))
|
|
||||||
for _, contract := range contracts {
|
|
||||||
contractInfo := &bundle.ContractInfo{
|
|
||||||
ContractUUID: contract.ContractUUID,
|
|
||||||
ContractName: contract.ContractName,
|
|
||||||
ProjectName: contract.ProjectName,
|
|
||||||
CustomerName: contract.CustomerName,
|
|
||||||
ContractorName: contract.ContractorName,
|
|
||||||
SigningDate: contract.SigningDate,
|
|
||||||
EffectiveDate: contract.EffectiveDate,
|
|
||||||
ContractAmount: contract.ContractAmount,
|
|
||||||
ContractCurrencyType: int32(contract.ContractCurrencyType),
|
|
||||||
ContractPaymentCycle: contract.ContractPaymentCycle,
|
|
||||||
DevelopmentCycle: contract.DevelopmentCycle,
|
|
||||||
QualityAssuranceFee: contract.QualityAssuranceFee,
|
|
||||||
QualityAssuranceCurrencyType: int32(contract.QualityAssuranceCurrencyType),
|
|
||||||
MaintenanceCycleType: int32(contract.MaintenanceCycleType),
|
|
||||||
MaintenanceFee: contract.MaintenanceFee,
|
|
||||||
MaintenanceCurrencyType: int32(contract.MaintenanceCurrencyType),
|
|
||||||
ContractAttachments: jsonToAttachments(contract.ContractAttachmentURLs),
|
|
||||||
OtherAttachments: jsonToAttachments(contract.OtherAttachmentURLs),
|
|
||||||
Operator: contract.Operator,
|
|
||||||
}
|
|
||||||
// 格式化操作时间
|
|
||||||
if !contract.OperatorTime.IsZero() {
|
|
||||||
contractInfo.OperatorTime = contract.OperatorTime.Format("2006-01-02 15:04")
|
|
||||||
}
|
|
||||||
contractInfoList = append(contractInfoList, contractInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.List = contractInfoList
|
|
||||||
res.Total = total
|
|
||||||
res.Page = req.Page
|
|
||||||
res.PageSize = req.PageSize
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetContractDetail 根据合同UUID查询详情
|
|
||||||
func GetContractDetail(req *bundle.ContractDetailRequest) (res *bundle.ContractDetailResponse, err error) {
|
|
||||||
res = new(bundle.ContractDetailResponse)
|
|
||||||
|
|
||||||
// 参数校验
|
|
||||||
if req.ContractUUID == "" {
|
|
||||||
res.Msg = "合同UUID不能为空"
|
|
||||||
return res, errors.New("合同UUID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层查询
|
|
||||||
contract, err := dao.GetContractByUUID(req.ContractUUID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "查询合同信息失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果合同不存在
|
|
||||||
if contract == nil {
|
|
||||||
res.Msg = "合同不存在"
|
|
||||||
return res, errors.New("合同不存在")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换model到proto响应
|
|
||||||
contractProto := &bundle.Contract{
|
|
||||||
ContractUUID: contract.ContractUUID,
|
|
||||||
ContractName: contract.ContractName,
|
|
||||||
ProjectName: contract.ProjectName,
|
|
||||||
CustomerName: contract.CustomerName,
|
|
||||||
ContractorName: contract.ContractorName,
|
|
||||||
SigningDate: contract.SigningDate,
|
|
||||||
EffectiveDate: contract.EffectiveDate,
|
|
||||||
ContractAmount: contract.ContractAmount,
|
|
||||||
ContractCurrencyType: int32(contract.ContractCurrencyType),
|
|
||||||
ContractPaymentCycle: contract.ContractPaymentCycle,
|
|
||||||
DevelopmentCycle: contract.DevelopmentCycle,
|
|
||||||
MaintenanceCycleType: int64(contract.MaintenanceCycleType),
|
|
||||||
MaintenanceFee: contract.MaintenanceFee,
|
|
||||||
MaintenanceCurrencyType: int32(contract.MaintenanceCurrencyType),
|
|
||||||
QualityAssuranceFee: contract.QualityAssuranceFee,
|
|
||||||
QualityAssuranceCurrencyType: int32(contract.QualityAssuranceCurrencyType),
|
|
||||||
ContractAttachments: jsonToAttachments(contract.ContractAttachmentURLs),
|
|
||||||
OtherAttachments: jsonToAttachments(contract.OtherAttachmentURLs),
|
|
||||||
Operator: contract.Operator,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化操作时间
|
|
||||||
if !contract.OperatorTime.IsZero() {
|
|
||||||
contractProto.OperatorTime = contract.OperatorTime.Format("2006-01-02 15:04")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换支付周期子表
|
|
||||||
if len(contract.PaymentCycles) > 0 {
|
|
||||||
contractProto.PaymentCycles = make([]*bundle.ContractPaymentCycle, 0, len(contract.PaymentCycles))
|
|
||||||
for _, pc := range contract.PaymentCycles {
|
|
||||||
contractProto.PaymentCycles = append(contractProto.PaymentCycles, &bundle.ContractPaymentCycle{
|
|
||||||
ContractPaymentCycleUUID: pc.ContractPaymentCycleUUID,
|
|
||||||
ContractUUID: pc.ContractUUID,
|
|
||||||
PaymentCyclePeriod: int32(pc.PaymentCyclePeriod),
|
|
||||||
DeliveryTime: pc.DeliveryTime,
|
|
||||||
ContractPaymentCycleAmount: pc.ContractPaymentCycleAmount,
|
|
||||||
PaymentCycleCurrencyType: int32(pc.PaymentCycleCurrencyType),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换开发周期子表
|
|
||||||
if len(contract.DevelopmentCycles) > 0 {
|
|
||||||
contractProto.DevelopmentCycles = make([]*bundle.DevelopmentCycle, 0, len(contract.DevelopmentCycles))
|
|
||||||
for _, dc := range contract.DevelopmentCycles {
|
|
||||||
contractProto.DevelopmentCycles = append(contractProto.DevelopmentCycles, &bundle.DevelopmentCycle{
|
|
||||||
DevelopmentCycleUUID: dc.DevelopmentCycleUUID,
|
|
||||||
ContractUUID: dc.ContractUUID,
|
|
||||||
DevelopmentPeriod: int32(dc.DevelopmentPeriod),
|
|
||||||
DevelopmentTime: dc.DevelopmentTime,
|
|
||||||
Attachments: jsonToAttachments(dc.AttachmentURLs),
|
|
||||||
DeliveryContent: dc.DeliveryContent,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Contract = contractProto
|
|
||||||
res.Msg = "查询成功"
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDevelopmentCyclesByContractUUID 根据合同UUID查询开发周期
|
|
||||||
func GetDevelopmentCyclesByContractUUID(req *bundle.GetDevelopmentCyclesByContractUUIDRequest) (res *bundle.GetDevelopmentCyclesByContractUUIDResponse, err error) {
|
|
||||||
res = new(bundle.GetDevelopmentCyclesByContractUUIDResponse)
|
|
||||||
|
|
||||||
// 参数校验
|
|
||||||
if req.ContractUUID == "" {
|
|
||||||
res.Msg = "合同UUID不能为空"
|
|
||||||
return res, errors.New("合同UUID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层查询
|
|
||||||
developmentCycles, err := dao.GetDevelopmentCyclesByContractUUID(req.ContractUUID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "查询开发周期失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换model到proto响应
|
|
||||||
developmentCycleList := make([]*bundle.DevelopmentCycle, 0, len(developmentCycles))
|
|
||||||
for _, dc := range developmentCycles {
|
|
||||||
developmentCycleList = append(developmentCycleList, &bundle.DevelopmentCycle{
|
|
||||||
DevelopmentCycleUUID: dc.DevelopmentCycleUUID,
|
|
||||||
ContractUUID: dc.ContractUUID,
|
|
||||||
DevelopmentPeriod: int32(dc.DevelopmentPeriod),
|
|
||||||
DevelopmentTime: dc.DevelopmentTime,
|
|
||||||
Attachments: jsonToAttachments(dc.AttachmentURLs),
|
|
||||||
DeliveryContent: dc.DeliveryContent,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
res.List = developmentCycleList
|
|
||||||
res.Msg = "查询成功"
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPaymentCyclesByContractUUID 根据合同UUID查询支付周期
|
|
||||||
func GetPaymentCyclesByContractUUID(req *bundle.GetPaymentCyclesByContractUUIDRequest) (res *bundle.GetPaymentCyclesByContractUUIDResponse, err error) {
|
|
||||||
res = new(bundle.GetPaymentCyclesByContractUUIDResponse)
|
|
||||||
|
|
||||||
// 参数校验
|
|
||||||
if req.ContractUUID == "" {
|
|
||||||
res.Msg = "合同UUID不能为空"
|
|
||||||
return res, errors.New("合同UUID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层查询
|
|
||||||
paymentCycles, err := dao.GetPaymentCyclesByContractUUID(req.ContractUUID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "查询支付周期失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换model到proto响应
|
|
||||||
paymentCycleList := make([]*bundle.ContractPaymentCycle, 0, len(paymentCycles))
|
|
||||||
for _, pc := range paymentCycles {
|
|
||||||
paymentCycleList = append(paymentCycleList, &bundle.ContractPaymentCycle{
|
|
||||||
ContractPaymentCycleUUID: pc.ContractPaymentCycleUUID,
|
|
||||||
ContractUUID: pc.ContractUUID,
|
|
||||||
PaymentCyclePeriod: int32(pc.PaymentCyclePeriod),
|
|
||||||
DeliveryTime: pc.DeliveryTime,
|
|
||||||
ContractPaymentCycleAmount: pc.ContractPaymentCycleAmount,
|
|
||||||
PaymentCycleCurrencyType: int32(pc.PaymentCycleCurrencyType),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
res.List = paymentCycleList
|
|
||||||
res.Msg = "查询成功"
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
@ -1,273 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"micro-bundle/internal/dao"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
"time"
|
|
||||||
"unicode/utf8"
|
|
||||||
)
|
|
||||||
|
|
||||||
// validateCustomerFields 校验客户字段
|
|
||||||
func validateCustomerFields(customer *bundle.Customer) error {
|
|
||||||
// 1. 客户名称:必填;最多50个字
|
|
||||||
if customer.CustomerName == "" {
|
|
||||||
return errors.New("客户名称不能为空")
|
|
||||||
}
|
|
||||||
if utf8.RuneCountInString(customer.CustomerName) > 50 {
|
|
||||||
return errors.New("客户名称最多50个字")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 授权代表:必填;最多50个字
|
|
||||||
if customer.AuthorizedRepresentative == "" {
|
|
||||||
return errors.New("授权代表不能为空")
|
|
||||||
}
|
|
||||||
if utf8.RuneCountInString(customer.AuthorizedRepresentative) > 50 {
|
|
||||||
return errors.New("授权代表最多50个字")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 注册地址:必填;最多200字
|
|
||||||
if customer.RegistrationAddress == "" {
|
|
||||||
return errors.New("注册地址不能为空")
|
|
||||||
}
|
|
||||||
if utf8.RuneCountInString(customer.RegistrationAddress) > 200 {
|
|
||||||
return errors.New("注册地址最多200个字")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. 推荐人:非必填;最多50个字
|
|
||||||
if customer.ReferralPerson != "" && utf8.RuneCountInString(customer.ReferralPerson) > 50 {
|
|
||||||
return errors.New("推荐人最多50个字")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCustomerList 多条件查询客户列表
|
|
||||||
func GetCustomerList(req *bundle.CustomerListRequest) (res *bundle.CustomerListResponse, err error) {
|
|
||||||
res = new(bundle.CustomerListResponse)
|
|
||||||
|
|
||||||
// 构建dao层查询请求
|
|
||||||
daoReq := &dao.CustomerQueryRequest{
|
|
||||||
CustomerName: req.CustomerName,
|
|
||||||
ReferralPerson: req.ReferralPerson,
|
|
||||||
Page: int(req.Page),
|
|
||||||
PageSize: int(req.PageSize),
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层查询
|
|
||||||
customers, total, err := dao.GetCustomerList(daoReq)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换model到proto响应
|
|
||||||
customerInfoList := make([]*bundle.CustomerInfo, 0, len(customers))
|
|
||||||
for _, customer := range customers {
|
|
||||||
customerInfo := &bundle.CustomerInfo{
|
|
||||||
CustomerID: customer.CustomerID,
|
|
||||||
CustomerName: customer.CustomerName,
|
|
||||||
AuthorizedRepresentative: customer.AuthorizedRepresentative,
|
|
||||||
RegistrationAddress: customer.RegistrationAddress,
|
|
||||||
ReferralPerson: customer.ReferralPerson,
|
|
||||||
Operator: customer.Operator,
|
|
||||||
}
|
|
||||||
// 格式化操作时间
|
|
||||||
if !customer.OperatorTime.IsZero() {
|
|
||||||
customerInfo.OperatorTime = customer.OperatorTime.Format("2006-01-02 15:04")
|
|
||||||
}
|
|
||||||
customerInfoList = append(customerInfoList, customerInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
res.List = customerInfoList
|
|
||||||
res.Total = total
|
|
||||||
res.Page = req.Page
|
|
||||||
res.PageSize = req.PageSize
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCustomerDetail 根据客户ID查询客户详情
|
|
||||||
func GetCustomerDetail(req *bundle.CustomerDetailRequest) (res *bundle.CustomerDetailResponse, err error) {
|
|
||||||
res = new(bundle.CustomerDetailResponse)
|
|
||||||
|
|
||||||
// 参数校验
|
|
||||||
if req.CustomerID == "" {
|
|
||||||
res.Msg = "客户ID不能为空"
|
|
||||||
return res, errors.New("客户ID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层查询
|
|
||||||
customer, err := dao.GetCustomerByID(req.CustomerID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "查询客户信息失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果客户不存在
|
|
||||||
if customer == nil {
|
|
||||||
res.Msg = "客户不存在"
|
|
||||||
return res, errors.New("客户不存在")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转换model到proto响应
|
|
||||||
customerProto := &bundle.Customer{
|
|
||||||
CustomerID: customer.CustomerID,
|
|
||||||
CustomerName: customer.CustomerName,
|
|
||||||
AuthorizedRepresentative: customer.AuthorizedRepresentative,
|
|
||||||
RegistrationAddress: customer.RegistrationAddress,
|
|
||||||
ReferralPerson: customer.ReferralPerson,
|
|
||||||
Operator: customer.Operator,
|
|
||||||
OperatorID: customer.OperatorID,
|
|
||||||
OperatorNum: customer.OperatorNum,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化时间字段
|
|
||||||
if !customer.OperatorTime.IsZero() {
|
|
||||||
customerProto.OperatorTime = customer.OperatorTime.Format("2006-01-02 15:04")
|
|
||||||
}
|
|
||||||
if !customer.CreatedAt.IsZero() {
|
|
||||||
customerProto.CreatedAt = customer.CreatedAt.Format("2006-01-02 15:04:05")
|
|
||||||
}
|
|
||||||
if !customer.UpdatedAt.IsZero() {
|
|
||||||
customerProto.UpdatedAt = customer.UpdatedAt.Format("2006-01-02 15:04:05")
|
|
||||||
}
|
|
||||||
|
|
||||||
res.Customer = customerProto
|
|
||||||
res.Msg = "查询成功"
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateCustomer 更新客户接口(根据action判断新增/更新/删除)
|
|
||||||
func UpdateCustomer(req *bundle.CustomerUpdateRequest) (res *bundle.CommonResponse, err error) {
|
|
||||||
res = new(bundle.CommonResponse)
|
|
||||||
|
|
||||||
// 参数校验
|
|
||||||
if req.Customer == nil {
|
|
||||||
res.Msg = "客户信息不能为空"
|
|
||||||
return res, errors.New("客户信息不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据action执行不同操作
|
|
||||||
switch req.Action {
|
|
||||||
case "create": // 新增
|
|
||||||
// 字段校验
|
|
||||||
if err := validateCustomerFields(req.Customer); err != nil {
|
|
||||||
res.Msg = err.Error()
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
// 检查客户名称是否已存在
|
|
||||||
exists, err := dao.CheckCustomerNameExists(req.Customer.CustomerName, "")
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "检查客户名称重复失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if exists {
|
|
||||||
res.Msg = "客户名称重复"
|
|
||||||
return res, errors.New("客户名称重复")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建model对象
|
|
||||||
customer := &model.Customer{
|
|
||||||
CustomerName: req.Customer.CustomerName,
|
|
||||||
AuthorizedRepresentative: req.Customer.AuthorizedRepresentative,
|
|
||||||
RegistrationAddress: req.Customer.RegistrationAddress,
|
|
||||||
ReferralPerson: req.Customer.ReferralPerson,
|
|
||||||
Operator: req.Customer.Operator,
|
|
||||||
OperatorID: req.Customer.OperatorID,
|
|
||||||
OperatorNum: req.Customer.OperatorNum,
|
|
||||||
}
|
|
||||||
customer.OperatorTime = time.Now()
|
|
||||||
|
|
||||||
// 调用dao层创建
|
|
||||||
err = dao.CreateCustomer(customer)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "创建失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Msg = "创建成功"
|
|
||||||
|
|
||||||
case "update": // 更新
|
|
||||||
// 参数校验
|
|
||||||
if req.Customer.CustomerID == "" {
|
|
||||||
res.Msg = "ID不能为空"
|
|
||||||
return res, errors.New("ID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 字段校验
|
|
||||||
if err := validateCustomerFields(req.Customer); err != nil {
|
|
||||||
res.Msg = err.Error()
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查客户名称是否重复
|
|
||||||
exists, err := dao.CheckCustomerNameExists(req.Customer.CustomerName, req.Customer.CustomerID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "检查客户名称重复失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
if exists {
|
|
||||||
res.Msg = "客户名称重复"
|
|
||||||
return res, errors.New("客户名称重复")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 构建model对象
|
|
||||||
customer := &model.Customer{
|
|
||||||
CustomerName: req.Customer.CustomerName,
|
|
||||||
AuthorizedRepresentative: req.Customer.AuthorizedRepresentative,
|
|
||||||
RegistrationAddress: req.Customer.RegistrationAddress,
|
|
||||||
ReferralPerson: req.Customer.ReferralPerson,
|
|
||||||
Operator: req.Customer.Operator,
|
|
||||||
OperatorID: req.Customer.OperatorID,
|
|
||||||
OperatorNum: req.Customer.OperatorNum,
|
|
||||||
}
|
|
||||||
customer.OperatorTime = time.Now()
|
|
||||||
customer.UpdatedAt = time.Now()
|
|
||||||
// 调用dao层更新
|
|
||||||
err = dao.UpdateCustomer(req.Customer.CustomerID, customer)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "更新失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Msg = "更新成功"
|
|
||||||
|
|
||||||
case "delete": // 删除
|
|
||||||
// 参数校验
|
|
||||||
if req.Customer.CustomerID == "" {
|
|
||||||
res.Msg = "客户ID不能为空"
|
|
||||||
return res, errors.New("客户ID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用dao层删除
|
|
||||||
err = dao.DeleteCustomer(req.Customer.CustomerID)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "删除失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
res.Msg = "删除成功"
|
|
||||||
|
|
||||||
default:
|
|
||||||
res.Msg = "未知操作"
|
|
||||||
return res, errors.New("未知操作")
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetReferralPersonList 查询所有不重复的推荐人列表
|
|
||||||
func GetReferralPersonList(req *bundle.ReferralPersonListRequest) (res *bundle.ReferralPersonListResponse, err error) {
|
|
||||||
res = new(bundle.ReferralPersonListResponse)
|
|
||||||
|
|
||||||
// 调用dao层查询不重复的推荐人
|
|
||||||
referralPersons, err := dao.GetDistinctReferralPersons(req.Keyword)
|
|
||||||
if err != nil {
|
|
||||||
res.Msg = "查询失败"
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
res.List = referralPersons
|
|
||||||
res.Msg = "查询成功"
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
@ -1,129 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"micro-bundle/internal/dao"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CreateInvoice(req *bundle.CreateInvoiceReq) (*bundle.CreateInvoiceResp, error) {
|
|
||||||
res, err := dao.CreateInvoice(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreatePaperInvoiceAddress(req *bundle.CreatePaperInvoiceAddressReq) (*bundle.CreatePaperInvoiceAddressResp, error) {
|
|
||||||
res, err := dao.CreatePaperInvoiceAddress(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInvoiceList(req *bundle.GetInvoiceListReq) (*bundle.GetInvoiceListResp, error) {
|
|
||||||
res := new(bundle.GetInvoiceListResp)
|
|
||||||
data, total, err := dao.GetInvoiceList(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res.Total = total
|
|
||||||
res.Size = req.Size
|
|
||||||
res.Page = req.Page
|
|
||||||
res.Data = lo.Map(data, func(m *model.InvoiceInfo, _ int) *bundle.InvoiceInfo {
|
|
||||||
return &bundle.InvoiceInfo{
|
|
||||||
Name: m.Name,
|
|
||||||
Phone: m.TelAreaCode + m.Phone,
|
|
||||||
Country: m.Country,
|
|
||||||
Address: m.Address,
|
|
||||||
ApplyTime: m.ApplyTime,
|
|
||||||
UserName: m.UserName,
|
|
||||||
UserNum: m.UserNum,
|
|
||||||
OrderNo: m.OrderNo,
|
|
||||||
InvoiceNo: m.InvoiceNo,
|
|
||||||
InvoiceUrl: m.InvoiceUrl,
|
|
||||||
PaperInvocieStatus: m.PaperInvocieStatus,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateInvoiceExpressInfo(req *bundle.UpdateInvoiceExpressInfoReq) (*bundle.UpdateInvoiceExpressInfoResp, error) {
|
|
||||||
res, err := dao.UpdateInvoiceExpressInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInvoiceExpressInfo(req *bundle.GetInvoiceExpressInfoReq) (*bundle.GetInvoiceExpressInfoResp, error) {
|
|
||||||
res, err := dao.GetInvoiceExpressInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetOrderInfoByOrderNo(req *bundle.GetOrderInfoByOrderNoReq) (*bundle.GetOrderInfoByOrderNoResp, error) {
|
|
||||||
res := new(bundle.GetOrderInfoByOrderNoResp)
|
|
||||||
orderRecord, err := dao.GetOrderInfoByOrderNo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res = &bundle.GetOrderInfoByOrderNoResp{
|
|
||||||
UserName: orderRecord.UserName,
|
|
||||||
UserId: strconv.FormatInt(orderRecord.UserId, 10),
|
|
||||||
UserNum: orderRecord.UserNum,
|
|
||||||
OrderNo: orderRecord.OrderNo,
|
|
||||||
TotalAmount: strconv.FormatFloat(float64(orderRecord.TotalAmount), 'f', 2, 64),
|
|
||||||
BundleName: orderRecord.BundleName,
|
|
||||||
AmountType: orderRecord.AmountType,
|
|
||||||
Address: orderRecord.Address,
|
|
||||||
Phone: orderRecord.Phone,
|
|
||||||
PayTime: orderRecord.PayTime,
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetInvoiceInfoByOrderNo(req *bundle.GetInvoiceInfoByOrderNoReq) (*bundle.GetInvoiceInfoByOrderNoResp, error) {
|
|
||||||
res := new(bundle.GetInvoiceInfoByOrderNoResp)
|
|
||||||
data, err := dao.GetInvoiceInfoByOrderNo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res.Data = lo.Map(data, func(m *model.InvoiceInfoByOrderNo, _ int) *bundle.InvoiceInfoByOrderNo {
|
|
||||||
return &bundle.InvoiceInfoByOrderNo{
|
|
||||||
OrderNo: m.OrderNo,
|
|
||||||
InvoiceNo: m.InvoiceNo,
|
|
||||||
InvoiceUrl: m.InvoiceUrl,
|
|
||||||
BundleName: m.BundleName,
|
|
||||||
AmountType: m.AmountType,
|
|
||||||
TotalAmount: strconv.FormatFloat(float64(m.TotalAmount), 'f', -1, 64),
|
|
||||||
PayTime: m.PayTime,
|
|
||||||
PaperInvocieStatus: m.PaperInvocieStatus,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetLastInvoiceNo(req *bundle.GetLastInvoiceNoReq) (*bundle.GetLastInvoiceNoResp, error) {
|
|
||||||
res := new(bundle.GetLastInvoiceNoResp)
|
|
||||||
lastNo, err := dao.GetLastInvoiceNo()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
res.LastNo = lastNo.InvoiceNo
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdataInvoiceInfo(req *bundle.UpdataInvoiceInfoReq) (*bundle.UpdataInvoiceInfoResp, error) {
|
|
||||||
res, err := dao.UpdataInvoiceInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
@ -1,28 +1,18 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
uuid "github.com/satori/go.uuid"
|
|
||||||
"micro-bundle/internal/dao"
|
"micro-bundle/internal/dao"
|
||||||
"micro-bundle/internal/model"
|
"micro-bundle/internal/model"
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
"micro-bundle/pkg/app"
|
"micro-bundle/pkg/app"
|
||||||
"micro-bundle/pkg/utils"
|
"micro-bundle/pkg/utils"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateOrderRecord(req *bundle.OrderCreateRecord) (res *bundle.CommonResponse, err error) {
|
func CreateOrderRecord(req *bundle.OrderCreateRecord) (res *bundle.CommonResponse, err error) {
|
||||||
res = new(bundle.CommonResponse)
|
res = new(bundle.CommonResponse)
|
||||||
//orderUUID := app.ModuleClients.SfNode.Generate().Base64()
|
orderUUID := app.ModuleClients.SfNode.Generate().Base64()
|
||||||
uuidV4, err := uuid.NewV4()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("生成错误", err)
|
|
||||||
return nil, errors.New("生成uuid失败")
|
|
||||||
}
|
|
||||||
orderUUID := uuidV4.String()
|
|
||||||
orderNo := utils.GetOrderNo()
|
orderNo := utils.GetOrderNo()
|
||||||
if req.OrderNo != "" {
|
if req.OrderNo != "" {
|
||||||
orderNo = req.OrderNo
|
orderNo = req.OrderNo
|
||||||
@ -79,9 +69,6 @@ func CreateOrderRecord(req *bundle.OrderCreateRecord) (res *bundle.CommonRespons
|
|||||||
Language: req.Language,
|
Language: req.Language,
|
||||||
BundleOrderValueAdd: addRecords,
|
BundleOrderValueAdd: addRecords,
|
||||||
PlatformIds: req.PlatformIds,
|
PlatformIds: req.PlatformIds,
|
||||||
InviterID: req.InviterId,
|
|
||||||
PurchaseType: req.PurchaseType,
|
|
||||||
RenewalOrderUUID: req.RenewalOrderUUID,
|
|
||||||
}
|
}
|
||||||
res, err = dao.CreateOrderRecord(orderRecord)
|
res, err = dao.CreateOrderRecord(orderRecord)
|
||||||
return
|
return
|
||||||
@ -103,8 +90,6 @@ func UpdateOrderRecordByOrderNo(req *bundle.OrderRecord) (res *bundle.CommonResp
|
|||||||
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
||||||
orderRecord.UUID = req.Uuid
|
orderRecord.UUID = req.Uuid
|
||||||
orderRecord.BundleUUID = req.BundleUuid
|
orderRecord.BundleUUID = req.BundleUuid
|
||||||
orderRecord.Status = req.Status
|
|
||||||
fmt.Println("UpdateOrderRecordByOrderNo Status:", req.Status)
|
|
||||||
res, err = dao.UpdateOrderRecordByOrderNO(orderRecord)
|
res, err = dao.UpdateOrderRecordByOrderNO(orderRecord)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -124,18 +109,6 @@ func OrderRecordsDetail(req *bundle.OrderRecordsDetailRequest) (res *bundle.Orde
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func GetInEffectOrderRecord(req *bundle.GetInEffectOrderRecordRequest) (res *bundle.OrderRecord, err error) {
|
|
||||||
res = new(bundle.OrderRecord)
|
|
||||||
orderReq := &bundle.OrderRecordsDetailRequest{
|
|
||||||
CustomerID: strconv.FormatUint(req.UserID, 10),
|
|
||||||
Status: 2,
|
|
||||||
}
|
|
||||||
res, err = dao.OrderRecordDetail(orderReq)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("未找到有效订单")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateFinancialConfirmationStatus(req *bundle.FinancialConfirmationRequest) (res *bundle.CommonResponse, err error) {
|
func UpdateFinancialConfirmationStatus(req *bundle.FinancialConfirmationRequest) (res *bundle.CommonResponse, err error) {
|
||||||
res = new(bundle.CommonResponse)
|
res = new(bundle.CommonResponse)
|
||||||
@ -215,20 +188,3 @@ func ReSignTheContract(req *bundle.ReSignTheContractRequest) (res *bundle.Common
|
|||||||
res, err = dao.ReSignTheContract(req)
|
res, err = dao.ReSignTheContract(req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateOrderRecordByOrderUuid(req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
|
||||||
res = new(bundle.CommonResponse)
|
|
||||||
orderRecord := new(model.BundleOrderRecords)
|
|
||||||
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
|
|
||||||
orderRecord.UUID = req.Uuid
|
|
||||||
orderRecord.BundleUUID = req.BundleUuid
|
|
||||||
orderRecord.Status = req.Status
|
|
||||||
fmt.Println("UpdateOrderRecordByOrderUuid Status:", req.Status)
|
|
||||||
res, err = dao.UpdateOrderRecordByOrderUuid(orderRecord)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
func OrderListByOrderUuid(req *bundle.OrderInfoByOrderUuidRequest) (res *bundle.OrderInfoByOrderNoResp, err error) {
|
|
||||||
res = new(bundle.OrderInfoByOrderNoResp)
|
|
||||||
res, err = dao.OrderListByOrderUuid(req)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,77 +0,0 @@
|
|||||||
package logic
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"micro-bundle/internal/dao"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
|
||||||
|
|
||||||
"github.com/samber/lo"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SendQuestionnaireSurvey(req *bundle.SendQuestionnaireSurveyRequest) (*bundle.SendQuestionnaireSurveyResponse, error) {
|
|
||||||
resp, err := dao.SendQuestionnaireSurvey(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetQuestionnaireSurveyInfo(req *bundle.GetQuestionnaireSurveyInfoRequest) (*bundle.GetQuestionnaireSurveyInfoResponse, error) {
|
|
||||||
resp := new(bundle.GetQuestionnaireSurveyInfoResponse)
|
|
||||||
data, err := dao.GetQuestionnaireSurveyInfo(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("获取问卷信息失败")
|
|
||||||
}
|
|
||||||
bundleInfo := &model.BundleInfo{}
|
|
||||||
err = json.Unmarshal([]byte(data.BundleInfo), bundleInfo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.New("反序列化失败")
|
|
||||||
}
|
|
||||||
fmt.Println("获取套餐名称:", bundleInfo.BundleName)
|
|
||||||
resp.UserName = data.UserName
|
|
||||||
resp.BundleInfo = &bundle.SurveyBundleInfo{}
|
|
||||||
resp.BundleInfo.BundleName = bundleInfo.BundleName
|
|
||||||
resp.BundleInfo.StartAt = bundleInfo.StartAt.Format("2006-01-02 15:04:05")
|
|
||||||
resp.BundleInfo.ExpiredAt = bundleInfo.ExpiredAt.Format("2006-01-02 15:04:05")
|
|
||||||
resp.BundleInfo.BundleAccountNumber = int32(bundleInfo.BundleAccountNumber)
|
|
||||||
resp.BundleInfo.BundleVideoNumber = int32(bundleInfo.BundleVideoNumber)
|
|
||||||
resp.BundleInfo.IncreaseVideoNumber = int32(bundleInfo.IncreaseVideoNumber)
|
|
||||||
resp.BundleInfo.BundleImageNumber = int32(bundleInfo.BundleImageNumber)
|
|
||||||
resp.BundleInfo.BundleDataNumber = int32(bundleInfo.BundleDataNumber)
|
|
||||||
resp.BundleInfo.BundleCompetitiveNumber = int32(bundleInfo.BundleCompetitiveNumber)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateQuestionnaireSurveyAnswer(req *bundle.CreateQuestionnaireSurveyAnswerRequest) (*bundle.CreateQuestionnaireSurveyAnswerResponse, error) {
|
|
||||||
resp := new(bundle.CreateQuestionnaireSurveyAnswerResponse)
|
|
||||||
err := dao.CreateQuestionnaireSurveyAnswer(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetQuestionnaireSurveyList(req *bundle.GetQuestionnaireSurveyListRequest) (resp *bundle.GetQuestionnaireSurveyListResponse, err error) {
|
|
||||||
resp = &bundle.GetQuestionnaireSurveyListResponse{}
|
|
||||||
data, total, err := dao.GetQuestionnaireSurveyList(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
resp.Total = int32(total)
|
|
||||||
resp.Page = req.Page
|
|
||||||
resp.Size = req.PageSize
|
|
||||||
resp.SurveyList = lo.Map(data, func(m *model.QuestionnaireSurvey, _ int) *bundle.SurveyListInfo {
|
|
||||||
return &bundle.SurveyListInfo{
|
|
||||||
UserName: m.UserName,
|
|
||||||
UserTel: m.UserTel,
|
|
||||||
UserNum: m.UserNum,
|
|
||||||
SurveyTitle: m.SurveyTitle,
|
|
||||||
SurveyStatus: int32(m.SurveyStatus),
|
|
||||||
SurveyUrl: m.SurveyUrl,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
||||||
@ -3,19 +3,19 @@ package logic
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"micro-bundle/internal/dao"
|
"micro-bundle/internal/dao"
|
||||||
"micro-bundle/internal/dto"
|
|
||||||
"micro-bundle/internal/model"
|
|
||||||
"micro-bundle/pb/bundle"
|
"micro-bundle/pb/bundle"
|
||||||
commonErr "micro-bundle/pkg/err"
|
commonErr "micro-bundle/pkg/err"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetValidArtistList 查询套餐状态为有效中的艺人列表
|
// GetValidArtistList 查询套餐状态为有效中的艺人列表
|
||||||
func GetValidArtistList() ([]dto.ValidArtistInfo, error) {
|
// 调用dao层获取艺人详细信息
|
||||||
|
func GetValidArtistList() ([]dao.ValidArtistInfo, error) {
|
||||||
return dao.GetValidArtistList()
|
return dao.GetValidArtistList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetValidArtistIDs 查询套餐没有过期的艺人ID列表(保持向后兼容)
|
// GetValidArtistIDs 查询套餐没有过期的艺人ID列表(保持向后兼容)
|
||||||
|
// 根据BundleOrderRecords表查询过期时间大于当前时间且状态为已支付的艺人
|
||||||
func GetValidArtistIDs() ([]string, error) {
|
func GetValidArtistIDs() ([]string, error) {
|
||||||
artistList, err := GetValidArtistList()
|
artistList, err := GetValidArtistList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -34,6 +34,8 @@ func GetValidArtistIDs() ([]string, error) {
|
|||||||
|
|
||||||
// todo 目前暂时不做检验,后续需要做判断
|
// todo 目前暂时不做检验,后续需要做判断
|
||||||
// GetValidEmployeeIDs 查询可以被指派任务的员工ID列表
|
// GetValidEmployeeIDs 查询可以被指派任务的员工ID列表
|
||||||
|
// 这里可以根据实际业务需求实现,比如查询员工表、权限表等
|
||||||
|
// 目前先返回一个示例实现,实际项目中需要根据具体的员工管理逻辑来实现
|
||||||
func GetValidEmployeeIDs() ([]string, error) {
|
func GetValidEmployeeIDs() ([]string, error) {
|
||||||
var employeeIDs []string
|
var employeeIDs []string
|
||||||
|
|
||||||
@ -61,18 +63,40 @@ func ValidateEmployee(employeeNum string) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPendingTaskList 查询待指派任务记录
|
||||||
|
func GetPendingTaskList(req *dao.TaskQueryRequest) ([]*dao.TaskQueryResponse, int64, error) {
|
||||||
|
// 1. 先查询套餐没有过期的艺人
|
||||||
|
validArtist, err := GetValidArtistList()
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 调用DAO层查询待指派任务记录(已包含联表查询和排序分页)
|
||||||
|
recordResponse, total, err := dao.GetPendingTaskList(req, validArtist)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 直接返回DAO层的结果(已经包含了所有计算和排序分页逻辑)
|
||||||
|
return recordResponse, total, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetArtistUploadStatsList 查询艺人上传与额度统计列表
|
// GetArtistUploadStatsList 查询艺人上传与额度统计列表
|
||||||
func GetArtistUploadStatsList(req *dto.TaskQueryRequest) ([]*dto.ArtistUploadStatsItem, int64, error) {
|
func GetArtistUploadStatsList(req *dao.TaskQueryRequest) ([]*dao.ArtistUploadStatsItem, int64, error) {
|
||||||
return dao.GetArtistUploadStatsList(req)
|
return dao.GetArtistUploadStatsList(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPendingUploadBreakdownBySubNums(subNums []string, page int, pageSize int) ([]*dao.ArtistPendingUploadBreakdownItem, int64, error) {
|
||||||
|
return dao.GetPendingUploadBreakdownBySubNums(subNums, page, pageSize)
|
||||||
|
}
|
||||||
|
|
||||||
// GetPendingAssignBySubNums 查询指定艺人的可指派数量
|
// GetPendingAssignBySubNums 查询指定艺人的可指派数量
|
||||||
func GetPendingAssignBySubNums(subNums []string, page int, pageSize int) ([]*dto.ArtistPendingAssignItem, int64, error) {
|
func GetPendingAssignBySubNums(subNums []string, page int, pageSize int) ([]*dao.ArtistPendingAssignItem, int64, error) {
|
||||||
return dao.GetPendingAssignBySubNums(subNums, page, pageSize)
|
return dao.GetPendingAssignBySubNums(subNums, page, pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssignTask 指派某位员工完成某个艺人的任务
|
// AssignTask 指派某位员工完成某个艺人的任务
|
||||||
func AssignTask(req *dto.TaskAssignRequest) error {
|
func AssignTask(req *dao.TaskAssignRequest) error {
|
||||||
// 1. 验证员工是否可以被指派任务
|
// 1. 验证员工是否可以被指派任务
|
||||||
isValid, err := ValidateEmployee(req.TaskAssigneeNum)
|
isValid, err := ValidateEmployee(req.TaskAssigneeNum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,10 +105,10 @@ func AssignTask(req *dto.TaskAssignRequest) error {
|
|||||||
if !isValid {
|
if !isValid {
|
||||||
return commonErr.ReturnError(nil, "员工不能被指派任务", "该员工不在可指派任务的员工列表中")
|
return commonErr.ReturnError(nil, "员工不能被指派任务", "该员工不在可指派任务的员工列表中")
|
||||||
}
|
}
|
||||||
if req.AssignVideoCount < 0 || req.AssignPostCount < 0 || req.AssignDataCount < 0 || req.AssignVideoScriptCount < 0 || req.AssignReportCount < 0 {
|
if req.AssignVideoCount < 0 || req.AssignPostCount < 0 || req.AssignDataCount < 0 || req.AssignVideoScriptCount < 0 {
|
||||||
return commonErr.ReturnError(nil, "指派数量不能小于0", "任一指派数量不得小于0")
|
return commonErr.ReturnError(nil, "指派数量不能小于0", "任一指派数量不得小于0")
|
||||||
}
|
}
|
||||||
if req.AssignVideoCount == 0 && req.AssignPostCount == 0 && req.AssignDataCount == 0 && req.AssignVideoScriptCount == 0 && req.AssignReportCount == 0 {
|
if req.AssignVideoCount == 0 && req.AssignPostCount == 0 && req.AssignDataCount == 0 && req.AssignVideoScriptCount == 0 {
|
||||||
return commonErr.ReturnError(nil, "指派数量不能全部为0", "至少有一个指派数量需大于0")
|
return commonErr.ReturnError(nil, "指派数量不能全部为0", "至少有一个指派数量需大于0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +124,7 @@ func AssignTask(req *dto.TaskAssignRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BatchAssignTask 批量指派
|
// BatchAssignTask 批量指派
|
||||||
func BatchAssignTask(items []*dto.BatchAssignItem) error {
|
func BatchAssignTask(items []*dao.BatchAssignItem) error {
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
return commonErr.ReturnError(nil, "参数错误", "批量指派项不能为空")
|
return commonErr.ReturnError(nil, "参数错误", "批量指派项不能为空")
|
||||||
}
|
}
|
||||||
@ -118,13 +142,13 @@ func BatchAssignTask(items []*dto.BatchAssignItem) error {
|
|||||||
if !isValid {
|
if !isValid {
|
||||||
return commonErr.ReturnError(nil, "员工不能被指派任务", "该员工不在可指派任务的员工列表中")
|
return commonErr.ReturnError(nil, "员工不能被指派任务", "该员工不在可指派任务的员工列表中")
|
||||||
}
|
}
|
||||||
if it.AssignVideoCount < 0 || it.AssignPostCount < 0 || it.AssignDataCount < 0 || it.AssignVideoScriptCount < 0 || it.AssignReportCount < 0 {
|
if it.AssignVideoCount < 0 || it.AssignPostCount < 0 || it.AssignDataCount < 0 || it.AssignVideoScriptCount < 0 {
|
||||||
return commonErr.ReturnError(nil, "指派数量不能小于0", "任一指派数量不得小于0")
|
return commonErr.ReturnError(nil, "指派数量不能小于0", "任一指派数量不得小于0")
|
||||||
}
|
}
|
||||||
if it.AssignVideoCount == 0 && it.AssignPostCount == 0 && it.AssignDataCount == 0 && it.AssignVideoScriptCount == 0 && it.AssignReportCount == 0 {
|
if it.AssignVideoCount == 0 && it.AssignPostCount == 0 && it.AssignDataCount == 0 && it.AssignVideoScriptCount == 0 {
|
||||||
return commonErr.ReturnError(nil, "指派数量不能全部为0", "至少有一个指派数量需大于0")
|
return commonErr.ReturnError(nil, "指派数量不能全部为0", "至少有一个指派数量需大于0")
|
||||||
}
|
}
|
||||||
if it.AssignVideoCount > 0 || it.AssignPostCount > 0 || it.AssignDataCount > 0 || it.AssignVideoScriptCount > 0 || it.AssignReportCount > 0 {
|
if it.AssignVideoCount > 0 || it.AssignPostCount > 0 || it.AssignDataCount > 0 || it.AssignVideoScriptCount > 0 {
|
||||||
hasPositive = true
|
hasPositive = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,6 +160,42 @@ func BatchAssignTask(items []*dto.BatchAssignItem) error {
|
|||||||
return dao.BatchAssignTasks(items)
|
return dao.BatchAssignTasks(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdatePendingCount 修改待发数量
|
||||||
|
func UpdatePendingCount(req *dao.UpdatePendingCountRequest) error {
|
||||||
|
// 待发视频数、图文数、数据分析数不能都为0
|
||||||
|
if req.PendingVideoCount == 0 && req.PendingPostCount == 0 && req.PendingDataCount == 0 {
|
||||||
|
return commonErr.ReturnError(nil, "请输入正确的本次任务数字", "待发视频数、图文数、数据分析数不能都为0")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 验证艺人是否有有效套餐
|
||||||
|
validArtistIDs, err := GetValidArtistIDs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查艺人是否在有效列表中
|
||||||
|
isValidArtist := false
|
||||||
|
for _, artistID := range validArtistIDs {
|
||||||
|
if artistID == req.SubNum {
|
||||||
|
isValidArtist = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isValidArtist {
|
||||||
|
return commonErr.ReturnError(nil, "艺人套餐已过期", "该艺人没有有效的套餐,无法修改待发数量")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询艺人当前任务余额,校验是否存在记录(不做数量比较,避免排除手动余额)
|
||||||
|
_, err = dao.GetRemainingPendingBySubNum(req.SubNum)
|
||||||
|
if err != nil {
|
||||||
|
return commonErr.ReturnError(err, "查询艺人任务余额失败", "查询艺人任务余额失败: ")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 调用DAO层更新待发数量(DAO 内部已做充足的额度与当月限额校验)
|
||||||
|
return dao.UpdatePendingCount(req)
|
||||||
|
}
|
||||||
|
|
||||||
// GetRecentAssignRecords 查询最近被指派记录
|
// GetRecentAssignRecords 查询最近被指派记录
|
||||||
func GetRecentAssignRecords(limit int) ([]*bundle.RecentAssigneeItem, error) {
|
func GetRecentAssignRecords(limit int) ([]*bundle.RecentAssigneeItem, error) {
|
||||||
records, err := dao.GetRecentAssignRecords(limit)
|
records, err := dao.GetRecentAssignRecords(limit)
|
||||||
@ -154,7 +214,7 @@ func GetRecentAssignRecords(limit int) ([]*bundle.RecentAssigneeItem, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetEmployeeAssignedTasks 根据登录人信息查询被指派给该员工的艺人任务
|
// GetEmployeeAssignedTasks 根据登录人信息查询被指派给该员工的艺人任务
|
||||||
func GetEmployeeAssignedTasks(req *dto.EmployeeTaskQueryRequest) ([]*dto.TaskAssignRecordsResponse, int64, error) {
|
func GetEmployeeAssignedTasks(req *dao.EmployeeTaskQueryRequest) ([]*dao.TaskAssignRecordsResponse, int64, error) {
|
||||||
// 1. 调用DAO层查询被指派给该员工的艺人任务
|
// 1. 调用DAO层查询被指派给该员工的艺人任务
|
||||||
record, total, err := dao.GetEmployeeAssignedTasks(req)
|
record, total, err := dao.GetEmployeeAssignedTasks(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -163,34 +223,28 @@ func GetEmployeeAssignedTasks(req *dto.EmployeeTaskQueryRequest) ([]*dto.TaskAss
|
|||||||
|
|
||||||
// 如果查询的 status = 2 的话,待发数量就为指派时,指派的数量
|
// 如果查询的 status = 2 的话,待发数量就为指派时,指派的数量
|
||||||
if req.Status == 2 {
|
if req.Status == 2 {
|
||||||
var recordResponse []*dto.TaskAssignRecordsResponse
|
var recordResponse []*dao.TaskAssignRecordsResponse
|
||||||
for _, record := range record {
|
for _, record := range record {
|
||||||
recordResponse = append(recordResponse, &dto.TaskAssignRecordsResponse{
|
recordResponse = append(recordResponse, &dao.TaskAssignRecordsResponse{
|
||||||
AssignRecordsUUID: record.AssignRecordsUUID,
|
AssignRecordsUUID: record.AssignRecordsUUID,
|
||||||
SubNum: record.SubNum,
|
SubNum: record.SubNum,
|
||||||
TelNum: record.TelNum,
|
TelNum: record.TelNum,
|
||||||
ArtistName: record.ArtistName,
|
ArtistName: record.ArtistName,
|
||||||
Status: record.Status,
|
Status: record.Status,
|
||||||
ActualStatus: record.ActualStatus,
|
ActualStatus: record.ActualStatus,
|
||||||
CompleteTime: record.CompleteTime,
|
CompleteTime: record.CompleteTime,
|
||||||
OperatorType: record.OperatorType,
|
OperatorType: record.OperatorType,
|
||||||
Operator: record.Operator,
|
Operator: record.Operator,
|
||||||
OperatorNum: record.OperatorNum,
|
OperatorNum: record.OperatorNum,
|
||||||
OperatorTime: record.OperatorTime,
|
OperatorTime: record.OperatorTime,
|
||||||
TaskAssignee: record.TaskAssignee,
|
TaskAssignee: record.TaskAssignee,
|
||||||
TaskAssigneeNum: record.TaskAssigneeNum,
|
TaskAssigneeNum: record.TaskAssigneeNum,
|
||||||
PendingVideoCount: record.AssignVideoCount,
|
PendingVideoCount: record.AssignVideoCount,
|
||||||
PendingPostCount: record.AssignPostCount,
|
PendingPostCount: record.AssignPostCount,
|
||||||
PendingDataCount: record.AssignDataCount,
|
PendingDataCount: record.AssignDataCount,
|
||||||
PendingVideoScriptCount: record.AssignVideoScriptCount,
|
PendingVideoScriptCount: record.AssignVideoScriptCount,
|
||||||
PendingReportCount: record.AssignReportCount,
|
TaskBatch: record.TaskBatch,
|
||||||
CompleteVideoScriptCount: record.CompleteVideoScriptCount,
|
UpdatedAt: record.UpdatedAt,
|
||||||
CompleteVideoCount: record.CompleteVideoCount,
|
|
||||||
CompletePostCount: record.CompletePostCount,
|
|
||||||
CompleteDataCount: record.CompleteDataCount,
|
|
||||||
CompleteReportCount: record.CompleteReportCount,
|
|
||||||
TaskBatch: record.TaskBatch,
|
|
||||||
UpdatedAt: record.UpdatedAt,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,9 +252,9 @@ func GetEmployeeAssignedTasks(req *dto.EmployeeTaskQueryRequest) ([]*dto.TaskAss
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 转换为响应结构体
|
// 2. 转换为响应结构体
|
||||||
var recordResponse []*dto.TaskAssignRecordsResponse
|
var recordResponse []*dao.TaskAssignRecordsResponse
|
||||||
for _, record := range record {
|
for _, record := range record {
|
||||||
recordResponse = append(recordResponse, &dto.TaskAssignRecordsResponse{
|
recordResponse = append(recordResponse, &dao.TaskAssignRecordsResponse{
|
||||||
AssignRecordsUUID: record.AssignRecordsUUID,
|
AssignRecordsUUID: record.AssignRecordsUUID,
|
||||||
SubNum: record.SubNum,
|
SubNum: record.SubNum,
|
||||||
TelNum: record.TelNum,
|
TelNum: record.TelNum,
|
||||||
@ -218,7 +272,6 @@ func GetEmployeeAssignedTasks(req *dto.EmployeeTaskQueryRequest) ([]*dto.TaskAss
|
|||||||
PendingPostCount: record.PendingPostCount,
|
PendingPostCount: record.PendingPostCount,
|
||||||
PendingDataCount: record.PendingDataCount,
|
PendingDataCount: record.PendingDataCount,
|
||||||
PendingVideoScriptCount: record.PendingVideoScriptCount,
|
PendingVideoScriptCount: record.PendingVideoScriptCount,
|
||||||
PendingReportCount: record.PendingReportCount,
|
|
||||||
TaskBatch: record.TaskBatch,
|
TaskBatch: record.TaskBatch,
|
||||||
UpdatedAt: record.UpdatedAt,
|
UpdatedAt: record.UpdatedAt,
|
||||||
})
|
})
|
||||||
@ -237,6 +290,7 @@ func TerminateTaskByUUID(assignRecordsUUID string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BatchTerminateTaskByUUIDs 批量根据指派记录UUID终止任务(实际状态置为已中止)
|
// BatchTerminateTaskByUUIDs 批量根据指派记录UUID终止任务(实际状态置为已中止)
|
||||||
|
// 返回成功数量、失败数量、失败UUID列表和错误(仅当整体参数错误时返回错误)
|
||||||
func BatchTerminateTaskByUUIDs(assignRecordsUUIDs []string) (int, int, []string, error) {
|
func BatchTerminateTaskByUUIDs(assignRecordsUUIDs []string) (int, int, []string, error) {
|
||||||
if len(assignRecordsUUIDs) == 0 {
|
if len(assignRecordsUUIDs) == 0 {
|
||||||
return 0, 0, nil, commonErr.ReturnError(nil, "参数错误", "AssignRecordsUUIDs 不能为空")
|
return 0, 0, nil, commonErr.ReturnError(nil, "参数错误", "AssignRecordsUUIDs 不能为空")
|
||||||
@ -303,7 +357,7 @@ func CompleteTaskManually(assignRecordsUUID string, taskAssigneeNum string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTaskProgress 员工实际完成任务状态更新
|
// UpdateTaskProgress 员工实际完成任务状态更新
|
||||||
func UpdateTaskProgress(req *dto.CompleteTaskRequest) error {
|
func UpdateTaskProgress(req *dao.CompleteTaskRequest) error {
|
||||||
if req.UUID == "" {
|
if req.UUID == "" {
|
||||||
return commonErr.ReturnError(nil, "作品UUID不能为空", "UUID不能为空")
|
return commonErr.ReturnError(nil, "作品UUID不能为空", "UUID不能为空")
|
||||||
}
|
}
|
||||||
@ -311,16 +365,16 @@ func UpdateTaskProgress(req *dto.CompleteTaskRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTaskAssignRecordsList 多条件查询操作记录表
|
// GetTaskAssignRecordsList 多条件查询操作记录表
|
||||||
func GetTaskAssignRecordsList(req *dto.TaskAssignRecordsQueryRequest) ([]*dto.TaskAssignRecordsResponse, int64, *dto.TaskAssignRecordsSummary, error) {
|
func GetTaskAssignRecordsList(req *dao.TaskAssignRecordsQueryRequest) ([]*dao.TaskAssignRecordsResponse, int64, *dao.TaskAssignRecordsSummary, error) {
|
||||||
record, total, summary, err := dao.GetTaskAssignRecordsList(req)
|
record, total, summary, err := dao.GetTaskAssignRecordsList(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, nil, err
|
return nil, 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 转换为响应结构体
|
// 2. 转换为响应结构体
|
||||||
var recordResponse []*dto.TaskAssignRecordsResponse
|
var recordResponse []*dao.TaskAssignRecordsResponse
|
||||||
for _, record := range record {
|
for _, record := range record {
|
||||||
recordResponse = append(recordResponse, &dto.TaskAssignRecordsResponse{
|
recordResponse = append(recordResponse, &dao.TaskAssignRecordsResponse{
|
||||||
AssignRecordsUUID: record.AssignRecordsUUID,
|
AssignRecordsUUID: record.AssignRecordsUUID,
|
||||||
SubNum: record.SubNum,
|
SubNum: record.SubNum,
|
||||||
TelNum: record.TelNum,
|
TelNum: record.TelNum,
|
||||||
@ -339,12 +393,10 @@ func GetTaskAssignRecordsList(req *dto.TaskAssignRecordsQueryRequest) ([]*dto.Ta
|
|||||||
PendingPostCount: record.AssignPostCount,
|
PendingPostCount: record.AssignPostCount,
|
||||||
PendingDataCount: record.AssignDataCount,
|
PendingDataCount: record.AssignDataCount,
|
||||||
PendingVideoScriptCount: record.AssignVideoScriptCount,
|
PendingVideoScriptCount: record.AssignVideoScriptCount,
|
||||||
PendingReportCount: record.AssignReportCount,
|
|
||||||
CompleteVideoScriptCount: record.CompleteVideoScriptCount,
|
CompleteVideoScriptCount: record.CompleteVideoScriptCount,
|
||||||
CompleteVideoCount: record.CompleteVideoCount,
|
CompleteVideoCount: record.CompleteVideoCount,
|
||||||
CompletePostCount: record.CompletePostCount,
|
CompletePostCount: record.CompletePostCount,
|
||||||
CompleteDataCount: record.CompleteDataCount,
|
CompleteDataCount: record.CompleteDataCount,
|
||||||
CompleteReportCount: record.CompleteReportCount,
|
|
||||||
UpdatedAt: record.UpdatedAt,
|
UpdatedAt: record.UpdatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -352,6 +404,65 @@ func GetTaskAssignRecordsList(req *dto.TaskAssignRecordsQueryRequest) ([]*dto.Ta
|
|||||||
return recordResponse, total, summary, nil
|
return recordResponse, total, summary, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增:查询艺人剩余待发数量(区分套餐/增值,共6个字段)
|
||||||
|
func GetArtistRemainingPending(subNum string) (*dao.ArtistRemainingPendingResponse, error) {
|
||||||
|
if strings.TrimSpace(subNum) == "" {
|
||||||
|
return nil, commonErr.ReturnError(nil, "查询参数错误", "艺人编号不能为空")
|
||||||
|
}
|
||||||
|
return dao.GetRemainingPendingBySubNum(subNum)
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculatePendingFromTaskBalance 从TaskBalance表计算待发任务数量
|
||||||
|
func calculatePendingFromTaskBalance(subNum string) (videoTotal, imageTotal, dataTotal int) {
|
||||||
|
// 查询用户的任务余额
|
||||||
|
tb, err := dao.GetTaskBalanceBySubNum(subNum)
|
||||||
|
if err != nil || tb == nil {
|
||||||
|
return 0, 0, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算视频类待发数量:总余额 - 消耗数量
|
||||||
|
videoTotal = (tb.MonthlyBundleLimitExpiredVideoNumber - tb.MonthlyBundleLimitExpiredVideoConsumptionNumber) +
|
||||||
|
(tb.MonthlyBundleLimitVideoNumber - tb.MonthlyBundleLimitVideoConsumptionNumber) +
|
||||||
|
(tb.BundleVideoNumber - tb.BundleVideoConsumptionNumber) +
|
||||||
|
(tb.IncreaseVideoNumber - tb.IncreaseVideoConsumptionNumber) +
|
||||||
|
(tb.MonthlyIncreaseLimitVideoNumber - tb.MonthlyIncreaseLimitVideoConsumptionNumber) +
|
||||||
|
(tb.MonthlyIncreaseLimitExpiredVideoNumber - tb.MonthlyIncreaseLimitExpiredVideoConsumptionNumber) +
|
||||||
|
(tb.ManualVideoNumber - tb.ManualVideoConsumptionNumber)
|
||||||
|
if videoTotal < 0 {
|
||||||
|
videoTotal = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算图片类待发数量:总余额 - 消耗数量
|
||||||
|
imageTotal = (tb.MonthlyBundleLimitExpiredImageNumber - tb.MonthlyBundleLimitExpiredImageConsumptionNumber) +
|
||||||
|
(tb.MonthlyBundleLimitImageNumber - tb.MonthlyBundleLimitImageConsumptionNumber) +
|
||||||
|
(tb.BundleImageNumber - tb.BundleImageConsumptionNumber) +
|
||||||
|
(tb.IncreaseImageNumber - tb.IncreaseImageConsumptionNumber) +
|
||||||
|
(tb.MonthlyIncreaseLimitImageNumber - tb.MonthlyIncreaseLimitImageConsumptionNumber) +
|
||||||
|
(tb.MonthlyIncreaseLimitExpiredImageNumber - tb.MonthlyIncreaseLimitExpiredImageConsumptionNumber) +
|
||||||
|
(tb.ManualImageNumber - tb.ManualImageConsumptionNumber)
|
||||||
|
if imageTotal < 0 {
|
||||||
|
imageTotal = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算数据分析类待发数量:总余额 - 消耗数量
|
||||||
|
dataTotal = (tb.MonthlyBundleLimitExpiredDataAnalysisNumber - tb.MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber) +
|
||||||
|
(tb.MonthlyBundleLimitDataAnalysisNumber - tb.MonthlyBundleLimitDataAnalysisConsumptionNumber) +
|
||||||
|
(tb.BundleDataAnalysisNumber - tb.BundleDataAnalysisConsumptionNumber) +
|
||||||
|
(tb.IncreaseDataAnalysisNumber - tb.IncreaseDataAnalysisConsumptionNumber) +
|
||||||
|
(tb.MonthlyIncreaseLimitDataAnalysisNumber - tb.MonthlyIncreaseLimitDataAnalysisConsumptionNumber) +
|
||||||
|
(tb.MonthlyIncreaseLimitExpiredDataAnalysisNumber - tb.MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber) +
|
||||||
|
(tb.ManualDataAnalysisNumber - tb.ManualDataAnalysisConsumptionNumber)
|
||||||
|
if dataTotal < 0 {
|
||||||
|
dataTotal = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return videoTotal, imageTotal, dataTotal
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateTaskBalanceEveryMonLogic() {
|
||||||
|
dao.UpdateTaskBalanceEveryMon()
|
||||||
|
}
|
||||||
|
|
||||||
// GetTaskActualStatusByUUID 根据指派记录UUID查询实际完成状态
|
// GetTaskActualStatusByUUID 根据指派记录UUID查询实际完成状态
|
||||||
func GetTaskActualStatusByUUID(assignRecordsUUID string) (int, error) {
|
func GetTaskActualStatusByUUID(assignRecordsUUID string) (int, error) {
|
||||||
if strings.TrimSpace(assignRecordsUUID) == "" {
|
if strings.TrimSpace(assignRecordsUUID) == "" {
|
||||||
@ -411,12 +522,6 @@ func buildDefaultPendingLayout() string {
|
|||||||
{"已释放数据额度", "releasedDataAnalysisTotal", 1},
|
{"已释放数据额度", "releasedDataAnalysisTotal", 1},
|
||||||
{"套餐数据总数", "bundleDataAnalysisTotal", 1},
|
{"套餐数据总数", "bundleDataAnalysisTotal", 1},
|
||||||
{"增值数据总数", "increaseDataAnalysisTotal", 1},
|
{"增值数据总数", "increaseDataAnalysisTotal", 1},
|
||||||
{"可指派竞品报告数", "allowReportCount", 1},
|
|
||||||
{"可上传竞品报告数", "pendingReportCount", 1},
|
|
||||||
{"已上传竞品报告数", "uploadedReportCount", 1},
|
|
||||||
{"已释放竞品报告额度", "releasedReportTotal", 1},
|
|
||||||
{"套餐竞品报告总数", "bundleReportTotal", 1},
|
|
||||||
{"增值竞品报告总数", "increaseReportTotal", 1},
|
|
||||||
{"进行中任务数", "progressTaskCount", 1},
|
{"进行中任务数", "progressTaskCount", 1},
|
||||||
{"已完成任务数", "completeTaskCount", 1},
|
{"已完成任务数", "completeTaskCount", 1},
|
||||||
}
|
}
|
||||||
@ -442,17 +547,16 @@ func AddHiddenTaskAssignee(taskAssignee string, taskAssigneeNum string) error {
|
|||||||
return dao.AddHiddenTaskAssignee(taskAssignee, taskAssigneeNum)
|
return dao.AddHiddenTaskAssignee(taskAssignee, taskAssigneeNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTaskWorkLogList(req *dto.TaskWorkLogQueryRequest) ([]*model.TaskWorkLog, int64, error) {
|
|
||||||
return dao.GetTaskWorkLogList(req)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTaskWorkLog 创建任务日志记录
|
// CreateTaskWorkLog 创建任务日志记录
|
||||||
func CreateTaskWorkLog(req *dto.CreateTaskWorkLogRequest) error {
|
// 用于记录任务操作日志,包括加任务、消耗任务、完成任务、任务过期等操作
|
||||||
|
func CreateTaskWorkLog(req *dao.CreateTaskWorkLogRequest) error {
|
||||||
|
// 参数校验已在 DAO 层完成,这里可以添加额外的业务逻辑校验
|
||||||
|
// 例如:校验操作类型是否合法、任务类型是否合法等
|
||||||
if req.OperationType < 1 || req.OperationType > 4 {
|
if req.OperationType < 1 || req.OperationType > 4 {
|
||||||
return commonErr.ReturnError(nil, "参数错误", "操作类型必须在1-4之间")
|
return commonErr.ReturnError(nil, "参数错误", "操作类型必须在1-4之间")
|
||||||
}
|
}
|
||||||
if req.TaskType < 1 || req.TaskType > 6 {
|
if req.TaskType < 1 || req.TaskType > 3 {
|
||||||
return commonErr.ReturnError(nil, "参数错误", "任务类型必须在1-6之间")
|
return commonErr.ReturnError(nil, "参数错误", "任务类型必须在1-3之间")
|
||||||
}
|
}
|
||||||
if req.TaskCount < 0 {
|
if req.TaskCount < 0 {
|
||||||
return commonErr.ReturnError(nil, "参数错误", "任务数量不能为负数")
|
return commonErr.ReturnError(nil, "参数错误", "任务数量不能为负数")
|
||||||
|
|||||||
@ -97,7 +97,6 @@ type BundleExtensionRecords struct {
|
|||||||
OperatorName string `gorm:"column:operator_name;type:varchar(256)" json:"operatorName"`
|
OperatorName string `gorm:"column:operator_name;type:varchar(256)" json:"operatorName"`
|
||||||
OperatorPhoneNumber string `gorm:"column:operator_phone_number;type:varchar(256)" json:"operatorPhoneNumber"`
|
OperatorPhoneNumber string `gorm:"column:operator_phone_number;type:varchar(256)" json:"operatorPhoneNumber"`
|
||||||
TimeUnit uint `gorm:"column:time_unit;type:int(11) unsigned;comment:时间单位" json:"timeUnit"`
|
TimeUnit uint `gorm:"column:time_unit;type:int(11) unsigned;comment:时间单位" json:"timeUnit"`
|
||||||
CompetitiveAdditional uint `gorm:"column:competitive_additional;type:int(11) unsigned;comment:竞品数额外增加" json:"competitive_additional"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 表名称
|
// TableName 表名称
|
||||||
@ -112,7 +111,6 @@ type BundleExtendRecordItemPo struct {
|
|||||||
ImagesAdditional int
|
ImagesAdditional int
|
||||||
DataAdditional int
|
DataAdditional int
|
||||||
VideoAdditional int
|
VideoAdditional int
|
||||||
CompetitiveAdditional int
|
|
||||||
AvailableDurationAdditional uint `gorm:"column:available_duration_additional;type:int(11) unsigned;comment:可用时长增加" json:"available_duration_additional"`
|
AvailableDurationAdditional uint `gorm:"column:available_duration_additional;type:int(11) unsigned;comment:可用时长增加" json:"available_duration_additional"`
|
||||||
Type int
|
Type int
|
||||||
Remark string
|
Remark string
|
||||||
@ -159,17 +157,15 @@ type BundleBalancePo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UserBundleBalancePo struct {
|
type UserBundleBalancePo struct {
|
||||||
OrderUUID string `json:"orderUUID" gorm:"column:order_uuid"`
|
OrderUUID string `json:"orderUUID" gorm:"column:order_uuid"`
|
||||||
BundleUuid string `json:"bundleUuid" gorm:"column:bundle_uuid"`
|
BundleUuid string `json:"bundleUuid" gorm:"column:bundle_uuid"`
|
||||||
BundleName string `json:"bundleName" gorm:"column:bundle_name"`
|
BundleName string `json:"bundleName" gorm:"column:bundle_name"`
|
||||||
BundleStatus string `json:"bundleStatus" gorm:"column:bundle_status"`
|
BundleStatus string `json:"bundleStatus" gorm:"column:bundle_status"`
|
||||||
PayTime time.Time `json:"payTime" gorm:"column:pay_time"`
|
PayTime string `json:"payTime" gorm:"column:pay_time"`
|
||||||
ExpiredTime string `json:"expiredTime" gorm:"column:expired_time"`
|
ExpiredTime string `json:"expiredTime" gorm:"column:expired_time"`
|
||||||
PaymentAmount string `json:"paymentAmount" gorm:"column:payment_amount"`
|
PaymentAmount string `json:"paymentAmount" gorm:"column:payment_amount"`
|
||||||
PaymentType int32 `json:"paymentType" gorm:"column:payment_type"`
|
PaymentType int32 `json:"paymentType" gorm:"column:payment_type"`
|
||||||
Activate int `gorm:"column:activate"`
|
Activate int `gorm:"column:activate"`
|
||||||
RenewalOrderUUID string `gorm:"column:renewal_order_uuid;type:varchar(1024);comment:续费订单UUID" json:"renewalOrderUUID"`
|
|
||||||
PurchaseType uint64 `gorm:"column:purchase_type;type:bigint;comment:购买类型 1:新购 2:续费" json:"purchaseType"`
|
|
||||||
BundleBalance
|
BundleBalance
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,39 +290,6 @@ type BundleBalance struct {
|
|||||||
|
|
||||||
MonthlyNewDurationNumber int `gorm:"column:monthly_new_duration_number;comment:当月新增手动扩展时长(天)"`
|
MonthlyNewDurationNumber int `gorm:"column:monthly_new_duration_number;comment:当月新增手动扩展时长(天)"`
|
||||||
ExpansionPacksNumber int `gorm:"column:expansion_packs_number;not null;comment:扩展包数量"`
|
ExpansionPacksNumber int `gorm:"column:expansion_packs_number;not null;comment:扩展包数量"`
|
||||||
|
|
||||||
// ===== 竞品数 =====
|
|
||||||
BundleCompetitiveNumber int `gorm:"column:bundle_competitive_number;not null;comment:非限制类型套餐权益竞品数总数"`
|
|
||||||
IncreaseCompetitiveNumber int `gorm:"column:increase_competitive_number;not null;comment:非限制类型增值权益竞品数总数"`
|
|
||||||
BundleLimitCompetitiveNumber int `gorm:"column:bundle_limit_competitive_number;not null;comment:套餐权益限制类型竞品数非过期总数"`
|
|
||||||
IncreaseLimitCompetitiveNumber int `gorm:"column:increase_limit_competitive_number;not null;comment:增值权益限制类型竞品数非过期总数"`
|
|
||||||
BundleLimitCompetitiveExpiredNumber int `gorm:"column:bundle_limit_competitive_expired_number;not null;comment:套餐权益限制类型竞品数会过期总数"`
|
|
||||||
IncreaseLimitCompetitiveExpiredNumber int `gorm:"column:increase_limit_competitive_expired_number;not null;comment:增值权益限制类型竞品数会过期总数"`
|
|
||||||
MonthlyInvalidBundleCompetitiveNumber int `gorm:"column:monthly_invalid_bundle_competitive_number;not null;comment:当月失效的套餐权益竞品数总数"`
|
|
||||||
InvalidBundleCompetitiveNumber int `gorm:"column:invalid_bundle_competitive_number;not null;comment:历史失效的套餐权益竞品数总数"`
|
|
||||||
MonthlyInvalidIncreaseCompetitiveNumber int `gorm:"column:monthly_invalid_increase_competitive_number;not null;comment:当月失效的增值权益竞品数总数"`
|
|
||||||
InvalidIncreaseCompetitiveNumber int `gorm:"column:invalid_increase_competitive_number;not null;comment:历史失效的增值权益竞品数总数"`
|
|
||||||
BundleCompetitiveConsumptionNumber int `gorm:"column:bundle_competitive_consumption_number;not null;comment:非限制类型套餐权益竞品数使用数"`
|
|
||||||
IncreaseCompetitiveConsumptionNumber int `gorm:"column:increase_competitive_consumption_number;not null;comment:非限制类型增值权益竞品数使用数"`
|
|
||||||
BundleLimitCompetitiveConsumptionNumber int `gorm:"column:bundle_limit_competitive_consumption_number;not null;comment:套餐权益限制类型竞品数非过期使用数"`
|
|
||||||
IncreaseLimitCompetitiveConsumptionNumber int `gorm:"column:increase_limit_competitive_consumption_number;not null;comment:增值权益限制类型竞品数非过期使用数"`
|
|
||||||
BundleLimitCompetitiveExpiredConsumptionNumber int `gorm:"column:bundle_limit_competitive_expired_consumption_number;not null;comment:套餐权益限制类型竞品数会过期使用数"`
|
|
||||||
IncreaseLimitCompetitiveExpiredConsumptionNumber int `gorm:"column:increase_limit_competitive_expired_consumption_number;not null;comment:增值权益限制类型竞品数会过期使用数"`
|
|
||||||
MonthlyBundleCompetitiveConsumptionNumber int `gorm:"column:monthly_bundle_competitive_consumption_number;not null;comment:当月套餐类型竞品数已使用额度"`
|
|
||||||
MonthlyIncreaseCompetitiveConsumptionNumber int `gorm:"column:monthly_increase_competitive_consumption_number;not null;comment:当月增值类型竞品数已使用额度"`
|
|
||||||
MonthlyBundleLimitCompetitiveNumber int `gorm:"column:monthly_bundle_limit_competitive_number;not null;comment:当月套餐限制类型竞品数可使用额度"`
|
|
||||||
MonthlyIncreaseLimitCompetitiveNumber int `gorm:"column:monthly_increase_limit_competitive_number;not null;comment:当月增值限制类型竞品数可使用额度"`
|
|
||||||
MonthlyBundleLimitCompetitiveConsumptionNumber int `gorm:"column:monthly_bundle_limit_competitive_consumption_number;not null;comment:当月套餐限制类型竞品数已使用额度"`
|
|
||||||
MonthlyIncreaseLimitCompetitiveConsumptionNumber int `gorm:"column:monthly_increase_limit_competitive_consumption_number;not null;comment:当月增值限制类型竞品数已使用额度"`
|
|
||||||
MonthlyBundleLimitExpiredCompetitiveNumber int `gorm:"column:monthly_bundle_limit_expired_competitive_number;not null;comment:当月套餐限制类会过期型竞品数可使用额度"`
|
|
||||||
MonthlyIncreaseLimitExpiredCompetitiveNumber int `gorm:"column:monthly_increase_limit_expired_competitive_number;not null;comment:当月增值限制类会过期型竞品数可使用额度"`
|
|
||||||
MonthlyBundleLimitExpiredCompetitiveConsumptionNumber int `gorm:"column:monthly_bundle_limit_expired_competitive_consumption_number;not null;comment:当月套餐限制类型会过期竞品数已使用额度"`
|
|
||||||
MonthlyIncreaseLimitExpiredCompetitiveConsumptionNumber int `gorm:"column:monthly_increase_limit_expired_competitive_consumption_number;not null;comment:当月增值限制类会过期型竞品数已使用额度"`
|
|
||||||
MonthlyLimitCompetitiveQuotaNumber int `gorm:"column:monthly_limit_competitive_quota_number;not null;comment:当月限制类型竞品数额度"`
|
|
||||||
ManualCompetitiveNumber int `gorm:"column:manual_competitive_number;comment:手动扩展竞品数总数"`
|
|
||||||
ManualCompetitiveConsumptionNumber int `gorm:"column:manual_competitive_consumption_number;comment:手动扩展竞品数使用数"`
|
|
||||||
MonthlyNewManualCompetitiveNumber int `gorm:"column:monthly_new_manual_competitive_number;comment:当月手动扩展竞品数新增数"`
|
|
||||||
MonthlyManualCompetitiveConsumptionNumber int `gorm:"column:monthly_manual_competitive_consumption_number;comment:当月手动扩展竞品数使用数"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 表名称
|
// TableName 表名称
|
||||||
@ -351,17 +314,14 @@ type BundleBalanceUsePo struct {
|
|||||||
VideoNumber int
|
VideoNumber int
|
||||||
ImageNumber int
|
ImageNumber int
|
||||||
DataAnalysisNumber int
|
DataAnalysisNumber int
|
||||||
CompetitiveNumber int
|
|
||||||
}
|
}
|
||||||
type BundleBalanceExtendPo struct {
|
type BundleBalanceExtendPo struct {
|
||||||
UserId int
|
UserId int
|
||||||
AccountNumber int
|
AccountNumber int
|
||||||
VideoNumber int
|
VideoNumber int
|
||||||
ImageNumber int
|
ImageNumber int
|
||||||
CompetitiveNumber int
|
DataAnalysisNumber int
|
||||||
DataAnalysisNumber int
|
DurationNumber int
|
||||||
DurationNumber int
|
|
||||||
CompetitiveAdditional int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type BundleUsedRecord struct {
|
type BundleUsedRecord struct {
|
||||||
@ -417,7 +377,6 @@ type ManualIncreaseBundleBalance struct {
|
|||||||
TotalVideoAdditional int `gorm:"column:total_video_additional"`
|
TotalVideoAdditional int `gorm:"column:total_video_additional"`
|
||||||
TotalImageAdditional int `gorm:"column:total_image_additional"`
|
TotalImageAdditional int `gorm:"column:total_image_additional"`
|
||||||
TotalDataAnalysisAdditional int `gorm:"column:total_data_analysis_additional"`
|
TotalDataAnalysisAdditional int `gorm:"column:total_data_analysis_additional"`
|
||||||
TotalCompetitiveAdditional int `gorm:"column:total_competitive_additional"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 套餐购买导出
|
// 套餐购买导出
|
||||||
@ -435,18 +394,3 @@ type PurchaseItem struct {
|
|||||||
FinalAmount float32 `gorm:"column:finalAmount"`
|
FinalAmount float32 `gorm:"column:finalAmount"`
|
||||||
FeeAmount float32 `gorm:"column:feeAmount"`
|
FeeAmount float32 `gorm:"column:feeAmount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 续费账号数信息
|
|
||||||
type RenewalInfo struct {
|
|
||||||
AccountBundleNumber int
|
|
||||||
AccountIncreaseNumber int
|
|
||||||
}
|
|
||||||
|
|
||||||
// 套餐时间信息
|
|
||||||
type BundleBalanceTimeInfo struct {
|
|
||||||
UserId int `gorm:"column:user_id;not null"`
|
|
||||||
OrderUUID string `gorm:"column:order_uuid;not null"`
|
|
||||||
Month string `gorm:"column:month;not null"`
|
|
||||||
ExpiredAt time.Time `gorm:"column:expired_at;not null"`
|
|
||||||
StartAt time.Time `gorm:"column:start_at;not null"`
|
|
||||||
}
|
|
||||||
|
|||||||
@ -45,9 +45,6 @@ type BundleOrderRecords struct {
|
|||||||
BundleOrderValueAdd []BundleOrderValueAdd `gorm:"foreignKey:OrderUUID;references:UUID" json:"bundleOrderValueAdd"`
|
BundleOrderValueAdd []BundleOrderValueAdd `gorm:"foreignKey:OrderUUID;references:UUID" json:"bundleOrderValueAdd"`
|
||||||
ReSignature int `json:"reSignature" gorm:"column:re_signature;default:2;type:int;comment:是否重新签 1:是 2:否"`
|
ReSignature int `json:"reSignature" gorm:"column:re_signature;default:2;type:int;comment:是否重新签 1:是 2:否"`
|
||||||
PlatformIds PlatformIDs `gorm:"column:platform_ids;type:json;NOT NULL;comment:发布平台ID集合 TIKTOK= 1, YOUTUBE = 2, INS = 3 , DM = 4, BL = 5;" json:"platformIDs"`
|
PlatformIds PlatformIDs `gorm:"column:platform_ids;type:json;NOT NULL;comment:发布平台ID集合 TIKTOK= 1, YOUTUBE = 2, INS = 3 , DM = 4, BL = 5;" json:"platformIDs"`
|
||||||
InviterID uint64 `gorm:"column:inviter_id;type:bigint;comment:邀请人ID" json:"inviterID"`
|
|
||||||
PurchaseType uint64 `gorm:"column:purchase_type;type:bigint;comment:购买类型 1:新购 2:续费" json:"purchaseType"`
|
|
||||||
RenewalOrderUUID string `gorm:"column:renewal_order_uuid;type:varchar(1024);comment:续费订单UUID" json:"renewalOrderUUID"`
|
|
||||||
}
|
}
|
||||||
type BundleOrderValueAdd struct {
|
type BundleOrderValueAdd struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
|
|||||||
@ -239,68 +239,3 @@ type VideoScript struct {
|
|||||||
func (VideoScript) TableName() string {
|
func (VideoScript) TableName() string {
|
||||||
return "cast_video_script"
|
return "cast_video_script"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 竞品报告表
|
|
||||||
type CastCompetitiveReport struct {
|
|
||||||
Uuid string `gorm:"column:uuid;type:varchar(50);NOT NULL;primary_key;" json:"id"`
|
|
||||||
SubNum string `gorm:"column:subNum;type:varchar(50);NOT NULL;default:'';comment:'艺人编号'" json:"subNum"`
|
|
||||||
ArtistName string `gorm:"column:artist_name;type:varchar(50);NOT NULL;default:'';comment:'艺人名字'" json:"artistName"`
|
|
||||||
ArtistID string `gorm:"column:artist_id;type:varchar(50);NOT NULL;default:'';comment:'艺人ID';" json:"artistID"`
|
|
||||||
ArtistPhone string `gorm:"column:artist_phone;type:varchar(50);NOT NULL;default:'';comment:'艺人手机号'" json:"artistPhone"`
|
|
||||||
|
|
||||||
ReportContent string `gorm:"column:report_content;type:text;NOT NULL;comment:报告内容" json:"reportContent"`
|
|
||||||
ImageUrl string `gorm:"column:image_url;type:varchar(255);NOT NULL;default:'';comment:图片url" json:"imageUrl"`
|
|
||||||
Title string `gorm:"column:title;type:varchar(50);NOT NULL;" json:"title"`
|
|
||||||
OperatorID string `gorm:"column:operator_id;type:varchar(50);NOT NULL;default:'';comment:操作人ID" json:"operatorID"`
|
|
||||||
OperatorName string `gorm:"column:operator_name;type:varchar(50);NOT NULL;default:'';comment:操作人名称" json:"operatorName"`
|
|
||||||
WorkReportStatus uint8 `gorm:"column:work_report_status;type:tinyint(1);NOT NULL;default:1;comment: 1 待提交 2 审批中 3 审批驳回 4 待艺人验收 5 验收失败 6 待阅读 7 已阅读" json:"workReportStatus"`
|
|
||||||
Reason string `gorm:"column:reason;type:varchar(255);NOT NULL;default:'';comment:原因" json:"reason"`
|
|
||||||
ComfirmType int `gorm:"column:comfirm_type;type:tinyint(1);NOT NULL;default:0;comment:'确认类型 1 艺人确认 2 系统确认'" json:"comfirmType"`
|
|
||||||
Cost uint8 `gorm:"column:cost;type:tinyint(1);NOT NULL;default:0;comment: 1 消耗 2 未消耗" json:"cost"`
|
|
||||||
SubmitTime string `gorm:"column:submit_time;type:varchar(50);NOT NULL;default:'';comment:'提交时间'" json:"submitTime"`
|
|
||||||
StatusUpdateTime string `gorm:"column:status_update_time;type:varchar(50);NOT NULL;default:'';comment:状态更新时间" json:"statusUpdateTime"`
|
|
||||||
ApprovalID string `gorm:"column:approval_id;type:varchar(50);NOT NULL;default:'';comment:审批ID" json:"approvalID"`
|
|
||||||
ConfirmRemark string `gorm:"column:confirm_remark;type:varchar(300);NOT NULL;default:'';comment:艺人确认备注" json:"confirmRemark"`
|
|
||||||
|
|
||||||
// pdf 的 url 链接
|
|
||||||
PdfUrl string `gorm:"column:pdf_url;type:varchar(255);NOT NULL;default:'';comment:'pdf 的 url 链接'" json:"pdfUrl"`
|
|
||||||
Source uint8 `gorm:"column:source;type:tinyint(1);NOT NULL;default:1;comment: 1 系统 2 导入" json:"source"`
|
|
||||||
|
|
||||||
Extra *CastCompetitiveReportExtra `gorm:"foreignKey:ReportUuid;references:Uuid" json:"extra,omitempty"`
|
|
||||||
WorkItems []CastCompetitiveReportWorkItem `gorm:"foreignKey:ReportUuid;references:Uuid" json:"workItems,omitempty"`
|
|
||||||
|
|
||||||
CreatedAt int `gorm:"column:created_at;type:int(11);autoCreateTime" json:"createdAt"`
|
|
||||||
UpdatedAt int `gorm:"column:updated_at;type:int(11);autoUpdateTime" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (CastCompetitiveReport) TableName() string {
|
|
||||||
return "cast_competitive_report"
|
|
||||||
}
|
|
||||||
|
|
||||||
type CastCompetitiveReportExtra struct {
|
|
||||||
ReportUuid string `gorm:"column:report_uuid;type:varchar(50);NOT NULL;index:idx_report_uuid;default:'';comment:竞品报告uuid;primary_key" json:"reportUuid"`
|
|
||||||
ArtistConfirmedTime int64 `gorm:"column:artist_confirmed_time;type:bigint(20);NOT NULL;default:0;comment:艺人确认时间" json:"artistConfirmedTime"`
|
|
||||||
CostType uint32 `gorm:"column:cost_type;type:tinyint(3);NOT NULL;default:1;comment:计费类型 1 套餐 2 增值" json:"costType"`
|
|
||||||
CreatedAt int `gorm:"column:created_at;type:int(11);autoCreateTime" json:"createdAt"`
|
|
||||||
UpdatedAt int `gorm:"column:updated_at;type:int(11);autoUpdateTime" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (CastCompetitiveReportExtra) TableName() string {
|
|
||||||
return "cast_competitive_report_extra"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 竞品报告作品关联表 - 存储竞品报告关联的作品uuid(最多5个)
|
|
||||||
type CastCompetitiveReportWorkItem struct {
|
|
||||||
// 使用联合主键 (report_uuid, work_uuid) 防止同一报告重复关联同一作品
|
|
||||||
ReportUuid string `gorm:"column:report_uuid;type:varchar(50);NOT NULL;primaryKey;index:idx_report_uuid;default:'';comment:竞品报告uuid" json:"reportUuid"`
|
|
||||||
WorkUuid string `gorm:"column:work_uuid;type:varchar(50);NOT NULL;primaryKey;index:idx_work_uuid;default:'';comment:作品uuid" json:"workUuid"`
|
|
||||||
CreatedAt int `gorm:"column:created_at;type:int(11);autoCreateTime" json:"createdAt"`
|
|
||||||
UpdatedAt int `gorm:"column:updated_at;type:int(11);autoUpdateTime" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
func (CastCompetitiveReportWorkItem) TableName() string {
|
|
||||||
return "cast_competitive_report_work_item"
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,110 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/plugin/soft_delete"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 定义常量
|
|
||||||
const (
|
|
||||||
CurrencyTypeRMB = 1 // 人民币
|
|
||||||
CurrencyTypeUSD = 2 // 美元
|
|
||||||
CurrencyTypeJPY = 3 // 日元
|
|
||||||
)
|
|
||||||
|
|
||||||
// 维护周期
|
|
||||||
const (
|
|
||||||
MaintenanceCycleTypeYear = 1 // 年
|
|
||||||
MaintenanceCycleTypeHalfYear = 2 // 半年
|
|
||||||
MaintenanceCycleTypeQuarter = 3 // 季度
|
|
||||||
MaintenanceCycleTypeMonth = 4 // 月
|
|
||||||
)
|
|
||||||
|
|
||||||
// AttachmentItem 单个附件:DB 中附件字段存的是该结构体数组的 JSON
|
|
||||||
type AttachmentItem struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
FileName string `json:"fileName"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 合同表
|
|
||||||
type Contract struct {
|
|
||||||
ContractUUID string `gorm:"column:contract_uuid;comment:合同UUID" json:"contractUUID"`
|
|
||||||
ContractName string `gorm:"column:contract_name;comment:合同名称" json:"contractName"`
|
|
||||||
ProjectName string `gorm:"column:project_name;comment:项目名称" json:"projectName"`
|
|
||||||
CustomerName string `gorm:"column:customer_name;comment:客户名称" json:"customerName"`
|
|
||||||
ContractorName string `gorm:"column:contractor_name;comment:承办商名称" json:"contractorName"`
|
|
||||||
SigningDate string `gorm:"column:signing_date;comment:签署日期" json:"signingDate"`
|
|
||||||
EffectiveDate string `gorm:"column:effective_date;comment:生效日期" json:"effectiveDate"`
|
|
||||||
|
|
||||||
// 合同总金额
|
|
||||||
ContractAmount float64 `json:"contractAmount" gorm:"column:contract_amount;type:decimal(18,4);comment:合同金额"`
|
|
||||||
ContractCurrencyType int `json:"contractCurrencyType" gorm:"column:contract_currency_type;type:int;comment:合同货币类型"`
|
|
||||||
|
|
||||||
ContractPaymentCycle string `gorm:"column:contract_payment_cycle;type:text;comment:支付周期" json:"contractPaymentCycle"` // 单独一个字段,用来存
|
|
||||||
DevelopmentCycle string `gorm:"column:development_cycle;type:text;comment:开发周期" json:"developmentCycle"` // 单独一个字段,用来存开发周期
|
|
||||||
|
|
||||||
// 维护费用
|
|
||||||
MaintenanceCycleType int `json:"maintenanceCycleType" gorm:"column:maintenance_cycle_type;type:int;comment:维护周期类型"`
|
|
||||||
MaintenanceFee float64 `json:"maintenanceFee" gorm:"column:maintenance_fee;type:decimal(18,4);comment:维护费用"`
|
|
||||||
MaintenanceCurrencyType int `json:"maintenanceCurrencyType" gorm:"column:maintenance_currency_type;type:int;comment:维护货币类型"`
|
|
||||||
|
|
||||||
// 质量保证金
|
|
||||||
QualityAssuranceFee float64 `json:"qualityAssuranceFee" gorm:"column:quality_assurance_fee;type:decimal(18,4);comment:质量保证金额"`
|
|
||||||
QualityAssuranceCurrencyType int `json:"qualityAssuranceCurrencyType" gorm:"column:quality_assurance_currency_type;type:int;comment:质量保证金货币类型"`
|
|
||||||
|
|
||||||
// 附件:JSON 数组,每项为 {"url":"","fileName":""}
|
|
||||||
ContractAttachmentURLs string `gorm:"column:contract_attachment_urls;type:json;comment:合同附件(含url+fileName)" json:"contractAttachmentURLs"`
|
|
||||||
OtherAttachmentURLs string `gorm:"column:other_attachment_urls;type:json;comment:其他附件(含url+fileName)" json:"otherAttachmentURLs"`
|
|
||||||
|
|
||||||
Operator string `gorm:"column:operator;comment:操作人;index:idx_operator" json:"operator"`
|
|
||||||
OperatorID string `gorm:"column:operator_id;type:varchar(50);NOT NULL;default:'';comment:操作人ID" json:"operatorID"`
|
|
||||||
OperatorNum string `gorm:"column:operator_num;comment:操作人账号;index:idx_operator_num" json:"operatorNum"`
|
|
||||||
OperatorTime time.Time `gorm:"column:operator_time;comment:操作时间;index:idx_operator_time;" json:"operatorTime"`
|
|
||||||
|
|
||||||
PaymentCycles []ContractPaymentCycle `gorm:"foreignKey:ContractUUID;references:ContractUUID" json:"paymentCycles"`
|
|
||||||
DevelopmentCycles []DevelopmentCycle `gorm:"foreignKey:ContractUUID;references:ContractUUID" json:"developmentCycles"`
|
|
||||||
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_deleted_at" json:"deletedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Contract) TableName() string {
|
|
||||||
return "contract"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 支付周期子表
|
|
||||||
type ContractPaymentCycle struct {
|
|
||||||
ContractPaymentCycleUUID string `gorm:"column:contract_payment_cycle_uuid;comment:合同支付周期UUID" json:"contractPaymentCycleUUID"`
|
|
||||||
ContractUUID string `gorm:"column:contract_uuid;comment:合同UUID" json:"contractUUID"`
|
|
||||||
PaymentCyclePeriod int `json:"paymentCyclePeriod" gorm:"column:payment_cycle_period;type:int;comment:支付周期第几期"`
|
|
||||||
DeliveryTime string `gorm:"column:delivery_time;type:text;comment:交付时间点" json:"deliveryTime"`
|
|
||||||
ContractPaymentCycleAmount float64 `json:"contractPaymentCycleAmount" gorm:"column:contract_payment_cycle_amount;type:decimal(18,4);comment:合同支付周期金额"`
|
|
||||||
PaymentCycleCurrencyType int `json:"paymentCycleCurrencyType" gorm:"column:payment_cycle_currency_type;type:int;comment:支付周期货币类型"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_deleted_at" json:"deletedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ContractPaymentCycle) TableName() string {
|
|
||||||
return "contract_payment_cycle"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开发周期子表
|
|
||||||
type DevelopmentCycle struct {
|
|
||||||
DevelopmentCycleUUID string `gorm:"column:development_cycle_uuid;comment:开发周期UUID" json:"developmentCycleUUID"`
|
|
||||||
ContractUUID string `gorm:"column:contract_uuid;comment:合同UUID" json:"contractUUID"`
|
|
||||||
DevelopmentPeriod int `json:"developmentPeriod" gorm:"column:development_period;type:int;comment:开发第几期"`
|
|
||||||
DevelopmentTime string `gorm:"column:development_time;type:text;comment:开发时间" json:"developmentTime"`
|
|
||||||
// 附件:JSON 数组,每项为 {"url":"","fileName":""}
|
|
||||||
AttachmentURLs string `gorm:"column:attachment_urls;type:json;comment:附件(含url+fileName)" json:"attachmentURLs"`
|
|
||||||
DeliveryContent string `gorm:"column:delivery_content;type:text;comment:交付内容" json:"deliveryContent"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_deleted_at" json:"deletedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DevelopmentCycle) TableName() string {
|
|
||||||
return "contract_development_cycle"
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/plugin/soft_delete"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 客户表
|
|
||||||
type Customer struct {
|
|
||||||
CustomerID string `gorm:"column:customer_id;type:varchar(50);NOT NULL;primarykey;comment:客户ID" json:"customerID"`
|
|
||||||
CustomerName string `gorm:"column:customer_name;comment:客户名称;uniqueIndex:idx_customer_name_deleted,priority:1" json:"customerName"`
|
|
||||||
AuthorizedRepresentative string `gorm:"column:authorized_representative;comment:授权代表" json:"authorizedRepresentative"`
|
|
||||||
RegistrationAddress string `gorm:"column:registration_address;comment:注册地址" json:"registrationAddress"`
|
|
||||||
ReferralPerson string `gorm:"column:referral_person;comment:推荐人;index:idx_referral_person" json:"referralPerson"` // 增加索引
|
|
||||||
Operator string `gorm:"column:operator;comment:操作人;index:idx_operator" json:"operator"`
|
|
||||||
OperatorID string `gorm:"column:operator_id;type:varchar(50);NOT NULL;default:'';comment:操作人ID" json:"operatorID"`
|
|
||||||
OperatorNum string `gorm:"column:operator_num;comment:操作人账号;index:idx_operator_num" json:"operatorNum"`
|
|
||||||
OperatorTime time.Time `gorm:"column:operator_time;comment:操作时间;index:idx_operator_time;" json:"operatorTime"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_deleted_at;uniqueIndex:idx_customer_name_deleted,priority:2" json:"deletedAt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Customer) TableName() string {
|
|
||||||
return "customer"
|
|
||||||
}
|
|
||||||
@ -1,93 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/plugin/soft_delete"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 发票主表
|
|
||||||
type Invoice struct {
|
|
||||||
ID int64 `gorm:"primarykey"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11)" json:"deletedAt"`
|
|
||||||
UserId int `gorm:"column:user_id;comment:用户ID"`
|
|
||||||
UserNum string `gorm:"column:user_num;comment:用户编号"`
|
|
||||||
UserName string `gorm:"column:user_name;comment:用户名称"`
|
|
||||||
OrderNo string `gorm:"column:order_no;comment:订单编号"`
|
|
||||||
ApplyTime time.Time `gorm:"column:apply_time;comment:申请时间"`
|
|
||||||
InvoiceType int `gorm:"column:invoice_type;comment:发票类型 1基础类型"`
|
|
||||||
InvoiceNo string `gorm:"column:invoice_no;comment:发票编号"`
|
|
||||||
InvoiceUrl string `gorm:"column:invoice_url;comment:发票URL"`
|
|
||||||
PaperInvocieStatus int `gorm:"column:paper_invocie_status;default:1;comment:纸质发票状态1未申请 2已申请 3已邮寄"`
|
|
||||||
Remark string `gorm:"column:remark;comment:备注"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Invoice) TableName() string {
|
|
||||||
return "invoice"
|
|
||||||
}
|
|
||||||
|
|
||||||
// 纸质发票地址
|
|
||||||
type PaperInvoiceAddress struct {
|
|
||||||
ID int64 `gorm:"primarykey"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11)" json:"deletedAt"`
|
|
||||||
UserId int `gorm:"column:user_id;comment:用户ID"`
|
|
||||||
ApplyTime time.Time `gorm:"column:apply_time;comment:申请时间"`
|
|
||||||
OrderNo string `gorm:"column:order_no;comment:订单编号"`
|
|
||||||
InvoiceNo string `gorm:"column:invoice_no;comment:发票编号"`
|
|
||||||
Name string `gorm:"column:name;comment:申请纸质发票姓名"`
|
|
||||||
TelAreaCode string `gorm:"column:tel_area_code;comment:申请纸质发票电话区号"`
|
|
||||||
Phone string `gorm:"column:phone;comment:申请纸质发票电话"`
|
|
||||||
PostalCode string `gorm:"column:postal_code;type:varchar(20);comment:申请纸质发票邮政编码"`
|
|
||||||
Country string `gorm:"column:country;comment:申请纸质发票国家"`
|
|
||||||
Address string `gorm:"column:address;comment:详细地址"`
|
|
||||||
ExpressCompany string `gorm:"column:express_company;comment:快递公司"`
|
|
||||||
ExpressNo string `gorm:"column:express_no;comment:快递单号"`
|
|
||||||
Remark string `gorm:"column:remark;comment:备注"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PaperInvoiceAddress) TableName() string {
|
|
||||||
return "paper_invoice_address"
|
|
||||||
}
|
|
||||||
|
|
||||||
type InvoiceInfo struct {
|
|
||||||
Name string `gorm:"column:name;comment:姓名"`
|
|
||||||
TelAreaCode string `gorm:"column:tel_area_code;comment:电话区号"`
|
|
||||||
Phone string `gorm:"column:phone;comment:电话"`
|
|
||||||
Country string `gorm:"column:country;comment:国家"`
|
|
||||||
Address string `gorm:"column:address;comment:地址"`
|
|
||||||
ApplyTime string `gorm:"column:apply_time;comment:申请时间"`
|
|
||||||
UserName string `gorm:"column:user_name;comment:用户名称"`
|
|
||||||
UserNum string `gorm:"column:user_num;comment:用户编号"`
|
|
||||||
OrderNo string `gorm:"column:order_no;comment:订单编号"`
|
|
||||||
InvoiceNo string `gorm:"column:invoice_no;comment:发票编号"`
|
|
||||||
InvoiceUrl string `gorm:"column:invoice_url;comment:发票URL"`
|
|
||||||
PaperInvocieStatus int64 `gorm:"column:paper_invocie_status;comment:纸质发票状态"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type InvoiceOrderInfo struct {
|
|
||||||
UserName string `gorm:"column:user_name;comment:用户名称"`
|
|
||||||
UserId int64 `gorm:"column:user_id;comment:用户ID"`
|
|
||||||
UserNum string `gorm:"column:user_num;comment:用户编号"`
|
|
||||||
OrderNo string `gorm:"column:order_no;comment:订单编号"`
|
|
||||||
AmountType int64 `gorm:"column:amount_type;comment:金额类型 1:人民币 2:美元"`
|
|
||||||
TotalAmount float32 `gorm:"column:total_amount;comment:总金额"`
|
|
||||||
BundleName string `gorm:"column:bundle_name;comment:套餐名称"`
|
|
||||||
Address string `gorm:"column:address;comment:地址"`
|
|
||||||
Phone string `gorm:"column:phone;comment:电话"`
|
|
||||||
PayTime string `gorm:"column:pay_time;comment:支付时间"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type InvoiceInfoByOrderNo struct {
|
|
||||||
OrderNo string `gorm:"column:order_no;comment:订单编号"`
|
|
||||||
InvoiceNo string `gorm:"column:invoice_no;comment:发票编号"`
|
|
||||||
InvoiceUrl string `gorm:"column:invoice_url;comment:发票URL"`
|
|
||||||
BundleName string `gorm:"column:bundle_name;comment:套餐名称"`
|
|
||||||
AmountType int64 `gorm:"column:amount_type;comment:金额类型 1:人民币 2:美元"`
|
|
||||||
TotalAmount float32 `gorm:"column:total_amount;comment:总金额"`
|
|
||||||
PayTime string `gorm:"column:pay_time;comment:支付时间"`
|
|
||||||
PaperInvocieStatus int64 `gorm:"column:paper_invocie_status;comment:纸质发票状态 1:未申请 2:已申请 3:已邮寄"`
|
|
||||||
}
|
|
||||||
@ -1,75 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type QuestionnaireSurvey struct {
|
|
||||||
gorm.Model
|
|
||||||
SurveyUUID string `gorm:"column:survey_uuid;comment:问卷UUID" json:"survey_uuid"`
|
|
||||||
UserId int `gorm:"column:user_id;comment:用户ID" json:"user_id"`
|
|
||||||
UserNum string `gorm:"column:user_num;comment:用户编号" json:"user_num"`
|
|
||||||
UserName string `gorm:"column:user_name;comment:用户姓名" json:"user_name"`
|
|
||||||
UserTel string `gorm:"column:user_tel;comment:用户电话" json:"user_tel"`
|
|
||||||
OrderUUID string `gorm:"column:order_uuid;comment:订单UUID" json:"order_uuid"`
|
|
||||||
SendTime time.Time `gorm:"column:send_time;comment:发送时间" json:"send_time"`
|
|
||||||
SubmitTime time.Time `gorm:"column:submit_time;comment:提交时间" json:"submit_time"`
|
|
||||||
SurveyTitle string `gorm:"column:survey_title;comment:问卷标题" json:"survey_title"`
|
|
||||||
SurveyStatus int `gorm:"column:survey_status;comment:问卷状态 1:已发送 2:已提交" json:"survey_status"`
|
|
||||||
BundleInfo string `gorm:"column:bundle_info;type:varchar(1024);comment:套餐信息" json:"bundle_info"`
|
|
||||||
SurveyAnswer string `gorm:"column:survey_answer;type:varchar(512);comment:问卷答案" json:"survey_answer"`
|
|
||||||
MeritsReview string `gorm:"column:merits_review;type:varchar(512);comment:优点评价" json:"merits_review"`
|
|
||||||
SuggestionsorImprovements string `gorm:"column:suggestionsor_improvements;type:varchar(512);comment:改进建议" json:"suggestionsor_improvements"`
|
|
||||||
AdditionalComments string `gorm:"column:additional_comments;type:varchar(512);comment:补充意见" json:"additional_comments"`
|
|
||||||
SurveyUrl string `gorm:"column:survey_url;comment:问卷URL" json:"survey_url"`
|
|
||||||
SubmitBy string `gorm:"column:submit_by;comment:提交人" json:"submit_by"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (QuestionnaireSurvey) TableName() string {
|
|
||||||
return "questionnaire_survey"
|
|
||||||
}
|
|
||||||
|
|
||||||
type BundleInfo struct {
|
|
||||||
BundleName string `gorm:"column:bundle_name;not null;comment:套餐名称" json:"bundle_name"`
|
|
||||||
StartAt time.Time `gorm:"column:start_at;type:datetime;comment:套餐开始时间"`
|
|
||||||
ExpiredAt time.Time `gorm:"column:expired_at;type:datetime;comment:套餐过期时间"`
|
|
||||||
BundleAccountNumber int `gorm:"column:bundle_account_number;not null;comment:套餐账号数量" json:"bundle_account_number"`
|
|
||||||
BundleVideoNumber int `gorm:"column:bundle_video_number;not null;comment:套餐视频数量" json:"bundle_video_number"`
|
|
||||||
IncreaseVideoNumber int `gorm:"column:increase_video_number;not null;comment:增值视频数量" json:"increase_video_number"`
|
|
||||||
BundleImageNumber int `gorm:"column:bundle_image_number;not null;comment:套餐图片数量" json:"bundle_image_number"`
|
|
||||||
BundleDataNumber int `gorm:"column:bundle_data_number;not null;comment:套餐数据数量" json:"bundle_data_number"`
|
|
||||||
BundleCompetitiveNumber int `gorm:"column:bundle_competitive_number;not null;comment:套餐竞品数量" json:"bundle_competitive_number"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SurveyAnswer struct {
|
|
||||||
BundleAccountScore int32 `gorm:"column:bundle_account_score;not null;comment:套餐账号评分" json:"bundle_account_score"`
|
|
||||||
BundleVideoScore int32 `gorm:"column:bundle_video_score;not null;comment:套餐视频评分" json:"bundle_video_score"`
|
|
||||||
IncreaseVideoScore int32 `gorm:"column:increase_video_score;not null;comment:增值视频评分" json:"increase_video_score"`
|
|
||||||
BundleImageScore int32 `gorm:"column:bundle_image_score;not null;comment:套餐图片评分" json:"bundle_image_score"`
|
|
||||||
BundleDataScore int32 `gorm:"column:bundle_data_score;not null;comment:套餐数据评分" json:"bundle_data_score"`
|
|
||||||
BundleCompetitiveScore int32 `gorm:"column:bundle_competitive_score;not null;comment:套餐竞品评分" json:"bundle_competitive_score"`
|
|
||||||
ServiceResponseSpeed int32 `gorm:"column:service_response_speed;not null;comment:服务响应速度评分" json:"service_response_speed"`
|
|
||||||
ServiceStaffProfessionalism int32 `gorm:"column:service_staff_professionalism;not null;comment:服务人员专业性评分" json:"service_staff_professionalism"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserInfo struct {
|
|
||||||
UserId int `gorm:"column:user_id;not null;comment:用户ID" json:"user_id"`
|
|
||||||
UserNum string `gorm:"column:user_num;not null;comment:用户编号" json:"user_num"`
|
|
||||||
UserName string `gorm:"column:user_name;not null;comment:用户姓名" json:"user_name"`
|
|
||||||
UserTel string `gorm:"column:user_tel;not null;comment:用户电话" json:"user_tel"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type DbBundleInfo struct {
|
|
||||||
UserName string `json:"user_name"`
|
|
||||||
BundleName string `json:"bundle_name"`
|
|
||||||
StartAt time.Time `json:"start_at"`
|
|
||||||
ExpiredAt time.Time `json:"expired_at"`
|
|
||||||
BundleAccountNumber int32 `json:"bundle_account_number"`
|
|
||||||
BundleVideoNumber int32 `json:"bundle_video_number"`
|
|
||||||
IncreaseVideoNumber int32 `json:"increase_video_number"`
|
|
||||||
BundleImageNumber int32 `json:"bundle_image_number"`
|
|
||||||
BundleDataNumber int32 `json:"bundle_data_number"`
|
|
||||||
BundleCompetitiveNumber int32 `json:"bundle_competitive_number"`
|
|
||||||
}
|
|
||||||
@ -12,7 +12,6 @@ var OrderByDataAnalysis = map[string]string{
|
|||||||
"increase_data_analysis_total": "increase_data_total",
|
"increase_data_analysis_total": "increase_data_total",
|
||||||
"released_data_analysis_total": "released_data_total",
|
"released_data_analysis_total": "released_data_total",
|
||||||
"pending_data_analysis_count": "pending_data_count",
|
"pending_data_analysis_count": "pending_data_count",
|
||||||
"sub_num": "customer_num",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var OrderByPending = map[string]string{
|
var OrderByPending = map[string]string{
|
||||||
@ -20,7 +19,6 @@ var OrderByPending = map[string]string{
|
|||||||
"pending_post_count": "assign_post_count",
|
"pending_post_count": "assign_post_count",
|
||||||
"pending_data_count": "assign_data_count",
|
"pending_data_count": "assign_data_count",
|
||||||
"pending_video_script_count": "assign_video_script_count",
|
"pending_video_script_count": "assign_video_script_count",
|
||||||
"pending_report_count": "assign_report_count",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TaskManagement struct {
|
type TaskManagement struct {
|
||||||
@ -66,19 +64,16 @@ type TaskAssignRecords struct {
|
|||||||
PendingVideoCount int `gorm:"column:pending_video_count;comment:待发视频数量" json:"pendingVideoCount"`
|
PendingVideoCount int `gorm:"column:pending_video_count;comment:待发视频数量" json:"pendingVideoCount"`
|
||||||
PendingPostCount int `gorm:"column:pending_post_count;comment:待发图文数量" json:"pendingPostCount"`
|
PendingPostCount int `gorm:"column:pending_post_count;comment:待发图文数量" json:"pendingPostCount"`
|
||||||
PendingDataCount int `gorm:"column:pending_data_count;comment:待发数据数量" json:"pendingDataCount"`
|
PendingDataCount int `gorm:"column:pending_data_count;comment:待发数据数量" json:"pendingDataCount"`
|
||||||
PendingReportCount int `gorm:"column:pending_report_count;comment:待发竞品报告数量" json:"pendingReportCount"`
|
|
||||||
// 指派视频脚本数
|
// 指派视频脚本数
|
||||||
AssignVideoScriptCount int `gorm:"column:assign_video_script_count;comment:指派待发视频脚本数" json:"assignVideoScriptCount"`
|
AssignVideoScriptCount int `gorm:"column:assign_video_script_count;comment:指派待发视频脚本数" json:"assignVideoScriptCount"`
|
||||||
AssignVideoCount int `gorm:"column:assign_video_count;comment:指派待发视频数" json:"assignVideoCount"`
|
AssignVideoCount int `gorm:"column:assign_video_count;comment:指派待发视频数" json:"assignVideoCount"`
|
||||||
AssignPostCount int `gorm:"column:assign_post_count;comment:指派待发图文数" json:"assignPostCount"`
|
AssignPostCount int `gorm:"column:assign_post_count;comment:指派待发图文数" json:"assignPostCount"`
|
||||||
AssignDataCount int `gorm:"column:assign_data_count;comment:指派待发数据数" json:"assignDataCount"`
|
AssignDataCount int `gorm:"column:assign_data_count;comment:指派待发数据数" json:"assignDataCount"`
|
||||||
AssignReportCount int `gorm:"column:assign_report_count;comment:指派待发竞品报告数" json:"assignReportCount"`
|
|
||||||
// 已完成视频脚本数
|
// 已完成视频脚本数
|
||||||
CompleteVideoScriptCount int `gorm:"column:complete_video_script_count;comment:已完成视频脚本数" json:"completeVideoScriptCount"`
|
CompleteVideoScriptCount int `gorm:"column:complete_video_script_count;comment:已完成视频脚本数" json:"completeVideoScriptCount"`
|
||||||
CompleteVideoCount int `gorm:"column:complete_video_count;comment:已完成视频数" json:"completeVideoCount"`
|
CompleteVideoCount int `gorm:"column:complete_video_count;comment:已完成视频数" json:"completeVideoCount"`
|
||||||
CompletePostCount int `gorm:"column:complete_post_count;comment:已完成图文数" json:"completePostCount"`
|
CompletePostCount int `gorm:"column:complete_post_count;comment:已完成图文数" json:"completePostCount"`
|
||||||
CompleteDataCount int `gorm:"column:complete_data_count;comment:已完成数据数" json:"completeDataCount"`
|
CompleteDataCount int `gorm:"column:complete_data_count;comment:已完成数据数" json:"completeDataCount"`
|
||||||
CompleteReportCount int `gorm:"column:complete_report_count;comment:已完成竞品报告数" json:"completeReportCount"`
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间;index:idx_updated_at" json:"updatedAt"`
|
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间;index:idx_updated_at" json:"updatedAt"`
|
||||||
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_assign_deleted_at" json:"deletedAt"`
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_assign_deleted_at" json:"deletedAt"`
|
||||||
@ -88,12 +83,10 @@ func (t *TaskAssignRecords) TableName() string {
|
|||||||
return "task_assign_records"
|
return "task_assign_records"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 指派记录的完成明细表
|
|
||||||
// 用于记录每次完成的具体 UUID,保障可追溯与可回滚,避免仅靠汇总计数导致不可逆的统计偏差。
|
|
||||||
type TaskAssignUUIDItems struct {
|
type TaskAssignUUIDItems struct {
|
||||||
ID int64 `gorm:"primarykey;autoIncrement"`
|
ID int64 `gorm:"primarykey;autoIncrement"`
|
||||||
AssignRecordsUUID string `gorm:"column:assign_records_uuid;comment:指派记录UUID;index:idx_assign_records_uuid;index:idx_assign_records_uuid_type,priority:1" json:"assignRecordsUUID"`
|
AssignRecordsUUID string `gorm:"column:assign_records_uuid;comment:指派记录UUID;index:idx_assign_records_uuid;index:idx_assign_records_uuid_type,priority:1" json:"assignRecordsUUID"`
|
||||||
Type int `gorm:"column:type;comment:指派类型 1:视频 2:图文 3:数据 4:视频脚本 5:竞品报告;index:idx_assign_records_uuid_type,priority:2" json:"type"`
|
Type int `gorm:"column:type;comment:指派类型 1:视频 2:图文 3:数据 4:视频脚本;index:idx_assign_records_uuid_type,priority:2" json:"type"`
|
||||||
UUID string `gorm:"column:uuid;comment:任务UUID;index:idx_uuid" json:"uuid"`
|
UUID string `gorm:"column:uuid;comment:任务UUID;index:idx_uuid" json:"uuid"`
|
||||||
|
|
||||||
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
||||||
@ -114,6 +107,140 @@ func (TaskPendingLayout) TableName() string {
|
|||||||
return "task_pending_layout"
|
return "task_pending_layout"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 任务余额表
|
||||||
|
type TaskBalance struct {
|
||||||
|
ID int64 `gorm:"primarykey"`
|
||||||
|
SubNum string `gorm:"column:sub_num;comment:用户编号;index:idx_task_sub_num;not null" json:"subNum"`
|
||||||
|
TelNum string `gorm:"column:tel_num;comment:手机号;index:idx_task_tel_num;not null" json:"telNum"`
|
||||||
|
Month string `gorm:"column:month;type:varchar(32);comment:月份;index:idx_task_month;not null" json:"month"`
|
||||||
|
ExpiredAt time.Time `gorm:"column:expired_at;type:datetime;comment:任务过期时间" json:"expiredAt"`
|
||||||
|
StartAt time.Time `gorm:"column:start_at;type:datetime;comment:任务开始时间" json:"startAt"`
|
||||||
|
|
||||||
|
// ===== 视频类 =====
|
||||||
|
BundleVideoNumber int `gorm:"column:bundle_video_number;not null;comment:非限制类型套餐权益视频总数"`
|
||||||
|
IncreaseVideoNumber int `gorm:"column:increase_video_number;not null;comment:非限制类型增值权益视频总数"`
|
||||||
|
BundleLimitVideoNumber int `gorm:"column:bundle_limit_video_number;not null;comment:套餐权益限制类型非过期总数"`
|
||||||
|
IncreaseLimitVideoNumber int `gorm:"column:increase_limit_video_number;not null;comment:增值权益限制类型非过期总数"`
|
||||||
|
BundleLimitVideoExpiredNumber int `gorm:"column:bundle_limit_video_expired_number;not null;comment:套餐权益限制类型会过期总数"`
|
||||||
|
IncreaseLimitVideoExpiredNumber int `gorm:"column:increase_limit_video_expired_number;not null;comment:增值权益限制类型会过期总数"`
|
||||||
|
MonthlyInvalidBundleVideoNumber int `gorm:"column:monthly_invalid_bundle_video_number;not null;comment:当月失效的套餐权益视频总数"`
|
||||||
|
InvalidBundleVideoNumber int `gorm:"column:invalid_bundle_video_number;not null;comment:历史失效的套餐权益视频总数"`
|
||||||
|
MonthlyInvalidIncreaseVideoNumber int `gorm:"column:monthly_invalid_increase_video_number;not null;comment:当月失效的增值权益视频总数"`
|
||||||
|
InvalidIncreaseVideoNumber int `gorm:"column:invalid_increase_video_number;not null;comment:历史失效的增值权益视频总数"`
|
||||||
|
BundleVideoConsumptionNumber int `gorm:"column:bundle_video_consumption_number;not null;comment:非限制类型套餐权益视频使用数"`
|
||||||
|
IncreaseVideoConsumptionNumber int `gorm:"column:increase_video_consumption_number;not null;comment:非限制类型增值权益视频使用数"`
|
||||||
|
BundleLimitVideoConsumptionNumber int `gorm:"column:bundle_limit_video_consumption_number;not null;comment:套餐权益限制类型非过期使用数"`
|
||||||
|
IncreaseLimitVideoConsumptionNumber int `gorm:"column:increase_limit_video_consumption_number;not null;comment:增值权益限制类型非过期使用数"`
|
||||||
|
BundleLimitVideoExpiredConsumptionNumber int `gorm:"column:bundle_limit_video_expired_consumption_number;not null;comment:套餐权益限制类型会过期使用数"`
|
||||||
|
IncreaseLimitVideoExpiredConsumptionNumber int `gorm:"column:increase_limit_video_expired_consumption_number;not null;comment:增值权益限制类型会过期使用数"`
|
||||||
|
MonthlyBundleVideoConsumptionNumber int `gorm:"column:monthly_bundle_video_consumption_number;not null;comment:当月套餐类型视频已使用额度"`
|
||||||
|
MonthlyIncreaseVideoConsumptionNumber int `gorm:"column:monthly_increase_video_consumption_number;not null;comment:当月增值类型视频已使用额度"`
|
||||||
|
MonthlyBundleLimitVideoNumber int `gorm:"column:monthly_bundle_limit_video_number;not null;comment:当月套餐限制类型视频可使用额度"`
|
||||||
|
MonthlyIncreaseLimitVideoNumber int `gorm:"column:monthly_increase_limit_video_number;not null;comment:当月增值限制类型视频可使用额度"`
|
||||||
|
MonthlyBundleLimitVideoConsumptionNumber int `gorm:"column:monthly_bundle_limit_video_consumption_number;not null;comment:当月套餐限制类型视频已使用额度"`
|
||||||
|
MonthlyIncreaseLimitVideoConsumptionNumber int `gorm:"column:monthly_increase_limit_video_consumption_number;not null;comment:当月增值限制类型视频已使用额度"`
|
||||||
|
MonthlyBundleLimitExpiredVideoNumber int `gorm:"column:monthly_bundle_limit_expired_video_number;not null;comment:当月套餐限制类会过期型视频可使用额度"`
|
||||||
|
MonthlyIncreaseLimitExpiredVideoNumber int `gorm:"column:monthly_increase_limit_expired_video_number;not null;comment:当月增值限制类会过期型视频可使用额度"`
|
||||||
|
MonthlyBundleLimitExpiredVideoConsumptionNumber int `gorm:"column:monthly_bundle_limit_expired_video_consumption_number;not null;comment:当月套餐限制类型会过期视频已使用额度"`
|
||||||
|
MonthlyIncreaseLimitExpiredVideoConsumptionNumber int `gorm:"column:monthly_increase_limit_expired_video_consumption_number;not null;comment:当月增值限制类会过期型视频已使用额度"`
|
||||||
|
MonthlyLimitVideoQuotaNumber int `gorm:"column:monthly_limit_video_quota_number;not null;comment:当月限制类型视频额度"`
|
||||||
|
ManualVideoNumber int `gorm:"column:manual_video_number;comment:手动扩展视频总数"`
|
||||||
|
ManualVideoConsumptionNumber int `gorm:"column:manual_video_consumption_number;comment:手动扩展视频使用数"`
|
||||||
|
MonthlyNewManualVideoNumber int `gorm:"column:monthly_new_manual_video_number;comment:当月手动扩展视频新增数"`
|
||||||
|
MonthlyManualVideoConsumptionNumber int `gorm:"column:monthly_manual_video_consumption_number;comment:当月手动扩展视频使用数"`
|
||||||
|
|
||||||
|
// ===== 图片类 =====
|
||||||
|
BundleImageNumber int `gorm:"column:bundle_image_number;not null;comment:非限制类型套餐权益图片总数"`
|
||||||
|
IncreaseImageNumber int `gorm:"column:increase_image_number;not null;comment:非限制类型增值权益图片总数"`
|
||||||
|
BundleLimitImageNumber int `gorm:"column:bundle_limit_image_number;not null;comment:套餐权益限制类型非过期总数"`
|
||||||
|
IncreaseLimitImageNumber int `gorm:"column:increase_limit_image_number;not null;comment:增值权益限制类型非过期总数"`
|
||||||
|
BundleLimitImageExpiredNumber int `gorm:"column:bundle_limit_image_expired_number;not null;comment:套餐权益限制类型会过期总数"`
|
||||||
|
IncreaseLimitImageExpiredNumber int `gorm:"column:increase_limit_image_expired_number;not null;comment:增值权益限制类型会过期总数"`
|
||||||
|
MonthlyInvalidBundleImageNumber int `gorm:"column:monthly_invalid_bundle_image_number;not null;comment:当月失效的套餐权益图片总数"`
|
||||||
|
InvalidBundleImageNumber int `gorm:"column:invalid_bundle_image_number;not null;comment:历史失效的套餐权益图片总数"`
|
||||||
|
MonthlyInvalidIncreaseImageNumber int `gorm:"column:monthly_invalid_increase_image_number;not null;comment:当月失效的增值权益图片总数"`
|
||||||
|
InvalidIncreaseImageNumber int `gorm:"column:invalid_increase_image_number;not null;comment:历史失效的增值权益图片总数"`
|
||||||
|
BundleImageConsumptionNumber int `gorm:"column:bundle_image_consumption_number;not null;comment:非限制类型套餐权益图片使用数"`
|
||||||
|
IncreaseImageConsumptionNumber int `gorm:"column:increase_image_consumption_number;not null;comment:非限制类型增值权益图片使用数"`
|
||||||
|
BundleLimitImageConsumptionNumber int `gorm:"column:bundle_limit_image_consumption_number;not null;comment:套餐权益限制类型非过期使用数"`
|
||||||
|
IncreaseLimitImageConsumptionNumber int `gorm:"column:increase_limit_image_consumption_number;not null;comment:增值权益限制类型非过期使用数"`
|
||||||
|
BundleLimitImageExpiredConsumptionNumber int `gorm:"column:bundle_limit_image_expired_consumption_number;not null;comment:套餐权益限制类型会过期使用数"`
|
||||||
|
IncreaseLimitImageExpiredConsumptionNumber int `gorm:"column:increase_limit_image_expired_consumption_number;not null;comment:增值权益限制类型会过期使用数"`
|
||||||
|
MonthlyBundleImageConsumptionNumber int `gorm:"column:monthly_bundle_image_consumption_number;not null;comment:当月套餐类型图片已使用额度"`
|
||||||
|
MonthlyIncreaseImageConsumptionNumber int `gorm:"column:monthly_increase_image_consumption_number;not null;comment:当月增值类型图片已使用额度"`
|
||||||
|
MonthlyBundleLimitImageNumber int `gorm:"column:monthly_bundle_limit_image_number;not null;comment:当月套餐限制类型图片可使用额度"`
|
||||||
|
MonthlyIncreaseLimitImageNumber int `gorm:"column:monthly_increase_limit_image_number;not null;comment:当月增值限制类型图片可使用额度"`
|
||||||
|
MonthlyBundleLimitImageConsumptionNumber int `gorm:"column:monthly_bundle_limit_image_consumption_number;not null;comment:当月套餐限制类型图片已使用额度"`
|
||||||
|
MonthlyIncreaseLimitImageConsumptionNumber int `gorm:"column:monthly_increase_limit_image_consumption_number;not null;comment:当月增值限制类型图片已使用额度"`
|
||||||
|
MonthlyBundleLimitExpiredImageNumber int `gorm:"column:monthly_bundle_limit_expired_image_number;not null;comment:当月套餐限制类会过期型图片可使用额度"`
|
||||||
|
MonthlyIncreaseLimitExpiredImageNumber int `gorm:"column:monthly_increase_limit_expired_image_number;not null;comment:当月增值限制类会过期型图片可使用额度"`
|
||||||
|
MonthlyBundleLimitExpiredImageConsumptionNumber int `gorm:"column:monthly_bundle_limit_expired_image_consumption_number;not null;comment:当月套餐限制类型会过期图片已使用额度"`
|
||||||
|
MonthlyIncreaseLimitExpiredImageConsumptionNumber int `gorm:"column:monthly_increase_limit_expired_image_consumption_number;not null;comment:当月增值限制类会过期型图片已使用额度"`
|
||||||
|
MonthlyLimitImageQuotaNumber int `gorm:"column:monthly_limit_image_quota_number;not null;comment:当月限制类型图片额度"`
|
||||||
|
ManualImageNumber int `gorm:"column:manual_image_number;comment:手动扩展图片总数"`
|
||||||
|
ManualImageConsumptionNumber int `gorm:"column:manual_image_consumption_number;comment:手动扩展图片使用数"`
|
||||||
|
MonthlyNewManualImageNumber int `gorm:"column:monthly_new_manual_image_number;comment:当月手动扩展图片新增数"`
|
||||||
|
MonthlyManualImageConsumptionNumber int `gorm:"column:monthly_manual_image_consumption_number;comment:当月手动扩展图片使用数"`
|
||||||
|
|
||||||
|
// ===== 数据分析类 =====
|
||||||
|
BundleDataAnalysisNumber int `gorm:"column:bundle_data_analysis_number;not null;comment:非限制类型套餐权益数据分析总数"`
|
||||||
|
IncreaseDataAnalysisNumber int `gorm:"column:increase_data_analysis_number;not null;comment:非限制类型增值权益数据分析总数"`
|
||||||
|
BundleLimitDataAnalysisNumber int `gorm:"column:bundle_limit_data_analysis_number;not null;comment:套餐权益限制类型非过期总数"`
|
||||||
|
IncreaseLimitDataAnalysisNumber int `gorm:"column:increase_limit_data_analysis_number;not null;comment:增值权益限制类型非过期总数"`
|
||||||
|
BundleLimitDataAnalysisExpiredNumber int `gorm:"column:bundle_limit_data_analysis_expired_number;not null;comment:套餐权益限制类型会过期总数"`
|
||||||
|
IncreaseLimitDataAnalysisExpiredNumber int `gorm:"column:increase_limit_data_analysis_expired_number;not null;comment:增值权益限制类型会过期总数"`
|
||||||
|
MonthlyInvalidBundleDataAnalysisNumber int `gorm:"column:monthly_invalid_bundle_data_analysis_number;not null;comment:当月失效的套餐权益数据分析总数"`
|
||||||
|
InvalidBundleDataAnalysisNumber int `gorm:"column:invalid_bundle_data_analysis_number;not null;comment:历史失效的套餐权益数据分析总数"`
|
||||||
|
MonthlyInvalidIncreaseDataAnalysisNumber int `gorm:"column:monthly_invalid_increase_data_analysis_number;not null;comment:当月失效的增值权益数据分析总数"`
|
||||||
|
InvalidIncreaseDataAnalysisNumber int `gorm:"column:invalid_increase_data_analysis_number;not null;comment:历史失效的增值权益数据分析总数"`
|
||||||
|
BundleDataAnalysisConsumptionNumber int `gorm:"column:bundle_data_analysis_consumption_number;not null;comment:非限制类型套餐权益数据分析使用数"`
|
||||||
|
IncreaseDataAnalysisConsumptionNumber int `gorm:"column:increase_data_analysis_consumption_number;not null;comment:非限制类型增值权益数据分析使用数"`
|
||||||
|
BundleLimitDataAnalysisConsumptionNumber int `gorm:"column:bundle_limit_data_analysis_consumption_number;not null;comment:套餐权益限制类型非过期使用数"`
|
||||||
|
IncreaseLimitDataAnalysisConsumptionNumber int `gorm:"column:increase_limit_data_analysis_consumption_number;not null;comment:增值权益限制类型非过期使用数"`
|
||||||
|
BundleLimitDataAnalysisExpiredConsumptionNumber int `gorm:"column:bundle_limit_data_analysis_expired_consumption_number;not null;comment:套餐权益限制类型会过期使用数"`
|
||||||
|
IncreaseLimitDataAnalysisExpiredConsumptionNumber int `gorm:"column:increase_limit_data_analysis_expired_consumption_number;not null;comment:增值权益限制类型会过期使用数"`
|
||||||
|
MonthlyBundleDataAnalysisConsumptionNumber int `gorm:"column:monthly_bundle_data_analysis_consumption_number;not null;comment:当月套餐类型数据分析已使用额度"`
|
||||||
|
MonthlyIncreaseDataAnalysisConsumptionNumber int `gorm:"column:monthly_increase_data_analysis_consumption_number;not null;comment:当月增值类型数据分析已使用额度"`
|
||||||
|
MonthlyBundleLimitDataAnalysisNumber int `gorm:"column:monthly_bundle_limit_data_analysis_number;not null;comment:当月套餐限制类型数据分析可使用额度"`
|
||||||
|
MonthlyIncreaseLimitDataAnalysisNumber int `gorm:"column:monthly_increase_limit_data_analysis_number;not null;comment:当月增值限制类型数据分析可使用额度"`
|
||||||
|
MonthlyBundleLimitDataAnalysisConsumptionNumber int `gorm:"column:monthly_bundle_limit_data_analysis_consumption_number;not null;comment:当月套餐限制类型数据分析已使用额度"`
|
||||||
|
MonthlyIncreaseLimitDataAnalysisConsumptionNumber int `gorm:"column:monthly_increase_limit_data_analysis_consumption_number;not null;comment:当月增值限制类型数据分析已使用额度"`
|
||||||
|
MonthlyBundleLimitExpiredDataAnalysisNumber int `gorm:"column:monthly_bundle_limit_expired_data_analysis_number;not null;comment:当月套餐限制类会过期型数据分析可使用额度"`
|
||||||
|
MonthlyIncreaseLimitExpiredDataAnalysisNumber int `gorm:"column:monthly_increase_limit_expired_data_analysis_number;not null;comment:当月增值限制类会过期型数据分析可使用额度"`
|
||||||
|
MonthlyBundleLimitExpiredDataAnalysisConsumptionNumber int `gorm:"column:monthly_bundle_limit_expired_data_analysis_consumption_number;not null;comment:当月套餐限制类型会过期数据分析已使用额度"`
|
||||||
|
MonthlyIncreaseLimitExpiredDataAnalysisConsumptionNumber int `gorm:"column:monthly_increase_limit_expired_data_analysis_consumption_number;not null;comment:当月增值限制类会过期型数据分析已使用额度"`
|
||||||
|
MonthlyLimitDataAnalysisQuotaNumber int `gorm:"column:monthly_limit_data_analysis_quota_number;not null;comment:当月限制类型数据分析额度"`
|
||||||
|
ManualDataAnalysisNumber int `gorm:"column:manual_data_analysis_number;comment:手动扩展数据分析总数"`
|
||||||
|
ManualDataAnalysisConsumptionNumber int `gorm:"column:manual_data_analysis_consumption_number;comment:手动扩展数据分析使用数"`
|
||||||
|
MonthlyNewManualDataAnalysisNumber int `gorm:"column:monthly_new_manual_data_analysis_number;comment:当月手动扩展数据分析新增数"`
|
||||||
|
MonthlyManualDataAnalysisConsumptionNumber int `gorm:"column:monthly_manual_data_analysis_consumption_number;comment:当月手动扩展数据分析使用数"`
|
||||||
|
|
||||||
|
MonthlyNewDurationNumber int `gorm:"column:monthly_new_duration_number;comment:当月新增手动扩展时长(天)"`
|
||||||
|
ExpansionPacksNumber int `gorm:"column:expansion_packs_number;not null;comment:扩展包数量"`
|
||||||
|
|
||||||
|
CreatedAt time.Time `gorm:"column:created_at;comment:创建时间" json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `gorm:"column:updated_at;comment:更新时间" json:"updatedAt"`
|
||||||
|
DeletedAt soft_delete.DeletedAt `gorm:"column:deleted_at;type:int(11);index:idx_task_balance_deleted_at" json:"deletedAt"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TaskBalance) TableName() string {
|
||||||
|
return "task_balance_new"
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskSyncStatus 用于标记一次性任务余额同步是否已经执行
|
||||||
|
// 记录键唯一,避免重复执行
|
||||||
|
type TaskSyncStatus struct {
|
||||||
|
ID int64 `gorm:"primarykey"`
|
||||||
|
SyncKey string `gorm:"column:sync_key;type:varchar(100);uniqueIndex;not null"`
|
||||||
|
ExecutedAt time.Time `gorm:"column:executed_at;type:datetime;not null"`
|
||||||
|
Remark string `gorm:"column:remark;type:varchar(255)"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (TaskSyncStatus) TableName() string { return "task_sync_status" }
|
||||||
|
|
||||||
|
// InitialSyncKey 一次性同步的唯一标识键
|
||||||
|
const InitialSyncKey = "bundle_to_task_balance_initial_sync"
|
||||||
|
|
||||||
// 隐藏指派人表
|
// 隐藏指派人表
|
||||||
type TaskAssigneeHidden struct {
|
type TaskAssigneeHidden struct {
|
||||||
// 让id自增
|
// 让id自增
|
||||||
@ -144,7 +271,7 @@ type TaskWorkLog struct {
|
|||||||
|
|
||||||
// ===== 操作信息 =====
|
// ===== 操作信息 =====
|
||||||
OperationType int `gorm:"column:operation_type;type:int(11);comment:任务操作类型 1:加任务 2:消耗任务 3:完成任务;4:任务过期;index:idx_operation_type;not null" default:"0" json:"operationType"`
|
OperationType int `gorm:"column:operation_type;type:int(11);comment:任务操作类型 1:加任务 2:消耗任务 3:完成任务;4:任务过期;index:idx_operation_type;not null" default:"0" json:"operationType"`
|
||||||
TaskType int `gorm:"column:task_type;type:int(11);comment:任务类型 1:视频 2:图片 3:数据分析 4:视频脚本 5:竞品报告;index:idx_task_type;not null" default:"0" json:"taskType"`
|
TaskType int `gorm:"column:task_type;type:int(11);comment:任务类型 1:视频 2:图片 3:数据分析;index:idx_task_type;not null" default:"0" json:"taskType"`
|
||||||
TaskCount int `gorm:"column:task_count;type:int(11);comment:任务数量;not null" default:"0" json:"taskCount"`
|
TaskCount int `gorm:"column:task_count;type:int(11);comment:任务数量;not null" default:"0" json:"taskCount"`
|
||||||
Remark string `gorm:"column:remark;type:varchar(500);comment:任务备注" default:"" json:"remark"`
|
Remark string `gorm:"column:remark;type:varchar(500);comment:任务备注" default:"" json:"remark"`
|
||||||
|
|
||||||
|
|||||||
818
pb/bundle.proto
818
pb/bundle.proto
File diff suppressed because it is too large
Load Diff
16854
pb/bundle/bundle.pb.go
16854
pb/bundle/bundle.pb.go
File diff suppressed because it is too large
Load Diff
@ -17,9 +17,6 @@ var _ = proto.Marshal
|
|||||||
var _ = fmt.Errorf
|
var _ = fmt.Errorf
|
||||||
var _ = math.Inf
|
var _ = math.Inf
|
||||||
|
|
||||||
func (this *GetInEffectOrderRecordRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *QueryTheOrderSnapshotInformationReq) Validate() error {
|
func (this *QueryTheOrderSnapshotInformationReq) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -368,6 +365,12 @@ func (this *BatchGetValueAddServiceLangResponse) Validate() error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (this *UpdateBundleBalanceReq) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (this *UpdateBundleBalanceResp) Validate() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (this *BundleExtendRequest) Validate() error {
|
func (this *BundleExtendRequest) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -487,12 +490,6 @@ func (this *GetBundleBalanceByUserIdReq) Validate() error {
|
|||||||
func (this *GetBundleBalanceByUserIdResp) Validate() error {
|
func (this *GetBundleBalanceByUserIdResp) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (this *GetBundleBalanceByOrderUUIDReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetBundleBalanceByOrderUUIDResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *OnlyAddValueListByOrderNoRequest) Validate() error {
|
func (this *OnlyAddValueListByOrderNoRequest) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -749,22 +746,6 @@ func (this *SetPendingTaskLayoutReq) Validate() error {
|
|||||||
func (this *SetPendingTaskLayoutResp) Validate() error {
|
func (this *SetPendingTaskLayoutResp) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (this *TaskWorkLogQueryRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *TaskWorkLogInfo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *TaskWorkLogQueryResponse) Validate() error {
|
|
||||||
for _, item := range this.Records {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Records", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreateTaskWorkLogRequest) Validate() error {
|
func (this *CreateTaskWorkLogRequest) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -837,320 +818,3 @@ func (this *MetricsVideoSubmitExportItem) Validate() error {
|
|||||||
func (this *MetricsBalanceDetailExportReq) Validate() error {
|
func (this *MetricsBalanceDetailExportReq) Validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (this *CustomerListRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CustomerListResponse) Validate() error {
|
|
||||||
for _, item := range this.List {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("List", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CustomerDetailRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CustomerDetailResponse) Validate() error {
|
|
||||||
if this.Customer != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Customer); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Customer", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CustomerUpdateRequest) Validate() error {
|
|
||||||
if this.Customer != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Customer); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Customer", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CustomerInfo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *Customer) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ReferralPersonListRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ReferralPersonListResponse) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractUpdateRequest) Validate() error {
|
|
||||||
if this.Contract != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Contract); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Contract", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractListRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractListResponse) Validate() error {
|
|
||||||
for _, item := range this.List {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("List", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractDetailRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractDetailResponse) Validate() error {
|
|
||||||
if this.Contract != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.Contract); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Contract", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetDevelopmentCyclesByContractUUIDRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetDevelopmentCyclesByContractUUIDResponse) Validate() error {
|
|
||||||
for _, item := range this.List {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("List", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetPaymentCyclesByContractUUIDRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetPaymentCyclesByContractUUIDResponse) Validate() error {
|
|
||||||
for _, item := range this.List {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("List", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *AttachmentItem) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractInfo) Validate() error {
|
|
||||||
for _, item := range this.ContractAttachments {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("ContractAttachments", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, item := range this.OtherAttachments {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("OtherAttachments", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *Contract) Validate() error {
|
|
||||||
for _, item := range this.ContractAttachments {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("ContractAttachments", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, item := range this.OtherAttachments {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("OtherAttachments", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, item := range this.PaymentCycles {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("PaymentCycles", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, item := range this.DevelopmentCycles {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("DevelopmentCycles", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ContractPaymentCycle) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *DevelopmentCycle) Validate() error {
|
|
||||||
for _, item := range this.Attachments {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Attachments", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreateInvoiceReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreateInvoiceResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreatePaperInvoiceAddressReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreatePaperInvoiceAddressResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *InvoiceInfo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetInvoiceListReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetInvoiceListResp) Validate() error {
|
|
||||||
for _, item := range this.Data {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *UpdateInvoiceExpressInfoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *UpdateInvoiceExpressInfoResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetInvoiceExpressInfoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetInvoiceExpressInfoResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetOrderInfoByOrderNoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetOrderInfoByOrderNoResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *WorkCastInfo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ExportWorkCastInfoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *ExportWorkCastInfoResp) Validate() error {
|
|
||||||
for _, item := range this.Data {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *OrderInfoByOrderUuidRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetInvoiceInfoByOrderNoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *InvoiceInfoByOrderNo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetInvoiceInfoByOrderNoResp) Validate() error {
|
|
||||||
for _, item := range this.Data {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("Data", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetLastInvoiceNoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetLastInvoiceNoResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *UpdataInvoiceInfoReq) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *UpdataInvoiceInfoResp) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *SendQuestionnaireSurveyRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *SendQuestionnaireSurveyResponse) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetQuestionnaireSurveyInfoRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *SurveyBundleInfo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetQuestionnaireSurveyInfoResponse) Validate() error {
|
|
||||||
if this.BundleInfo != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.BundleInfo); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("BundleInfo", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *SurveyAnswer) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *SurveyFeedback) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreateQuestionnaireSurveyAnswerRequest) Validate() error {
|
|
||||||
if this.SurveyAnswer != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.SurveyAnswer); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("SurveyAnswer", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if this.SurveyFeedback != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(this.SurveyFeedback); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("SurveyFeedback", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *CreateQuestionnaireSurveyAnswerResponse) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetQuestionnaireSurveyListRequest) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *SurveyListInfo) Validate() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (this *GetQuestionnaireSurveyListResponse) Validate() error {
|
|
||||||
for _, item := range this.SurveyList {
|
|
||||||
if item != nil {
|
|
||||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
|
||||||
return github_com_mwitkow_go_proto_validators.FieldError("SurveyList", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,7 @@
|
|||||||
package cron
|
package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"micro-bundle/internal/logic"
|
"micro-bundle/internal/logic"
|
||||||
|
|
||||||
@ -10,13 +11,14 @@ import (
|
|||||||
func InitCronJob() {
|
func InitCronJob() {
|
||||||
c := cron.New(cron.WithSeconds())
|
c := cron.New(cron.WithSeconds())
|
||||||
|
|
||||||
spec := "0 0 0 1 * *"
|
// 避免冲突,任务余额每月更新定时任务 - 每月1号1点执行
|
||||||
|
taskBalanceSpec := "0 0 1 1 * *"
|
||||||
_, err := c.AddFunc(spec, func() {
|
_, err := c.AddFunc(taskBalanceSpec, func() {
|
||||||
log.Printf("执行余量每月数据更新")
|
log.Printf("执行任务余额每月数据更新")
|
||||||
logic.UpdateBundleBalance()
|
logic.UpdateTaskBalanceEveryMonLogic()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("添加任务余额每月数据更新定时任务失败", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -62,34 +62,12 @@ func loadMysqlConn(conn string) *gorm.DB {
|
|||||||
// &model.Reconciliation{},
|
// &model.Reconciliation{},
|
||||||
&model.BundleActivate{},
|
&model.BundleActivate{},
|
||||||
&model.BundleBalanceLayout{},
|
&model.BundleBalanceLayout{},
|
||||||
&model.Contract{},
|
|
||||||
&model.ContractPaymentCycle{},
|
|
||||||
&model.DevelopmentCycle{},
|
|
||||||
&model.Customer{},
|
|
||||||
&model.Invoice{},
|
|
||||||
&model.PaperInvoiceAddress{},
|
|
||||||
&model.QuestionnaireSurvey{},
|
|
||||||
)
|
)
|
||||||
if db.Migrator().HasColumn(&model.BundleOrderRecords{}, "platform_ids") == false {
|
if db.Migrator().HasColumn(&model.BundleOrderRecords{}, "platform_ids") == false {
|
||||||
if err := db.Migrator().AddColumn(&model.BundleOrderRecords{}, "platform_ids"); err != nil {
|
if err := db.Migrator().AddColumn(&model.BundleOrderRecords{}, "platform_ids"); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if db.Migrator().HasColumn(&model.BundleOrderRecords{}, "inviter_id") == false {
|
|
||||||
if err := db.Migrator().AddColumn(&model.BundleOrderRecords{}, "inviter_id"); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if db.Migrator().HasColumn(&model.BundleOrderRecords{}, "renewal_order_uuid") == false {
|
|
||||||
if err := db.Migrator().AddColumn(&model.BundleOrderRecords{}, "renewal_order_uuid"); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if db.Migrator().HasColumn(&model.BundleOrderRecords{}, "purchase_type") == false {
|
|
||||||
if err := db.Migrator().AddColumn(&model.BundleOrderRecords{}, "purchase_type"); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// return nil
|
// return nil
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -132,6 +110,7 @@ func loadTaskBenchMysqlConn(conn string) *gorm.DB {
|
|||||||
&model.TaskManagement{},
|
&model.TaskManagement{},
|
||||||
&model.TaskAssignRecords{},
|
&model.TaskAssignRecords{},
|
||||||
// &model.TaskBalance{},
|
// &model.TaskBalance{},
|
||||||
|
&model.TaskSyncStatus{},
|
||||||
&model.TaskPendingLayout{},
|
&model.TaskPendingLayout{},
|
||||||
&model.TaskAssignUUIDItems{},
|
&model.TaskAssignUUIDItems{},
|
||||||
// 隐藏人员人记录表
|
// 隐藏人员人记录表
|
||||||
|
|||||||
@ -126,11 +126,3 @@ const (
|
|||||||
IsExpired = 1 //已过期
|
IsExpired = 1 //已过期
|
||||||
NotExpired = 0 //未过期
|
NotExpired = 0 //未过期
|
||||||
)
|
)
|
||||||
|
|
||||||
// 问卷状态
|
|
||||||
const (
|
|
||||||
//已发送
|
|
||||||
QuestionnaireSent = 1
|
|
||||||
//已提交
|
|
||||||
QuestionnaireSubmitted = 2
|
|
||||||
)
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ const source = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|||||||
|
|
||||||
// 生成订单号 模版 BD20250220104501+6位随机数 避免 订单号重复
|
// 生成订单号 模版 BD20250220104501+6位随机数 避免 订单号重复
|
||||||
func GetOrderNo() string {
|
func GetOrderNo() string {
|
||||||
return "BD" + GetRandomString(20)
|
return "BD" + time.Now().Format("20060102150405") + GetRandomString(6)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成随机字符串
|
// 生成随机字符串
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user