company_controller.go
1.6 KB
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
package controllers
import (
"errors"
"github.com/astaxie/beego/logs"
companyService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/company/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type CompanyController struct {
BaseController
}
//Prepare 重写 BaseController 的Prepare方法
func (c *CompanyController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMISSION_ENTERPRISE); !ok {
return
}
}
func (c *CompanyController) SetPhone() {
//用与适配前端定义的数据结构
type Paramter struct {
Type int `json:"type"`
Phone string `json:"phone"`
}
var (
param Paramter
err error
)
if err = c.BindJsonData(¶m); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
switch param.Type {
case 1:
c.editPhone(param.Phone)
case 2:
c.getPhone()
default:
c.ResponseError(errors.New("参数错误"))
}
return
}
func (c *CompanyController) getPhone() {
companyid := c.GetUserCompany()
srv := companyService.NewCompanyService(nil)
data, err := srv.GetCompanyData(companyid)
if err != nil {
c.ResponseError(err)
return
}
result := map[string]interface{}{
"phone": data.Phone,
}
c.ResponseData(result)
return
}
func (c *CompanyController) editPhone(phone string) {
companyid := c.GetUserCompany()
srv := companyService.NewCompanyService(nil)
err := srv.UpdateCompanyPhone(companyid, phone)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}