Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"block.go",
"member.go",
"monitor.go",
"official.go",
"pagination.go",
"params.go",
"realname.go",
"realname_old.go",
"review.go",
"search.go",
],
importpath = "go-common/app/admin/main/member/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/member/conf:go_default_library",
"//app/admin/main/member/model/block:go_default_library",
"//app/service/main/member/model:go_default_library",
"//app/service/main/member/model/block:go_default_library",
"//library/log:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/admin/main/member/model/block:all-srcs",
"//app/admin/main/member/model/bom:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["member_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//vendor/github.com/stretchr/testify/assert:go_default_library"],
)

View File

@@ -0,0 +1,13 @@
package model
import (
"go-common/app/service/main/member/model/block"
)
// BlockResult is
type BlockResult struct {
MID int64 `json:"mid"`
BlockStatus block.BlockStatus `json:"block_status"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
}

View File

@@ -0,0 +1,32 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"http.go",
"model.go",
"notify.go",
],
importpath = "go-common/app/admin/main/member/model/block",
tags = ["automanaged"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,46 @@
package block
import (
"time"
)
// DBUser .
type DBUser struct {
ID int64
MID int64
Status BlockStatus
CTime time.Time
MTime time.Time
}
// DBUserDetail .
type DBUserDetail struct {
ID int64
MID int64
BlockCount int
CTime time.Time
MTime time.Time
}
// DBHistory .
type DBHistory struct {
ID int64
MID int64
AdminID int64
AdminName string
Source BlockSource
Area BlockArea
Reason string
Comment string
Action BlockAction
StartTime time.Time
Duration int64
Notify bool
CTime time.Time
MTime time.Time
}
// MCBlockInfo .
type MCBlockInfo struct {
BlockStatus BlockStatus `json:"bs"`
}

View File

@@ -0,0 +1,131 @@
package block
// ParamValidator .
type ParamValidator interface {
Validate() bool
}
// ParamSearch .
type ParamSearch struct {
MIDs []int64 `form:"mids,split"`
}
// Validate .
func (p *ParamSearch) Validate() bool {
p.MIDs = intsSet(p.MIDs)
if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
return false
}
return true
}
// ParamHistory .
type ParamHistory struct {
MID int64 `form:"mid"`
Desc bool `form:"desc"`
PS int `form:"ps"`
PN int `form:"pn"`
}
// Validate .
func (p *ParamHistory) Validate() bool {
if p.MID <= 0 {
return false
}
if p.PS <= 0 || p.PS > 100 {
return false
}
if p.PN <= 0 {
return false
}
return true
}
// ParamBatchBlock .
type ParamBatchBlock struct {
MIDs []int64 `form:"mids,split"`
AdminID int64 `form:"admin_id"`
AdminName string `form:"admin_name"`
Source BlockMgrSource `form:"source"`
Area BlockArea `form:"area"`
Reason string `form:"reason"`
Comment string `form:"comment"`
Action BlockAction `form:"action"`
Duration int64 `form:"duration"` // 单位:天
Notify bool `form:"notify"`
}
// Validate .
func (p *ParamBatchBlock) Validate() bool {
p.MIDs = intsSet(p.MIDs)
if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
return false
}
if p.AdminID <= 0 {
return false
}
if p.AdminName == "" {
return false
}
if p.Source != BlockMgrSourceSys && p.Source != BlockMgrSourceCredit {
return false
}
if !p.Area.Contain() {
return false
}
if p.Comment == "" {
return false
}
if p.Action != BlockActionForever && p.Action != BlockActionLimit {
return false
}
if p.Action == BlockActionLimit {
if p.Duration <= 0 {
return false
}
}
return true
}
// ParamBatchRemove .
type ParamBatchRemove struct {
MIDs []int64 `form:"mids,split"`
AdminID int64 `form:"admin_id"`
AdminName string `form:"admin_name"`
Comment string `form:"comment"`
Notify bool `form:"notify"`
}
// Validate .
func (p *ParamBatchRemove) Validate() bool {
p.MIDs = intsSet(p.MIDs)
if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
return false
}
if p.AdminID <= 0 {
return false
}
if p.AdminName == "" {
return false
}
if p.Comment == "" {
return false
}
return true
}
func intsSet(ints []int64) (intSet []int64) {
if len(ints) == 0 {
return
}
OUTER:
for i := range ints {
for ni := range intSet {
if ints[i] == intSet[ni] {
continue OUTER
}
}
intSet = append(intSet, ints[i])
}
return
}

View File

@@ -0,0 +1,248 @@
package block
import (
"time"
)
// BlockStatus 封禁状态 0. 未封禁 1. 永久封禁 2. 限时封禁
type BlockStatus uint8
const (
// BlockStatusFalse 未封禁
BlockStatusFalse BlockStatus = iota
// BlockStatusForever 永久封禁
BlockStatusForever
// BlockStatusLimit 限时封禁
BlockStatusLimit
// BlockStatusCredit 小黑屋封禁
BlockStatusCredit
)
// BlockSource 封禁来源 1. 小黑屋(小黑屋和manager后台封禁) 2. 系统封禁(反作弊及监控系统上报) 3.解封 (所有后台,用户前台自助的解封)
type BlockSource uint8
// Contain .
func (b BlockSource) Contain() bool {
switch b {
case BlockSourceBlackHouse, BlockSourceSys, BlockSourceManager, BlockSourceBplus:
return true
default:
return false
}
}
const (
// BlockSourceBlackHouse 小黑屋封禁
BlockSourceBlackHouse BlockSource = iota + 1
// BlockSourceSys 系统封禁
BlockSourceSys
// BlockSourceManager 管理后台
BlockSourceManager
// BlockSourceBplus B+相关(动态、im、小视频)
BlockSourceBplus
)
// String .
func (b BlockSource) String() string {
switch b {
case BlockSourceBlackHouse:
return "小黑屋封禁"
case BlockSourceSys:
return "系统封禁"
default:
return ""
}
}
const (
// BlockLogBizID 用户审核日志
BlockLogBizID int = 122
)
// BlockArea 封禁业务
type BlockArea uint8
// Contain .
func (b BlockArea) Contain() bool {
switch b {
case BlockAreaNone, BlockAreaReply, BlockAreaDanmaku, BlockAreaMessage, BlockAreaTag, BlockAreaProfile, BlockAreaArchive, BlockAreaMusic, BlockAreaArticle, BlockAreaSpaceBanner, BlockAreaDynamic, BlockAreaAlbum, BlockAreaQuickVideo:
return true
default:
return false
}
}
func (b BlockArea) String() string {
switch b {
case BlockAreaReply:
return "评论"
case BlockAreaDanmaku:
return "弹幕"
case BlockAreaMessage:
return "私信"
case BlockAreaTag:
return "标签"
case BlockAreaProfile:
return "个人资料"
case BlockAreaArchive:
return "投稿"
case BlockAreaMusic:
return "音频"
case BlockAreaArticle:
return "专栏"
case BlockAreaSpaceBanner:
return "空间头图"
case BlockAreaDynamic:
return "动态"
case BlockAreaAlbum:
return "相册"
case BlockAreaQuickVideo:
return "小视频"
default:
return ""
}
}
// const .
const (
BlockAreaNone BlockArea = iota
BlockAreaReply
BlockAreaDanmaku
BlockAreaMessage
BlockAreaTag
BlockAreaProfile // 个人资料
BlockAreaArchive
BlockAreaMusic
BlockAreaArticle
BlockAreaSpaceBanner // 空间头图
BlockAreaDynamic // 动态
BlockAreaAlbum // 相册
BlockAreaQuickVideo //小视频
)
// BlockAction .
type BlockAction uint8
const (
// BlockActionLimit 限时封禁
BlockActionLimit BlockAction = iota + 1
// BlockActionForever 永久封禁
BlockActionForever
// BlockActionAdminRemove 后台解封
BlockActionAdminRemove
// BlockActionSelfRemove 自动解封
BlockActionSelfRemove
)
// String .
func (b BlockAction) String() string {
switch b {
case BlockActionLimit:
return "限时封禁"
case BlockActionForever:
return "永久封禁"
case BlockActionAdminRemove:
return "后台解封"
case BlockActionSelfRemove:
return "自动解封"
default:
return ""
}
}
// BlockInfo 封禁信息
type BlockInfo struct {
MID int64 `json:"mid"`
Nickname string `json:"nickname"`
Username string `json:"username"` // 注册生成时不可更改的username
Tel string `json:"tel"`
TelStatus int32 `json:"tel_status"`
Mail string `json:"mail"` // 绑定的邮箱
Level int32 `json:"level"`
SpyScore int8 `json:"spy_score"`
FigureRank int8 `json:"figure_rank"`
RegTime int64 `json:"reg_time"`
BlockStatus BlockStatus `json:"block_status"` // blockStatus 封禁状态 0. 未封禁 1. 永久封禁 2. 限时封禁
BlockCount int `json:"block_count"`
}
// ParseStatus .
func (b *BlockInfo) ParseStatus(db *DBUser) {
switch db.Status {
case BlockStatusCredit:
b.BlockStatus = BlockStatusLimit
default:
b.BlockStatus = db.Status
}
}
// BlockHistory 封禁历史
type BlockHistory struct {
Type BlockMgrType `json:"type"`
Operator string `json:"operator"` // 操作人
Reason string `json:"reason"` // 封禁原因
Action BlockAction `json:"action"` // 操作类型
ActionTime int64 `json:"action_time"` // 操作时间
RemoveTime int64 `json:"remove_time"` // 解封时间
Comment string `json:"comment"`
}
// BlockDetail blockDetail.
type BlockDetail struct {
Status BlockStatus `json:"status"`
Total int `json:"total"`
History []*BlockHistory `json:"history"`
}
// ParseDB .
func (b *BlockHistory) ParseDB(data *DBHistory) {
switch data.Action {
case BlockActionForever, BlockActionLimit:
switch data.Source {
case BlockSourceSys, BlockSourceManager:
b.Type = BlockMgrTypeSys
default:
b.Type = BlockMgrTypeCredit
}
case BlockActionSelfRemove, BlockActionAdminRemove:
b.Type = BlockMgrTypeRemove
}
b.Operator = data.AdminName
if data.Area.String() == "" {
b.Reason = data.Reason
} else {
b.Reason = data.Area.String() + " - " + data.Reason
}
b.Action = data.Action
b.ActionTime = data.StartTime.Unix()
if b.Action == BlockActionLimit {
b.RemoveTime = data.StartTime.Add(time.Second * time.Duration(data.Duration)).Unix()
}
b.Comment = data.Comment
}
// BlockMessage 通知消息体
type BlockMessage struct {
MID int64 `json:"mid"` // 用户mid
Area BlockArea `json:"area"` // BlockArea 封禁类型 1. 小黑屋(小黑屋和manager后台封禁) 2. 系统封禁(反作弊及监控系统上报) 3.解封 (所有后台,用户前台自助的解封)
Status BlockStatus `json:"status"` // blockStatus 封禁状态 0. 未封禁 1. 永久封禁 2. 限时封禁
}
// BlockMgrType mgr后台用
type BlockMgrType uint8
// BlockType enum
const (
BlockMgrTypeCredit = iota + 1
BlockMgrTypeSys
BlockMgrTypeRemove
)
// BlockMgrSource mgr后台用
type BlockMgrSource uint8
// BlockMgrSource enum
const (
BlockMgrSourceSys = iota + 1
BlockMgrSourceCredit
)

View File

@@ -0,0 +1,8 @@
package block
// AccountNotify .
type AccountNotify struct {
UID int64 `json:"mid"`
Type string `json:"type"`
Action string `json:"action"`
}

View File

@@ -0,0 +1,42 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"bom.go",
"discard_go15.go",
],
importpath = "go-common/app/admin/main/member/model/bom",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_xtest",
srcs = ["bom_test.go"],
tags = ["automanaged"],
deps = [
"//app/admin/main/member/model/bom:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,39 @@
// Package bom is used to clean up UTF-8 Byte Order Marks.
package bom
import (
"bufio"
"io"
)
const (
bom0 = 0xef
bom1 = 0xbb
bom2 = 0xbf
)
// Clean returns b with the 3 byte BOM stripped off the front if it is present.
// If the BOM is not present, then b is returned.
func Clean(b []byte) []byte {
if len(b) >= 3 &&
b[0] == bom0 &&
b[1] == bom1 &&
b[2] == bom2 {
return b[3:]
}
return b
}
// NewReader returns an io.Reader that will skip over initial UTF-8 byte order marks.
func NewReader(r io.Reader) io.Reader {
buf := bufio.NewReader(r)
b, err := buf.Peek(3)
if err != nil {
// not enough bytes
return buf
}
if b[0] == bom0 && b[1] == bom1 && b[2] == bom2 {
discardBytes(buf, 3)
}
return buf
}

View File

@@ -0,0 +1,80 @@
package bom_test
import (
"bytes"
"io/ioutil"
"testing"
"go-common/app/admin/main/member/model/bom"
"github.com/stretchr/testify/assert"
)
var testCases = []struct {
Input []byte
Expected []byte
}{
{
Input: nil,
Expected: nil,
},
{
Input: []byte{},
Expected: []byte{},
},
{
Input: []byte{0xef},
Expected: []byte{0xef},
},
{
Input: []byte{0xef, 0xbb},
Expected: []byte{0xef, 0xbb},
},
{
Input: []byte{0xef, 0xbb, 0xbf},
Expected: []byte{},
},
{
Input: []byte{0xef, 0xbb, 0xbf, 0x41, 0x42, 0x43},
Expected: []byte{0x41, 0x42, 0x43},
},
{
Input: []byte{0xef, 0xbb, 0x41, 0x42, 0x43},
Expected: []byte{0xef, 0xbb, 0x41, 0x42, 0x43},
},
{
Input: []byte{0xef, 0x41, 0x42, 0x43},
Expected: []byte{0xef, 0x41, 0x42, 0x43},
},
{
Input: []byte{0x41, 0x42, 0x43},
Expected: []byte{0x41, 0x42, 0x43},
},
}
func TestClean(t *testing.T) {
assert := assert.New(t)
for _, tc := range testCases {
output := bom.Clean(tc.Input)
assert.Equal(tc.Expected, output)
}
}
func TestReader(t *testing.T) {
assert := assert.New(t)
for _, tc := range testCases {
// An input value of nil works differently to the Clean function.
// In this case it results in an empty buffer, not nil.
expected := tc.Expected
if tc.Input == nil {
expected = []byte{}
}
r1 := bytes.NewReader(tc.Input)
r2 := bom.NewReader(r1)
output, err := ioutil.ReadAll(r2)
assert.NoError(err)
assert.Equal(expected, output)
}
}

View File

@@ -0,0 +1,12 @@
// +build !go1.5
package bom
import "bufio"
func discardBytes(buf *bufio.Reader, n int) {
// cannot use the buf.Discard method as it was introduced in Go 1.5
for i := 0; i < n; i++ {
buf.ReadByte()
}
}

View File

@@ -0,0 +1,10 @@
// +build go1.5
package bom
import "bufio"
func discardBytes(buf *bufio.Reader, n int) {
// the Discard method was introduced in Go 1.5
buf.Discard(n)
}

View File

@@ -0,0 +1,306 @@
package model
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"math/rand"
"net/url"
"path/filepath"
"strconv"
"strings"
"time"
xtime "go-common/library/time"
)
const (
_expMulti = 100
level1 = 1
level2 = 200
level3 = 1500
level4 = 4500
level5 = 10800
level6 = 28800
levelMax = -1
_URLNoFace = "http://static.hdslb.com/images/member/noface.gif"
// ManagerLogID manager log id.
ManagerLogID = 121
//FaceCheckLogID is.
FaceCheckLogID = 161
// bfs facepri bucket
_facepriKeyID = "8923aff2e1124bb2"
_facepriKeySecret = "b237e8927823cc2984aee980123cb0"
)
// base audit type const.
const (
BaseAuditType = iota
BaseAuditTypeFace
BaseAuditTypeSign
BaseAuditTypeName
)
// Base is.
type Base struct {
Mid int64 `json:"mid" gorm:"column:mid"`
Name string `json:"name" gorm:"column:name"`
Sex int64 `json:"sex" gorm:"column:sex"`
Face string `json:"face" gorm:"column:face"`
Sign string `json:"sign" gorm:"column:sign"`
Rank int64 `json:"rank" gorm:"column:rank"`
Birthday xtime.Time `json:"birthday" gorm:"column:birthday"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
}
// RandFaceURL get face URL
func (b *Base) RandFaceURL() {
if b.Face == "" {
b.Face = _URLNoFace
return
}
b.Face = fmt.Sprintf("http://i%d.hdslb.com%s", rand.Int63n(3), b.Face)
}
// Detail is.
type Detail struct {
Mid int64 `json:"mid" gorm:"column:mid"`
Birthday xtime.Time `json:"birthday" gorm:"column:birthday"`
Place int64 `json:"place" gorm:"column:place"`
Marital int64 `json:"marital" gorm:"column:marital"`
Dating int64 `json:"dating" gorm:"column:dating"`
Tags string `json:"tags" gorm:"column:tags"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
}
// Exp is.
type Exp struct {
Mid int64 `json:"mid" gorm:"column:mid"`
Exp int64 `json:"exp" gorm:"column:exp"`
Flag uint32 `json:"flag" gorm:"column:flag"`
AddTime xtime.Time `json:"addtime" gorm:"column:addtime"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
}
// Moral is.
type Moral struct {
Mid int64 `json:"mid" gorm:"column:mid"`
Moral int64 `json:"moral" gorm:"column:moral"`
Added int64 `json:"added" gorm:"column:added"`
Deducted int64 `json:"deducted" gorm:"column:deducted"`
LastRecoverDate xtime.Time `json:"last_recover_date" gorm:"colum:last_recover_date"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
}
// UserAddit is.
type UserAddit struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
FaceReject int64 `json:"face_reject" gorm:"colum:face_reject"`
ViolationCount int64 `json:"violation_count" gorm:"colum:violation_count"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
Remark string `json:"remark" gorm:"column:remark"`
}
// Level is.
type Level struct {
CurrentLevel int32 `json:"current_level"`
CurrentMin int32 `json:"current_min"`
CurrentExp int32 `json:"current_exp"`
NextExp int32 `json:"next_exp"`
}
// Profile is.
type Profile struct {
Base Base `json:"base"`
Detail Detail `json:"detail"`
Exp Exp `json:"exp"`
Level Level `json:"level"`
Moral Moral `json:"moral"`
Official Official `json:"official"`
Coin Coin `json:"coin"`
Addit UserAddit `json:"addit"`
Realanme Realname `json:"realname"`
}
// Coin is.
type Coin struct {
Coins float64 `json:"coins"`
}
// UserLog is.
type UserLog struct {
Mid int64 `json:"mid"`
IP string `json:"ip"`
TS int64 `json:"ts"`
Content map[string]string `json:"content"`
}
// FaceRecord is.
type FaceRecord struct {
ID int64 `json:"id"`
Mid int64 `json:"mid"`
ModifyTime xtime.Time `json:"modify_time"`
ApplyTime xtime.Time `json:"apply_time"`
NewFace string `json:"new_face"`
OldFace string `json:"old_face"`
Operator string `json:"operator"`
Status int8 `json:"status"`
}
// BaseReview is.
type BaseReview struct {
Base
Addit UserAddit `json:"addit"`
Logs []AuditLog `json:"logs"`
}
// AddExpMsg is.
type AddExpMsg struct {
Event string `json:"event,omitempty"`
Mid int64 `json:"mid,omitempty"`
IP string `json:"ip,omitempty"`
Ts int64 `json:"ts,omitempty"`
}
// BuildFaceURL is.
func BuildFaceURL(raw string) string {
if raw == "" {
return _URLNoFace
}
ori, err := url.Parse(raw)
if err != nil {
return raw
}
if ori.Path == "/images/member/noface.gif" {
return _URLNoFace
}
if strings.HasPrefix(ori.Path, "/bfs/facepri") {
token := authorize(_facepriKeyID, _facepriKeySecret, "GET", "facepri", filepath.Base(ori.Path), time.Now().Unix())
p := url.Values{}
p.Set("token", token)
ori.RawQuery = p.Encode()
}
if ori.Hostname() == "" {
ori.Host = fmt.Sprintf("i%d.hdslb.com", rand.Int63n(3))
ori.Scheme = "http"
}
return ori.String()
}
// authorize returns authorization for upload file to bfs
func authorize(key, secret, method, bucket, filename string, expire int64) string {
content := fmt.Sprintf("%s\n%s\n%s\n%d\n", method, bucket, filename, expire)
mac := hmac.New(sha1.New, []byte(secret))
mac.Write([]byte(content))
signature := base64.StdEncoding.EncodeToString(mac.Sum(nil))
return fmt.Sprintf("%s:%s:%d", key, signature, expire)
}
// BuildFaceURL is.
func (fr *FaceRecord) BuildFaceURL() {
fr.NewFace = BuildFaceURL(fr.NewFace)
fr.OldFace = BuildFaceURL(fr.OldFace)
}
// ParseStatus is.
func ParseStatus(s string) int8 {
st, _ := strconv.ParseInt(s, 10, 8)
return int8(st)
}
// ParseLogTime is.
func ParseLogTime(ts string) (xt xtime.Time, err error) {
var (
t time.Time
)
if t, err = time.ParseInLocation("2006-01-02 15:04:05", ts, time.Local); err != nil {
return
}
xt.Scan(t)
return
}
// ParseApplyTime is.
func ParseApplyTime(ts string) xtime.Time {
ti, _ := strconv.ParseInt(ts, 10, 64)
return xtime.Time(ti)
}
// NewProfile is.
func NewProfile() *Profile {
return &Profile{}
}
// FaceRecordList is
type FaceRecordList []*FaceRecord
// Filter is
func (frl FaceRecordList) Filter(con func(*FaceRecord) bool) FaceRecordList {
res := make(FaceRecordList, 0)
for _, fr := range frl {
if con(fr) {
res = append(res, fr)
}
}
return res
}
// Paginate is
func (frl FaceRecordList) Paginate(skip int, size int) FaceRecordList {
if skip > len(frl) {
skip = len(frl)
}
end := skip + size
if end > len(frl) {
end = len(frl)
}
return frl[skip:end]
}
// FromExp is.
func (lv *Level) FromExp(e *Exp) {
exp := e.Exp / _expMulti
switch {
case exp < level1:
lv.CurrentLevel = 0
lv.CurrentMin = 0
lv.NextExp = level1
case exp < level2:
lv.CurrentLevel = 1
lv.CurrentMin = level1
lv.NextExp = level2
case exp < level3:
lv.CurrentLevel = 2
lv.CurrentMin = level2
lv.NextExp = level3
case exp < level4:
lv.CurrentLevel = 3
lv.CurrentMin = level3
lv.NextExp = level4
case exp < level5:
lv.CurrentLevel = 4
lv.CurrentMin = level4
lv.NextExp = level5
case exp < level6:
lv.CurrentLevel = 5
lv.CurrentMin = level5
lv.NextExp = level6
default:
lv.CurrentLevel = 6
lv.CurrentMin = level6
lv.NextExp = levelMax
}
lv.CurrentExp = int32(exp)
}

