Commit f076c5b0 authored by shajiaiming's avatar shajiaiming

客户端app权限

parent 5d033468
package models
import (
"bwallet/pkg/setting"
"github.com/jinzhu/gorm"
"time"
)
type ClientApp struct {
Model
Type uint8 `gorm:"not null;default:0" json:"type"`
BundleId string `gorm:"type:varchar(128)" json:"bundle_id,omitempty"`
AppSignature string `gorm:"type:varchar(128)" json:"app_signature,omitempty"`
AppPackage string `gorm:"type:varchar(128)" json:"app_package,omitempty"`
AppSecret string `gorm:"type:varchar(128)" json:"app_secret,omitempty"`
CreatedAt int64 `gorm:"type:datetime" json:"created_at,omitempty"`
Deadline int64 `gorm:"type:datetime" json:"deadline,omitempty"`
}
func (a ClientApp) TableName() string {
return setting.DatabaseSetting.Name_Sources + ".wallet_client_app"
}
func GetClientApp(id int32) (*ClientApp, error) {
var app ClientApp
err := db.Where("id = ?", id).First(&app).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
err = db.Model(&app).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
return &app, nil
}
func ExistClientAppById(id int32) (bool, error) {
var app ClientApp
err := db.Select("id").Where("id = ?", id).First(&app).Error
if err != nil && err != gorm.ErrRecordNotFound {
return false, err
}
if app.ID > 0 {
return true, nil
}
return false, nil
}
func GetClientAppTotal(maps interface{}) (int, error) {
var count int
if err := db.Model(&ClientApp{}).Where(maps).Count(&count).Error; err != nil {
return 0, err
}
return count, nil
}
func GetClientApps(pageNum, pageSize int, maps interface{}) ([]*ClientApp, error) {
var app []*ClientApp
err := db.Where(maps).Order("created_at desc").Offset(pageNum).Limit(pageSize).Find(&app).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
return app, nil
}
func AddClientApp(data map[string]interface{}) (error) {
app := ClientApp{
Type: data["type"].(uint8),
BundleId: data["bundle_id"].(string),
AppSignature: data["app_signature"].(string),
AppPackage: data["app_package"].(string),
AppSecret: data["app_secret"].(string),
CreatedAt: time.Now().Unix(),
Deadline: data["deadline"].(int64),
}
if err := db.Create(&app).Error; err != nil {
return err
}
return nil
}
func EditClientApp(id int32, data interface{}) error {
if err := db.Model(&ClientApp{}).Where("id = ?", id).Updates(data).Error; err != nil {
return err
}
return nil
}
func DeleteClientApp(id int32) error {
if err := db.Where("id = ?", id).Delete(ClientApp{}).Error; err != nil {
return err
}
return nil
}
This diff is collapsed.
package app
import (
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"bwallet/service/client_app_service"
"github.com/gin-gonic/gin"
)
func AppSecret(c *gin.Context) {
arg := c.Query("secret")
if arg == "" {
handler.SendResponse(c, errno.ErrValidation, nil)
return
}
app_service := client_app_service.ClientApp{
AppSecret: arg,
PageNum: util.GetPage(c),
PageSize: util.GetLimit(c),
}
total, err := app_service.Count()
if err != nil {
handler.SendResponse(c, errno.ErrCountClientApp, nil)
return
}
if 0 == total {
handler.SendResponse(c, errno.ErrClientAppNotFound, nil)
return
}
app, err := app_service.GetAll()
if err != nil {
handler.SendResponse(c, errno.InternalServerError, nil)
return
}
handler.SendResponse(c, nil, app[0].Deadline)
}
......@@ -28,13 +28,15 @@ func InitRouter() *gin.Engine {
//r.POST("/upload", api.UploadImage)
client := r.Group("/interface")
client.Use(aes.Aes())
client.GET("/news", app.GetNews)
client.GET("/one-news", app.GetOneNews)
client.GET("/articles", app.GetArticle)
client.GET("/article", app.GetOneArticle)
client.GET("/live-categories", app.GetLiveCategories)
client.GET("/transaction-fee", app.GetTransactionFee)
client.GET("/secret", app.AppSecret)
client.Use(aes.Aes())
client.POST("/user", app.AddUser)
api := r.Group("/api")
......
package client_app_service
import (
"bwallet/models"
)
type ClientApp struct {
Id int32 `json:"omitempty"`
Type uint8 `json:"omitempty"`
BundleId string `json:"omitempty"`
AppSignature string `json:"omitempty"`
AppPackage string `json:"omitempty"`
AppSecret string `json:"omitempty"`
CreatedAt int64
Deadline int64
PageNum int
PageSize int
}
func (a *ClientApp) GetClientApp() (*models.ClientApp, error) {
app, err := models.GetClientApp(a.Id)
if err != nil {
return nil, err
}
return app, nil
}
func (a *ClientApp) GetAll() ([]*models.ClientApp, error) {
var app []*models.ClientApp
app, err := models.GetClientApps(a.PageNum, a.PageSize, a.getMaps())
if err != nil {
return nil, err
}
return app, nil
}
func (a *ClientApp) Add() error {
app := map[string]interface{}{
"type": a.Type,
"bundle_id": a.BundleId,
"app_signature": a.AppSignature,
"app_package": a.AppPackage,
"app_secret": a.AppSecret,
"deadline": a.Deadline,
}
if err := models.AddClientApp(app); err != nil {
return err
}
return nil
}
func (a *ClientApp) Edit() error {
return models.EditClientApp(a.Id, map[string]interface{}{
"type": a.Type,
"bundle_id": a.BundleId,
"app_signature": a.AppSignature,
"app_package": a.AppPackage,
"app_secret": a.AppSecret,
"deadline": a.Deadline,
})
}
func (a *ClientApp) ExistById() (bool, error) {
return models.ExistClientAppById(a.Id)
}
func (a *ClientApp) Count() (int, error) {
return models.GetClientAppTotal(a.getMaps())
}
func (a *ClientApp) Delete() error {
return models.DeleteClientApp(a.Id)
}
func (a *ClientApp) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{})
if a.Id != 0 {
maps["id"] = a.Id
}
if a.AppSecret != "" {
maps["app_secret"] = a.AppSecret
}
return maps
}
package streamer_service
import (
"bwallet/models"
)
type Streamer struct {
Uid int32
UserName string
NickName string
Password string
RegTime int64
LastLoginTime int64
RegIp uint32
LastLoginIp uint32
Status uint8
PlatformId int64
PageNum int
PageSize int
}
func (s *Streamer) GetOneStreamer() (*models.Streamer, error) {
streamer, err := models.GetStreamer(s.Uid)
if err != nil {
return nil, err
}
return streamer, nil
}
func (s *Streamer) GetAll() ([]*models.Streamer, error) {
var streamer []*models.Streamer
streamer, err := models.GetStreamers(s.PageNum, s.PageSize, s.getMaps())
if err != nil {
return nil, err
}
return streamer, nil
}
func (s *Streamer) Add() error {
streamer := map[string]interface{}{
"username": s.UserName,
"nickname": s.NickName,
"password": s.Password,
"reg_ip": s.RegIp,
"last_login_ip": s.LastLoginIp,
"status": s.Status,
"platform_id": s.PlatformId,
}
if err := models.AddStreamer(streamer); err != nil {
return err
}
return nil
}
func (s *Streamer) Edit() error {
return models.EditStreamer(s.Uid, map[string]interface{}{
"username": s.UserName,
"nickname": s.NickName,
"password": s.Password,
"reg_ip": s.RegIp,
"last_login_ip": s.LastLoginIp,
"status": s.Status,
"platform_id": s.PlatformId,
})
}
func (s *Streamer) ExistById() (bool, error) {
return models.ExistStreamerById(s.Uid)
}
func (s *Streamer) Count() (int, error) {
return models.GetStreamerTotal(s.getMaps())
}
func (s *Streamer) Delete() error {
return models.DeleteStreamer(s.Uid)
}
func (s *Streamer) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{})
if s.Uid != 0 {
maps["id"] = s.Uid
}
if s.PlatformId != 0 {
maps["platform_id"] = s.PlatformId
}
maps["status"] = s.Status
return maps
}
package user_service
import (
"bwallet/models"
)
type User struct {
Uid int32
UserName string
NickName string
Password string
RegTime int64
LastLoginTime int64
RegIp uint32
LastLoginIp uint32
Status uint8
PlatformId int64
PageNum int
PageSize int
}
func (u *User) GetOneUser() (*models.User, error) {
user, err := models.GetUser(u.Uid)
if err != nil {
return nil, err
}
return user, nil
}
func (u *User) GetAll() ([]*models.User, error) {
var user []*models.User
user, err := models.GetUsers(u.PageNum, u.PageSize, u.getMaps())
if err != nil {
return nil, err
}
return user, nil
}
func (u *User) Add() error {
user := map[string]interface{}{
"username": u.UserName,
"nickname": u.NickName,
"password": u.Password,
"reg_ip": u.RegIp,
"last_login_ip": u.LastLoginIp,
"status": u.Status,
"platform_id": u.PlatformId,
}
if err := models.AddUser(user); err != nil {
return err
}
return nil
}
func (u *User) Edit() error {
return models.EditUser(u.Uid, map[string]interface{}{
"username": u.UserName,
"nickname": u.NickName,
"password": u.Password,
"reg_ip": u.RegIp,
"last_login_ip": u.LastLoginIp,
"status": u.Status,
"platform_id": u.PlatformId,
})
}
func (u *User) ExistById() (bool, error) {
return models.ExistUserById(u.Uid)
}
func (u *User) Count() (int, error) {
return models.GetUserTotal(u.getMaps())
}
func (u *User) Delete() error {
return models.DeleteUser(u.Uid)
}
func (u *User) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{})
if u.Uid != 0 {
maps["id"] = u.Uid
}
if u.PlatformId != 0 {
maps["platform_id"] = u.PlatformId
}
maps["status"] = u.Status
return maps
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment