71 lines
1.6 KiB
Go
71 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
"lone-services/services/order/internal/dao"
|
|
"lone-services/services/order/internal/model"
|
|
"strconv"
|
|
"strings"
|
|
|
|
order "lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type OrderInfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderInfoLogic {
|
|
return &OrderInfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *OrderInfoLogic) OrderInfo(in *order.IdRequest) (*order.Response, error) {
|
|
var v validate.InfoValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
|
|
var info dao.OrderInfo
|
|
modelObj := model.OrderModel{}.Init()
|
|
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
|
err := modelObj.GetOne(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
if info.Id < utils.NumberOne {
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
var productItems []dao.OrderProducts
|
|
ww := modelbase.Params{
|
|
In: map[string][]string{"order_sn": strings.Split(info.ProductIds, utils.DecollatorComma)},
|
|
}
|
|
err = model.OrderProductModel{}.Init().Items(ww, &productItems)
|
|
if err != nil {
|
|
l.Logger.Error("product err:", err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
info.ProductItems = productItems
|
|
mobile, _ := utils.DecryptPhone(info.Mobile)
|
|
info.AesMobile = info.Mobile
|
|
info.Mobile = utils.DecryptPhoneReplace(mobile)
|
|
|
|
return l.ok(info)
|
|
|
|
}
|