View File

@@ -0,0 +1,15 @@
package model
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuildFaceURL(t *testing.T) {
face := BuildFaceURL("/bfs/facepri/4a259f715b63157f24f76521231480438058436e.jpg")
u, err := url.Parse(face)
assert.Nil(t, err)
assert.NotNil(t, u.Query().Get("token"))
}

View File

@@ -0,0 +1,19 @@
package model
import (
xtime "go-common/library/time"
)
// Monitor is.
type Monitor struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
Operator string `json:"operator" gorm:"column:operator"`
Remark string `json:"remark" gorm:"column:remark"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
IsDeleted bool `json:"is_deleted" gorm:"column:is_deleted"`
// 昵称,后期拼进来
Name string `json:"name" gorm:"-"`
}

View File

@@ -0,0 +1,173 @@
package model
import (
"encoding/json"
xtime "go-common/library/time"
)
// official role const.
const (
OfficialRoleUnauth = iota
OfficialRoleUp
OfficialRoleIdentify
OfficialRoleBusiness
OfficialRoleGov
OfficialRoleMedia
OfficialRoleOther
)
// OfficialRoleName official role name.
func OfficialRoleName(role int8) string {
switch role {
case OfficialRoleUnauth:
return "未认证"
case OfficialRoleUp:
return "UP主认证"
case OfficialRoleIdentify:
return "身份认证"
case OfficialRoleBusiness:
return "企业认证"
case OfficialRoleGov:
return "政府认证"
case OfficialRoleMedia:
return "媒体认证"
case OfficialRoleOther:
return "其他认证"
}
return ""
}
// official state const.
const (
OfficialStateWait = iota
OfficialStatePass
OfficialStateNoPass
OfficialStateReWait
)
// OfficialStateName official state name.
func OfficialStateName(state int8) string {
switch state {
case OfficialStateWait:
return "待审核"
case OfficialStatePass:
return "审核通过"
case OfficialStateNoPass:
return "审核未通过"
case OfficialStateReWait:
return "待重新审核"
}
return ""
}
// all
var (
AllRoles = []int8{
OfficialRoleUnauth,
OfficialRoleUp,
OfficialRoleIdentify,
OfficialRoleBusiness,
OfficialRoleGov,
OfficialRoleMedia,
OfficialRoleOther,
}
AllStates = []int8{
OfficialStateWait,
OfficialStatePass,
OfficialStateNoPass,
OfficialStateReWait,
}
)
// Official is.
type Official struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
Role int8 `json:"role" gorm:"column:role"`
Title string `json:"title" gorm:"column:title"`
Desc string `json:"desc" gorm:"column:description"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
// 后台展示需求,需要查 official doc 对应的昵称
Name string `json:"name" gorm:"-"`
}
// OfficialDoc is.
type OfficialDoc struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
Name string `json:"name" gorm:"column:name"`
State int8 `json:"state" gorm:"column:state"`
Role int8 `json:"role" gorm:"column:role"`
Title string `json:"title" gorm:"column:title"`
Desc string `json:"desc" gorm:"column:description"`
Uname string `json:"uname" gorm:"column:uname"`
Extra string `json:"-" gorm:"column:extra"`
IsInternal bool `json:"is_internal" gorm:"column:is_internal"`
RejectReason string `json:"reject_reason" gorm:"column:reject_reason"`
SubmitSource string `json:"submit_source" gorm:"column:submit_source"`
SubmitTime xtime.Time `json:"submit_time" gorm:"column:submit_time"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
*OfficialExtra `gorm:"-"`
}
// OfficialExtra extra.
type OfficialExtra struct {
Realname int8 `json:"realname" gorm:"-"`
Operator string `json:"operator" gorm:"-"`
Telephone string `json:"telephone" gorm:"-"`
Email string `json:"email" gorm:"-"`
Address string `json:"address" gorm:"-"`
Company string `json:"company" gorm:"-"`
CreditCode string `json:"credit_code" gorm:"-"` // 社会信用代码
Organization string `json:"organization" gorm:"-"` // 政府或组织名称
OrganizationType string `json:"organization_type" gorm:"-"` // 政府或机构类型
BusinessLicense string `json:"business_license" gorm:"-"` // 企业营业执照
BusinessScale string `json:"business_scale" gorm:"-"` // 企业规模
BusinessLevel string `json:"business_level" gorm:"-"` // 行政级别
BusinessAuth string `json:"business_auth" gorm:"-"` // 企业授权函
Supplement string `json:"supplement" gorm:"-"` // 其他补充材料
Professional string `json:"professional" gorm:"-"` // 专业资质
Identification string `json:"identification" gorm:"-"` // 身份证明
OfficalSite string `json:"official_site" gorm:"-"` // 官方站点
RegisteredCapital string `json:"registered_capital" gorm:"-"` // 注册资本
}
// OfficialDocAddit .
type OfficialDocAddit struct {
Mid int64 `json:"mid" gorm:"mid"`
Property string `json:"property" gorm:"property"`
Vstring string `json:"vstring" gorm:"vstring"`
}
// ParseExtra parse extra.
func (oc *OfficialDoc) ParseExtra() {
oe := &OfficialExtra{}
if len(oc.Extra) > 0 {
json.Unmarshal([]byte(oc.Extra), oe)
}
oc.OfficialExtra = oe
}
// Validate is.
func (oc *OfficialDoc) Validate() bool {
if oc.Mid <= 0 ||
oc.Name == "" ||
oc.Role <= 0 ||
oc.Title == "" {
return false
}
return true
}
// String is
func (oe *OfficialExtra) String() string {
bs, _ := json.Marshal(oe)
if len(bs) == 0 {
bs = []byte("{}")
}
return string(bs)
}

View File

@@ -0,0 +1,25 @@
package model
// Page is.
type Page struct {
Num int `json:"num"`
Size int `json:"size"`
Total int `json:"total"`
}
// CommonPagination is.
type CommonPagination struct {
Page Page `json:"page"`
}
// MemberPagination is.
type MemberPagination struct {
Members interface{} `json:"members"`
*CommonPagination
}
// FaceRecordPagination is.
type FaceRecordPagination struct {
Records interface{} `json:"records"`
*CommonPagination
}

View File

@@ -0,0 +1,343 @@
package model
import (
"go-common/app/admin/main/member/model/block"
xtime "go-common/library/time"
)
// ArgMid is.
type ArgMid struct {
Mid int64 `form:"mid" validate:"min=1,required"`
}
// ArgMids is.
type ArgMids struct {
Mid []int64 `form:"mid,split" validate:"dive,gt=0"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
}
// ArgExpSet is.
type ArgExpSet struct {
Mid int64 `form:"mid" validate:"min=1"`
Exp float64 `form:"exp" validate:"required"`
Reason string `form:"reason" validate:"required"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
IP string `form:"ip"`
}
// ArgMoralSet is.
type ArgMoralSet struct {
Mid int64 `form:"mid" validate:"min=1"`
Moral float64 `form:"moral" validate:"required"`
Reason string `form:"reason" validate:"required"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
IP string `form:"ip"`
}
// ArgRankSet is.
type ArgRankSet struct {
Mid int64 `form:"mid" validate:"min=1"`
Rank int64 `form:"rank" validate:"required"`
Reason string `form:"reason" validate:"required"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
IP string `form:"ip"`
}
// ArgCoinSet is.
type ArgCoinSet struct {
Mid int64 `form:"mid" validate:"min=1"`
Coins float64 `form:"coins" validate:"required"`
Reason string `form:"reason" validate:"required"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
IP string `form:"ip"`
}
// ArgAdditRemarkSet is.
type ArgAdditRemarkSet struct {
Mid int64 `form:"mid" validate:"min=1"`
Remark string `form:"remark"`
}
// ArgBaseReview is.
type ArgBaseReview struct {
Mid []int64 `form:"mid,split"`
StartMid int64 `form:"start_mid" validate:"min=0"`
EndMid int64 `form:"end_mid" validate:"min=0"`
}
// Mids mid list.
func (amr *ArgBaseReview) Mids() []int64 {
mids := amr.Mid
for i := amr.StartMid; i <= amr.EndMid; i++ {
mids = append(mids, i)
}
return mids
}
// ArgList is.
type ArgList struct {
Mid int64 `form:"mid"`
Keyword string `form:"keyword"`
PN int64 `form:"pn"`
PS int64 `form:"ps"`
}
// ArgOfficial is.
type ArgOfficial struct {
Mid int64 `form:"mid"`
Role []int64 `form:"role,split"`
STime xtime.Time `form:"stime"`
ETime xtime.Time `form:"etime"`
Pn int `form:"pn"`
Ps int `form:"ps"`
}
// ArgOfficialDoc is.
type ArgOfficialDoc struct {
Mid int64 `form:"mid"`
Role []int64 `form:"role,split"`
State []int64 `form:"state,split"`
STime xtime.Time `form:"stime"`
ETime xtime.Time `form:"etime"`
Uname string `form:"uname"`
Pn int `form:"pn"`
Ps int `form:"ps"`
}
// ArgOfficialAudit is.
type ArgOfficialAudit struct {
Mid int64 `form:"mid" validate:"min=1"`
State int8 `form:"state" validate:"min=1"`
UID int64 `form:"uid" validate:"min=1"`
Uname string `form:"uname" validate:"min=1"`
Reason string `form:"reason"`
Source string `form:"source"`
IsInternal bool `form:"is_internal"`
}
// ArgOfficialEdit is.
type ArgOfficialEdit struct {
Mid int64 `form:"mid" validate:"min=1,required"`
Role int8 `form:"role" validate:"min=0"`
Name string `form:"name" validate:"gt=1,required"`
Title string `form:"title" validate:"gt=1,required"`
Desc string `form:"desc"`
// extra
Telephone string `form:"telephone"`
Email string `form:"email"`
Address string `form:"address"`
Supplement string `form:"supplement"`
Company string `form:"company"`
Operator string `form:"operator"`
CreditCode string `form:"credit_code"`
Organization string `form:"organization"`
OrganizationType string `form:"organization_type"`
BusinessLicense string `form:"business_license"`
BusinessScale string `form:"business_scale"`
BusinessLevel string `form:"business_level"`
BusinessAuth string `form:"business_auth"`
OfficalSite string `form:"official_site"`
RegisteredCapital string `form:"registered_capital"`
SendMessage bool `form:"send_msg"`
MessageTitle string `form:"msg_title"`
MessageContent string `form:"msg_content"`
UID int64 `form:"uid" validate:"min=1"`
Uname string `form:"uname" validate:"min=1"`
IsInternal bool `form:"is_internal"`
}
// ArgOfficialSubmit arg submit official doc
type ArgOfficialSubmit struct {
Mid int64 `form:"mid"`
Name string `form:"name"`
Role int8 `form:"role"`
Title string `form:"title"`
Desc string `form:"desc"`
// extra
Realname int8 `form:"realname"`
Operator string `form:"operator"`
Telephone string `form:"telephone"`
Email string `form:"email"`
Address string `form:"address"`
Company string `form:"company"`
CreditCode string `form:"credit_code"` // 社会信用代码
Organization string `form:"organization"` // 政府或组织名称
OrganizationType string `form:"organization_type"` // 组织或机构类型
BusinessLicense string `form:"business_license"` // 企业营业执照
BusinessScale string `form:"business_scale"` // 企业规模
BusinessLevel string `form:"business_level"` // 企业登记
BusinessAuth string `form:"business_auth"` // 企业授权函
Supplement string `form:"supplement"` // 其他补充材料
Professional string `form:"professional"` // 专业资质
Identification string `form:"identification"` // 身份证明
OfficalSite string `form:"official_site"`
RegisteredCapital string `form:"registered_capital"`
UID int64 `form:"uid"`
Uname string `form:"uname"`
IsInternal bool `form:"is_internal"`
SubmitSource string `form:"submit_source"`
}
// ArgFaceHistory is.
type ArgFaceHistory struct {
Mid int64 `form:"mid"`
Operator string `form:"operator"`
Status []int8 `form:"status,split"`
STime xtime.Time `form:"stime" validate:"min=0"`
ETime xtime.Time `form:"etime" validate:"min=0"`
PS int `form:"ps" validate:"min=0,max=50"`
PN int `form:"pn" validate:"min=0"`
}
// ArgMonitor is.
type ArgMonitor struct {
Mid int64 `form:"mid"`
Pn int `form:"pn"`
Ps int `form:"ps"`
}
// ArgAddMonitor is.
type ArgAddMonitor struct {
Mid int64 `form:"mid" validate:"min=1,required"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
Remark string `form:"remark"`
}
// ArgDelMonitor is.
type ArgDelMonitor struct {
Mid int64 `form:"mid" validate:"min=1,required"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
Remark string `form:"remark"`
}
// ArgReviewList is.
type ArgReviewList struct {
Mid int64 `form:"mid"`
Property []int8 `form:"property,split"`
Operator string `form:"operator"`
State []int8 `form:"state,split"`
IsDesc bool `form:"is_desc"`
IsMonitor bool `form:"is_monitor"`
ForceDB bool `form:"force_db"`
STime xtime.Time `form:"stime" validate:"min=0"`
ETime xtime.Time `form:"etime" validate:"min=0"`
Ps int `form:"ps" validate:"min=0,max=50"`
Pn int `form:"pn" validate:"min=0"`
}
// ArgReviewAudit is.
type ArgReviewAudit struct {
ID []int64 `form:"id,split" validate:"dive,gt=0"`
State int8 `form:"state" validate:"min=1"`
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
Remark string `form:"remark"`
BlockUser bool `form:"block_user"`
//for block
ArgBatchBlock
}
// ArgBatchBlock .
type ArgBatchBlock struct {
Source block.BlockMgrSource `form:"block_source"`
Area block.BlockArea `form:"block_area"`
Reason string `form:"block_reason"`
Comment string `form:"block_comment"`
Action block.BlockAction `form:"block_action"`
Duration int64 `form:"block_duration"` // 单位:天
Notify bool `form:"block_notify"`
}
// Validate .
func (p *ArgBatchBlock) Validate() bool {
// p.MIDs = intsSet(p.MIDs)
// if len(p.MIDs) == 0 || len(p.MIDs) > 200 {
// return false
// }
// if p.AdminID <= 0 {
// return false
// }
// if p.AdminName == "" {
// return false
// }
if p.Source != block.BlockMgrSourceSys && p.Source != block.BlockMgrSourceCredit {
return false
}
if !p.Area.Contain() {
return false
}
if p.Comment == "" {
return false
}
if p.Action != block.BlockActionForever && p.Action != block.BlockActionLimit {
return false
}
if p.Action == block.BlockActionLimit {
if p.Duration <= 0 {
return false
}
}
return true
}
// ArgReview is.
type ArgReview struct {
ID int64 `form:"id" validate:"min=1"`
}
// ArgPubExpMsg is.
type ArgPubExpMsg struct {
Event string `form:"event" validate:"min=1,required"`
Mid int64 `form:"mid" validate:"min=1,required"`
IP string `form:"ip"`
Ts int64 `form:"ts"`
}
// Mode is.
func (a *ArgFaceHistory) Mode() string {
if a.Mid > 0 && a.Operator != "" {
return "op"
}
if a.Mid > 0 {
return "mid"
}
return "op"
}
// ArgBatchFormal is
type ArgBatchFormal struct {
FileData []byte
Operator string `form:"operator"`
OperatorID int64 `form:"operator_id"`
}
// ArgRealnameSubmit is
type ArgRealnameSubmit struct {
Mid int64 `form:"mid" validate:"required"`
Realname string `form:"realname" validate:"required"`
CardType int8 `form:"card_type"`
CardNum string `form:"card_num" validate:"required"`
Country int16 `form:"country"`
FrontImageToken string `form:"front_image_token" validate:"required"`
BackImageToken string `form:"back_image_token" validate:"required"`
HandImageToken string `form:"hand_image_token"`
Operator string `form:"operator" validate:"required"`
OperatorID int64 `form:"operator_id" validate:"required"`
Remark string `form:"remark" validate:"required"`
}

