first commit
This commit is contained in:
98
service/backend/model/biz/cdkbiz.go
Normal file
98
service/backend/model/biz/cdkbiz.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package biz
|
||||
|
||||
import (
|
||||
"gitlab.33.cn/chat/dtalk/service/backend/model/db"
|
||||
"gitlab.33.cn/chat/dtalk/service/backend/model/types"
|
||||
"gitlab.33.cn/utils/go-kit/convert"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 业务模型
|
||||
|
||||
// CdkType cdk 种类
|
||||
type CdkType struct {
|
||||
CdkId int64 `json:"cdkId,omitempty"`
|
||||
CdkName string `json:"cdkName,omitempty"`
|
||||
CoinName string `json:"coinName,omitempty"`
|
||||
ExchangeRate int64 `json:"exchangeRate,omitempty"`
|
||||
CdkInfo string `json:"cdkInfo,omitempty"`
|
||||
// 未发放的cdk数量
|
||||
CdkAvailable int64 `json:"cdkAvailable,omitempty"`
|
||||
// 已发放的cdk数量
|
||||
CdkUsed int64 `json:"cdkUsed,omitempty"`
|
||||
// 冻结状态中的cdk数量
|
||||
CdkFrozen int64 `json:"cdkFrozen,omitempty"`
|
||||
}
|
||||
|
||||
func (cdkType *CdkType) ToTypes() *types.CdkType {
|
||||
return &types.CdkType{
|
||||
CdkId: convert.ToString(cdkType.CdkId),
|
||||
CdkName: cdkType.CdkName,
|
||||
CoinName: cdkType.CoinName,
|
||||
ExchangeRate: cdkType.ExchangeRate,
|
||||
CdkInfo: cdkType.CdkInfo,
|
||||
CdkAvailable: cdkType.CdkAvailable,
|
||||
CdkUsed: cdkType.CdkUsed,
|
||||
CdkFrozen: cdkType.CdkFrozen,
|
||||
}
|
||||
}
|
||||
|
||||
// Cdk cdk 实例
|
||||
type Cdk struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
CdkId int64 `json:"cdkId,omitempty"`
|
||||
CdkContent string `json:"cdkContent,omitempty"`
|
||||
UserId string `json:"userId,omitempty"`
|
||||
CdkStatus int32 `json:"cdkStatus,omitempty"`
|
||||
OrderId int64 `json:"orderId,omitempty"`
|
||||
CreateTime int64 `json:"createTime"`
|
||||
UpdateTime int64
|
||||
ExchangeTime int64 `json:"exchangeTime"`
|
||||
}
|
||||
|
||||
func (cdk *Cdk) ToTypes() *types.Cdk {
|
||||
return &types.Cdk{
|
||||
Id: convert.ToString(cdk.Id),
|
||||
CdkId: convert.ToString(cdk.CdkId),
|
||||
CdkContent: cdk.CdkContent,
|
||||
UserId: cdk.UserId,
|
||||
CdkStatus: cdk.CdkStatus,
|
||||
OrderId: convert.ToString(cdk.OrderId),
|
||||
CreateTime: convert.ToString(cdk.CreateTime),
|
||||
ExchangeTime: convert.ToString(cdk.ExchangeTime),
|
||||
}
|
||||
}
|
||||
|
||||
func (cdk *Cdk) CheckUserId(userId string) bool {
|
||||
return cdk.UserId == userId
|
||||
}
|
||||
|
||||
func (cdk *Cdk) CheckFrozen() bool {
|
||||
return cdk.CdkStatus == db.CdkFrozen
|
||||
}
|
||||
|
||||
type CdkOrderMessage struct {
|
||||
PersonId string
|
||||
CdkId int64
|
||||
Number int64
|
||||
Done chan *CdkOrder
|
||||
}
|
||||
|
||||
func NewCdkOrderMessage(personId string, cdkId, number int64) *CdkOrderMessage {
|
||||
return &CdkOrderMessage{
|
||||
PersonId: personId,
|
||||
CdkId: cdkId,
|
||||
Number: number,
|
||||
Done: make(chan *CdkOrder),
|
||||
}
|
||||
}
|
||||
|
||||
type CdkOrder struct {
|
||||
Err error
|
||||
OrderId int64
|
||||
}
|
||||
|
||||
type ClearFrozenOrderMessage struct {
|
||||
OrderId int64
|
||||
Deadline time.Duration
|
||||
}
|
||||
8
service/backend/model/biz/tx.go
Normal file
8
service/backend/model/biz/tx.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package biz
|
||||
|
||||
type TxResult struct {
|
||||
Success bool
|
||||
To string
|
||||
Amount int64
|
||||
Symbol string
|
||||
}
|
||||
6
service/backend/model/const.go
Normal file
6
service/backend/model/const.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
PlatformChat33Pro = "Chat33Pro"
|
||||
Size = 20
|
||||
)
|
||||
47
service/backend/model/db/db.go
Normal file
47
service/backend/model/db/db.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package db
|
||||
|
||||
// 数据库模型
|
||||
// 持久化模型 PO
|
||||
|
||||
type TimeInfo struct {
|
||||
CreateTime int64
|
||||
UpdateTime int64
|
||||
DeleteTime int64
|
||||
}
|
||||
|
||||
type CdkType struct {
|
||||
CdkId int64
|
||||
CdkName string
|
||||
CdkInfo string
|
||||
CoinName string
|
||||
ExchangeRate int64
|
||||
TimeInfo
|
||||
}
|
||||
|
||||
type Cdk struct {
|
||||
Id int64
|
||||
CdkId int64
|
||||
CdkContent string
|
||||
UserId string
|
||||
CdkStatus int32
|
||||
OrderId int64
|
||||
TimeInfo
|
||||
ExchangeTime int64
|
||||
}
|
||||
|
||||
type CdkOrder struct {
|
||||
Id int64
|
||||
OrderId int64
|
||||
TransferHash string
|
||||
UserId string
|
||||
OrderStatus int32
|
||||
TimeInfo
|
||||
ExchangeTime int64
|
||||
}
|
||||
|
||||
const (
|
||||
CdkUnused = 0
|
||||
CdkFrozen = 1
|
||||
CdkUsed = 2
|
||||
CdkExchange = 3
|
||||
)
|
||||
201
service/backend/model/types/cdkhttp.go
Normal file
201
service/backend/model/types/cdkhttp.go
Normal file
@@ -0,0 +1,201 @@
|
||||
package types
|
||||
|
||||
type GeneralResponse struct {
|
||||
Result int `json:"result"`
|
||||
Message int `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// http 请求和返回
|
||||
|
||||
// CdkType cdk 种类
|
||||
type CdkType struct {
|
||||
CdkId string `json:"cdkId"`
|
||||
CdkName string `json:"cdkName"`
|
||||
CoinName string `json:"coinName"`
|
||||
ExchangeRate int64 `json:"exchangeRate"`
|
||||
CdkInfo string `json:"cdkInfo"`
|
||||
// 未发放的cdk数量
|
||||
CdkAvailable int64 `json:"cdkAvailable"`
|
||||
// 已发放的cdk数量
|
||||
CdkUsed int64 `json:"cdkUsed"`
|
||||
// 冻结状态中的cdk数量
|
||||
CdkFrozen int64 `json:"cdkFrozen"`
|
||||
}
|
||||
|
||||
// Cdk cdk 实例
|
||||
type Cdk struct {
|
||||
Id string `json:"id"`
|
||||
CdkId string `json:"cdkId"`
|
||||
CdkName string `json:"cdkName"`
|
||||
CdkContent string `json:"cdkContent"`
|
||||
UserId string `json:"userId"`
|
||||
CdkStatus int32 `json:"cdkStatus"`
|
||||
OrderId string `json:"orderId"`
|
||||
CreateTime string `json:"createTime"`
|
||||
ExchangeTime string `json:"exchangeTime"`
|
||||
}
|
||||
|
||||
// PageInfo 分页信息
|
||||
type PageInfo struct {
|
||||
// 页数
|
||||
Page int64 `json:"page"`
|
||||
// 每页数量
|
||||
PageSize int64 `json:"pageSize"`
|
||||
}
|
||||
|
||||
// -----------------------------backend-----------------------------
|
||||
|
||||
// CreateCdkTypeReq 创建 cdk 种类请求
|
||||
type CreateCdkTypeReq struct {
|
||||
CdkName string `json:"cdkName"`
|
||||
CoinName string `json:"coinName" binding:"required"`
|
||||
ExchangeRate int64 `json:"exchangeRate" binding:"required"`
|
||||
CdkInfo string `json:"cdkInfo"`
|
||||
}
|
||||
|
||||
// CreateCdkTypeResp 创建 cdk 种类响应
|
||||
type CreateCdkTypeResp struct {
|
||||
CdkId string `json:"cdkId"`
|
||||
}
|
||||
|
||||
// GetCdkTypesReq 查询 cdk 种类请求
|
||||
type GetCdkTypesReq struct {
|
||||
PageInfo
|
||||
CoinName string `json:"coinName"`
|
||||
}
|
||||
|
||||
// GetCdkTypesResp 查询 cdk 种类响应
|
||||
type GetCdkTypesResp struct {
|
||||
TotalElements int64 `json:"totalElements"`
|
||||
TotalPages int64 `json:"totalPages"`
|
||||
CdkTypes []*CdkType `json:"cdkTypes"`
|
||||
}
|
||||
|
||||
// CreateCdksReq 批量上传 cdk 请求
|
||||
type CreateCdksReq struct {
|
||||
CdkId string `json:"cdkId" binding:"required"`
|
||||
CdkContents []string `json:"cdkContents" binding:"required"`
|
||||
}
|
||||
|
||||
// CreateCdksResp 批量上传 cdk 响应
|
||||
type CreateCdksResp struct {
|
||||
}
|
||||
|
||||
// GetCdksReq 查询 cdk 实例请求
|
||||
type GetCdksReq struct {
|
||||
PageInfo
|
||||
CdkId string `json:"cdkId" binding:"required"`
|
||||
CdkContent string `json:"cdkContent"`
|
||||
}
|
||||
|
||||
// GetCdksResp 查询 cdk 实例响应
|
||||
type GetCdksResp struct {
|
||||
TotalElements int64 `json:"totalElements"`
|
||||
TotalPages int64 `json:"totalPages"`
|
||||
Cdks []*Cdk `json:"cdks"`
|
||||
}
|
||||
|
||||
// GetCdksWithCdkNameReq 根据 cdkName 查询 cdk 实例请求
|
||||
//type GetCdksWithCdkNameReq struct {
|
||||
// PageInfo
|
||||
// CdkName string `json:"cdkName"`
|
||||
//}
|
||||
|
||||
// GetCdksWithCdkNameResp 根据 cdkName 查询 cdk 实例响应
|
||||
//type GetCdksWithCdkNameResp struct {
|
||||
// TotalElements int64 `json:"totalElements"`
|
||||
// TotalPages int64 `json:"totalPages"`
|
||||
// Cdks []*Cdk `json:"cdks"`
|
||||
//}
|
||||
|
||||
// DeleteCdksReq 删除 cdk 实例请求
|
||||
type DeleteCdksReq struct {
|
||||
Ids []string `json:"ids" binding:"required"`
|
||||
}
|
||||
|
||||
// DeleteCdksResp 删除 cdk 实例响应
|
||||
type DeleteCdksResp struct {
|
||||
}
|
||||
|
||||
// DeleteCdkTypesReq 删除 cdkType 请求
|
||||
type DeleteCdkTypesReq struct {
|
||||
CdkIds []string `json:"cdkIds" binding:"required"`
|
||||
}
|
||||
|
||||
// DeleteCdkTypesResp 删除 cdkType 响应
|
||||
type DeleteCdkTypesResp struct {
|
||||
}
|
||||
|
||||
type UpdateCdkTypeReq struct {
|
||||
CdkId string `json:"cdkId" binding:"required"`
|
||||
CdkName string `json:"cdkName" binding:"required"`
|
||||
CoinName string `json:"coinName" binding:"required"`
|
||||
ExchangeRate int64 `json:"exchangeRate" binding:"required"`
|
||||
}
|
||||
|
||||
type UpdateCdkTypeResp struct {
|
||||
}
|
||||
|
||||
type ExchangeCdksReq struct {
|
||||
Ids []string `json:"ids" binding:"required"`
|
||||
}
|
||||
|
||||
type ExchangeCdksResp struct {
|
||||
}
|
||||
|
||||
// -----------------------------app-----------------------------
|
||||
|
||||
// GetCdksByUserIdReq 查询某人拥有的 cdk 实例请求
|
||||
type GetCdksByUserIdReq struct {
|
||||
PageInfo
|
||||
//CdkId string `json:"cdkId" binding:"required"`
|
||||
PersonId string `json:"-"`
|
||||
}
|
||||
|
||||
// GetCdksByUserIdResp 查询某人拥有的 cdk 实例响应
|
||||
type GetCdksByUserIdResp struct {
|
||||
TotalElements int64 `json:"totalElements"`
|
||||
TotalPages int64 `json:"totalPages"`
|
||||
Cdks []*Cdk `json:"cdks"`
|
||||
}
|
||||
|
||||
// GetCdkTypeByCoinNameReq 根据票券名称查询对应的 cdk 信息请求
|
||||
type GetCdkTypeByCoinNameReq struct {
|
||||
CoinName string `json:"coinName" binding:"required"`
|
||||
}
|
||||
|
||||
// GetCdkTypeByCoinNameResp 根据票券名称查询对应的 cdk 信息响应
|
||||
type GetCdkTypeByCoinNameResp struct {
|
||||
*CdkType
|
||||
}
|
||||
|
||||
// CreateCdkOrderReq 创建兑换券订单请求
|
||||
type CreateCdkOrderReq struct {
|
||||
PersonId string `json:"-"`
|
||||
// cdk 种类编号
|
||||
CdkId string `json:"cdkId" binding:"required"`
|
||||
// 兑换数量
|
||||
Number int64 `json:"number" binding:"required"`
|
||||
}
|
||||
|
||||
// CreateCdkOrderResp 创建兑换券订单响应
|
||||
type CreateCdkOrderResp struct {
|
||||
// 订单编号
|
||||
OrderId string `json:"orderId"`
|
||||
}
|
||||
|
||||
// DealCdkOrderReq 处理兑换券订单请求
|
||||
type DealCdkOrderReq struct {
|
||||
PersonId string `json:"-"`
|
||||
// 订单编号
|
||||
OrderId string `json:"orderId" binding:"required"`
|
||||
// 处理结果
|
||||
Result bool `json:"result"`
|
||||
// 转账记录 hash
|
||||
TransferHash string `json:"transferHash" binding:"required"`
|
||||
}
|
||||
|
||||
// DealCdkOrderResp 处理兑换券订单响应
|
||||
type DealCdkOrderResp struct {
|
||||
}
|
||||
76
service/backend/model/version.go
Normal file
76
service/backend/model/version.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"gitlab.33.cn/chat/dtalk/pkg/util"
|
||||
)
|
||||
|
||||
type Description []string
|
||||
|
||||
func (desc *Description) ToString() string {
|
||||
b, err := json.Marshal(desc)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func ConvertDescription(str string) (Description, error) {
|
||||
var desc Description
|
||||
err := json.Unmarshal([]byte(str), &desc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return desc, nil
|
||||
}
|
||||
|
||||
type VersionForm struct {
|
||||
Id int64 `json:"id"`
|
||||
Platform string `json:"platform"`
|
||||
Status int32 `json:"status"`
|
||||
DeviceType string `json:"deviceType"`
|
||||
VersionName string `json:"versionName"`
|
||||
VersionCode int64 `json:"versionCode"`
|
||||
Url string `json:"url"`
|
||||
Force bool `json:"force"`
|
||||
Description Description `json:"description"`
|
||||
OpeUser string `json:"opeUser"`
|
||||
Md5 string `json:"md5"`
|
||||
Size int64 `json:"size"`
|
||||
UpdateTime int64 `json:"updateTime"`
|
||||
CreateTime int64 `json:"createTime"`
|
||||
}
|
||||
|
||||
func ConvertVersionForm(record *map[string]string) (*VersionForm, error) {
|
||||
description, err := ConvertDescription((*record)["description"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &VersionForm{
|
||||
Id: util.ToInt64((*record)["id"]),
|
||||
Platform: (*record)["platform"],
|
||||
Status: util.ToInt32((*record)["state"]),
|
||||
DeviceType: (*record)["device_type"],
|
||||
VersionName: (*record)["version_name"],
|
||||
VersionCode: util.ToInt64((*record)["version_code"]),
|
||||
Url: (*record)["download_url"],
|
||||
Force: util.ToBool((*record)["force_update"]),
|
||||
Description: description,
|
||||
OpeUser: (*record)["ope_user"],
|
||||
Md5: (*record)["md5"],
|
||||
Size: util.ToInt64((*record)["size"]),
|
||||
UpdateTime: util.ToInt64((*record)["update_time"]),
|
||||
CreateTime: util.ToInt64((*record)["create_time"]),
|
||||
}, nil
|
||||
}
|
||||
|
||||
type Claims struct {
|
||||
Username string `json:"username"`
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
type UserInfo struct {
|
||||
UserName string `json:"userName"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
17
service/backend/model/version_test.go
Normal file
17
service/backend/model/version_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_Marshal(t *testing.T) {
|
||||
var desc Description = []string{"1", "2"}
|
||||
|
||||
b, err := json.Marshal(&desc)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
t.Log("success", string(b))
|
||||
}
|
||||
78
service/backend/model/versionhttp.go
Normal file
78
service/backend/model/versionhttp.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package model
|
||||
|
||||
type VersionCreateRequest struct {
|
||||
Platform string `json:"platform"`
|
||||
Description []string `json:"description"`
|
||||
Force bool `json:"force"`
|
||||
Url string `json:"url"`
|
||||
VersionCode int64 `json:"versionCode"`
|
||||
VersionName string `json:"versionName"`
|
||||
DeviceType string `json:"deviceType"`
|
||||
OpeUser string `json:"opeUser"`
|
||||
Md5 string `json:"md5"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
type VersionUpdateRequest struct {
|
||||
Description []string `json:"description"`
|
||||
Force bool `json:"force"`
|
||||
Url string `json:"url"`
|
||||
VersionCode int64 `json:"versionCode"`
|
||||
VersionName string `json:"versionName"`
|
||||
Id int64 `json:"id"`
|
||||
OpeUser string `json:"opeUser"`
|
||||
Md5 string `json:"md5"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
type VersionChangeStatusRequest struct {
|
||||
Id int64 `json:"id"`
|
||||
OpeUser string `json:"opeUser"`
|
||||
}
|
||||
|
||||
type VersionCheckAndUpdateRequest struct {
|
||||
VersionCode int64 `form:"versionCode" json:"versionCode"`
|
||||
DeviceType string `json:"deviceType"`
|
||||
}
|
||||
|
||||
type GetVersionListRequest struct {
|
||||
Page int64 `json:"page"`
|
||||
Platform string `json:"platform"`
|
||||
DeviceType string `json:"deviceType"`
|
||||
}
|
||||
|
||||
type GetTokenRequest struct {
|
||||
UserName string `form:"userName" json:"userName"`
|
||||
Password string `form:"password" json:"password"`
|
||||
}
|
||||
|
||||
type VersionCreateResponse struct {
|
||||
Version VersionForm `json:"version"`
|
||||
}
|
||||
|
||||
type VersionUpdateResponse struct {
|
||||
Version VersionForm `json:"version"`
|
||||
}
|
||||
|
||||
type VersionChangeStatusResponse struct {
|
||||
VersionList []VersionForm `json:"versionList"`
|
||||
}
|
||||
|
||||
type VersionCheckAndUpdateResponse struct {
|
||||
VersionForm
|
||||
}
|
||||
|
||||
type GetVersionListResponse struct {
|
||||
TotalElements int64 `json:"totalElements"`
|
||||
TotalPages int64 `json:"totalPages"`
|
||||
VersionList []VersionForm `json:"versionList"`
|
||||
}
|
||||
|
||||
type GetTokenResponse struct {
|
||||
UserInfo UserInfoResponse `json:"userInfo"`
|
||||
}
|
||||
|
||||
type UserInfoResponse struct {
|
||||
UserName string `json:"userName"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
Reference in New Issue
Block a user