@@ -0,0 +1,46 @@ | |||
# Binaries for programs and plugins | |||
*.exe | |||
*.exe~ | |||
*.dll | |||
*.so | |||
*.dylib | |||
# Test binary, built with `go test -c` | |||
*.test | |||
# Output of the go coverage tool, specifically when used with LiteIDE | |||
*.out | |||
.idea | |||
.vscode | |||
*.log | |||
.DS_Store | |||
Thumbs.db | |||
*.swp | |||
*.swn | |||
*.swo | |||
*.swm | |||
*.7z | |||
*.zip | |||
*.rar | |||
*.tar | |||
*.tar.gz | |||
go.sum | |||
/etc/cfg.yaml | |||
images | |||
test/test.json | |||
etc/cfg.yml | |||
t.json | |||
t1.json | |||
t2.json | |||
t3.json | |||
t.go | |||
wait-for-it.sh | |||
test.go | |||
xorm | |||
test.csv | |||
nginx.conf | |||
.devcontainer | |||
.devcontainer/Dockerfile | |||
.devcontainer/sources.list | |||
/t1.go | |||
/tmp/* | |||
.idea/* | |||
/.idea/modules.xml |
@@ -0,0 +1,34 @@ | |||
# 多重构建,减少镜像大小 | |||
# 构建:使用golang:1.15版本 | |||
FROM golang:1.15 as build | |||
# 容器环境变量添加,会覆盖默认的变量值 | |||
ENV GO111MODULE=on | |||
ENV GOPROXY=https://goproxy.cn,direct | |||
ENV TZ="Asia/Shanghai" | |||
# 设置工作区 | |||
WORKDIR /go/release | |||
# 把全部文件添加到/go/release目录 | |||
ADD . . | |||
# 编译:把main.go编译成可执行的二进制文件,命名为zyos | |||
RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o zyos main.go | |||
FROM ubuntu:xenial as prod | |||
LABEL maintainer="wuhanqin" | |||
ENV TZ="Asia/Shanghai" | |||
COPY static/html static/html | |||
# 时区纠正 | |||
RUN rm -f /etc/localtime \ | |||
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ | |||
&& echo "Asia/Shanghai" > /etc/timezone | |||
# 在build阶段复制可执行的go二进制文件app | |||
COPY --from=build /go/release/zyos ./zyos | |||
COPY --from=build /go/release/etc/cfg.yml /var/zyos/cfg.yml | |||
# 启动服务 | |||
CMD ["./zyos","-c","/var/zyos/cfg.yml"] | |||
@@ -0,0 +1,34 @@ | |||
# 多重构建,减少镜像大小 | |||
# 构建:使用golang:1.15版本 | |||
FROM golang:1.15 as build | |||
# 容器环境变量添加,会覆盖默认的变量值 | |||
ENV GO111MODULE=on | |||
ENV GOPROXY=https://goproxy.cn,direct | |||
ENV TZ="Asia/Shanghai" | |||
# 设置工作区 | |||
WORKDIR /go/release | |||
# 把全部文件添加到/go/release目录 | |||
ADD . . | |||
# 编译:把main.go编译成可执行的二进制文件,命名为zyos | |||
RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o zyos_mall_task cmd/task/main.go | |||
FROM ubuntu:xenial as prod | |||
LABEL maintainer="wuhanqin" | |||
ENV TZ="Asia/Shanghai" | |||
COPY static/html static/html | |||
# 时区纠正 | |||
RUN rm -f /etc/localtime \ | |||
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ | |||
&& echo "Asia/Shanghai" > /etc/timezone | |||
# 在build阶段复制可执行的go二进制文件app | |||
COPY --from=build /go/release/zyos_mall_task ./zyos_mall_task | |||
COPY --from=build /go/release/etc/task.yml /var/zyos/task.yml | |||
# 启动服务 | |||
CMD ["./zyos_mall_task","-c","/var/zyos/task.yml"] | |||
@@ -0,0 +1,32 @@ | |||
.PHONY: build clean tool lint help | |||
APP=applet | |||
all: build | |||
build: | |||
go build -o ./bin/$(APP) ./cmd/main.go | |||
lite: | |||
go build -ldflags "-s -w" -o ./bin/$(APP) ./cmd/main.go | |||
install: | |||
#@go build -v . | |||
go install ./cmd/... | |||
tool: | |||
go vet ./...; true | |||
gofmt -w . | |||
lint: | |||
golint ./... | |||
clean: | |||
rm -rf go-gin-example | |||
go clean -i . | |||
help: | |||
@echo "make: compile packages and dependencies" | |||
@echo "make tool: run specified go tool" | |||
@echo "make lint: golint ./..." | |||
@echo "make clean: remove object files and cached files" |
@@ -0,0 +1,48 @@ | |||
# applet | |||
## 要看 nginx.conf 和 wap conf | |||
## 层级介绍 | |||
- hdl 做接收数据的报错, 数据校验 | |||
- svc 做数据处理的报错, 数据转换 | |||
- lib 只抛出错误给hdl或者svc进行处理, 不做数据校验 | |||
- db 可以处理db错误,其它错误返回给svc进行处理 | |||
- mw 中间件 | |||
- md 结构体 | |||
#### 介绍 | |||
基于gin的接口小程序 | |||
#### 软件架构 | |||
软件架构说明 | |||
#### 安装教程 | |||
1. xxxx | |||
2. xxxx | |||
3. xxxx | |||
#### 使用说明 | |||
1. xxxx | |||
2. xxxx | |||
3. xxxx | |||
#### 参与贡献 | |||
1. Fork 本仓库 | |||
2. 新建 Feat_xxx 分支 | |||
3. 提交代码 | |||
4. 新建 Pull Request | |||
## swagger | |||
``` | |||
// 参考:https://segmentfault.com/a/1190000013808421 | |||
// 安装命令行 | |||
go get -u github.com/swaggo/swag/cmd/swag | |||
// 生成 | |||
swag init | |||
``` |
@@ -0,0 +1,78 @@ | |||
package cfg | |||
import ( | |||
"time" | |||
) | |||
type Config struct { | |||
Debug bool `yaml:"debug"` | |||
Prd bool `yaml:"prd"` | |||
CurlDebug bool `yaml:"curldebug"` | |||
SrvAddr string `yaml:"srv_addr"` | |||
RedisAddr string `yaml:"redis_addr"` | |||
DB DBCfg `yaml:"db"` | |||
Log LogCfg `yaml:"log"` | |||
ArkID ArkIDCfg `yaml:"arkid"` | |||
Admin AdminCfg `yaml:"admin"` | |||
Official OfficialCfg `yaml:"official"` | |||
WxappletFilepath WxappletFilepathCfg `yaml:"wxapplet_filepath"` | |||
Local bool | |||
AppComm AppCommCfg `yaml:"app_comm"` | |||
} | |||
// 公共模块 | |||
type AppCommCfg struct { | |||
URL string `yaml:"url"` | |||
} | |||
// OfficialCfg is 官网 | |||
type OfficialCfg struct { | |||
URL string `yaml:"url"` | |||
} | |||
type WxappletFilepathCfg struct { | |||
URL string `yaml:"url"` | |||
} | |||
// AdminCfg is 后台接口调用需要 | |||
type AdminCfg struct { | |||
URL string `yaml:"url"` | |||
IURL string `yaml:"iurl"` | |||
AesKey string `yaml:"api_aes_key"` | |||
AesIV string `yaml:"api_aes_iv"` | |||
Host string `yaml:"host"` | |||
} | |||
type ArkIDCfg struct { | |||
Admin string `yaml:"admin"` | |||
AdminPassword string `yaml:"admin_password"` | |||
Url string `yaml:"url` | |||
} | |||
//数据库配置结构体 | |||
type DBCfg struct { | |||
Host string `yaml:"host"` //ip及端口 | |||
Name string `yaml:"name"` //库名 | |||
User string `yaml:"user"` //用户 | |||
Psw string `yaml:"psw"` //密码 | |||
ShowLog bool `yaml:"show_log"` //是否显示SQL语句 | |||
MaxLifetime time.Duration `yaml:"max_lifetime"` | |||
MaxOpenConns int `yaml:"max_open_conns"` | |||
MaxIdleConns int `yaml:"max_idle_conns"` | |||
Path string `yaml:"path"` //日志文件存放路径 | |||
} | |||
//日志配置结构体 | |||
type LogCfg struct { | |||
AppName string `yaml:"app_name" ` | |||
Level string `yaml:"level"` | |||
IsStdOut bool `yaml:"is_stdout"` | |||
TimeFormat string `yaml:"time_format"` // second, milli, nano, standard, iso, | |||
Encoding string `yaml:"encoding"` // console, json | |||
IsFileOut bool `yaml:"is_file_out"` | |||
FileDir string `yaml:"file_dir"` | |||
FileName string `yaml:"file_name"` | |||
FileMaxSize int `yaml:"file_max_size"` | |||
FileMaxAge int `yaml:"file_max_age"` | |||
} |
@@ -0,0 +1,3 @@ | |||
package cfg | |||
// 统一管理缓存 |
@@ -0,0 +1,9 @@ | |||
package cfg | |||
import ( | |||
"applet/app/utils/cache" | |||
) | |||
func InitCache() { | |||
cache.NewRedis(RedisAddr) | |||
} |
@@ -0,0 +1,60 @@ | |||
package cfg | |||
import ( | |||
"flag" | |||
"io/ioutil" | |||
"gopkg.in/yaml.v2" | |||
) | |||
//配置文件数据,全局变量 | |||
var ( | |||
Debug bool | |||
Prd bool | |||
CurlDebug bool | |||
SrvAddr string | |||
RedisAddr string | |||
DB *DBCfg | |||
Log *LogCfg | |||
ArkID *ArkIDCfg | |||
Admin *AdminCfg | |||
Official *OfficialCfg | |||
WxappletFilepath *WxappletFilepathCfg | |||
Local bool | |||
AppComm *AppCommCfg | |||
) | |||
//初始化配置文件,将cfg.yml读入到内存 | |||
func InitCfg() { | |||
//用指定的名称、默认值、使用信息注册一个string类型flag。 | |||
path := flag.String("c", "etc/cfg.yml", "config file") | |||
//解析命令行参数写入注册的flag里。 | |||
//解析之后,flag的值可以直接使用。 | |||
flag.Parse() | |||
var ( | |||
c []byte | |||
err error | |||
conf *Config | |||
) | |||
if c, err = ioutil.ReadFile(*path); err != nil { | |||
panic(err) | |||
} | |||
//yaml.Unmarshal反序列化映射到Config | |||
if err = yaml.Unmarshal(c, &conf); err != nil { | |||
panic(err) | |||
} | |||
//数据读入内存 | |||
Prd = conf.Prd | |||
Debug = conf.Debug | |||
Local = conf.Local | |||
CurlDebug = conf.CurlDebug | |||
DB = &conf.DB | |||
Log = &conf.Log | |||
ArkID = &conf.ArkID | |||
RedisAddr = conf.RedisAddr | |||
SrvAddr = conf.SrvAddr | |||
Admin = &conf.Admin | |||
Official = &conf.Official | |||
WxappletFilepath = &conf.WxappletFilepath | |||
AppComm = &conf.AppComm | |||
} |
@@ -0,0 +1,20 @@ | |||
package cfg | |||
import "applet/app/utils/logx" | |||
func InitLog() { | |||
logx.InitDefaultLogger(&logx.LogConfig{ | |||
AppName: Log.AppName, | |||
Level: Log.Level, | |||
StacktraceLevel: "error", | |||
IsStdOut: Log.IsStdOut, | |||
TimeFormat: Log.TimeFormat, | |||
Encoding: Log.Encoding, | |||
IsFileOut: Log.IsFileOut, | |||
FileDir: Log.FileDir, | |||
FileName: Log.FileName, | |||
FileMaxSize: Log.FileMaxSize, | |||
FileMaxAge: Log.FileMaxAge, | |||
Skip: 2, | |||
}) | |||
} |
@@ -0,0 +1,45 @@ | |||
package cfg | |||
import ( | |||
"flag" | |||
"io/ioutil" | |||
"gopkg.in/yaml.v2" | |||
mc "applet/app/utils/cache/cache" | |||
"applet/app/utils/logx" | |||
) | |||
func InitTaskCfg() { | |||
path := flag.String("c", "etc/task.yml", "config file") | |||
flag.Parse() | |||
var ( | |||
c []byte | |||
err error | |||
conf *Config | |||
) | |||
if c, err = ioutil.ReadFile(*path); err != nil { | |||
panic(err) | |||
} | |||
if err = yaml.Unmarshal(c, &conf); err != nil { | |||
panic(err) | |||
} | |||
Prd = conf.Prd | |||
Debug = conf.Debug | |||
DB = &conf.DB | |||
Log = &conf.Log | |||
Admin = &conf.Admin | |||
RedisAddr = conf.RedisAddr | |||
Local = conf.Local | |||
AppComm = &conf.AppComm | |||
} | |||
var MemCache mc.Cache | |||
func InitMemCache() { | |||
var err error | |||
MemCache, err = mc.NewCache("memory", `{"interval":60}`) | |||
if err != nil { | |||
logx.Fatal(err.Error()) | |||
} | |||
} |
@@ -0,0 +1,112 @@ | |||
package db | |||
import ( | |||
"database/sql" | |||
"fmt" | |||
"os" | |||
"time" | |||
_ "github.com/go-sql-driver/mysql" //必须导入mysql驱动,否则会panic | |||
"xorm.io/xorm" | |||
"xorm.io/xorm/log" | |||
"applet/app/cfg" | |||
"applet/app/utils/logx" | |||
) | |||
var Db *xorm.Engine | |||
//根据DB配置文件初始化数据库 | |||
func InitDB(c *cfg.DBCfg) error { | |||
var ( | |||
err error | |||
f *os.File | |||
) | |||
//创建Orm引擎 | |||
if Db, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", c.User, c.Psw, c.Host, c.Name)); err != nil { | |||
return err | |||
} | |||
Db.SetConnMaxLifetime(c.MaxLifetime * time.Second) //设置最长连接时间 | |||
Db.SetMaxOpenConns(c.MaxOpenConns) //设置最大打开连接数 | |||
Db.SetMaxIdleConns(c.MaxIdleConns) //设置连接池的空闲数大小 | |||
if err = Db.Ping(); err != nil { //尝试ping数据库 | |||
return err | |||
} | |||
if c.ShowLog { //根据配置文件设置日志 | |||
Db.ShowSQL(true) //设置是否打印sql | |||
Db.Logger().SetLevel(0) //设置日志等级 | |||
//修改日志文件存放路径文件名是%s.log | |||
path := fmt.Sprintf(c.Path, c.Name) | |||
f, err = os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777) | |||
if err != nil { | |||
os.RemoveAll(c.Path) | |||
if f, err = os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777); err != nil { | |||
return err | |||
} | |||
} | |||
logger := log.NewSimpleLogger(f) | |||
logger.ShowSQL(true) | |||
Db.SetLogger(logger) | |||
} | |||
return nil | |||
} | |||
/********************************************* 公用方法 *********************************************/ | |||
// 数据批量插入 | |||
func DbInsertBatch(Db *xorm.Engine, m ...interface{}) error { | |||
if len(m) == 0 { | |||
return nil | |||
} | |||
id, err := Db.Insert(m...) | |||
if id == 0 || err != nil { | |||
return logx.Warn("cannot insert data :", err) | |||
} | |||
return nil | |||
} | |||
// QueryNativeString 查询原生sql | |||
func QueryNativeString(Db *xorm.Engine, sql string, args ...interface{}) ([]map[string]string, error) { | |||
results, err := Db.SQL(sql, args...).QueryString() | |||
return results, err | |||
} | |||
// UpdateComm common update | |||
func UpdateComm(Db *xorm.Engine, id interface{}, model interface{}) (int64, error) { | |||
row, err := Db.ID(id).Update(model) | |||
return row, err | |||
} | |||
// InsertComm common insert | |||
func InsertComm(Db *xorm.Engine, model interface{}) (int64, error) { | |||
row, err := Db.InsertOne(model) | |||
return row, err | |||
} | |||
// ExecuteOriginalSql 执行原生sql | |||
func ExecuteOriginalSql(session *xorm.Session, sql string) (sql.Result, error) { | |||
result, err := session.Exec(sql) | |||
if err != nil { | |||
_ = logx.Warn(err) | |||
return nil, err | |||
} | |||
return result, nil | |||
} | |||
// GetComm | |||
// payload *model | |||
// return *model,has,err | |||
func GetComm(Db *xorm.Engine, model interface{}) (interface{}, bool, error) { | |||
has, err := Db.Get(model) | |||
if err != nil { | |||
_ = logx.Warn(err) | |||
return nil, false, err | |||
} | |||
return model, has, nil | |||
} | |||
// InsertCommWithSession common insert | |||
func InsertCommWithSession(session *xorm.Session, model interface{}) (int64, error) { | |||
row, err := session.InsertOne(model) | |||
return row, err | |||
} |
@@ -0,0 +1,16 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
//UserProfileFindByArkID is get userprofile by arkid | |||
func CapitalPoolByIsUse(Db *xorm.Engine) (*model.CapitalPool, error) { | |||
var m model.CapitalPool | |||
if has, err := Db.Where("is_use = 1").Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} |
@@ -0,0 +1,40 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"errors" | |||
"xorm.io/xorm" | |||
) | |||
// GetCloudBundleByVersion is 根据版本 获取打包记录 | |||
func GetCloudBundleByVersion(Db *xorm.Engine, appverison string, os int) (*model.CloudBundle, error) { | |||
m := new(model.CloudBundle) | |||
has, err := Db.Where("version = ? and os = ?", appverison, os).Get(m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !has { | |||
return nil, errors.New("not Found") | |||
} | |||
return m, nil | |||
} | |||
// GetCloudBundleByVersionPlatform is 根据版本\os 获取打包记录 | |||
func GetCloudBundleByVersionPlatform(Db *xorm.Engine, appverison string, platform string) (*model.CloudBundle, error) { | |||
m := new(model.CloudBundle) | |||
var tag int | |||
if platform == "ios" { | |||
tag = 2 | |||
} else { | |||
tag = 1 | |||
} | |||
has, err := Db.Where("version = ? and os=?", appverison, tag).Get(m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !has { | |||
return nil, errors.New("not Found") | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,33 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// 通过文件名目录与文件名查找文件 | |||
func FileGetByPFidAndName(Db *xorm.Engine, dirId, fname string) (*model.SysFile, error) { | |||
var f model.SysFile | |||
if has, err := Db.Where("parent_fid = ? AND show_name = ?", dirId, fname).Get(&f); !has || err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &f, nil | |||
} | |||
// 插入文件信息 | |||
func FileInsert(Db *xorm.Engine, f *model.SysFile) error { | |||
if _, err := Db.InsertOne(f); err != nil { | |||
return logx.Warn(err) | |||
} | |||
return nil | |||
} | |||
// 文件信息更新 | |||
func FileUpdate(Db *xorm.Engine, f *model.SysFile) error { | |||
if _, err := Db.Where("`fid` = ?", f.Fid).Update(f); err != nil { | |||
return logx.Warn(err) | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,43 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
type AgentBase struct { | |||
Session *xorm.Session | |||
AgentBase *model.RegionalAgentBase | |||
} | |||
func NewAgentBase(session *xorm.Session, agentBase *model.RegionalAgentBase) *AgentBase { | |||
return &AgentBase{ | |||
Session: session, | |||
AgentBase: agentBase, | |||
} | |||
} | |||
func (a AgentBase) GetAgentBaseInfo() bool { | |||
isHas, err := a.Session.Get(a.AgentBase) | |||
if err != nil { | |||
return false | |||
} | |||
if !isHas { | |||
return false | |||
} | |||
return true | |||
} | |||
// GetCountByRegionalAgentBase 通过传入的参数查询数据(单条) | |||
func GetCountByRegionalAgentBase(Db *xorm.Engine) (*model.RegionalAgentBase, error) { | |||
var m model.RegionalAgentBase | |||
get, err := Db.Get(&m) | |||
if err != nil { | |||
return &m, err | |||
} | |||
if !get { | |||
return &m, logx.Warn("Not found") | |||
} | |||
return &m, nil | |||
} |
@@ -0,0 +1,46 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// 系统配置get | |||
func SysCfgGetAll(Db *xorm.Engine) (*[]model.SysCfg, error) { | |||
var cfgList []model.SysCfg | |||
if err := Db.Cols("key,val,memo").Find(&cfgList); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
// 获取一条记录 | |||
func SysCfgGetOne(Db *xorm.Engine, key string) (*model.SysCfg, error) { | |||
var cfgList model.SysCfg | |||
if has, err := Db.Where("`key`=?", key).Get(&cfgList); err != nil || has == false { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
// 返回最后插入id | |||
func SysCfgInsert(Db *xorm.Engine, key, val, memo string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val, Memo: memo} | |||
_, err := Db.InsertOne(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
return true | |||
} | |||
func SysCfgUpdate(Db *xorm.Engine, key, val, memo string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val, Memo: memo} | |||
_, err := Db.Where("`key`=?", key).Cols("val,memo").Update(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
return true | |||
} |
@@ -0,0 +1,476 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"errors" | |||
"strconv" | |||
"strings" | |||
"github.com/gin-gonic/gin" | |||
"github.com/tidwall/gjson" | |||
"xorm.io/xorm" | |||
) | |||
// 返回所有, 不管是否显示 | |||
func SysModFindAll(Db *xorm.Engine) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// 查找主模块数据 | |||
func SysModFindMain(Db *xorm.Engine) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.Where("mod_pid = 0 AND state = 1 AND position = 'base'"). | |||
Asc("sort"). | |||
Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// 用父ID查找子模块数据 | |||
func SysModFindByPId(c *gin.Context, Db *xorm.Engine, id int) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.Where("state = 1").Where("mod_pid = ?", id). | |||
Asc("sort"). | |||
Find(&m); err != nil { | |||
return nil, err | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
var ms []model.SysModule | |||
modname_list := []string{"product", "search_result_taobao_item", "hot_rank_tab_view"} | |||
for _, item := range *mm.(*[]model.SysModule) { | |||
if strings.Contains(item.Data, "tmall") == false && item.ModName == "product_detail_title" { | |||
item.Data = strings.Replace(item.Data, "\"platform_css\":[", "\"platform_css\":[{\"name\":\"天猫\",\"type\":\"tmall\",\"text_color\":\"#FFFFFF\",\"bg_color\":\"#FF4242\"},", 1) | |||
} | |||
if strings.Contains(item.Data, "tmall") == false && utils.InArr(item.ModName, modname_list) { | |||
item.Data = strings.Replace(item.Data, "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"index\":\"7\",\"type\":\"tmall\",\"platform_name\":\"天猫\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1) | |||
item.Data = strings.Replace(item.Data, "{\"type\":\"kaola\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"type\":\"kaola\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"type\":\"tmall\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1) | |||
} | |||
if strings.Contains(item.Data, "优惠卷") { | |||
item.Data = strings.Replace(item.Data, "优惠卷", "优惠券", -1) | |||
} | |||
ms = append(ms, item) | |||
} | |||
return &ms, nil | |||
} | |||
// 用父ID查找子模块数据 | |||
func SysModFindByPIds(c *gin.Context, Db *xorm.Engine, ids ...int) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.In("mod_pid", ids).Where("state = 1"). | |||
Asc("sort"). | |||
Find(&m); err != nil { | |||
return nil, err | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
var ms []model.SysModule | |||
for _, item := range *mm.(*[]model.SysModule) { | |||
//数据里面 | |||
if strings.Contains(item.Data, "tmall") == false && item.ModName == "product" { | |||
item.Data = strings.Replace(item.Data, "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"index\":\"7\",\"type\":\"tmall\",\"platform_name\":\"天猫\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1) | |||
} | |||
item = SysModDataByReplace(c, item) | |||
ms = append(ms, item) | |||
} | |||
return &ms, nil | |||
} | |||
// 用IDS找对应模块数据 | |||
func SysModFindByIds(Db *xorm.Engine, ids ...int) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.In("mod_id", ids).Where("state = 1"). | |||
Cols("mod_id,mod_pid,mod_name,position,skip_identifier,title,subtitle,url,margin,aspect_ratio,icon,img,font_color,bg_img,bg_color,bg_color_t,badge,path,data,sort"). | |||
Asc("sort").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// ID查找对应模块 | |||
func SysModFindById(c *gin.Context, Db *xorm.Engine, id string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND mod_id = ?", id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
// SysModFindByTmpId is 根据模板 | |||
func SysModFindByTmpId(c *gin.Context, Db *xorm.Engine, id string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND template_id = ?", id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
// Name查找对应模块 | |||
func SysModFindByName(c *gin.Context, Db *xorm.Engine, name string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND mod_name = ?", name). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
// SysModFindByName is Name查找对应模块 | |||
func SysModFindByNames(names ...string) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.In("mod_name", names).Where("state = 1"). | |||
Cols("mod_id,mod_pid,mod_name,position,skip_identifier,title,subtitle,url,margin,aspect_ratio,icon,img,font_color,bg_img,bg_color,bg_color_t,badge,path,data,sort"). | |||
Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// SysModFindByPosition is 根据位置查找对应模块 | |||
func SysModFindByPosition(Db *xorm.Engine, positions ...string) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.In("position", positions).Where("state = 1").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// 根据跳转标识 查找对应模块 | |||
func SysModFindBySkipIdentifier(c *gin.Context, Db *xorm.Engine, name string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND skip_identifier = ?", name). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
// 根据跳转标识和位置 查找对应模块list | |||
func SysModFindBySkipIdentifierAndPosition(c *gin.Context, Db *xorm.Engine, name string, position string) (*[]model.SysModule, error) { | |||
var m []model.SysModule | |||
if err := Db.Where("state = 1 AND skip_identifier = ? AND position = ?", name, position). | |||
Cols("mod_id,mod_pid,mod_name,position,skip_identifier,title,subtitle,url,margin,aspect_ratio,icon,img,font_color,bg_img,bg_color,bg_color_t,badge,path,data,sort"). | |||
Asc("sort").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*[]model.SysModule), nil | |||
} | |||
// SysModFindByTemplateIDAndSkip is 根据模板id 查找对应模块 | |||
func SysModFindByTemplateIDAndSkip(Db *xorm.Engine, id interface{}, skip string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND skip_identifier = ?", id, skip). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// SysModFindByTemplateIDAndPID is 根据模板id 和pid =0 查找父模块 | |||
func SysModFindByTemplateIDAndPID(Db *xorm.Engine, id interface{}, pid interface{}) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_pid = ?", id, pid). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// SysModFindByTemplateIDAndModName is 根据模板id 和mod name 查找模块 | |||
func SysModFindByTemplateIDAndModName(Db *xorm.Engine, id interface{}, modName string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = ?", id, modName). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// SysModFindNavIsUsed 查找正在使用的底部导航栏模板 | |||
func SysModFindNavIsUsedByPlatform(c *gin.Context, Db *xorm.Engine, platform string) (*model.SysModule, error) { | |||
var ( | |||
tm model.SysTemplate | |||
m model.SysModule | |||
) | |||
switch platform { | |||
case "ios": | |||
if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 2 "). | |||
Cols("id,uid,name,is_use,is_system"). | |||
Get(&tm); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
appvserison := SysCfgGet(c, "ios_audit_version") | |||
if c.GetHeader("app_version_name") == appvserison && c.GetHeader("app_version_name") != "" { | |||
m, err := GetCloudBundleByVersion(Db, appvserison, 2) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
tm.Id = int(gjson.Get(m.TemplateDuringAudit, "bottom").Int()) | |||
} | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
case "android": | |||
has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 2 ").Cols("id,uid,name,is_use,is_system").Get(&tm) | |||
if err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
appvserison := SysCfgGet(c, "android_audit_version") | |||
if appvserison != "" && c.GetHeader("app_version_name") == appvserison { | |||
m, err := GetCloudBundleByVersion(Db, appvserison, 1) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
tm.Id = int(gjson.Get(m.TemplateDuringAudit, "bottom").Int()) | |||
} | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
case "wx_applet", "wap": | |||
if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 "). | |||
Cols("id,uid,name,is_use,is_system"). | |||
Get(&tm); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
appvserison := SysCfgGet(c, "mp_audit_version") | |||
// fmt.Println("header:", c.Request.Header) | |||
if c.GetHeader("AppVersionName") == appvserison && c.GetHeader("AppVersionName") != "" { | |||
m, err := SysCfgGetOne(Db, "mp_audit_template") | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
tm.Id = int(gjson.Get(m.Val, "bottom").Int()) | |||
} | |||
// fmt.Println("template_id", tm.Id) | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
case "baidu_applet": | |||
if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 "). | |||
Cols("id,uid,name,is_use,is_system"). | |||
Get(&tm); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
appvserison := SysCfgGet(c, "baidu_audit_version") | |||
if appvserison != "" && c.GetHeader("app_version_name") == appvserison { | |||
m, err := SysCfgGetOne(Db, "baidu_audit_template") | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
tm.Id = int(gjson.Get(m.Val, "bottom").Int()) | |||
} | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
case "toutiao_applet": | |||
if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 "). | |||
Cols("id,uid,name,is_use,is_system"). | |||
Get(&tm); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
appvserison := SysCfgGet(c, "tt_audit_version") | |||
if appvserison != "" && c.GetHeader("app_version_name") == appvserison { | |||
m, err := SysCfgGetOne(Db, "tt_audit_template") | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
tm.Id = int(gjson.Get(m.Val, "bottom").Int()) | |||
} | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
case "alipay_applet": | |||
if has, err := Db.Where("is_use = 1 AND type = 'bottom' AND platform = 4 "). | |||
Cols("id,uid,name,is_use,is_system"). | |||
Get(&tm); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
appvserison := SysCfgGet(c, "zfb_audit_version") | |||
if appvserison != "" && c.GetHeader("app_version_name") == appvserison { | |||
m, err := SysCfgGetOne(Db, "zfb_audit_template") | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
tm.Id = int(gjson.Get(m.Val, "bottom").Int()) | |||
} | |||
if has, err := Db.Where("state = 1 AND template_id = ? AND mod_name = 'bottom_nav'", tm.Id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
default: | |||
return &m, errors.New("Platform not support") | |||
} | |||
} | |||
// SysModFindBySkipIdentifierAndModName is 根据mod_name和位置 查找对应模块 | |||
func SysModFindBySkipIdentifierAndModName(c *gin.Context, Db *xorm.Engine, name string, modName string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND skip_identifier = ? AND mod_name = ?", name, modName).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
// SysModFindByModName is 根据mod_name和位置 查找对应模块 | |||
func SysModFindByModName(c *gin.Context, Db *xorm.Engine, modName string) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND mod_name = ?", modName).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
// 根据跳转标识和平台类型查找 | |||
func SysModFindBySkipIdentifierAndPlatform(c *gin.Context, Db *xorm.Engine, name string, platform int) (*model.SysModule, error) { | |||
var m model.SysModule | |||
if has, err := Db.Where("state = 1 AND skip_identifier = ? AND platform = ?", name, platform).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysModule), nil | |||
} | |||
//公共处理modData的链接 | |||
func SysModDataByReplace(c *gin.Context, mod model.SysModule) model.SysModule { | |||
//替换链接的一些参数 | |||
if strings.Contains(mod.Data, "[replace_APP_URL]") { | |||
mod.Data = strings.Replace(mod.Data, "[replace_APP_URL]", c.GetString("domain_wap_base"), -1) | |||
} | |||
if strings.Contains(mod.Data, "[replace_masterId]") { | |||
mod.Data = strings.Replace(mod.Data, "[replace_masterId]", c.GetString("mid"), -1) | |||
} | |||
if strings.Contains(mod.Data, "优惠卷") { | |||
mod.Data = strings.Replace(mod.Data, "优惠卷", "优惠券", -1) | |||
} | |||
if strings.Contains(mod.Data, "[replace_uid]") { | |||
token := c.GetHeader("Authorization") | |||
// 按空格分割 | |||
parts := strings.SplitN(token, " ", 2) | |||
if len(parts) == 2 && parts[0] == "Bearer" { | |||
// parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它 | |||
mc, _ := utils.ParseToken(parts[1]) | |||
mod.Data = strings.Replace(mod.Data, "[replace_uid]", strconv.Itoa(mc.UID), -1) | |||
} | |||
} | |||
//if strings.Contains(mod.Data, "\"child_category_id") && strings.Contains(mod.Data, "\"category_id") { | |||
// //如果存在这两个字段,要换一下 | |||
// mod.Data = strings.ReplaceAll(mod.Data, "\"category_id", "\"null_category_id") | |||
// mod.Data = strings.ReplaceAll(mod.Data, "\"child_category_id", "\"category_id") | |||
//} | |||
return mod | |||
} | |||
//公共处理modData的链接 | |||
func SysModDataByReplaceSecond(c *gin.Context, mod *model.SysModule) *model.SysModule { | |||
//替换链接的一些参数 | |||
if strings.Contains(mod.Data, "[replace_APP_URL]") { | |||
mod.Data = strings.Replace(mod.Data, "[replace_APP_URL]", c.GetString("domain_wap_base"), -1) | |||
} | |||
if strings.Contains(mod.Data, "[replace_masterId]") { | |||
mod.Data = strings.Replace(mod.Data, "[replace_masterId]", c.GetString("mid"), -1) | |||
} | |||
if strings.Contains(mod.Data, "优惠卷") { | |||
mod.Data = strings.Replace(mod.Data, "优惠卷", "优惠券", -1) | |||
} | |||
if strings.Contains(mod.Data, "[replace_uid]") { | |||
token := c.GetHeader("Authorization") | |||
// 按空格分割 | |||
parts := strings.SplitN(token, " ", 2) | |||
if len(parts) == 2 && parts[0] == "Bearer" { | |||
// parts[1]是获取到的tokenString,我们使用之前定义好的解析JWT的函数来解析它 | |||
mc, _ := utils.ParseToken(parts[1]) | |||
mod.Data = strings.Replace(mod.Data, "[replace_uid]", strconv.Itoa(mc.UID), -1) | |||
} | |||
} | |||
//if strings.Contains(mod.Data, "\"child_category_id") && strings.Contains(mod.Data, "\"category_id") { | |||
// //如果存在这两个字段,要换一下 | |||
// mod.Data = strings.ReplaceAll(mod.Data, "\"category_id", "\"null_category_id") | |||
// mod.Data = strings.ReplaceAll(mod.Data, "\"child_category_id", "\"category_id") | |||
//} | |||
return mod | |||
} |
@@ -0,0 +1,493 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"applet/app/utils/logx" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/syyongx/php2go" | |||
"github.com/tidwall/gjson" | |||
"regexp" | |||
"strings" | |||
"xorm.io/xorm" | |||
"github.com/gin-gonic/gin" | |||
) | |||
//处理多眼导航数据 激励广告过滤 | |||
func MultiNavFormat(c *gin.Context, mod model.SysModule) model.SysModule { | |||
var data = mod.Data | |||
var listStyle = gjson.Get(data, "list_style").String() | |||
var multiNav []md.MultiNav | |||
if err := json.Unmarshal([]byte(listStyle), &multiNav); err != nil { | |||
return mod | |||
} | |||
userLevelWeight := c.GetString("user_level_weight") | |||
var list []md.MultiNav | |||
for _, v := range multiNav { | |||
if v.SkipIdentifier == "pub.flutter.incentive_ad" && v.Data.Conditions == "1" { | |||
var levelWeight = 0 | |||
if v.Data.LevelWeight != "" && v.Data.LevelWeight != "0" { | |||
levelWeight = utils.StrToInt(v.Data.LevelWeight) | |||
} | |||
//如果用户等级大于等于设置等级 就显示 | |||
if utils.StrToInt(userLevelWeight) >= levelWeight && c.GetString("user_login") == "1" { | |||
list = append(list, v) | |||
} | |||
} else { | |||
list = append(list, v) | |||
} | |||
} | |||
b, err := json.Marshal(list) | |||
if err != nil { | |||
return mod | |||
} | |||
if b != nil { | |||
mod.Data = strings.Replace(mod.Data, listStyle, string(b), -1) | |||
} | |||
return mod | |||
} | |||
func sysModFormat(c *gin.Context, m interface{}) (interface{}, error) { | |||
var mods []model.SysModule | |||
protocol := SysCfgGet(c, "file_bucket_scheme") | |||
domain := SysCfgGet(c, "file_bucket_host") | |||
//fmt.Println(protocol, domain) | |||
if protocol == "" || domain == "" { | |||
return nil, errors.New("System configuration error, object storage protocol and domain name not found") | |||
} | |||
modname_list := []string{"product", "search_result_taobao_item", "hot_rank_tab_view"} | |||
switch m.(type) { | |||
case *[]model.SysModule: | |||
ms := m.(*[]model.SysModule) | |||
for _, item := range *ms { | |||
replaceList := reformatPng(item.Data) | |||
l := removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, php2go.Rawurlencode(s)) | |||
item.Data = strings.ReplaceAll(item.Data, ss, `"`+newVal+`"`) | |||
} | |||
replaceList = reformatJPG(item.Data) | |||
l = removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, php2go.Rawurlencode(s)) | |||
item.Data = strings.Replace(item.Data, ss, `"`+newVal+`"`, -1) | |||
} | |||
replaceList = reformatGIF(item.Data) | |||
l = removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, php2go.Rawurlencode(s)) | |||
item.Data = strings.Replace(item.Data, ss, `"`+newVal+`"`, -1) | |||
} | |||
if strings.Contains(item.Data, "tmall") == false && item.ModName == "product_detail_title" { | |||
item.Data = strings.Replace(item.Data, "\"platform_css\":[", "\"platform_css\":[{\"name\":\"天猫\",\"type\":\"tmall\",\"text_color\":\"#FFFFFF\",\"bg_color\":\"#FF4242\"},", 1) | |||
} | |||
if strings.Contains(item.Data, "tmall") == false && utils.InArr(item.ModName, modname_list) { | |||
item.Data = strings.Replace(item.Data, "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"index\":\"6\",\"type\":\"kaola\",\"platform_name\":\"考拉\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"index\":\"7\",\"type\":\"tmall\",\"platform_name\":\"天猫\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1) | |||
item.Data = strings.Replace(item.Data, "{\"type\":\"kaola\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", "{\"type\":\"kaola\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"},{\"type\":\"tmall\",\"provider_name_color\":\"#FFFFFF\",\"provider_bg_color\":\"#FF4242\"}", 1) | |||
} | |||
item = SysModDataByReplace(c, item) | |||
if item.ModName == "multi_nav" { | |||
item = MultiNavFormat(c, item) | |||
} | |||
mods = append(mods, item) | |||
} | |||
return &mods, nil | |||
case *model.SysModule: | |||
m := m.(*model.SysModule) | |||
repalceList := reformatPng(m.Data) | |||
l := removeDuplicateElement(repalceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
if skipHTTPPng(s) { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
new := fmt.Sprintf(`%s://%s/%s`, protocol, domain, php2go.Rawurlencode(s)) | |||
m.Data = strings.Replace(m.Data, ss, `"`+new+`"`, -1) | |||
} | |||
repalceList = reformatJPG(m.Data) | |||
l = removeDuplicateElement(repalceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, php2go.Rawurlencode(s)) | |||
m.Data = strings.Replace(m.Data, ss, `"`+new+`"`, -1) | |||
} | |||
repalceList = reformatGIF(m.Data) | |||
l = removeDuplicateElement(repalceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, php2go.Rawurlencode(s)) | |||
m.Data = strings.Replace(m.Data, ss, `"`+new+`"`, -1) | |||
} | |||
m = SysModDataByReplaceSecond(c, m) | |||
return m, nil | |||
case []*model.UserLevel: | |||
ms := m.([]*model.UserLevel) | |||
for _, item := range ms { | |||
replaceList := reformatPng(item.CssSet) | |||
l := removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
// png | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
item.CssSet = strings.Replace(item.CssSet, ss, `"`+newVal+`"`, -1) | |||
// jpg | |||
replaceList = reformatJPG(item.CssSet) | |||
l = removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
item.CssSet = strings.Replace(item.CssSet, ss, `"`+newVal+`"`, -1) | |||
} | |||
} | |||
} | |||
return ms, nil | |||
case []*model.SysPushUser: | |||
ms := m.([]*model.SysPushUser) | |||
for _, item := range ms { | |||
replaceList := reformatPng(item.SendData) | |||
l := removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
// png | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
item.SendData = strings.Replace(item.SendData, ss, `"`+newVal+`"`, -1) | |||
// jpg | |||
replaceList = reformatJPG(item.SendData) | |||
l = removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
newVal := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
item.SendData = strings.Replace(item.SendData, ss, `"`+newVal+`"`, -1) | |||
} | |||
} | |||
} | |||
return ms, nil | |||
case *model.SysPushUser: | |||
m := m.(*model.SysPushUser) | |||
repalceList := reformatPng(m.SendData) | |||
l := removeDuplicateElement(repalceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
m.SendData = strings.Replace(m.SendData, ss, `"`+new+`"`, -1) | |||
} | |||
repalceList = reformatJPG(m.SendData) | |||
l = removeDuplicateElement(repalceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
m.SendData = strings.Replace(m.SendData, ss, `"`+new+`"`, -1) | |||
} | |||
repalceList = reformatGIF(m.SendData) | |||
l = removeDuplicateElement(repalceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
m.SendData = strings.Replace(m.SendData, ss, `"`+new+`"`, -1) | |||
} | |||
return m, nil | |||
default: | |||
return nil, nil | |||
} | |||
} | |||
func ReformatStr(str string, c *gin.Context) string { | |||
protocol := SysCfgGet(c, "file_bucket_scheme") | |||
domain := SysCfgGet(c, "file_bucket_host") | |||
// PNG | |||
replaceList := reformatPng(str) | |||
l := removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
if skipHTTPPng(new) { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
str = strings.Replace(str, ss, `"`+new+`"`, -1) | |||
} | |||
// JPG | |||
replaceList = reformatJPG(str) | |||
l = removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
if skipHTTPPng(new) { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
str = strings.Replace(str, ss, `"`+new+`"`, -1) | |||
} | |||
// GIF | |||
replaceList = reformatGIF(str) | |||
l = removeDuplicateElement(replaceList) | |||
for _, s := range l { | |||
if strings.Contains(s, "http") { | |||
continue | |||
} | |||
s = strings.ReplaceAll(s, `\`, "") | |||
s = php2go.Rawurlencode(s) | |||
new := fmt.Sprintf("%s://%s/%s", protocol, domain, s) | |||
if skipHTTPPng(new) { | |||
continue | |||
} | |||
ss := s | |||
s = strings.ReplaceAll(s, `"`, "") | |||
str = strings.Replace(str, ss, `"`+new+`"`, -1) | |||
} | |||
return str | |||
} | |||
// 正则匹配 | |||
func reformatPng(data string) []string { | |||
re, _ := regexp.Compile(`"([^\"]*.png")`) | |||
list := re.FindAllString(data, -1) | |||
return list | |||
} | |||
// | |||
func skipHTTPPng(data string) bool { | |||
re, _ := regexp.Compile(`(http|https):\/\/([^\"]*.png)`) | |||
return re.MatchString(data) | |||
} | |||
// 正则匹配 | |||
func reformatJPG(data string) []string { | |||
re, _ := regexp.Compile(`"([^\"]*.jpg")`) | |||
list := re.FindAllString(data, -1) | |||
return list | |||
} | |||
// 正则匹配 | |||
func reformatGIF(data string) []string { | |||
re, _ := regexp.Compile(`"([^\"]*.gif")`) | |||
list := re.FindAllString(data, -1) | |||
return list | |||
} | |||
func removeDuplicateElement(addrs []string) []string { | |||
result := make([]string, 0, len(addrs)) | |||
temp := map[string]int{} | |||
i := 1 | |||
for _, item := range addrs { | |||
if _, ok := temp[item]; !ok { | |||
temp[item] = i | |||
result = append(result, item) | |||
continue | |||
} | |||
temp[item] = temp[item] + 1 | |||
} | |||
// fmt.Println(temp) | |||
return result | |||
} | |||
//单条记录获取 | |||
func SysCfgGet(c *gin.Context, key string) string { | |||
res := SysCfgFind(c, key) | |||
//fmt.Println(res) | |||
if _, ok := res[key]; !ok { | |||
return "" | |||
} | |||
return res[key] | |||
} | |||
//单条记录获取DB | |||
func SysCfgGetWithDb(eg *xorm.Engine, masterId string, HKey string) string { | |||
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, masterId, HKey[0:1]) | |||
get, err := cache.HGetString(cacheKey, HKey) | |||
if err != nil || get == "" { | |||
cfg, err := SysCfgGetOne(eg, HKey) | |||
if err != nil || cfg == nil { | |||
_ = logx.Error(err) | |||
return "" | |||
} | |||
// key是否存在 | |||
cacheKeyExist := false | |||
if cache.Exists(cacheKey) { | |||
cacheKeyExist = true | |||
} | |||
// 设置缓存 | |||
_, err = cache.HSet(cacheKey, HKey, cfg.Val) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
return "" | |||
} | |||
if !cacheKeyExist { // 如果是首次设置 设置过期时间 | |||
_, err := cache.Expire(cacheKey, md.CfgCacheTime) | |||
if err != nil { | |||
_ = logx.Error(err) | |||
return "" | |||
} | |||
} | |||
return cfg.Val | |||
} | |||
return get | |||
} | |||
// 多条记录获取 | |||
func SysCfgFind(c *gin.Context, keys ...string) map[string]string { | |||
res := map[string]string{} | |||
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, c.GetString("mid")) | |||
err := cache.GetJson(cacheKey, &res) | |||
if err != nil || len(res) == 0 { | |||
cfgList, _ := SysCfgGetAll(DBs[c.GetString("mid")]) | |||
if cfgList == nil { | |||
return nil | |||
} | |||
for _, v := range *cfgList { | |||
res[v.Key] = v.Val | |||
} | |||
cache.SetJson(cacheKey, res, md.CfgCacheTime) | |||
} | |||
if len(keys) == 0 { | |||
return res | |||
} | |||
tmp := map[string]string{} | |||
for _, v := range keys { | |||
if val, ok := res[v]; ok { | |||
tmp[v] = val | |||
} else { | |||
tmp[v] = "" | |||
} | |||
} | |||
return tmp | |||
} | |||
// 多条记录获取DB | |||
func SysCfgFindWithDb(eg *xorm.Engine, masterId string, keys ...string) map[string]string { | |||
res := map[string]string{} | |||
cacheKey := fmt.Sprintf(md.AppCfgCacheKey, masterId) | |||
err := cache.GetJson(cacheKey, &res) | |||
if err != nil || len(res) == 0 { | |||
cfgList, _ := SysCfgGetAll(eg) | |||
if cfgList == nil { | |||
return nil | |||
} | |||
for _, v := range *cfgList { | |||
res[v.Key] = v.Val | |||
} | |||
cache.SetJson(cacheKey, res, md.CfgCacheTime) | |||
} | |||
if len(keys) == 0 { | |||
return res | |||
} | |||
tmp := map[string]string{} | |||
for _, v := range keys { | |||
if val, ok := res[v]; ok { | |||
tmp[v] = val | |||
} else { | |||
tmp[v] = "" | |||
} | |||
} | |||
return tmp | |||
} |
@@ -0,0 +1,39 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"errors" | |||
"xorm.io/xorm" | |||
) | |||
// InertSysPushAppOne is 插入一条记录在 表sys_push_app | |||
func InertSysPushAppOne(Db *xorm.Engine, m *model.SysPushApp) (int64, error) { | |||
affect, err := Db.InsertOne(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affect, nil | |||
} | |||
//UpdateSysPushApp is 更新某条记录 | |||
func UpdateSysPushApp(Db *xorm.Engine, m *model.SysPushApp) (int64, error) { | |||
affect, err := Db.ID(m.Id).Update(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affect, nil | |||
} | |||
//SysPushAppByID is 根据id 获取对应的推送信息 | |||
func SysPushAppByID(Db *xorm.Engine, id interface{}) (*model.SysPushApp, error) { | |||
m := new(model.SysPushApp) | |||
has, err := Db.ID(id).Get(m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !has { | |||
return nil, errors.New("Not Found") | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,21 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"errors" | |||
"xorm.io/xorm" | |||
) | |||
//SysPushTemplateByType is 根据类型 | |||
func SysPushTemplateByType(Db *xorm.Engine, t string) (*model.SysPushTemplate, error) { | |||
m := new(model.SysPushTemplate) | |||
has, err := Db.Where("type = ?", t).Get(m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !has { | |||
return nil, errors.New("Not Found") | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,94 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"github.com/gin-gonic/gin" | |||
"xorm.io/xorm" | |||
) | |||
// SysPushUserByUIDByTypeIn is 根据uid和类型获取对应的通知 | |||
func SysPushUserByUIDByTypeIn(c *gin.Context, Db *xorm.Engine, uid interface{}, limit int, start int, t ...interface{}) ([]*model.SysPushUser, error) { | |||
var m []*model.SysPushUser | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("uid = ?", uid).In("type", t...).Desc("time").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
mm, err := sysModFormat(c, m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.([]*model.SysPushUser), nil | |||
} | |||
if err := Db.Where("uid = ?", uid).In("type", t...).Limit(limit, start).Desc("time").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
mm, err := sysModFormat(c, m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.([]*model.SysPushUser), nil | |||
} | |||
//SysPushUserInTypeGET is In 查询 一个 | |||
func SysPushUserInTypeGET(c *gin.Context, Db *xorm.Engine, uid interface{}, ts ...interface{}) (*model.SysPushUser, error) { | |||
m := new(model.SysPushUser) | |||
has, err := Db.Where("uid = ?", uid).In("type", ts...).Desc("time").Get(m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !has { | |||
return nil, nil | |||
} | |||
mm, err := sysModFormat(c, m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.(*model.SysPushUser), nil | |||
} | |||
//SysPushUserInType is In 查询 | |||
func SysPushUserInType(c *gin.Context, Db *xorm.Engine, uid interface{}, ts ...interface{}) ([]*model.SysPushUser, error) { | |||
var m []*model.SysPushUser | |||
if err := Db.Where("uid = ?", uid).In("type", ts...).Desc("time").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
mm, err := sysModFormat(c, &m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.([]*model.SysPushUser), nil | |||
} | |||
//SysPushUserInTypeCount is In 查询 | |||
func SysPushUserInTypeCount(Db *xorm.Engine, uid interface{}, ts ...interface{}) (int64, error) { | |||
m := new(model.SysPushUser) | |||
count, err := Db.Where("uid = ? AND is_read = 0", uid).In("type", ts...).Count(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return count, nil | |||
} | |||
//SysPushUserInsertOne is 插入一条记录 | |||
func SysPushUserInsertOne(Db *xorm.Engine, m *model.SysPushUser) (int64, error) { | |||
affected, err := Db.InsertOne(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
//BatchUpdateSysPushUserRead is 批量更新某种类型的通知 | |||
func BatchUpdateSysPushUserRead(Db *xorm.Engine, uid, t interface{}) error { | |||
sql := "update sys_push_user set is_read = ? where uid = ? and type = ?" | |||
_, err := Db.Exec(sql, 1, uid, t) | |||
if err != nil { | |||
return logx.Warn(err) | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,26 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
//SysTmpFindByIsUseByType is find tmp by issystem | |||
func SysTmpFindByIsUseByType(Db *xorm.Engine, use, t, platform string) (*model.SysTemplate, error) { | |||
var m model.SysTemplate | |||
if has, err := Db.Where("is_use = ? AND type = ? AND platform = ?", use, t, platform). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
func SysTmpFindByID(Db *xorm.Engine, id int) (*model.SysTemplate, error) { | |||
var m model.SysTemplate | |||
if has, err := Db.Where("id = ?", id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} |
@@ -0,0 +1,298 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/logx" | |||
"fmt" | |||
"xorm.io/xorm" | |||
) | |||
// UserisExistByUsernameAndPassword is usernameAndPassword exist | |||
func UserisExistByUsernameAndPassword(Db *xorm.Engine, username string, password string) (bool, error) { | |||
has, err := Db.Where("username = ? AND password = ?", username, utils.Md5(password)).Exist(&model.User{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserisExistByMobile is exist | |||
func UserisExistByMobile(Db *xorm.Engine, n string) (bool, error) { | |||
has, err := Db.Where("phone = ?", n).Exist(&model.User{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserInByUIDByLevel is In查询 以及是否是有效用户 | |||
func UserInByUIDByLevel(Db *xorm.Engine, ids []int, levelID interface{}) (*[]model.User, error) { | |||
var m []model.User | |||
if err := Db.In("uid", ids).Where("level = ?", levelID). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserFindByMobile search user by mobile | |||
func UserFindByMobile(Db *xorm.Engine, mobile string) (*model.User, error) { | |||
var m model.User | |||
if has, err := Db.Where("(phone = ? OR uid = ?) AND delete_at = 0", mobile, mobile). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserFindExistByMobile search user by mobile | |||
func UserFindExistByMobile(Db *xorm.Engine, mobile string) (*model.User, bool, error) { | |||
var m model.User | |||
has, err := Db.Where("(phone = ? OR uid = ?) AND delete_at = 0", mobile, mobile).Get(&m) | |||
if err != nil { | |||
logx.Infof("UserFindExistByMobile err") | |||
return nil, false, logx.Warn(err) | |||
} | |||
return &m, has, nil | |||
} | |||
// UserFindByMobile search user by mobile | |||
func UserFindByMobileAll(Db *xorm.Engine, mobile string) (*model.User, error) { | |||
var m model.User | |||
if has, err := Db.Where("(phone = ? OR uid = ?)", mobile, mobile). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserGetByMobileIgnoreDelete search user by mobile ignore delete | |||
func UserGetByMobileIgnoreDelete(Db *xorm.Engine, mobile string) (*model.User, bool, error) { | |||
m := new(model.User) | |||
has, err := Db.Where("phone = ?", mobile).Get(m) | |||
if err != nil { | |||
return nil, false, logx.Warn(err) | |||
} | |||
return m, has, nil | |||
} | |||
// UsersFindByMobileLike search users by mobile | |||
func UsersFindByMobileLike(Db *xorm.Engine, mobile string) (*[]model.User, error) { | |||
var m []model.User | |||
if err := Db.Where("phone like ?", "%"+mobile+"%"). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersFindByNickNameLike search users by nickname | |||
func UsersFindByNickNameLike(Db *xorm.Engine, nickname string) (*[]model.User, error) { | |||
var m []model.User | |||
if err := Db.Where("nickname like ?", "%"+nickname+"%"). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UsersInByIds is 根据ids 查找users | |||
func UsersInByIds(Db *xorm.Engine, ids []int, limit, start int) (*[]model.User, error) { | |||
var m []model.User | |||
if limit == 0 && start == 0 { | |||
if err := Db.In("uid", ids). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.In("uid", ids).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UsersInByIdsWhereLv is 根据ids和 lv会员等级 查找users | |||
func UsersInByIdsWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, start int) (*[]model.User, error) { | |||
var m []model.User | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("level = ?", lv).In("uid", ids). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("level = ?", lv).In("uid", ids).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UsersInByIdsByAscWhereLv is 根据ids和 lv会员等级 查找users 升排序 | |||
func UsersInByIdsByAscWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, start int, c string) (*[]model.User, error) { | |||
var m []model.User | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("level = ?", lv).In("uid", ids).Asc(c). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("level = ?", lv).In("uid", ids).Asc(c).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UsersInByIdsByDescWhereLv is 根据ids和 lv会员等级 查找users 降排序 | |||
func UsersInByIdsByDescWhereLv(Db *xorm.Engine, ids []int, lv interface{}, limit, start int, c string) (*[]model.User, error) { | |||
var m []model.User | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("level = ?", lv).In("uid", ids).Desc(c). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("level = ?", lv).In("uid", ids).Desc(c).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserFindByArkidUserName search user by mobile | |||
func UserFindByArkidUserName(Db *xorm.Engine, name string) (*model.User, error) { | |||
var m model.User | |||
if has, err := Db.Where("username = ?", name). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserFindByID is find user byid | |||
func UserFindByID(Db *xorm.Engine, id interface{}) (*model.User, error) { | |||
var m model.User | |||
if has, err := Db.Where("uid = ?", id). | |||
Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
func UserFindByIDs(Db *xorm.Engine, uids []int) (*[]model.User, error) { | |||
var m []model.User | |||
if err := Db.In("uid", uids).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersInByIdsByDesc is 根据某列 降序 | |||
func UsersInByIdsByDesc(Db *xorm.Engine, ids []int, limit, start int, c string) (*[]model.User, error) { | |||
var m []model.User | |||
if limit == 0 && start == 0 { | |||
if err := Db.In("uid", ids).Desc(c). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.In("uid", ids).Desc(c).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersInByIdsByAsc is 根据某列 升序 | |||
func UsersInByIdsByAsc(Db *xorm.Engine, ids []int, limit, start int, c string) (*[]model.User, error) { | |||
var m []model.User | |||
if limit == 0 && start == 0 { | |||
if err := Db.In("uid", ids).Asc(c). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.In("uid", ids).Asc(c).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserInsert is insert user | |||
func UserInsert(Db *xorm.Engine, user *model.User) (int64, error) { | |||
affected, err := Db.Insert(user) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
// UserIsExistByMobile is mobile exist | |||
func UserIsExistByMobile(Db *xorm.Engine, mobile string) (bool, error) { | |||
//fmt.Println(mobile) | |||
has, err := Db.Where("phone = ? OR uid = ?", mobile, mobile).Exist(&model.User{}) | |||
fmt.Println(has, mobile) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserIsExistByID is mobile exist by id | |||
func UserIsExistByID(Db *xorm.Engine, id string) (bool, error) { | |||
has, err := Db.Where("uid = ?", id).Exist(&model.User{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserUpdate is update user | |||
func UserUpdate(Db *xorm.Engine, uid interface{}, user *model.User, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = Db.Where("uid=?", uid).Cols(forceColums...).Update(user) | |||
} else { | |||
affected, err = Db.Where("uid=?", uid).Update(user) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func UserUpdateWithSession(Db *xorm.Session, uid interface{}, user *model.User, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = Db.Where("uid=?", uid).Cols(forceColums...).Update(user) | |||
} else { | |||
affected, err = Db.Where("uid=?", uid).Update(user) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
// UserDelete is delete user | |||
func UserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
return Db.Where("uid = ?", uid).Delete(model.User{}) | |||
} |
@@ -0,0 +1,85 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// GetUserFav is 获取商品收藏 | |||
func GetUserFav(Db *xorm.Engine, uid, itemid interface{}) (*model.UserFavorite, error) { | |||
var m model.UserFavorite | |||
if has, err := Db.Where("uid = ? AND item_id = ?", uid, itemid).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//InsertUserFavOne is 插入一条收藏记录 | |||
func InsertUserFavOne(Db *xorm.Engine, m *model.UserFavorite) (int64, error) { | |||
affected, err := Db.InsertOne(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
//UserFavFindByProvider 根据提供商来筛选收藏的 | |||
func UserFavFindByProvider(Db *xorm.Engine, uid interface{}, provider string, limit, start int) ([]*model.UserFavorite, error) { | |||
var m []*model.UserFavorite | |||
var err error | |||
if provider == "all" { | |||
if limit == 0 && start == 0 { | |||
err = Db.Where("uid = ?", uid).Desc("create_at").Find(&m) | |||
} else { | |||
err = Db.Where("uid = ?", uid).Desc("create_at").Limit(limit, start).Find(&m) | |||
} | |||
} else { | |||
if limit == 0 && start == 0 { | |||
err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Find(&m) | |||
} else { | |||
err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Limit(limit, start).Find(&m) | |||
} | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
//UserFavFindSearchByTitle is 我的收藏搜索 | |||
func UserFavFindSearchByTitle(Db *xorm.Engine, uid interface{}, title string, limit, start int) ([]*model.UserFavorite, error) { | |||
var m []*model.UserFavorite | |||
var err error | |||
if limit == 0 && start == 0 { | |||
err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Find(&m) | |||
} else { | |||
err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Limit(limit, start).Find(&m) | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// UserFavDelete is 删除收藏夹 | |||
func UserFavDelete(Db *xorm.Engine, uid interface{}, itemIds []interface{}) (int64, error) { | |||
var m model.UserFavorite | |||
affect, err := Db.Where("uid = ?", uid).In("item_id", itemIds).Delete(&m) | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affect, nil | |||
} | |||
// UserFavDeleteByUserDelete is 删除用户时删除对应的收藏夹 | |||
func UserFavDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
var m model.UserFavorite | |||
affect, err := Db.Where("uid = ?", uid).Delete(&m) | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affect, nil | |||
} |
@@ -0,0 +1,71 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// GetFinUserFlowByID is 用户流水记录 | |||
func GetFinUserFlowByID(Db *xorm.Engine, id interface{}) (*model.FinUserFlow, error) { | |||
var m model.FinUserFlow | |||
if has, err := Db.Where("id = ?", id).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// GetFinUserFlowByID is 用户流水记录 | |||
func GetFinUserFlowByUIDANDOID(Db *xorm.Engine, types, uid, ordId string) (*model.FinUserFlow, error) { | |||
var m model.FinUserFlow | |||
if has, err := Db.Where("uid = ? and ord_id = ? and type = ?", uid, ordId, types).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//FinUserFlowInsertOne is 插入一条流水记录 | |||
func FinUserFlowInsertOne(Db *xorm.Engine, m *model.FinUserFlow) error { | |||
_, err := Db.InsertOne(m) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} | |||
// FinUserFlowByUID is 用户流水 | |||
func FinUserFlowInputByUID(Db *xorm.Engine, uid interface{}, time string, limit, start int) ([]*model.FinUserFlow, error) { | |||
var m []*model.FinUserFlow | |||
if err := Db.Where("uid = ? AND create_at like ?", uid, time+"%").In("type", "0").Desc("create_at").Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// FinUserFlowByUIDByOrderAction is 用户流水 by OrderAction | |||
func FinUserFlowInputByUIDByOrderActionByTime(Db *xorm.Engine, uid, oa interface{}, time string, limit, start int) ([]*model.FinUserFlow, error) { | |||
var m []*model.FinUserFlow | |||
if err := Db.Where("uid = ? AND ord_action = ? AND create_at like ?", uid, oa, time+"%").Desc("create_at").Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// FinUserFlowByUIDByOrderAction is 用户流水 by OrderAction | |||
func FinUserFlowInputByUIDByTypeByTime(Db *xorm.Engine, uid int, time string, limit, start int) ([]*model.FinUserFlow, error) { | |||
var m []*model.FinUserFlow | |||
if err := Db.Where("uid = ? AND type = 1 AND create_at like ?", uid, time+"%").Desc("create_at").Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// 在事务中使用,插入一条流水记录 | |||
func FinUserFlowInsertOneWithSession(session *xorm.Session, m *model.FinUserFlow) error { | |||
_, err := session.InsertOne(m) | |||
if err != nil { | |||
return err | |||
} | |||
return nil | |||
} |
@@ -0,0 +1,91 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// GetUserFootMark is 获取商品足迹 | |||
func GetUserFootMark(Db *xorm.Engine, uid, itemid interface{}) (*model.UserFootMark, error) { | |||
var m model.UserFootMark | |||
if has, err := Db.Where("uid = ? AND item_id = ?", uid, itemid).Get(&m); err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//InsertUserFavOne is 插入一条足迹记录 | |||
func InsertUserFootMarkOne(Db *xorm.Engine, m *model.UserFootMark) (int64, error) { | |||
affected, err := Db.InsertOne(m) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
// UpdateUserFootMarkOne is 更新一条足迹记录 | |||
func UpdateUserFootMarkOne(Db *xorm.Engine, m *model.UserFootMark) (int64, error) { | |||
row, err := Db.ID(m.Id).AllCols().Update(m) | |||
return row, err | |||
} | |||
//UserFootMarkFindByProvider 根据提供商来筛选足迹的 | |||
func UserFootMarkFindByProvider(Db *xorm.Engine, uid interface{}, provider string, limit, start int) ([]*model.UserFootMark, error) { | |||
var m []*model.UserFootMark | |||
var err error | |||
if provider == "all" { | |||
if limit == 0 && start == 0 { | |||
err = Db.Where("uid = ?", uid).Desc("create_at").Find(&m) | |||
} else { | |||
err = Db.Where("uid = ?", uid).Desc("create_at").Limit(limit, start).Find(&m) | |||
} | |||
} else { | |||
if limit == 0 && start == 0 { | |||
err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Find(&m) | |||
} else { | |||
err = Db.Where("uid = ? AND provider = ?", uid, provider).Desc("create_at").Limit(limit, start).Find(&m) | |||
} | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
//UserFootMarkFindSearchByTitle is 我的足迹搜索 | |||
func UserFootMarkFindSearchByTitle(Db *xorm.Engine, uid interface{}, title string, limit, start int) ([]*model.UserFootMark, error) { | |||
var m []*model.UserFootMark | |||
var err error | |||
if limit == 0 && start == 0 { | |||
err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Find(&m) | |||
} else { | |||
err = Db.Where("item_title like ?", "%"+title+"%").Desc("create_at").Limit(limit, start).Find(&m) | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// UserFootMarkDelete is 删除足迹夹 | |||
func UserFootMarkDelete(Db *xorm.Engine, uid interface{}, itemIds []interface{}) (int64, error) { | |||
var m model.UserFootMark | |||
affect, err := Db.Where("uid = ?", uid).In("item_id", itemIds).Delete(&m) | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affect, nil | |||
} | |||
// UserFootMarkDeleteByUserDelete is 删除用户时删除对应的足迹夹 | |||
func UserFootMarkDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
var m model.UserFootMark | |||
affect, err := Db.Where("uid = ?", uid).Delete(&m) | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affect, nil | |||
} |
@@ -0,0 +1,123 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"github.com/gin-gonic/gin" | |||
"xorm.io/xorm" | |||
) | |||
//UserLevelByID is 根据用户id 获取对应的等级信息 | |||
func UserLevelByID(Db *xorm.Engine, id interface{}) (*model.UserLevel, error) { | |||
m := new(model.UserLevel) | |||
has, err := Db.Where("id = ?", id).Get(m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
if !has { | |||
return nil, logx.Error("Not found") | |||
} | |||
return m, nil | |||
} | |||
//UserLevelTop is 查询最高的等级 | |||
func UserLevelTop(Db *xorm.Engine) (*model.UserLevel, error) { | |||
m := new(model.UserLevel) | |||
has, err := Db.OrderBy("level_weight DESC").Get(m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
if !has { | |||
return nil, logx.Error("Not found") | |||
} | |||
return m, nil | |||
} | |||
//UserLevelNext is 查询下一等级 | |||
func UserLevelNext(Db *xorm.Engine, curLevelWeight int) (*model.UserLevel, error) { | |||
m := new(model.UserLevel) | |||
has, err := Db.Where("level_weight > ?", curLevelWeight).OrderBy("level_weight ASC").Get(m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
if !has { | |||
return nil, logx.Error("Not found") | |||
} | |||
return m, nil | |||
} | |||
// UserLevelByWeight is 根据权重获取对应的等级 | |||
func UserLevelByWeight(Db *xorm.Engine, w interface{}) (*model.UserLevel, error) { | |||
m := new(model.UserLevel) | |||
has, err := Db.Where("level_weight = ?", w).Get(m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
if !has { | |||
return nil, logx.Warn("Not found") | |||
} | |||
return m, nil | |||
} | |||
//UserLevelInIDescByWeight is In 查询获取 权重最低 对应等级 | |||
func UserLevelInIDescByWeightLow(Db *xorm.Engine) ([]*model.UserLevel, error) { | |||
var ms []*model.UserLevel | |||
if err := Db.Asc("level_weight").Limit(1).Find(&ms); err != nil { | |||
return nil, err | |||
} | |||
return ms, nil | |||
} | |||
//UserLevelInIDescByWeight is In 查询获取对应等级 根据权重排序 | |||
func UserLevelInIDescByWeight(Db *xorm.Engine, ids []int) ([]*model.UserLevel, error) { | |||
var ms []*model.UserLevel | |||
if err := Db.In("id", ids).Desc("level_weight").Find(&ms); err != nil { | |||
return nil, err | |||
} | |||
return ms, nil | |||
} | |||
// UserLevlAll is 获取所有开启等级并且升序返回 | |||
func UserLevlAll(c *gin.Context, Db *xorm.Engine) ([]*model.UserLevel, error) { | |||
var m []*model.UserLevel | |||
err := Db.Where("is_use = ?", 1).Asc("level_weight").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.([]*model.UserLevel), nil | |||
} | |||
// UserLevlEgAll is 获取所有开启等级并且升序返回 | |||
func UserLevlEgAll(Db *xorm.Engine) ([]*model.UserLevel, error) { | |||
var m []*model.UserLevel | |||
err := Db.Where("is_use = ?", 1).Asc("level_weight").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// UserLevlAllByWeight is 获取所有等级并且权重升序返回 | |||
func UserLevlAllByWeight(c *gin.Context, Db *xorm.Engine) ([]*model.UserLevel, error) { | |||
var m []*model.UserLevel | |||
err := Db.Asc("level_weight").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
mm, err := sysModFormat(c, m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return mm.([]*model.UserLevel), nil | |||
} |
@@ -0,0 +1,72 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// 用户当前等级正在审核中的记录 | |||
func UserLevelAuditingFindByUidAndLevel(Db *xorm.Engine, uid int, levelId int) (*model.UserLevelAudit, error) { | |||
var m model.UserLevelAudit | |||
has, err := Db.Where("uid=? AND state=? AND current_level_id=?", uid, 1, levelId).Get(&m) | |||
if err != nil || !has { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// 用户正在审核中的记录 | |||
func UserLevelAuditingFindByUid(Db *xorm.Engine, uid int) (*model.UserLevelAudit, error) { | |||
var m model.UserLevelAudit | |||
has, err := Db.Where("uid=? AND state=?", uid, 1).Get(&m) | |||
if err != nil || !has { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// 插入一条记录 | |||
func UserLevelAuditInsertWithSession(Db *xorm.Session, data *model.UserLevelAudit) (int64, error) { | |||
affect, err := Db.Insert(data) | |||
if err != nil || affect != 1 { | |||
return 0, err | |||
} | |||
return affect, nil | |||
} | |||
func UserLevelAuditFindById(Db *xorm.Engine, id int) (*model.UserLevelAudit, error) { | |||
var m model.UserLevelAudit | |||
has, err := Db.Where("id=?", id).Get(&m) | |||
if err != nil || !has { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
func UserLevelAuditFindByIdAndUid(Db *xorm.Engine, id int, uid int) (*model.UserLevelAudit, error) { | |||
var m model.UserLevelAudit | |||
has, err := Db.Where("next_level_id=? AND uid=? AND state<>2", id, uid).Get(&m) | |||
if err != nil || !has { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
// 更新审核记录 | |||
func UserLevelAuditUpdateByIdWithSession(session *xorm.Session, id int, audit *model.UserLevelAudit, forceColumns ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColumns != nil { | |||
affected, err = session.Where("id=?", id).Cols(forceColumns...).Update(audit) | |||
} else { | |||
affected, err = session.Where("id=?", id).Update(audit) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} |
@@ -0,0 +1,145 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
// 获取对应等级未过期的付费订单 | |||
func UserLevelOrderListByUIDByLevelTypeByExpire(Db *xorm.Engine, uid, levelID interface{}) ([]*model.UserLevelOrd, error) { | |||
var m []*model.UserLevelOrd | |||
err := Db.Where("uid = ? AND level_id = ? AND state = ? ", uid, levelID, 1).Desc("expire_at").Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
// OrderListByPvdAndNoSettledWithPage is 查询未结算订单 | |||
func UserLevelOrderListByUIDByNoSettledWithPage(Db *xorm.Engine, page int) ([]*model.UserLevelOrd, error) { | |||
perPage := 100 | |||
startPlace := (page - 1) * perPage | |||
var o []*model.UserLevelOrd | |||
err := Db.Where("settle_at=?", 0).In("state", 1).Limit(perPage, startPlace).Find(&o) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return o, nil | |||
} | |||
// 获取一个订单 | |||
func UserLevelOrderById(Db *xorm.Engine, id string) (*model.UserLevelOrd, error) { | |||
var m *model.UserLevelOrd | |||
has, err := Db.Where("id = ? ", id).Get(&m) | |||
if err != nil || has == false { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
//UserLevelOrderListByUIDByLevelByDateTypeByExpire is 获取某用户某等级的订单,按照过期时间降序排序 | |||
func UserLevelOrderListByUIDByLevelByDateTypeByExpire(Db *xorm.Engine, uid, levelID, t interface{}) ([]*model.UserLevelOrd, error) { | |||
var m []*model.UserLevelOrd | |||
err := Db.Where("uid = ? AND level_id = ? AND date_type = ? AND state = ? ", uid, levelID, t, 1).Desc("expire_at").Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
//UserLevelOrderOneByUIDByLevelByDateTypeByExpire is 获取某用户某等级的订单,按照过期时间降序排序 | |||
func UserLevelOrderOneByUIDByLevelByDateTypeByExpire(Db *xorm.Engine, uid, levelID interface{}) ([]*model.UserLevelOrd, error) { | |||
var m []*model.UserLevelOrd | |||
err := Db.Where("uid = ? AND level_id = ? and state = 1", uid, levelID).Desc("expire_at").Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
//UserLevelOrdInsertOne is 插入一个 等级付费升级的订单 | |||
func UserLevelOrdInsertOne(Db *xorm.Engine, order *model.UserLevelOrd) (int64, error) { | |||
affect, err := Db.InsertOne(order) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affect, nil | |||
} | |||
//UserLevelOrdUpdateOne is 更新付费升级订单 | |||
func UserLevelOrdUpdateOne(Db *xorm.Engine, order *model.UserLevelOrd) (int64, error) { | |||
affect, err := Db.ID(order.Id).Update(order) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affect, nil | |||
} | |||
func UserLevelOrdUpdateOneWithSession(Db *xorm.Session, order *model.UserLevelOrd) (int64, error) { | |||
affect, err := Db.ID(order.Id).Update(order) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affect, nil | |||
} | |||
func UserLevelOrdFindOneByOid(Db *xorm.Engine, id int64) (*model.UserLevelOrd, error) { | |||
var m model.UserLevelOrd | |||
has, err := Db.Where("id=? AND state=?", id, 1).Get(&m) | |||
if err != nil || !has { | |||
return nil, err | |||
} | |||
return &m, nil | |||
} | |||
func UserLevelOrdFindByUidStateLevelAndNotExpire(Db *xorm.Engine, uid int, state int, level string) (*model.UserLevelOrd, error) { | |||
var m model.UserLevelOrd | |||
//过期时间还没到 或者是永久的订单 | |||
if has, err := Db.Where("uid = ? AND level_id = ? AND state = ? AND (expire_at>= ? OR date_type=4)", uid, level, state, time.Now().Unix()).Get(&m); !has || err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// 查询订单状态 | |||
func UserLevelOrdFindByID(Db *xorm.Engine, id int) (*model.UserLevelOrd, error) { | |||
var m model.UserLevelOrd | |||
if has, err := Db.Where("id = ?", id).Get(&m); !has || err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// 获取对应id订单 | |||
func UserLevelOrdFindByIDs(Db *xorm.Engine, ids []int) ([]*model.UserLevelOrd, error) { | |||
var m []*model.UserLevelOrd | |||
err := Db.In("id", ids).Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
//session事务修改订单 | |||
func UserLvUpOrderUpdateWithSession(session *xorm.Session, ordId int64, order *model.UserLevelOrd, forceCols ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceCols != nil { | |||
affected, err = session.Where("id=?", ordId).Cols(forceCols...).Update(order) | |||
} else { | |||
affected, err = session.Where("id=?", ordId).Update(order) | |||
} | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affected, nil | |||
} |
@@ -0,0 +1,39 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"errors" | |||
"xorm.io/xorm" | |||
) | |||
//UserLevelTaskInIDS is 根据ids 获取等级任务 | |||
func UserLevelTaskInIDS(Db *xorm.Engine, ids []int) ([]*model.UserLevelTask, error) { | |||
var m []*model.UserLevelTask | |||
if err := Db.In("level_id", ids).Asc("level_id").Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
//UserLevelTaskByID is 根据id 获取等级任务列表 | |||
func UserLevelTaskByID(Db *xorm.Engine, id interface{}) ([]*model.UserLevelTask, error) { | |||
var m []*model.UserLevelTask | |||
if err := Db.Where("level_id = ?", id).Find(&m); err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
//UserLevelTaskOneByID is 根据id 获取等级任务 | |||
func UserLevelTaskOneByID(Db *xorm.Engine, id interface{}) (*model.UserLevelTask, error) { | |||
m := new(model.UserLevelTask) | |||
has, err := Db.Where("id = ?", id).Get(m) | |||
//fmt.Println(m) | |||
if !has { | |||
return nil, errors.New("Not found") | |||
} | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,188 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
//UserNoticeByReceiverByTime is 获取改接收者的 | |||
func UserNoticeByReceiverByTime(Db *xorm.Engine, uid interface{}, sort string) (*[]model.UserNotice, error) { | |||
switch sort { | |||
case "desc": | |||
// 降序 | |||
var m []model.UserNotice | |||
err := Db.Where("receiver = ?", uid).Desc("create_at").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
case "asc": | |||
//升序 | |||
var m []model.UserNotice | |||
err := Db.Where("receiver = ?", uid).Asc("create_at").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
default: | |||
//默认 | |||
var m []model.UserNotice | |||
err := Db.Where("receiver = ?", uid).Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
} | |||
//UserNoticeByReceiverByTimeByType is 获取改接收者的By Type | |||
func UserNoticeByReceiverByTimeByType(Db *xorm.Engine, uid, t interface{}, sort string, limit, start int) (*[]model.UserNotice, error) { | |||
switch sort { | |||
case "desc": | |||
// 降序 | |||
var m []model.UserNotice | |||
if limit == 0 && start == 0 { | |||
err := Db.Where("receiver = ? AND type = ?", uid, t).Desc("create_at").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
err := Db.Where("receiver = ? AND type = ?", uid, t).Desc("create_at").Limit(limit, start).Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
case "asc": | |||
//升序 | |||
var m []model.UserNotice | |||
if limit == 0 && start == 0 { | |||
err := Db.Where("receiver = ? AND type = ?", uid, t).Asc("create_at").Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
err := Db.Where("receiver = ? AND type = ?", uid, t).Asc("create_at").Limit(limit, start).Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
default: | |||
//默认 | |||
var m []model.UserNotice | |||
if limit == 0 && start == 0 { | |||
err := Db.Where("receiver = ? AND type = ?", uid).Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
err := Db.Where("receiver = ? AND type = ?", uid, t).Limit(limit, start).Find(&m) | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
} | |||
//GetUserNoticeByReceiverByTimeByType is 获取改接收者的By Type | |||
func GetUserNoticeByReceiverByTimeByType(Db *xorm.Engine, uid, t interface{}, sort string) (*model.UserNotice, error) { | |||
var ( | |||
has bool | |||
err error | |||
) | |||
switch sort { | |||
case "desc": | |||
// 降序 | |||
var m model.UserNotice | |||
if t == 0 || t == 1 { | |||
// fmt.Println(t) | |||
has, err = Db.Where("receiver = '0' AND type = ?", t).Desc("create_at").Get(&m) | |||
} else { | |||
has, err = Db.Where("receiver = ? AND type = ?", uid, t).Desc("create_at").Get(&m) | |||
} | |||
if !has { | |||
return &m, logx.Warn("Not found") | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
case "asc": | |||
//升序 | |||
var m model.UserNotice | |||
if t == 0 || t == 1 { | |||
has, err = Db.Where("receiver = '0' AND type = ?", t).Asc("create_at").Get(&m) | |||
} else { | |||
has, err = Db.Where("receiver = ? AND type = ?", uid, t).Asc("create_at").Get(&m) | |||
} | |||
if !has { | |||
return &m, logx.Warn("Not found") | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
default: | |||
//默认 | |||
var m model.UserNotice | |||
if t == 0 || t == 1 { | |||
// fmt.Println(t) | |||
has, err = Db.Where("receiver = '0' AND type = ?", t).Get(&m) | |||
} else { | |||
has, err = Db.Where("receiver = ? AND type = ?", uid, t).Get(&m) | |||
} | |||
if !has { | |||
return &m, logx.Warn("Not found") | |||
} | |||
if err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
} | |||
//GetUserUnReadCountByType is 获取 | |||
func GetUserUnReadCountByType(Db *xorm.Engine, id, t interface{}) (int64, error) { | |||
var ( | |||
count int64 | |||
err error | |||
) | |||
n := new(model.UserNotice) | |||
if t == 0 || t == 1 { | |||
count, err = Db.Where("receiver = '0' AND type = ? AND status = '0'", t).Count(n) | |||
} else { | |||
count, err = Db.Where("receiver = ? AND type = ? AND status = '0'", id, t).Count(n) | |||
} | |||
if err != nil { | |||
return 0, nil | |||
} | |||
return count, nil | |||
} | |||
//BatchUpdateUserNoticeRead is 批量更新某种类型的通知 | |||
func BatchUpdateUserNoticeRead(Db *xorm.Engine, uid, t interface{}) error { | |||
sql := "update user_notice set status = ? where receiver = ? and type = ?" | |||
_, err := Db.Exec(sql, 1, uid, t) | |||
if err != nil { | |||
return logx.Warn(err) | |||
} | |||
return nil | |||
} | |||
//UserNoticeInsertOne 插入一条通知数据 | |||
func UserNoticeInsertOne(Db *xorm.Engine, m *model.UserNotice) error { | |||
_, err := Db.InsertOne(m) | |||
if err != nil { | |||
return logx.Warn(err) | |||
} | |||
return nil | |||
} | |||
//UserNoticeDeleteByUserDelete is 删除用户通知 | |||
func UserNoticeDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
return Db.Where("receiver = ? OR sender = ?", uid, uid).Delete(model.UserNotice{}) | |||
} |
@@ -0,0 +1,438 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils/logx" | |||
"errors" | |||
"xorm.io/xorm" | |||
) | |||
//UserProfileFindByArkID is get userprofile by arkid | |||
func UserProfileFindByArkID(Db *xorm.Engine, id interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("arkid_uid = ?", id).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserProfileFindByInviteCode is get userprofile by InviteCode | |||
func UserProfileFindByInviteCode(Db *xorm.Engine, code string) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("invite_code = ?", code).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserProfileFindByInviteCode is get userprofile by InviteCode | |||
func UserProfileFindByCustomInviteCode(Db *xorm.Engine, code string) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("custom_invite_code = ?", code).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserProfileFindByInviteCodes is get userprofile by InviteCode | |||
func UserProfileFindByInviteCodes(Db *xorm.Engine, codes ...string) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := Db.In("invite_code", codes).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserProfileFindByCustomInviteCodes is get userprofile by CustomInviteCode | |||
func UserProfileFindByCustomInviteCodes(Db *xorm.Engine, codes ...string) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := Db.In("custom_invite_code", codes).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByID search user_profile by userid | |||
func UserProfileFindByID(Db *xorm.Engine, id interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("uid = ?", id).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileOrderByNew 找最新的记录 | |||
func UserProfileOrderByNew(Db *xorm.Engine) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("invite_code != ''").OrderBy("uid desc").Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByTaobaoOpenID search user_profile ByTaobaoOpenID | |||
func UserProfileFindByTaobaoOpenID(Db *xorm.Engine, openid interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("third_party_taobao_oid = ?", openid).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByQQOpenID search user_profile ByTaobaoOpenID | |||
func UserProfileFindByQQOpenID(Db *xorm.Engine, openid interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("third_party_qq_openid = ?", openid).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByAppleToken search user_profile AppleToken | |||
func UserProfileFindByAppleToken(Db *xorm.Engine, token interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("third_party_apple_token = ?", token).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByWeChatOpenID search user_profile By 微信openid | |||
func UserProfileFindByWeChatOpenID(Db *xorm.Engine, openid interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("third_party_wechat_openid = ?", openid).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByWeChatMiniOpenID search user_profile By 小程序openid | |||
func UserProfileFindByWeChatMiniOpenID(Db *xorm.Engine, openid interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("third_party_wechat_mini_openid = ?", openid).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileFindByWeChatUnionID search user_profile By 微信唯一id | |||
func UserProfileFindByWeChatUnionID(Db *xorm.Engine, openid interface{}) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := Db.Where("third_party_wechat_unionid = ?", openid).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileisExistByTaobaoOpenID is exist by Taobao | |||
func UserProfileisExistByTaobaoOpenID(Db *xorm.Engine, openid string) (bool, error) { | |||
has, err := Db.Where("third_party_taobao_oid = ?", openid).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistByQQOpenID is exist by QQ openid | |||
func UserProfileisExistByQQOpenID(Db *xorm.Engine, openid string) (bool, error) { | |||
has, err := Db.Where("third_party_qq_openid = ?", openid).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistByAppleToken is exist by apple token | |||
func UserProfileisExistByAppleToken(Db *xorm.Engine, token string) (bool, error) { | |||
has, err := Db.Where("third_party_apple_token = ?", token).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistByWeChatOpenID is exist by Wecaht openid | |||
func UserProfileisExistByWeChatOpenID(Db *xorm.Engine, openid string) (bool, error) { | |||
has, err := Db.Where("third_party_wechat_openid = ?", openid).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistByWeChatMiniOpenID is exist by Wecaht openid | |||
func UserProfileisExistByWeChatMiniOpenID(Db *xorm.Engine, openid string) (bool, error) { | |||
has, err := Db.Where("third_party_wechat_mini_openid = ?", openid).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistByWeChatUnionID is exist by Wecaht openid | |||
func UserProfileisExistByWeChatUnionID(Db *xorm.Engine, openid string) (bool, error) { | |||
has, err := Db.Where("third_party_wechat_unionid = ?", openid).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistByRelationIDAndSpecialID is exist by RelationIdAndSpecialId | |||
func UserProfileisExistByRelationIDAndSpecialID(Db *xorm.Engine, SpecialID, RelationID int64) (bool, error) { | |||
has, err := Db.Where("acc_taobao_self_id = ? AND acc_taobao_share_id = ?", SpecialID, RelationID).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileisExistBySpecialID is exist by SpecialId | |||
func UserProfileisExistBySpecialID(Db *xorm.Engine, SpecialID string) (bool, error) { | |||
has, err := Db.Where("acc_taobao_self_id = ? ", SpecialID).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileCountByRelationID 统计relationID数量 | |||
func UserProfileCountByRelationID(Db *xorm.Engine) (total int64, err error) { | |||
relate := new(model.UserProfile) | |||
total, err = Db.Where("acc_taobao_share_id > 0").Count(relate) | |||
return | |||
} | |||
// UserProfileCountByPUID 统计直推下级数量 | |||
func UserProfileCountByPUID(Db *xorm.Engine, puid int) (total int64, err error) { | |||
relate := new(model.UserProfile) | |||
total, err = Db.Where("parent_uid = ?", puid).Count(relate) | |||
return | |||
} | |||
// UserProfileisExistByRelationID is exist by RelationID | |||
func UserProfileisExistByRelationID(Db *xorm.Engine, RelationID string) (bool, error) { | |||
has, err := Db.Where("acc_taobao_share_id = ? ", RelationID).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileFindByIDs is in sql by ids | |||
func UserProfileFindByIDs(Db *xorm.Engine, uids ...int) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := Db.In("uid", uids).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileByPuid search user_profile by parent_uid | |||
func UserProfileByPuid(Db *xorm.Engine, puid interface{}) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := Db.Where("parent_uid = ?", puid).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UsersProfileInByIds is profiles by ids | |||
func UsersProfileInByIds(Db *xorm.Engine, ids []int, limit, start int) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if limit == 0 && start == 0 { | |||
if err := Db.In("uid", ids).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.In("uid", ids).Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersProfileInByUIDByisVerify is In查询 以及是否是有效用户 | |||
func UsersProfileInByUIDByisVerify(Db *xorm.Engine, ids []int, isVerify interface{}) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := Db.In("uid", ids).Where("is_verify = ?", isVerify). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersProfileInByIdsByDesc is 根据某列 降序 | |||
func UsersProfileInByIdsByDesc(Db *xorm.Engine, ids []int, limit, start int, c string) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if limit == 0 && start == 0 { | |||
if err := Db.In("uid", ids).Desc(c).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.In("uid", ids).Desc(c).Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersProfileInByIdsByAsc is 根据某列 升序 | |||
func UsersProfileInByIdsByAsc(Db *xorm.Engine, ids []int, limit, start int, c string) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if limit == 0 && start == 0 { | |||
if err := Db.In("uid", ids).Asc(c).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.In("uid", ids).Asc(c).Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UsersProfileByAll is 查询所有分享id大于0的数据 | |||
func UsersProfileByTaobaoShateIdNotNull(Db *xorm.Engine, limit, start int) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := Db.Where("acc_taobao_share_id > 0").Limit(limit, start).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserProfileIsExistByUserID is mobile exist | |||
func UserProfileIsExistByUserID(Db *xorm.Engine, id int) (bool, error) { | |||
has, err := Db.Where("uid = ?", id).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileIsExistByInviteCode is exist ? | |||
func UserProfileIsExistByInviteCode(Db *xorm.Engine, code string) (bool, error) { | |||
has, err := Db.Where("invite_code = ?", code).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
// UserProfileIsExistByCustomInviteCode is exist ? | |||
func UserProfileIsExistByCustomInviteCode(Db *xorm.Engine, code string) (bool, error) { | |||
has, err := Db.Where("custom_invite_code = ?", code).Exist(&model.UserProfile{}) | |||
if err != nil { | |||
return false, err | |||
} | |||
return has, nil | |||
} | |||
//UserProfileInsert is insert user | |||
func UserProfileInsert(Db *xorm.Engine, userProfile *model.UserProfile) (int64, error) { | |||
affected, err := Db.Insert(userProfile) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
//UserProfileUpdate is update userprofile | |||
func UserProfileUpdate(Db *xorm.Engine, uid interface{}, userProfile *model.UserProfile, forceCols ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceCols != nil { | |||
affected, err = Db.Where("uid=?", uid).Cols(forceCols...).Update(userProfile) | |||
} else { | |||
affected, err = Db.Where("uid=?", uid).Update(userProfile) | |||
} | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affected, nil | |||
} | |||
//UserProfileUpdateByArkID is update userprofile | |||
func UserProfileUpdateByArkID(Db *xorm.Engine, arkid interface{}, userProfile *model.UserProfile, forceCols ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceCols != nil { | |||
affected, err = Db.Where("arkid_uid=?", arkid).Cols(forceCols...).Update(userProfile) | |||
} else { | |||
affected, err = Db.Where("arkid_uid=?", arkid).Update(userProfile) | |||
} | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affected, nil | |||
} | |||
// UserProfileDelete is delete user profile | |||
func UserProfileDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
return Db.Where("uid = ?", uid).Delete(model.UserProfile{}) | |||
} | |||
func UserProfileFindByIdWithSession(session *xorm.Session, uid int) (*model.UserProfile, error) { | |||
var m model.UserProfile | |||
if has, err := session.Where("uid = ?", uid).Get(&m); err != nil || has == false { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// 在事务中更新用户信息 | |||
func UserProfileUpdateWithSession(session *xorm.Session, uid interface{}, userProfile *model.UserProfile, forceCols ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceCols != nil { | |||
affected, err = session.Where("uid=?", uid).Cols(forceCols...).Update(userProfile) | |||
} else { | |||
affected, err = session.Where("uid=?", uid).Update(userProfile) | |||
} | |||
if err != nil { | |||
return 0, logx.Warn(err) | |||
} | |||
return affected, nil | |||
} | |||
// 根据uid获取md.user | |||
func UserAllInfoByUid(Db *xorm.Engine, uid interface{}) (*md.User, error) { | |||
u, err := UserFindByID(Db, uid) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if u == nil { | |||
return nil, errors.New("user is nil") | |||
} | |||
up, err := UserProfileFindByID(Db, uid) | |||
if err != nil { | |||
return nil, err | |||
} | |||
// 获取user 等级 | |||
ul, err := UserLevelByID(Db, u.Level) | |||
if err != nil { | |||
return nil, err | |||
} | |||
user := &md.User{ | |||
Info: u, | |||
Profile: up, | |||
Level: ul, | |||
} | |||
return user, nil | |||
} |
@@ -0,0 +1,213 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
// UserRelateInsert is 插入一条数据到用户关系表 | |||
func UserRelateInsert(Db *xorm.Engine, userRelate *model.UserRelate) (int64, error) { | |||
affected, err := Db.Insert(userRelate) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
//UserRelateByPuid is 获取用户关系列表 by puid | |||
func UserRelatesByPuid(Db *xorm.Engine, puid interface{}, limit, start int) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("parent_uid = ?", puid). | |||
Cols(`id,parent_uid,uid,level,invite_time`). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("parent_uid = ?", puid). | |||
Cols(`id,parent_uid,uid,level,invite_time`).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserRelatesByPuidByLv is 获取用户关系列表 by puid 和lv | |||
func UserRelatesByPuidByLv(Db *xorm.Engine, puid, lv interface{}, limit, start int) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("parent_uid = ? AND level = ?", puid, lv). | |||
Cols(`id,parent_uid,uid,level,invite_time`). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("parent_uid = ? AND level = ?", puid, lv). | |||
Cols(`id,parent_uid,uid,level,invite_time`).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserRelatesByPuidByLvByTime is 获取直属 level =1用户关系列表 by puid 和lv by time | |||
func UserRelatesByPuidByLvByTime(Db *xorm.Engine, puid, lv, stime, etime interface{}, limit, start int) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("parent_uid = ? AND level = ? AND invite_time > ? AND invite_time < ?", puid, lv, stime, etime). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("parent_uid = ? AND level = ? AND invite_time > ? AND invite_time < ?", puid, lv, stime, etime). | |||
Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserRelatesByPuidByTime is 获取户关系列表 by puid 和lv by time | |||
func UserRelatesByPuidByTime(Db *xorm.Engine, puid, stime, etime interface{}, limit, start int) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("parent_uid = ? AND invite_time > ? AND invite_time < ?", puid, stime, etime). | |||
Cols(`id,parent_uid,uid,level,invite_time`). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("parent_uid = ? AND invite_time > ? AND invite_time < ?", puid, stime, etime). | |||
Cols(`id,parent_uid,uid,level,invite_time`).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserRelatesByPuidExceptLv is 获取用户关系列表 by puid 和非 lv | |||
func UserRelatesByPuidExceptLv(Db *xorm.Engine, puid, lv interface{}, limit, start int) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if limit == 0 && start == 0 { | |||
if err := Db.Where("parent_uid = ? AND level != ?", puid, lv). | |||
Cols(`id,parent_uid,uid,level,invite_time`). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
if err := Db.Where("parent_uid = ? AND level != ?", puid, lv). | |||
Cols(`id,parent_uid,uid,level,invite_time`).Limit(limit, start). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserRelateByUID is 获取用户关系表 by uid | |||
func UserRelateByUID(Db *xorm.Engine, uid interface{}) (*model.UserRelate, bool, error) { | |||
r := new(model.UserRelate) | |||
has, err := Db.Where("uid=?", uid).Get(r) | |||
if err != nil { | |||
return nil, false, err | |||
} | |||
return r, has, nil | |||
} | |||
//UserRelateByUIDByLv is 获取用户关系表 by uid | |||
func UserRelateByUIDByLv(Db *xorm.Engine, uid, lv interface{}) (*model.UserRelate, bool, error) { | |||
r := new(model.UserRelate) | |||
has, err := Db.Where("uid=? AND level=?", uid, lv).Get(r) | |||
if err != nil { | |||
return nil, false, err | |||
} | |||
return r, has, nil | |||
} | |||
//UserRelateByUIDAndPUID 根据 Puid 和uid 查找 ,用于确认关联 | |||
func UserRelateByUIDAndPUID(Db *xorm.Engine, uid, puid interface{}) (*model.UserRelate, bool, error) { | |||
r := new(model.UserRelate) | |||
has, err := Db.Where("uid=? AND parent_uid=?", uid, puid).Get(r) | |||
if err != nil { | |||
return nil, false, err | |||
} | |||
return r, has, nil | |||
} | |||
//UserRelatesByPuIDAndLv is 查询用户关系表 获取指定等级和puid的关系 | |||
func UserRelatesByPuIDAndLv(Db *xorm.Engine, puid, lv interface{}) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if err := Db.Where("parent_uid = ? AND level = ?", puid, lv). | |||
Cols(`id,parent_uid,uid,level,invite_time`). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserRelateInByUID is In查询 | |||
func UserRelateInByUID(Db *xorm.Engine, ids []int) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if err := Db.In("uid", ids). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
// UserRelatesByUIDDescLv is Where 查询 根据level 降序 | |||
func UserRelatesByUIDDescLv(Db *xorm.Engine, id interface{}) (*[]model.UserRelate, error) { | |||
var m []model.UserRelate | |||
if err := Db.Where("uid = ?", id).Desc("level"). | |||
Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
//UserRelateCountByPUID is 根据puid 计数 | |||
func UserRelateCountByPUID(Db *xorm.Engine, pid interface{}) (int64, error) { | |||
count, err := Db.Where("parent_uid = ?", pid).Count(model.UserRelate{}) | |||
if err != nil { | |||
return 0, nil | |||
} | |||
return count, nil | |||
} | |||
//UserRelateDelete is 删除关联他上级的关系记录,以及删除他下级的关联记录 | |||
func UserRelateDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
// 删除与之上级的记录 | |||
_, err := Db.Where("uid = ?", uid).Delete(model.UserRelate{}) | |||
if err != nil { | |||
return 0, err | |||
} | |||
// 删除与之下级的记录 | |||
_, err = Db.Where("parent_uid = ?", uid).Delete(model.UserRelate{}) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return 1, nil | |||
} | |||
//UserRelateDelete is 删除关联他上级的关系记录 | |||
func UserRelateExtendDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
// 删除与之上级的记录 | |||
_, err := Db.Where("uid = ?", uid).Delete(model.UserRelate{}) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return 1, nil | |||
} |
@@ -0,0 +1,25 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
"xorm.io/xorm" | |||
) | |||
//UserTagDeleteByUserDelete is 删除用户时删除用户标签 | |||
func UserTagDeleteByUserDelete(Db *xorm.Engine, uid interface{}) (int64, error) { | |||
return Db.Where("uid = ?", uid).Delete(model.UserTag{}) | |||
} | |||
func UserTagsByUid(Db *xorm.Engine, uid interface{}) ([]string, error) { | |||
var tagList []*model.UserTag | |||
if err := Db.Where("uid=?", uid).Cols("tag_name").Find(&tagList); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
var tags []string | |||
for _, item := range tagList { | |||
tags = append(tags, item.TagName) | |||
} | |||
return tags, nil | |||
} |
@@ -0,0 +1,35 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"xorm.io/xorm" | |||
) | |||
func GetUserVirtualAmountOne(session *xorm.Session, uid int, coinId int) (*model.UserVirtualAmount, error) { | |||
var m model.UserVirtualAmount | |||
isExist, err := session.Table("user_virtual_amount").Where("uid = ? AND coin_id = ?", uid, coinId).Get(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if !isExist { | |||
return nil, nil | |||
} | |||
return &m, nil | |||
} | |||
func GetUserVirtualAmountSum(eg *xorm.Engine, uid int, coinId int) (string, error) { | |||
//TODO 后面针对单个虚拟币 | |||
var m model.UserVirtualAmount | |||
sum, err := eg.Table("user_virtual_amount").Where("uid = ? ", uid).Sum(&m, "amount") | |||
if err != nil { | |||
return "0", err | |||
} | |||
return utils.Float64ToStr(sum), nil | |||
} | |||
/*func UserVirtualAmountUpdateWithSession(session *xorm.Session, m *model.UserVirtualAmount) bool { | |||
}*/ |
@@ -0,0 +1,63 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/md" | |||
"applet/app/utils/cache" | |||
"errors" | |||
"fmt" | |||
"xorm.io/xorm" | |||
) | |||
func GetVirtualCoinList(eg *xorm.Engine, masterId string) ([]*model.VirtualCoin, error) { | |||
var m []*model.VirtualCoin | |||
cacheKey := fmt.Sprintf(md.VirtualCoinCfgCacheKey, masterId) | |||
err := cache.GetJson(cacheKey, &m) | |||
if err != nil || len(m) == 0 { | |||
err := eg.Where("is_use=1").Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
cache.SetJson(cacheKey, m, md.CfgCacheTime) | |||
} | |||
return m, nil | |||
} | |||
// InsertUserVirtualFlow 插入一条虚拟币流水 | |||
func InsertUserVirtualFlow(eg *xorm.Engine, m model.UserVirtualCoinFlow) error { | |||
insert, err := eg.Insert(m) | |||
if err != nil { | |||
return err | |||
} | |||
if insert == 0 { | |||
return errors.New("插入虚拟币流水错误") | |||
} | |||
return nil | |||
} | |||
func InsertUserVirtualFlowWithSess(sess *xorm.Session, m model.UserVirtualCoinFlow) error { | |||
insert, err := sess.Insert(m) | |||
if err != nil { | |||
return err | |||
} | |||
if insert == 0 { | |||
return errors.New("插入虚拟币流水错误") | |||
} | |||
return nil | |||
} | |||
func GetBlockCoin(eg *xorm.Engine) (*model.VirtualCoin, error) { | |||
var m model.VirtualCoin | |||
get, err := eg.Where("is_block = 1").Get(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if get { | |||
return &m, nil | |||
} | |||
return nil, errors.New("查询有误!") | |||
} |
@@ -0,0 +1,16 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"xorm.io/xorm" | |||
) | |||
// 根据订单id查出相关的数据 | |||
func GetVirtualCoinRelateListWithOrdId(engine *xorm.Engine, ordId int64) ([]*model.VirtualCoinRelate, error) { | |||
var list []*model.VirtualCoinRelate | |||
err := engine.Table("virtual_coin_relate").Where("oid = ?", ordId).Find(&list) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return list, nil | |||
} |
@@ -0,0 +1,104 @@ | |||
package db | |||
import ( | |||
"fmt" | |||
"os" | |||
"time" | |||
"xorm.io/xorm" | |||
"xorm.io/xorm/log" | |||
"applet/app/cfg" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
var DBs map[string]*xorm.Engine | |||
// 每个站长都要有自己的syscfg 缓存, 键是站长id,值是缓存名 | |||
// var SysCfgMapKey map[string]string | |||
func NewDB(c *cfg.DBCfg) (*xorm.Engine, error) { | |||
db, err := xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", c.User, c.Psw, c.Host, c.Name)) | |||
if err != nil { | |||
return nil, err | |||
} | |||
db.SetConnMaxLifetime(c.MaxLifetime * time.Second) | |||
db.SetMaxOpenConns(c.MaxOpenConns) | |||
db.SetMaxIdleConns(c.MaxIdleConns) | |||
err = db.Ping() | |||
if err != nil { | |||
return nil, err | |||
} | |||
if c.ShowLog { | |||
db.ShowSQL(true) | |||
db.Logger().SetLevel(log.LOG_DEBUG) | |||
f, err := os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777) | |||
if err != nil { | |||
os.RemoveAll(c.Path) | |||
if f, err = os.OpenFile(c.Path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0777); err != nil { | |||
return nil, err | |||
} | |||
} | |||
logger := log.NewSimpleLogger(f) | |||
logger.ShowSQL(true) | |||
db.SetLogger(logger) | |||
} | |||
return db, nil | |||
} | |||
// InitDBs is 初始化多数据库 | |||
func InitDBs(ch chan int) { | |||
// 初始化多数据库 | |||
var tables *[]model.DbMapping | |||
InitMapDbs(cfg.DB, cfg.Prd) | |||
ch <- 1 | |||
// 每10s 查询一次模板数据库的db mapping 表,如果有新增数据库记录,则添加到 DBs中 | |||
ticker := time.NewTicker(time.Duration(time.Second * 120)) | |||
for range ticker.C { | |||
if cfg.Prd { | |||
tables = GetAllDatabasePrd() //默认获取全部 | |||
} else { | |||
tables = GetAllDatabaseDev() //默认获取全部 | |||
} | |||
if tables == nil { | |||
logx.Warn("no database tables data") | |||
continue | |||
} | |||
for _, item := range *tables { | |||
_, ok := DBs[item.DbMasterId] | |||
if !ok { | |||
// 不在db.DBs 则添加进去 | |||
dbCfg := cfg.DBCfg{ | |||
Name: item.DbName, | |||
ShowLog: cfg.DB.ShowLog, | |||
MaxLifetime: cfg.DB.MaxLifetime, | |||
MaxOpenConns: cfg.DB.MaxOpenConns, | |||
MaxIdleConns: cfg.DB.MaxIdleConns, | |||
Path: fmt.Sprintf(cfg.DB.Path, item.DbName), | |||
} | |||
if item.DbHost != "" && item.DbUsername != "" && item.DbPassword != "" { | |||
dbCfg.Host = item.DbHost | |||
dbCfg.User = item.DbUsername | |||
dbCfg.Psw = item.DbPassword | |||
} else { | |||
dbCfg.Host = cfg.DB.Host | |||
dbCfg.User = cfg.DB.User | |||
dbCfg.Psw = cfg.DB.Psw | |||
} | |||
e, err := NewDB(&dbCfg) | |||
if err != nil || e == nil { | |||
logx.Warnf("db engine can't create, please check config, params[host:%s, user:%s, psw: %s, name: %s], err: %v", dbCfg.Host, dbCfg.User, dbCfg.Psw, dbCfg.Name, err) | |||
} else { | |||
DBs[item.DbMasterId] = e | |||
} | |||
} | |||
// 如果 被禁用则删除 | |||
if item.DeletedAt == 1 { | |||
logx.Infof("%s have been removed", item.DbMasterId) | |||
delete(DBs, item.DbMasterId) | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
package db | |||
import ( | |||
"xorm.io/xorm" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
// 批量获取信息 | |||
func DbsDealOrderUseFindByIds(eg *xorm.Engine, types string, ids []string) (*[]model.DealOrderUser, error) { | |||
var ord []model.DealOrderUser | |||
if err := eg.In("id", ids). | |||
Where("type = ?", types). | |||
Find(&ord); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if len(ord) == 0 { | |||
return nil, nil | |||
} | |||
return &ord, nil | |||
} | |||
func DbsDealOrderUserUpdate(eg *xorm.Engine, id int, ord *model.DealOrderUser) error { | |||
if _, err := eg.Where(" `id` = ?", id).AllCols().Update(ord); err != nil { | |||
return logx.Warn(err) | |||
} | |||
return nil | |||
} | |||
func DbsDealOrderUserInsert(eg *xorm.Engine, ord *model.DealOrderUser) bool { | |||
_, err := eg.InsertOne(ord) | |||
if err != nil { | |||
logx.Warn(err) | |||
return false | |||
} | |||
return true | |||
} |
@@ -0,0 +1,194 @@ | |||
package db | |||
import ( | |||
"errors" | |||
"fmt" | |||
"xorm.io/xorm" | |||
"applet/app/cfg" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
func MapBaseExists() (bool, error) { | |||
return Db.IsTableExist("db_mapping") | |||
} | |||
func InitMapDbs(c *cfg.DBCfg, prd bool) { | |||
var tables *[]model.DbMapping | |||
exists, err := MapBaseExists() | |||
if !exists || err != nil { | |||
logx.Fatalf("db_mapping not exists : %v", err) | |||
} | |||
// tables := MapAllDatabases(debug) | |||
if prd { | |||
tables = GetAllDatabasePrd() //debug 获取生产 | |||
} else { | |||
tables = GetAllDatabaseDev() //debug 获取开发 | |||
} | |||
if tables == nil { | |||
logx.Fatal("no database tables data") | |||
} | |||
var e *xorm.Engine | |||
DBs = map[string]*xorm.Engine{} | |||
for _, v := range *tables { | |||
if v.DbName != "" && v.DeletedAt == 0 && v.DbName != c.Name { | |||
dbCfg := cfg.DBCfg{ | |||
Name: v.DbName, | |||
ShowLog: c.ShowLog, | |||
MaxLifetime: c.MaxLifetime, | |||
MaxOpenConns: c.MaxOpenConns, | |||
MaxIdleConns: c.MaxIdleConns, | |||
Path: fmt.Sprintf(c.Path, v.DbName), | |||
} | |||
if v.DbHost != "" && v.DbUsername != "" && v.DbPassword != "" { | |||
dbCfg.Host = v.DbHost | |||
dbCfg.User = v.DbUsername | |||
dbCfg.Psw = v.DbPassword | |||
} else { | |||
dbCfg.Host = c.Host | |||
dbCfg.User = c.User | |||
dbCfg.Psw = c.Psw | |||
} | |||
e, err = NewDB(&dbCfg) | |||
if err != nil || e == nil { | |||
logx.Warnf("db engine can't create, please check config, params[host:%s, user:%s, psw: %s, name: %s], err: %v", dbCfg.Host, dbCfg.User, dbCfg.Psw, dbCfg.Name, err) | |||
} else { | |||
DBs[v.DbMasterId] = e | |||
} | |||
} | |||
} | |||
} | |||
func MapAllDatabases(debug bool) *[]model.DbMapping { | |||
sql := "`db_name` != ?" | |||
if debug { | |||
sql = "`db_name` = ?" | |||
} | |||
var m []model.DbMapping | |||
if err := Db.Where(sql, cfg.DB.Name).Find(&m); err != nil || len(m) == 0 { | |||
logx.Warn(err) | |||
return nil | |||
} | |||
return &m | |||
} | |||
// GetAllDatabasePrd is 获取生成库 所有db 除了 deleted_at = 1 的 | |||
func GetAllDatabasePrd() *[]model.DbMapping { | |||
var m []model.DbMapping | |||
if err := Db.Where("deleted_at != ? AND is_dev = '0' ", 1).Find(&m); err != nil || len(m) == 0 { | |||
logx.Warn(err) | |||
return nil | |||
} | |||
return &m | |||
} | |||
// GetAllDatabaseDev is 获取开发库 所有db 除了 deleted_at = 1 的 | |||
func GetAllDatabaseDev() *[]model.DbMapping { | |||
var m []model.DbMapping | |||
var err error | |||
fmt.Println("cfg.Local is: ", cfg.Local) | |||
if cfg.Local { // 本地调试 加快速度 | |||
fmt.Println("notice:LOCAL TEST, only masterId:** 123456 ** available!") | |||
err = Db.Where("deleted_at != ? AND is_dev = '1' AND db_master_id=?", 1, 123456).Find(&m) | |||
} else { | |||
err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m) | |||
} | |||
//err := Db.Where("deleted_at != ? AND is_dev = '1' and db_master_id='123456'", 1).Find(&m) | |||
if err != nil || len(m) == 0 { | |||
logx.Warn(err) | |||
return nil | |||
} | |||
return &m | |||
} | |||
//GetDatabaseByMasterID is 根据站长id 获取对应的的数据库信息 | |||
func GetDatabaseByMasterID(Db *xorm.Engine, id string) (*model.DbMapping, error) { | |||
var m model.DbMapping | |||
has, err := Db.Where("db_master_id=?", id).Get(&m) | |||
if !has { | |||
return nil, errors.New("Not Found DB data by " + id) | |||
} | |||
if err != nil { | |||
return nil, err | |||
} | |||
if m.DbHost == "" { | |||
m.DbHost = cfg.DB.Host | |||
m.DbUsername = cfg.DB.User | |||
m.DbPassword = cfg.DB.Psw | |||
} | |||
return &m, nil | |||
} | |||
//SessionGetDatabaseByMasterID is 根据站长id 获取对应的的数据库信息 | |||
func SessionGetDatabaseByMasterID(Db *xorm.Session, id string) (*model.DbMapping, error) { | |||
var m model.DbMapping | |||
has, err := Db.Where("db_master_id=?", id).Get(&m) | |||
if !has { | |||
return nil, errors.New("Not Found DB data by " + id) | |||
} | |||
if err != nil { | |||
return nil, err | |||
} | |||
if m.DbHost == "" { | |||
m.DbHost = cfg.DB.Host | |||
m.DbName = cfg.DB.Name | |||
m.DbUsername = cfg.DB.User | |||
m.DbPassword = cfg.DB.Psw | |||
} | |||
return &m, nil | |||
} | |||
// 获取自动任务队列 | |||
func MapCrontabCfg(eg *xorm.Engine) *[]model.SysCfg { | |||
var c []model.SysCfg | |||
// 数据库查询如果有下划线会认为是一个任意字符 | |||
if err := eg.Where("`key` LIKE 'mall_cron\\_%' AND val != ''").Cols("`key`,`val`").Find(&c); err != nil || len(c) == 0 { | |||
logx.Warn(err) | |||
return nil | |||
} | |||
return &c | |||
} | |||
// 获取官方域名 | |||
func GetOfficialDomainInfoByType(Db *xorm.Engine, masterId, key string) (string, error) { | |||
type SysCfg struct { | |||
K string | |||
V string | |||
Memo string | |||
} | |||
var domainBase SysCfg | |||
has, err := Db.Where("k=?", "domain_base").Get(&domainBase) | |||
if err != nil { | |||
return "", err | |||
} | |||
if has == false { | |||
return "", errors.New("can not find key by : domain_base") | |||
} | |||
if key == "wap" { | |||
return "h5." + masterId + "." + domainBase.V, nil | |||
} | |||
if key == "api" { | |||
var apiDomain SysCfg | |||
has, err = Db.Where("k=?", "domain_api_base").Get(&apiDomain) | |||
if err != nil { | |||
return "", err | |||
} | |||
if has == false { | |||
return "", errors.New("can not find key by : domain_api_base") | |||
} | |||
return apiDomain.V, nil | |||
} | |||
if key == "admin" { | |||
return "admin." + masterId + "." + domainBase.V, nil | |||
} | |||
// 默认返回H5的 | |||
return "h5." + masterId + "." + domainBase.V, nil | |||
} |
@@ -0,0 +1,30 @@ | |||
package db | |||
import ( | |||
"xorm.io/xorm" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
func DbsPlanCommissionById(eg *xorm.Engine, id int) (*model.PlanCommission, error) { | |||
var m model.PlanCommission | |||
if isGet, err := eg.Where("id = ?", id).Get(&m); err != nil || !isGet { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
func DbsPlanCommissionByIds(eg *xorm.Engine, ids ...int) []*model.PlanCommission { | |||
var m []*model.PlanCommission | |||
var err error | |||
if len(ids) > 0 { | |||
err = eg.In("id", ids).Find(&m) | |||
} else { | |||
err = eg.Find(&m) | |||
} | |||
if err != nil { | |||
return nil | |||
} | |||
return m | |||
} |
@@ -0,0 +1,51 @@ | |||
package db | |||
import ( | |||
"xorm.io/xorm" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
func DbsPlanRewardByPvd(eg *xorm.Engine, pvd string) (*model.PlanReward, error) { | |||
m := &model.PlanReward{} | |||
if isGet, err := eg.Where("pvd = ?", pvd).Get(m); err != nil || !isGet { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
func DbsPlanRewardByPvds(eg *xorm.Engine, pvds ...string) ([]*model.PlanReward, error) { | |||
var m []*model.PlanReward | |||
var err error | |||
if len(pvds) > 0 { | |||
err = eg.In("pvd", pvds).Find(&m) | |||
} else { | |||
err = eg.Find(&m) | |||
} | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} | |||
// 查询使用自动结算的平台 | |||
func DbsPlanRewardIsAutoSettle(eg *xorm.Engine) ([]*model.PlanReward, error) { | |||
var m []*model.PlanReward | |||
var err error | |||
if err = eg.In("pvd", "mall_goods", "mall_group_buy", "mall_goods_user_lv").Where(" settle_mode=? AND plan_settle_id<>?", 1, 0).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} | |||
// 查出开启的渠道 | |||
func DbsPlanRewardIsOpen(eg *xorm.Engine) ([]*model.PlanReward, error) { | |||
var m []*model.PlanReward | |||
var err error | |||
if err = eg.Where(" state=?", 1).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,17 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"xorm.io/xorm" | |||
) | |||
func PlanSettleListByIds(eg *xorm.Engine, ids []int) ([]*model.PlanSettle, error) { | |||
var m []*model.PlanSettle | |||
var err error | |||
err = eg.In("id", ids).Find(&m) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return m, nil | |||
} |
@@ -0,0 +1,55 @@ | |||
package db | |||
import ( | |||
"xorm.io/xorm" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
// 系统配置get | |||
func DbsSysCfgGetAll(eg *xorm.Engine) (*[]model.SysCfg, error) { | |||
var cfgList []model.SysCfg | |||
if err := eg.Cols("`key`,`val`").Find(&cfgList); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
// 获取一条记录 | |||
func DbsSysCfgGet(eg *xorm.Engine, key string) (*model.SysCfg, error) { | |||
var cfgList model.SysCfg | |||
if has, err := eg.Where("`key`=?", key).Get(&cfgList); err != nil || has == false { | |||
return nil, logx.Error(err) | |||
} | |||
return &cfgList, nil | |||
} | |||
func DbsSysCfgInsert(eg *xorm.Engine, key, val string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val} | |||
_, err := eg.Where("`key`=?", key).Cols("val,memo").Update(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
return true | |||
} | |||
func DbsSysCfgInserts(eg *xorm.Engine, key, val string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val} | |||
_, err := eg.InsertOne(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
return true | |||
} | |||
func DbsSysCfgUpdate(eg *xorm.Engine, key, val string) bool { | |||
cfg := model.SysCfg{Key: key, Val: val} | |||
_, err := eg.Where("`key`=?", key).Cols("val").Update(&cfg) | |||
if err != nil { | |||
logx.Error(err) | |||
return false | |||
} | |||
return true | |||
} |
@@ -0,0 +1,41 @@ | |||
package db | |||
import ( | |||
"xorm.io/xorm" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
func DbsUser(eg *xorm.Engine, uid int) (*[]model.UserRelate, error) { | |||
var userRelate []model.UserRelate | |||
if err := eg.Where("uid = ?", uid).Asc("level").Find(&userRelate); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if len(userRelate) == 0 { | |||
return nil, nil | |||
} | |||
return &userRelate, nil | |||
} | |||
func DbsUserFindByIds(eg *xorm.Engine, uid []int) (*[]model.User, error) { | |||
var users []model.User | |||
if err := eg.In("uid", uid).Asc("level").Find(&users); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if len(users) == 0 { | |||
return nil, nil | |||
} | |||
return &users, nil | |||
} | |||
func DbsUserRelate(eg *xorm.Engine, uid int) (*[]model.UserRelate, error) { | |||
var userRelate []model.UserRelate | |||
if err := eg.Where("uid = ?", uid).Asc("level").Find(&userRelate); err != nil { | |||
return nil, logx.Error(err) | |||
} | |||
if len(userRelate) == 0 { | |||
return nil, nil | |||
} | |||
return &userRelate, nil | |||
} |
@@ -0,0 +1,44 @@ | |||
package db | |||
import ( | |||
"xorm.io/xorm" | |||
"applet/app/db/model" | |||
"applet/app/utils/logx" | |||
) | |||
// UserProfileFindByIDs is in sql by ids | |||
func DbsUserProfileFindByIDs(eg *xorm.Engine, uids ...int) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
if err := eg.In("uid", uids).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
return &m, nil | |||
} | |||
func DbsUserProfileFindByIDsList(eg *xorm.Engine, uids []int) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
col := "uid" | |||
if err := eg.In(col, uids).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
if len(m) == 0 { | |||
return nil, nil | |||
} | |||
return &m, nil | |||
} | |||
func DbsUserProfileFindByTbPids(eg *xorm.Engine, pids []int64, isShare bool) (*[]model.UserProfile, error) { | |||
var m []model.UserProfile | |||
col := "acc_taobao_self_id" | |||
col_where := "acc_taobao_self_id>0" | |||
if isShare { | |||
col = "acc_taobao_share_id" | |||
col_where = "acc_taobao_share_id>0" | |||
} | |||
if err := eg.Where(col_where).In(col, pids).Find(&m); err != nil { | |||
return nil, logx.Warn(err) | |||
} | |||
if len(m) == 0 { | |||
return nil, nil | |||
} | |||
return &m, nil | |||
} |
@@ -0,0 +1,22 @@ | |||
package model | |||
type TKBrand struct { | |||
BrandId int `json:"brandId" xorm:"not null pk autoincr comment('品牌id') INT(10)"` //品牌ID | |||
BrandName string `json:"brandName" xorm:"not null default '' comment('品牌名称') VARCHAR(64)"` //品牌名称 | |||
BrandLogo string `json:"brandLogo" xorm:"not null default '' comment('品牌logo') VARCHAR(255)"` //品牌logo | |||
BrandEnglish string `json:"brandEnglish" xorm:"not null default '' comment('品牌英文名称') VARCHAR(255)"` //品牌英文名称 | |||
Name string `json:"name" xorm:"not null default '' comment('官方旗舰店旗舰店铺名称') VARCHAR(255)"` //官方旗舰店旗舰店铺名称 | |||
SellerId string `json:"sellerId" xorm:"not null default '' comment('店铺ID') VARCHAR(255)"` //店铺ID | |||
BrandScore int `json:"brandScore" xorm:"not null default '' comment('店铺评分') INT(10)"` //店铺评分 | |||
Location string `json:"location" xorm:"not null default '' comment('发源地') VARCHAR(255)"` //发源地 | |||
EstablishTime string `json:"establishTime" xorm:"not null default '' comment('创立时间') VARCHAR(255)"` //创立时间 | |||
BelongTo string `json:"belongTo" xorm:"not null default '' comment('所属公司') VARCHAR(255)"` //所属公司 | |||
Position string `json:"position" xorm:"not null default '' comment('品牌定位:1. 奢侈 2.轻奢 3.大众') VARCHAR(255)"` //品牌定位:1. 奢侈 2.轻奢 3.大众 | |||
Consumer string `json:"consumer" xorm:"not null default '' comment('品牌定位:1. 奢侈 2.轻奢 3.大众') VARCHAR(255)"` //消费群体 | |||
Label string `json:"Label" xorm:"not null default '' comment('标签') VARCHAR(255)"` //标签 | |||
SimpleLabel string `json:"simpleLabel" xorm:"not null default '' comment('一句话评价') VARCHAR(255)"` //一句话评价 | |||
Cids string `json:"cids" xorm:"not null default '' comment('主营类目(可能有多个主营类目,用逗号隔开)') VARCHAR(255)"` //主营类目(可能有多个主营类目,用逗号隔开) | |||
BrandDesc string `json:"brandDesc" xorm:"not null default '' comment('品牌介绍') VARCHAR(255)"` //品牌介绍 (2020.10.30更新字段) | |||
FansNum int `json:"fansNum" xorm:"not null default '' comment('粉丝数') INT(10)"` //粉丝数 (2020.10.30更新字段) | |||
Sales2h int `json:"sales2h" xorm:"not null default '' comment('近期销量') INT(10)"` //近期销量 (2020.10.30更新字段) | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type AcquisitionLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr comment('主键') BIGINT(10)"` | |||
ParentUid int `json:"parent_uid" xorm:"not null default 0 comment('上级会员ID') unique(idx_union_u_p_id) INT(20)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('关联UserID') unique(idx_union_u_p_id) INT(20)"` | |||
Level int `json:"level" xorm:"not null default 1 comment('推广等级(1直属,大于1非直属)') INT(10)"` | |||
InviteTime time.Time `json:"invite_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('邀请时间') TIMESTAMP"` | |||
State int `json:"state" xorm:"not null default 0 comment('0为未完成,1为已完成') TINYINT(1)"` | |||
CompleteCon string `json:"complete_con" xorm:"not null default '' VARCHAR(16)"` | |||
} |
@@ -0,0 +1,21 @@ | |||
package model | |||
type AcquisitionRewardLog struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Uid int `json:"uid" xorm:"not null default 0 INT(11)"` | |||
ToUid int `json:"to_uid" xorm:"not null default 0 comment('被邀请人uid') INT(11)"` | |||
Title string `json:"title" xorm:"not null comment('标题') VARCHAR(255)"` | |||
Source int `json:"source" xorm:"not null default 0 comment('1为直推奖励 | |||
2为间推奖励 | |||
3为额外奖励 | |||
4为榜单奖励 | |||
来源标识') TINYINT(4)"` | |||
SourceText string `json:"source_text" xorm:"not null default '' comment('来源text') VARCHAR(255)"` | |||
JobsTag int `json:"jobs_tag" xorm:"comment('任务标识,只有额外奖励有') TINYINT(1)"` | |||
Money string `json:"money" xorm:"not null default 0.00 comment('奖励金额') DECIMAL(10,2)"` | |||
CreatedAt int `json:"created_at" xorm:"not null comment('创建时间') INT(10)"` | |||
GivenAt int `json:"given_at" xorm:"comment('奖励发放时间') INT(10)"` | |||
State int `json:"state" xorm:"not null default 1 comment('发放状态 0未发放 1已发放') TINYINT(1)"` | |||
IsFrozen int `json:"is_frozen" xorm:"not null default 0 comment('冻结状态 0未冻结 1已冻结') TINYINT(1)"` | |||
UpdatedAt int `json:"updated_at" xorm:"comment('更新时间') INT(10)"` | |||
} |
@@ -0,0 +1,19 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type AdmList struct { | |||
AdmId int `json:"adm_id" xorm:"not null pk autoincr INT(10)"` | |||
AdmName string `json:"adm_name" xorm:"not null default '' comment('管理员名称') VARCHAR(64)"` | |||
AdmPsw string `json:"adm_psw" xorm:"not null default '' comment('密码') CHAR(32)"` | |||
Phone string `json:"phone" xorm:"not null default '' comment('手机号') VARCHAR(16)"` | |||
RoleId int `json:"role_id" xorm:"not null default 0 comment('0为超管,其它请参照角色表') TINYINT(3)"` | |||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1启用') TINYINT(1)"` | |||
Ip string `json:"ip" xorm:"not null default '' comment('最后登陆IP,如果与当前IP不一致,请强退') VARCHAR(15)"` | |||
Token string `json:"token" xorm:"not null default '' comment('最后登陆token') unique CHAR(40)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(200)"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
LatestLoginAt int `json:"latest_login_at" xorm:"not null default 0 comment('最新登陆时间,时间戳') INT(10)"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type AdmLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
AdmId int `json:"adm_id" xorm:"not null default 0 comment('管理员ID') INT(11)"` | |||
Ip string `json:"ip" xorm:"not null default '' comment('IP') VARCHAR(15)"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('登陆时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,16 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type AdmOpLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
AdmId int `json:"adm_id" xorm:"not null pk default 0 comment('管理员ID') INT(11)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('被操作人UID,如非操作用户信息,默认为0') INT(11)"` | |||
Perm string `json:"perm" xorm:"not null default '' comment('操作权限,敏感模块权限') VARCHAR(128)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('操作描述') VARCHAR(512)"` | |||
Ip string `json:"ip" xorm:"not null default '' comment('操作IP') VARCHAR(15)"` | |||
State int `json:"state" xorm:"not null default 1 comment('操作结果1成功,0失败') TINYINT(1)"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,16 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type AdmRole struct { | |||
RoleId int `json:"role_id" xorm:"not null pk comment('角色ID') INT(10)"` | |||
RoleName string `json:"role_name" xorm:"not null default '' comment('角色名称') VARCHAR(64)"` | |||
Perms string `json:"perms" xorm:"comment('权限列表') TEXT"` | |||
IsSuper int `json:"is_super" xorm:"not null default 0 comment('是否超管') TINYINT(1)"` | |||
State int `json:"state" xorm:"not null default 1 comment('0禁用,1启用') TINYINT(1)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(500)"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,10 @@ | |||
package model | |||
type AdmRolePerms struct { | |||
Id int `json:"id" xorm:"not null pk autoincr comment('ID') INT(10)"` | |||
Pid int `json:"pid" xorm:"not null comment('父ID') INT(10)"` | |||
Perm string `json:"perm" xorm:"not null default '' comment('权限匹配名') VARCHAR(128)"` | |||
PermName string `json:"perm_name" xorm:"not null default '' comment('后台显示名称') VARCHAR(64)"` | |||
Sort int `json:"sort" xorm:"not null default 0 comment('显示排序,越大越前') INT(11)"` | |||
State int `json:"state" xorm:"not null default 1 comment('是否开启') TINYINT(1)"` | |||
} |
@@ -0,0 +1,14 @@ | |||
package model | |||
type AppRelease struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Version string `json:"version" xorm:"not null default '' VARCHAR(255)"` | |||
Os int `json:"os" xorm:"comment('系统:1.Android;2.ios') TINYINT(1)"` | |||
Memo string `json:"memo" xorm:"TEXT"` | |||
Src string `json:"src" xorm:"VARCHAR(255)"` | |||
CreatedAt int `json:"created_at" xorm:"INT(11)"` | |||
State int `json:"state" xorm:"not null default 1 comment('版本状态:0关 1开') TINYINT(1)"` | |||
UpdateNotice int `json:"update_notice" xorm:"not null default 1 comment('更新提醒:0关 1开') TINYINT(1)"` | |||
YybUrl string `json:"yyb_url" xorm:"comment('应用宝url') VARCHAR(255)"` | |||
ForceUpdate int `json:"force_update" xorm:"comment('强制更新(安卓)') TINYINT(1)"` | |||
} |
@@ -0,0 +1,22 @@ | |||
package model | |||
type Article struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Pid int `json:"pid" xorm:"not null default 0 comment('一级分类,对应article_cate表parent_id=0的记录') INT(11)"` | |||
CateId int `json:"cate_id" xorm:"not null default 0 comment('分类ID') index INT(11)"` | |||
TypeId int `json:"type_id" xorm:"not null default 0 comment('类型,对应article_cate表pid=0的记录') index INT(11)"` | |||
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示:0不显示;1显示') TINYINT(1)"` | |||
CreatedAt int `json:"created_at" xorm:"comment('创建时间') INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"comment('更新时间') INT(11)"` | |||
Cover string `json:"cover" xorm:"comment('封面') VARCHAR(255)"` | |||
Tags string `json:"tags" xorm:"comment('标签') VARCHAR(2048)"` | |||
Content string `json:"content" xorm:"comment('内容') LONGTEXT"` | |||
Info string `json:"info" xorm:"comment('描述') LONGTEXT"` | |||
IsSelected int `json:"is_selected" xorm:"not null default 0 comment('是否精选') TINYINT(1)"` | |||
IsRecommend int `json:"is_recommend" xorm:"not null default 0 comment('是否推荐') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"` | |||
WatchCount int `json:"watch_count" xorm:"not null default 0 comment('观看人数') INT(11)"` | |||
LikeCount int `json:"like_count" xorm:"not null default 0 comment('喜爱人数') INT(11)"` | |||
ForwardCount int `json:"forward_count" xorm:"not null default 0 comment('转发人数') INT(11)"` | |||
} |
@@ -0,0 +1,10 @@ | |||
package model | |||
type ArticleCate struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Pid int `json:"pid" xorm:"default 0 comment('上级,0表示文章类型') INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
CreatedAt int `json:"created_at" xorm:"INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"INT(11)"` | |||
} |
@@ -0,0 +1,13 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type ArticleLikeLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
ArticleId int64 `json:"article_id" xorm:"not null default 0 comment('文章ID') unique(IDX_LOG) BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') unique(IDX_LOG) INT(10)"` | |||
//CreatedAt time.Time `json:"created_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` | |||
CreatedAt time.Time `json:"created_at" xorm:"created"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type ArticleWatchLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
ArticleId int64 `json:"article_id" xorm:"not null default 0 comment('文章ID') unique(IDX_LOG) BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') unique(IDX_LOG) INT(10)"` | |||
CreatedAt time.Time `json:"created_at" xorm:"created"` | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type BusinessCollegeOrd struct { | |||
Id int64 `json:"id" xorm:"pk comment('订单id') BIGINT(22)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('uid') INT(10)"` | |||
ModId int `json:"mod_id" xorm:"not null default 0 comment('模块ID') INT(10)"` | |||
PayAmount string `json:"pay_amount" xorm:"not null default 0 comment('付费金额') DECIMAL(2)"` | |||
PayChannel int `json:"pay_channel" xorm:"not null default 0 comment('1:支付宝,2:微信,3:余额') TINYINT(1)"` | |||
State int `json:"state" xorm:"not null default 0 comment('支付状态:0未支付1已支付') TINYINT(1)"` | |||
CreateAt time.Time `json:"create_at" xorm:"created"` | |||
} |
@@ -0,0 +1,18 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type CapitalPool struct { | |||
Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"` | |||
IsUse int `json:"is_use" xorm:"not null comment('是否开启(否:0;是:1)') TINYINT(1)"` | |||
IsAuto int `json:"is_auto" xorm:"not null default 0 comment('是否自动分红(否:0;是:1)') TINYINT(1)"` | |||
BonusType string `json:"bonus_type" xorm:"not null default '0' comment('分红类型(1佣金,2积分,3区块币)多个以逗号隔开') VARCHAR(255)"` | |||
BonusDateType int `json:"bonus_date_type" xorm:"not null default 0 comment('日期类型(1每天,2固定时间)') TINYINT(1)"` | |||
BonusTime string `json:"bonus_time" xorm:"default '0' comment('分红日期(1,15,30)多个日期已逗号分隔开;ps 只有日期类型是2才是有数据') VARCHAR(255)"` | |||
BonusLevelType int `json:"bonus_level_type" xorm:"not null default 0 comment('用户等级分红类型(1,指定等级,2大于或等于指定等级)') TINYINT(1)"` | |||
UserLevelGroup string `json:"user_level_group" xorm:"not null comment('指定用户等级组json') TEXT"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` | |||
UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
type ChannelActivity struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Img string `json:"img" xorm:"default '' comment('图片') VARCHAR(255)"` | |||
Sort int `json:"sort" xorm:"default 0 comment('排序') INT(5)"` | |||
IsUse int `json:"is_use" xorm:"default 0 comment('是否使用') INT(1)"` | |||
Source string `json:"source" xorm:"default '' comment('来源 淘宝=>tb 京东=>jd 拼多多=>pdd 唯品会=>wph 苏宁易购=>snyg 考拉=>kaola') VARCHAR(50)"` | |||
IsRecommend int `json:"is_recommend" xorm:"default 0 comment('是否官方推荐') INT(1)"` | |||
StartTime int `json:"start_time" xorm:"default 0 comment('开始时间') INT(11)"` | |||
EndTime int `json:"end_time" xorm:"default 0 comment('结束时间') INT(11)"` | |||
ActivityId string `json:"activity_id" xorm:"default '' comment('活动id') VARCHAR(100)"` | |||
Url string `json:"url" xorm:"comment('活动链接') TEXT"` | |||
Name string `json:"name" xorm:"default '' comment('名称') VARCHAR(255)"` | |||
} |
@@ -0,0 +1,7 @@ | |||
package model | |||
type City struct { | |||
Name string `json:"name" xorm:"VARCHAR(64)"` | |||
Id string `json:"id" xorm:"not null pk VARCHAR(12)"` | |||
ProvinceId string `json:"province_id" xorm:"index VARCHAR(12)"` | |||
} |
@@ -0,0 +1,17 @@ | |||
package model | |||
type CloudBundle struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Os int `json:"os" xorm:"not null default 1 comment('系统类型:1.Android; 2.IOS') TINYINT(1)"` | |||
Version string `json:"version" xorm:"not null default '' comment('版本号') VARCHAR(255)"` | |||
Modules string `json:"modules" xorm:"not null default '' comment('包含的模块') VARCHAR(255)"` | |||
ApplyAt int `json:"apply_at" xorm:"comment('申请时间') INT(11)"` | |||
FinishAt int `json:"finish_at" xorm:"comment('完成时间') INT(11)"` | |||
State int `json:"state" xorm:"not null default 1 comment('状态:正在排队0,正在同步代码1,正在更新配置2,正在混淆3,正在打包4,正在上传5,打包成功999,异常-1') SMALLINT(5)"` | |||
Memo string `json:"memo" xorm:"comment('备注') TEXT"` | |||
ErrorMsg string `json:"error_msg" xorm:"comment('错误信息') TEXT"` | |||
Src string `json:"src" xorm:"comment('包源地址') VARCHAR(255)"` | |||
BuildId string `json:"build_id" xorm:"comment('build版本ID') VARCHAR(255)"` | |||
BuildNumber string `json:"build_number" xorm:"default '' VARCHAR(255)"` | |||
TemplateDuringAudit string `json:"template_during_audit" xorm:"not null default '' VARCHAR(255)"` | |||
} |
@@ -0,0 +1,7 @@ | |||
package model | |||
type County struct { | |||
Name string `json:"name" xorm:"VARCHAR(64)"` | |||
Id string `json:"id" xorm:"not null pk VARCHAR(12)"` | |||
CityId string `json:"city_id" xorm:"index VARCHAR(12)"` | |||
} |
@@ -0,0 +1,18 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type DbMapping struct { | |||
DbMasterId string `json:"db_master_id" xorm:"not pk null comment('站长id') VARCHAR(32)"` | |||
DbHost string `json:"db_host" xorm:"not null default '' comment('数据库连接(带port)') VARCHAR(255)"` | |||
DbUsername string `json:"db_username" xorm:"not null default '' comment('数据库用户名') VARCHAR(255)"` | |||
DbPassword string `json:"db_password" xorm:"not null default '' comment('数据库用户名密码') VARCHAR(255)"` | |||
DbName string `json:"db_name" xorm:"not null comment('数据库名') VARCHAR(255)"` | |||
ExternalMysql string `json:"external_mysql" xorm:"not null default '0' comment('是否外部mysql(0是内部,1是外部)') VARCHAR(255)"` | |||
IsDev int `json:"is_dev" xorm:"not null default 0 comment('开发库是1,0是生产库') TINYINT(1)"` | |||
CreatedAt time.Time `json:"created_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdatedAt time.Time `json:"updated_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 comment('是否已删除') TINYINT(1)"` | |||
} |
@@ -0,0 +1,11 @@ | |||
package model | |||
type DealOrderUser struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Type string `json:"type" xorm:"default '' comment('类型 activity_order活动订单 oil_order加油订单') index VARCHAR(100)"` | |||
Uid int `json:"uid" xorm:"default 0 comment('用户id') index INT(11)"` | |||
Time int `json:"time" xorm:"default 0 comment('写入时间') index INT(11)"` | |||
EndTime int `json:"end_time" xorm:"default 0 comment('结束时间') index INT(11)"` | |||
RelationId int64 `json:"relation_id" xorm:"default 0 comment('渠道id') index BIGINT(12)"` | |||
Data string `json:"data" xorm:"comment('拓展用') TEXT"` | |||
} |
@@ -0,0 +1,22 @@ | |||
package model | |||
type DuomaiMallBrand struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
ThirdId int `json:"third_id" xorm:"not null default 0 comment('三方平台ID') INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('品牌名称') VARCHAR(255)"` | |||
SubName string `json:"sub_name" xorm:"not null default '' comment('品牌副标题') VARCHAR(255)"` | |||
Logo string `json:"logo" xorm:"not null default '' comment('品牌logo') VARCHAR(255)"` | |||
Url string `json:"url" xorm:"not null default '' comment('商城地址') VARCHAR(255)"` | |||
CommRate string `json:"comm_rate" xorm:"not null default '' comment('返利比例') VARCHAR(255)"` | |||
CateId int `json:"cate_id" xorm:"not null default 0 comment('分类ID') INT(11)"` | |||
Desc string `json:"desc" xorm:"not null comment('商城简介') TEXT"` | |||
Detail string `json:"detail" xorm:"not null comment('商城详情') TEXT"` | |||
Data string `json:"data" xorm:"not null comment('商城详情') TEXT"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"not null default 0 comment('排序') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
Tags string `json:"tags" xorm:"not null comment('标签,“,”号分割') TEXT"` | |||
CommList string `json:"comm_list" xorm:"comment('分佣列表') TEXT"` | |||
} |
@@ -0,0 +1,11 @@ | |||
package model | |||
type DuomaiMallBrandCate struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('分类名称') VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"default 0 comment('排序') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
} |
@@ -0,0 +1,10 @@ | |||
package model | |||
type FinSysLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
FromUid int `json:"from_uid" xorm:"not null default 0 comment('来自于用户') INT(11)"` | |||
FromSource int `json:"from_source" xorm:"not null default 0 comment('来源') TINYINT(4)"` | |||
Amount float32 `json:"amount" xorm:"not null default 0.0000 comment('金额') FLOAT(12,4)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(50)"` | |||
CreateAt int `json:"create_at" xorm:"not null default 0 comment('创建时间') INT(11)"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package model | |||
type FinUserCommissionLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null INT(10)"` | |||
Oid string `json:"oid" xorm:"not null default '' comment('订单ID') VARCHAR(50)"` | |||
OrderType int `json:"order_type" xorm:"not null default 0 comment('0自购,1分享') TINYINT(1)"` | |||
OrderProvider string `json:"order_provider" xorm:"not null default '' comment('订单供应商') VARCHAR(32)"` | |||
} |
@@ -0,0 +1,29 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type FinUserFlow struct { | |||
Id int64 `json:"id" xorm:"pk autoincr comment('流水编号') BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` | |||
Type int `json:"type" xorm:"not null default 0 comment('0收入,1支出') TINYINT(1)"` | |||
Amount string `json:"amount" xorm:"not null default 0.0000 comment('变动金额') DECIMAL(11,4)"` | |||
BeforeAmount string `json:"before_amount" xorm:"not null default 0.0000 comment('变动前金额') DECIMAL(11,4)"` | |||
AfterAmount string `json:"after_amount" xorm:"not null default 0.0000 comment('变动后金额') DECIMAL(11,4)"` | |||
SysFee string `json:"sys_fee" xorm:"not null default 0.0000 comment('手续费') DECIMAL(11,4)"` | |||
PaymentType int `json:"payment_type" xorm:"not null default 1 comment('1支付宝,2微信.3手动转账') TINYINT(1)"` | |||
OrdType string `json:"ord_type" xorm:"not null default '' comment('订单类型taobao,jd,pdd,vip,suning,kaola,own自营,withdraw提现') VARCHAR(20)"` | |||
OrdId string `json:"ord_id" xorm:"not null default '' comment('对应订单编号') VARCHAR(50)"` | |||
OrdTitle string `json:"ord_title" xorm:"not null default '' comment('订单标题') VARCHAR(50)"` | |||
OrdAction int `json:"ord_action" xorm:"not null default 0 comment('10自购,11推广,12团队,20提现,21消费') TINYINT(2)"` | |||
OrdTime int `json:"ord_time" xorm:"not null default 0 comment('下单时间or提现时间') INT(11)"` | |||
OrdDetail string `json:"ord_detail" xorm:"not null default '' comment('记录商品ID或提现账号') VARCHAR(50)"` | |||
ExpectedTime string `json:"expected_time" xorm:"not null default '0' comment('预期到账时间,字符串用于直接显示,结算后清除内容') VARCHAR(30)"` | |||
State int `json:"state" xorm:"not null default 1 comment('1未到账,2已到账') TINYINT(1)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(2000)"` | |||
OtherId int64 `json:"other_id" xorm:"not null default 0 comment('其他关联订单,具体根据订单类型判断') BIGINT(20)"` | |||
AliOrdId string `json:"ali_ord_id" xorm:"default '' comment('支付宝订单号') VARCHAR(128)"` | |||
CreateAt time.Time `json:"create_at" xorm:"created not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdateAt time.Time `json:"update_at" xorm:"updated not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,19 @@ | |||
package model | |||
type FinUserLog struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null comment('用户ID') INT(10)"` | |||
Type int `json:"type" xorm:"not null default 0 comment('0余额,1积分') TINYINT(1)"` | |||
FromType int `json:"from_type" xorm:"not null default 0 comment('来源类型:1,导购订单结算;2,拉新奖励;3,管理调整') TINYINT(3)"` | |||
ValidBefore float32 `json:"valid_before" xorm:"not null default 0.0000 comment('之前可用余额') FLOAT(10,4)"` | |||
ValidAfter float32 `json:"valid_after" xorm:"not null default 0.0000 comment('之后可用余额') FLOAT(10,4)"` | |||
ValidAlter float32 `json:"valid_alter" xorm:"not null default 0.0000 comment('变更金额') FLOAT(10,4)"` | |||
InvalidBefore float32 `json:"invalid_before" xorm:"not null default 0.0000 comment('之前冻结余额') FLOAT(10,4)"` | |||
InvalidAfter float32 `json:"invalid_after" xorm:"not null default 0.0000 comment('之后冻结余额') FLOAT(10,4)"` | |||
InvalidAlter float32 `json:"invalid_alter" xorm:"not null default 0.0000 comment('变更金额') FLOAT(10,4)"` | |||
SysCommission float32 `json:"sys_commission" xorm:"not null default 0.000000 comment('平台抽取手续费') FLOAT(12,6)"` | |||
Oid string `json:"oid" xorm:"not null default '' comment('关联订单ID') VARCHAR(50)"` | |||
Action string `json:"action" xorm:"not null default '' comment('操作行为,如:withdraw提现') VARCHAR(20)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(80)"` | |||
CreateAt int `json:"create_at" xorm:"not null default 0 comment('创建时间') INT(10)"` | |||
} |
@@ -0,0 +1,20 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type FinWithdrawApply struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') index INT(10)"` | |||
AdmId int `json:"adm_id" xorm:"not null default 0 comment('审核人ID,0为系统自动') INT(10)"` | |||
Amount string `json:"amount" xorm:"not null default 0.00 comment('提现金额') DECIMAL(10,2)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注,失败请备注原因') VARCHAR(500)"` | |||
Type int `json:"type" xorm:"not null default 1 comment('提现类型;1:手动;2:自动') TINYINT(1)"` | |||
WithdrawAccount string `json:"withdraw_account" xorm:"not null default '' comment('提现账号') VARCHAR(64)"` | |||
WithdrawName string `json:"withdraw_name" xorm:"not null default '' comment('提现人姓名') VARCHAR(12)"` | |||
Reason int `json:"reason" xorm:"not null default 0 comment('审核失败(驳回理由);1:当前账号不满足提现规则;2:账号异常;3:资金异常') TINYINT(1)"` | |||
CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('申请时间') TIMESTAMP"` | |||
UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('处理时间') TIMESTAMP"` | |||
State int `json:"state" xorm:"not null default 0 comment('0申请中,1通过,2完成,3失败') TINYINT(1)"` | |||
} |
@@ -0,0 +1,67 @@ | |||
package model | |||
import "time" | |||
//产品发布表 | |||
type GuideGoods struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
GoodsUrl string `json:"goodsUrl" xorm:"not null comment('传进来的商品链接') VARCHAR(50)"` | |||
ItemUrl string `json:"itemUrl" xorm:"not null default 0 comment('搜索出来的商品链接') VARCHAR(50)"` | |||
GoodsId string `json:"goodsId" xorm:"not null default 0 comment('商品id') VARCHAR(50)"` | |||
Provider string `json:"provider" xorm:"not null default 0 comment('渠道key') VARCHAR(50)"` | |||
ProviderName string `json:"providerName" xorm:"not null default 0.0000 comment('渠道') VARCHAR(50)"` | |||
ProviderImg string `json:"providerImg" xorm:"not null default 0 comment('渠道图片') VARCHAR(50)"` | |||
ProviderImgUrl string `json:"providerImgUrl" xorm:"not null default 0 comment('渠道图片Url') VARCHAR(50)"` | |||
GoodsTitle string `json:"goodsTitle" xorm:"not null default 0.0000 comment('商品标题') VARCHAR(50)"` | |||
GoodsPrice string `json:"goodsPrice" xorm:"not null default 1 comment('商品原价') VARCHAR(50)"` | |||
WlGoodsPrice string `json:"wlGoodsPrice" xorm:"not null default 1 comment('商品卷后价') VARCHAR(50)"` | |||
CouponPrice string `json:"couponPrice" xorm:"not null default 1 comment('优惠劵金额') VARCHAR(50)"` | |||
CouponUrl string `json:"couponUrl" xorm:"not null default 1 comment('优惠劵Url') VARCHAR(50)"` | |||
Category string `json:"category" xorm:"not null default 1 comment('分类') VARCHAR(50)"` | |||
CategoryName string `json:"categoryName" xorm:"not null default 1 comment('分类名') VARCHAR(50)"` | |||
InOrderCount string `json:"inOrderCount" xorm:"not null default 1 comment('销量') VARCHAR(50)"` | |||
GoodsDesc string `json:"goodsDesc" xorm:"not null default 0.0000 comment('商品描述') VARCHAR(50)"` | |||
GoodsContent string `json:"goodsContent" xorm:"not null default 0.0000 comment('商品文案(以json存)') VARCHAR(50)"` | |||
GoodsImg string `json:"goodsImg" xorm:"not null default 0.0000 comment('商品主图') VARCHAR(50)"` | |||
GoodsImgUrl string `json:"goodsImgUrl" xorm:"not null default 0.0000 comment('商品主图URL') VARCHAR(50)"` | |||
GoodsImgList string `json:"goodsImgList" xorm:"not null default 0.0000 comment('商品图片组(以json存)') VARCHAR(50)"` | |||
VideoUrl string `json:"videoUrl" xorm:"not null default 0.0000 comment('商品视频URL') VARCHAR(50)"` | |||
IsPutOn string `json:"isPutOn" xorm:"not null default 0 comment('是否上架;0:否;1:是') VARCHAR(50)"` | |||
PutOnAt time.Time `json:"putOnAt"xorm:"not null default 0 comment('创建时间') datetime"` | |||
PutDownAt time.Time `json:"putDownAt"xorm:"not null default 0 comment('创建时间') datetime"` | |||
CreateAt time.Time `xorm:"not null default 0 comment('创建时间') datetime"` | |||
UpdateAt time.Time `xorm:"not null default 0 comment('更新时间') datetime"` | |||
} | |||
//产品发布app端数据 | |||
type GuideGoodsApp struct { | |||
Id string `json:"id"` | |||
GoodsUrl string `json:"goods_url"` | |||
ItemURL string `json:"item_url"` | |||
GoodsId string `json:"goods_id"` | |||
Provider string `json:"provider"` | |||
ProviderName string `json:"provider_name"` | |||
ProviderImg string `json:"provider_img"` | |||
ProviderImgUrl string `json:"provider_img_url"` | |||
GoodsTitle string `json:"goods_title"` | |||
GoodsPrice string `json:"goods_price"` | |||
WlGoodsPrice string `json:"wl_goods_price"` | |||
CouponPrice string `json:"coupon_price"` | |||
CouponURL string `json:"coupon_url"` | |||
Category string `json:"category"` | |||
CategoryName string `json:"category_name"` | |||
InOrderCount string `json:"in_order_count"` | |||
GoodsDesc string `json:"goods_desc"` | |||
GoodsContent string `json:"goods_content"` | |||
GoodsImg string `json:"goods_img"` | |||
GoodsImgUrl string `json:"goods_img_url"` | |||
GoodsImgList string `json:"goods_img_list"` | |||
VideoUrl string `json:"video_url"` | |||
StateInfo string `json:"state_info"` | |||
IsPutOn string `json:"is_put_on"` | |||
PutOnAt string `json:"put_on_at"` | |||
PutDownAt string `json:"put_down_at"` | |||
Commission string `json:"commission"` //反的价钱 | |||
ShareValue string `json:"share_value"` //分享赚 | |||
SlefBuy string `json:"slef_buy"` //自购赚 | |||
} |
@@ -0,0 +1,23 @@ | |||
package model | |||
import "time" | |||
//激励广告表 | |||
type IncentiveAd struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
AdName string `json:"ad_name" xorm:"not null comment('广告名称(唯一)') VARCHAR(50)"` | |||
SdkType string `json:"sdk_type" xorm:"not null default 0 comment('平台:1,优量汇;2,快手联盟;3,穿山甲') VARCHAR(50)"` | |||
AndroidMediaId string `json:"android_media_id" xorm:"not null default 0 comment('安卓媒体id') VARCHAR(50)"` | |||
IosMediaId string `json:"ios_media_id" xorm:"not null default 0.0000 comment('ios媒体id') VARCHAR(50)"` | |||
AndroidAdId string `json:"android_ad_id" xorm:"not null default 0.0000 comment('安卓广告id') VARCHAR(50)"` | |||
IosAdId string `json:"ios_ad_id" xorm:"not null default 0.0000 comment('ios广告id') VARCHAR(50)"` | |||
Conditions int `json:"conditions" xorm:"not null default 1 comment('是否开启条件限制(0否,1是)') TINYINT(1)"` | |||
Autoplay int `json:"autoplay" xorm:"not null default 1 comment('是否自动播放(0否,1是)') TINYINT(1)"` | |||
AutoClickAd int `json:"auto_click_ad" xorm:"not null default 1 comment('是否自动点击广告(0否,1是)') TINYINT(1)"` | |||
LevelLimitId int `json:"level_limit_id" xorm:"comment('等级id') INT(11)"` | |||
LevelLimitName string `json:"level_limit_name" xorm:"comment('等级名称') VARCHAR(50)"` | |||
LevelWeight int `json:"level_weight" xorm:" comment('等级权重') INT(11)"` | |||
CreateAt time.Time `xorm:"not null default 0 comment('创建时间') datetime"` | |||
UpdateAt time.Time `xorm:"not null default 0 comment('更新时间') datetime"` | |||
VisitCount int `json:"visit_count" xorm:" default 0 comment('可观看次数') INT(11)"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package model | |||
type IncentiveAdTotal struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
AdId int `json:"ad_id" xorm:"default 0 comment('广告id') INT(11)"` | |||
Count int `json:"count" xorm:"default 0 comment('观看数量') INT(11)"` | |||
Time int `json:"time" xorm:"default 0 comment('时间') INT(11)"` | |||
Uid int `json:"uid" xorm:"default 0 comment('用户id') INT(11)"` | |||
} |
@@ -0,0 +1,6 @@ | |||
package model | |||
type LogisticCompany struct { | |||
Name string `json:"name" xorm:"comment('快递公司名称') VARCHAR(255)"` | |||
Code string `json:"code" xorm:"comment('快递公司代号') VARCHAR(255)"` | |||
} |
@@ -0,0 +1,52 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type MallOrd struct { | |||
OrdId int64 `json:"ord_id" xorm:"not null pk BIGINT(20)"` | |||
MainOrdId int64 `json:"main_ord_id" xorm:"not null comment('主订单号') index BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"comment('用户id') index INT(11)"` | |||
BuyerName string `json:"buyer_name" xorm:"comment('购买人') VARCHAR(255)"` | |||
BuyerPhone string `json:"buyer_phone" xorm:"comment('购买人手机号') VARCHAR(255)"` | |||
CostPrice string `json:"cost_price" xorm:"comment('价格') DECIMAL(12,2)"` | |||
CostVirtualCoin string `json:"cost_virtual_coin" xorm:"comment('消耗的虚拟币') DECIMAL(12,2)"` | |||
VirtualCoinId int `json:"virtual_coin_id" xorm:"comment('使用的虚拟币id') INT(11)"` | |||
State int `json:"state" xorm:"comment('订单状态:0未支付 1已支付 2已发货 3已完成 4售后中 5部分售后中 6关闭') TINYINT(1)"` | |||
PayTime time.Time `json:"pay_time" xorm:"comment('支付时间') DATETIME"` | |||
PayChannel int `json:"pay_channel" xorm:"not null comment('支付方式:1balance 2alipay 3wx_pay') TINYINT(1)"` | |||
ShippingTime time.Time `json:"shipping_time" xorm:"comment('发货时间') DATETIME"` | |||
LogisticCompany string `json:"logistic_company" xorm:"not null default '' comment('物流公司') VARCHAR(255)"` | |||
LogisticNum string `json:"logistic_num" xorm:"not null default '' comment('物流单号') VARCHAR(255)"` | |||
ReceiverPhone string `json:"receiver_phone" xorm:"not null default '' comment('收货人手机号') VARCHAR(20)"` | |||
ReceiverName string `json:"receiver_name" xorm:"not null default '' comment('收货人名字') VARCHAR(255)"` | |||
ReceiverAddressDetail string `json:"receiver_address_detail" xorm:"not null default '' comment('收货人地址') VARCHAR(255)"` | |||
ShippingType int `json:"shipping_type" xorm:"not null default 1 comment('运送方式:1快递送货') TINYINT(1)"` | |||
CouponDiscount string `json:"coupon_discount" xorm:"not null default 0.00 comment('优惠券折扣额') DECIMAL(12,2)"` | |||
DiscountPrice string `json:"discount_price" xorm:"not null default 0.00 comment('立减') DECIMAL(12,2)"` | |||
UserCouponId int64 `json:"user_coupon_id" xorm:"comment('使用的优惠券id') BIGINT(20)"` | |||
ReturnInsuranceFee string `json:"return_insurance_fee" xorm:"not null default 0.00 comment('退货无忧费用') DECIMAL(12,2)"` | |||
IsReceipt int `json:"is_receipt" xorm:"not null default 0 comment('是否开具发票 0否 1是') TINYINT(255)"` | |||
ShippingFee string `json:"shipping_fee" xorm:"not null default 0.00 comment('运费') DECIMAL(12,2)"` | |||
Comment string `json:"comment" xorm:"not null comment('备注') VARCHAR(2048)"` | |||
ProvinceName string `json:"province_name" xorm:"not null default '' comment('收货省份') VARCHAR(255)"` | |||
CityName string `json:"city_name" xorm:"not null default '' comment('收货城市') VARCHAR(255)"` | |||
CountyName string `json:"county_name" xorm:"not null default '' comment('收货区域') VARCHAR(255)"` | |||
PayNum string `json:"pay_num" xorm:"not null default '' comment('交易流水') VARCHAR(255)"` | |||
ConfirmTime time.Time `json:"confirm_time" xorm:"comment('确认时间') DATETIME"` | |||
EstimateIntegral string `json:"estimate_integral" xorm:"not null default 0.0000 comment('预计积分') DECIMAL(12,4)"` | |||
EstimateCommission string `json:"estimate_commission" xorm:"not null default 0.0000 comment('预计佣金') DECIMAL(12,4)"` | |||
CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||
UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` | |||
DeletedTime time.Time `json:"deleted_time" xorm:"comment('删除时间') DATETIME"` | |||
FinishTime time.Time `json:"finish_time" xorm:"comment('完成时间') DATETIME"` | |||
OrderType int `json:"order_type" xorm:"not null default 1 comment('订单类型:1普通订单 2拼团订单') TINYINT(3)"` | |||
Data string `json:"data" xorm:"comment('订单相关的数据') TEXT"` | |||
GroupBuyCommission string `json:"group_buy_commission" xorm:"default 0.0000 comment('团购未中奖佣金') DECIMAL(12,4)"` | |||
GroupBuySettleTime time.Time `json:"group_buy_settle_time" xorm:"comment('拼团结算时间') DATETIME"` | |||
SettleTime time.Time `json:"settle_time" xorm:"comment('结算时间') DATETIME"` | |||
GroupBuyCommissionTime time.Time `json:"group_buy_commission_time" xorm:"comment('拼团分佣时间') DATETIME"` | |||
CommissionTime time.Time `json:"commission_time" xorm:"comment('分佣时间') DATETIME"` | |||
ShareUid int `json:"share_uid" xorm:"comment('分享人') INT(11)"` | |||
} |
@@ -0,0 +1,14 @@ | |||
package model | |||
type MomentsCate struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Pid int `json:"pid" xorm:"not null default 0 comment('上级,0表示一级分类') INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('分类名称') VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
TypeId int `json:"type_id" xorm:"not null default 0 comment('类型') TINYINT(10)"` | |||
Data string `json:"data" xorm:"not null default '' comment('保存不同类型定义的设置数据') VARCHAR(255)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
Child *[]MomentsCate `json:"child"` | |||
} |
@@ -0,0 +1,13 @@ | |||
package model | |||
type MomentsMaterial struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Pid int `json:"pid" xorm:"not null default 0 comment('分类ID') INT(11)"` | |||
CateId int `json:"cate_id" xorm:"not null default 0 comment('子分类') INT(11)"` | |||
TypeId int `json:"type_id" xorm:"not null default 0 comment('类型ID') INT(11)"` | |||
Data string `json:"data" xorm:"not null comment('素材详情json') TEXT"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示:0不显示;1显示') TINYINT(1)"` | |||
CreatedAt int `json:"created_at" xorm:"comment('创建时间') INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"comment('更新时间') INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
type NewcomersFreePriceType struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
PriceName string `json:"price_name" xorm:"not null comment('价格类型') VARCHAR(255)"` | |||
NeedQuan int `json:"need_quan" xorm:"not null default 0 comment('需要的福利券') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否开启') TINYINT(1)"` | |||
IsDel int `json:"is_del" xorm:"not null default 0 INT(11)"` | |||
NeedUseQuan int `json:"need_use_quan" xorm:"not null default 1 INT(1)"` | |||
NeedLimitBuy int `json:"need_limit_buy" xorm:"not null default 0 INT(1)"` | |||
Auth string `json:"auth" xorm:"not null comment('权限') TEXT"` | |||
LimitBuyCondition string `json:"limit_buy_condition" xorm:"not null comment('限购条件') TEXT"` | |||
} |
@@ -0,0 +1,31 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type NewcomersFreeProduct struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
GoodId string `json:"good_id" xorm:"not null default '' comment('平台商品ID') VARCHAR(255)"` | |||
Source string `json:"source" xorm:"not null default 'taobao' comment('来源平台') VARCHAR(255)"` | |||
SourceUrl string `json:"source_url" xorm:"not null default '' comment('用户输入地址') VARCHAR(255)"` | |||
PriceType int `json:"price_type" xorm:"not null default 0 comment('所属价格类型') TINYINT(1)"` | |||
OriginalPrice string `json:"original_price" xorm:"not null default 0.00 comment('原价') DECIMAL(10,2)"` | |||
CouponPrice string `json:"coupon_price" xorm:"not null default 0.00 comment('券后价格') DECIMAL(10,2)"` | |||
ReturnMoney string `json:"return_money" xorm:"not null default 0.00 comment('返还的钱') DECIMAL(10,2)"` | |||
Money string `json:"money" xorm:"not null default 0 comment('实付金额') DECIMAL(10)"` | |||
Stock int `json:"stock" xorm:"not null default 0 comment('库存数量') INT(11)"` | |||
Sale int `json:"sale" xorm:"not null default 0 comment('卖掉的数量') INT(11)"` | |||
EndTime time.Time `json:"end_time" xorm:"not null comment('结束时间') DATETIME"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否上架') TINYINT(1)"` | |||
IsDel int `json:"is_del" xorm:"not null default 0 comment('是否删除') TINYINT(1)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(255)"` | |||
StartTime time.Time `json:"start_time" xorm:"not null comment('开始时间') DATETIME"` | |||
Pictures string `json:"pictures" xorm:"not null default '' comment('图片地址') VARCHAR(255)"` | |||
CouponUrl string `json:"coupon_url" xorm:"not null default '' comment('优惠券链接') VARCHAR(255)"` | |||
Amount int `json:"amount" xorm:"default 0 comment('总数') INT(11)"` | |||
ReturnType int `json:"return_type" xorm:"default 0 comment('0平台补贴 1 淘礼金补贴') INT(1)"` | |||
OwnbuyReturnType int `json:"ownbuy_return_type" xorm:"default 0 comment('自购补贴:1开启、0关闭') INT(1)"` | |||
} |
@@ -0,0 +1,8 @@ | |||
package model | |||
type NewcomersInviteRecord struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
FromUid int `json:"from_uid" xorm:"not null default 0 comment('邀请人uid') INT(11)"` | |||
ToUid int `json:"to_uid" xorm:"not null default 0 comment('被邀请人uid') INT(11)"` | |||
QualificationRecord int `json:"qualification_record" xorm:"not null default 0 comment('获得资格记录表ID') INT(11)"` | |||
} |
@@ -0,0 +1,10 @@ | |||
package model | |||
type NewcomersQualification struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') INT(10)"` | |||
RemainTimes int `json:"remain_times" xorm:"not null default 0 comment('剩余次数') INT(11)"` | |||
CumulativeTimes int `json:"cumulative_times" xorm:"not null default 0 comment('累计次数') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
} |
@@ -0,0 +1,21 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type NewcomersQualificationRecord struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Uid int `json:"uid" xorm:"not null default 0 INT(11)"` | |||
Source int `json:"source" xorm:"not null default 0 comment('1为注册获得 | |||
2为分享获得 | |||
3为消费扣除 | |||
4为后台修改 | |||
来源标识') TINYINT(4)"` | |||
SourceText string `json:"source_text" xorm:"not null default '' comment('来源') VARCHAR(255)"` | |||
ChangeNum int `json:"change_num" xorm:"not null default 0 comment('变更值') INT(11)"` | |||
AfterChangeNum int `json:"after_change_num" xorm:"not null default 0 comment('变更后值') INT(11)"` | |||
OrderId int64 `json:"order_id" xorm:"not null default 0 comment('新人免单订单ID(与order_list主键对应)') BIGINT(20)"` | |||
CreatedAt time.Time `json:"created_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` | |||
UpdatedAt time.Time `json:"updated_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` | |||
} |
@@ -0,0 +1,10 @@ | |||
package model | |||
type OrdItemInfo struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
ItemId string `json:"item_id" xorm:"not null default '' comment('商品id') index VARCHAR(100)"` | |||
Pvd string `json:"pvd" xorm:"not null default '' comment('供应商') VARCHAR(32)"` | |||
Thumbnail string `json:"thumbnail" xorm:"not null default '' comment('缩略图URL') VARCHAR(2000)"` | |||
ItemTitle string `json:"item_title" xorm:"not null default '' comment('标题') VARCHAR(256)"` | |||
ItemLink string `json:"item_link" xorm:"not null default '' comment('商品链接') VARCHAR(2000)"` | |||
} |
@@ -0,0 +1,42 @@ | |||
package model | |||
type OrdList struct { | |||
OrdId int64 `xorm:"pk autoincr BIGINT(20)" json:"ord_id"` | |||
Uid int `xorm:"not null index INT(10)" json:"uid"` | |||
PvdOid string `xorm:"not null index(IDX_PVD) VARCHAR(50)" json:"pvd_oid"` | |||
ParentOrdId int64 `xorm:" BIGINT(20)" json:"parent_ord_id"` | |||
Pvd string `xorm:"not null default '' index(IDX_PVD) index(IDX_PVD_ITEM) VARCHAR(8)" json:"pvd"` | |||
ItemId string `xorm:"not null default '' index(IDX_PVD_ITEM) VARCHAR(50)" json:"item_id"` | |||
ItemNum int `xorm:"not null default 1 TINYINT(3)" json:"item_num"` | |||
ItemPrice float64 `xorm:"not null default 0.00 FLOAT(10,2)" json:"item_price"` | |||
ItemCommissionRate float64 `xorm:"not null default 0.00 FLOAT(6,4)" json:"item_commission_rate"` | |||
PaidPrice float64 `xorm:"not null default 0.00 FLOAT(10,2)" json:"paid_price"` | |||
OrderType int `xorm:"not null default 0 TINYINT(1)" json:"order_type"` | |||
PriceType int `xorm:"not null default 0 INT(1)" json:"price_type"` | |||
OrderCompare int `xorm:"not null default 0 TINYINT(1)" json:"order_compare"` | |||
SubsidyFee float64 `xorm:"not null default 0.00 FLOAT(8,2)" json:"subsidy_fee"` | |||
SubsidyRate float64 `xorm:"not null default 0.0000 FLOAT(10,4)" json:"subsidy_rate"` | |||
UserCommission float64 `xorm:"not null default 0.000 FLOAT(8,3)" json:"user_commission"` | |||
UserCommissionRate float64 `xorm:"not null default 0.0000 FLOAT(6,4)" json:"user_commission_rate"` | |||
PvdCommission float64 `xorm:"not null default 0.0000 FLOAT(8,4)" json:"pvd_commission"` | |||
PvdCommissionRate float64 `xorm:"not null default 0.0000 FLOAT(6,4)" json:"pvd_commission_rate"` | |||
SysCommission float64 `xorm:"not null default 0.0000 FLOAT(8,4)" json:"sys_commission"` | |||
SysCommissionRate float64 `xorm:"not null default 0.0000 FLOAT(6,4)" json:"sys_commission_rate"` | |||
PlanCommissionId int `xorm:"not null default 0 INT(10)" json:"plan_commission_id"` | |||
PlanCommissionState int `xorm:"not null default 0 TINYINT(1)" json:"plan_commission_state"` | |||
Reason string `xorm:"not null default '' VARCHAR(32)" json:"reason"` | |||
State int `xorm:"not null default 0 TINYINT(1)" json:"state"` | |||
LockState int `xorm:"not null default 0 TINYINT(1)" json:"lock_state"` | |||
CreateAt int `xorm:"not null default 0 INT(10)" json:"create_at"` | |||
UpdateAt int `xorm:"not null default 0 INT(11)" json:"update_at"` | |||
ConfirmAt int `xorm:"not null default 0 INT(10)" json:"confirm_at"` | |||
PvdSettleAt int `xorm:"not null default 0 INT(10)" json:"pvd_settle_at"` | |||
SettleAt int `xorm:"not null default 0 INT(10)" json:"settle_at"` | |||
SubsidyAt int `xorm:"not null default 0 INT(10)" json:"subsidy_at"` | |||
BenefitList string `xorm:"not null default '' index VARCHAR(200)" json:"benefit_list"` | |||
BenefitAll float64 `xorm:"not null default 0.00 FLOAT(8,2)" json:"benefit_all"` | |||
Data string `xorm:"not null default '' VARCHAR(2000)" json:"data"` | |||
UpdateFrom int `xorm:"not null default 0 TINYINT(1)" json:"update_from"` | |||
CreateFrom int `xorm:"not null default 0 TINYINT(1)" json:"create_from"` | |||
PvdPid string `xorm:"not null default '' index VARCHAR(100)" json:"pvd_pid"` | |||
} |
@@ -0,0 +1,29 @@ | |||
package model | |||
type OrdListHis struct { | |||
OrdId int64 `json:"ord_id" xorm:"not null pk autoincr comment('本系统订单ID') BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"` | |||
ProviderOid string `json:"provider_oid" xorm:"not null comment('供应商订单订单号') VARCHAR(50)"` | |||
SkuId string `json:"sku_id" xorm:"not null default '' comment('商品SKU') VARCHAR(50)"` | |||
ItemId string `json:"item_id" xorm:"not null comment('商品ID') VARCHAR(50)"` | |||
ItemPrice string `json:"item_price" xorm:"not null default 0.00 comment('商品单价') DECIMAL(10,2)"` | |||
Provider string `json:"provider" xorm:"not null default '' comment('供应商taobao,jd,pdd,vip,suning,kaola') VARCHAR(16)"` | |||
PaidPrice string `json:"paid_price" xorm:"not null default 0.00 comment('付款金额') DECIMAL(10,2)"` | |||
OrderType int `json:"order_type" xorm:"not null default 0 comment('0自购,1分享订单,粉丝订单') TINYINT(1)"` | |||
BuyerId int `json:"buyer_id" xorm:"not null default 0 comment('0分享订单,其它自购或粉丝') INT(11)"` | |||
UpdateFrom int `json:"update_from" xorm:"not null default 0 comment('订单更新来源,0.API,1.导入,2.后台操作') TINYINT(1)"` | |||
UserCommission string `json:"user_commission" xorm:"not null default 0.000 comment('用户佣金') DECIMAL(10,3)"` | |||
UserCommissionRate string `json:"user_commission_rate" xorm:"not null default 0.0000 comment('用户佣金比例,如10.05%就是0.1005') DECIMAL(6,4)"` | |||
ProviderAllCommission string `json:"provider_all_commission" xorm:"not null default 0.000 comment('联盟返佣总额') DECIMAL(10,3)"` | |||
ProviderAllCommissionRate string `json:"provider_all_commission_rate" xorm:"not null default 0.0000 comment('联盟返佣比例') DECIMAL(6,4)"` | |||
PlanCommissionId int `json:"plan_commission_id" xorm:"not null default 0 comment('分佣方案') INT(10)"` | |||
PlanSettleId int `json:"plan_settle_id" xorm:"not null default 0 comment('结算方案') INT(10)"` | |||
SettleState int `json:"settle_state" xorm:"not null default 0 comment('用户结算状态,0未结算,1已结算') TINYINT(1)"` | |||
Reason string `json:"reason" xorm:"not null default '' comment('失效原因') VARCHAR(32)"` | |||
State int `json:"state" xorm:"not null default 0 comment('0已付款,1已收货,2成功,3失效') TINYINT(1)"` | |||
CreateAt int `json:"create_at" xorm:"not null default 0 comment('创建时间') INT(10)"` | |||
UpdateAt int `json:"update_at" xorm:"not null default 0 comment('更新时间') INT(10)"` | |||
ConfirmAt int `json:"confirm_at" xorm:"not null default 0 comment('确认收货时间') INT(10)"` | |||
ProviderSettleAt int `json:"provider_settle_at" xorm:"not null default 0 comment('供应商结算时间') INT(10)"` | |||
SettleAt int `json:"settle_at" xorm:"not null default 0 comment('用户分佣结算时间') INT(10)"` | |||
} |
@@ -0,0 +1,11 @@ | |||
package model | |||
type OrdListRelate struct { | |||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||
Oid int64 `json:"oid" xorm:"not null default 0 comment('订单号') index unique(IDX_ORD) BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户ID') unique(IDX_ORD) index INT(10)"` | |||
Amount float64 `json:"amount" xorm:"not null default 0.00 comment('金额') FLOAT(10,2)"` | |||
Pvd string `json:"pvd" xorm:"not null default '' comment('供应商taobao,jd,pdd,vip,suning,kaola') index VARCHAR(8)"` | |||
CreateAt int `json:"create_at" xorm:"not null default 0 comment('订单创建时间') index INT(10)"` | |||
Level int `json:"level" xorm:"not null default 0 comment('0自购 1直推 大于1:间推') INT(10)"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package model | |||
import "time" | |||
type PlanCommission struct { | |||
Id int `json:"id" xorm:"not null pk autoincr comment('分佣方案ID,现在只允许1,2') INT(10)"` | |||
PlanName string `json:"plan_name" xorm:"not null default '' comment('方案名称') VARCHAR(64)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(256)"` | |||
Mode string `json:"mode" xorm:"not null default '' comment('模式,lv_all级差按总佣金,lv_self级差按自购') VARCHAR(16)"` | |||
Data string `json:"data" xorm:"not null default '' comment('里面包含等级分配方案数据') VARCHAR(3000)"` | |||
UpdateAt time.Time `json:"update_at" xorm:"default CURRENT_TIMESTAMP TIMESTAMP"` | |||
} |
@@ -0,0 +1,15 @@ | |||
package model | |||
type PlanReward struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
Pvd string `json:"pvd" xorm:"not null comment('供应商') VARCHAR(16)"` | |||
PvdRate float32 `json:"pvd_rate" xorm:"not null default 0.0000 comment('供应商抽成比例') FLOAT(6,4)"` | |||
SysRate float32 `json:"sys_rate" xorm:"not null default 0.0000 comment('平台抽成比例') FLOAT(6,4)"` | |||
SettleMode int `json:"settle_mode" xorm:"not null default 1 comment('0.手动方案,1.自动方案') TINYINT(1)"` | |||
PlanCommissionId int `json:"plan_commission_id" xorm:"not null default 0 comment('佣金方案0未设置,>0对应方案') TINYINT(3)"` | |||
PlanSettleId int `json:"plan_settle_id" xorm:"not null default 0 comment('结算方案0未设置,>0对应方案') TINYINT(3)"` | |||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1开启') TINYINT(1)"` | |||
Source int `json:"source" xorm:"not null default 1 comment('佣金来源:1联盟佣金 2补贴金额') TINYINT(1)"` | |||
RegionRate float32 `json:"region_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||
GlobalRate float32 `json:"global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||
} |
@@ -0,0 +1,14 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type PlanSettle struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
PlanName string `json:"plan_name" xorm:"not null default '' comment('方案名称') VARCHAR(128)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(512)"` | |||
SettleMode int `json:"settle_mode" xorm:"not null default 0 comment('0组合条件,1固定条件') TINYINT(1)"` | |||
SettleCondition string `json:"settle_condition" xorm:"comment('当组合时候存json,固定存数字(组合条件时settleTime为0时是立即结算)') TEXT"` | |||
UpdateTime time.Time `json:"update_time" xorm:"default CURRENT_TIMESTAMP TIMESTAMP"` | |||
} |
@@ -0,0 +1,8 @@ | |||
package model | |||
type PlanWithdraw struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||
PlanName string `json:"plan_name" xorm:"not null default '' comment('方案名称') VARCHAR(64)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('方案描述') VARCHAR(512)"` | |||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1开启') TINYINT(1)"` | |||
} |
@@ -0,0 +1,21 @@ | |||
package model | |||
type PrivilegeCardBrand struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
ZhimengId int `json:"zhimeng_id" xorm:"not null default 0 comment('智盟ID') INT(11)"` | |||
ThirdId int `json:"third_id" xorm:"not null default 0 comment('三方平台ID') INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('品牌名称') VARCHAR(255)"` | |||
SubName string `json:"sub_name" xorm:"not null default '' comment('品牌副标题') VARCHAR(255)"` | |||
Logo string `json:"logo" xorm:"not null default '' comment('品牌logo') VARCHAR(255)"` | |||
CateId int `json:"cate_id" xorm:"not null default 0 comment('分类ID') INT(11)"` | |||
Type string `json:"type" xorm:"not null default '' comment('类型') VARCHAR(255)"` | |||
TypeId string `json:"type_id" xorm:"not null default '' comment('类型id') VARCHAR(255)"` | |||
AccountType string `json:"account_type" xorm:"comment('账号类型') VARCHAR(255)"` | |||
Remark string `json:"remark" xorm:"not null comment('温馨提示') TEXT"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"default 0 comment('排序') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
Skip string `json:"skip" xorm:"comment('跳转信息') TEXT"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package model | |||
type PrivilegeCardBrandCate struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('分类名称') VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"default 0 comment('排序') INT(11)"` | |||
Amount int `json:"amount" xorm:"default 0 comment('品牌数量') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
} |
@@ -0,0 +1,24 @@ | |||
package model | |||
type PrivilegeCardGoods struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
ZhimengId int `json:"zhimeng_id" xorm:"not null default 0 comment('智盟ID') INT(11)"` | |||
ThirdId int `json:"third_id" xorm:"not null default 0 comment('三方平台ID') INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('商品名称') VARCHAR(255)"` | |||
GoodsImg string `json:"goods_img" xorm:"not null default '' comment('商品图片') VARCHAR(255)"` | |||
BrandId int `json:"brand_id" xorm:"not null default 0 comment('品牌ID') INT(11)"` | |||
Times string `json:"times" xorm:"not null default '' comment('时长') VARCHAR(255)"` | |||
CateId int `json:"cate_id" xorm:"not null default 0 comment('商品分类ID') INT(11)"` | |||
MarkupMode int `json:"markup_mode" xorm:"not null default 0 comment('加价模式 0为利润空间1为进货价') TINYINT(1)"` | |||
MarkupRate int `json:"markup_rate" xorm:"not null default 0 comment('加价比例') INT(3)"` | |||
OfficialPrice string `json:"official_price" xorm:"not null default 0.00 comment('原价') DECIMAL(10,2)"` | |||
PlatformPrice string `json:"platform_price" xorm:"not null default 0.00 comment('进货价') DECIMAL(10,2)"` | |||
FinalPrice string `json:"final_price" xorm:"not null default 0.00 comment('销售价') DECIMAL(10,2)"` | |||
Type string `json:"type" xorm:"not null default '' comment('类型') VARCHAR(255)"` | |||
TypeId string `json:"type_id" xorm:"not null default '' comment('类型id') VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"default 0 comment('排序') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
} |
@@ -0,0 +1,13 @@ | |||
package model | |||
type PrivilegeCardGoodsCate struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('商品分类名称') VARCHAR(255)"` | |||
IsShow int `json:"is_show" xorm:"not null default 1 comment('是否显示') TINYINT(1)"` | |||
Sort int `json:"sort" xorm:"default 0 comment('排序') INT(11)"` | |||
BrandId int `json:"brand_id" xorm:"not null default 0 comment('从属品牌ID') INT(11)"` | |||
Amount int `json:"amount" xorm:"default 0 comment('商品数量') INT(11)"` | |||
CreatedAt int `json:"created_at" xorm:"not null default 0 INT(11)"` | |||
UpdatedAt int `json:"updated_at" xorm:"not null default 0 INT(11)"` | |||
DeletedAt int `json:"deleted_at" xorm:"not null default 0 INT(11)"` | |||
} |
@@ -0,0 +1,24 @@ | |||
package model | |||
import ( | |||
"time" | |||
) | |||
type PrivilegeCardNum struct { | |||
Id int64 `json:"id" xorm:"pk autoincr comment('主键') BIGINT(11)"` | |||
CardNum string `json:"card_num" xorm:"not null default '' comment('卡号') index VARCHAR(255)"` | |||
CardKey string `json:"card_key" xorm:"not null default '' comment('激活码') index VARCHAR(255)"` | |||
Uid int `json:"uid" xorm:"comment('绑定用户') index INT(11)"` | |||
Phone string `json:"phone" xorm:"not null default '' comment('用户手机号') VARCHAR(255)"` | |||
ParentUid int `json:"parent_uid" xorm:"not null default 0 comment('推荐人') index INT(11)"` | |||
CardType int `json:"card_type" xorm:"not null default 1 comment('1实体卡 2虚拟卡') TINYINT(1)"` | |||
Theme string `json:"theme" xorm:"not null default '' comment('主题描述') VARCHAR(255)"` | |||
FromType int `json:"from_type" xorm:"not null default 0 comment('来源:0用户购买 1后台操作 2 导入') TINYINT(1)"` | |||
Status int `json:"status" xorm:"not null default 0 comment('状态:0未激活 1激活') TINYINT(1)"` | |||
GivenData string `json:"given_data" xorm:"comment('赠送权益数据') TEXT"` | |||
ValidDateType int `json:"valid_date_type" xorm:"not null default 0 comment('1月度 2季度 3年度 4永久 5自定义(天数)') TINYINT(1)"` | |||
CustomDay int `json:"custom_day" xorm:"not null default 0 comment('自定义天数') INT(11)"` | |||
ExpireTime time.Time `json:"expire_time" xorm:"not null default '0000-00-00 00:00:00' comment('过期时间 2099-12-31 23:59:59表示永久') DATETIME"` | |||
CreateTime time.Time `json:"create_time" xorm:"created not null default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||
UpdateTime time.Time `json:"update_time" xorm:"updated not null default 'CURRENT_TIMESTAMP' comment('更新时间') DATETIME"` | |||
} |