feat:优化项目信息
This commit is contained in:
99
app/api/admin/controller/order/instance.go
Normal file
99
app/api/admin/controller/order/instance.go
Normal file
@ -0,0 +1,99 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"SciencesServer/app/api/admin/model"
|
||||
"SciencesServer/app/basic/controller"
|
||||
model2 "SciencesServer/app/common/model"
|
||||
"SciencesServer/app/session"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Instance struct {
|
||||
*session.Admin
|
||||
}
|
||||
|
||||
type InstanceHandle func(session *session.Admin) *Instance
|
||||
|
||||
type (
|
||||
// InstanceInfo 订单信息
|
||||
InstanceInfo struct {
|
||||
ID string `json:"id"`
|
||||
*model.OrderInstanceInfo
|
||||
}
|
||||
// InstanceDetail 订单详细信息
|
||||
InstanceDetail struct {
|
||||
ID string `json:"id"`
|
||||
*model.OrderInstanceInfo
|
||||
Params *model2.OrderInstanceParams `json:"params"`
|
||||
}
|
||||
// InstancePageInfo 订单分页信息
|
||||
InstancePageInfo struct {
|
||||
*controller.ReturnPages
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
)
|
||||
|
||||
// Index 首页信息
|
||||
func (c *Instance) Index(orderNo, name, mobile, status string, page, pageSize int) (*InstancePageInfo, error) {
|
||||
mOrderInstance := model.NewOrderInstance()
|
||||
|
||||
var count int64
|
||||
|
||||
where := make([]*model2.ModelWhere, 0)
|
||||
|
||||
if orderNo != "" {
|
||||
where = append(where, model2.NewWhereLike("o.order_no", orderNo))
|
||||
}
|
||||
if name != "" {
|
||||
where = append(where, model2.NewWhereLike("u.name", name))
|
||||
}
|
||||
if mobile != "" {
|
||||
where = append(where, model2.NewWhereLike("u.mobile", mobile))
|
||||
}
|
||||
if status != "" {
|
||||
where = append(where, model2.NewWhereLike("o.status", utils.StringToInt(status)))
|
||||
}
|
||||
var amount float64
|
||||
|
||||
out, err := mOrderInstance.Orders(page, pageSize, &count, &amount)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*InstanceInfo, 0)
|
||||
|
||||
for _, v := range out {
|
||||
list = append(list, &InstanceInfo{
|
||||
ID: v.GetEncodeID(), OrderInstanceInfo: v,
|
||||
})
|
||||
}
|
||||
return &InstancePageInfo{
|
||||
ReturnPages: &controller.ReturnPages{Data: list, Count: count},
|
||||
Amount: amount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Detail 详细信息
|
||||
func (c *Instance) Detail(id uint64) (*InstanceDetail, error) {
|
||||
mOrderInstance := model.NewOrderInstance()
|
||||
|
||||
out, err := mOrderInstance.Detail(id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if out.ID <= 0 {
|
||||
return nil, errors.New("操作错误,订单信息不存在或已被删除")
|
||||
}
|
||||
return &InstanceDetail{
|
||||
ID: mOrderInstance.GetEncodeID(),
|
||||
OrderInstanceInfo: out,
|
||||
Params: out.GetParamsAttribute(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *session.Admin) *Instance {
|
||||
return &Instance{session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user