@@ -6,6 +6,7 @@ import ( | |||||
"applet/app/md" | "applet/app/md" | ||||
"applet/app/md/comm" | "applet/app/md/comm" | ||||
"applet/app/svc" | "applet/app/svc" | ||||
"applet/app/svc/sys_cfg" | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"applet/app/utils/cache" | "applet/app/utils/cache" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
@@ -37,9 +38,7 @@ func GetOssUrl(c *gin.Context) { | |||||
e.OutErr(c, err1.Code, err1.Error()) | e.OutErr(c, err1.Code, err1.Error()) | ||||
return | return | ||||
} | } | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfgs, err := sysCfgDb.SysCfgGetAll() | sysCfgs, err := sysCfgDb.SysCfgGetAll() | ||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | e.OutErr(c, e.ERR_DB_ORM, err.Error()) | ||||
@@ -7,8 +7,8 @@ import ( | |||||
"applet/app/lib/validate" | "applet/app/lib/validate" | ||||
"applet/app/md" | "applet/app/md" | ||||
"applet/app/svc" | "applet/app/svc" | ||||
"applet/app/svc/sys_cfg" | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/aliyun" | ||||
@@ -319,9 +319,7 @@ func commReq(c *gin.Context, req md.RegisterReq) { | |||||
}() | }() | ||||
var parentUser *model.User | var parentUser *model.User | ||||
var inviteCode string | var inviteCode string | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfg := sysCfgDb.SysCfgFindWithDb(enum.AppInviteType, enum.AppInviteLength) | sysCfg := sysCfgDb.SysCfgFindWithDb(enum.AppInviteType, enum.AppInviteLength) | ||||
inviteCode = svc.ReturnCode(utils.StrToInt(sysCfg[enum.AppInviteLength]), utils.StrToInt(sysCfg[enum.AppInviteType]), 0) | inviteCode = svc.ReturnCode(utils.StrToInt(sysCfg[enum.AppInviteLength]), utils.StrToInt(sysCfg[enum.AppInviteType]), 0) | ||||
if req.InviteCode != "" { | if req.InviteCode != "" { | ||||
@@ -7,6 +7,7 @@ import ( | |||||
alipay "applet/app/lib/gopay" | alipay "applet/app/lib/gopay" | ||||
"applet/app/md" | "applet/app/md" | ||||
"applet/app/svc" | "applet/app/svc" | ||||
"applet/app/svc/sys_cfg" | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"applet/app/utils/cache" | "applet/app/utils/cache" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
@@ -410,9 +411,7 @@ func LaunchBindAlipayAccount(c *gin.Context) { | |||||
appId := client.AppId | appId := client.AppId | ||||
scope := "auth_user" | scope := "auth_user" | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfgs, err := sysCfgDb.SysCfgGetAll() | sysCfgs, err := sysCfgDb.SysCfgGetAll() | ||||
if err != nil { | if err != nil { | ||||
e.OutErr(c, e.ERR_DB_ORM, err.Error()) | e.OutErr(c, e.ERR_DB_ORM, err.Error()) | ||||
@@ -2,16 +2,13 @@ package alipay | |||||
import ( | import ( | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"applet/app/svc/sys_cfg" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
"errors" | "errors" | ||||
) | ) | ||||
func FacePrepareAlipayCode(method string, params map[string]string) (interface{}, error) { | func FacePrepareAlipayCode(method string, params map[string]string) (interface{}, error) { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfgMap := sysCfgDb.SysCfgFindWithDb("alipay_face_url", enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) | sysCfgMap := sysCfgDb.SysCfgFindWithDb("alipay_face_url", enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) | ||||
// 获取私钥和APPID | // 获取私钥和APPID | ||||
@@ -2,8 +2,7 @@ package alipay | |||||
import ( | import ( | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"applet/app/svc/sys_cfg" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
"github.com/go-pay/gopay" | "github.com/go-pay/gopay" | ||||
"github.com/go-pay/gopay/alipay" | "github.com/go-pay/gopay/alipay" | ||||
@@ -26,9 +25,7 @@ type InitAlipayStruct struct { | |||||
// isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。 | // isProd:是否是正式环境,沙箱环境请选择新版沙箱应用。 | ||||
func InitAlipay(initData *InitAlipayStruct) (client *alipay.Client, err error) { | func InitAlipay(initData *InitAlipayStruct) (client *alipay.Client, err error) { | ||||
if initData == nil { | if initData == nil { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfgMap := sysCfgDb.SysCfgFindWithDb(enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) | sysCfgMap := sysCfgDb.SysCfgFindWithDb(enum.AlipayAppId, enum.AlipayPrivateKey, enum.AlipayPublicKey, enum.AlipayPublicContentRSA2, enum.AlipayRootContent, enum.AppPublicContent) | ||||
initData = &InitAlipayStruct{ | initData = &InitAlipayStruct{ | ||||
IsProd: true, | IsProd: true, | ||||
@@ -2,16 +2,13 @@ package svc | |||||
import ( | import ( | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"applet/app/svc/sys_cfg" | |||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"github.com/tidwall/gjson" | "github.com/tidwall/gjson" | ||||
) | ) | ||||
func AliyunCaptchBase(c *gin.Context) (string, string) { | func AliyunCaptchBase(c *gin.Context) (string, string) { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
data := sysCfgDb.SysCfgFindWithDb("aliyun_captch_id_android", "aliyun_captch_key_android", "aliyun_captch_id_ios", "aliyun_captch_key_ios", "aliyun_captch_id_h5", "aliyun_captch_key_h5") | data := sysCfgDb.SysCfgFindWithDb("aliyun_captch_id_android", "aliyun_captch_key_android", "aliyun_captch_id_ios", "aliyun_captch_key_ios", "aliyun_captch_id_h5", "aliyun_captch_key_h5") | ||||
if c.GetHeader("platform") == "android" { | if c.GetHeader("platform") == "android" { | ||||
return data["aliyun_captch_id_android"], data["aliyun_captch_key_android"] | return data["aliyun_captch_id_android"], data["aliyun_captch_key_android"] | ||||
@@ -25,9 +22,7 @@ func AliyunCaptchBase(c *gin.Context) (string, string) { | |||||
return "", "" | return "", "" | ||||
} | } | ||||
func AliyunSmsBase(c *gin.Context, types string) map[string]string { | func AliyunSmsBase(c *gin.Context, types string) map[string]string { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
data := sysCfgDb.SysCfgFindWithDb("aliyun_sms_id", "aliyun_sms_secret", "aliyun_sms_code", "aliyun_sms_sign_name") | data := sysCfgDb.SysCfgFindWithDb("aliyun_sms_id", "aliyun_sms_secret", "aliyun_sms_code", "aliyun_sms_sign_name") | ||||
data["aliyun_sms_code"] = gjson.Get(data["aliyun_sms_code"], types).String() | data["aliyun_sms_code"] = gjson.Get(data["aliyun_sms_code"], types).String() | ||||
return data | return data | ||||
@@ -2,8 +2,8 @@ package svc | |||||
import ( | import ( | ||||
"applet/app/db" | "applet/app/db" | ||||
"applet/app/svc/sys_cfg" | |||||
"applet/app/utils" | "applet/app/utils" | ||||
"applet/app/utils/cache" | |||||
"applet/app/utils/logx" | "applet/app/utils/logx" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | ||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | ||||
@@ -25,17 +25,13 @@ func UserImg(user *model.User) *model.User { | |||||
return user | return user | ||||
} | } | ||||
func GetOssDomain() string { | func GetOssDomain() string { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") | sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") | ||||
http := sysCfg["oss_bucket_scheme"] | http := sysCfg["oss_bucket_scheme"] | ||||
return http + "://" + sysCfg["oss_domain"] + "/" | return http + "://" + sysCfg["oss_domain"] + "/" | ||||
} | } | ||||
func GetOssUrl(img string) string { | func GetOssUrl(img string) string { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db) | |||||
sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") | sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme") | ||||
if strings.Contains(img, "http") == false && img != "" { | if strings.Contains(img, "http") == false && img != "" { | ||||
http := sysCfg["oss_bucket_scheme"] | http := sysCfg["oss_bucket_scheme"] | ||||
@@ -51,11 +47,7 @@ func NumFormat(num int) string { | |||||
return str | return str | ||||
} | } | ||||
func GetSysCfgStr(key string) string { | func GetSysCfgStr(key string) string { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn) | |||||
return sysCfgDb.SysCfgGetWithDb(key) | |||||
return sys_cfg.NewSysCfgDb(db.Db).SysCfgGetWithDb(key) | |||||
} | } | ||||
// 是否实名 | // 是否实名 | ||||
@@ -1,8 +1,7 @@ | |||||
package svc | package svc | ||||
import ( | import ( | ||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"applet/app/svc/sys_cfg" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" | ||||
"fmt" | "fmt" | ||||
"strings" | "strings" | ||||
@@ -11,9 +10,7 @@ import ( | |||||
// ImageBucket is 获取域名 | // ImageBucket is 获取域名 | ||||
func ImageBucket(engine *xorm.Engine) (string, string) { | func ImageBucket(engine *xorm.Engine) (string, string) { | ||||
redisConn := cache.GetPool().Get() | |||||
defer redisConn.Close() | |||||
sysCfgDb := implement.NewSysCfgDb(engine, redisConn) | |||||
sysCfgDb := sys_cfg.NewSysCfgDb(engine) | |||||
res := sysCfgDb.SysCfgFindWithDb(enum.AliyunOssBucketScheme, enum.AliyunOssDomain) | res := sysCfgDb.SysCfgFindWithDb(enum.AliyunOssBucketScheme, enum.AliyunOssDomain) | ||||
return res[enum.AliyunOssBucketScheme], res[enum.AliyunOssDomain] | return res[enum.AliyunOssBucketScheme], res[enum.AliyunOssDomain] | ||||
} | } | ||||
@@ -0,0 +1,14 @@ | |||||
package sys_cfg | |||||
import "code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
type SysCfgDao interface { | |||||
SysCfgGetAll() (*[]model.SysCfg, error) | |||||
SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error) | |||||
SysCfgGetOne(key string) (*model.SysCfg, error) | |||||
SysCfgInsert(key, val, memo string) bool | |||||
SysCfgUpdate(key, val string) bool | |||||
SysCfgGetWithDb(HKey string) string | |||||
SysCfgDel(HKey string) error | |||||
SysCfgFindWithDb(keys ...string) map[string]string | |||||
} |
@@ -0,0 +1,118 @@ | |||||
package sys_cfg | |||||
import ( | |||||
"applet/app/utils/cache" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/md" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
zhios_order_relate_logx "code.fnuoos.com/EggPlanet/egg_models.git/utils/logx" | |||||
"fmt" | |||||
"xorm.io/xorm" | |||||
) | |||||
func NewSysCfgDb(engine *xorm.Engine) SysCfgDao { | |||||
return &SysCfgDb{ | |||||
Db: engine, | |||||
} | |||||
} | |||||
type SysCfgDb struct { | |||||
Db *xorm.Engine | |||||
} | |||||
func (s SysCfgDb) SysCfgGetAll() (*[]model.SysCfg, error) { | |||||
var cfgList []model.SysCfg | |||||
if err := s.Db.Cols("key,val,memo").Find(&cfgList); err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &cfgList, nil | |||||
} | |||||
func (s SysCfgDb) SysCfgGetOneNoDataNoErr(key string) (*model.SysCfg, error) { | |||||
var cfgList model.SysCfg | |||||
_, err := s.Db.Where("`key`=?", key).Get(&cfgList) | |||||
if err != nil { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &cfgList, nil | |||||
} | |||||
func (s SysCfgDb) SysCfgGetOne(key string) (*model.SysCfg, error) { | |||||
var cfgList model.SysCfg | |||||
if has, err := s.Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &cfgList, nil | |||||
} | |||||
func (s SysCfgDb) SysCfgInsert(key, val, memo string) bool { | |||||
cfg := model.SysCfg{Key: key, Val: val, Memo: memo} | |||||
_, err := s.Db.InsertOne(&cfg) | |||||
if err != nil { | |||||
zhios_order_relate_logx.Error(err) | |||||
return false | |||||
} | |||||
return true | |||||
} | |||||
func (s SysCfgDb) SysCfgUpdate(key, val string) bool { | |||||
cfg := model.SysCfg{Key: key, Val: val} | |||||
_, err := s.Db.Where("`key`=?", key).Cols("val").Update(&cfg) | |||||
if err != nil { | |||||
zhios_order_relate_logx.Error(err) | |||||
return false | |||||
} | |||||
s.SysCfgDel(key) | |||||
return true | |||||
} | |||||
func (s SysCfgDb) SysCfgGetWithDb(HKey string) string { | |||||
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1]) | |||||
get, err := cache.HGetString(cacheKey, HKey) | |||||
if err != nil || get == "" { | |||||
cfg, err := s.SysCfgGetOne(HKey) | |||||
if err != nil || cfg == nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
return "" | |||||
} | |||||
// key是否存在 | |||||
cacheKeyExist := false | |||||
if cache.Exists(cacheKey) { | |||||
cacheKeyExist = true | |||||
} | |||||
// 设置缓存 | |||||
_, err = cache.HSet(cacheKey, HKey, cfg.Val) | |||||
if err != nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
return "" | |||||
} | |||||
if !cacheKeyExist { // 如果是首次设置 设置过期时间 | |||||
_, err := cache.Expire(cacheKey, md.CfgCacheTime) | |||||
if err != nil { | |||||
_ = zhios_order_relate_logx.Error(err) | |||||
return "" | |||||
} | |||||
} | |||||
return cfg.Val | |||||
} | |||||
return get | |||||
} | |||||
func (s SysCfgDb) SysCfgDel(HKey string) error { | |||||
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, HKey[0:1]) | |||||
_, err := cache.HDel(cacheKey, HKey) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
return nil | |||||
} | |||||
func (s SysCfgDb) SysCfgFindWithDb(keys ...string) map[string]string { | |||||
res := map[string]string{} | |||||
for _, v := range keys { | |||||
val := s.SysCfgGetWithDb(v) | |||||
res[v] = val | |||||
} | |||||
return res | |||||
} |
@@ -32,8 +32,8 @@ require ( | |||||
) | ) | ||||
require ( | require ( | ||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241211055111-7c47b67b46d2 | |||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241212061625-6194cb8f4125 | |||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241212120727-3681308aeb14 | |||||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241212122404-22c05dd7f73c | |||||
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | ||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible | ||||