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, Uuid: utils.StrToInt(c.GetString("mid")), AgentId: data.AgentId, 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 }