From a56fa52493d3f2e9fc76353cb60ad34e584e24cd Mon Sep 17 00:00:00 2001 From: kongyuebin Date: Tue, 4 May 2021 16:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=AC=AC=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- legend/controllers/showPageController.go | 4 ++- legend/models/fast/orderInfoDao.go | 25 ++++++++++++++++++ legend/models/init.go | 33 ------------------------ legend/utils/dateTime.go | 5 ++++ 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/legend/controllers/showPageController.go b/legend/controllers/showPageController.go index 873eaad..18a503f 100644 --- a/legend/controllers/showPageController.go +++ b/legend/controllers/showPageController.go @@ -33,8 +33,10 @@ func (c *ShowPageController) WelcomePage() { c.Data["balance"] = accountInfo.Balance c.Data["unBalance"] = accountInfo.FreezeAmount c.Data["settleAmount"] = accountInfo.SettleAmount - //c.Data["todayAmount"] = accountInfo.TodayIncome // 获取今天充值金额 + todayIncome := accountService.GetTodayIncome() + logs.Debug("获取到当天充值金额:", todayIncome) + c.Data["todayAmount"] = todayIncome c.TplName = "welcome.html" } diff --git a/legend/models/fast/orderInfoDao.go b/legend/models/fast/orderInfoDao.go index d056cae..925ba8c 100644 --- a/legend/models/fast/orderInfoDao.go +++ b/legend/models/fast/orderInfoDao.go @@ -1,5 +1,10 @@ package fast +import ( + "github.com/beego/beego/v2/adapter/orm" + "github.com/beego/beego/v2/core/logs" +) + type OrderInfo struct { Id string `orm:"pk;column(id)"` MerchantOrderId string @@ -36,3 +41,23 @@ type OrderInfo struct { UpdateTime string CreateTime string } + +const ORDERINFO = "order_info" + +func (c *OrderInfo) TableName() string { + return ORDERINFO +} + +/** +** 获取短时间内的充值金额 + */ +func GetRangeDateIncome(startTime, endTime string) float64 { + o := orm.NewOrm() + sum := 0.00 + err := o.Raw("select sum(order_amount) from order_info where status = ? and create_time >= ? and create_time <= ?", "success", startTime, endTime).QueryRow(&sum) + if err != nil { + logs.Error("获取短时间内金额失败,err:", err) + } + + return sum +} diff --git a/legend/models/init.go b/legend/models/init.go index 2acebb3..8587cf1 100644 --- a/legend/models/init.go +++ b/legend/models/init.go @@ -14,42 +14,9 @@ import ( ** 链接数据库,注册已经存在的数据表,进行orm映射操作 */ func init() { - //initFastPay() initLegend() } -/** -** 初始化快付支付系统的mysql数据库 - */ -func initFastPay() { - dbType, _ := web.AppConfig.String("dbtype") - mysqlHost, _ := web.AppConfig.String("fast::host") - mysqlPort, _ := web.AppConfig.String("fast::port") - mysqlUserName, _ := web.AppConfig.String("fast::username") - mysqlPassword, _ := web.AppConfig.String("fast::password") - mysqlDbName, _ := web.AppConfig.String("fast::dbname") - - logs.Info("host:%s, port:%s, usreName:%s, password:%s, dbname:%s, dbType:%s", mysqlHost, mysqlPort, - mysqlUserName, mysqlPassword, mysqlDbName, dbType) - - pStr := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&loc=Local", - mysqlUserName, mysqlPassword, mysqlHost, mysqlPort, mysqlDbName) - - if err := orm.RegisterDataBase("default", dbType, pStr); err != nil { - logs.Error("init fast fail:%s", err) - os.Exit(1) - } - orm.SetMaxIdleConns("default", 30) - orm.SetMaxIdleConns("default", 30) - - orm.RegisterModel(new(fast.MerchantInfo)) - orm.RegisterModel(new(fast.RpUserPayConfig)) - orm.RegisterModel(new(fast.RpUserBankAccount)) - orm.RegisterModel(new(fast.AccountInfo)) - - logs.Info("init fast success ......") -} - /** ** 初始化传奇支付系统的mysql数据库 */ diff --git a/legend/utils/dateTime.go b/legend/utils/dateTime.go index c3cb133..faeb42f 100644 --- a/legend/utils/dateTime.go +++ b/legend/utils/dateTime.go @@ -6,3 +6,8 @@ func GetNowTime() string { t := time.Now().Format("2006-01-02 15:04:05") return t } + +func GetNowDate() string { + t := time.Now().Format("2006-01-02") + return t +}