package svc import ( "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" ) func FinancialDynamicsMediumList(c *gin.Context, req md.FinancialDynamicsMediumListReq) md.FinancialDynamicsMediumListRes { engine := db.Db NewMediumFinancialDynamicsDb := implement.NewMediumFinancialDynamicsDb(engine) user := GetUser(c) list, total, _ := NewMediumFinancialDynamicsDb.FindMediumFinancialDynamics(c.GetString("mid"), utils.IntToStr(user.MediumId), req.StartTime, req.EndTime, utils.StrToInt(req.Page), utils.StrToInt(req.Limit)) data := make([]md.FinancialDynamicsMediumListData, 0) if len(list) > 0 { for _, v := range list { var tmp = md.FinancialDynamicsMediumListData{ Id: utils.IntToStr(v.Id), PayTime: v.PayTime, Amount: v.Amount, PayMethod: utils.IntToStr(v.PayMethod), Certificate: v.Certificate, Memo: v.Memo, BusinessKind: utils.IntToStr(v.BusinessKind), } data = append(data, tmp) } } res := md.FinancialDynamicsMediumListRes{ List: data, Total: total, PayMethod: md.PayMethod, BusinessKind: md.BusinessKind, } return res } func FinancialDynamicsMediumTotal(c *gin.Context, req md.FinancialDynamicsMediumTotalReq) md.FinancialDynamicsMediumTotalRes { engine := db.Db sql := `select sum(amount) as amount,COUNT(*) as count from %s where %s` where := "uuid=" + c.GetString("mid") user := GetUser(c) where += " and medium_id=" + utils.IntToStr(user.MediumId) sql1 := fmt.Sprintf(sql, "medium_list", where) res := md.FinancialDynamicsMediumTotalRes{ BalanceAmount: "0.00", AllAmount: "0.00", UseAmount: "0.00", PayCount: "0", } nativeString, _ := db.QueryNativeString(engine, sql1) for _, v := range nativeString { if utils.StrToFloat64(v["amount"]) > 0 { res.BalanceAmount = v["amount"] } } sql2 := fmt.Sprintf(sql, "medium_financial_dynamics", where) nativeString2, _ := db.QueryNativeString(engine, sql2) for _, v := range nativeString2 { if utils.StrToFloat64(v["amount"]) > 0 { res.AllAmount = v["amount"] } if utils.StrToFloat64(v["count"]) > 0 { res.PayCount = v["count"] } } res.UseAmount = utils.Float64ToStr(utils.StrToFloat64(res.AllAmount) - utils.StrToFloat64(res.BalanceAmount)) return res }