liuxiaolong
2020-06-03 733f4542f872b0befd99a0c66977b213ec8dfb44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package controllers
 
import (
    "basic.com/dbapi.git"
    "github.com/gin-gonic/gin"
    "webserver/extend/code"
    "webserver/extend/util"
)
 
type LicenseController struct {
 
}
 
 
type LicenseRegister struct {
    Company string  `json:"company" binding:"required"`
    Email   string    `json:"email" binding:"required"`
    Phone   string    `json:"phone" binding:"required"`
}
 
// @Summary 获取注册码
// @Description 获取注册码
// @Accept json
// @Produce json
// @Tags license
// @Param reqBody body controllers.LicenseRegister true "注册参数:公司、邮箱、手机号"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/license/getRegisterCode [post]
func (lc LicenseController) GetRegisterCode(c *gin.Context) {
    var reqBody LicenseRegister
    err := c.BindJSON(&reqBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"公司、邮箱和手机号必填")
        return
    }
    var api dbapi.LicenseApi
    paramBody := util.Struct2Map(reqBody)
    b, d := api.GetRegisterCode(paramBody)
    if b {
        util.ResponseFormat(c,code.Success,d)
    } else {
        util.ResponseFormat(c,code.ComError,"")
    }
}
 
type LicenseSaveArg struct {
    License string `json:"license" binding:"required"`
}
 
// @Summary 保存license
// @Description 保存license
// @Accept json
// @Produce json
// @Tags license
// @Param reqBody body controllers.LicenseSaveArg true "license字符串"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/license/save [post]
func (lc LicenseController) Save(c *gin.Context) {
    var reqBody LicenseSaveArg
    err := c.BindJSON(&reqBody)
    if err !=nil {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.LicenseApi
    paramBody := util.Struct2Map(reqBody)
    b, d := api.Save(paramBody)
    if b {
        util.ResponseFormat(c,code.Success,d)
    } else {
        util.ResponseFormat(c,code.UpdateFail,"")
    }
}
 
type ShowResult struct {
    Expired bool
    License interface{}
}
 
// @Summary 显示license注册信息
// @Description 显示license注册信息
// @Produce json
// @Tags license
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
// @Router /data/api-v/license/show [get]
func (lc LicenseController) Show(c *gin.Context) {
    var api dbapi.LicenseApi
    status,b, d := api.Show()
    if b {
        util.ResponseFormat(c,code.Success,ShowResult{
            Expired: false,
            License: d,
        })
    } else {
        if status == 403 {
            util.ResponseFormat(c,code.Success, ShowResult{
                Expired: true,
                License: d,
            })
        } else {
            util.ResponseFormat(c,code.ComError,"")
        }
 
    }
}