130 lines
3.2 KiB
Go
130 lines
3.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/order/internal/dao"
|
|
"lone-services/services/order/internal/model"
|
|
"lone-services/services/order/validator"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ApiSupplyInfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewApiSupplyInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSupplyInfoLogic {
|
|
return &ApiSupplyInfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ApiSupplyInfoLogic) ApiSupplyInfo(in *order.ApiSupplyInfoRequest) (*order.Response, error) {
|
|
var v validator.SupplyInfoValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
w := modelbase.Params{Eq: map[string]string{
|
|
"sale_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen),
|
|
"order_sn": in.OrderSn,
|
|
},
|
|
}
|
|
|
|
var info dao.SupplyInfo
|
|
err := model.SupplyModel{}.Init().GetOne(w, &info)
|
|
if err != nil {
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
l.getData(&info)
|
|
return l.ok(info)
|
|
}
|
|
|
|
func (l *ApiSupplyInfoLogic) getData(info *dao.SupplyInfo) utils.Status {
|
|
|
|
w := modelbase.Params{Eq: map[string]string{"order_sn": info.OrderSn}}
|
|
var orderInfo dao.OrderInfo
|
|
err := model.OrderModel{}.Init().GetOne(w, &orderInfo)
|
|
if err != nil {
|
|
return utils.Fail
|
|
}
|
|
|
|
if orderInfo.Id < utils.NumberOne {
|
|
return utils.ErrorNotFund
|
|
}
|
|
|
|
var orderProducts []dao.OrderProductInfo
|
|
err = model.OrderProductModel{}.Init().Items(w, &orderProducts)
|
|
if err != nil {
|
|
return utils.Fail
|
|
}
|
|
if len(orderProducts) < utils.NumberOne {
|
|
return utils.ErrorNotFund
|
|
}
|
|
|
|
for _, item := range orderProducts {
|
|
info.ProductInfo = append(info.ProductInfo, dao.SupplyOrderProduct{
|
|
Id: item.ProductId,
|
|
Name: item.ProductName,
|
|
Price: item.Price,
|
|
Number: item.Number,
|
|
Images: strings.Split(item.Images, utils.DecollatorComma),
|
|
Content: item.Content,
|
|
})
|
|
}
|
|
|
|
if orderInfo.SaleMobile != utils.StringEmpty {
|
|
saleMobile, sErr := utils.DecryptPhone(orderInfo.SaleMobile)
|
|
if sErr != nil {
|
|
return utils.Fail
|
|
}
|
|
info.SaleMobile = saleMobile
|
|
}
|
|
|
|
if orderInfo.Mobile != utils.StringEmpty {
|
|
mobile, sErr := utils.DecryptPhone(orderInfo.Mobile)
|
|
if sErr != nil {
|
|
return utils.Fail
|
|
}
|
|
info.Mobile = mobile
|
|
}
|
|
info.SaleName = orderInfo.SaleName
|
|
info.StoreId = int64(orderInfo.StoreId)
|
|
info.StoreName = orderInfo.StoreName
|
|
info.Address = orderInfo.Address
|
|
info.Addressee = orderInfo.Addressee
|
|
info.OrderStatus = int32(orderInfo.Status)
|
|
if info.Status == int32(dao.SupplyStatusOk) {
|
|
deliveryInfo, dErr := svc.GetDeliveryInfo(l.svcCtx.ExpressSvcName, orderInfo.Id, dao.OrderTypeSupply)
|
|
if dErr != utils.Ok {
|
|
return dErr
|
|
}
|
|
info.DeliveryInfo = dao.SupplyOrderDeliveryInfo{
|
|
TransitName: deliveryInfo.TransitName,
|
|
TransitSn: deliveryInfo.TransitSn,
|
|
EstimatedTime: deliveryInfo.EstimatedTime,
|
|
TransitQuery: deliveryInfo.TransitQuery,
|
|
Status: deliveryInfo.Status,
|
|
Id: deliveryInfo.Id,
|
|
}
|
|
}
|
|
return utils.Ok
|
|
}
|