Files

56 lines
1.8 KiB
Go

package delivery
import (
"git.apinb.com/bsm-sdk/core/infra"
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/common"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"github.com/gin-gonic/gin"
)
func Dashboard(ctx *gin.Context) {
point, _, ok := currentScope(ctx)
if !ok {
return
}
result := gin.H{}
queries := []struct {
key string
model any
where string
args []any
}{
{"staff_count", &models.StaffAccount{}, "delivery_basic_id = ? AND role_code = ? AND status <> ?", []any{point.ID, "delivery", common.StatusArchived}},
{"user_count", &models.UserServiceRelation{}, "delivery_basic_id = ? AND status <> ?", []any{point.ID, common.StatusArchived}},
{"contract_count", &models.GasorderContract{}, "delivery_basic_id = ? AND status <> ?", []any{point.ID, common.StatusArchived}},
{"order_count", &models.GasorderBasic{}, "delivery_basic_id = ? AND status <> ?", []any{point.ID, common.StatusArchived}},
}
for _, query := range queries {
var count int64
if err := db().Model(query.model).Where(query.where, query.args...).Count(&count).Error; err != nil {
infra.Response.Error(ctx, err)
return
}
result[query.key] = count
}
infra.Response.Success(ctx, result)
}
func DashboardReport(ctx *gin.Context) {
point, _, ok := currentScope(ctx)
if !ok {
return
}
type row struct {
Status int `json:"status"`
Count int64 `json:"count"`
}
var rows []row
if err := db().Model(&models.GasorderBasic{}).Select("order_status AS status, count(*) AS count").
Where("delivery_basic_id = ? AND status <> ?", point.ID, common.StatusArchived).
Group("order_status").Order("order_status").Scan(&rows).Error; err != nil {
infra.Response.Error(ctx, err)
return
}
infra.Response.Success(ctx, gin.H{"orders_by_status": rows})
}