fix(fee):完成配电维护费部分的查询语句调整。
This commit is contained in:
parent
308c9e959c
commit
ed83fbc77c
|
@ -131,14 +131,22 @@ func (_MaintenanceFeeService) EnsureFeeBelongs(uid, mid string) (bool, error) {
|
||||||
ctx, cancel := global.TimeoutContext()
|
ctx, cancel := global.TimeoutContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
exists, err := global.DB.NewSelect().Model((*model.Park)(nil)).
|
parks := make([]model.Park, 0)
|
||||||
|
err := global.DB.NewSelect().Model(&parks).
|
||||||
Relation("MaintenanceFees").
|
Relation("MaintenanceFees").
|
||||||
Where("p.user_id = ?", uid).
|
Where("p.user_id = ?", uid).
|
||||||
Where("m.id = ?", mid).
|
Scan(ctx)
|
||||||
Exists(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
exists := lo.Reduce(parks, func(acc bool, elem model.Park, _ int) bool {
|
||||||
|
for _, e := range elem.MaintenanceFees {
|
||||||
|
if e.Id == mid {
|
||||||
|
return acc || true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return acc || false
|
||||||
|
}, false)
|
||||||
if !exists {
|
if !exists {
|
||||||
return false, exceptions.NewNotFoundError("指定维护费所属园区未找到。")
|
return false, exceptions.NewNotFoundError("指定维护费所属园区未找到。")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user