Files
lone-services/services/order/internal/logic/itemsLogic.go
T
2026-08-26 17:32:54 +08:00

98 lines
2.4 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"
order "lone-services/rpc/order/pb"
"lone-services/services/order/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ItemsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic {
return &ItemsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ItemsLogic) Items(in *order.OrderItemsRequest) (*order.Response, error) {
var v validator.OrderItemsValidator
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)
}
var info []dao.OrderInfo
w := modelbase.Params{
Page: int(in.Page),
Size: int(in.Size),
Order: "id desc",
}
w.Like = make(map[string]string)
w.Eq = make(map[string]string)
w.Other = make(map[string]string)
if in.ProductId > utils.NumberZero {
w.Other["FIND_IN_SET(?, product_ids)"] = strconv.FormatInt(in.ProductId, utils.NumberTen)
}
//Time string
if len(in.Mobile) > utils.NumberZero {
phone := utils.GetSearchPhone(in.Mobile)
if len(phone) > utils.NumberZero {
w.Like["mobile LIKE ? "] = "%%" + phone + "%%"
}
}
if len(in.OrderSn) > utils.NumberZero {
w.Like["order_sn LIKE ? "] = "%%" + in.OrderSn + "%%"
}
if in.StoreId > utils.NumberZero {
w.Eq["store_id"] = strconv.FormatInt(in.StoreId, utils.NumberTen)
}
if in.SaleId > utils.NumberZero {
w.Eq["sale_id"] = strconv.FormatInt(in.SaleId, utils.NumberTen)
}
if in.Status > utils.NumberZero {
w.Eq["status"] = string(in.Status)
}
if len(in.Time) > utils.NumberZero {
w.Other["create_time > ?"] = strconv.Itoa(int(in.Time[utils.NumberZero]))
w.Other["create_time < ?"] = strconv.Itoa(int(in.Time[utils.NumberOne]))
}
err := model.OrderModel{}.Init().Items(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.ErrorNotFund)
}
for key, v := range info {
mobile, aErr := utils.DecryptPhone(v.Mobile)
if aErr == nil {
info[key].AesMobile = v.Mobile
info[key].Mobile = utils.DecryptPhoneReplace(mobile)
}
}
return l.ok(info)
}