From ba02a72f5573bc2353c5f20e4a0c0b8c23036dc0 Mon Sep 17 00:00:00 2001 From: kongyuebin Date: Thu, 11 Nov 2021 21:57:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E6=88=B7=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E7=9A=84bugs=EF=BC=8C=E5=8F=AF=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- merchant/common/mq_config.go | 25 ------- merchant/conf/app.conf | 9 ++- merchant/conf/config.go | 18 ----- merchant/controllers/account_history.go | 2 +- merchant/controllers/login.go | 2 +- merchant/main.go | 5 +- merchant/models/init.go | 18 ++--- merchant/models/transaction.go | 90 ------------------------- 8 files changed, 21 insertions(+), 148 deletions(-) delete mode 100644 merchant/common/mq_config.go delete mode 100644 merchant/conf/config.go delete mode 100644 merchant/models/transaction.go diff --git a/merchant/common/mq_config.go b/merchant/common/mq_config.go deleted file mode 100644 index 472bdcd..0000000 --- a/merchant/common/mq_config.go +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************** - ** @Desc : This file for ... - ** @Time : 2019/11/6 11:37 - ** @Author : yuebin - ** @File : mq_config - ** @Last Modified by : yuebin - ** @Last Modified time: 2019/11/6 11:37 - ** @Software: GoLand -****************************************************/ -package common - -import "net" - -const ( - mqHost = "127.0.0.1" - mqPort = "61613" - - MqOrderQuery = "order_query" - MQ_PAYFOR_QUERY = "payfor_query" - MqOrderNotify = "order_notify" -) - -func GetMQAddress() string { - return net.JoinHostPort(mqHost, mqPort) -} diff --git a/merchant/conf/app.conf b/merchant/conf/app.conf index 6e1d20f..39a58b6 100644 --- a/merchant/conf/app.conf +++ b/merchant/conf/app.conf @@ -14,4 +14,11 @@ filepath= ./logs/jhmerchant.log #separate="["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"]" separate="["emergency","alert","critical","error","warning","notice","info","debug"]" #日志保存最大天数 -maxdays=10 \ No newline at end of file +maxdays=10 + +[mysql] +dbhost = localhost +dbport = 3306 +dbuser = root +dbpasswd = Kyb^15273031604 +dbbase = juhe_pay \ No newline at end of file diff --git a/merchant/conf/config.go b/merchant/conf/config.go deleted file mode 100644 index 8e330d3..0000000 --- a/merchant/conf/config.go +++ /dev/null @@ -1,18 +0,0 @@ -/*************************************************** - ** @Desc : This file for ... - ** @Time : 2019/10/26 15:30 - ** @Author : yuebin - ** @File : conf_pro - ** @Last Modified by : yuebin - ** @Last Modified time: 2019/10/26 15:30 - ** @Software: GoLand -****************************************************/ -package conf - -const ( - DB_HOST = "localhost" - DB_PORT = "3306" - DB_USER = "root" - DB_PASSWORD = "Kyb^15273031604" - DB_BASE = "juhe_pay" -) diff --git a/merchant/controllers/account_history.go b/merchant/controllers/account_history.go index 4aaf6a6..13bce53 100644 --- a/merchant/controllers/account_history.go +++ b/merchant/controllers/account_history.go @@ -28,7 +28,7 @@ func (c *History) ShowHistoryListUI() { ranMd5 := encrypt.EncodeMd5([]byte(pubMethod.RandomString(46))) c.Ctx.SetCookie(enum.UserCookie, ranMd5, enum.CookieExpireTime) c.Ctx.SetSecureCookie(ranMd5, enum.UserCookie, ranMd5, enum.CookieExpireTime) - c.SetSession(enum.UserCookie, ranMd5) + _ = c.SetSession(enum.UserCookie, ranMd5) c.Data["payType"] = enum.GetHistoryStatus() c.Data["userName"] = u.MerchantName diff --git a/merchant/controllers/login.go b/merchant/controllers/login.go index df60aa2..3ef07ee 100644 --- a/merchant/controllers/login.go +++ b/merchant/controllers/login.go @@ -98,7 +98,7 @@ func (c *Login) UserLogin() { stopRun: c.Data["json"] = pubMethod.JsonFormat(flag, "", msg, url) - c.ServeJSON() + _ = c.ServeJSON() c.StopRun() } diff --git a/merchant/main.go b/merchant/main.go index 096a927..4430fe1 100644 --- a/merchant/main.go +++ b/merchant/main.go @@ -6,15 +6,14 @@ import ( _ "merchant/models" _ "merchant/routers" "merchant/sys" + "merchant/utils" ) func init() { - // 初始化数据库 - // 初始化Session sys.InitSession() - + utils.InitLogs() // 如果是开发模式,则显示命令信息 s, _ := beego.AppConfig.String("runmode") isDev := !(s != "dev") diff --git a/merchant/models/init.go b/merchant/models/init.go index 927e396..9e40aba 100644 --- a/merchant/models/init.go +++ b/merchant/models/init.go @@ -13,22 +13,22 @@ import ( "fmt" "github.com/beego/beego/v2/adapter/orm" "github.com/beego/beego/v2/core/logs" - "merchant/conf" + "github.com/beego/beego/v2/server/web" ) -func Init() { - dbHost := conf.DB_HOST - dbUser := conf.DB_USER - dbPassword := conf.DB_PASSWORD - dbBase := conf.DB_BASE - dbPort := conf.DB_PORT +func init() { + dbHost, _ := web.AppConfig.String("mysql::dbhost") + dbUser, _ := web.AppConfig.String("mysql::dbuser") + dbPassword, _ := web.AppConfig.String("mysql::dbpasswd") + dbBase, _ := web.AppConfig.String("mysql::dbbase") + dbPort, _ := web.AppConfig.String("mysql::dbport") link := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPassword, dbHost, dbPort, dbBase) logs.Info("mysql init.....", link) - orm.RegisterDriver("mysql", orm.DRMySQL) - orm.RegisterDataBase("default", "mysql", link, 30, 30) + _ = orm.RegisterDriver("mysql", orm.DRMySQL) + _ = orm.RegisterDataBase("default", "mysql", link, 30, 30) orm.RegisterModel(new(UserInfo), new(MenuInfo), new(SecondMenuInfo), new(PowerInfo), new(RoleInfo), new(BankCardInfo), new(RoadInfo), new(RoadPoolInfo), new(AgentInfo), new(MerchantInfo), new(MerchantDeployInfo), diff --git a/merchant/models/transaction.go b/merchant/models/transaction.go deleted file mode 100644 index bc9e96d..0000000 --- a/merchant/models/transaction.go +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************** - ** @Desc : This file for ... - ** @Time : 2019/10/19 14:17 - ** @Author : yuebin - ** @File : transaction - ** @Last Modified by : yuebin - ** @Last Modified time: 2019/10/19 14:17 - ** @Software: GoLand -****************************************************/ -package models - -import ( - "github.com/beego/beego/v2/adapter/orm" - "github.com/beego/beego/v2/core/logs" - "merchant/common" - "merchant/utils" -) - -func OperatorAccount(accountUid, operatorType string, amount float64) (string, bool) { - o := orm.NewOrm() - o.Begin() - - defer func(interface{}) { - if r := recover(); r != nil { - o.Rollback() - logs.Error("operator account fail") - } - }(o) - - msg := "" - //处理事务 - accountInfo := new(AccountInfo) - if err := o.Raw("select * from account_info where account_uid = ? for update", accountUid).QueryRow(accountInfo); err != nil || accountInfo.AccountUid == "" { - logs.Error("operator account get account info for update fail: ", err) - o.Rollback() - return msg, false - } - - accountInfo.UpdateTime = utils.GetBasicDateTime() - flag := true - - switch operatorType { - case common.PLUS_AMOUNT: //处理加款操作 - accountInfo.Balance = accountInfo.Balance + amount - accountInfo.SettleAmount = accountInfo.SettleAmount + amount - case common.SUB_AMOUNT: //处理减款 - if accountInfo.Balance >= amount && accountInfo.SettleAmount >= amount { - accountInfo.Balance = accountInfo.Balance - amount - accountInfo.SettleAmount = accountInfo.SettleAmount - amount - } else { - msg = "账户余额不够减" - flag = false - } - case common.FREEZE_AMOUNT: //处理冻结款 - accountInfo.FreezeAmount = accountInfo.FreezeAmount + amount - case common.UNFREEZE_AMOUNT: //处理解冻款 - if accountInfo.FreezeAmount >= amount { - accountInfo.FreezeAmount = accountInfo.FreezeAmount - amount - } else { - msg = "账户冻结金额不够解冻款" - flag = false - } - } - if !flag { - o.Rollback() - return msg, false - } - - if _, err := o.Update(accountInfo); err != nil { - logs.Error("operator account update account fail: ", err) - o.Rollback() - return msg, false - } - //往account_history表中插入一条动账记录 - accountHistory := AccountHistoryInfo{AccountUid: accountUid, AccountName: accountInfo.AccountName, Type: operatorType, - Amount: amount, Balance: accountInfo.Balance, CreateTime: utils.GetBasicDateTime(), UpdateTime: utils.GetBasicDateTime()} - - if _, err := o.Insert(&accountHistory); err != nil { - logs.Error("operator account insert account history fail: ", err) - o.Rollback() - return msg, false - } - if err := o.Commit(); err != nil { - logs.Error("operator account commit fail: ", err) - return msg, false - } else { - logs.Info("操作账户成功") - return "", true - } -}