Browse Source

更新

master
huangjiajun 2 months ago
parent
commit
1e854cb5e9
21 changed files with 6708 additions and 751 deletions
  1. +73
    -0
      app/enum/adunit_enum.go
  2. +248
    -0
      app/hdl/hdl_data_center.go
  3. +84
    -0
      app/hdl/hdl_index.go
  4. +130
    -0
      app/hdl/hdl_settle_center.go
  5. +11
    -0
      app/md/comm.go
  6. +102
    -0
      app/md/md_data_center.go
  7. +24
    -0
      app/md/md_index.go
  8. +124
    -0
      app/md/md_settle_center.go
  9. +33
    -4
      app/router/router.go
  10. +31
    -0
      app/svc/svc_comm.go
  11. +640
    -0
      app/svc/svc_data_center.go
  12. +183
    -0
      app/svc/svc_index.go
  13. +4
    -4
      app/svc/svc_qualification.go
  14. +191
    -0
      app/svc/svc_settle_center.go
  15. +52
    -0
      app/utils/convert.go
  16. +11
    -16
      app/utils/rand.go
  17. +36
    -0
      app/utils/xls.go
  18. +1837
    -342
      docs/docs.go
  19. +1837
    -342
      docs/swagger.json
  20. +1051
    -42
      docs/swagger.yaml
  21. +6
    -1
      go.mod

+ 73
- 0
app/enum/adunit_enum.go View File

@@ -0,0 +1,73 @@
package enum

import "applet/app/md"

type AdunitType string //广告单元类型
var AdTypeList = []md.SelectData{
{Name: "banner", Value: AdunitTypeForBanner},
{Name: "激励视频", Value: AdunitTypeForRewardVideo},
{Name: "插屏广告", Value: AdunitTypeForInterstitial},
{Name: "视频广告", Value: AdunitTypeForVideoFeeds},
//{Name: "视频贴片广告", Value: "5"},
}

const (
AdunitTypeForBanner = "SLOT_ID_WEAPP_BANNER"
AdunitTypeForRewardVideo = "SLOT_ID_WEAPP_REWARD_VIDEO"
AdunitTypeForInterstitial = "SLOT_ID_WEAPP_INTERSTITIAL"
AdunitTypeForVideoFeeds = "SLOT_ID_WEAPP_VIDEO_FEEDS"
AdunitTypeForVideoBegin = "SLOT_ID_WEAPP_VIDEO_BEGIN"
)

func (gt AdunitType) String() string {
switch gt {
case AdunitTypeForBanner:
return "小程序banner"
case AdunitTypeForRewardVideo:
return "小程序激励视频"
case AdunitTypeForInterstitial:
return "小程序插屏广告"
case AdunitTypeForVideoFeeds:
return "小程序视频广告"
case AdunitTypeForVideoBegin:
return "小程序视频贴片广告"
default:
return "未知"
}
}

type AdunitStatus string //广告单元开关状态

const (
AdunitStatusForOn = "AD_UNIT_STATUS_ON"
AdunitStatusForOff = "AD_UNIT_STATUS_OFF"
)

func (gt AdunitStatus) String() string {
switch gt {
case AdunitStatusForOn:
return "开通"
case AdunitStatusForOff:
return "关闭"
default:
return "未知"
}
}

type SetCoverAdposStatus int32 //广告单元开关状态

const (
SetCoverAdposStatusForOn = 1
SetCoverAdposStatusForOff = 4
)

func (gt SetCoverAdposStatus) String() string {
switch gt {
case SetCoverAdposStatusForOn:
return "开通"
case SetCoverAdposStatusForOff:
return "关闭"
default:
return "未知"
}
}

+ 248
- 0
app/hdl/hdl_data_center.go View File

@@ -0,0 +1,248 @@
package hdl

import (
"applet/app/e"
"applet/app/lib/validate"
"applet/app/md"
"applet/app/svc"
"github.com/gin-gonic/gin"
)

// DataCenterRecordTotal
// @Summary 数据明细合计
// @Tags 数据中心------嘉俊
// @Description 数据中心-数据明细合计
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterTableReq true "请求参数"
// @Success 200 {object} md.DataCenterTotalData "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/record/total [POST]
func DataCenterRecordTotal(c *gin.Context) {
var req md.DataCenterTableReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterRecordTotal(c, req)
e.OutSuc(c, res, nil)
return
}

// DataCenterRecordList
// @Summary 数据明细
// @Tags 数据中心------嘉俊
// @Description 数据中心-数据明细
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterRecordReq true "请求参数"
// @Success 200 {object} md.DataCenterRecordRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/record/list [POST]
func DataCenterRecordList(c *gin.Context) {
var req md.DataCenterRecordReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterRecordList(c, req)
e.OutSuc(c, res, nil)
return
}

// DataCenterRecordOutPut
// @Summary 数据明细-导出
// @Tags 数据中心------嘉俊
// @Description 数据中心-数据明细-导出
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterRecordOutPutReq true "请求参数"
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/record/output [POST]
func DataCenterRecordOutPut(c *gin.Context) {
var req md.DataCenterRecordOutPutReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
svc.DataCenterRecordOutPut(c, req)
return
}

// DataCenterCommissionRecordTotal
// @Summary 佣金收益-明细合计
// @Tags 数据中心------嘉俊
// @Description 数据中心-佣金收益-明细合计
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterTableReq true "请求参数"
// @Success 200 {object} md.DataCenterCommissionTotalData "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/commission/record/total [POST]
func DataCenterCommissionRecordTotal(c *gin.Context) {
var req md.DataCenterTableReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterCommissionRecordTotal(c, req)
e.OutSuc(c, res, nil)
return
}

// DataCenterCommissionRecordList
// @Summary 佣金收益-数据明细
// @Tags 数据中心------嘉俊
// @Description 数据中心-佣金收益-数据明细
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterRecordReq true "请求参数"
// @Success 200 {object} md.DataCenterCommissionRecordRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/commission/record/list [POST]
func DataCenterCommissionRecordList(c *gin.Context) {
var req md.DataCenterRecordReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
res := svc.DataCenterCommissionRecordList(c, req)
e.OutSuc(c, res, nil)
return
}

// DataCenterCommissionRecordOutPut
// @Summary 佣金收益-数据明细-导出
// @Tags 数据中心------嘉俊
// @Description 数据中心-佣金收益-数据明细-导出
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterRecordOutPutReq true "请求参数"
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/commission/record/output [POST]
func DataCenterCommissionRecordOutPut(c *gin.Context) {
var req md.DataCenterRecordOutPutReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
svc.DataCenterCommissionRecordOutPut(c, req)
return
}

// DataCenterSelectData
// @Summary 筛选条件
// @Tags 数据中心------嘉俊
// @Description 数据中心-筛选条件
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/select/data [GET]
func DataCenterSelectData(c *gin.Context) {
svc.DataCenterSelectData(c)
}

// DataCenterProfitRecordList
// @Summary 分润收益-数据明细
// @Tags 数据中心------嘉俊
// @Description 数据中心-分润收益-数据明细
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterProfitRecordReq true "请求参数"
// @Success 200 {object} md.DataCenterProfitRecordRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/profit/record/list [POST]
func DataCenterProfitRecordList(c *gin.Context) {
var req md.DataCenterProfitRecordReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
res := svc.DataCenterProfitRecordList(c, req)
e.OutSuc(c, res, nil)
return
}

// DataCenterProfitRecordOutPut
// @Summary 分润收益-数据明细-导出
// @Tags 数据中心------嘉俊
// @Description 数据中心-分润收益-数据明细-导出
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.DataCenterProfitRecordOutPutReq true "请求参数"
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/dataCenter/profit/record/output [POST]
func DataCenterProfitRecordOutPut(c *gin.Context) {
var req md.DataCenterProfitRecordOutPutReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.StartDate == "" || req.EndDate == "" {
e.OutErr(c, 400, e.NewErr(400, "筛选时间不能为空"))
return
}
svc.DataCenterProfitRecordOutPut(c, req)
return
}

+ 84
- 0
app/hdl/hdl_index.go View File

@@ -0,0 +1,84 @@
package hdl

import (
"applet/app/e"
"applet/app/lib/validate"
"applet/app/md"
"applet/app/svc"
"applet/app/utils"
db "code.fnuoos.com/zhimeng/model.git/src"
"code.fnuoos.com/zhimeng/model.git/src/super/implement"
"github.com/gin-gonic/gin"
)

