order apis

This commit is contained in:
2026-08-26 17:32:54 +08:00
parent eabdc8772e
commit 299191749b
32 changed files with 1321 additions and 251 deletions
+68 -11
View File
@@ -2,6 +2,12 @@ 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"
@@ -25,16 +31,67 @@ func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic
}
func (l *ItemsLogic) Items(in *order.OrderItemsRequest) (*order.Response, error) {
//调用其它服务实例
//cli, err := svc.GetRpcClient(l.svcCtx.ExpressSvcName)
//if err != nil {
// l.Logger.Errorf("get express rpc err: %v", err)
// //降级逻辑
// return l.out(utils.ErrorInternalServer, "express"+utils.ErrorInternalServer.Msg)
//}
//expClient := express.NewExpressClient(cli.Conn())
//res, _ := expClient.Ping(context.Background(), &express.Request{})
//l.Logger.Error("res: %v", res)
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)
return &order.Response{}, nil
}