38cffc2f2a
CI / changes (push) Successful in 1m43s
CI / ad (push) Successful in 1s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 37s
CI / chore (push) Successful in 1s
CI / equipment (push) Successful in 27s
CI / express (push) Successful in 0s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 1s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 36s
CI / product (push) Successful in 0s
CI / record (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 0s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 1s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 1s
107 lines
2.6 KiB
Go
107 lines
2.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/services/equipment/internal/dao"
|
|
"lone-services/services/equipment/internal/model"
|
|
"strconv"
|
|
|
|
"lone-services/rpc/equipment/pb"
|
|
"lone-services/services/equipment/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AuthorizationStoreItemsLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewAuthorizationStoreItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorizationStoreItemsLogic {
|
|
return &AuthorizationStoreItemsLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// 门店端获取授权列表
|
|
func (l *AuthorizationStoreItemsLogic) AuthorizationStoreItems(in *equipment.EmptyRequest) (*equipment.Response, error) {
|
|
adminInfo := utils.GetUserFromCtx(l.ctx)
|
|
if adminInfo.ID < utils.NumberOne {
|
|
return l.fail(utils.ErrorNoLoginInfo)
|
|
}
|
|
|
|
w := modelbase.Params{Eq: map[string]string{
|
|
"store_id": strconv.Itoa(int(adminInfo.BizId))}}
|
|
var info []dao.AuthorizationRecordInfo
|
|
err := model.AuthorizationRecordModel{}.Init().Items(w, &info)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
return l.fail(utils.Fail)
|
|
}
|
|
|
|
ids := make(map[int64]int64)
|
|
for _, v := range info {
|
|
ids[v.UserId] = v.UserId
|
|
}
|
|
|
|
var items []dao.AuthorizationRecordStoreItems
|
|
if len(ids) < utils.NumberOne {
|
|
return l.ok(items)
|
|
}
|
|
idsSlice := make([]int64, 0, len(ids))
|
|
for k := range ids {
|
|
idsSlice = append(idsSlice, k)
|
|
}
|
|
|
|
userItems := svc.GetUsers(idsSlice, l.svcCtx.UserSvcName)
|
|
|
|
userIdItems := make(map[int64]dao.AuthorizationRecordStoreItems)
|
|
|
|
for _, val := range userItems {
|
|
ww := modelbase.Params{Eq: map[string]string{
|
|
"store_id": strconv.Itoa(int(adminInfo.BizId)),
|
|
"user_id": strconv.Itoa(int(val.Id))}}
|
|
storeNumber, err := model.AuthorizationRecordModel{}.Init().CountNumber(ww)
|
|
if err != nil {
|
|
l.Logger.Error(err)
|
|
}
|
|
|
|
mobile := utils.StringEmpty
|
|
if val.Mobile != utils.StringEmpty {
|
|
tmp, phoneErr := utils.DecryptPhone(val.Mobile)
|
|
if phoneErr != nil {
|
|
l.Logger.Error(phoneErr)
|
|
}
|
|
mobile = tmp
|
|
}
|
|
userIdItems[val.Id] = dao.AuthorizationRecordStoreItems{
|
|
Username: val.Name,
|
|
Mobile: mobile,
|
|
Avatar: val.Avatar,
|
|
Birthday: val.Birthday,
|
|
Gender: int32(val.Gender),
|
|
UsageCount: int32(storeNumber),
|
|
}
|
|
|
|
}
|
|
|
|
for _, v := range info {
|
|
item, ok := userIdItems[v.UserId]
|
|
if !ok {
|
|
continue
|
|
}
|
|
item.Id = v.Id
|
|
item.Open = v.Open
|
|
item.Status = v.Status
|
|
item.UserId = v.UserId
|
|
items = append(items, item)
|
|
}
|
|
return l.ok(items)
|
|
}
|