// Base
// @Summary 右上角基本数据
// @Tags 首页------嘉俊
// @Description 首页-右上角基本数据
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/index/base [GET]
func Base(c *gin.Context) {
user := svc.GetUser(c)
NewAgentListDb := implement.NewAgentListDb(db.Db)
data, _ := NewAgentListDb.GetAgentList(user.AgentId)
settleType := []string{"", "日结", "周结", "月结", "预付"}
name := user.Username
if data.CompanyName != "" {
name = data.CompanyName
}
if data.CompanyAbbreviation != "" {
name = data.CompanyAbbreviation
}
res := map[string]string{
"account_id": utils.IntToStr(user.AgentId),
"name": name,
"account": user.Username,
"settle_type": utils.IntToStr(data.SettlementType),
"settle_type_str": settleType[data.SettlementType],
}
e.OutSuc(c, res, nil)
return
}

// IndexTotal
// @Summary 统计数据
// @Tags 首页------嘉俊
// @Description 首页-统计数据
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/index/total [GET]
func IndexTotal(c *gin.Context) {
svc.IndexTotal(c)
}

// IndexAppList
// @Summary 数据明细
// @Tags 数据中心------嘉俊
// @Description 数据中心-数据明细
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.IndexAppListReq true "请求参数"
// @Success 200 {object} md.IndexAppListRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/index/app/list [POST]
func IndexAppList(c *gin.Context) {
var req md.IndexAppListReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
res := svc.IndexAppList(c, req)
e.OutSuc(c, res, nil)
return
}

+ 130
- 0
app/hdl/hdl_settle_center.go View File

@@ -0,0 +1,130 @@
package hdl

import (
"applet/app/e"
"applet/app/lib/validate"
"applet/app/md"
"applet/app/svc"
"github.com/gin-gonic/gin"
)

// SettleCenterMediumList
// @Summary 媒体结算报表
// @Tags 结算中心------嘉俊
// @Description 结算中心-媒体结算报表
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.SettleCenterDataReq true "请求参数"
// @Success 200 {object} md.SettleCenterMediumDataRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/settleCenter/medium/list [POST]
func SettleCenterMediumList(c *gin.Context) {
var req md.SettleCenterDataReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
res := svc.SettleCenterMediumList(c, req)
e.OutSuc(c, res, nil)
return
}

// SettleCenterList
// @Summary 渠道个人结算报表
// @Tags 结算中心------嘉俊
// @Description 结算中心-渠道个人结算报表
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.SettleCenterDataReq true "请求参数"
// @Success 200 {object} md.SettleCenterDataRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/settleCenter/agent/list [POST]
func SettleCenterList(c *gin.Context) {
var req md.SettleCenterDataReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
res := svc.SettleCenterList(c, req)
e.OutSuc(c, res, nil)
return
}

// SettleCenterDetail
// @Summary 渠道个人结算报表-详情
// @Tags 结算中心------嘉俊
// @Description 结算中心-渠道个人结算报表-详情
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.CommDetailReq true "请求参数"
// @Success 200 {object} md.SettleCenterDataDetailRes "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/settleCenter/agent/detail [POST]
func SettleCenterDetail(c *gin.Context) {
var req md.CommDetailReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
res := svc.SettleCenterDetail(c, req)
e.OutSuc(c, res, nil)
return
}

// SettleCenterSettleFileSave
// @Summary 渠道个人详情-结算单保存
// @Tags 财务中心------嘉俊
// @Description 财务中心-渠道个人详情-结算单保存
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.SettleFileReq true "请求参数"
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/settleCenter/agent/settle/file/save [POST]
func SettleCenterSettleFileSave(c *gin.Context) {
var req md.SettleFileReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
svc.SettleCenterSettleFileSave(c, req)
}

// SettleCenterInvoiceSave
// @Summary 渠道个人详情-发票上传
// @Tags 财务中心------嘉俊
// @Description 财务中心-渠道个人详情-发票上传
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Accept json
// @Produce json
// @Param args body md.InvoiceReq true "请求参数"
// @Success 200 {string} "具体看返回内容 这是data里面的数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/settleCenter/agent/invoice/save [POST]
func SettleCenterInvoiceSave(c *gin.Context) {
var req md.InvoiceReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
svc.SettleCenterInvoiceSave(c, req)
}

+ 11
- 0
app/md/comm.go View File

@@ -1,6 +1,17 @@
package md

var AppletPlatform = []SelectData{
{Name: "微信小程序", Value: "wx_applet"},
}

var AppletPlatformMap = map[string]string{
"wx_applet": "微信小程序",
}

type SelectData struct {
Name string `json:"name" example:"名称"`
Value string `json:"value" example:"值"`
}
type CommDetailReq struct {
Id string `json:"id" example:"列表id"`
}

+ 102
- 0
app/md/md_data_center.go View File

@@ -0,0 +1,102 @@
package md

type DataCenterTableReq struct {
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
AdType string `json:"ad_type" example:"广告位类型"`
}

type DataCenterRecordReq struct {
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
AdType string `json:"ad_type" example:"广告位类型"`
Limit string `json:"limit"`
Page string `json:"page" `
}
type DataCenterRecordOutPutReq struct {
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
AdType string `json:"ad_type" example:"广告位类型"`
Limit string `json:"limit" example:"10000 个一页"`
Page string `json:"page" `
}

type DataCenterTableRes struct {
List []DataCenterTableData `json:"list" `
}

type DataCenterTableData struct {
Date string `json:"date" example:"日期"`
ExposureCount string `json:"exposure_count" example:"曝光量"`
MediaRevenue string `json:"media_revenue" example:"预估收益"`
Ecpm string `json:"ecpm" example:"ecpm"`
}
type DataCenterRecordRes struct {
List []DataCenterTotalData `json:"list" `
Total int64 `json:"total" `
}
type DataCenterCommissionRecordRes struct {
List []DataCenterCommissionTotalData `json:"list" `
Total int64 `json:"total" `
}
type DataCenterCommissionTotalData struct {
Date string `json:"date" example:"日期"`
AppName string `json:"app_name"`
PlatformName string `json:"platform_name"`
AdvName string `json:"adv_name"`
ExposureCount string `json:"exposure_count" example:"曝光量"`
Commission string `json:"commission" example:"预估佣金"`
OtherCommission string `json:"other_commission" example:"额外奖励"`
AllCommission string `json:"all_commission" example:"预估总佣金"`
Ecpm string `json:"ecpm" example:"ecpm"`
ClickRate string `json:"click_rate" example:"点击率"`
ClickCount string `json:"click_count" example:"点击量"`
}

