micro-bundle/internal/logic/orderRecordsLogic.go

79 lines
2.7 KiB
Go
Raw Normal View History

2025-02-20 12:40:39 +00:00
package logic
import (
2025-02-22 13:20:19 +00:00
"fmt"
2025-02-20 12:40:39 +00:00
"micro-bundle/internal/dao"
"micro-bundle/internal/model"
"micro-bundle/pb/bundle"
"micro-bundle/pkg/app"
"micro-bundle/pkg/utils"
2025-03-25 08:30:09 +00:00
"github.com/jinzhu/copier"
2025-02-20 12:40:39 +00:00
)
func CreateOrderRecord(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 = app.ModuleClients.SfNode.Generate().Base64()
orderRecord.OrderNo = utils.GetOrderNo()
2025-02-22 12:02:50 +00:00
orderRecord.BundleUUID = req.BundleUuid
2025-03-25 08:30:09 +00:00
orderRecord.ValueAddBundleRecordUUID = app.ModuleClients.SfNode.Generate().Base64()
2025-02-22 13:20:19 +00:00
fmt.Printf("orderRecord %+v\n", orderRecord)
2025-03-25 08:30:09 +00:00
valueAddRecord := &model.ValueAddBundleRecord{
UUID: orderRecord.ValueAddBundleRecordUUID,
OriginalPrice: req.OriginalPrice,
DiscountPrice: req.DiscountPrice,
TotalPrice: req.ValueAddBundleAmount,
ValueAddBundleNum: int(req.ValueAddBundleNum),
SavedAmount: req.SavedAmount,
}
res, err = dao.CreateOrderRecord(orderRecord, valueAddRecord)
2025-02-20 12:40:39 +00:00
return
}
func UpdateOrderRecord(req *bundle.OrderRecord) (res *bundle.CommonResponse, err error) {
res = new(bundle.CommonResponse)
orderRecord := new(model.BundleOrderRecords)
_ = copier.CopyWithOption(&orderRecord, req, copier.Option{DeepCopy: true})
2025-02-23 02:37:53 +00:00
orderRecord.UUID = req.Uuid
2025-02-23 02:38:15 +00:00
orderRecord.BundleUUID = req.BundleUuid
2025-03-25 08:30:09 +00:00
orderRecord.ValueAddBundleRecordUUID = req.ValueAddBundleUuid
2025-02-20 12:40:39 +00:00
res, err = dao.UpdateOrderRecord(orderRecord)
return
}
2025-02-23 08:35:55 +00:00
func UpdateOrderRecordByOrderNo(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
res, err = dao.UpdateOrderRecordByOrderNO(orderRecord)
return
}
2025-02-20 12:40:39 +00:00
func OrderRecordsList(req *bundle.OrderRecordsRequest) (res *bundle.OrderRecordsResponse, err error) {
res = new(bundle.OrderRecordsResponse)
res, err = dao.OrderRecordsList(req)
return
}
func OrderRecordsDetail(req *bundle.OrderRecordsDetailRequest) (res *bundle.OrderRecordsDetailResponse, err error) {
res = new(bundle.OrderRecordsDetailResponse)
res.OrderRecord = new(bundle.OrderRecord)
2025-02-21 13:09:54 +00:00
res.OrderRecord, err = dao.OrderRecordDetail(req)
2025-02-20 12:40:39 +00:00
if err != nil {
res.Msg = err.Error()
}
return
}
2025-03-25 08:30:09 +00:00
func ValueAddBundleRecordDetail(req *bundle.ValueAddBundleDetailRequest) (res *bundle.ValueAddBundleDetailResponse, err error) {
res = new(bundle.ValueAddBundleDetailResponse)
res, err = dao.ValueAddBundleRecordDetail(req)
if err != nil {
res.Msg = err.Error()
}
return
}