-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
137 lines (124 loc) · 5.24 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package FinanceDeposit
import (
CoreSQL "github.com/fotomxq/weeekj_core/v5/core/sql"
CoreSQLConfig "github.com/fotomxq/weeekj_core/v5/core/sql/config"
CoreSQLMarks "github.com/fotomxq/weeekj_core/v5/core/sql/marks"
CoreSQLPages "github.com/fotomxq/weeekj_core/v5/core/sql/pages"
Router2SystemConfig "github.com/fotomxq/weeekj_core/v5/router2/system_config"
"github.com/lib/pq"
)
// ArgsGetConfigList 获取列表参数
type ArgsGetConfigList struct {
//分页
Pages CoreSQLPages.ArgsDataList
//搜索
Search string
}
// GetConfigList 获取列表
func GetConfigList(args *ArgsGetConfigList) (dataList []FieldsConfigType, dataCount int64, err error) {
where := ""
maps := map[string]interface{}{}
if args.Search != "" {
where = where + "(des ILIKE '%' || :search || '%')"
maps["search"] = args.Search
} else {
maps = nil
}
if where == "" {
where = "true"
}
dataCount, err = CoreSQL.GetListPageAndCount(
Router2SystemConfig.MainDB.DB,
&dataList,
"finance_deposit_config",
"mark",
"SELECT mark, name, des, currency, take_out, take_limit, once_save_min_limit, once_save_max_limit, once_take_min_limit, once_take_max_limit, configs FROM finance_deposit_config WHERE "+where,
where,
maps,
&args.Pages,
[]string{"mark", "name"},
)
return
}
// ArgsGetConfigByMark 获取mark参数
type ArgsGetConfigByMark struct {
//标识码
Mark string `json:"mark" check:"mark"`
}
// GetConfigByMark 获取mark
func GetConfigByMark(args *ArgsGetConfigByMark) (data FieldsConfigType, err error) {
err = Router2SystemConfig.MainDB.Get(&data, "SELECT mark, name, des, currency, take_out, take_limit, once_save_min_limit, once_save_max_limit, once_take_min_limit, once_take_max_limit, configs FROM finance_deposit_config WHERE mark = $1", args.Mark)
return
}
// ArgsGetConfigMore 获取一组配置参数
type ArgsGetConfigMore struct {
//Mark列
Marks pq.StringArray `json:"marks" check:"marks"`
}
// GetConfigMore 获取一组配置
func GetConfigMore(args *ArgsGetConfigMore) (dataList []FieldsConfigType, err error) {
err = CoreSQLMarks.GetMarks(&dataList, "finance_deposit_config", "mark, name, des, currency, take_out, take_limit, once_save_min_limit, once_save_max_limit, once_take_min_limit, once_take_max_limit, configs", args.Marks)
return
}
// GetConfigMoreMap 获取一组配置名称组
func GetConfigMoreMap(args *ArgsGetConfigMore) (data map[string]string, err error) {
data, err = CoreSQLMarks.GetMarksName("finance_deposit_config", args.Marks)
return
}
// GetConfigName 获取配置名称
func GetConfigName(mark string) (name string) {
_ = Router2SystemConfig.MainDB.Get(&name, "SELECT name FROM finance_deposit_config WHERE mark = $1", mark)
return
}
// ArgsSetConfig 保存或设置新的参数
type ArgsSetConfig struct {
//标识码
// 可用于同一类货币下,多个用途,如赠送的储值额度、或用户自行充值的额度
// user 用户自己储值 ; deposit 押金 ; free 免费赠送额度 ; ... 特定系统下的充值模块
Mark string `db:"mark" json:"mark"`
//显示名称
Name string `db:"name" json:"name"`
//备注
Des string `db:"des" json:"des"`
//储蓄货币类型
// 采用CoreCurrency匹配
Currency int `db:"currency" json:"currency"`
//能否取出
// 如果能,则允许用户使用取出接口
TakeOut bool `db:"take_out" json:"takeOut"`
//取款最低限额
// 低于该资金禁止取款,同时需启动是否可取
TakeLimit int64 `db:"take_limit" json:"takeLimit"`
//单次存款最低限额
OnceSaveMinLimit int64 `db:"once_save_min_limit" json:"onceSaveMinLimit"`
//单次存款最大限额
OnceSaveMaxLimit int64 `db:"once_save_max_limit" json:"onceSaveMaxLimit"`
//单次取款最低限额
OnceTakeMinLimit int64 `db:"once_take_min_limit" json:"onceTakeMinLimit"`
//单次取款最大限额
OnceTakeMaxLimit int64 `db:"once_take_max_limit" json:"onceTakeMaxLimit"`
//扩展参数设计
Configs CoreSQLConfig.FieldsConfigsType `db:"configs" json:"configs"`
}
// SetConfig 保存或设置新的
func SetConfig(args *ArgsSetConfig) (data FieldsConfigType, err error) {
data, err = GetConfigByMark(&ArgsGetConfigByMark{
Mark: args.Mark,
})
if err != nil {
_, err = CoreSQL.CreateOne(Router2SystemConfig.MainDB.DB, "INSERT INTO finance_deposit_config (mark, name, des, currency, take_out, take_limit, once_save_min_limit, once_save_max_limit, once_take_min_limit, once_take_max_limit, configs) VALUES (:mark,:name,:des,:currency,:take_out,:take_limit,:once_save_min_limit,:once_save_max_limit,:once_take_min_limit,:once_take_max_limit,:configs)", args)
} else {
_, err = CoreSQL.UpdateOne(Router2SystemConfig.MainDB.DB, "UPDATE finance_deposit_config SET name = :name, des = :des, currency = :currency, take_out = :take_out, take_limit = :take_limit, once_save_min_limit = :once_save_min_limit, once_save_max_limit = :once_save_max_limit, once_take_min_limit = :once_take_min_limit, once_take_max_limit = :once_take_max_limit, configs = :configs WHERE mark = :mark", args)
}
return
}
// ArgsDeleteConfigByMark 删除参数
type ArgsDeleteConfigByMark struct {
//标识码
Mark string `db:"mark" json:"mark"`
}
// DeleteConfigByMark 删除
func DeleteConfigByMark(args *ArgsDeleteConfigByMark) (err error) {
_, err = CoreSQL.DeleteOne(Router2SystemConfig.MainDB.DB, "finance_deposit_config", "mark", args)
return
}