|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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 FinanceCenterAgentInvoiceSave(c *gin.Context, req md.InvoiceReq) {
- 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
- }
- if data.PayState == 5 {
- e.OutErr(c, 400, e.NewErr(400, "结算单已付款,不能调整"))
- return
- }
- NewAgentInvoiceDb := implement.NewAgentInvoiceDb(engine)
- invoice, _ := NewAgentInvoiceDb.GetAgentInvoice(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 FinanceCenterAgentSettleFileSave(c *gin.Context, req md.SettleFileReq) {
- engine := db.Db
- NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
- data, _ := NewAgentSettlementDb.GetAgentSettlementById(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 FinanceCenterAgentPaySave(c *gin.Context, req md.CommDetailReq) {
- engine := db.Db
- NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
- data, _ := NewAgentSettlementDb.GetAgentSettlementById(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 FinanceCenterAgentCheckSave(c *gin.Context, req md.CommDetailReq) {
- engine := db.Db
- NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
- data, _ := NewAgentSettlementDb.GetAgentSettlementById(utils.StrToInt(req.Id))
- if data.State >= 2 {
- e.OutErr(c, 400, e.NewErr(400, "已推送给代理,不能再调整"))
- return
- }
- data.State = 2
- engine.Where("id=?", data.Id).Cols("state").Update(data)
- e.OutSuc(c, "success", nil)
- return
- }
- func FinanceCenterAgentOtherIncomeSave(c *gin.Context, req md.OtherIncomeReq) {
- engine := db.Db
- NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
- data, _ := NewAgentSettlementDb.GetAgentSettlementById(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 FinanceCenterAgentDetail(c *gin.Context, req md.CommDetailReq) md.FinanceCenterDataAgentDetailRes {
- 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)
- invoice.File = file
-
- }
- tmp := md.FinanceCenterDataAgentDetail{
- Source: "手动导入",
- SettleFile: data.SettleFile,
- Invoice: invoice,
- AllIncome: utils.Float64ToStr(float64(data.OtherIncome+data.BasicIncome) / 100),
- Income: 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
- }
- }
- tmpAgent := GetAgentInfo(c, data.AgentId)
- if tmpAgent["name"] != "" {
- tmp.Name = tmpAgent["name"]
- }
- if tmpAgent["account"] != "" {
- tmp.Account = tmpAgent["account"]
- }
- tmp.DownUrl = "http://" + c.Request.Host + "/api/agent/settle/file/down?id=" + utils.IntToStr(data.Id)
-
- res := md.FinanceCenterDataAgentDetailRes{
- Data: tmp,
- InvoiceCate: md.InvoiceCate,
- SettleType: md.AccountSettleState,
- BusinessKind: md.BusinessKind,
- SettlePayState: md.SettlePayState,
- SettleState: md.SettleState,
- InvoiceState: md.InvoiceState,
- }
- return res
- }
- func FinanceCenterAgentList(c *gin.Context, req md.FinanceCenterDataReq) md.FinanceCenterDataAgentRes {
- engine := db.Db
- NewAgentSettlementDb := implement.NewAgentSettlementDb(engine)
- AgentList, total, _ := NewAgentSettlementDb.FindAgentSettlementList(c.GetString("mid"), "", "", req.PayState, "", req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.FinanceCenterDataAgentData, 0)
- if len(AgentList) > 0 {
- for _, v := range AgentList {
- var tmp = md.FinanceCenterDataAgentData{
- Id: utils.IntToStr(v.Id),
- 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: "预估",
- }
- tmpAgent := GetAgentInfo(c, v.AgentId)
- if tmpAgent["name"] != "" {
- tmp.Name = tmpAgent["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.FinanceCenterDataAgentRes{
- List: data,
- Total: total,
- SettleType: md.AccountSettleState,
- BusinessKind: md.BusinessKind,
- SettlePayState: md.SettlePayState,
- SettleState: md.SettleState,
- }
- return res
- }
|