View File

@@ -0,0 +1,612 @@
package model
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"strconv"
"strings"
"time"
"go-common/app/admin/main/member/conf"
memmdl "go-common/app/service/main/member/model"
"go-common/library/log"
xtime "go-common/library/time"
"github.com/pkg/errors"
)
// realname conf var
var (
RealnameSalt = "biliidentification@#$%^&*()(*&^%$#"
RealnameImgPrefix = "/idenfiles/"
RealnameImgSuffix = ".txt"
LogActionRealnameUnbind = "realname_unbind"
LogActionRealnameBack = "realname_back"
LogActionRealnameSubmit = "realname_submit"
RealnameManagerLogID = 251
)
type realnameChannel string
// RealnameChannle
const (
ChannelMain realnameChannel = "main"
ChannelAlipay realnameChannel = "alipay"
)
func (ch realnameChannel) DBChannel() uint8 {
switch ch {
case ChannelMain:
return 0
case ChannelAlipay:
return 1
}
return 0
}
type realnameAction string
// RealnameAction
const (
RealnameActionPass realnameAction = "pass"
RealnameActionReject realnameAction = "reject"
)
// RealnameCardType is.
type RealnameCardType string
const (
cardTypeIdentityCard RealnameCardType = "identity_card"
cardTypeForeignPassport RealnameCardType = "foreign_passport"
//Mainland Travel Permit for Hong Kong and Macao Residents
cardTypeHongkongMacaoPermit RealnameCardType = "hongkong_macao_travel_permit"
//Mainland travel permit for Taiwan residents
cardTypeTaiwanPermit RealnameCardType = "taiwan_travel_permit"
cardTypeChinaPassport RealnameCardType = "china_passport"
//Foreigner's Permanent Residence Card
cardTypeForeignerPermanentResidenceCard RealnameCardType = "foreigner_permanent_residence_card"
cardTypeForeignIdentityCard RealnameCardType = "foreign_identity_card"
)
// RealnameApplyStatus is.
type RealnameApplyStatus string
// RealnameApplyStatus
const (
RealnameApplyStateAll RealnameApplyStatus = "all"
RealnameApplyStatePending RealnameApplyStatus = "pending"
RealnameApplyStatePassed RealnameApplyStatus = "passed"
RealnameApplyStateRejective RealnameApplyStatus = "rejective"
RealnameApplyStateNone RealnameApplyStatus = "none"
)
// DBStatus is.
func (r RealnameApplyStatus) DBStatus() int {
switch r {
case RealnameApplyStatePending:
return 0
case RealnameApplyStatePassed:
return 1
case RealnameApplyStateRejective:
return 2
default:
return -1
}
}
// ArgRealnameList is.
type ArgRealnameList struct {
Channel realnameChannel `form:"channel" validate:"required"`
MID int64 `form:"mid"`
Card string `form:"card"`
CardType RealnameCardType `form:"card_type"`
Country int `form:"country"`
OPName string `form:"op_name"`
TSFrom int64 `form:"ts_from"`
TSTo int64 `form:"ts_to"`
State RealnameApplyStatus `form:"state"`
PS int `form:"ps"`
PN int `form:"pn"`
IsDesc bool `form:"is_desc"`
}
// DBCardType return card_type store in db
func (a *ArgRealnameList) DBCardType() int {
switch a.CardType {
case cardTypeIdentityCard:
return 0
case cardTypeForeignPassport:
return 1
case cardTypeHongkongMacaoPermit:
return 2
case cardTypeTaiwanPermit:
return 3
case cardTypeChinaPassport:
return 4
case cardTypeForeignerPermanentResidenceCard:
return 5
case cardTypeForeignIdentityCard:
return 6
default:
log.Warn("ArgRealnameList : %+v , unknown CardType", a)
return -1
}
}
// DBCountry return country store in db
func (a *ArgRealnameList) DBCountry() int {
if a.CardType == "" {
return -1
}
return a.Country
}
// DBState return state store in db
func (a *ArgRealnameList) DBState() int {
switch a.State {
case RealnameApplyStateAll:
return -1
case RealnameApplyStatePending:
return 0
case RealnameApplyStatePassed:
return 1
case RealnameApplyStateRejective:
return 2
case RealnameApplyStateNone:
return 3
default:
log.Warn("ArgRealnameList : %+v , unknown State", a)
return 0
}
}
// ArgRealnamePendingList is.
type ArgRealnamePendingList struct {
Channel realnameChannel `form:"channel" validate:"required"`
PS int `form:"ps"`
PN int `form:"pn"`
}
// ArgRealnameAuditApply is.
type ArgRealnameAuditApply struct {
ID int64 `form:"id" validate:"required"`
Channel realnameChannel `form:"channel" validate:"required"`
Action realnameAction `form:"action" validate:"required"`
Reason string `form:"reason"`
}
// DBChannel return channel store in db
func (a *ArgRealnameAuditApply) DBChannel() int {
switch a.Channel {
case ChannelMain:
return 0
case ChannelAlipay:
return 1
default:
log.Warn("ArgRealnameAuditApply : %+v , unknown Channel", a)
return 0
}
}
// ArgRealnameReasonList is.
type ArgRealnameReasonList struct {
PS int `form:"ps"`
PN int `form:"pn"`
}
// ArgRealnameSetReason is.
type ArgRealnameSetReason struct {
Reasons []string `form:"reasons,split"`
}
// ArgRealnameImage is.
type ArgRealnameImage struct {
Token string `form:"token" validate:"required"`
}
// ArgRealnameImagePreview is.
type ArgRealnameImagePreview struct {
ArgRealnameImage
BorderSize uint `form:"border_size"` // 图片最大边长度(缩放后)
}
// ArgRealnameSearchCard is.
type ArgRealnameSearchCard struct {
Cards []string `form:"cards,split" validate:"required"`
CardType int `form:"card_type"`
Country int `form:"card_type"`
}
// RespRealnameApply is.
type RespRealnameApply struct {
ID int64 `json:"id"`
Channel realnameChannel `json:"channel"`
MID int64 `json:"mid"`
Nickname string `json:"nickname"`
Times int `json:"times"`
CardType RealnameCardType `json:"card_type"`
Country int16 `json:"country"`
Card string `json:"card"`
Realname string `json:"realname"`
Level int32 `json:"level"`
IMGIDs []int64 `json:"-"`
IMGs []string `json:"imgs"`
State RealnameApplyStatus `json:"state"`
OPName string `json:"op_name"`
OPTS int64 `json:"op_ts"`
OPReason string `json:"op_reason"`
CreateTS int64 `json:"create_ts"`
}
// ParseDBMainApply parse realname_apply from db
func (r *RespRealnameApply) ParseDBMainApply(db *DBRealnameApply) {
var err error
r.ID = db.ID
r.Channel = ChannelMain
r.MID = db.MID
r.CardType = r.convertCardType(db.CardType)
r.Country = db.Country
if db.CardNum != "" {
if r.Card, err = CardDecrypt(db.CardNum); err != nil {
log.Error("%+v", err)
}
}
r.IMGIDs = append(r.IMGIDs, db.HandIMG, db.FrontIMG, db.BackIMG)
r.Realname = db.Realname
r.State = r.ParseStatus(db.Status)
r.OPName = db.Operator
r.OPTS = db.OperatorTime.Unix()
r.OPReason = db.Remark
r.CreateTS = db.CTime.Unix()
}
// ParseDBAlipayApply parse realname_alipay_apply from db
func (r *RespRealnameApply) ParseDBAlipayApply(db *DBRealnameAlipayApply) {
var err error
r.ID = db.ID
r.Channel = ChannelAlipay
r.MID = db.MID
r.CardType = cardTypeIdentityCard // identity_card
r.Country = 0 // china
if db.Card != "" {
if r.Card, err = CardDecrypt(db.Card); err != nil {
log.Error("%+v", err)
}
}
r.ParseDBApplyIMG(db.IMG)
r.Realname = db.Realname
r.State = r.ParseStatus(db.Status)
r.OPName = "alipay"
if db.Operator != "" {
r.OPName = db.Operator
}
r.OPTS = db.OperatorTime.Unix()
r.OPReason = db.Reason
r.CreateTS = db.CTime.Unix()
}
// ParseDBApplyIMG parse apply_img from db
func (r *RespRealnameApply) ParseDBApplyIMG(token string) {
r.IMGs = append(r.IMGs, imgURL(token))
}
// ParseMember parse member info from rpc call
func (r *RespRealnameApply) ParseMember(mem *memmdl.Member) {
r.Nickname = mem.Name
r.Level = mem.LevelInfo.Cur
}
func imgURL(token string) string {
token = strings.TrimPrefix(token, "/idenfiles/")
token = strings.TrimSuffix(token, ".txt")
return fmt.Sprintf(conf.Conf.Realname.ImageURLTemplate, token)
}
// ParseStatus parse status stored in db
func (r *RespRealnameApply) ParseStatus(status int) (s RealnameApplyStatus) {
switch status {
case 0:
return RealnameApplyStatePending
case 1:
return RealnameApplyStatePassed
case 2:
return RealnameApplyStateRejective
default:
log.Warn("RespRealnameApply parse status err , unknown apply status :%d", status)
return RealnameApplyStateNone
}
}
// ConvertCardType convert card_type from db to api
func (r *RespRealnameApply) convertCardType(cardType int8) (t RealnameCardType) {
switch cardType {
case 0:
return cardTypeIdentityCard
case 1:
return cardTypeForeignPassport
case 2:
return cardTypeHongkongMacaoPermit
case 3:
return cardTypeTaiwanPermit
case 4:
return cardTypeChinaPassport
case 5:
return cardTypeForeignerPermanentResidenceCard
case 6:
return cardTypeForeignIdentityCard
default:
log.Warn("RespRealnameApply parse card type err , unknown card type :%d", cardType)
return cardTypeIdentityCard
}
}
// DBRealnameInfo is.
type DBRealnameInfo struct {
ID int64 `gorm:"column:id"`
MID int64 `gorm:"column:mid"`
Channel uint8 `gorm:"column:channel"`
Realname string `gorm:"column:realname"`
Country int16 `gorm:"column:country"`
CardType int8 `gorm:"column:card_type"`
Card string `gorm:"column:card"`
CardMD5 string `gorm:"column:card_md5"`
Status int `gorm:"column:status"`
Reason string `gorm:"column:reason"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}
// TableName is...
func (d *DBRealnameInfo) TableName() string {
return "realname_info"
}
// DBRealnameApply is.
type DBRealnameApply struct {
ID int64 `gorm:"column:id"`
MID int64 `gorm:"column:mid"`
Realname string `gorm:"column:realname"`
Country int16 `gorm:"column:country"`
CardType int8 `gorm:"column:card_type"`
CardNum string `gorm:"column:card_num"`
CardMD5 string `gorm:"column:card_md5"`
HandIMG int64 `gorm:"column:hand_img"`
FrontIMG int64 `gorm:"column:front_img"`
BackIMG int64 `gorm:"column:back_img"`
Status int `gorm:"column:status"`
Operator string `gorm:"column:operator"`
OperatorID int64 `gorm:"column:operator_id"`
OperatorTime time.Time `gorm:"column:operator_time"`
Remark string `gorm:"column:remark"`
RemarkStatus int8 `gorm:"column:remark_status"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}
// TableName is...
func (d *DBRealnameApply) TableName() string {
return "realname_apply"
}
// DBRealnameAlipayApply is.
type DBRealnameAlipayApply struct {
ID int64 `gorm:"column:id"`
MID int64 `gorm:"column:mid"`
Realname string `gorm:"column:realname"`
Card string `gorm:"column:card"`
IMG string `gorm:"column:img"`
Status int `gorm:"column:status"`
Reason string `gorm:"column:reason"`
Bizno string `gorm:"column:bizno"`
Operator string `gorm:"column:operator"`
OperatorID int64 `gorm:"column:operator_id"`
OperatorTime time.Time `gorm:"column:operator_time"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}
// TableName is...
func (d *DBRealnameAlipayApply) TableName() string {
return "realname_alipay_apply"
}
// IsPassed is...
func (d *DBRealnameApply) IsPassed() bool {
return d.Status == 1
}
// DBRealnameApplyIMG is.
type DBRealnameApplyIMG struct {
ID int64 `gorm:"column:id"`
IMGData string `gorm:"column:img_data"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}
// TableName ...
func (d *DBRealnameApplyIMG) TableName() string {
return "realname_apply_img"
}
// DBRealnameConfig ...
type DBRealnameConfig struct {
ID int64 `gorm:"column:id"`
Key string `gorm:"column:key"`
Data string `gorm:"column:data"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}
// TableName ...
func (d *DBRealnameConfig) TableName() string {
return "realname_config"
}
// CardDecrypt is
func CardDecrypt(data string) (text string, err error) {
var (
dataBytes = []byte(data)
decryptedData []byte
textBytes []byte
size int
)
decryptedData = make([]byte, base64.StdEncoding.DecodedLen(len(dataBytes)))
if size, err = base64.StdEncoding.Decode(decryptedData, dataBytes); err != nil {
err = errors.Wrapf(err, "base decode %s", data)
return
}
if textBytes, err = rsaDecrypt(decryptedData[:size]); err != nil {
err = errors.Wrapf(err, "rsa decrypt %s , data : %s", decryptedData, data)
return
}
text = string(textBytes)
return
}
func rsaDecrypt(text []byte) (content []byte, err error) {
block, _ := pem.Decode(conf.Conf.Realname.RsaPriv)
if block == nil {
err = errors.New("private key error")
return
}
var (
privateKey *rsa.PrivateKey
)
if privateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes); err != nil {
err = errors.WithStack(err)
return
}
if content, err = rsa.DecryptPKCS1v15(rand.Reader, privateKey, text); err != nil {
err = errors.WithStack(err)
return
}
return
}
// DBRealnameAuditLog is.
type DBRealnameAuditLog struct {
ID int64 `gorm:"column:id"`
MID int64 `gorm:"column:mid"`
AdminID int64 `gorm:"column:admin_id"`
AdminName string `gorm:"column:admin_name"`
Channel uint8 `gorm:"column:channel"`
FromState int `gorm:"column:from_state"`
ToState int `gorm:"column:to_state"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}
// Tablename is.
func (d *DBRealnameAuditLog) Tablename() string {
return "realname_audit_log"
}
// Realname is.
type Realname struct {
State RealnameApplyStatus `json:"state"`
Channel realnameChannel `json:"moral"`
Card string `json:"card"`
CardType int8 `json:"card_type"`
Country int16 `json:"country"`
Realname string `json:"realname"`
Images []string `json:"images"`
}
// ParseDBApplyIMG parse apply_img from db
func (r *Realname) ParseDBApplyIMG(token string) {
r.Images = append(r.Images, imgURL(token))
}
// ParseInfo .
func (r *Realname) ParseInfo(info *DBRealnameInfo) {
switch info.Status {
case 0:
r.State = RealnameApplyStatePending
case 1:
r.State = RealnameApplyStatePassed
case 2:
r.State = RealnameApplyStateRejective
default:
log.Warn("Realname status err , unknown info status :%d", info.Status)
r.State = RealnameApplyStateNone
}
switch info.Channel {
case 0:
r.Channel = ChannelMain
case 1:
r.Channel = ChannelAlipay
default:
log.Warn("Realname channel err , unknown info channel :%d", info.Channel)
r.Channel = ChannelMain
}
r.Realname = info.Realname
r.CardType = info.CardType
r.Country = info.Country
var err error
var maskedCard string
if info.Card != "" && r.State == RealnameApplyStatePassed {
if r.Card, err = CardDecrypt(info.Card); err != nil {
log.Error("%+v", err)
}
var (
cStrs = strings.Split(r.Card, "")
)
if len(cStrs) > 0 {
if len(cStrs) == 1 {
maskedCard = "*"
} else if len(cStrs) > 5 {
maskedCard = cStrs[0] + strings.Repeat("*", len(cStrs)-3) + strings.Join(cStrs[len(cStrs)-2:], "")
} else {
maskedCard = cStrs[0] + strings.Repeat("*", len(cStrs)-1)
}
}
r.Card = maskedCard
}
}
// RealnameExport is.
type RealnameExport struct {
Mid int64 `json:"mid" gorm:"column:mid"`
UserID string `json:"userid" gorm:"column:userid"`
Uname string `json:"uname" gorm:"column:uname"`
Realname string `json:"realname" gorm:"column:realname"`
Tel string `json:"tel" gorm:"column:tel"`
CardType int8 `json:"card_type" gorm:"column:card_type"`
CardNum string `json:"card_num" gorm:"column:card_num"`
}
// PassportQueryByMidResult is.
type PassportQueryByMidResult struct {
Mid int64 `json:"mid"`
Name string `json:"name"`
Userid string `json:"userid"`
Email string `json:"email"`
Tel string `json:"tel"`
Jointime xtime.Time `json:"jointime"`
}
var _cardTypeToString = map[int8]string{
0: "身份证",
1: "护照(境外签发)",
2: "港澳居民来往内地通行证",
3: "台湾居民来往大陆通行证",
4: "护照(中国签发)",
5: "外国人永久居留证",
6: "其他国家或地区身份证",
}
// CardTypeString is
func CardTypeString(cardType int8) string {
typeString, ok := _cardTypeToString[cardType]
if !ok {
return strconv.FormatInt(int64(cardType), 10)
}
return typeString
}

