fix:购物车下单
This commit is contained in:
parent
8768588a8f
commit
ed5dce9ff0
|
@ -10,6 +10,7 @@ import (
|
|||
type Repositories struct {
|
||||
ImageHandle repositories.ImageHandle
|
||||
NewResource repositories.Resource
|
||||
NewOrder repositories.Order
|
||||
}
|
||||
|
||||
type NewAllRepositorieData struct {
|
||||
|
@ -22,5 +23,6 @@ func NewAllRepositories(newData *NewAllRepositorieData) *Repositories {
|
|||
return &Repositories{
|
||||
ImageHandle: repositories.NewImageHandle(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
|
||||
NewResource: repositories.NewResource(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
|
||||
NewOrder: repositories.NewOrder(newData.GormDB, newData.BLMServiceUrl, newData.AwsSession),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,23 +108,51 @@ type OrderStatus struct {
|
|||
|
||||
// 订单商品
|
||||
type OrderProduct struct {
|
||||
Amount AmountInfo `json:"amount"` // 商品总价
|
||||
ExpectedDeliveryTime string `json:"expected_delivery_time"` // 预计到货时间
|
||||
Number int64 `json:"number"` // 商品数量
|
||||
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
||||
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
||||
ProductID int64 `json:"product_id"` // 商品ID
|
||||
ProductLogo string `json:"product_logo"` // 商品logo
|
||||
ProductLogoResource *Resource `json:"product_logo_resource"` // 商品封面--资源详情
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ProductPrice AmountInfo `json:"product_price"` // 商品单价
|
||||
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
||||
ProductSnapshot map[string]interface{} `json:"product_snapshot"` // 商品快照
|
||||
ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照
|
||||
Unit string `json:"unit"` // 商品单位
|
||||
DiyInformation *DiyInformation `json:"diy_information"`
|
||||
FittingInfo *FittingInfo `json:"fitting_info"`
|
||||
ProductCover string `json:"product_cover"` // 商品封面
|
||||
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
||||
ProductSn string `json:"product_sn"` // 商品编码
|
||||
SizeInfo *SizeInfo `json:"size_info"`
|
||||
StepNum []int `json:"step_num"` // 阶梯数量
|
||||
}
|
||||
type SizeInfo struct {
|
||||
SizeID int64 `json:"size_id"`
|
||||
Capacity string `json:"capacity"`
|
||||
Title TitleInfo `json:"title"`
|
||||
}
|
||||
type TitleInfo struct {
|
||||
CM string `json:"cm"`
|
||||
Inch string `json:"inch"`
|
||||
}
|
||||
|
||||
// 资源详情
|
||||
type Resource struct {
|
||||
Metadata map[string]interface{} `json:"metadata"` // 资源额外
|
||||
ResourceID string `json:"resource_id"` // 资源ID
|
||||
ResourceType string `json:"resource_type"` // 资源类型
|
||||
ResourceURL string `json:"resource_url"` // 资源地址
|
||||
// 缩略图结构
|
||||
type ProductCoverMetadata struct {
|
||||
Height int64 `json:"height"` // 高度
|
||||
ResourceID string `json:"resource_id"` // 资源ID
|
||||
ResourceURL string `json:"resource_url"` // 资源链接
|
||||
Width int64 `json:"width"` // 宽度
|
||||
}
|
||||
|
||||
// DIY数据
|
||||
type DiyInformation struct {
|
||||
Address string `json:"address"` // 地址
|
||||
Phone string `json:"phone"` // 电话
|
||||
Qrcode string `json:"qrcode"` // 二维码
|
||||
Slogan string `json:"slogan"` // slogan
|
||||
Website string `json:"website"` // 网站
|
||||
}
|
||||
|
||||
// 配件信息
|
||||
type FittingInfo struct {
|
||||
FittingID int64 `json:"fitting_id"` // 配件id
|
||||
FittingName string `json:"fitting_name"` // 配件名称
|
||||
}
|
||||
|
|
11
server/order/etc/order.yaml
Normal file
11
server/order/etc/order.yaml
Normal file
|
@ -0,0 +1,11 @@
|
|||
Name: order
|
||||
Host: 0.0.0.0
|
||||
Port: 9921
|
||||
Timeout: 15000 #服务超时时间(毫秒)
|
||||
SourceMysql: fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen
|
||||
SourceRabbitMq:
|
||||
Log:
|
||||
Stat: false
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
AccessExpire: 2592000
|
14
server/order/internal/config/config.go
Normal file
14
server/order/internal/config/config.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fusenapi/server/order/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
SourceRabbitMq string
|
||||
}
|
35
server/order/internal/handler/createorderhandler.go
Normal file
35
server/order/internal/handler/createorderhandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/order/internal/logic"
|
||||
"fusenapi/server/order/internal/svc"
|
||||
"fusenapi/server/order/internal/types"
|
||||
)
|
||||
|
||||
func CreateOrderHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.CreateOrderReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewCreateOrderLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.CreateOrder(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/order/internal/logic"
|
||||
"fusenapi/server/order/internal/svc"
|
||||
"fusenapi/server/order/internal/types"
|
||||
)
|
||||
|
||||
func CreatePrePaymentDepositHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.CreatePrePaymentDepositReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewCreatePrePaymentDepositLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.CreatePrePaymentDeposit(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
35
server/order/internal/handler/orderlisthandler.go
Normal file
35
server/order/internal/handler/orderlisthandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/order/internal/logic"
|
||||
"fusenapi/server/order/internal/svc"
|
||||
"fusenapi/server/order/internal/types"
|
||||
)
|
||||
|
||||
func OrderListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.OrderListReq
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewOrderListLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.OrderList(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
32
server/order/internal/handler/routes.go
Normal file
32
server/order/internal/handler/routes.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/server/order/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/order/create",
|
||||
Handler: CreateOrderHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/order/create-prepayment-deposit",
|
||||
Handler: CreatePrePaymentDepositHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/order/list",
|
||||
Handler: OrderListHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
63
server/order/internal/logic/createorderlogic.go
Normal file
63
server/order/internal/logic/createorderlogic.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/constants"
|
||||
"fusenapi/service/repositories"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/order/internal/svc"
|
||||
"fusenapi/server/order/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateOrderLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
|
||||
return &CreateOrderLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *CreateOrderLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if userinfo.IsUser() {
|
||||
// 如果是,返回未授权的错误码
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
tPlus60Days := time.Now().AddDate(0, 0, 60)
|
||||
res, err := l.svcCtx.Repositories.NewOrder.Create(l.ctx, &repositories.CreateReq{
|
||||
ExpectedDeliveryTime: tPlus60Days,
|
||||
CurrentCurrency: string(constants.CURRENCYUSD),
|
||||
OriginalCurrency: string(constants.CURRENCYUSD),
|
||||
UserId: userinfo.UserId,
|
||||
CartIds: req.CartIds,
|
||||
DeliveryMethod: req.DeliveryMethod,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return resp.SetStatus(&res.ErrorCode)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *CreateOrderLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
43
server/order/internal/logic/createprepaymentdepositlogic.go
Normal file
43
server/order/internal/logic/createprepaymentdepositlogic.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/order/internal/svc"
|
||||
"fusenapi/server/order/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreatePrePaymentDepositLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreatePrePaymentDepositLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreatePrePaymentDepositLogic {
|
||||
return &CreatePrePaymentDepositLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *CreatePrePaymentDepositLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *CreatePrePaymentDepositLogic) CreatePrePaymentDeposit(req *types.CreatePrePaymentDepositReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *CreatePrePaymentDepositLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
43
server/order/internal/logic/orderlistlogic.go
Normal file
43
server/order/internal/logic/orderlistlogic.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/order/internal/svc"
|
||||
"fusenapi/server/order/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type OrderListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
|
||||
return &OrderListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *OrderListLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *OrderListLogic) OrderList(req *types.OrderListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *OrderListLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
31
server/order/internal/svc/servicecontext.go
Normal file
31
server/order/internal/svc/servicecontext.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package svc
|
||||
|
||||
import (
|
||||
"fusenapi/server/order/internal/config"
|
||||
|
||||
"fusenapi/initalize"
|
||||
"fusenapi/model/gmodel"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
|
||||
MysqlConn *gorm.DB
|
||||
AllModels *gmodel.AllModelsGen
|
||||
Repositories *initalize.Repositories
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
conn := initalize.InitMysql(c.SourceMysql)
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MysqlConn: conn,
|
||||
AllModels: gmodel.NewAllModels(conn),
|
||||
Repositories: initalize.NewAllRepositories(&initalize.NewAllRepositorieData{
|
||||
GormDB: conn,
|
||||
}),
|
||||
}
|
||||
}
|
95
server/order/internal/types/types.go
Normal file
95
server/order/internal/types/types.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type CreateOrderReq struct {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
|
||||
}
|
||||
|
||||
type CreatePrePaymentDepositReq struct {
|
||||
OrderSn string `json:"order_sn"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
DeliveryAddres DeliveryAddres `json:"delivery_addres,optional"`
|
||||
}
|
||||
|
||||
type DeliveryAddres struct {
|
||||
Address string `json:"address,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Mobile string `json:"mobile,optional"`
|
||||
}
|
||||
|
||||
type OrderListReq struct {
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type Auth struct {
|
||||
AccessSecret string `json:"accessSecret"`
|
||||
AccessExpire int64 `json:"accessExpire"`
|
||||
RefreshAfter int64 `json:"refreshAfter"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Filename string `fsfile:"filename"`
|
||||
Header map[string][]string `fsfile:"header"`
|
||||
Size int64 `fsfile:"size"`
|
||||
Data []byte `fsfile:"data"`
|
||||
}
|
||||
|
||||
type Meta struct {
|
||||
TotalCount int64 `json:"total_count"`
|
||||
PageCount int64 `json:"page_count"`
|
||||
CurrentPage int `json:"current_page"`
|
||||
PerPage int `json:"per_page"`
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *Response) Set(Code int, Message string) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
}
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) *Response {
|
||||
return &Response{
|
||||
Code: Code,
|
||||
Message: Message,
|
||||
Data: Data,
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) *Response {
|
||||
newResp := &Response{
|
||||
Code: sr.Code,
|
||||
Message: msg,
|
||||
}
|
||||
if len(data) == 1 {
|
||||
newResp.Data = data[0]
|
||||
}
|
||||
return newResp
|
||||
}
|
39
server/order/order.go
Normal file
39
server/order/order.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/fsconfig"
|
||||
|
||||
"fusenapi/server/order/internal/config"
|
||||
"fusenapi/server/order/internal/handler"
|
||||
"fusenapi/server/order/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/order.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
cfgContent := fsconfig.StartNacosConfig(*configFile, nil)
|
||||
var c config.Config
|
||||
conf.LoadConfigFromYamlBytes([]byte(cfgContent), &c)
|
||||
|
||||
c.Timeout = int64(time.Second * 15)
|
||||
server := rest.MustNewServer(c.RestConf, rest.WithCustomCors(auth.FsCors, func(w http.ResponseWriter) {
|
||||
}))
|
||||
defer server.Stop()
|
||||
|
||||
ctx := svc.NewServiceContext(c)
|
||||
handler.RegisterHandlers(server, ctx)
|
||||
|
||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||
server.Start()
|
||||
}
|
7
server/order/order_test.go
Normal file
7
server/order/order_test.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
main()
|
||||
}
|
|
@ -14,29 +14,30 @@ service order {
|
|||
@handler CreateOrderHandler
|
||||
post /api/order/create(CreateOrderReq) returns (response);
|
||||
|
||||
@handler CreatePrePaymentHandler
|
||||
post /api/order/create-prepayment-balance(CreatePrePaymentReq) returns (response);
|
||||
@handler CreatePrePaymentDepositHandler
|
||||
post /api/order/create-prepayment-deposit(CreatePrePaymentDepositReq) returns (response);
|
||||
|
||||
@handler OrderListHandler
|
||||
post /api/order/list(OrderListReq) returns (response);
|
||||
|
||||
}
|
||||
|
||||
type CreateOrderReq struct {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod string `json:"delivery_method,options=[1,2]"`
|
||||
type CreateOrderReq {
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
|
||||
}
|
||||
|
||||
type CreatePrePaymentReq struct {
|
||||
OrderSn string `json:"order_sn"`
|
||||
DeliveryMethod int `json:"delivery_method"`
|
||||
DeliveryAddres struct {
|
||||
Address string `json:"address,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Mobile string `json:"mobile,optional"`
|
||||
} `json:"delivery_addres,optional"`
|
||||
type CreatePrePaymentDepositReq {
|
||||
OrderSn string `json:"order_sn"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
DeliveryAddres DeliveryAddres `json:"delivery_addres,optional"`
|
||||
}
|
||||
|
||||
type OrderListReq struct {
|
||||
type DeliveryAddres {
|
||||
Address string `json:"address,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Mobile string `json:"mobile,optional"`
|
||||
}
|
||||
|
||||
type OrderListReq {
|
||||
}
|
|
@ -32,6 +32,7 @@ type (
|
|||
}
|
||||
Order interface {
|
||||
// 下单
|
||||
Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error)
|
||||
// 预支付
|
||||
// 列表
|
||||
// 详情
|
||||
|
@ -45,7 +46,7 @@ type (
|
|||
|
||||
/* 下单 */
|
||||
CreateReq struct {
|
||||
ExpectedDeliveryTime string `json:"expected_delivery_time"` // 预计到货时间
|
||||
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||
ExchangeRate int64 `json:"exchange_rate"` // 换算汇率(厘)
|
||||
CurrentCurrency string `json:"current_currency"` // 当前货币
|
||||
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||
|
@ -250,24 +251,14 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
orderProductTotal = orderProductTotal + productTotalPrice
|
||||
|
||||
// 订单商品
|
||||
var productLogoResource *gmodel.Resource
|
||||
if shoppingCart.ShoppingCartProduct.CoverResource != nil {
|
||||
var coverResourceMetadata map[string]interface{}
|
||||
if shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
|
||||
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &coverResourceMetadata)
|
||||
}
|
||||
productLogoResource = &gmodel.Resource{
|
||||
Metadata: coverResourceMetadata,
|
||||
ResourceID: shoppingCart.ShoppingCartProduct.CoverResource.ResourceId,
|
||||
ResourceType: *shoppingCart.ShoppingCartProduct.CoverResource.ResourceType,
|
||||
ResourceURL: *shoppingCart.ShoppingCartProduct.CoverResource.ResourceUrl,
|
||||
}
|
||||
}
|
||||
var productSnapshot = make(map[string]interface{}, 1)
|
||||
productSnapshot["product_snapshot"] = shoppingCart.ShoppingCartProduct
|
||||
|
||||
var productCoverMetadata map[string]interface{}
|
||||
if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
|
||||
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata)
|
||||
}
|
||||
orderProductList = append(orderProductList, gmodel.OrderProduct{
|
||||
Amount: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
TotalPrice: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: productTotalPrice,
|
||||
Current: productTotalPrice,
|
||||
|
@ -275,12 +266,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
OriginalCurrency: in.OriginalCurrency,
|
||||
}),
|
||||
ExpectedDeliveryTime: in.ExpectedDeliveryTime,
|
||||
Number: *shoppingCart.PurchaseQuantity,
|
||||
PurchaseQuantity: *shoppingCart.PurchaseQuantity,
|
||||
ProductID: *shoppingCart.ProductId,
|
||||
ProductLogo: *shoppingCart.ShoppingCartProduct.Cover,
|
||||
ProductLogoResource: productLogoResource,
|
||||
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
|
||||
ProductCoverMetadata: productCoverMetadata,
|
||||
ProductName: *shoppingCart.ShoppingCartProduct.Title,
|
||||
ProductPrice: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ItemPrice: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: productPrice,
|
||||
Current: productPrice,
|
||||
|
@ -289,6 +280,23 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
}),
|
||||
ProductSnapshot: productSnapshot,
|
||||
ShoppingCartSnapshot: &shoppingCart.FsShoppingCart,
|
||||
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
|
||||
DiyInformation: &gmodel.DiyInformation{
|
||||
Address: shoppingCartSnapshot.UserDiyInformation.Address,
|
||||
Phone: shoppingCartSnapshot.UserDiyInformation.Phone,
|
||||
Qrcode: shoppingCartSnapshot.UserDiyInformation.Qrcode,
|
||||
Slogan: shoppingCartSnapshot.UserDiyInformation.Slogan,
|
||||
Website: shoppingCartSnapshot.UserDiyInformation.Website,
|
||||
},
|
||||
FittingInfo: &gmodel.FittingInfo{
|
||||
FittingID: *shoppingCart.FittingId,
|
||||
FittingName: shoppingCartSnapshot.FittingInfo.FittingName,
|
||||
},
|
||||
SizeInfo: &gmodel.SizeInfo{
|
||||
SizeID: *shoppingCart.SizeId,
|
||||
Capacity: shoppingCartSnapshot.SizeInfo.Capacity,
|
||||
},
|
||||
StepNum: stepNum,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -357,7 +365,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT],
|
||||
}
|
||||
// 订单状态--链路
|
||||
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime)
|
||||
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime)
|
||||
var orderInfo = gmodel.OrderInfo{
|
||||
Ctime: nowTime,
|
||||
DeliveryMethod: in.DeliveryMethod,
|
||||
|
|
|
@ -103,7 +103,7 @@ func GenerateOrderNumber(deliveryMethod int, userID int) string {
|
|||
}
|
||||
|
||||
// 初始化订单状态
|
||||
func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time) []gmodel.OrderStatus {
|
||||
func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTime time.Time) []gmodel.OrderStatus {
|
||||
var list []gmodel.OrderStatus
|
||||
|
||||
var orderStatus []constants.OrderStatusCode
|
||||
|
@ -120,8 +120,7 @@ func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time) []gmodel.Or
|
|||
}
|
||||
list[0].Ctime = noTime
|
||||
list[0].Utime = noTime
|
||||
tPlus60Days := noTime.AddDate(0, 0, 60)
|
||||
list[len(list)-1].ExpectedTime = tPlus60Days
|
||||
list[len(list)-1].ExpectedTime = expectedTime
|
||||
return list
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user