package channelApi import ( "fmt" "net/http" "path/filepath" "stat/api/proto" "stat/common/stdLog" "stat/common/utils" "stat/middleware/define" "stat/service/channelSer" "github.com/gin-gonic/gin" ) // @Tags 渠道结算 // @Summary 分组分页获取渠道结算 // @Description 分组分页获取渠道结算 // @Accept json // @Produce json // @Param param body proto.SettlementInfoSearch true "参数列表" // @Success 200 {object} proto.SettlementInfoSearchResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/list [POST] func GetSearchSettlementInfo(ctx *gin.Context) { var req = &proto.SettlementInfoSearch{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } resp, serr := channelSer.SearchSettlementInfo(ctx, req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } stdLog.ServerJSON(ctx, stdLog.Success, resp) } // @Tags 渠道结算 // @Summary 分组分页获取渠道结算申请表(渠道账号看的) // @Description 分组分页获取渠道结算申请表(渠道账号看的) // @Accept json // @Produce json // @Param param body proto.GetApplyFormReq true "参数列表" // @Success 200 {object} proto.GetApplyFormResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/agent/channel/applies [POST] func GetApplyForm(ctx *gin.Context) { var req = &proto.GetApplyFormReq{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } accType, err := utils.GetAccountType(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } if accType != define.Channel { stdLog.ServerJSON(ctx, stdLog.Failure, fmt.Errorf("代理账号才可以查看")) } resp, serr := channelSer.SearchApplyForm(ctx, req, account) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } stdLog.ServerJSON(ctx, stdLog.Success, resp) } // @Tags 渠道结算 // @Summary 获取结算申请人名字列表 // @Description 获取结算申请人名字列表 // @Accept json // @Produce json // @Param param body proto.GetSettlementApplicantListReq true "参数列表" // @Success 200 {object} proto.GetSettlementApplicantListResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/applicant/list [POST] func GetSettlementApplicantList(ctx *gin.Context) { var req = &proto.GetSettlementApplicantListReq{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } resp, serr := channelSer.GetSettlementApplicantList(ctx, req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } stdLog.ServerJSON(ctx, stdLog.Success, resp) } // @Tags 渠道结算 // @Summary 分组分页获取渠道结算已删除列表 // @Description 分组分页获取渠道结算已删除列表 // @Accept json // @Produce json // @Param param body proto.SettlementInfoSearch true "参数列表" // @Success 200 {object} proto.SettlementInfoSearchResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/deleted/list [POST] func GetSearchDeletedSettlementInfo(ctx *gin.Context) { var req = &proto.SettlementInfoSearch{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } resp, serr := channelSer.SearchDeletedSettlementInfo(ctx, req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } stdLog.ServerJSON(ctx, stdLog.Success, resp) } // @Tags 渠道结算 // @Summary 分组分页获取渠道结算导出 // @Description 分组分页获取渠道结算导出 // @Accept json // @Produce json // @Param param body proto.SettlementInfoSearch true "参数列表" // @Success 200 {object} proto.SettlementInfoSearchResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/export [POST] func GetSearchSettlementInfoExport(ctx *gin.Context) { var req = &proto.SettlementInfoSearch{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } fPath, serr := channelSer.SearchSettlementInfoExport(ctx, req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } ctx.Writer.WriteHeader(http.StatusOK) ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filepath.Base(fPath))) ctx.Header("Content-Type", "application/octet-stream") ctx.File(fPath) } // @Tags 渠道结算 // @Summary 分组分页获取渠道结算申请表导出 // @Description 分组分页获取渠道结算申请表导出 // @Accept json // @Produce json // @Param param body proto.SettlementInfoSearch true "参数列表" // @Success 200 {object} proto.SettlementInfoSearchResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/v2/export [POST] func GetSearchSettlementInfoApplyExport(ctx *gin.Context) { var req = &proto.SettlementInfoSearch{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } fPath, serr := channelSer.SearchSettlementInfoApplyExport(ctx, req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } ctx.Writer.WriteHeader(http.StatusOK) ctx.Header("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filepath.Base(fPath))) ctx.Header("Content-Type", "application/octet-stream") ctx.File(fPath) } // @Tags 渠道结算 // @Summary 添加一个渠道结算 // @Description 添加一个渠道结算 // @Accept json // @Produce json // @Param param body proto.SettlementInfoAdd true "参数列表" // @Success 200 {string} string "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/add [POST] func AddOneSettlementInfo(ctx *gin.Context) { var req = &proto.SettlementInfoAdd{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } serr := channelSer.AddSettlementInfo(ctx, req) if serr != nil { if serr.Error() == "重复结算" { stdLog.ServerJSON(ctx, stdLog.SettlementDouble, serr.Error()) } else { stdLog.ServerJSON(ctx, stdLog.Failure, serr.Error()) } return } stdLog.ServerJSON(ctx, stdLog.Success, "") } // @Tags 渠道结算 // @Summary 添加一个渠道结算2 // @Description 添加一个渠道结算2 // @Accept json // @Produce json // @Param param body proto.SettlementInfoAdd true "参数列表" // @Success 200 {string} string "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/v2/add [POST] func AddOneSettlementInfo2(ctx *gin.Context) { var req = &proto.SettlementInfoAdd2{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, err) return } account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } accType, err := utils.GetAccountType(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } serr := channelSer.AddSettlementInfo2(ctx, req, accType, account) if serr != nil { if serr.Error() == "重复结算" { stdLog.ServerJSON(ctx, stdLog.SettlementDouble, serr.Error()) } else { stdLog.ServerJSON(ctx, stdLog.Failure, serr.Error()) } return } stdLog.ServerJSON(ctx, stdLog.Success, "") } // @Tags 渠道结算 // @Summary 更新一个渠道结算 // @Description 更新一个渠道结算 // @Accept json // @Produce json // @Param param body proto.SettlementInfoUpdate true "参数列表" // @Success 200 {string} string "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/update [POST] func UpdateOneSettlementInfo(ctx *gin.Context) { var req = &proto.SettlementInfoUpdate{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, nil) return } serr := channelSer.UpdateSettlementInfo(ctx, *req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr) return } stdLog.ServerJSON(ctx, stdLog.Success, "") } // @Tags 渠道结算 // @Summary 更新一个渠道结算2 // @Description 更新一个渠道结算2 // @Accept json // @Produce json // @Param param body proto.SettlementInfoUpdate true "参数列表" // @Success 200 {string} string "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/v2/update [POST] func UpdateOneSettlementInfo2(ctx *gin.Context) { var req = &proto.SettlementInfoUpdate2{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, nil) return } account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } accType, err := utils.GetAccountType(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } serr := channelSer.UpdateSettlementInfo2(ctx, *req, accType, account) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr.Error()) return } stdLog.ServerJSON(ctx, stdLog.Success, "") } // @Tags 渠道结算 // @Summary 删除一个渠道结算项 // @Description 删除一个渠道结算(只有特定状态的结算项可以删除) // @Accept json // @Produce json // @Param param body proto.SettlementInfoDelete true "参数列表" // @Success 200 {string} string "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/v2/del [POST] func DelOneSettlementInfo(ctx *gin.Context) { var req = &proto.SettlementInfoDelete{} if err := ctx.ShouldBind(req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, nil) return } account, err := utils.GetAdmin(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } accType, err := utils.GetAccountType(ctx) if err != nil { stdLog.ServerJSON(ctx, stdLog.Failure, err.Error()) } serr := channelSer.DeleteSettlementInfo(ctx, *req, accType, account) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr.Error()) return } stdLog.ServerJSON(ctx, stdLog.Success, "") } // @Tags 渠道结算 // @Summary 查看渠道结算项的详情 // @Description 查看渠道结算项的详情 // @Accept json // @Produce json // @Param param body proto.SettlementInfoDetail true "参数列表" // @Success 200 {object} proto.SettlementInfoDetailResp "成功" // @Failure 400 {string} string "获取失败的返回结果" // @Security ApiKeyAuth // @Router /api/stat/settlementinfo/v2/detail [POST] func DetailOneSettlementInfo(ctx *gin.Context) { var req = proto.SettlementInfoDetail{} if err := ctx.ShouldBind(&req); err != nil { stdLog.ServerJSON(ctx, stdLog.ParamError, nil) return } resp, serr := channelSer.DetailSettlementInfo(ctx, req) if serr != nil { stdLog.ServerJSON(ctx, stdLog.Failure, serr.Error()) return } stdLog.ServerJSON(ctx, stdLog.Success, resp) }