92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/dao"
|
|
"lone-services/services/order/internal/model"
|
|
"lone-services/services/order/internal/svc"
|
|
"strconv"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AddressItemLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewAddressItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddressItemLogic {
|
|
return &AddressItemLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *AddressItemLogic) AddressItem(in *order.AddressItemsRequest) (*order.Response, error) {
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
var info []dao.Address
|
|
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 len(in.Name) > utils.NumberZero {
|
|
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
|
|
}
|
|
//Time string
|
|
if len(in.Mobile) > utils.NumberZero {
|
|
phone := utils.GetSearchPhone(in.Mobile)
|
|
if len(phone) > utils.NumberZero {
|
|
w.Like["mobile LIKE ? "] = "%%" + phone + "%%"
|
|
}
|
|
}
|
|
if in.DistrictId > utils.NumberZero {
|
|
w.Other["FIND_IN_SET(?, district_ids)"] = strconv.FormatInt(in.DistrictId, utils.NumberTen)
|
|
}
|
|
if len(in.Name) > utils.NumberZero {
|
|
w.Eq["name"] = in.Name
|
|
}
|
|
if in.StoreId > utils.NumberZero {
|
|
w.Eq["target_id"] = strconv.FormatInt(in.StoreId, utils.NumberTen)
|
|
w.Eq["type"] = strconv.Itoa(dao.AddressTypeStore)
|
|
}
|
|
if in.SaleId > utils.NumberZero {
|
|
w.Eq["target_id"] = strconv.FormatInt(in.SaleId, utils.NumberTen)
|
|
w.Eq["type"] = strconv.Itoa(dao.AddressTypeSale)
|
|
}
|
|
|
|
if len(in.Time) > utils.NumberZero {
|
|
w.Other["create_time > ?"] = in.Time[utils.NumberZero]
|
|
w.Other["create_time < ?"] = in.Time[utils.NumberOne]
|
|
}
|
|
|
|
err := model.AddressModel{}.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
|
|
l.Logger.Error(mobile)
|
|
info[key].Mobile = utils.DecryptPhoneReplace(mobile)
|
|
l.Logger.Error(utils.DecryptPhoneReplace(mobile))
|
|
}
|
|
}
|
|
return l.ok(info)
|
|
}
|