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" "encoding/json" "github.com/gin-gonic/gin" ) func FinanceCenterMediumInvoiceSave(c *gin.Context, req md.InvoiceReq) { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id)) if data.State != 3 { e.OutErr(c, 400, e.NewErr(400, "媒体未完成签订")) return } if data.PayState == 5 { e.OutErr(c, 400, e.NewErr(400, "结算单已付款,不能调整")) return } NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine) invoice, _ := NewMediumInvoiceDb.GetMediumInvoice(data.Id) if req.State == "1" { data.PayState = 4 invoice.State = 1 for k := range req.File { req.File[k].State = "1" } } if req.State == "2" { invoice.State = 2 data.PayState = 3 for k, v := range req.File { if v.State == "0" { req.File[k].State = "1" } } } invoice.File = utils.SerializeStr(req.File) engine.Where("id=?", data.Id).Cols("pay_state").Update(data) engine.Where("id=?", invoice.Id).Cols("state,file").Update(invoice) e.OutSuc(c, "success", nil) return } func FinanceCenterMediumSettleFileSave(c *gin.Context, req md.SettleFileReq) { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id)) if data.State >= 2 { e.OutErr(c, 400, e.NewErr(400, "已推送给媒体,不能再调整")) return } data.State = 2 data.SettleFile = req.File engine.Where("id=?", data.Id).Cols("state,settle_file").Update(data) e.OutSuc(c, "success", nil) return } func FinanceCenterMediumPaySave(c *gin.Context, req md.CommDetailReq) { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id)) if data.PayState < 4 { e.OutErr(c, 400, e.NewErr(400, "不能再调整")) return } data.PayState = 5 engine.Where("id=?", data.Id).Cols("pay_state").Update(data) e.OutSuc(c, "success", nil) return } func FinanceCenterMediumCheckSave(c *gin.Context, req md.CommDetailReq) { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id)) if data.State > 1 { e.OutErr(c, 400, e.NewErr(400, "不能再调整")) return } data.State = 1 engine.Where("id=?", data.Id).Cols("state").Update(data) e.OutSuc(c, "success", nil) return } func FinanceCenterMediumOtherIncomeSave(c *gin.Context, req md.OtherIncomeReq) { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id)) if data.State >= 2 { e.OutErr(c, 400, e.NewErr(400, "已推送给媒体,不能再调整")) return } data.OtherIncome = int(utils.StrToFloat64(req.Amount) * 100) engine.Where("id=?", data.Id).Cols("other_income").Update(data) e.OutSuc(c, "success", nil) return } func FinanceCenterMediumDetail(c *gin.Context, req md.CommDetailReq) md.FinanceCenterDataDetailRes { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) data, _ := NewMediumSettlementDb.GetMediumSettlementById(utils.StrToInt(req.Id)) file := make([]md.InvoiceFile, 0) invoice := md.Invoice{ Type: "0", Time: "", Count: "0", File: file, } //发票 NewMediumInvoiceDb := implement.NewMediumInvoiceDb(engine) invoiceData, _ := NewMediumInvoiceDb.GetMediumInvoice(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) invoice.File = file } tmp := md.FinanceCenterDataDetail{ Source: "手动导入", SettleFile: data.SettleFile, Invoice: invoice, AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100), TopIncome: utils.Float64ToStr(float64(data.OriginalIncome) / 100), CommissionIncome: utils.Float64ToStr(float64(data.CommissionRetention) / 100), PlatformIncome: utils.Float64ToStr(float64(data.PlatformRetention) / 100), ChangeIncome: utils.Float64ToStr(float64(data.PriceAdjustmentRetention) / 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), } if data.EndDate != "" && data.EndDate != "0000-00-00" { if data.EndDate != data.StartDate { tmp.TimeStr += "~" + data.EndDate } } tmpMedium := GetMediumInfo(c, data.MediumId) if tmpMedium["name"] != "" { tmp.Name = tmpMedium["name"] } if tmpMedium["account"] != "" { tmp.Account = tmpMedium["account"] } tmp.DownUrl = "http://" + c.Request.Host + "/api/medium/settle/file/down?id=" + utils.IntToStr(data.Id) res := md.FinanceCenterDataDetailRes{ Data: tmp, InvoiceCate: md.InvoiceCate, SettleType: md.AccountSettleState, BusinessKind: md.BusinessKind, SettlePayState: md.SettlePayState, SettleState: md.SettleState, InvoiceState: md.InvoiceState, } return res } func FinanceCenterMediumList(c *gin.Context, req md.FinanceCenterDataReq) md.FinanceCenterDataRes { engine := db.Db NewMediumSettlementDb := implement.NewMediumSettlementDb(engine) MediumList, total, _ := NewMediumSettlementDb.FindMediumSettlementList(c.GetString("mid"), "", "", req.PayState, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.FinanceCenterDataData, 0) if len(MediumList) > 0 { for _, v := range MediumList { var tmp = md.FinanceCenterDataData{ Id: utils.IntToStr(v.Id), Name: "", AllIncome: utils.Float64ToStr(float64(v.OtherIncome+v.BasicIncome) / 100), TopIncome: utils.Float64ToStr(float64(v.OriginalIncome) / 100), CommissionIncome: utils.Float64ToStr(float64(v.CommissionRetention) / 100), PlatformIncome: utils.Float64ToStr(float64(v.PlatformRetention) / 100), ChangeIncome: utils.Float64ToStr(float64(v.PriceAdjustmentRetention) / 100), MediumIncome: 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: "预估", } tmpMedium := GetMediumInfo(c, v.MediumId) if tmpMedium["name"] != "" { tmp.Name = tmpMedium["name"] } 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.FinanceCenterDataRes{ List: data, Total: total, SettleType: md.AccountSettleState, BusinessKind: md.BusinessKind, SettlePayState: md.SettlePayState, SettleState: md.SettleState, } return res } func FinanceCenterPlatformList(c *gin.Context, req md.FinanceCenterPlatformDataReq) md.FinanceCenterPlatformDataRes { engine := db.Db NewPlatformSettlementDb := implement.NewPlatformSettlementDb(engine) MediumList, total, _ := NewPlatformSettlementDb.FindPlatformSettlementList(c.GetString("mid"), req.Date, req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.FinanceCenterPlatformDataData, 0) if len(MediumList) > 0 { for _, v := range MediumList { var tmp = md.FinanceCenterPlatformDataData{ Id: utils.IntToStr(v.Id), TopIncome: utils.Float64ToStr(float64(v.OriginalIncome) / 100), CommissionIncome: utils.Float64ToStr(float64(v.CommissionRetention) / 100), PlatformIncome: utils.Float64ToStr(float64(v.PlatformRetention) / 100), ChangeIncome: utils.Float64ToStr(float64(v.PriceAdjustmentRetention) / 100), MediumIncome: utils.Float64ToStr(float64(v.MediumIncome) / 100), AgentIncome: utils.Float64ToStr(float64(v.AgentIncome) / 100), TimeStr: v.StartDate, UpdateAt: v.UpdateAt, } data = append(data, tmp) } } res := md.FinanceCenterPlatformDataRes{ List: data, Total: total, } return res }