解决冲突
This commit is contained in:
commit
9c64f3bc6d
@ -1,6 +1,7 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"micro-bundle/internal/model"
|
||||
"micro-bundle/pb/bundle"
|
||||
"micro-bundle/pkg/app"
|
||||
@ -9,8 +10,11 @@ import (
|
||||
"micro-bundle/pkg/utils"
|
||||
)
|
||||
|
||||
func CreateOrderRecord(orderRecord *model.BundleOrderRecords) (res *bundle.CommonResponse, err error) {
|
||||
func CreateOrderRecord(orderRecord *model.BundleOrderRecords, req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
|
||||
res = new(bundle.CommonResponse)
|
||||
bundleInfo := new(model.BundleProfile)
|
||||
|
||||
// 生成UUID和订单号
|
||||
orderRecord.UUID = app.ModuleClients.SfNode.Generate().Base64()
|
||||
orderRecord.OrderNo = utils.GetOrderNo()
|
||||
|
||||
@ -22,13 +26,66 @@ func CreateOrderRecord(orderRecord *model.BundleOrderRecords) (res *bundle.Commo
|
||||
}
|
||||
}()
|
||||
|
||||
// 查询套餐主表并预加载
|
||||
err = tx.Model(&model.BundleProfile{}).
|
||||
Where("uuid = ?", orderRecord.BundleUUID).
|
||||
Preload("BundleToValueAddService").
|
||||
Preload("BundleProfileLang", "language = ?", req.Language).
|
||||
First(&bundleInfo).Error
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
res.Msg = msg.ErrorBundleNotFound
|
||||
return res, commonErr.ReturnError(err, msg.ErrorBundleNotFound, "查询Bundle信息失败: ")
|
||||
}
|
||||
|
||||
// 填充BundleCommonJson字段
|
||||
if bundleJson, e := json.Marshal(bundleInfo); e == nil {
|
||||
orderRecord.BundleCommonJson = string(bundleJson)
|
||||
} else {
|
||||
tx.Rollback()
|
||||
res.Msg = msg.ErrorDataConvert
|
||||
return res, commonErr.ReturnError(e, msg.ErrorDataConvert, "Bundle信息转换失败: ")
|
||||
}
|
||||
|
||||
// 创建主订单
|
||||
if err = tx.Model(&model.BundleOrderRecords{}).Create(&orderRecord).Error; err != nil {
|
||||
if err = tx.Model(&model.BundleOrderRecords{}).Create(orderRecord).Error; err != nil {
|
||||
tx.Rollback()
|
||||
res.Msg = msg.ErrorCreateOrderInfo
|
||||
return res, commonErr.ReturnError(err, msg.ErrorCreateOrderInfo, "创建订单信息失败: ")
|
||||
}
|
||||
|
||||
// 创建子订单
|
||||
for _, service := range bundleInfo.BundleToValueAddService {
|
||||
amount, PriceType, serviceType, e := calculateAmount(service.ValueUid, req, req.Language)
|
||||
if e != nil {
|
||||
tx.Rollback()
|
||||
res.Msg = msg.ErrorDataConvert
|
||||
return res, commonErr.ReturnError(e, msg.ErrorDataConvert, "子订单金额计算失败: ")
|
||||
}
|
||||
|
||||
childOrder := &model.BundleOrderValueAdd{
|
||||
UUID: app.ModuleClients.SfNode.Generate().Base64(),
|
||||
OrderUUID: orderRecord.UUID, // 修正: 这里应使用主订单UUID
|
||||
CustomerID: orderRecord.CustomerID,
|
||||
CustomerNum: orderRecord.CustomerNum,
|
||||
CustomerName: orderRecord.CustomerName,
|
||||
ServiceType: serviceType,
|
||||
CurrencyType: PriceType,
|
||||
Amount: amount,
|
||||
Num: 0,
|
||||
Unit: 0,
|
||||
ValueAddUUID: service.ValueUid,
|
||||
Source: 1,
|
||||
PaymentStatus: 1,
|
||||
}
|
||||
|
||||
if err = tx.Model(&model.BundleOrderValueAdd{}).Create(childOrder).Error; err != nil {
|
||||
tx.Rollback()
|
||||
res.Msg = msg.ErrorCreateOrderInfo
|
||||
return res, commonErr.ReturnError(err, msg.ErrorCreateOrderInfo, "创建子订单信息失败: ")
|
||||
}
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
if err = tx.Commit().Error; err != nil {
|
||||
res.Msg = msg.ErrorCommitTransaction
|
||||
@ -41,6 +98,30 @@ func CreateOrderRecord(orderRecord *model.BundleOrderRecords) (res *bundle.Commo
|
||||
return
|
||||
}
|
||||
|
||||
// calculateAmount 计算子订单金额
|
||||
func calculateAmount(valueUid string, req *bundle.OrderRecord, language string) (float64, int64, int32, error) {
|
||||
var valueAddServiceLang *model.ValueAddServiceLang
|
||||
err := app.ModuleClients.BundleDB.
|
||||
Where("uuid = ? AND language = ?", valueUid, language).
|
||||
First(&valueAddServiceLang).Error
|
||||
if err != nil {
|
||||
return 0, valueAddServiceLang.PriceType, valueAddServiceLang.ServiceType, err
|
||||
}
|
||||
|
||||
var amount float64
|
||||
for _, opt := range valueAddServiceLang.Options {
|
||||
if valueAddServiceLang.PriceMode == 1 {
|
||||
for _, p := range req.PriceOptionsInfo {
|
||||
if p.ValueUid == valueUid && opt.Id == p.Id {
|
||||
amount = float64(float32(opt.Num) * opt.Price)
|
||||
}
|
||||
}
|
||||
} else if valueAddServiceLang.PriceMode == 2 {
|
||||
amount = float64(opt.Price)
|
||||
}
|
||||
}
|
||||
return amount, valueAddServiceLang.PriceType, valueAddServiceLang.ServiceType, nil
|
||||
}
|
||||
func UpdateOrderRecord(orderRecord *model.BundleOrderRecords) (res *bundle.CommonResponse, err error) {
|
||||
res = new(bundle.CommonResponse)
|
||||
err = app.ModuleClients.BundleDB.Model(&model.BundleOrderRecords{}).Where("uuid = ?", orderRecord.UUID).Updates(orderRecord).Error
|
||||
@ -60,6 +141,16 @@ func UpdateOrderRecordByOrderNO(orderRecord *model.BundleOrderRecords) (res *bun
|
||||
res.Msg = msg.ErrorUpdateOrderInfo
|
||||
return res, commonErr.ReturnError(err, msg.ErrorUpdateOrderInfo, "更新订单信息失败: ")
|
||||
}
|
||||
valueAdd := &model.BundleOrderValueAdd{
|
||||
PaymentStatus: int(orderRecord.Status),
|
||||
PaymentTime: orderRecord.PayTime,
|
||||
}
|
||||
//更新子订单支付状态
|
||||
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, "更新订单信息失败: ")
|
||||
}
|
||||
res.Uuid = orderRecord.UUID
|
||||
res.Msg = msg.SuccessUpdateOrderInfo
|
||||
return
|
||||
|
@ -19,8 +19,8 @@ func CreateOrderRecord(req *bundle.OrderRecord) (res *bundle.CommonResponse, err
|
||||
orderRecord.BundleUUID = req.BundleUuid
|
||||
orderRecord.ValueAddBundleUUID = req.ValueAddBundleUuid
|
||||
orderRecord.FinancialConfirmation = model.ConfirmationNotConfirmed
|
||||
|
||||
res, err = dao.CreateOrderRecord(orderRecord)
|
||||
orderRecord.Language = req.Language
|
||||
res, err = dao.CreateOrderRecord(orderRecord, req)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,25 @@ type BundleOrderRecords struct {
|
||||
FinancialConfirmation int32 `json:"financialConfirmation" gorm:"column:financial_confirmation;type:int;comment:财务确认 1:未确认 2:已确认"`
|
||||
ExpirationTime string `json:"expirationTime" gorm:"column:expiration_time;comment:套餐过期时间"`
|
||||
BundleCommonJson string `json:"bundle_common_json" gorm:"column:bundle_common_json;type:json;serializer:json;comment:套餐信息"`
|
||||
Language string `gorm:"column:language;comment:语言" json:"language"`
|
||||
}
|
||||
type BundleOrderValueAdd struct {
|
||||
gorm.Model
|
||||
UUID string `json:"uuid" gorm:"column:uuid;type:varchar(1024);comment:UUID"`
|
||||
OrderUUID string `json:"orderUUID" gorm:"column:order_uuid;type:varchar(1024);comment:套餐UUID"`
|
||||
CustomerID string `json:"customerID" gorm:"column:customer_id;type:varchar(1024);comment:客户ID"`
|
||||
CustomerNum string `json:"customerNum" gorm:"column:customer_num;type:varchar(1024);comment:客户编号"`
|
||||
CustomerName string `json:"customerName" gorm:"column:customer_name;type:varchar(1024);comment:客户名"`
|
||||
ServiceType int32 `json:"serviceType" gorm:"column:service_type;type:int;comment:服务类型 1:视频 2:图文 3:数据报表 4:账号数 5:可用时长"`
|
||||
CurrencyType int64 `json:"currencyType" gorm:"column:currency_type;type:int;comment:货币类型"`
|
||||
Amount float64 `json:"amount" gorm:"column:amount;type:decimal(12,2);comment:金额"`
|
||||
Num int32 `json:"num" gorm:"column:num;type:int;comment:数量"`
|
||||
Unit int32 `json:"unit" gorm:"column:unit;type:varchar(1024);comment:单位 1个 2条 3天 4月 5年"`
|
||||
ValueAddUUID string `json:"valueAddUUID" gorm:"column:value_add_uuid;type:varchar(1024);comment:增值服务UUID"`
|
||||
Source int `json:"source" gorm:"column:source;comment:增加方式 1套餐 2单独购买 3拓展"`
|
||||
Remark string `json:"remark" gorm:"column:remark;comment:备注"`
|
||||
PaymentStatus int `json:"paymentStatus" gorm:"column:payment_status;comment:支付状态 1未支付 2已支付"`
|
||||
PaymentTime string `gorm:"column:payment_time;comment:支付时间" json:"paymentTime"`
|
||||
}
|
||||
|
||||
// 财务确认状态
|
||||
|
@ -162,8 +162,13 @@ message OrderRecord {
|
||||
string addBundleCommonUid = 32 [json_name = "addBundleCommonUid"];
|
||||
int32 financialConfirmation = 33 [json_name = "financialConfirmation"];
|
||||
string telNum = 34 [json_name = "telNum"];
|
||||
string language = 35 [json_name = "language"];
|
||||
repeated PriceOptionsInfo priceOptionsInfo = 36 [json_name = "priceOptionsInfo"];
|
||||
}
|
||||
message PriceOptionsInfo {
|
||||
int32 id = 1 [json_name = "id"];
|
||||
string valueUid = 2 [json_name = "valueUid"];
|
||||
}
|
||||
|
||||
message OrderRecordsRequest {
|
||||
int32 page = 1 [json_name = "page"];
|
||||
int32 pageSize = 2 [json_name = "pageSize"];
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,8 +7,8 @@ import (
|
||||
fmt "fmt"
|
||||
math "math"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
_ "github.com/mwitkow/go-proto-validators"
|
||||
_ "google.golang.org/protobuf/types/descriptorpb"
|
||||
_ "github.com/mwitkow/go-proto-validators"
|
||||
github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators"
|
||||
)
|
||||
|
||||
@ -92,6 +92,16 @@ func (this *BundleDetailResponseV2) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *OrderRecord) Validate() error {
|
||||
for _, item := range this.PriceOptionsInfo {
|
||||
if item != nil {
|
||||
if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil {
|
||||
return github_com_mwitkow_go_proto_validators.FieldError("PriceOptionsInfo", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (this *PriceOptionsInfo) Validate() error {
|
||||
return nil
|
||||
}
|
||||
func (this *OrderRecordsRequest) Validate() error {
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go-triple. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-triple v1.0.8
|
||||
// - protoc v5.29.2
|
||||
// - protoc v4.24.0--rc1
|
||||
// source: pb/bundle.proto
|
||||
|
||||
package bundle
|
||||
|
@ -51,6 +51,7 @@ func loadMysqlConn(conn string) *gorm.DB {
|
||||
&model.BundleToValueAddService{},
|
||||
&model.BundleProfileHistory{},
|
||||
&model.ValueAddServiceHistory{},
|
||||
&model.BundleOrderValueAdd{},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -56,7 +56,9 @@ const (
|
||||
|
||||
ErrorGetOrderInfo = "获取订单信息失败"
|
||||
|
||||
ErrorGetOrderList = "获取订单列表失败"
|
||||
ErrorGetOrderList = "获取订单列表失败"
|
||||
ErrorBundleNotFound = "套餐不存在"
|
||||
ErrorDataConvert = "数据转换失败"
|
||||
)
|
||||
|
||||
// 增值套餐信息
|
||||
|
Loading…
Reference in New Issue
Block a user