statistics_company.go 4.4 KB
package service

import (
	"fmt"
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/dto"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
	"math/rand"
	"time"
)

// 企业端统计  【0%】
type CompanyStatisticsService struct {
}

// IndexStatistics  TODO:首页统计 (入口页面统计数据)
func (srv CompanyStatisticsService) IndexStatistics(cmd *command.IndexStatisticsCommand) (interface{}, error) {
	value := dto.IndexStatistics{}
	value.ProjectOverviewStatistics.ContractSum = 20
	value.ProjectOverviewStatistics.CooperationUserCount = 5
	value.ProjectOverviewStatistics.ProjectSum = 5

	gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
		cmd.Operator)
	companyDividendsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CompanyDividendsStatistics, map[string]interface{}{
		"companyId": cmd.Operator.CompanyId,
		"orgId":     cmd.Operator.OrgId,
		"action":    1, //当前月
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	cooperationModeStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationModeStatistics, map[string]interface{}{
		"companyId": cmd.Operator.CompanyId,
		"orgId":     cmd.Operator.OrgId,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}
	cooperationGoodsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationGoodsStatistics, map[string]interface{}{
		"companyId": cmd.Operator.CompanyId,
		"orgId":     cmd.Operator.OrgId,
		"rankType":  1, //月榜
		"top":       5,
	})
	if err != nil {
		return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
	}

	return map[string]interface{}{
		"currentMonthDividendsStatistics": companyDividendsStatistics,
		"cooperationModeStatistics":       cooperationModeStatistics,
		"CooperationGoodsStatistics":      cooperationGoodsStatistics,
	}, nil
}

// CooperationPersonStatistics  TODO:共创人员统计(共创人员明细)
func (srv CompanyStatisticsService) CooperationPersonStatistics(userMenusCommand *command.CooperationPersonStatisticsCommand) (interface{}, error) {
	return map[string]interface{}{}, nil
}

// GoodsStatistics  TODO:产品统计排行榜 年月榜
func (srv CompanyStatisticsService) GoodsStatistics(userMenusCommand *command.GoodsStatisticsCommand) (int64, interface{}, error) {
	type rankItem struct {
		GoodAmount float64 `json:"goodAmount"`
		GoodName   string  `json:"goodName"`
		GoodRatio  float64 `json:"goodRatio"`
		Rank       int     `json:"rank"`
	}
	var items []rankItem
	for i := 0; i < 5; i++ {
		item := rankItem{
			GoodAmount: 2000,
			GoodName:   fmt.Sprintf("商品%v", rand.Intn(100)),
			GoodRatio:  20,
			Rank:       i + 1,
		}
		items = append(items, item)
	}
	return 5, items, nil
}

// CooperationDividendsStatistics TODO:公司共创人员列表(分红支出统计)
func (srv CompanyStatisticsService) CooperationDividendsStatistics(userMenusCommand *command.CooperationDividendsStatisticsCommand) (int64, interface{}, error) {
	type cooperationDividendItem struct {
		CooperationTime      int64   `json:"cooperationTime"`
		DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
		ActuallyPaidAmount   float64 `json:"actuallyPaidAmount"`
		UnPaidAmount         float64 `json:"unPaidAmount"`
		Participator         struct {
			UserType int `json:"userType"`
			UserInfo struct {
				// 用户姓名
				UserName string `json:"userName,omitempty"`
				// 手机号码
				UserPhone string `json:"userPhone,omitempty"`
				// 头像
				//Avatar string `json:"avatar,omitempty"`
				// 邮箱
				//Email string `json:"email,omitempty"`
			} `json:"userInfo"`
		} `json:"participator"` // 参与人
	}

	var results []cooperationDividendItem
	for i := 0; i < 5; i++ {
		item := cooperationDividendItem{
			CooperationTime:      time.Now().Unix() * 1000,
			DividendsOrderAmount: 6000,
			ActuallyPaidAmount:   5000,
			UnPaidAmount:         1000,
		}
		item.Participator.UserInfo.UserName = fmt.Sprintf("用户%v", rand.Intn(100))
		results = append(results, item)
	}
	return 5, results, nil
}