View File

@@ -0,0 +1,41 @@
package model
import (
"time"
)
// DeDeIdentificationCardApplyImg is.
type DeDeIdentificationCardApplyImg struct {
ID int64 `gorm:"column:id"`
IMGData string `gorm:"column:img_data"`
AddTime time.Time `gorm:"column:add_time"`
}
// TableName is
func (d *DeDeIdentificationCardApplyImg) TableName() string {
return "dede_identification_card_apply_img"
}
// DeDeIdentificationCardApply is
type DeDeIdentificationCardApply struct {
ID int64 `gorm:"column:id"`
MID int64 `gorm:"column:mid"`
Realname string `gorm:"column:realname"`
Type int8 `gorm:"column:type"`
CardData string `gorm:"column:card_data"`
CardForSearch string `gorm:"column:card_for_search"`
FrontImg int64 `gorm:"column:front_img"`
FrontImg2 int64 `gorm:"column:front_img2"`
BackImg int64 `gorm:"column:back_img"`
ApplyTime int32 `gorm:"column:apply_time"`
Operator string `gorm:"column:operater"`
OperatorTime int32 `gorm:"column:operater_time"`
Status int8 `gorm:"column:status"`
Remark string `gorm:"column:remark"`
RemarkStatus int8 `gorm:"column:remark_status"`
}
// TableName is
func (d *DeDeIdentificationCardApply) TableName() string {
return "dede_identification_card_apply"
}

