Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
f0f9ae287d
|
@ -7,20 +7,6 @@ import (
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
type NewFsOrder struct {
|
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单ID
|
|
||||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
|
|
||||||
DeliveryMethod *int64 `gorm:"index;default:0;" json:"delivery_method"` // 物流类型
|
|
||||||
OrderSn *string `gorm:"index;default:'';" json:"order_sn"` //
|
|
||||||
OrderSource *string `gorm:"default:'';" json:"order_source"` //
|
|
||||||
Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态
|
|
||||||
PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态
|
|
||||||
Metadata *OrderDetail `gorm:"metadata,type:json" json:"metadata"` //
|
|
||||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
|
||||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
|
||||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:0=否,1=是
|
|
||||||
}
|
|
||||||
|
|
||||||
// 订单详情
|
// 订单详情
|
||||||
type OrderDetail struct {
|
type OrderDetail struct {
|
||||||
DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址
|
DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址
|
||||||
|
@ -53,7 +39,7 @@ type PayInfo struct {
|
||||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||||
PayAmount AmountInfo `json:"pay_amount"` // 金额明细
|
PayAmount AmountInfo `json:"pay_amount"` // 金额明细
|
||||||
PayMethod string `json:"pay_method"` // 交易方式
|
PayMethod string `json:"pay_method"` // 交易方式
|
||||||
PayTime time.Time `json:"pay_time"` // 支付时间
|
PayTime **time.Time `json:"pay_time"` // 支付时间
|
||||||
Status PayStatus `json:"status"` // 当前状态
|
Status PayStatus `json:"status"` // 当前状态
|
||||||
StatusLink []PayStatus `json:"status_link"` // 状态链路
|
StatusLink []PayStatus `json:"status_link"` // 状态链路
|
||||||
TradeNo string `json:"trade_no"` // 支付交易号
|
TradeNo string `json:"trade_no"` // 支付交易号
|
||||||
|
@ -86,35 +72,35 @@ type PayStatus struct {
|
||||||
|
|
||||||
// 订单信息
|
// 订单信息
|
||||||
type OrderInfo struct {
|
type OrderInfo struct {
|
||||||
Ctime time.Time `json:"ctime"` // 创建日期
|
Ctime *time.Time `json:"ctime"` // 创建日期
|
||||||
DeliveryMethod int64 `json:"delivery_method"` // 物流类型
|
DeliveryMethod int64 `json:"delivery_method"` // 物流类型
|
||||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||||
OrderSn string `json:"order_sn"` // 订单编号
|
OrderSn string `json:"order_sn"` // 订单编号
|
||||||
Status OrderStatus `json:"status"` // 当前状态
|
Status OrderStatus `json:"status"` // 当前状态
|
||||||
StatusLink []OrderStatus `json:"status_link"` // 状态链路
|
StatusLink []OrderStatus `json:"status_link"` // 状态链路
|
||||||
Utime time.Time `json:"utime"` // 更新时间
|
Utime *time.Time `json:"utime"` // 更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订单状态--用户
|
// 订单状态--用户
|
||||||
type OrderStatus struct {
|
type OrderStatus struct {
|
||||||
Children []*OrderStatus `json:"children"` // 子状态,管理人员的处理状态, 用户不可见
|
Children []*OrderStatus `json:"children"` // 子状态,管理人员的处理状态, 用户不可见
|
||||||
Ctime time.Time `json:"ctime"` // 创建时间
|
Ctime *time.Time `json:"ctime"` // 创建时间
|
||||||
ExpectedTime time.Time `json:"expected_time"` // 预计时间
|
ExpectedTime *time.Time `json:"expected_time"` // 预计时间
|
||||||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||||
StatusCode constants.OrderStatusCode `json:"status_code"` // 状态编码
|
StatusCode constants.OrderStatusCode `json:"status_code"` // 状态编码
|
||||||
StatusTitle string `json:"status_title"` // 状态名称
|
StatusTitle string `json:"status_title"` // 状态名称
|
||||||
Utime time.Time `json:"utime"` // 更新时间
|
Utime *time.Time `json:"utime"` // 更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订单商品
|
// 订单商品
|
||||||
type OrderProduct struct {
|
type OrderProduct struct {
|
||||||
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
||||||
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
|
ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
||||||
ProductID int64 `json:"product_id"` // 商品ID
|
ProductID int64 `json:"product_id"` // 商品ID
|
||||||
ProductName string `json:"product_name"` // 商品名称
|
ProductName string `json:"product_name"` // 商品名称
|
||||||
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
||||||
ProductSnapshot map[string]interface{} `json:"product_snapshot"` // 商品快照
|
ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照
|
||||||
ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照
|
ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照
|
||||||
ProductCover string `json:"product_cover"` // 商品封面
|
ProductCover string `json:"product_cover"` // 商品封面
|
||||||
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
||||||
|
|
|
@ -4,6 +4,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (m *FsShoppingCartModel) TableName() string {
|
||||||
|
return m.name
|
||||||
|
}
|
||||||
|
|
||||||
// 关联查询
|
// 关联查询
|
||||||
type RelaFsShoppingCart struct {
|
type RelaFsShoppingCart struct {
|
||||||
FsShoppingCart
|
FsShoppingCart
|
||||||
|
@ -37,6 +41,7 @@ type ModelInfo struct {
|
||||||
type FittingInfo struct {
|
type FittingInfo struct {
|
||||||
FittingJson string `json:"fitting_json"` //配件设计json数据
|
FittingJson string `json:"fitting_json"` //配件设计json数据
|
||||||
FittingName string `json:"fitting_name"` //配件名称
|
FittingName string `json:"fitting_name"` //配件名称
|
||||||
|
|
||||||
}
|
}
|
||||||
type TemplateInfo struct {
|
type TemplateInfo struct {
|
||||||
TemplateJson string `json:"template_json"` //模板设计json数据
|
TemplateJson string `json:"template_json"` //模板设计json数据
|
||||||
|
|
35
server/order/internal/handler/orderdetailhandler.go
Normal file
35
server/order/internal/handler/orderdetailhandler.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 OrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var req types.OrderDetailReq
|
||||||
|
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建一个业务逻辑层实例
|
||||||
|
l := logic.NewOrderDetailLogic(r.Context(), svcCtx)
|
||||||
|
|
||||||
|
rl := reflect.ValueOf(l)
|
||||||
|
basic.BeforeLogic(w, r, rl)
|
||||||
|
|
||||||
|
resp := l.OrderDetail(&req, userinfo)
|
||||||
|
|
||||||
|
if !basic.AfterLogic(w, r, rl, resp) {
|
||||||
|
basic.NormalAfterLogic(w, r, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,10 +23,15 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Handler: CreatePrePaymentDepositHandler(serverCtx),
|
Handler: CreatePrePaymentDepositHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodGet,
|
||||||
Path: "/api/order/list",
|
Path: "/api/order/list",
|
||||||
Handler: OrderListHandler(serverCtx),
|
Handler: OrderListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/api/order/detail",
|
||||||
|
Handler: OrderDetailHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat
|
||||||
func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
// userinfo 传入值时, 一定不为null
|
// userinfo 传入值时, 一定不为null
|
||||||
if userinfo.IsUser() {
|
if !userinfo.IsUser() {
|
||||||
// 如果是,返回未授权的错误码
|
// 如果是,返回未授权的错误码
|
||||||
return resp.SetStatus(basic.CodeUnAuth)
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,9 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
|
||||||
return resp.SetStatus(&res.ErrorCode)
|
return resp.SetStatus(&res.ErrorCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp.SetStatus(basic.CodeOK)
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
|
"order_sn": res.OrderSn,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
|
57
server/order/internal/logic/orderdetaillogic.go
Normal file
57
server/order/internal/logic/orderdetaillogic.go
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fusenapi/service/repositories"
|
||||||
|
"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 OrderDetailLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOrderDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderDetailLogic {
|
||||||
|
return &OrderDetailLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理进入前逻辑w,r
|
||||||
|
// func (l *OrderDetailLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
func (l *OrderDetailLogic) OrderDetail(req *types.OrderDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
|
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||||
|
// userinfo 传入值时, 一定不为null
|
||||||
|
if !userinfo.IsUser() {
|
||||||
|
// 如果是,返回未授权的错误码
|
||||||
|
return resp.SetStatus(basic.CodeUnAuth)
|
||||||
|
}
|
||||||
|
res, err := l.svcCtx.Repositories.NewOrder.Detail(l.ctx, &repositories.DetailReq{
|
||||||
|
OrderSn: req.OrderSn,
|
||||||
|
UserId: userinfo.UserId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return resp.SetStatus(basic.CodeApiErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.SetStatus(basic.CodeOK, map[string]interface{}{
|
||||||
|
"order_detail": res,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||||
|
// func (l *OrderDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||||
|
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
// }
|
|
@ -5,6 +5,10 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type OrderDetailReq struct {
|
||||||
|
OrderSn string `form:"order_sn"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreateOrderReq struct {
|
type CreateOrderReq struct {
|
||||||
CartIds []int64 `json:"cart_ids"`
|
CartIds []int64 `json:"cart_ids"`
|
||||||
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
|
DeliveryMethod int64 `json:"delivery_method,options=[1,2]"`
|
||||||
|
|
|
@ -208,6 +208,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
IsInvalid: false,
|
IsInvalid: false,
|
||||||
InvalidDescription: "",
|
InvalidDescription: "",
|
||||||
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
|
||||||
|
IsSelected: *cart.IsSelected > 0,
|
||||||
}
|
}
|
||||||
//是否有失效的
|
//是否有失效的
|
||||||
if description, ok := mapCartChange[cart.Id]; ok {
|
if description, ok := mapCartChange[cart.Id]; ok {
|
||||||
|
|
|
@ -52,6 +52,7 @@ type CartItem struct {
|
||||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
|
IsSelected bool `json:"is_selected"` //是否选中
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProductInfo struct {
|
type ProductInfo struct {
|
||||||
|
|
7
server/shopping-cart/order_test.go
Normal file
7
server/shopping-cart/order_test.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestMain(t *testing.T) {
|
||||||
|
main()
|
||||||
|
}
|
|
@ -18,8 +18,15 @@ service order {
|
||||||
post /api/order/create-prepayment-deposit(CreatePrePaymentDepositReq) returns (response);
|
post /api/order/create-prepayment-deposit(CreatePrePaymentDepositReq) returns (response);
|
||||||
|
|
||||||
@handler OrderListHandler
|
@handler OrderListHandler
|
||||||
post /api/order/list(OrderListReq) returns (response);
|
get /api/order/list(OrderListReq) returns (response);
|
||||||
|
|
||||||
|
@handler OrderDetailHandler
|
||||||
|
get /api/order/detail(OrderDetailReq) returns (response);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderDetailReq {
|
||||||
|
OrderSn string `form:"order_sn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateOrderReq {
|
type CreateOrderReq {
|
||||||
|
|
|
@ -69,6 +69,7 @@ type CartItem {
|
||||||
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
|
IsSelected bool `json:"is_selected"` //是否选中
|
||||||
}
|
}
|
||||||
type ProductInfo {
|
type ProductInfo {
|
||||||
ProductId int64 `json:"product_id"` //产品id
|
ProductId int64 `json:"product_id"` //产品id
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"fusenapi/utils/curl"
|
"fusenapi/utils/curl"
|
||||||
"fusenapi/utils/file"
|
"fusenapi/utils/file"
|
||||||
"fusenapi/utils/hash"
|
"fusenapi/utils/hash"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
@ -222,21 +223,22 @@ type TemplateTagColor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
|
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
|
||||||
// 查询logo最新基础信息
|
s := strings.Split(in.LogoUrl, "/")
|
||||||
resLogoInfo, err := l.LogoInfo(ctx, &LogoInfoReq{
|
if len(s) <= 1 {
|
||||||
UserId: in.UserId,
|
return nil, errors.New("无效的logo")
|
||||||
GuestId: in.GuestId,
|
}
|
||||||
})
|
logoResourceId := s[len(s)-1]
|
||||||
|
userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn)
|
||||||
|
resLogoInfo, err := userMaterialModel.FindOneByLogoResourceId(ctx, logoResourceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据hash 查询数据资源
|
// 根据hash 查询数据资源
|
||||||
var hashKeyData = *in
|
var hashKeyData = *in
|
||||||
hashKeyData.GuestId = 0
|
hashKeyData.GuestId = 0
|
||||||
hashKeyData.UserId = 0
|
hashKeyData.UserId = 0
|
||||||
hashKeyData.LogoUrl = *resLogoInfo.LogoUrl
|
hashKeyData.LogoUrl = in.LogoUrl
|
||||||
var hashKeyDataMap map[string]interface{}
|
var hashKeyDataMap map[string]interface{}
|
||||||
hashKeyDataB, _ := json.Marshal(hashKeyData)
|
hashKeyDataB, _ := json.Marshal(hashKeyData)
|
||||||
json.Unmarshal(hashKeyDataB, &hashKeyDataMap)
|
json.Unmarshal(hashKeyDataB, &hashKeyDataMap)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
@ -11,6 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,6 +32,7 @@ type (
|
||||||
// 预支付
|
// 预支付
|
||||||
// 列表
|
// 列表
|
||||||
// 详情
|
// 详情
|
||||||
|
Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderAddress struct {
|
OrderAddress struct {
|
||||||
|
@ -54,20 +57,54 @@ type (
|
||||||
OrderSn string
|
OrderSn string
|
||||||
}
|
}
|
||||||
/* 下单 */
|
/* 下单 */
|
||||||
|
|
||||||
|
/* 详情 */
|
||||||
|
DetailReq struct {
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
OrderSn string `json:"order_sn"`
|
||||||
|
}
|
||||||
|
DetailRes struct {
|
||||||
|
}
|
||||||
|
/* 详情 */
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 详情
|
||||||
|
func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error) {
|
||||||
|
var order gmodel.FsOrder
|
||||||
|
result := d.MysqlConn.Where("order_sn = ?", in.OrderSn).Where("user_id = ?", in.UserId).Take(&order)
|
||||||
|
if result.Error != nil {
|
||||||
|
return nil, result.Error
|
||||||
|
}
|
||||||
|
d.OrderDetailHandler(ctx, &order)
|
||||||
|
return &DetailRes{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *defaultOrder) OrderDetailHandler(ctx context.Context, order *gmodel.FsOrder) (res *DetailRes, err error) {
|
||||||
|
var orderDetail gmodel.OrderDetail
|
||||||
|
|
||||||
|
err = json.Unmarshal(*order.Metadata, &orderDetail)
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("create handler unmarshal metadata failed, err: %v", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Println(orderDetail)
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 下单
|
// 下单
|
||||||
func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error) {
|
func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error) {
|
||||||
var errorCode basic.StatusResponse
|
var errorCode basic.StatusResponse
|
||||||
// 订单编号
|
// 订单编号
|
||||||
var orderSn string = order.GenerateOrderNumber(int(in.DeliveryMethod), int(in.UserId))
|
var orderSn string = order.GenerateOrderNumber()
|
||||||
|
|
||||||
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||||
// 查询购物车
|
// 查询购物车
|
||||||
var shoppingCartList []*gmodel.RelaFsShoppingCart
|
var shoppingCartList []*gmodel.RelaFsShoppingCart
|
||||||
resShoppingCartFind := tx.Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB {
|
resShoppingCartFind := tx.Table(gmodel.NewFsShoppingCartModel(tx).TableName()).
|
||||||
return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource")
|
Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB {
|
||||||
}).Preload("ShoppingCartProductPriceList").
|
return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource")
|
||||||
|
}).Preload("ShoppingCartProductPriceList").
|
||||||
Preload("ShoppingCartProductModel3dList").
|
Preload("ShoppingCartProductModel3dList").
|
||||||
Preload("ShoppingCartProductModel3dFitting").
|
Preload("ShoppingCartProductModel3dFitting").
|
||||||
Where("id IN ?", in.CartIds).
|
Where("id IN ?", in.CartIds).
|
||||||
|
@ -150,7 +187,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
} else {
|
} else {
|
||||||
var isProductPrice bool
|
var isProductPrice bool
|
||||||
for _, shoppingCartProductPriceInfo := range shoppingCart.ShoppingCartProductPriceList {
|
for _, shoppingCartProductPriceInfo := range shoppingCart.ShoppingCartProductPriceList {
|
||||||
if shoppingCart.SizeId == shoppingCartProductPriceInfo.SizeId {
|
if *shoppingCart.SizeId == *shoppingCartProductPriceInfo.SizeId {
|
||||||
shoppingCartProductPrice = shoppingCartProductPriceInfo
|
shoppingCartProductPrice = shoppingCartProductPriceInfo
|
||||||
isProductPrice = true
|
isProductPrice = true
|
||||||
break
|
break
|
||||||
|
@ -172,7 +209,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
} else {
|
} else {
|
||||||
var isProductModel bool
|
var isProductModel bool
|
||||||
for _, shoppingCartProductModel3dInfo := range shoppingCart.ShoppingCartProductModel3dList {
|
for _, shoppingCartProductModel3dInfo := range shoppingCart.ShoppingCartProductModel3dList {
|
||||||
if shoppingCart.SizeId == shoppingCartProductModel3dInfo.SizeId {
|
if *shoppingCart.SizeId == *shoppingCartProductModel3dInfo.SizeId {
|
||||||
shoppingCartProductModel3d = shoppingCartProductModel3dInfo
|
shoppingCartProductModel3d = shoppingCartProductModel3dInfo
|
||||||
isProductModel = true
|
isProductModel = true
|
||||||
break
|
break
|
||||||
|
@ -216,8 +253,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
orderProductTotal = orderProductTotal + productTotalPrice
|
orderProductTotal = orderProductTotal + productTotalPrice
|
||||||
|
|
||||||
// 订单商品
|
// 订单商品
|
||||||
var productSnapshot = make(map[string]interface{}, 1)
|
|
||||||
productSnapshot["product_snapshot"] = shoppingCart.ShoppingCartProduct
|
|
||||||
var productCoverMetadata map[string]interface{}
|
var productCoverMetadata map[string]interface{}
|
||||||
if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
|
if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
|
||||||
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata)
|
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata)
|
||||||
|
@ -230,7 +265,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
CurrentCurrency: in.CurrentCurrency,
|
CurrentCurrency: in.CurrentCurrency,
|
||||||
OriginalCurrency: in.OriginalCurrency,
|
OriginalCurrency: in.OriginalCurrency,
|
||||||
}),
|
}),
|
||||||
ExpectedDeliveryTime: in.ExpectedDeliveryTime,
|
ExpectedDeliveryTime: &in.ExpectedDeliveryTime,
|
||||||
PurchaseQuantity: *shoppingCart.PurchaseQuantity,
|
PurchaseQuantity: *shoppingCart.PurchaseQuantity,
|
||||||
ProductID: *shoppingCart.ProductId,
|
ProductID: *shoppingCart.ProductId,
|
||||||
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
|
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
|
||||||
|
@ -243,7 +278,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
CurrentCurrency: in.CurrentCurrency,
|
CurrentCurrency: in.CurrentCurrency,
|
||||||
OriginalCurrency: in.OriginalCurrency,
|
OriginalCurrency: in.OriginalCurrency,
|
||||||
}),
|
}),
|
||||||
ProductSnapshot: productSnapshot,
|
ProductSnapshot: shoppingCart.ShoppingCartProduct,
|
||||||
ShoppingCartSnapshot: &shoppingCart.FsShoppingCart,
|
ShoppingCartSnapshot: &shoppingCart.FsShoppingCart,
|
||||||
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
|
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
|
||||||
DiyInformation: &shoppingCartSnapshot.UserDiyInformation,
|
DiyInformation: &shoppingCartSnapshot.UserDiyInformation,
|
||||||
|
@ -322,15 +357,15 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
|
|
||||||
// 订单状态--当前
|
// 订单状态--当前
|
||||||
var status = gmodel.OrderStatus{
|
var status = gmodel.OrderStatus{
|
||||||
Ctime: nowTime,
|
Ctime: &nowTime,
|
||||||
Utime: nowTime,
|
Utime: &nowTime,
|
||||||
StatusCode: constants.ORDERSTATUSUNPAIDDEPOSIT,
|
StatusCode: constants.ORDERSTATUSUNPAIDDEPOSIT,
|
||||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT],
|
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT],
|
||||||
}
|
}
|
||||||
// 订单状态--链路
|
// 订单状态--链路
|
||||||
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime)
|
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime)
|
||||||
var orderInfo = gmodel.OrderInfo{
|
var orderInfo = gmodel.OrderInfo{
|
||||||
Ctime: nowTime,
|
Ctime: &nowTime,
|
||||||
DeliveryMethod: in.DeliveryMethod,
|
DeliveryMethod: in.DeliveryMethod,
|
||||||
OrderSn: orderSn,
|
OrderSn: orderSn,
|
||||||
Status: status,
|
Status: status,
|
||||||
|
@ -345,14 +380,19 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
PayStatus: payStatus,
|
PayStatus: payStatus,
|
||||||
}
|
}
|
||||||
// 数据库操作
|
// 数据库操作
|
||||||
var order = gmodel.NewFsOrder{
|
|
||||||
|
orderDetailByte, err := json.Marshal(orderDetail)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var order = gmodel.FsOrder{
|
||||||
UserId: &in.UserId,
|
UserId: &in.UserId,
|
||||||
DeliveryMethod: &in.DeliveryMethod,
|
DeliveryMethod: &in.DeliveryMethod,
|
||||||
OrderSn: &orderSn,
|
OrderSn: &orderSn,
|
||||||
Status: (*int64)(&status.StatusCode),
|
Status: (*int64)(&status.StatusCode),
|
||||||
PayStatus: (*int64)(&payStatus),
|
PayStatus: (*int64)(&payStatus),
|
||||||
Ctime: &nowTime,
|
Ctime: &nowTime,
|
||||||
Metadata: &orderDetail,
|
Metadata: &orderDetailByte,
|
||||||
}
|
}
|
||||||
result := tx.Create(&order)
|
result := tx.Create(&order)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
@ -361,6 +401,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logx.Errorf("create order failed, err: %v", err)
|
||||||
|
|
||||||
|
if errorCode.Code == 0 {
|
||||||
|
errorCode.Code = basic.CodeApiErr.Code
|
||||||
|
errorCode.Message = basic.CodeApiErr.Message
|
||||||
|
}
|
||||||
return &CreateRes{
|
return &CreateRes{
|
||||||
OrderSn: orderSn,
|
OrderSn: orderSn,
|
||||||
ErrorCode: errorCode,
|
ErrorCode: errorCode,
|
||||||
|
|
|
@ -100,12 +100,12 @@ var (
|
||||||
CodeLogoCombineErr = &StatusResponse{5115, "logo combine fail"} // 合图失败
|
CodeLogoCombineErr = &StatusResponse{5115, "logo combine fail"} // 合图失败
|
||||||
CodeLogoCombineNoFoundErr = &StatusResponse{5116, "template record not found"} // 模版不存在
|
CodeLogoCombineNoFoundErr = &StatusResponse{5116, "template record not found"} // 模版不存在
|
||||||
|
|
||||||
CodeErrOrder = &StatusResponse{5300, "ocreate order failed"} // 订单错误
|
CodeErrOrder = &StatusResponse{5300, "create order failed"} // 订单错误
|
||||||
CodeErrOrderCreatShoppingCartEmpty = &StatusResponse{5301, "ocreate order failed, shopping cart is empty"} // 订单创建失败,购物车为空
|
CodeErrOrderCreatShoppingCartEmpty = &StatusResponse{5301, "create order failed, shopping cart is empty"} // 订单创建失败,购物车为空
|
||||||
CodeErrOrderCreatShoppingCartNotMatched = &StatusResponse{5302, "ocreate order failed, shopping cart not matched"} // 订单创建失败,购物车不相符
|
CodeErrOrderCreatShoppingCartNotMatched = &StatusResponse{5302, "create order failed, shopping cart not matched"} // 订单创建失败,购物车不相符
|
||||||
CodeErrOrderCreatProductAbsent = &StatusResponse{5303, "ocreate order failed, product is absent"} // 订单创建失败,商品不存在
|
CodeErrOrderCreatProductAbsent = &StatusResponse{5303, "create order failed, product is absent"} // 订单创建失败,商品不存在
|
||||||
CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "ocreate order failed, price of product is absent"} // 订单创建失败,商品价格不存在
|
CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "create order failed, price of product is absent"} // 订单创建失败,商品价格不存在
|
||||||
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "ocreate order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在
|
||||||
)
|
)
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"math/rand"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,24 +79,33 @@ func GetAmountInfo(req GetAmountInfoReq) gmodel.AmountInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateOrderNumber(deliveryMethod int, userID int) string {
|
type GetAmountCurrencyUSDReq struct {
|
||||||
// 获取当前时间
|
ExchangeRate int64 `json:"exchange_rate"` // 换算汇率
|
||||||
now := time.Now()
|
CurrentAmount int64 `json:"current_amount"` // 当前金额
|
||||||
|
OriginalAmount int64 `json:"original_amount"` // 原始金额
|
||||||
|
CurrentCurrency string `json:"current_currency"` // 当前货币
|
||||||
|
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||||
|
}
|
||||||
|
|
||||||
// 生成年月日时分秒的字符串
|
type GetAmountCurrencyUSDRes struct {
|
||||||
year := strconv.Itoa(now.Year())
|
ExchangeRate string `json:"exchange_rate"` // 换算汇率
|
||||||
month := strconv.Itoa(int(now.Month()))
|
CurrentAmount string `json:"current_amount"` // 当前金额
|
||||||
day := strconv.Itoa(now.Day())
|
OriginalAmount string `json:"original_amount"` // 原始金额
|
||||||
hour := strconv.Itoa(now.Hour())
|
CurrentCurrency string `json:"current_currency"` // 当前货币
|
||||||
minute := strconv.Itoa(now.Minute())
|
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||||
second := strconv.Itoa(now.Second())
|
}
|
||||||
|
|
||||||
// 生成2位随机数
|
// 处理金额(美元)
|
||||||
rand.Seed(time.Now().UnixNano())
|
func GetAmountCurrencyUSD(req *GetAmountCurrencyUSDReq) (res GetAmountCurrencyUSDRes) {
|
||||||
randomNum := fmt.Sprintf("%02d", rand.Intn(100))
|
return GetAmountCurrencyUSDRes{
|
||||||
|
ExchangeRate: fmt.Sprintf("%.2f", float64(req.ExchangeRate)/1000),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 拼接订单号
|
func GenerateOrderNumber() string {
|
||||||
orderNumber := year + month + day + hour + minute + second + randomNum + strconv.Itoa(userID) + strconv.Itoa(deliveryMethod)
|
t := time.Now()
|
||||||
|
orderNumber := fmt.Sprintf("%d%02d%02d%08d", t.Year(), t.Month(), t.Day(), t.UnixNano()%100000000)
|
||||||
|
fmt.Println(orderNumber)
|
||||||
return orderNumber
|
return orderNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,9 +125,9 @@ func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTim
|
||||||
StatusTitle: constants.OrderStatusMessage[v],
|
StatusTitle: constants.OrderStatusMessage[v],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
list[0].Ctime = noTime
|
list[0].Ctime = &noTime
|
||||||
list[0].Utime = noTime
|
list[0].Utime = &noTime
|
||||||
list[len(list)-1].ExpectedTime = expectedTime
|
list[len(list)-1].ExpectedTime = &expectedTime
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user