Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
@@ -54,7 +54,18 @@ func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, userinfo *a
|
||||
qrType = *qrCodeSet.SvgFacebook
|
||||
}
|
||||
//生成二维码
|
||||
imgBase64, err := qrcode.CreateQrCodeBs64WithLogo(req.Url, "", "", 512, int(*qrCodeSet.IndexX), int(*qrCodeSet.IndexY), true)
|
||||
qrReq := qrcode.CreateQrCodeBs64WithLogoReq{
|
||||
Content: req.Url,
|
||||
OutPath: nil,
|
||||
LogoPath: nil,
|
||||
Size: *qrCodeSet.Size,
|
||||
X: qrCodeSet.IndexX,
|
||||
Y: qrCodeSet.IndexY,
|
||||
ForegroundColor: nil,
|
||||
BackgroundColor: nil,
|
||||
DisableBorder: false,
|
||||
}
|
||||
imgBase64, err := qrcode.CreateQrCodeBs64WithLogo(qrReq)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to generate qrcode")
|
||||
|
||||
@@ -33,7 +33,7 @@ func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserIn
|
||||
}
|
||||
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindAllGetType(l.ctx, userinfo.UserId)
|
||||
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindAllGetType(l.ctx)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
|
||||
78
server/orders/internal/handler/getorderdetailhandler.go
Normal file
78
server/orders/internal/handler/getorderdetailhandler.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/orders/internal/logic"
|
||||
"fusenapi/server/orders/internal/svc"
|
||||
"fusenapi/server/orders/internal/types"
|
||||
)
|
||||
|
||||
func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var (
|
||||
// 定义错误变量
|
||||
err error
|
||||
// 定义用户信息变量
|
||||
userinfo *auth.UserInfo
|
||||
)
|
||||
// 解析JWT token,并对空用户进行判断
|
||||
claims, err := svcCtx.ParseJwtToken(r)
|
||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401, // 返回401状态码,表示未授权
|
||||
Message: "unauthorized", // 返回未授权信息
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||
return
|
||||
}
|
||||
|
||||
if claims != nil {
|
||||
// 从token中获取对应的用户信息
|
||||
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 401,
|
||||
Message: "unauthorized",
|
||||
})
|
||||
logx.Info("unauthorized:", err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 如果claims为nil,则认为用户身份为白板用户
|
||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||
}
|
||||
|
||||
var req types.GetOrderDetailReq
|
||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewGetOrderDetailLogic(r.Context(), svcCtx)
|
||||
resp := l.GetOrderDetail(&req, userinfo)
|
||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/order/invoice",
|
||||
Handler: GetOrderInvoiceHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/order/detail",
|
||||
Handler: GetOrderDetailHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
218
server/orders/internal/logic/getorderdetaillogic.go
Normal file
218
server/orders/internal/logic/getorderdetaillogic.go
Normal file
@@ -0,0 +1,218 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/order"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/orders/internal/svc"
|
||||
"fusenapi/server/orders/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetOrderDetailLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetOrderDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderDetailLogic {
|
||||
return &GetOrderDetailLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetOrderDetailLogic) GetOrderDetail(req *types.GetOrderDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
//查询订单信息
|
||||
orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn)
|
||||
orderInfo, err := orderModel.FindOneBySn(l.ctx, userinfo.UserId, req.Sn)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeServiceErr, "failed to get order info")
|
||||
}
|
||||
if orderInfo.Id == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the order is not exists")
|
||||
}
|
||||
address := types.Address{}
|
||||
//直接邮寄才有地址信息
|
||||
if *orderInfo.DeliveryMethod == constants.DELIVERY_METHOD_ADDRESS {
|
||||
addressInfo, err := gmodel.NewFsAddressModel(l.svcCtx.MysqlConn).GetOne(l.ctx, *orderInfo.AddressId, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get address info")
|
||||
}
|
||||
if addressInfo.Id == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "address not exists")
|
||||
}
|
||||
address.Id = addressInfo.Id
|
||||
address.UserId = *addressInfo.UserId
|
||||
address.Name = *addressInfo.Name
|
||||
address.FirstName = *addressInfo.FirstName
|
||||
address.LastName = *addressInfo.LastName
|
||||
address.Mobile = *addressInfo.Mobile
|
||||
address.Street = *addressInfo.Street
|
||||
address.Suite = *addressInfo.Suite
|
||||
address.City = *addressInfo.City
|
||||
address.State = *addressInfo.State
|
||||
address.Country = *addressInfo.Country
|
||||
address.ZipCode = *addressInfo.ZipCode
|
||||
address.Status = *addressInfo.Status
|
||||
address.IsDefault = *addressInfo.IsDefault
|
||||
}
|
||||
//获取订单详情
|
||||
orderDetailModel := gmodel.NewFsOrderDetailModel(l.svcCtx.MysqlConn)
|
||||
orderDetails, err := orderDetailModel.GetOrderDetailsByOrderId(l.ctx, orderInfo.Id)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order details")
|
||||
}
|
||||
if len(orderDetails) == 0 {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order details is empty")
|
||||
}
|
||||
optionalIds := make([]int64, 0, len(orderDetails))
|
||||
productIds := make([]int64, 0, len(orderDetails))
|
||||
orderDetailTemplateIds := make([]int64, 0, len(orderDetails))
|
||||
for _, v := range orderDetails {
|
||||
optionalIds = append(optionalIds, *v.OptionalId)
|
||||
productIds = append(productIds, *v.ProductId)
|
||||
orderDetailTemplateIds = append(orderDetailTemplateIds, *v.OrderDetailTemplateId)
|
||||
}
|
||||
//获取配件列表
|
||||
productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn)
|
||||
productModel3dList, err := productModel3dModel.GetAllByIds(l.ctx, optionalIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product 3d models")
|
||||
}
|
||||
mapModel3d := make(map[int64]int)
|
||||
for k, v := range productModel3dList {
|
||||
mapModel3d[v.Id] = k
|
||||
}
|
||||
//获取产品列表
|
||||
productModel := gmodel.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||
productList, err := productModel.GetProductListByIds(l.ctx, productIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order product list")
|
||||
}
|
||||
mapProduct := make(map[int64]int)
|
||||
for k, v := range productList {
|
||||
mapProduct[v.Id] = k
|
||||
}
|
||||
//获取模板列表
|
||||
orderDetailTemplateModel := gmodel.NewFsOrderDetailTemplateModel(l.svcCtx.MysqlConn)
|
||||
detailTemplateList, err := orderDetailTemplateModel.GetListByIds(l.ctx, orderDetailTemplateIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order detail template list")
|
||||
}
|
||||
sizeIds := make([]int64, 0, len(detailTemplateList))
|
||||
mapDetailTemplate := make(map[int64]int)
|
||||
for k, v := range detailTemplateList {
|
||||
sizeIds = append(sizeIds, *v.SizeId)
|
||||
mapDetailTemplate[v.Id] = k
|
||||
}
|
||||
//获取尺寸信息
|
||||
productSizeModel := gmodel.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||
productSizeList, err := productSizeModel.GetAllByIds(l.ctx, sizeIds, "")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product size list")
|
||||
}
|
||||
mapProductSize := make(map[int64]int)
|
||||
for k, v := range productSizeList {
|
||||
mapProductSize[v.Id] = k
|
||||
}
|
||||
//获取支付信息
|
||||
payModel := gmodel.NewFsPayModel(l.svcCtx.MysqlConn)
|
||||
payList, err := payModel.GetOrderPayList(l.ctx, *orderInfo.Sn, 1, 0)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get pay records")
|
||||
}
|
||||
mapPay := make(map[int64]int) //pay_stat作为索引
|
||||
for k, v := range payList {
|
||||
mapPay[*v.PayStage] = k
|
||||
}
|
||||
//处理订单状态
|
||||
orderStatus := order.GetOrderStatus(*orderInfo.Status, *orderInfo.DeliveryMethod)
|
||||
//组装
|
||||
productListRsp := make([]types.Product, 0, len(orderDetails))
|
||||
for _, v := range orderDetails {
|
||||
cover := *v.Cover
|
||||
if req.Size >= 200 {
|
||||
coverSlice := strings.Split(".", *v.Cover)
|
||||
if len(coverSlice) >= 2 {
|
||||
cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
|
||||
}
|
||||
}
|
||||
Fitting := ""
|
||||
if model3dIndex, ok := mapModel3d[*v.OptionalId]; ok {
|
||||
Fitting = *productModel3dList[model3dIndex].Title
|
||||
}
|
||||
pcBox := int64(0)
|
||||
Size := ""
|
||||
if detailTemplateIndex, ok := mapDetailTemplate[*v.OrderDetailTemplateId]; ok {
|
||||
pcBox = *v.BuyNum / *detailTemplateList[detailTemplateIndex].EachBoxNum
|
||||
if sizeIndex, ok := mapProductSize[*detailTemplateList[detailTemplateIndex].SizeId]; ok {
|
||||
Size = *productSizeList[sizeIndex].Capacity
|
||||
}
|
||||
}
|
||||
Title := ""
|
||||
if productIndex, ok := mapProduct[*v.ProductId]; ok {
|
||||
Title = *productList[productIndex].Title
|
||||
}
|
||||
productListRsp = append(productListRsp, types.Product{
|
||||
Cover: cover,
|
||||
Fitting: Fitting,
|
||||
OptionPrice: *v.OptionPrice,
|
||||
OrderDetailTemplateId: *v.OrderDetailTemplateId,
|
||||
OrderId: *v.OrderId,
|
||||
Pcs: *v.BuyNum,
|
||||
PcsBox: pcBox,
|
||||
Price: *v.Amount,
|
||||
ProductId: *v.ProductId,
|
||||
Size: Size,
|
||||
Title: Title,
|
||||
})
|
||||
}
|
||||
data := types.GetOrderDetailRsp{
|
||||
Id: orderInfo.Id,
|
||||
TotalAmount: *orderInfo.TotalAmount,
|
||||
Deposit: *orderInfo.TotalAmount / 2,
|
||||
Remaining: *orderInfo.TotalAmount - *orderInfo.TotalAmount/2,
|
||||
IsPayCompleted: *orderInfo.IsPayCompleted,
|
||||
DeliveryMethod: *orderInfo.DeliveryMethod,
|
||||
Sn: *orderInfo.Sn,
|
||||
Status: orderStatus,
|
||||
Ctime: time.Unix(*orderInfo.Ctime, 0).Format("2006-01-02 15:04:05"),
|
||||
PayInfo: types.PayInfo{},
|
||||
Address: address,
|
||||
ProductList: productListRsp,
|
||||
}
|
||||
//首款
|
||||
if payIndex, ok := mapPay[1]; ok {
|
||||
data.PayInfo.Deposit = types.Deposit{
|
||||
Method: *payList[payIndex].Brand,
|
||||
TransNo: *payList[payIndex].TradeNo,
|
||||
}
|
||||
}
|
||||
//尾款
|
||||
if payIndex, ok := mapPay[2]; ok {
|
||||
data.PayInfo.Final = types.Deposit{
|
||||
Method: *payList[payIndex].Brand,
|
||||
TransNo: *payList[payIndex].TradeNo,
|
||||
}
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", data)
|
||||
}
|
||||
@@ -15,6 +15,67 @@ type GetOrderInvoiceRsp struct {
|
||||
Pdf string `json:"pdf"`
|
||||
}
|
||||
|
||||
type GetOrderDetailReq struct {
|
||||
Sn string `form:"sn"`
|
||||
Size int64 `form:"size, optional"`
|
||||
}
|
||||
|
||||
type GetOrderDetailRsp struct {
|
||||
Id int64 `json:"id"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
Deposit int64 `json:"deposit"`
|
||||
Remaining int64 `json:"remaining"`
|
||||
IsPayCompleted int64 `json:"is_pay_completed"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
Sn string `json:"sn"`
|
||||
Status int64 `json:"status"`
|
||||
Ctime string `json:"ctime"`
|
||||
PayInfo PayInfo `json:"pay_info"`
|
||||
Address Address `json:"address"`
|
||||
ProductList []Product `json:"productList"`
|
||||
}
|
||||
|
||||
type Product struct {
|
||||
Cover string `json:"cover"`
|
||||
Fitting string `json:"fitting"`
|
||||
OptionPrice int64 `json:"option_price"`
|
||||
OrderDetailTemplateId int64 `json:"order_detail_template_id"`
|
||||
OrderId int64 `json:"order_id"`
|
||||
Pcs int64 `json:"pcs"`
|
||||
PcsBox int64 `json:"pcs_box"`
|
||||
Price int64 `json:"price"`
|
||||
ProductId int64 `json:"product_id"`
|
||||
Size string `json:"size"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
type Address struct {
|
||||
Id int64 `json:"id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
FirstName string `json:"first_name"`
|
||||
LastName string `json:"last_name"`
|
||||
Mobile string `json:"mobile"`
|
||||
Street string `json:"street"`
|
||||
Suite string `json:"suite"`
|
||||
City string `json:"city"`
|
||||
State string `json:"state"`
|
||||
Country string `json:"country"`
|
||||
ZipCode string `json:"zip_code"`
|
||||
Status int64 `json:"status"`
|
||||
IsDefault int64 `json:"is_default"`
|
||||
}
|
||||
|
||||
type PayInfo struct {
|
||||
Deposit Deposit `json:"Deposit"`
|
||||
Final Deposit `json:"Final"`
|
||||
}
|
||||
|
||||
type Deposit struct {
|
||||
Method string `json:"method"`
|
||||
TransNo string `json:"trans_no"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
|
||||
@@ -55,7 +55,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||
}
|
||||
//查询用户信息
|
||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
userInfo, err := userModel.FindOne(l.ctx, userinfo.UserId)
|
||||
userInfo, err := userModel.FindUserById(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||
@@ -150,7 +150,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
|
||||
//千人千面处理
|
||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: int(userInfo.IsThousandFace),
|
||||
IsThousandFace: int(*userInfo.IsThousandFace),
|
||||
Cover: *v.Cover,
|
||||
CoverImg: *v.CoverImg,
|
||||
CoverDefault: *v.CoverImg,
|
||||
|
||||
@@ -32,7 +32,7 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
||||
}
|
||||
//获取用户信息
|
||||
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
|
||||
user, err := userModel.FindOne(l.ctx, userInfo.UserId)
|
||||
user, err := userModel.FindUserById(l.ctx, userInfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
|
||||
@@ -68,7 +68,7 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
|
||||
//千人千面处理
|
||||
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: int(user.IsThousandFace),
|
||||
IsThousandFace: int(*user.IsThousandFace),
|
||||
Cover: *v.Cover,
|
||||
CoverImg: *v.CoverImg,
|
||||
CoverDefault: *v.CoverImg,
|
||||
|
||||
Reference in New Issue
Block a user