View File

@@ -0,0 +1,101 @@
package model
import (
"encoding/json"
"fmt"
"go-common/app/admin/main/member/model/block"
"go-common/library/log"
xtime "go-common/library/time"
)
// review state const.
const (
ReviewStateWait = iota
ReviewStatePass
ReviewStateNoPass
ReviewStateArchived
ReviewStateQueuing = 10
)
// review property const.
const (
ReviewProperty = iota
ReviewPropertyFace
ReviewPropertySign
ReviewPropertyName
)
// all
var (
AllReviewStates = []int8{
ReviewStateWait,
ReviewStatePass,
ReviewStateNoPass,
ReviewStateQueuing,
}
)
// UserPropertyReview is
type UserPropertyReview struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
Old string `json:"old" gorm:"column:old"`
New string `json:"new" gorm:"column:new"`
State int8 `json:"state" gorm:"column:state"`
Property int8 `json:"property" gorm:"column:property"`
Remark string `json:"remark" gorm:"column:remark"`
Operator string `json:"operator" gorm:"column:operator"`
IsMonitor bool `json:"is_monitor" gorm:"column:is_monitor"`
Extra string `json:"extra" gorm:"column:extra"`
CTime xtime.Time `json:"ctime" gorm:"column:ctime"`
MTime xtime.Time `json:"mtime" gorm:"column:mtime"`
// 昵称,展示用
Name string `json:"name" gorm:"-"`
FaceReject int64 `json:"face_reject" gorm:"-"`
Block *block.BlockDetail `json:"block" gorm:"-"`
Follower int64 `json:"follower" gorm:"-"`
}
// Extra is.
type Extra struct {
NickFree bool `json:"nick_free"`
}
// NickFree nick free.
func (r *UserPropertyReview) NickFree() bool {
if len(r.Extra) == 0 {
return false
}
ext := Extra{}
if err := json.Unmarshal([]byte(r.Extra), &ext); err != nil {
log.Error("Failed to unmarshal extra, userPropertyReview: %+v error: %v", r, err)
return false
}
return ext.NickFree
}
// FaceCheckRes is.
type FaceCheckRes struct {
Blood float64 `json:"blood,omitempty"`
Violent float64 `json:"violent,omitempty"`
Sex float64 `json:"sex,omitempty"`
Politics float64 `json:"politics,omitempty"`
}
// Valid is.
func (fcr *FaceCheckRes) Valid() bool {
return fcr.Sex < 0.19 && fcr.Politics < 0.5 && fcr.Blood < 0.5 && fcr.Violent < 0.5
}
// String is.
func (fcr *FaceCheckRes) String() string {
return fmt.Sprintf("Sex: %.4f, Politics: %.4f", fcr.Sex, fcr.Politics)
}
//BuildFaceURL buildFaceUrl.
func (r *UserPropertyReview) BuildFaceURL() {
r.Old = BuildFaceURL(r.Old)
r.New = BuildFaceURL(r.New)
}

