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,"") } } }