feat: implement gas and delivery admin systems
This commit is contained in:
64
backend/api/internal/logic/gas/dashboard.go
Normal file
64
backend/api/internal/logic/gas/dashboard.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package gas
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
||||
"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 DashboardOverview(ctx *gin.Context) {
|
||||
station, ok := currentGas(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
counts := gin.H{}
|
||||
queries := []struct {
|
||||
key string
|
||||
query any
|
||||
where string
|
||||
args []any
|
||||
}{
|
||||
{"delivery_count", &models.DeliveryBasic{}, "gas_basic_id = ? AND status <> ?", []any{station.ID, common.StatusArchived}},
|
||||
{"staff_count", &models.StaffAccount{}, "gas_basic_id = ? AND status <> ?", []any{station.ID, common.StatusArchived}},
|
||||
{"contract_count", &models.GasorderContract{}, "gas_basic_id = ? AND status <> ?", []any{station.ID, common.StatusArchived}},
|
||||
{"order_count", &models.GasorderBasic{}, "gas_basic_id = ? AND status <> ?", []any{station.ID, common.StatusArchived}},
|
||||
}
|
||||
for _, item := range queries {
|
||||
var count int64
|
||||
if err := impl.DBService.Model(item.query).Where(item.where, item.args...).Count(&count).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
counts[item.key] = count
|
||||
}
|
||||
var userCount int64
|
||||
if err := impl.DBService.Model(&models.UserServiceRelation{}).
|
||||
Where("gas_basic_id = ? AND status <> ?", station.ID, common.StatusArchived).Count(&userCount).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
counts["user_count"] = userCount
|
||||
infra.Response.Success(ctx, counts)
|
||||
}
|
||||
|
||||
func DashboardReport(ctx *gin.Context) {
|
||||
station, ok := currentGas(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
type statusCount struct {
|
||||
Status int `json:"status"`
|
||||
Count int64 `json:"count"`
|
||||
}
|
||||
var orders []statusCount
|
||||
if err := impl.DBService.Model(&models.GasorderBasic{}).
|
||||
Select("order_status AS status, count(*) AS count").
|
||||
Where("gas_basic_id = ? AND status <> ?", station.ID, common.StatusArchived).
|
||||
Group("order_status").Order("order_status").Scan(&orders).Error; err != nil {
|
||||
infra.Response.Error(ctx, err)
|
||||
return
|
||||
}
|
||||
infra.Response.Success(ctx, gin.H{"orders_by_status": orders})
|
||||
}
|
||||
Reference in New Issue
Block a user