将boss系统的逻辑移到了gateway系统

This commit is contained in:
kongyuebin 2021-11-11 10:31:58 +08:00
parent 7cd2e963ad
commit 2a7be69a37
8 changed files with 158 additions and 92 deletions

View File

@ -0,0 +1,70 @@
package gateway
import (
"gateway/conf"
"gateway/models/order"
"gateway/query"
"gateway/service"
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/server/web"
)
type OrderController struct {
web.Controller
}
func (c *OrderController) OrderQuery() {
bankOrderId := c.GetString("bankOrderId")
logs.Debug("获取到boss后台的银行id = " + bankOrderId)
qy := query.SupplierOrderQueryResult(bankOrderId)
if qy {
c.Ctx.WriteString("success")
} else {
c.Ctx.WriteString("fail")
}
c.StopRun()
}
func (c *OrderController) OrderUpdate() {
bankOrderId := c.GetString("bankOrderId")
solveType := c.GetString("solveType")
orderInfo := order.GetOrderByBankOrderId(bankOrderId)
flag := false
if orderInfo.BankOrderId == "" {
logs.Error("该订单不存在,bankOrderId=", bankOrderId)
} else if orderInfo.Status != conf.SUCCESS {
logs.Notice("该订单没有完成支付不能进行此操作bankOrderId = ", bankOrderId)
} else {
switch solveType {
case conf.SUCCESS:
flag = service.SolvePaySuccess(bankOrderId, orderInfo.FactAmount, orderInfo.BankTransId)
case conf.FAIL:
flag = service.SolvePayFail(bankOrderId, orderInfo.BankTransId)
case conf.FREEZE_AMOUNT:
//将这笔订单进行冻结
flag = service.SolveOrderFreeze(bankOrderId)
case conf.UNFREEZE_AMOUNT:
//将这笔订单金额解冻
flag = service.SolveOrderUnfreeze(bankOrderId)
case conf.REFUND:
if orderInfo.Status == conf.SUCCESS {
flag = service.SolveRefund(bankOrderId)
}
case conf.ORDERROLL:
if orderInfo.Status == conf.SUCCESS {
flag = service.SolveOrderRoll(bankOrderId)
}
default:
logs.Error("不存在这样的处理类型")
}
if flag {
c.Ctx.WriteString(conf.SUCCESS)
} else {
c.Ctx.WriteString(conf.FAIL)
}
}
c.StopRun()
}

View File

@ -12,8 +12,12 @@ package gateway
import ( import (
"fmt" "fmt"
"gateway/conf" "gateway/conf"
"gateway/models/payfor"
"gateway/models/road"
"gateway/pay_for" "gateway/pay_for"
"gateway/response" "gateway/response"
"gateway/supplier/third_party"
"github.com/astaxie/beego/logs"
"github.com/beego/beego/v2/server/web" "github.com/beego/beego/v2/server/web"
"strings" "strings"
) )
@ -69,6 +73,45 @@ func (c *PayForGateway) PayForQuery() {
_ = c.ServeJSON() _ = c.ServeJSON()
} }
/*
** 查询上游的代付结果
*/
func (c *PayForGateway) QuerySupplierPayForResult() {
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
p := payfor.GetPayForByBankOrderId(bankOrderId)
if p.RoadUid == "" {
c.Ctx.WriteString("fail")
} else {
roadInfo := road.GetRoadInfoByRoadUid(p.RoadUid)
supplierCode := roadInfo.ProductUid
supplier := third_party.GetPaySupplierByCode(supplierCode)
res := supplier.PayFor(p)
logs.Debug("代付查询结果:", res)
c.Ctx.WriteString("success")
}
}
/**
** 接收boss发送过来的代付手动处理结果
*/
func (c *PayForGateway) SolvePayForResult() {
resultType := strings.TrimSpace(c.GetString("resultType"))
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
p := payfor.GetPayForByBankOrderId(bankOrderId)
if p.BankOrderId == "" {
c.Ctx.WriteString(conf.FAIL)
}
if resultType == conf.PAYFOR_FAIL {
pay_for.PayForFail(p)
} else if resultType == conf.PAYFOR_SUCCESS {
pay_for.PayForSuccess(p)
}
c.Ctx.WriteString(conf.SUCCESS)
}
/* /*
* 商户查找余额 * 商户查找余额
*/ */

View File

