refactor: reorganize modules and add Linux build tooling
This commit is contained in:
33
module/ec/order/internal/logic/common/get.go
Normal file
33
module/ec/order/internal/logic/common/get.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
)
|
||||
|
||||
// GetOrderSummaryByIdentity 根据订单号获取订单详情
|
||||
func GetOrderSummaryByIdentity(identity string) (*pb.OrderSummaryItem, error) {
|
||||
var (
|
||||
err error
|
||||
summary = new(models.OrderSummary)
|
||||
)
|
||||
err = models.DBService.Preload("OrderDetails").Where("identity = ?", identity).First(&summary).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ReflectProtoOrderSummary(summary), nil
|
||||
}
|
||||
|
||||
func GetOrderSummaryByNo(no string) (*pb.OrderSummaryItem, error) {
|
||||
var (
|
||||
err error
|
||||
summary = new(models.OrderSummary)
|
||||
)
|
||||
err = models.DBService.Preload("OrderDetails").Where("order_no = ?", no).First(&summary).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ReflectProtoOrderSummary(summary), nil
|
||||
}
|
||||
14
module/ec/order/internal/logic/common/no.go
Normal file
14
module/ec/order/internal/logic/common/no.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 订单号:2位年份,月,日,时,分,秒,6位随机数共18位
|
||||
func CreateOrderNo() string {
|
||||
t := time.Now().Local()
|
||||
rand := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
|
||||
return fmt.Sprintf("%d%d%d%d%d%d%s", t.Year()-2000, t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), rand)
|
||||
}
|
||||
100
module/ec/order/internal/logic/common/reflect.go
Normal file
100
module/ec/order/internal/logic/common/reflect.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"bsm/full/module/ec/order/internal/models"
|
||||
order "bsm/full/module/ec/order/pb"
|
||||
pb "bsm/full/module/ec/order/pb"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
// ReflectProtoOrderDetails 订单详情
|
||||
func ReflectProtoOrderDetails(v []models.OrderDetails) []*pb.OrderDetails {
|
||||
if nil == v {
|
||||
return nil
|
||||
}
|
||||
result := make([]*pb.OrderDetails, 0)
|
||||
for _, val := range v {
|
||||
result = append(result, &pb.OrderDetails{
|
||||
Id: int64(val.ID),
|
||||
ProductId: val.ProductID,
|
||||
SpecNo: val.SpecNo,
|
||||
SpecId: val.SpecID,
|
||||
Type: int64(val.Type),
|
||||
Title: val.Title,
|
||||
CoverImage: val.CoverImage,
|
||||
SalesPrice: val.SalesPrice,
|
||||
ProductArgs: val.ProductArgs,
|
||||
Number: int64(val.Number),
|
||||
UnitPrice: val.UnitPrice,
|
||||
ProductIdentity: val.ProductIdentity,
|
||||
GasTypes: int64(val.GasType),
|
||||
Spec: val.SpecTitle,
|
||||
TotalPrice: int64(val.Number) * val.UnitPrice,
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func ReflectProtoOrderSummary(summary *models.OrderSummary) *pb.OrderSummaryItem {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
item := pb.OrderSummaryItem{
|
||||
Id: int64(summary.ID),
|
||||
Identity: summary.Identity,
|
||||
OrderNo: summary.OrderNo,
|
||||
PartnerId: int64(summary.PartnerID),
|
||||
TotalPrice: summary.TotalPrice,
|
||||
TransPrice: summary.TransPrice,
|
||||
RefundPrice: summary.RefundPrice,
|
||||
LogisticsFee: summary.LogisticsFee,
|
||||
CouponAmount: summary.CouponAmount,
|
||||
Remark: summary.Remark,
|
||||
Status: summary.Status,
|
||||
LogisticsNumber: summary.LogisticsNumber,
|
||||
AddressIdentity: summary.AddressIdentity,
|
||||
County: summary.County,
|
||||
Province: summary.Province,
|
||||
City: summary.City,
|
||||
Area: summary.Area,
|
||||
Address: summary.Province + summary.City + summary.Area + summary.Address,
|
||||
Contact: summary.Contact,
|
||||
Phone: summary.Phone,
|
||||
DeliveryTime: summary.DeliveryTime,
|
||||
DeliveryIdentity: summary.DeliveryIdentity,
|
||||
PayType: int32(summary.PayType),
|
||||
PayAmount: summary.PayAmount,
|
||||
PayTradeNo: summary.PayTradeNo,
|
||||
PayTime: summary.PayTime.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
PayRemark: summary.PayRemark,
|
||||
Created: summary.CreatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
Updated: summary.UpdatedAt.Format(vars.YYYY_MM_DD_HH_MM_SS),
|
||||
Addr: summary.Address,
|
||||
CarIdentity: summary.CarIdentity,
|
||||
DeliveryAddress: summary.DeliveryAddress,
|
||||
Brand: summary.CarBrand,
|
||||
Version: summary.CarVersion,
|
||||
LicenseNumber: summary.LicenseNumber,
|
||||
MemberName: summary.MemberName,
|
||||
MemberPhone: summary.MemberPhone,
|
||||
Details: make([]*order.OrderDetails, 0),
|
||||
Approve: int32(summary.Approve),
|
||||
}
|
||||
if summary.OrderDetails != nil {
|
||||
item.Details = ReflectProtoOrderDetails(summary.OrderDetails)
|
||||
}
|
||||
if summary.PayTime.IsZero() {
|
||||
item.PayTime = ""
|
||||
}
|
||||
|
||||
return &item
|
||||
}
|
||||
|
||||
func ListModelToReply(list []*models.OrderSummary) []*pb.OrderSummaryItem {
|
||||
var data = make([]*order.OrderSummaryItem, 0)
|
||||
for _, summary := range list {
|
||||
data = append(data, ReflectProtoOrderSummary(summary))
|
||||
}
|
||||
return data
|
||||
}
|
||||
Reference in New Issue
Block a user