Files
lone-services/services/sale/internal/logic/apiLowerSaleItemsLogic.go
T
2026-09-23 11:24:25 +08:00

85 lines
2.1 KiB
Go

package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/pkg/validate"
"lone-services/rpc/sale/pb"
"lone-services/services/sale/internal/dao"
"lone-services/services/sale/internal/model"
"lone-services/services/sale/internal/svc"
"lone-services/services/sale/validator"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
type ApiLowerSaleItemsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewApiLowerSaleItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiLowerSaleItemsLogic {
return &ApiLowerSaleItemsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApiLowerSaleItemsLogic) ApiLowerSaleItems(in *sale.ApiLowerSaleItemsReq) (*sale.Response, error) {
var req validator.ApiSalesItemsValidator
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
return outResponse(utils.ErrorParams, msg), nil
}
adminInfo := utils.GetUserFromCtx(l.ctx)
if adminInfo.ID < utils.NumberOne {
return failResponse(utils.ErrorNoLoginInfo), nil
}
var info []dao.APiSaleInfo
w := modelbase.Params{
Page: int(in.Page),
Size: int(in.Size),
Order: "id desc",
Eq: map[string]string{"sale_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)},
In: map[string][]string{
"status": {
utils.StringStatusOk,
utils.StatusForbiddenString,
strconv.Itoa(int(utils.StatusWaitPass))},
},
}
if in.Type > utils.NumberZero {
if in.Type == utils.NumberNine {
w.In["type"] = []string{strconv.Itoa(int(dao.SaleTypeAgentCorp)), strconv.Itoa(int(dao.SaleTypeAgentPerson))}
} else {
w.Eq["type"] = strconv.Itoa(int(in.Type))
}
}
w.Like = make(map[string]string)
if len(in.Name) > utils.NumberZero {
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
}
items, err := model.SaleModel{}.Init().Page(w, &info)
if err != nil {
l.Logger.Error(err)
return failResponse(utils.Fail), nil
}
for key, v := range info {
mobile, aErr := utils.Crypto{}.AESDecryptECB(v.Mobile)
if aErr == nil {
info[key].Mobile = mobile
}
}
items.Items = info
return okResponse(items), nil
}