69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package handler
|
|
|
|
import (
|
|
"affiliate_dash/internal/middleware"
|
|
"affiliate_dash/internal/model"
|
|
"affiliate_dash/internal/pkg/response"
|
|
"affiliate_dash/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// DashboardHandler 仪表盘统计接口。
|
|
type DashboardHandler struct {
|
|
svc *service.FulfillmentService
|
|
}
|
|
|
|
func NewDashboardHandler(svc *service.FulfillmentService) *DashboardHandler {
|
|
return &DashboardHandler{svc: svc}
|
|
}
|
|
|
|
func (h *DashboardHandler) Dashboard(c *gin.Context) {
|
|
isAdmin := middleware.GetRole(c) == model.RoleAdmin
|
|
stats, err := h.svc.Dashboard(middleware.GetMerchantID(c), isAdmin)
|
|
if err != nil {
|
|
response.ServerError(c, err.Error())
|
|
return
|
|
}
|
|
if !isAdmin {
|
|
permissions := middleware.GetMerchantPermissions(c)
|
|
if _, ok := permissions[model.PermissionProductsManage]; !ok {
|
|
stats.CatalogProductCount = 0
|
|
stats.ProductCount = 0
|
|
stats.ActiveProductCount = 0
|
|
}
|
|
if _, ok := permissions[model.PermissionMembersManage]; !ok {
|
|
stats.UserCount = 0
|
|
}
|
|
if _, ok := permissions[model.PermissionOrdersManage]; !ok {
|
|
stats.OrderCount = 0
|
|
stats.TodayOrderCount = 0
|
|
stats.PaidOrderCount = 0
|
|
stats.DeliveringOrderCount = 0
|
|
stats.DeliveredOrderCount = 0
|
|
stats.ShipFailedOrderCount = 0
|
|
stats.CancelledOrderCount = 0
|
|
}
|
|
if _, ok := permissions[model.PermissionWalletView]; !ok {
|
|
stats.TotalSales = 0
|
|
stats.TodaySales = 0
|
|
stats.TotalFees = 0
|
|
stats.TodayFees = 0
|
|
}
|
|
if _, ok := permissions[model.PermissionWalletView]; !ok {
|
|
stats.WalletAvailableBalance = 0
|
|
stats.WalletFrozenBalance = 0
|
|
}
|
|
if _, ok := permissions[model.PermissionAPIManage]; !ok {
|
|
stats.APIClientCount = 0
|
|
stats.ActiveAPIClientCount = 0
|
|
}
|
|
if _, ok := permissions[model.PermissionCallbacksManage]; !ok {
|
|
stats.CallbackSubscriptionCount = 0
|
|
stats.PendingCallbackCount = 0
|
|
stats.FailedCallbackCount = 0
|
|
}
|
|
}
|
|
response.OK(c, stats)
|
|
}
|