type DataCenterTotalData struct {
Date string `json:"date" example:"日期"`
AppName string `json:"app_name"`
PlatformName string `json:"platform_name"`
AdvName string `json:"adv_name"`
ExposureCount string `json:"exposure_count" example:"曝光量"`
MediaRevenue string `json:"media_revenue" example:"预估收益"`
Ecpm string `json:"ecpm" example:"ecpm"`
ClickRate string `json:"click_rate" example:"点击率"`
ClickCount string `json:"click_count" example:"点击量"`
}
type DataCenterProfitRecordReq struct {
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Type string `json:"type" example:"0-日收益 1-月收益 2年收益"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
Limit string `json:"limit"`
Page string `json:"page" `
}
type DataCenterProfitRecordOutPutReq struct {
StartDate string `json:"start_date" example:"2024-08-30 默认查昨天的 最近7天"`
EndDate string `json:"end_date" example:"2024-08-30"`
Type string `json:"type" example:"0-日收益 1-月收益 2年收益"`
Platform string `json:"platform" example:"平台"`
AppId string `json:"app_id" example:"应用"`
Limit string `json:"limit" example:"10000 个一页"`
Page string `json:"page" `
}
type DataCenterProfitRecordRes struct {
List []DataCenterProfitRecordData `json:"list" `
Total int64 `json:"total" `
}
type DataCenterProfitRecordData struct {
Date string `json:"date" example:"日期"`
AppName string `json:"app_name"`
PlatformName string `json:"platform_name"`
Commission string `json:"commission" example:"预估佣金"`
OtherCommission string `json:"other_commission" example:"额外奖励"`
AllCommission string `json:"all_commission" example:"预估总佣金"`
}

+ 24
- 0
app/md/md_index.go View File

@@ -0,0 +1,24 @@
package md

type IndexAppListReq struct {
StartDate string `json:"start_date" example:"2024-08-30"`
EndDate string `json:"end_date" example:"2024-08-30"`
Sort string `json:"sort" example:"排序"`
}
type IndexAppListRes struct {
List []IndexAppListData `json:"list" `
Sort []SelectData `json:"sort"`
}

type IndexAppListData struct {
Name string `json:"name"`
Logo string `json:"logo"`
List []IndexAppListDataList `json:"list"`
TableList []string `json:"table_list"`
}
type IndexAppListDataList struct {
Name string `json:"name"`
Value string `json:"value"`
Type string `json:"type"`
Bili string `json:"bili"`
}

+ 124
- 0
app/md/md_settle_center.go View File

@@ -0,0 +1,124 @@
package md

var AccountSettleState = []SelectData{
{Name: "日结", Value: "1"},
{Name: "周结", Value: "2"},
{Name: "月结", Value: "3"},
{Name: "预付", Value: "4"},
}
var BusinessKind = []SelectData{
{Name: "广告合作", Value: "1"},
}
var InvoiceCate = []SelectData{
{Name: "电子发票", Value: "0"},
{Name: "纸质发票", Value: "1"},
}
var SettlePayState = []SelectData{
{Name: "未开始", Value: "0"},
{Name: "待审核发票", Value: "1"},
{Name: "发票审核中", Value: "2"},
{Name: "发票审核拒绝", Value: "3"},
{Name: "付款中", Value: "4"},
{Name: "已付款", Value: "5"},
}
var SettleState = []SelectData{
{Name: "未开始", Value: "0"},
{Name: "核算中", Value: "1"},
{Name: "待签订", Value: "2"},
{Name: "完成签订", Value: "3"},
}
var InvoiceState = []SelectData{
{Name: "待审核", Value: "0"},
{Name: "审核通过", Value: "1"},
{Name: "审核拒绝", Value: "2"},
}

type SettleCenterDataReq struct {
Limit string `json:"limit"`
Page string `json:"page" `
StartTime string `json:"start_time" example:"2024-08-29"`
EndTime string `json:"end_time" `
}
type SettleCenterDataRes struct {
List []SettleCenterDataData `json:"list" `
Total int64 `json:"total"`
BusinessKind []SelectData `json:"business_kind"`
SettlePayState []SelectData `json:"settle_pay_state"`
SettleState []SelectData `json:"settle_state"`
SettleType []SelectData `json:"settle_type"`
}

type SettleCenterDataData struct {
Id string `json:"id"`
TimeStr string `json:"time_str" example:"业务时间"`
BusinessKind string `json:"business_kind" example:"业务类型(1:广告合作)"`
SettleType string `json:"settle_type" example:"结算单类型(1:日结 2:周结 3:月结 4:预付)"`
AllIncome string `json:"all_income" example:"合计收益"`
Income string `json:"income" example:"基础收益"`
OtherIncome string `json:"other_income" example:"其他调整"`
PayState string `json:"pay_state" example:"结算单支付状态(0:未开始 1:待审核发票 2:发票审核中 3:发票审核拒绝 4:付款中 5:已付款)"`
State string `json:"state" example:"结算单状态(0:未开始 1:核算中 2:待签订 3:完成签订)"`
Label string `json:"label"`
SettleFile string `json:"settle_file" example:"结算单"`
}
type SettleCenterMediumDataRes struct {
List []SettleCenterMediumDataData `json:"list" `
Total int64 `json:"total"`
BusinessKind []SelectData `json:"business_kind"`
SettlePayState []SelectData `json:"settle_pay_state"`
SettleState []SelectData `json:"settle_state"`
SettleType []SelectData `json:"settle_type"`
}
type SettleCenterMediumDataData struct {
Id string `json:"id"`
Name string `json:"name" example:"媒体名称"`
TimeStr string `json:"time_str" example:"业务时间"`
BusinessKind string `json:"business_kind" example:"业务类型(1:广告合作)"`
SettleType string `json:"settle_type" example:"结算单类型(1:日结 2:周结 3:月结 4:预付)"`
AllIncome string `json:"all_income" example:"合计收益"`
Income string `json:"income" example:"基础收益"`
OtherIncome string `json:"other_income" example:"其他调整"`
PayState string `json:"pay_state" example:"结算单支付状态(0:未开始 1:待审核发票 2:发票审核中 3:发票审核拒绝 4:付款中 5:已付款)"`
State string `json:"state" example:"结算单状态(0:未开始 1:核算中 2:待签订 3:完成签订)"`
Label string `json:"label"`
}
type SettleCenterDataDetailRes struct {
Data SettleCenterDataDetail `json:"data" `
BusinessKind []SelectData `json:"business_kind"`
SettlePayState []SelectData `json:"settle_pay_state"`
InvoiceState []SelectData `json:"invoice_state"`
SettleState []SelectData `json:"settle_state"`
SettleType []SelectData `json:"settle_type"`
InvoiceCate []SelectData `json:"invoice_cate"`
}

type SettleCenterDataDetail struct {
TimeStr string `json:"time_str" example:"业务时间"`
BusinessKind string `json:"business_kind" example:"业务类型(1:广告合作)"`
SettleFile string `json:"settle_file" example:"结算单"`
Invoice Invoice `json:"invoice"`
AllIncome string `json:"all_income" example:"合计收益"`
MediumIncome string `json:"medium_income" example:"媒体结算"`
OtherIncome string `json:"other_income" example:"其他调整"`
PayState string `json:"pay_state" example:"结算单支付状态(0:未开始 1:待审核发票 2:发票审核中 3:发票审核拒绝 4:付款中 5:已付款)"`
State string `json:"state" example:"结算单状态(0:未开始 1:核算中 2:待签订 3:完成签订)"`
}
type Invoice struct {
Type string `json:"type"`
Time string `json:"time"`
Count string `json:"count"`
File []InvoiceFile `json:"file"`
}
type InvoiceFile struct {
Url string `json:"url"`
State string `json:"state" example:"0待确认 1审核通过 2审核失败"`
}
type SettleFileReq struct {
Id string `json:"id" example:"列表id"`
File string `json:"file" example:"七牛云链接 带http"`
}
type InvoiceReq struct {
Id string `json:"id" example:"列表id"`
Type string `json:"type" example:"0电子发票 1纸质发票"`
File []InvoiceFile `json:"file"`
}

+ 33
- 4
app/router/router.go View File

@@ -64,10 +64,13 @@ func route(r *gin.RouterGroup) {
r.POST("/qiniuyun/upload", hdl.ImgReqUpload) //七牛云上传
r.POST("/sms", hdl.Sms) //短信发送
}
r.Use(mw.Auth) // 以下接口需要JWT验证
rRole(r.Group("/role")) //权限管理
rMedium(r.Group("/medium")) //媒体中心
rAccount(r.Group("/account")) //账号中心
r.Use(mw.Auth) // 以下接口需要JWT验证
rRole(r.Group("/role")) //权限管理
rMedium(r.Group("/medium")) //媒体中心
rAccount(r.Group("/account")) //账号中心
rIndex(r.Group("/index")) //首页
rDataCenter(r.Group("/dataCenter")) //数据中心
rSettleCenter(r.Group("/settleCenter")) //结算中心

}

@@ -99,3 +102,29 @@ func rAccount(r *gin.RouterGroup) {
r.POST("/qualification/bank/save", hdl.QualificationBankSave) //资质认证-银行资质保存
r.POST("/qualification/contact/save", hdl.QualificationContactSave) //资质认证-联系方式保存
}
func rIndex(r *gin.RouterGroup) {
r.GET("/base", hdl.Base) //首页-基本信息
r.GET("/total", hdl.IndexTotal) //首页-统计数据
r.POST("/app/list", hdl.IndexAppList) //首页-应用数据
}
func rDataCenter(r *gin.RouterGroup) {
r.GET("/select/data", hdl.DataCenterSelectData) //数据中心-筛选条件
r.POST("/record/total", hdl.DataCenterRecordTotal) //数据中心-数据明细合计
r.POST("/record/list", hdl.DataCenterRecordList) //数据中心-数据明细
r.POST("/record/output", hdl.DataCenterRecordOutPut) //数据中心-数据明细-导出

r.POST("/commission/record/total", hdl.DataCenterCommissionRecordTotal) //数据中心-佣金收益明细合计
r.POST("/commission/record/list", hdl.DataCenterCommissionRecordList) //数据中心-佣金收益明细
r.POST("/commission/record/output", hdl.DataCenterCommissionRecordOutPut) //数据中心-佣金收益明细-导出

r.POST("/profit/record/list", hdl.DataCenterProfitRecordList) //数据中心-分润收益明细
r.POST("/profit/record/output", hdl.DataCenterProfitRecordOutPut) //数据中心-分润收益明细-导出

}
func rSettleCenter(r *gin.RouterGroup) {
r.POST("/medium/list", hdl.SettleCenterMediumList) //结算中心-媒体结算报表
r.POST("/agent/list", hdl.SettleCenterList) //结算中心-渠道个人结算报表
r.POST("/agent/detail", hdl.SettleCenterDetail) //结算中心-渠道个人结算报表-详情
r.POST("/agent/settle/file/save", hdl.SettleCenterSettleFileSave) //结算中心-渠道个人结算报表-结算单上传
r.POST("/agent/invoice/save", hdl.SettleCenterInvoiceSave) //结算中心-渠道个人结算报表-发票上传
}

+ 31
- 0
app/svc/svc_comm.go View File

@@ -0,0 +1,31 @@
package svc

import (
implement2 "code.fnuoos.com/zhimeng/model.git/src/implement"
"code.fnuoos.com/zhimeng/model.git/src/super/implement"
"github.com/gin-gonic/gin"
)

func GetMediumInfo(c *gin.Context, mediumId int) map[string]string {
var res = map[string]string{
"account": "",
"name": "",
}
NewMediumDb := implement2.NewMediumDb(MasterDb(c))
NewMediumListDb := implement.NewMediumListDb(MasterDb(c))
medium := NewMediumDb.GetSuperAdmin(mediumId)
if medium != nil {
res["account"] = medium.Username
res["name"] = medium.Memo
}
NewMediumList, _ := NewMediumListDb.GetMediumList(mediumId)
if NewMediumList != nil {
if NewMediumList.CompanyName != "" {
res["name"] = NewMediumList.CompanyName
}
if NewMediumList.CompanyAbbreviation != "" {
res["name"] = NewMediumList.CompanyAbbreviation
}
}
return res
}

+ 640
- 0
app/svc/svc_data_center.go View File

@@ -0,0 +1,640 @@
package svc

import (
"applet/app/e"
"applet/app/enum"
"applet/app/md"
"applet/app/utils"
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
db "code.fnuoos.com/zhimeng/model.git/src"
"code.fnuoos.com/zhimeng/model.git/src/implement"
model2 "code.fnuoos.com/zhimeng/model.git/src/model"
"fmt"
"github.com/gin-gonic/gin"
"github.com/jinzhu/copier"
"strings"
)

func DataCenterRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCenterTotalData {
appId := GetAppletId(c, req.AppId, req.Platform)
sql := `
SELECT
SUM(exposure_count) as exposure_count,
SUM(click_count) as click_count,
SUM(click_count)/SUM(exposure_count)*100 as click_rate,
SUM(ecpm) as ecpm,
SUM(media_revenue) as media_revenue
FROM generate_wx_ad_data
where %s
`
mediumId := GetAgentMediumId(c)
where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
if req.AdType != "" {
where += " and ad_slot='" + req.AdType + "'"
}
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
sql = fmt.Sprintf(sql, where)
nativeString, _ := db.QueryNativeString(db.Db, sql)
res := md.DataCenterTotalData{}
for _, v := range nativeString {
res = md.DataCenterTotalData{
Date: "-",
AppName: "-",
PlatformName: "-",
AdvName: "-",
ExposureCount: v["exposure_count"],
MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
ClickRate: utils.GetPrec(v["click_rate"], "2") + "%",
ClickCount: v["click_count"],
}
}
return res
}
func DataCenterRecordList(c *gin.Context, req md.DataCenterRecordReq) md.DataCenterRecordRes {
nativeString, total := comm(c, 1, req)
list := make([]md.DataCenterTotalData, 0)
for _, v := range nativeString {
NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(v["app_id"])
platform := ""
name := ""
if app != nil {
name = app.Name
platform = app.Platform
}
NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
adData, _ := NewAppletApplicationAdSpaceListDb.GetAppletApplicationAdSpaceListByAdId(v["slot_id"])
adName := enum.AdunitType(v["ad_slot"]).String()
if adData != nil {
adName = adData.Name
}
tmp := md.DataCenterTotalData{
Date: v["date"],
AppName: name,
PlatformName: md.AppletPlatformMap[platform],
AdvName: adName,
ExposureCount: v["exposure_count"],
MediaRevenue: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100),
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
ClickRate: v["click_rate"] + "%",
ClickCount: v["click_count"],
}
list = append(list, tmp)
}
res := md.DataCenterRecordRes{
List: list,
Total: total,
}
return res
}
func DataCenterRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
var req1 md.DataCenterRecordReq
copier.Copy(&req1, &req)
req.Limit = "10000"
nativeString, _ := comm(c, 0, req1)
appId := make([]string, 0)
adId := make([]string, 0)
for _, v := range nativeString {
appId = append(appId, v["app_id"])
adId = append(adId, v["slot_id"])
}
var app []model2.AppletApplication
appMap := make(map[string]model2.AppletApplication)
MasterDb(c).In("app_id=?", appId).Find(&app)
for _, v := range app {
appMap[v.AppId] = v
}
var ad []model2.AppletApplicationAdSpaceList
adMap := make(map[string]model2.AppletApplicationAdSpaceList)
MasterDb(c).In("ad_id=?", adId).Find(&adMap)
for _, v := range ad {
adMap[v.AdId] = v
}
name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
//写入数据
data := map[string]string{
"A1": "日期",
"B1": "应用名称",
"C1": "平台类型",
"D1": "广告位",
"E1": "曝光量",
"F1": "点击量",
"G1": "ECPM",
"H1": "预估收益",
}
for k, v := range nativeString {
i := utils.IntToStr(k + 2)
data["A"+i] = v["date"]
data["B"+i] = appMap[v["app_id"]].Name
data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
data["D"+i] = adMap[v["slot_id"]].Name
data["E"+i] = v["exposure_count"]
data["F"+i] = v["click_count"]
data["G"+i] = utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100)
data["H"+i] = utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100)
}

file := utils.Output(c, name, data)
filename := name + ".xlsx"
r := map[string]string{
"file": file,
"filename": filename,
}
e.OutSuc(c, r, nil)
return
}
func DataCenterCommissionRecordTotal(c *gin.Context, req md.DataCenterTableReq) md.DataCenterCommissionTotalData {
appId := GetAppletId(c, req.AppId, req.Platform)
sql := `
SELECT
SUM(exposure_count) as exposure_count,
SUM(click_count) as click_count,
SUM(click_count)/SUM(exposure_count)*100 as click_rate,
SUM(ecpm) as ecpm,
SUM(media_revenue) as media_revenue
FROM generate_wx_ad_data
where %s
`
mediumId := GetAgentMediumId(c)
where := "uuid=" + c.GetString("mid")
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
if req.AdType != "" {
where += " and ad_slot='" + req.AdType + "'"
}
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
whereMedium := where + " and medium_id in(" + mediumId + ")"
sql = fmt.Sprintf(sql, whereMedium)
nativeString, _ := db.QueryNativeString(db.Db, sql)
res := md.DataCenterCommissionTotalData{}
for _, v := range nativeString {
res = md.DataCenterCommissionTotalData{
Date: "-",
AppName: "-",
PlatformName: "-",
AdvName: "-",
ExposureCount: v["exposure_count"],
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
ClickRate: utils.GetPrec(v["click_rate"], "2") + "%",
ClickCount: v["click_count"],
AllCommission: "0",
OtherCommission: "0",
Commission: "0",
}
}
sqlAgent := `
SELECT
SUM(agent_revenue) as agent_revenue,
SUM(extra_revenue) as extra_revenue
FROM generate_wx_ad_data_with_agent_flow
where %s
`
user := GetUser(c)
whereAgent := where + " and agent_id=" + utils.IntToStr(user.AgentId)
sqlAgent = fmt.Sprintf(sqlAgent, whereAgent)
nativeStringAgent, _ := db.QueryNativeString(db.Db, sqlAgent)
for _, v := range nativeStringAgent {
res.Commission = utils.Float64ToStr(utils.StrToFloat64(v["agent_revenue"]) / 100)
res.OtherCommission = utils.Float64ToStr(utils.StrToFloat64(v["extra_revenue"]) / 100)
res.AllCommission = utils.Float64ToStr(utils.StrToFloat64(res.Commission) + utils.StrToFloat64(res.OtherCommission))
}
return res
}
func DataCenterCommissionRecordList(c *gin.Context, req md.DataCenterRecordReq) md.DataCenterCommissionRecordRes {
nativeString, total := commAgent(c, 1, req)
list := make([]md.DataCenterCommissionTotalData, 0)

for _, v := range nativeString {
NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(v["app_id"])
platform := ""
name := ""
if app != nil {
name = app.Name
platform = app.Platform
}
NewAppletApplicationAdSpaceListDb := implement.NewAppletApplicationAdSpaceListDb(MasterDb(c))
adData, _ := NewAppletApplicationAdSpaceListDb.GetAppletApplicationAdSpaceListByAdId(v["slot_id"])
adName := enum.AdunitType(v["ad_slot"]).String()
if adData != nil {
adName = adData.Name
}
tmp := md.DataCenterCommissionTotalData{
Date: v["date"],
AppName: name,
PlatformName: md.AppletPlatformMap[platform],
AdvName: adName,
ExposureCount: v["exposure_count"],
Ecpm: utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100),
ClickRate: v["click_rate"] + "%",
ClickCount: v["click_count"],
AllCommission: v["all_commission"],
OtherCommission: v["other_commission"],
Commission: v["commission"],
}
list = append(list, tmp)
}
res := md.DataCenterCommissionRecordRes{
List: list,
Total: total,
}
return res
}
func DataCenterCommissionRecordOutPut(c *gin.Context, req md.DataCenterRecordOutPutReq) {
var req1 md.DataCenterRecordReq
copier.Copy(&req1, &req)
req.Limit = "10000"
nativeString, _ := commAgent(c, 0, req1)
appId := make([]string, 0)
adId := make([]string, 0)
for _, v := range nativeString {
appId = append(appId, v["app_id"])
adId = append(adId, v["slot_id"])
}
var app []model2.AppletApplication
appMap := make(map[string]model2.AppletApplication)
MasterDb(c).In("app_id=?", appId).Find(&app)
for _, v := range app {
appMap[v.AppId] = v
}
var ad []model2.AppletApplicationAdSpaceList
adMap := make(map[string]model2.AppletApplicationAdSpaceList)
MasterDb(c).In("ad_id=?", adId).Find(&adMap)
for _, v := range ad {
adMap[v.AdId] = v
}
name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
//写入数据
data := map[string]string{
"A1": "日期",
"B1": "应用名称",
"C1": "平台类型",
"D1": "广告位",
"E1": "曝光量",
"F1": "点击量",
"G1": "ECPM",
"H1": "预估佣金",
"I1": "额外奖励",
"J1": "预估总收益",
}
for k, v := range nativeString {
i := utils.IntToStr(k + 2)
data["A"+i] = v["date"]
data["B"+i] = appMap[v["app_id"]].Name
data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
data["D"+i] = adMap[v["slot_id"]].Name
data["E"+i] = v["exposure_count"]
data["F"+i] = v["click_count"]
data["G"+i] = utils.Float64ToStr(utils.StrToFloat64(v["ecpm"]) / 100)
data["H"+i] = v["commission"]
data["I"+i] = v["other_commission"]
data["J"+i] = v["all_commission"]
}

file := utils.Output(c, name, data)
filename := name + ".xlsx"
r := map[string]string{
"file": file,
"filename": filename,
}
e.OutSuc(c, r, nil)
return
}
func DataCenterProfitRecordOutPut(c *gin.Context, req md.DataCenterProfitRecordOutPutReq) {
var req1 md.DataCenterProfitRecordReq
copier.Copy(&req1, &req)
req.Limit = "10000"
nativeString, _ := commAgentProfit(c, 0, req1)
appId := make([]string, 0)
for _, v := range nativeString {
appId = append(appId, v["app_id"])
}
var app []model2.AppletApplication
appMap := make(map[string]model2.AppletApplication)
MasterDb(c).In("app_id=?", appId).Find(&app)
for _, v := range app {
appMap[v.AppId] = v
}

name := req.StartDate + "~" + req.EndDate + "(第" + req.Page + "页 " + utils.IntToStr(len(nativeString)) + "条)"
//写入数据
data := map[string]string{
"A1": "日期",
"B1": "应用名称",
"C1": "平台类型",
"D1": "预估佣金",
"E1": "额外奖励",
"F1": "预估总收益",
}
for k, v := range nativeString {
i := utils.IntToStr(k + 2)
data["A"+i] = v["date"]
data["B"+i] = appMap[v["app_id"]].Name
data["C"+i] = md.AppletPlatformMap[appMap[v["app_id"]].Platform]
data["D"+i] = v["commission"]
data["E"+i] = v["other_commission"]
data["F"+i] = v["all_commission"]
}

file := utils.Output(c, name, data)
filename := name + ".xlsx"
r := map[string]string{
"file": file,
"filename": filename,
}
e.OutSuc(c, r, nil)
return
}
func DataCenterProfitRecordList(c *gin.Context, req md.DataCenterProfitRecordReq) md.DataCenterProfitRecordRes {
data, total := commAgentProfit(c, 1, req)
list := make([]md.DataCenterProfitRecordData, 0)
for _, v := range data {
NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
app, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(v["app_id"])
platform := ""
name := ""
if app != nil {
name = app.Name
platform = app.Platform
}
tmp := md.DataCenterProfitRecordData{
Date: v["date"],
AppName: name,
PlatformName: md2.PlatformMap[platform],
Commission: utils.Float64ToStr(utils.StrToFloat64(v["agent_revenue"]) / 100),
OtherCommission: utils.Float64ToStr(utils.StrToFloat64(v["extra_revenue"]) / 100),
}
tmp.AllCommission = utils.Float64ToStr(utils.StrToFloat64(tmp.Commission) + utils.StrToFloat64(tmp.OtherCommission))
list = append(list, tmp)
}
res := md.DataCenterProfitRecordRes{
List: list,
Total: total,
}
return res
}

func comm(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string]string, int64) {
appId := GetAppletId(c, req.AppId, req.Platform)
sql := `
SELECT
%s
FROM generate_wx_ad_data
where %s %s
`
mediumId := GetAgentMediumId(c)
where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
if req.AdType != "" {
where += " and ad_slot='" + req.AdType + "'"
}
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
field := `*`
start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
groupBy := " order by date desc,id desc"
if req.Page != "" {
groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
} else {
groupBy = " order by date asc,id asc"
}

sql1 := fmt.Sprintf(sql, field, where, groupBy)
nativeString, _ := db.QueryNativeString(db.Db, sql1)

var total int64 = 0
if isTotal == 1 {
sqlTotal := fmt.Sprintf(sql, "COUNT(*) as count ", where, "")
nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal)
for _, v := range nativeStringTotal {
total = utils.StrToInt64(v["count"])
}
}
return nativeString, total
}
func commAgentProfit(c *gin.Context, isTotal int, req md.DataCenterProfitRecordReq) ([]map[string]string, int64) {
appId := GetAppletId(c, req.AppId, req.Platform)
sql := `
SELECT
%s
FROM generate_wx_ad_data_with_agent_flow
where %s %s
`
user := GetUser(c)
where := "uuid=" + c.GetString("mid") + " and agent_id =" + utils.IntToStr(user.AgentId)
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
field := `%s,app_id,SUM(agent_revenue) as agent_revenue,SUM(extra_revenue) as extra_revenue`
start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
groupBy := " group by %s,app_id order by date desc,id desc"
if req.Page != "" {
groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
} else {
groupBy = " group by %s,app_id order by date asc,id asc"
}
timeStr := "date"
if req.Type == "1" {
timeStr = "DATE_FORMAT(date, '%Y-%m')"
}
if req.Type == "2" {
timeStr = "DATE_FORMAT(date, '%Y')"
}
field = fmt.Sprintf(field, timeStr)
groupBy = fmt.Sprintf(groupBy, timeStr+" as date")

sql1 := fmt.Sprintf(sql, field, where, groupBy)
nativeString, _ := db.QueryNativeString(db.Db, sql1)
var total int64 = 0
if isTotal == 1 {
sqlTotal := fmt.Sprintf(sql, field, where, "")
sqlTotal1 := `select COUNT(*) as count from (%s) as tmp`
sqlTotal1 = fmt.Sprintf(sqlTotal1, sqlTotal)
nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal1)
for _, v := range nativeStringTotal {
total = utils.StrToInt64(v["count"])
}
}
return nativeString, total
}

func commAgent(c *gin.Context, isTotal int, req md.DataCenterRecordReq) ([]map[string]string, int64) {
appId := GetAppletId(c, req.AppId, req.Platform)
sql := `
SELECT
%s
FROM generate_wx_ad_data
where %s %s
`
mediumId := GetAgentMediumId(c)
where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
if req.AppId != "" || req.Platform != "" {
where += " and app_id in(" + appId + ")"
}
if req.AdType != "" {
where += " and ad_slot='" + req.AdType + "'"
}
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
field := `*`
start := (utils.StrToInt(req.Page) - 1) * utils.StrToInt(req.Limit)
groupBy := " order by date desc,id desc"
if req.Page != "" {
groupBy += " limit " + utils.IntToStr(start) + "," + req.Limit
} else {
groupBy = " order by date asc,id asc"
}

sql1 := fmt.Sprintf(sql, field, where, groupBy)
nativeString, _ := db.QueryNativeString(db.Db, sql1)

var total int64 = 0
if isTotal == 1 {
sqlTotal := fmt.Sprintf(sql, "COUNT(*) as count ", where, "")
nativeStringTotal, _ := db.QueryNativeString(db.Db, sqlTotal)
for _, v := range nativeStringTotal {
total = utils.StrToInt64(v["count"])
}
}
var ids []string
for _, v := range nativeString {
ids = append(ids, v["id"])
}
if len(ids) > 0 {
sqlAgent := `
SELECT
SUM(agent_revenue) as agent_revenue,
SUM(extra_revenue) as extra_revenue
FROM generate_wx_ad_data_with_agent_flow
where %s
`
user := GetUser(c)
whereAgent := "original_data_id in(" + strings.Join(ids, ",") + ") and agent_id=" + utils.IntToStr(user.AgentId)
sqlAgent = fmt.Sprintf(sqlAgent, whereAgent)
nativeStringAgent, _ := db.QueryNativeString(db.Db, sqlAgent)
agentMap := make(map[string]map[string]string)
for _, v := range nativeStringAgent {
_, ok := agentMap[v["uid"]]
if ok == false {
agentMap[v["uid"]] = make(map[string]string)
}
agentMap[v["uid"]] = v
}
for k, v := range nativeString {
_, ok := agentMap[v["uid"]]
if ok {
nativeString[k]["commission"] = utils.Float64ToStr(utils.StrToFloat64(v["agent_revenue"]) / 100)
nativeString[k]["other_commission"] = utils.Float64ToStr(utils.StrToFloat64(v["extra_revenue"]) / 100)
nativeString[k]["all_commission"] = utils.Float64ToStr(utils.StrToFloat64(nativeString[k]["commission"]) + utils.StrToFloat64(nativeString[k]["other_commission"]))
} else {
nativeString[k]["commission"] = "0"
nativeString[k]["other_commission"] = "0"
nativeString[k]["all_commission"] = "0"
}
}
}
return nativeString, total
}
func DataCenterSelectData(c *gin.Context) {
NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
appList, _ := NewAppletApplicationDb.FindAllAppletApplicationList()
appMap := make(map[string][]map[string]interface{})
mediumId := GetAgentMediumId(c)
for _, v := range appList {
if strings.Contains(","+mediumId+",", ","+utils.IntToStr(v.MediumId)+",") == false {
continue
}
_, ok := appMap[v.Platform]
if ok == false {
appMap[v.Platform] = make([]map[string]interface{}, 0)
}
tmp := map[string]interface{}{
"name": v.Name,
"app_id": v.AppId,
"ad_type": enum.AdTypeList,
}
appMap[v.Platform] = append(appMap[v.Platform], tmp)
}
platform := []map[string]interface{}{
{
"name": "微信小程序",
"platform": "wx_applet",
"app_list": appMap["wx_applet"],
},
}
e.OutSuc(c, platform, nil)
return
}

// 应用
func GetAppletId(c *gin.Context, appId, platform string) string {
mediumId := ""
sess := MasterDb(c).Where("1=1")
var ids = make([]string, 0)
if appId != "" || platform != "" {
ids = append(ids, "-1")
}
if platform != "" {
var tmp []model2.AppletApplication
if platform != "" {
sess.And("platform = ? ", platform)
}
sess.Find(&tmp)
for _, v := range tmp {
ids = append(ids, utils.IntToStr(v.MediumId))
}
}
if appId != "" {
ids = []string{appId}
}
if appId != "" || platform != "" {
mediumId = strings.Join(ids, ",")
}
return mediumId
}
func GetAppletInfo(c *gin.Context, id string) map[string]string {
var res = map[string]string{
"platform": "",
"name": "",
"logo": "",
}
NewAppletApplicationDb := implement.NewAppletApplicationDb(MasterDb(c))
data, _ := NewAppletApplicationDb.GetAppletApplicationListByAppid(id)
if data != nil {
res["platform"] = data.Platform
res["name"] = data.Name
res["logo"] = data.Logo
}
return res
}

+ 183
- 0
app/svc/svc_index.go View File

@@ -0,0 +1,183 @@
package svc

import (
"applet/app/e"
"applet/app/md"
"applet/app/utils"
db "code.fnuoos.com/zhimeng/model.git/src"
"code.fnuoos.com/zhimeng/model.git/src/super/implement"
"fmt"
"github.com/gin-gonic/gin"
"strings"
"time"
)

func IndexTotal(c *gin.Context) {
//昨天
yesterday := utils.GetTimeRange("yesterday")
yesterdayTotal := commTotal(c, time.Unix(yesterday["start"], 0).Format("2006-01-02"), time.Unix(yesterday["end"]-3600, 0).Format("2006-01-02"))
//前天
beforeYesterDayTotal := commTotal(c, time.Unix(yesterday["start"]-86400, 0).Format("2006-01-02"), time.Unix(yesterday["start"]-3600, 0).Format("2006-01-02"))
//7天
withinSevenDays := utils.GetTimeRange("new_within_seven_days")
withinSevenDaysTotal := commTotal(c, time.Unix(withinSevenDays["start"], 0).Format("2006-01-02"), time.Unix(withinSevenDays["end"]-3600, 0).Format("2006-01-02"))
//7天前的 7天
beforeWithinSevenDaysTotal := commTotal(c, time.Unix(withinSevenDays["start"]-3600-7*86400, 0).Format("2006-01-02"), time.Unix(withinSevenDays["start"]-3600, 0).Format("2006-01-02"))
//本月
currentMonth := utils.GetTimeRange("current_month")
currentMonthTotal := commTotal(c, time.Unix(currentMonth["start"], 0).Format("2006-01-02"), time.Unix(currentMonth["end"]-3600, 0).Format("2006-01-02"))
//上月
lastMonth := utils.GetTimeRange("last_month")
lastMonthTotal := commTotal(c, time.Unix(lastMonth["start"], 0).Format("2006-01-02"), time.Unix(lastMonth["end"]-3600, 0).Format("2006-01-02"))
//上上月
beforeLastMonth := time.Unix(lastMonth["start"]-86400, 0)
beforeLastMonthStr := time.Date(beforeLastMonth.Year(), beforeLastMonth.Month(), 1, 0, 0, 0, 0, beforeLastMonth.Location())
beforeLastMonthTotal := commTotal(c, beforeLastMonthStr.Format("2006-01-02"), time.Unix(lastMonth["start"]-3600, 0).Format("2006-01-02"))
res := []md.IndexAppListDataList{
{Name: "昨日收益(媒体)", Type: "yesterday", Bili: commBili(c, beforeYesterDayTotal, yesterdayTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(yesterdayTotal[0]["media_revenue"]) / 100)},
{Name: "七日收益(媒体)", Type: "within_seven_days", Bili: commBili(c, beforeWithinSevenDaysTotal, withinSevenDaysTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(withinSevenDaysTotal[0]["media_revenue"]) / 100)},
{Name: "本月收益(媒体)", Type: "current_month", Bili: commBili(c, lastMonthTotal, currentMonthTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(currentMonthTotal[0]["media_revenue"]) / 100)},
{Name: "上月收益(媒体)", Type: "last_month", Bili: commBili(c, beforeLastMonthTotal, lastMonthTotal, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(lastMonthTotal[0]["media_revenue"]) / 100)},
{Name: "昨日收益(曝光量)", Type: "yesterday", Bili: commBili(c, beforeYesterDayTotal, yesterdayTotal, "exposure_count"), Value: yesterdayTotal[0]["exposure_count"]},
{Name: "七日收益(曝光量)", Type: "within_seven_days", Bili: commBili(c, beforeWithinSevenDaysTotal, withinSevenDaysTotal, "exposure_count"), Value: withinSevenDaysTotal[0]["exposure_count"]},
{Name: "本月收益(曝光量)", Type: "current_month", Bili: commBili(c, lastMonthTotal, currentMonthTotal, "exposure_count"), Value: currentMonthTotal[0]["exposure_count"]},
{Name: "上月收益(曝光量)", Type: "last_month", Bili: commBili(c, beforeLastMonthTotal, lastMonthTotal, "exposure_count"), Value: lastMonthTotal[0]["exposure_count"]},
}
e.OutSuc(c, res, nil)
return
}
func commBili(c *gin.Context, before, after []map[string]string, types string) string {
bili := "-%"
if utils.StrToFloat64(before[0][types]) > 0 {
tmpDiff := utils.StrToFloat64(after[0][types]) - utils.StrToFloat64(before[0][types])
types1 := "+"
if tmpDiff < 0 {
types1 = ""
}
bili = types1 + utils.Float64ToStr(tmpDiff/utils.StrToFloat64(before[0][types])*100) + "%"
}
return bili
}
func IndexAppList(c *gin.Context, req md.IndexAppListReq) md.IndexAppListRes {
appId := make([]string, 0)
data := commTotalByApp(c, req, appId)
for _, v := range data {
appId = append(appId, v["app_id"])
}
start := utils.TimeStdParseUnix(req.StartDate + " 00:00:00")
day := (utils.TimeStdParseUnix(req.EndDate+" 00:00:00") - start) / 86400
req.EndDate = time.Unix(start-1, 0).Format("2006-01-02")
req.StartDate = time.Unix(start-1-day*86400, 0).Format("2006-01-02")
dataLast := commTotalByApp(c, req, appId)
dataLastMap := make(map[string][]map[string]string)
for _, v := range dataLast {
dataLastMap[v["app_id"]] = make([]map[string]string, 0)
dataLastMap[v["app_id"]] = append(dataLastMap[v["app_id"]], v)
}
list := make([]md.IndexAppListData, 0)
for _, v := range data {
_, ok := dataLastMap[v["app_id"]]
if ok == false {
dataLastMap[v["app_id"]] = []map[string]string{
{"media_revenue": "0", "ecpm": "0", "exposure_count": "0", "click_count": "0", "click_rate": "0"},
}
}
tmpList := []map[string]string{
v,
}
dataList := []md.IndexAppListDataList{
{Name: "广告预估收益", Type: "media_revenue", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "media_revenue"), Value: utils.Float64ToStr(utils.StrToFloat64(v["media_revenue"]) / 100)},
{Name: "ECPM", Type: "ecpm", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "ecpm"), Value: v["ecpm"]},
{Name: "曝光量", Type: "exposure_count", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "exposure_count"), Value: v["exposure_count"]},
{Name: "点击量", Type: "click_count", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "click_count"), Value: v["click_count"]},
{Name: "点击率", Type: "click_rate", Bili: commBili(c, dataLastMap[v["app_id"]], tmpList, "click_rate"), Value: utils.GetPrec(v["click_rate"], "2") + "%"},
}
applet := GetAppletInfo(c, v["app_id"])
tmp := md.IndexAppListData{
Name: applet["name"],
Logo: applet["logo"],
List: dataList,
TableList: []string{},
}
list = append(list, tmp)
}
res := md.IndexAppListRes{
List: list,
Sort: []md.SelectData{
{Name: "按收益最高", Value: "media_revenue desc"},
{Name: "按ECPM最高", Value: "ecpm desc"},
{Name: "按曝光量最高", Value: "exposure_count desc"},
},
}
return res
}
func GetAgentMediumId(c *gin.Context) string {
user := GetUser(c)
NewAgentWithMediumDb := implement.NewAgentWithMediumDb(db.Db)
agent, _ := NewAgentWithMediumDb.FindAgentWithMediumListByAgentIdAll(user.AgentId)
mediumId := []string{"-1"}
for _, v := range agent {
mediumId = append(mediumId, utils.IntToStr(v.MediumId))
}
return strings.Join(mediumId, ",")
}
func commTotal(c *gin.Context, startDate, endDate string) []map[string]string {
sql := `
SELECT
SUM(exposure_count) as exposure_count,
SUM(click_count) as click_count,
SUM(click_rate) as click_rate,
SUM(ecpm) as ecpm,
SUM(media_revenue) as media_revenue
FROM generate_wx_ad_data
where %s
`
mediumId := GetAgentMediumId(c)
where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
if startDate != "" {
where += " and date>='" + startDate + "'"
}
if endDate != "" {
where += " and date<='" + endDate + "'"
}
sql = fmt.Sprintf(sql, where)
nativeString, _ := db.QueryNativeString(db.Db, sql)
if len(nativeString) == 0 {
nativeString = []map[string]string{
{
"media_revenue": "0",
},
}
}
return nativeString
}
func commTotalByApp(c *gin.Context, req md.IndexAppListReq, appId []string) []map[string]string {
sql := `
SELECT
app_id as app_id,
SUM(exposure_count) as exposure_count,
SUM(click_count) as click_count,
SUM(click_count)/SUM(exposure_count)*100 as click_rate,
SUM(ecpm) as ecpm,
SUM(media_revenue) as media_revenue
FROM generate_wx_ad_data
where %s group by app_id order by %s,id asc limit 20
`
mediumId := GetAgentMediumId(c)
where := "uuid=" + c.GetString("mid") + " and medium_id in(" + mediumId + ")"
if req.StartDate != "" {
where += " and date>='" + req.StartDate + "'"
}
if req.EndDate != "" {
where += " and date<='" + req.EndDate + "'"
}
if len(appId) > 0 {
where += " and app_id in(" + strings.Join(appId, ",") + ")"
}
if req.Sort == "" {
req.Sort = "media_revenue desc"
}
sql = fmt.Sprintf(sql, where, req.Sort)
nativeString, _ := db.QueryNativeString(db.Db, sql)
return nativeString
}

+ 4
- 4
app/svc/svc_qualification.go View File

@@ -154,7 +154,7 @@ func QualificationBankSave(c *gin.Context, req md.AgentBankInfo) error {
data.Uuid = utils.StrToInt(req.Uuid)
data.AgentId = utils.StrToInt(req.AgentId)
data.CurrencyConf = utils.StrToInt(req.CurrencyConf)
data.UpdateAt = time.Now()
data.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
if utils.StrToInt(req.Id) > 0 {

listDb := implement.NewAgentBankInfoDb(db.Db)
@@ -167,7 +167,7 @@ func QualificationBankSave(c *gin.Context, req md.AgentBankInfo) error {
}
db.Db.Where("id=?", req.Id).Update(&data)
} else {
data.CreateAt = time.Now()
data.CreateAt = time.Now().Format("2006-01-02 15:04:05")
db.Db.InsertOne(&data)
}
return nil
@@ -181,7 +181,7 @@ func QualificationContactSave(c *gin.Context, req md.AgentContactInfo) error {
data.Id = utils.StrToInt(req.Id)
data.Uuid = utils.StrToInt(req.Uuid)
data.AgentId = utils.StrToInt(req.AgentId)
data.UpdateAt = time.Now()
data.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
if utils.StrToInt(req.Id) > 0 {

listDb := implement.NewAgentContactInfoDb(db.Db)
@@ -194,7 +194,7 @@ func QualificationContactSave(c *gin.Context, req md.AgentContactInfo) error {
}
db.Db.Where("id=?", req.Id).Update(&data)
} else {
data.CreateAt = time.Now()
data.CreateAt = time.Now().Format("2006-01-02 15:04:05")
db.Db.InsertOne(&data)
}
return nil


+ 191
- 0
app/svc/svc_settle_center.go View File

@@ -0,0 +1,191 @@
package svc

import (
"applet/app/e"
"applet/app/md"
"applet/app/utils"
db "code.fnuoos.com/zhimeng/model.git/src"
"code.fnuoos.com/zhimeng/model.git/src/super/implement"
"code.fnuoos.com/zhimeng/model.git/src/super/model"
"encoding/json"
"github.com/gin-gonic/gin"
"time"
)

func SettleCenterMediumList(c *gin.Context, req md.SettleCenterDataReq) md.SettleCenterMediumDataRes {
engine := db.Db
NewMediumSettlementDb := implement.NewMediumSettlementDb(engine)
mediumId := GetAgentMediumId(c)
MediumList, total, _ := NewMediumSettlementDb.FindMediumSettlementList(c.GetString("mid"), mediumId, "", "", "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
data := make([]md.SettleCenterMediumDataData, 0)
if len(MediumList) > 0 {
for _, v := range MediumList {
medium := GetMediumInfo(c, v.MediumId)
name := ""
if medium != nil {
name = medium["name"]
}
var tmp = md.SettleCenterMediumDataData{
Id: utils.IntToStr(v.Id),
Name: name,
AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
Income: utils.Float64ToStr(float64(v.BasicIncome) / 100),
OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
TimeStr: v.StartDate,
SettleType: utils.IntToStr(v.Kind),
PayState: utils.IntToStr(v.PayState),
State: utils.IntToStr(v.State),
Label: "预估",
}
if v.EndDate != "" && v.EndDate != "0000-00-00" {
if v.EndDate != v.StartDate {
tmp.TimeStr += "~" + v.EndDate
}
tmp.Label = ""
}
data = append(data, tmp)
}
}
res := md.SettleCenterMediumDataRes{
List: data,
Total: total,
SettleType: md.AccountSettleState,
BusinessKind: md.BusinessKind,
SettlePayState: md.SettlePayState,
SettleState: md.SettleState,
}
return res
}
func SettleCenterList(c *gin.Context, req md.SettleCenterDataReq) md.SettleCenterDataRes {
user := GetUser(c)
engine := db.Db
NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
list, total, _ := NewAgentSettlementDb.FindAgentSettlementList(c.GetString("mid"), utils.IntToStr(user.AgentId), "", "", "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
data := make([]md.SettleCenterDataData, 0)
if len(list) > 0 {
for _, v := range list {
var tmp = md.SettleCenterDataData{
Id: utils.IntToStr(v.Id),
AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100),
Income: utils.Float64ToStr(float64(v.BasicIncome) / 100),
OtherIncome: utils.Float64ToStr(float64(v.OtherIncome) / 100),
TimeStr: v.StartDate,
SettleType: utils.IntToStr(v.Kind),
PayState: utils.IntToStr(v.PayState),
State: utils.IntToStr(v.State),
Label: "预估",
SettleFile: v.SettleFile,
}
if v.EndDate != "" && v.EndDate != "0000-00-00" {
if v.EndDate != v.StartDate {
tmp.TimeStr += "~" + v.EndDate
}
tmp.Label = ""
}
data = append(data, tmp)
}
}
res := md.SettleCenterDataRes{
List: data,
Total: total,
SettleType: md.AccountSettleState,
BusinessKind: md.BusinessKind,
SettlePayState: md.SettlePayState,
SettleState: md.SettleState,
}
return res
}
func SettleCenterDetail(c *gin.Context, req md.CommDetailReq) md.SettleCenterDataDetailRes {
engine := db.Db
NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
file := make([]md.InvoiceFile, 0)
invoice := md.Invoice{
Type: "0",
Time: "",
Count: "0",
File: file,
}
//发票
NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
invoiceData, _ := NewAgentInvoiceDb.GetAgentInvoice(data.Id)
if invoiceData != nil {
invoice.Type = utils.IntToStr(invoiceData.Type)
invoice.Time = invoiceData.UpdateAt
invoice.Count = utils.IntToStr(invoiceData.Count)
json.Unmarshal([]byte(invoiceData.File), &file)
}
tmp := md.SettleCenterDataDetail{
SettleFile: data.SettleFile,
Invoice: invoice,
AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
MediumIncome: utils.Float64ToStr(float64(data.BasicIncome) / 100),
OtherIncome: utils.Float64ToStr(float64(data.OtherIncome) / 100),
TimeStr: data.StartDate,
PayState: utils.IntToStr(data.PayState),
State: utils.IntToStr(data.State),
BusinessKind: utils.IntToStr(data.BusinessKind),
}
if data.EndDate != "" && data.EndDate != "0000-00-00" {
if data.EndDate != data.StartDate {
tmp.TimeStr += "~" + data.EndDate
}
}
res := md.SettleCenterDataDetailRes{
Data: tmp,
InvoiceCate: md.InvoiceCate,
SettleType: md.AccountSettleState,
BusinessKind: md.BusinessKind,
SettlePayState: md.SettlePayState,
SettleState: md.SettleState,
InvoiceState: md.InvoiceState,
}
return res
}
func SettleCenterSettleFileSave(c *gin.Context, req md.SettleFileReq) {
engine := db.Db
NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
if data.State == 3 {
e.OutErr(c, 400, e.NewErr(400, "已完成签订,不能再调整"))
return
}
data.State = 3
data.PayState = 1
data.SettleFile = req.File
engine.Where("id=?", data.Id).Cols("state,settle_file,pay_state").Update(data)
e.OutSuc(c, "success", nil)
return
}
func SettleCenterInvoiceSave(c *gin.Context, req md.InvoiceReq) {
engine := db.Db
NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
if data.PayState > 3 {
e.OutErr(c, 400, e.NewErr(400, "已完成审核,不能再调整"))
return
}
data.PayState = 2
engine.Where("id=?", data.Id).Cols("pay_sate").Update(data)
NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
invoice, _ := NewAgentInvoiceDb.GetAgentInvoice(data.Id)
if invoice == nil {
invoice = &model.AgentInvoice{
SettlementId: data.Id,
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
}
engine.Insert(invoice)
}
for k := range req.File {
req.File[k].State = "0"
}
invoice.File = utils.SerializeStr(req.File)
invoice.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
invoice.State = 0
invoice.Type = utils.StrToInt(req.Type)
invoice.Count = len(req.File)
engine.Where("id=?", invoice.Id).AllCols().Update(invoice)
e.OutSuc(c, "success", nil)
return
}

+ 52
- 0
app/utils/convert.go View File

@@ -320,3 +320,55 @@ func IntToStr(i int) string {
func Int64ToStr(i int64) string {
return strconv.FormatInt(i, 10)
}
func Float64ToStrByPrec(f float64, prec int) string {
return strconv.FormatFloat(f, 'f', prec, 64)
}
func GetPrec(sum, commPrec string) string {
if sum == "" {
sum = "0"
}
sum = StrToFormat(sum, StrToInt(commPrec))
ex := strings.Split(sum, ".")
if len(ex) == 2 {
if StrToFloat64(ex[1]) == 0 {
sum = ex[0]
} else {
val := Float64ToStrByPrec(StrToFloat64(ex[1]), 0)
keyMax := 0
for i := 0; i < len(val); i++ {
ch := string(val[i])
fmt.Println(StrToInt(ch))
if StrToInt(ch) > 0 {
keyMax = i
}
}
valNew := val[0 : keyMax+1]
sum = ex[0] + "." + strings.ReplaceAll(ex[1], val, valNew)
}
}
return sum
}
func StrToFormat(s string, prec int) string {
ex := strings.Split(s, ".")
if len(ex) == 2 {
if StrToFloat64(ex[1]) == 0 { //小数点后面为空就是不要小数点了
return ex[0]
}
//看取多少位
str := ex[1]
str1 := str
if prec < len(str) {
str1 = str[0:prec]
} else {
for i := 0; i < prec-len(str); i++ {
str1 += "0"
}
}
if prec > 0 {
return ex[0] + "." + str1
} else {
return ex[0]
}
}
return s
}

+ 11
- 16
app/utils/rand.go View File

@@ -31,22 +31,16 @@ func RandNum() string {
return fmt.Sprintf("%05v", rand.New(rand.NewSource(seed)).Int31n(1000000))
}
func GenerateUniqueRandomNumbers(n int) string {
rand.Seed(time.Now().UnixNano()) // 初始化随机种子
numbers := make([]int, n) // 创建一个切片来保存随机数
for i := range numbers {
j := 0
for {
b := rand.Intn(10) // 生成0-9之间的随机数
numbers[i] = b
for _, num := range numbers[:i] {
if num == b {
j++
break
}
}
if j == 0 {
break
}
rand.Seed(time.Now().UnixNano() + rand.Int63()) // 初始化随机种子

numbers := make([]int, 0, n) // 创建一个切片来保存随机数,初始容量为n
used := make(map[int]bool) // 跟踪已使用的数字

for len(numbers) < n {
b := rand.Intn(10) // 生成0-9之间的随机数
if !used[b] {
numbers = append(numbers, b)
used[b] = true
}
}

@@ -54,5 +48,6 @@ func GenerateUniqueRandomNumbers(n int) string {
for _, v := range numbers {
numbersStr += strconv.Itoa(v)
}

return numbersStr
}

+ 36
- 0
app/utils/xls.go View File

@@ -0,0 +1,36 @@
package utils

import (
"bytes"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin"
"io/ioutil"
)

func Output(c *gin.Context, name string, data map[string]string) string {
//创建excel文件
xlsx := excelize.NewFile()
//创建新表单
index := xlsx.NewSheet(name)
for k, v := range data {
//设置单元格的值
xlsx.SetCellValue(name, k, v)
}
//设置默认打开的表单
xlsx.SetActiveSheet(index)
////保存文件到指定路径
//err := xlsx.SaveAs("./" + name + ".xlsx")
//if err != nil {
// log.Fatal(err)
//}
//_ = file.Save(fileName)
c.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, name+".xlsx"))
c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
var buffer bytes.Buffer
_ = xlsx.Write(&buffer)
r := bytes.NewReader(buffer.Bytes())
fSrc, _ := ioutil.ReadAll(r)
str := "data:application/vnd.ms-excel;base64," + Base64RawStdEncode(string(fSrc))
return str
}

+ 1837
- 342
docs/docs.go
File diff suppressed because it is too large
View File


+ 1837
- 342
docs/swagger.json
File diff suppressed because it is too large
View File


+ 1051
- 42
docs/swagger.yaml
File diff suppressed because it is too large
View File


+ 6
- 1
go.mod View File

@@ -6,7 +6,6 @@ go 1.18

require (
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240821062104-50d608c7fd6a
code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240823034048-34202e969e8d
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/boombuler/barcode v1.0.1
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
@@ -37,6 +36,11 @@ require (
xorm.io/xorm v1.3.2
)

require (
code.fnuoos.com/zhimeng/model.git v0.0.3-0.20240831030801-8c60631f7b95
github.com/360EntSecGroup-Skylar/excelize v1.4.1
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
@@ -73,6 +77,7 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect


Loading…
Cancel
Save