@ -39,22 +39,6 @@ type MerchantDeployInfo struct {
const MERCHANT_DEPLOY_INFO = "merchant_deploy_info" const MERCHANT_DEPLOY_INFO = "merchant_deploy_info"
func InsertMerchantDeployInfo(merchantDeployInfo MerchantDeployInfo) bool {
o := orm.NewOrm()
_, err := o.Insert(&merchantDeployInfo)
if err != nil {
logs.Error("insert merchant deploy info fail: ", err)
return false
}
return true
}
func IsExistByUidAndPayType(uid, payType string) bool {
o := orm.NewOrm()
isEixst := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("merchant_uid", uid).Filter("pay_type", payType).Exist()
return isEixst
}
func GetMerchantDeployByUidAndPayType(uid, payType string) MerchantDeployInfo { func GetMerchantDeployByUidAndPayType(uid, payType string) MerchantDeployInfo {
o := orm.NewOrm() o := orm.NewOrm()
var merchantDeployInfo MerchantDeployInfo var merchantDeployInfo MerchantDeployInfo
@ -65,15 +49,6 @@ func GetMerchantDeployByUidAndPayType(uid, payType string) MerchantDeployInfo {
return merchantDeployInfo return merchantDeployInfo
} }
func GetMerchantDeployByUid(uid string) (ms []MerchantDeployInfo) {
o := orm.NewOrm()
_, err := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("merchant_uid", uid).All(&ms)
if err != nil {
logs.Error("get merchant deploy by uid fail:", err)
}
return ms
}
func GetMerchantDeployByHour(hour int) []MerchantDeployInfo { func GetMerchantDeployByHour(hour int) []MerchantDeployInfo {
o := orm.NewOrm() o := orm.NewOrm()
var merchantDeployList []MerchantDeployInfo var merchantDeployList []MerchantDeployInfo
@ -84,52 +59,3 @@ func GetMerchantDeployByHour(hour int) []MerchantDeployInfo {
return merchantDeployList return merchantDeployList
} }
func DeleteMerchantDeployByUidAndPayType(uid, payType string) bool {
o := orm.NewOrm()
_, err := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("merchant_uid", uid).Filter("pay_type", payType).Delete()
if err != nil {
logs.Error("delete merchant deploy by uid and payType fail: ", err)
return false
}
return true
}
func UpdateMerchantDeploy(merchantDeploy MerchantDeployInfo) bool {
o := orm.NewOrm()
_, err := o.Update(&merchantDeploy)
if err != nil {
logs.Error("update merchant deploy fail: ", err)
return false
}
return true
}
func GetMerchantDeployLenByMap(params map[string]string) int {
o := orm.NewOrm()
qs := o.QueryTable(MERCHANT_DEPLOY_INFO)
for k, v := range params {
if len(v) > 0 {
qs = qs.Filter(k, v)
}
}
cnt, err := qs.Count()
if err != nil {
logs.Error("get merchant deploy len by map fail: ", err)
}
return int(cnt)
}
func GetMerchantDeployListByMap(params map[string]string, displayCount, offset int) (md []MerchantDeployInfo) {
o := orm.NewOrm()
qs := o.QueryTable(MERCHANT_DEPLOY_INFO)
for k, v := range params {
if len(v) > 0 {
qs = qs.Filter(k, v)
}
}
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&md)
if err != nil {
logs.Error("get merchant deploy list by map fail: ", err)
}
return md
}

View File

@ -32,23 +32,29 @@ const (
LimitTimes = 5 //最多查询5次 LimitTimes = 5 //最多查询5次
) )
func SupplierOrderQueryResult(bankOrderId string) bool {
orderInfo := order.GetOrderByBankOrderId(bankOrderId)
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
logs.Error("不存在这样的订单,订单查询结束")
return false
}
if orderInfo.Status != "" && orderInfo.Status != "wait" {
logs.Error(fmt.Sprintf("该订单=%s已经处理完毕", bankOrderId))
return false
}
supplierCode := orderInfo.PayProductCode
supplier := third_party.GetPaySupplierByCode(supplierCode)
flag := supplier.PayQuery(orderInfo)
return flag
}
/* /*
** 该接口是查询上游的订单 ** 该接口是查询上游的订单
*/ */
func solveSupplierOrderQuery(task OrderQueryTask) { func solveSupplierOrderQuery(task OrderQueryTask) {
bankOrderId := task.BankOrderId bankOrderId := task.BankOrderId
orderInfo := order.GetOrderByBankOrderId(bankOrderId)
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 { flag := SupplierOrderQueryResult(bankOrderId)
logs.Error("不存在这样的订单,订单查询结束")
return
}
if orderInfo.Status != "" && orderInfo.Status != "wait" {
logs.Error(fmt.Sprintf("该订单=%s已经处理完毕", bankOrderId))
return
}
supplierCode := orderInfo.PayProductCode
supplier := third_party.GetPaySupplierByCode(supplierCode)
flag := supplier.PayQuery(orderInfo)
if flag { if flag {
logs.Info("订单查询成功, bankOrderId", bankOrderId) logs.Info("订单查询成功, bankOrderId", bankOrderId)
} else { } else {

View File

@ -16,4 +16,9 @@ func init() {
web.Router("/gateway/balance", &gateway.PayForGateway{}, "*:Balance") web.Router("/gateway/balance", &gateway.PayForGateway{}, "*:Balance")
// 接收银行回调 // 接收银行回调
web.Router("/daili/notify", &third_party.DaiLiImpl{}, "*:PayNotify") web.Router("/daili/notify", &third_party.DaiLiImpl{}, "*:PayNotify")
web.Router("/gateway/supplier/order/query", &gateway.OrderController{}, "*:OrderQuery")
web.Router("/gateway/update/order", &gateway.OrderController{}, "*:OrderUpdate")
web.Router("/gateway/supplier/payfor/query", &gateway.PayForGateway{}, "QuerySupplierPayForResult")
web.Router("/solve/payfor/result", &gateway.PayForGateway{}, "SolvePayForResult")
} }

View File

@ -152,7 +152,6 @@ func SolvePayFail(bankOrderId, transId string) bool {
err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error { err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
var orderTmp order.OrderInfo var orderTmp order.OrderInfo
//bankOrderId := orderInfo.BankOrderId
if err := txOrm.Raw("select * from order_info where bank_order_id = ?", bankOrderId).QueryRow(&orderTmp); err != nil || orderTmp.BankOrderId == "" { if err := txOrm.Raw("select * from order_info where bank_order_id = ?", bankOrderId).QueryRow(&orderTmp); err != nil || orderTmp.BankOrderId == "" {
return err return err
} }

View File

@ -95,15 +95,15 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
} }
} else { } else {
merchantLoad := new(merchant.MerchantLoadInfo) merchantLoad := new(merchant.MerchantLoadInfo)
if err := txOrm.Raw("select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update"). if err := txOrm.Raw("select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update", orderSettle.MerchantUid, orderSettle.RoadUid, date).
QueryRow(merchantLoad); err != nil || merchantLoad.UpdateTime == "" { QueryRow(merchantLoad); err != nil || merchantLoad.UpdateTime == "" {
logs.Error(fmt.Sprintf("结算过程select merchant load info失败错误信息#{err}")) logs.Error(fmt.Sprintf("结算过程select merchant load info失败错误信息%s", err))
return err return err
} else { } else {
merchantLoad.UpdateTime = utils.GetBasicDateTime() merchantLoad.UpdateTime = utils.GetBasicDateTime()
merchantLoad.LoadAmount += loadAmount merchantLoad.LoadAmount += loadAmount
if _, err := txOrm.Update(merchantLoad); err != nil { if _, err := txOrm.Update(merchantLoad); err != nil {
logs.Error(fmt.Sprintf("结算过程update merchant load info失败失败信息#{err}")) logs.Error(fmt.Sprintf("结算过程update merchant load info失败失败信息%s", err))
return err return err
} }
} }
@ -148,14 +148,15 @@ func MerchantLoadSolve() {
params := make(map[string]string) params := make(map[string]string)
params["status"] = conf.NO params["status"] = conf.NO
params["merchant_uid"] = merchantDeploy.MerchantUid params["merchant_uid"] = merchantDeploy.MerchantUid
params["load_date"] = loadDate params["load_date__lte"] = loadDate
merchantLoadList := merchant.GetMerchantLoadInfoByMap(params) merchantLoadList := merchant.GetMerchantLoadInfoByMap(params)
for _, merchantLoad := range merchantLoadList { for _, merchantLoad := range merchantLoadList {
if MerchantAbleAmount(merchantLoad) { if MerchantAbleAmount(merchantLoad) {
logs.Info(fmt.Sprintf("商户uid= %s押款金额=%f押款通道= %s, 解款成功", merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid)) logs.Info(fmt.Sprintf("商户uid= %s押款金额=%f押款通道= %s, 解款成功", merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid))
} else { } else {
logs.Error(fmt.Sprintf("商户uid=%s押款金额=%f押款通道=%s, 解款失败", merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid)) logs.Error(fmt.Sprintf("商户uid=%s押款金额=%f押款通道=%s, 解款失败",
merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid))
} }
} }
} }

View File

@ -170,6 +170,22 @@ func (c *DaiLiImpl) PayNotify() {
} }
func (c *DaiLiImpl) PayQuery(orderInfo order.OrderInfo) bool { func (c *DaiLiImpl) PayQuery(orderInfo order.OrderInfo) bool {
tradeStatus := "SUCCESS"
trxNo := orderInfo.BankOrderId
factAmount := 100.00
if tradeStatus == "SUCCESS" {
//调用支付成功的接口,做加款更新操作,需要把实际支付金额传入
if !service.SolvePaySuccess(orderInfo.BankOrderId, factAmount, trxNo) {
return false
}
} else if tradeStatus == "FAILED" {
if !service.SolvePayFail(orderInfo.BankOrderId, "") {
return false
}
} else {
logs.Info("订单状态处于:" + tradeStatus + "bankOrderId" + orderInfo.BankOrderId)
}
return true return true
} }