:building:添加查询订单参数

This commit is contained in:
sunxiaolong
2024-01-03 08:10:12 +08:00
parent 731d1eefb3
commit 146dc667a9
7 changed files with 204 additions and 14 deletions

143
cache/redis.go vendored Normal file
View File

@@ -0,0 +1,143 @@
package cache
import (
"fmt"
"github.com/go-redis/redis"
"github.com/pkg/errors"
"merchant/config"
"time"
)
var _ Repo = (*cacheRepo)(nil)
type Repo interface {
i()
Set(key, value string, ttl time.Duration) error
Get(key string) (string, error)
TTL(key string) (time.Duration, error)
Expire(key string, ttl time.Duration) bool
ExpireAt(key string, ttl time.Time) bool
Del(keys ...string) bool
Exists(keys ...string) bool
Incr(key string) int64
Close() error
}
type cacheRepo struct {
client *redis.Client
}
var cache *cacheRepo
func init() {
client, err := redisConnect()
if err != nil {
return
}
cache = &cacheRepo{
client: client,
}
}
func GetRedis() *cacheRepo {
if cache == nil {
client, err := redisConnect()
if err != nil {
return &cacheRepo{}
}
cache = &cacheRepo{
client: client,
}
}
return cache
}
func (c *cacheRepo) i() {}
func redisConnect() (*redis.Client, error) {
cfg, err := config.GetRedisCfg()
if err != nil {
return redis.NewClient(&redis.Options{}), err
}
client := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
Password: cfg.Password,
DB: cfg.DB,
})
if err := client.Ping().Err(); err != nil {
return nil, errors.Wrap(err, "ping redis err")
}
return client, nil
}
// Set set some <key,value> into redis
func (c *cacheRepo) Set(key, value string, ttl time.Duration) error {
if err := c.client.Set(key, value, ttl).Err(); err != nil {
return errors.Wrapf(err, "redis set key: %s err", key)
}
return nil
}
// Get get some key from redis
func (c *cacheRepo) Get(key string) (string, error) {
value, err := c.client.Get(key).Result()
if err != nil {
return "", errors.Wrapf(err, "redis get key: %s err", key)
}
return value, nil
}
// TTL get some key from redis
func (c *cacheRepo) TTL(key string) (time.Duration, error) {
ttl, err := c.client.TTL(key).Result()
if err != nil {
return -1, errors.Wrapf(err, "redis get key: %s err", key)
}
return ttl, nil
}
// Expire expire some key
func (c *cacheRepo) Expire(key string, ttl time.Duration) bool {
ok, _ := c.client.Expire(key, ttl).Result()
return ok
}
// ExpireAt expire some key at some time
func (c *cacheRepo) ExpireAt(key string, ttl time.Time) bool {
ok, _ := c.client.ExpireAt(key, ttl).Result()
return ok
}
func (c *cacheRepo) Exists(keys ...string) bool {
if len(keys) == 0 {
return true
}
value, _ := c.client.Exists(keys...).Result()
return value > 0
}
// Del del some key from redis
func (c *cacheRepo) Del(keys ...string) bool {
if len(keys) == 0 {
return true
}
value, _ := c.client.Del(keys...).Result()
return value > 0
}
func (c *cacheRepo) Incr(key string) int64 {
value, _ := c.client.Incr(key).Result()
return value
}
// Close close redis client
func (c *cacheRepo) Close() error {
return c.client.Close()
}

View File

@@ -26,9 +26,14 @@ dbuser = root
dbpasswd = 123456
dbbase = juhe_pay
[redis]
host = localhost
port = 6379
password = 123
[payLink]
url = http://localhost:12305/
[secret]
key = thisis32bitlongpassphraseimusing
iv = 1234567890123456
iv = 1234567890123456

View File

@@ -6,3 +6,25 @@ func GetRemoteHost() (string, error) {
remoteHost, err := web.AppConfig.String("remoteHost")
return remoteHost, err
}
func GetRedisCfg() (RedisCfg, error) {
host, err := web.AppConfig.String("redis::host")
if err != nil {
return RedisCfg{}, err // 返回错误
}
port, err := web.AppConfig.Int("redis::port")
if err != nil {
return RedisCfg{}, err // 返回错误
}
password, err := web.AppConfig.String("redis::password")
if err != nil {
return RedisCfg{}, err // 返回错误
}
return RedisCfg{
Host: host,
Port: port,
Password: password,
}, nil
}

8
config/models.go Normal file
View File

@@ -0,0 +1,8 @@
package config
type RedisCfg struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Password string `mapstructure:"password"`
DB int `mapstructure:"db"`
}

View File

@@ -40,6 +40,12 @@ type MerchantInfo struct {
OtpSecret string
}
type ProfitMargin struct {
Label string `json:"label"`
LinkID string `json:"linkID"`
Value int `json:"-"`
}
const MERCHANT_INFO = "merchant_info"
func IsExistByMerchantName(merchantName string) bool {

View File

@@ -6,8 +6,8 @@ import (
)
// QueryAllowedDeployInfoMM 获取指定商户的允许面额信息
func QueryAllowedDeployInfoMM(merchantUid, payType string) []int {
var resInfo []int
func QueryAllowedDeployInfoMM(merchantUid, payType string) []merchant.ProfitMargin {
var resInfo []merchant.ProfitMargin
merchantInfoList := merchant.GetMerchantDeployByUid(merchantUid)
if len(merchantInfoList) == 0 {
return resInfo
@@ -15,13 +15,10 @@ func QueryAllowedDeployInfoMM(merchantUid, payType string) []int {
for _, info := range merchantInfoList {
if info.PayType == payType {
var tmpData map[int]float64
if err := json.Unmarshal([]byte(info.SingleRoadPlatformRate), &tmpData); err == nil {
for i := range tmpData {
resInfo = append(resInfo, i)
}
err := json.Unmarshal([]byte(info.SingleRoadPlatformRate), &resInfo)
if err != nil {
break
}
break
}
}
return resInfo

View File

@@ -80,7 +80,6 @@
<label>
面值选择:
<select name="mm-select" id="mm-select">
<!-- <option value="100">100</option>-->
</select>
</label>
</div>
@@ -116,15 +115,24 @@
</style>
<script>
let globalSelectedValue = [];
function genLink() {
const mm = $("#mm-select").val();
$(".mm-iframe").attr("src", $("#payLink").val() + `&mmValue=${mm}`);
const result = globalSelectedValue.filter((item) => item.label === mm);
if (result.length !== 0) {
$(".mm-iframe").attr("src", `${$("#payLink").val()}&mmValue=${mm}&linkID=${result[0].linkID}`);
}
}
function createOnNewTab() {
const mm = $("#mm-select").val();
const src = $("#payLink").val() + `&mmValue=${mm}`
window.open(src, "_blank");
const result = globalSelectedValue.filter((item) => item.label === mm);
if (result.length !== 0) {
const src = `${$("#payLink").val()}&mmValue=${mm}&linkID=${result[0].linkID}`
window.open(src, "_blank");
}
}
// 获取可允许面值
@@ -136,8 +144,9 @@
if (res.code !== 0) {
alert(res.msg)
} else {
globalSelectedValue = res.data;
for (let i = 0; i < res.data.length; i++) {
$("#mm-select").append(`<option value="${res.data[i]}">${res.data[i]}</option>`)
$("#mm-select").append(`<option value="${res.data[i].label}">${res.data[i].label}</option>`)
}
}
},