修复商户后台的bugs,可正常运行
parent
5c43b3108a
commit
ba02a72f55
@ -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)
|
|
||||||
}
|
|
@ -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"
|
|
||||||
)
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue