:fix:修复面额接口错误
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
./idea
|
||||
./vscode
|
||||
./vscode
|
||||
/main.exe
|
||||
|
||||
@@ -22,4 +22,7 @@ port = 61613
|
||||
; 提交卡密接口
|
||||
submit_card_url = http://test.shop.center.mf178.cn/userapi/card/submit_card
|
||||
; url = https://shop.task.mf178.cn/userapi/card/submit_card
|
||||
query_card_url = http://test.shop.center.mf178.cn/userapi/card/order_info
|
||||
query_card_url = http://test.shop.center.mf178.cn/userapi/card/order_info
|
||||
|
||||
[shop]
|
||||
key = BjI@3@N5XeU7kLP5$MppMobz$3ljek7d
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/beego/beego/v2/server/web"
|
||||
|
||||
/***************************************************
|
||||
** @Desc : This file for ...
|
||||
** @Time : 2019/10/26 15:30
|
||||
@@ -102,3 +104,9 @@ var bankInfo = map[string]string{
|
||||
BJRCB: "北京农商行",
|
||||
SDB: "深圳发展银行",
|
||||
}
|
||||
|
||||
func GetMerchantKey() (key string, err error) {
|
||||
key = ""
|
||||
key, err = web.AppConfig.String("shop::key")
|
||||
return key, err
|
||||
}
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
/***************************************************
|
||||
** @Desc : This file for ...
|
||||
** @Time : 2019/10/29 15:01
|
||||
** @Author : yuebin
|
||||
** @File : pay_way_code
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/10/29 15:01
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package config
|
||||
|
||||
var ScanPayWayCodes = []string{
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gateway/config"
|
||||
"gateway/models/order"
|
||||
"gateway/response"
|
||||
"gateway/service"
|
||||
"gateway/supplier/third_party"
|
||||
"gateway/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ScanController struct {
|
||||
@@ -87,3 +90,43 @@ func (c *ScanController) Scan() {
|
||||
c.SolveFailJSON(p)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ScanController) GetAllowedMM() {
|
||||
payKey := strings.TrimSpace(c.GetString("payKey"))
|
||||
payType := "CARD_DH"
|
||||
shopKey := strings.TrimSpace(c.GetString("key"))
|
||||
key, err := config.GetMerchantKey()
|
||||
if err != nil {
|
||||
err = errors.New("系统错误,请联系客服")
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
}
|
||||
if key != shopKey {
|
||||
err = errors.New("秘钥错误,请联系客服")
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
}
|
||||
showMMValue, err := c.GetFloat("showMMValue")
|
||||
if err != nil {
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
}
|
||||
merchantInfo, err := service.GetMerchantInfoByPayKey(payKey)
|
||||
if err != nil {
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
}
|
||||
merchantDeployInfo := service.GerMerchantDeployInfoByUidAndPayWay(merchantInfo.MerchantUid, payType)
|
||||
factValue, err := merchantDeployInfo.GetFactMMValue(showMMValue)
|
||||
if err != nil {
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
}
|
||||
c.Data["json"] = response.Ok(factValue)
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
1
go.mod
1
go.mod
@@ -9,7 +9,6 @@ require (
|
||||
github.com/bytedance/sonic v1.10.2
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/go-stomp/stomp/v3 v3.0.5
|
||||
github.com/matoous/go-nanoid/v2 v2.0.0 // indirect
|
||||
github.com/rs/xid v1.5.0
|
||||
github.com/widuu/gojson v0.0.0-20170212122013-7da9d2cd949b
|
||||
)
|
||||
|
||||
5
go.sum
5
go.sum
@@ -302,10 +302,6 @@ github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/matoous/go-nanoid v1.5.0 h1:VRorl6uCngneC4oUQqOYtO3S0H5QKFtKuKycFG3euek=
|
||||
github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
|
||||
github.com/matoous/go-nanoid/v2 v2.0.0 h1:d19kur2QuLeHmJBkvYkFdhFBzLoo1XVm2GgTpL+9Tj0=
|
||||
github.com/matoous/go-nanoid/v2 v2.0.0/go.mod h1:FtS4aGPVfEkxKxhdWPAspZpZSh1cOjtM7Ej/So3hR0g=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
@@ -448,7 +444,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"gateway/models/accounts"
|
||||
"gateway/models/agent"
|
||||
"gateway/models/merchant"
|
||||
"gateway/models/merchant_deploy"
|
||||
"gateway/models/notify"
|
||||
"gateway/models/order"
|
||||
"gateway/models/payfor"
|
||||
@@ -50,7 +51,7 @@ func init() {
|
||||
new(road.RoadPoolInfo),
|
||||
new(agent.AgentInfo),
|
||||
new(merchant.MerchantInfo),
|
||||
new(merchant.MerchantDeployInfo),
|
||||
new(merchant_deploy.MerchantDeployInfo),
|
||||
new(accounts.AccountInfo),
|
||||
new(accounts.AccountHistoryInfo),
|
||||
new(order.OrderInfo),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package merchant
|
||||
package merchant_deploy
|
||||
|
||||
/***************************************************
|
||||
** @Desc : This file for ...
|
||||
@@ -12,6 +12,7 @@ package merchant
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
@@ -42,7 +43,7 @@ type MerchantDeployInfo struct {
|
||||
|
||||
type ProfitMargin struct {
|
||||
ShowLabel float64 `json:"showLabel"`
|
||||
FactLabel float64 `json:"fact_label"`
|
||||
FactLabel float64 `json:"factLabel"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
@@ -64,6 +65,21 @@ func (m *MerchantDeployInfo) GetSingleRoadPlatformRateMapping() (map[float64]flo
|
||||
return myMap, err
|
||||
}
|
||||
|
||||
func (m *MerchantDeployInfo) GetFactMMValue(showMMValue float64) (float64, error) {
|
||||
var ms []ProfitMargin
|
||||
// 使用json.Unmarshal函数解码JSON字符串到map中
|
||||
err := json.Unmarshal([]byte(m.SingleRoadPlatformRate), &ms)
|
||||
if err != nil {
|
||||
return 0.0, errors.New("获取面额失败")
|
||||
}
|
||||
for _, margin := range ms {
|
||||
if margin.ShowLabel == showMMValue {
|
||||
return margin.FactLabel, nil
|
||||
}
|
||||
}
|
||||
return 0.0, errors.New("当前面额不存在")
|
||||
}
|
||||
|
||||
func (m *MerchantDeployInfo) GetSingleRoadPlatformRateByPrice(price float64) (float64, error) {
|
||||
mapping, err := m.GetSingleRoadPlatformRateMapping()
|
||||
|
||||
@@ -110,6 +126,21 @@ func GetMerchantDeployByUidAndPayType(uid, payType string) MerchantDeployInfo {
|
||||
return merchantDeployInfo
|
||||
}
|
||||
|
||||
func GetMerchantDeployByUidAndRoadUid(uid, roadUid string) *MerchantDeployInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantDeployInfo *MerchantDeployInfo
|
||||
|
||||
_, err := o.QueryTable(MERCHANT_DEPLOY_INFO).
|
||||
Filter("merchant_uid", uid).Filter("single_road_uid", roadUid).
|
||||
Limit(1).
|
||||
All(merchantDeployInfo)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("get merchant deploy by uid and paytype fail:", err)
|
||||
}
|
||||
return merchantDeployInfo
|
||||
}
|
||||
|
||||
func GetMerchantDeployByHour(hour int) []MerchantDeployInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantDeployList []MerchantDeployInfo
|
||||
23
response/common.go
Normal file
23
response/common.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package response
|
||||
|
||||
type Resp struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// Ok 返回成功
|
||||
func Ok(data interface{}) *Resp {
|
||||
return &Resp{
|
||||
Code: 0,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// CommonErr 返回失败
|
||||
func CommonErr(code int, msg string) *Resp {
|
||||
return &Resp{
|
||||
Code: code,
|
||||
Msg: msg,
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ func init() {
|
||||
web.Router("/gateway/scan", &gateway.ScanController{}, "*:Scan")
|
||||
web.Router("/err/params", &gateway.ErrorGatewayController{}, "*:ErrorParams")
|
||||
|
||||
web.Router("/gateway/getAllowedMM", &gateway.ScanController{}, "*:GetAllowedMM")
|
||||
|
||||
//代付相关的接口
|
||||
web.Router("/gateway/payfor", &gateway.PayForGateway{}, "*:PayFor")
|
||||
web.Router("/gateway/payfor/query", &gateway.PayForGateway{}, "*:PayForQuery")
|
||||
|
||||
@@ -2,8 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"gateway/config"
|
||||
"gateway/models/merchant"
|
||||
"gateway/models/merchant_deploy"
|
||||
"gateway/models/order"
|
||||
"gateway/response"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
@@ -31,6 +33,19 @@ func GetMerchantInfoByUID(params map[string]string) *response.PayBaseResp {
|
||||
return c
|
||||
}
|
||||
|
||||
// GetMerchantInfoByPayKey 通过payKey获取商户信息
|
||||
func GetMerchantInfoByPayKey(payKey string) (merchantInfo merchant.MerchantInfo, err error) {
|
||||
merchantInfo = merchant.GetMerchantByPasskey(payKey)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
err = errors.New("商户不存在,请联系商户")
|
||||
return
|
||||
} else if merchantInfo.Status != config.ACTIVE {
|
||||
err = errors.New("商户状态已经被冻结或者被删除,请联系商户!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetMerchantInfo 获取商户信息
|
||||
func GetMerchantInfo(params map[string]string) *response.PayBaseResp {
|
||||
|
||||
@@ -180,3 +195,14 @@ func IpIsWhite() bool {
|
||||
//TODO
|
||||
return true
|
||||
}
|
||||
|
||||
// GetMerchantDeployInfo 获取商户当前使用通道
|
||||
func GetMerchantDeployInfo(uid, singleRoleId string) *merchant_deploy.MerchantDeployInfo {
|
||||
merchantDeploy := merchant_deploy.GetMerchantDeployByUidAndRoadUid(uid, singleRoleId)
|
||||
return merchantDeploy
|
||||
}
|
||||
|
||||
func GerMerchantDeployInfoByUidAndPayWay(uid, payWayCode string) merchant_deploy.MerchantDeployInfo {
|
||||
merchantDeploy := merchant_deploy.GetMerchantDeployByUidAndPayType(uid, payWayCode)
|
||||
return merchantDeploy
|
||||
}
|
||||
|
||||
@@ -1,18 +1,10 @@
|
||||
package service
|
||||
|
||||
/***************************************************
|
||||
** @Desc : 处理网关模块的一些需要操作数据库的功能
|
||||
** @Time : 2019/12/7 16:40
|
||||
** @Author : yuebin
|
||||
** @File : gateway_solve
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/12/7 16:40
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gateway/config"
|
||||
"gateway/models/merchant"
|
||||
"gateway/models/merchant_deploy"
|
||||
"gateway/models/order"
|
||||
"gateway/models/road"
|
||||
"gateway/response"
|
||||
@@ -25,6 +17,17 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func ChooseRoadWith(payWayCode, merchantUid string) (roadInfo road.RoadInfo, roadPoolInfo road.RoadPoolInfo, err error) {
|
||||
deployInfo := merchant_deploy.GetMerchantDeployByUidAndPayType(merchantUid, payWayCode)
|
||||
if deployInfo.MerchantUid == "" {
|
||||
err = errors.New("未找到商户配置")
|
||||
}
|
||||
|
||||
roadInfo = road.GetRoadInfoByRoadUid(deployInfo.SingleRoadUid)
|
||||
roadPoolInfo = road.GetRoadPoolByRoadPoolCode(deployInfo.RollRoadCode)
|
||||
return
|
||||
}
|
||||
|
||||
// ChooseRoad 选择通道
|
||||
func ChooseRoad(c *response.PayBaseResp) *response.PayBaseResp {
|
||||
payWayCode := c.Params["payWayCode"]
|
||||
@@ -32,14 +35,14 @@ func ChooseRoad(c *response.PayBaseResp) *response.PayBaseResp {
|
||||
|
||||
if err != nil {
|
||||
c.Code = -1
|
||||
c.Msg = "输入金额错误,金额应为正整数!"
|
||||
c.Msg = "输入金额错误!"
|
||||
return c
|
||||
}
|
||||
|
||||
merchantUid := c.MerchantInfo.MerchantUid
|
||||
|
||||
//通道配置信息
|
||||
deployInfo := merchant.GetMerchantDeployByUidAndPayType(merchantUid, payWayCode)
|
||||
deployInfo := merchant_deploy.GetMerchantDeployByUidAndPayType(merchantUid, payWayCode)
|
||||
|
||||
if deployInfo.MerchantUid == "" {
|
||||
c.Code = -1
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
/***************************************************
|
||||
** @Desc : 订单结算,将订单上面的钱加入到账户余额中
|
||||
** @Time : 2019/11/22 11:34
|
||||
** @Author : yuebin
|
||||
** @File : order_settle
|
||||
** @Last Modified by : yuebin
|
||||
** @Last Modified time: 2019/11/22 11:34
|
||||
** @Software: GoLand
|
||||
****************************************************/
|
||||
package service
|
||||
|
||||
import (
|
||||
@@ -16,6 +7,7 @@ import (
|
||||
"gateway/config"
|
||||
"gateway/models/accounts"
|
||||
"gateway/models/merchant"
|
||||
"gateway/models/merchant_deploy"
|
||||
"gateway/models/order"
|
||||
"gateway/utils"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
@@ -72,7 +64,7 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
|
||||
|
||||
// 商户有押款操作
|
||||
loadAmount := 0.0
|
||||
merchantDeployInfo := merchant.GetMerchantDeployByUidAndPayType(accountInfo.AccountUid, orderSettle.PayTypeCode)
|
||||
merchantDeployInfo := merchant_deploy.GetMerchantDeployByUidAndPayType(accountInfo.AccountUid, orderSettle.PayTypeCode)
|
||||
if merchantDeployInfo.IsLoan == config.YES {
|
||||
loadAmount = merchantDeployInfo.LoanRate * 0.01 * orderProfit.FactAmount
|
||||
date := utils.GetDate()
|
||||
@@ -142,7 +134,7 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
|
||||
// MerchantLoadSolve 商户的押款释放处理,根据商户的押款时间进行处理
|
||||
func MerchantLoadSolve() {
|
||||
hour := time.Now().Hour()
|
||||
merchantDeployList := merchant.GetMerchantDeployByHour(hour)
|
||||
merchantDeployList := merchant_deploy.GetMerchantDeployByHour(hour)
|
||||
for _, merchantDeploy := range merchantDeployList {
|
||||
logs.Info(fmt.Sprintf("开始执行商户uid= #{merchantDeploy.MerchantUid},进行解款操作"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user