-
Notifications
You must be signed in to change notification settings - Fork 1
/
owner.go
53 lines (49 loc) · 1.56 KB
/
owner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package user
import (
"github.com/admpub/nging/v5/application/handler"
"github.com/admpub/nging/v5/application/library/common"
"github.com/admpub/nging/v5/application/model"
"github.com/admpub/null"
modelCustomer "github.com/admpub/webx/application/model/official/customer"
"github.com/webx-top/db"
"github.com/webx-top/echo"
"github.com/webx-top/pagination"
)
func SelectCustomer(ctx echo.Context) error {
m := modelCustomer.NewCustomer(ctx)
cond := &db.Compounds{}
common.SelectPageCond(ctx, cond, `id`, `name%`)
_, err := handler.PagingWithLister(ctx, handler.NewLister(m, nil, func(r db.Result) db.Result {
return r.Select(`id`, `name`).OrderBy(`-id`)
}, cond.And()))
if err != nil {
return err
}
ctx.Set(`listData`, m.Objects())
return ctx.JSON(ctx.Data().SetData(ctx.Stored()))
}
func SelectUser(ctx echo.Context) error {
cond := &db.Compounds{}
common.SelectPageCond(ctx, cond, `id`, `username%`)
m := model.NewUser(ctx)
listData := []null.StringMap{}
_, err := handler.PagingWithLister(ctx, handler.NewLister(m, &listData, func(r db.Result) db.Result {
return r.Select(`id`, db.Raw(`username AS name`)).OrderBy(`-id`)
}, cond.And()))
if err != nil {
return err
}
ctx.Set(`listData`, listData)
return ctx.JSON(ctx.Data().SetData(ctx.Stored()))
}
func SelectOwner(ctx echo.Context, operation string) error {
if len(operation) > 0 {
switch operation {
case `customer`:
return SelectCustomer(ctx)
case `user`:
return SelectUser(ctx)
}
}
return ctx.JSON(ctx.Data().SetData(echo.H{`listData`: nil, `pagination`: pagination.New(ctx)}))
}