104 lines
2.5 KiB
Go
104 lines
2.5 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"
|
|
|
|
"lone-services/rpc/order/pb"
|
|
"lone-services/services/order/internal/svc"
|
|
|
|
"github.com/samber/lo"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type OrderAuditingItemsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewOrderAuditingItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAuditingItemsLogic {
|
|
return &OrderAuditingItemsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *OrderAuditingItemsLogic) OrderAuditingItems(in *order.OrderAuditingItemsRequest) (*order.Response, error) {
|
|
var v validator.AdminOrderAuditingItemsValidator
|
|
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.OrderImitateItems
|
|
w := modelbase.Params{
|
|
Page: int(v.Page),
|
|
Size: int(v.Size),
|
|
Order: "id desc",
|
|
Eq: map[string]string{},
|
|
Other: map[string]string{"verify_status > ?": strconv.Itoa(utils.NumberZero)},
|
|
}
|
|
|
|
if v.Status > utils.NumberZero {
|
|
w.Eq = map[string]string{"verify_status": strconv.Itoa(int(v.Status))}
|
|
}
|
|
|
|
if len(in.Time) > utils.NumberZero {
|
|
w.Other["create_time > ?"] = in.Time[utils.NumberZero]
|
|
w.Other["create_time < ?"] = in.Time[utils.NumberOne]
|
|
}
|
|
|
|
items, err := model.OrderModel{}.Init().Page(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
var ids []string
|
|
for _, v := range info {
|
|
ids = append(ids, v.OrderSn)
|
|
}
|
|
|
|
if len(ids) < utils.NumberOne {
|
|
return l.ok(items)
|
|
}
|
|
|
|
var productItems []dao.OrderProducts
|
|
ww := modelbase.Params{
|
|
In: map[string][]string{"order_sn": ids},
|
|
}
|
|
err = model.OrderProductModel{}.Init().Items(ww, &productItems)
|
|
if err != nil {
|
|
utils.Logger.Error("product err:", err)
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
productMap := lo.GroupBy(productItems, func(item dao.OrderProducts) string {
|
|
return item.OrderSn
|
|
})
|
|
|
|
for key, v := range info {
|
|
mobile, aErr := utils.DecryptPhone(v.Mobile)
|
|
if aErr == nil {
|
|
if _, ok := productMap[v.OrderSn]; ok {
|
|
info[key].ProductItems = productMap[v.OrderSn]
|
|
}
|
|
info[key].AesMobile = v.Mobile
|
|
info[key].Mobile = utils.DecryptPhoneReplace(mobile)
|
|
}
|
|
}
|
|
items.Items = info
|
|
return l.ok(items)
|
|
}
|