View File

@@ -0,0 +1,77 @@
package model
// SearchMemberResult is.
type SearchMemberResult struct {
Order string `json:"order"`
Sort string `json:"sort"`
Result []struct {
Mid int64 `json:"mid"`
Name string `json:"name"`
} `json:"result"`
Page Page `json:"page"`
}
// Mids is.
func (r *SearchMemberResult) Mids() []int64 {
mids := make([]int64, 0, len(r.Result))
for _, r := range r.Result {
mids = append(mids, r.Mid)
}
return mids
}
// Pagination is.
func (r *SearchMemberResult) Pagination() *CommonPagination {
return &CommonPagination{
Page: r.Page,
}
}
// SearchUserPropertyReviewResult is.
type SearchUserPropertyReviewResult struct {
Order string `json:"order"`
Sort string `json:"sort"`
Result []struct {
ID int64 `json:"id"`
} `json:"result"`
Page Page `json:"page"`
}
// IDs is.
func (r *SearchUserPropertyReviewResult) IDs() []int64 {
ids := make([]int64, 0, len(r.Result))
for _, r := range r.Result {
ids = append(ids, r.ID)
}
return ids
}
// Total is.
func (r *SearchUserPropertyReviewResult) Total() int {
return r.Page.Total
}
// SearchLogResult is.
type SearchLogResult struct {
Order string `json:"order"`
Sort string `json:"sort"`
Result []AuditLog `json:"result"`
Page Page `json:"page"`
}
// AuditLog is.
type AuditLog struct {
UID int64 `json:"uid"`
Uname string `json:"uname"`
OID int64 `json:"oid"`
Type int8 `json:"type"`
Action string `json:"action"`
Str0 string `json:"str_0"`
Str1 string `json:"str_1"`
Str2 string `json:"str_2"`
Int0 int `json:"int_0"`
Int1 int `json:"int_1"`
Int2 int `json:"int_2"`
Ctime string `json:"ctime"`
Extra string `json:"extra_data"`
}