作者 tangxvhui

总后台调用的接口

... ... @@ -2,6 +2,7 @@ package controllers
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/protocol"
"oppmg/services/platform"
... ... @@ -31,3 +32,26 @@ func (c PlatformController) UpdateData() {
msg = protocol.NewReturnResponse(nil, err)
return
}
func (c PlatformController) CompanyAdminChance() {
type Parameter struct {
CompanyId int64 `json:"company_id"`
Phone string `json:"phone"`
}
var msg = protocol.ErrWithMessage{}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
e := fmt.Errorf("json 解析失败 err:%s", err)
log.Error(e.Error())
msg.Errmsg = e.Error()
return
}
err := platform.AdminChance(param.CompanyId, param.Phone)
if err != nil {
log.Error("总后台调用CompanyAdminChance发生错误;%s", err)
msg.Errmsg = err.Error()
}
c.Data["json"] = msg
c.ServeJSON()
return
}
... ...
... ... @@ -84,4 +84,5 @@ type ResponseAchievementInfo struct {
Provider []AchievementProvider `json:"provider"` //机会提供者
SourceContent string `json:"source_content"` //成果描述文本
Images []AchievementImage `json:"image"` //图片
CrreateAt string `json:"create_at"`
}
... ...
... ... @@ -111,7 +111,6 @@ func NewReturnResponse(data interface{}, eRR error) (msg *ResponseMessage) {
return x.ParseToMessage()
}
msg = NewMessage("1")
msg.Errmsg = eRR.Error()
return
}
... ...
... ... @@ -12,6 +12,7 @@ func init() {
nsPlatform := beego.NewNamespace("/platform",
beego.NSBefore(middleware.LogRequestData),
beego.NSRouter("/update", &controllers.PlatformController{}, "post:UpdateData"),
beego.NSRouter("/admins_change", &controllers.PlatformController{}, "post:CompanyAdminChance"),
)
beego.AddNamespace(nsPlatform)
}
... ...
... ... @@ -286,6 +286,7 @@ func GetAchievementInfo(id int64, companyId int64) *protocol.ResponseAchievement
rspData.Images = img
rspData.GraspScore = achievementData.GraspScore
rspData.UserCompanyId = achievementData.UserCompanyId
rspData.CrreateAt = achievementData.CreateAt.Format("2006-01-02 15:04:05")
} else {
log.Error("获取achievement数据失败:%s", err)
}
... ...
package platform
import (
"fmt"
"oppmg/common/log"
"oppmg/models"
)
// AdminChance
//companyid 总管理后台的公司id
func AdminChance(companyid int64, phone string) error {
var (
companyData *models.Company
userData *models.User
// userCompanyData *models.UserCompany
err error
)
companyData, err = models.GetCompanyByUCenter(companyid)
if err != nil {
e := fmt.Errorf("获取公司数据失败,总后台company_id:%d", companyid)
log.Error(err.Error())
return e
}
userData, err = models.GetUserByPhone(phone)
if err != nil {
e := fmt.Errorf("获取用户数据失败,phone:%s", phone)
log.Error(err.Error())
return e
}
_, err = models.GetUserCompanyBy(userData.Id, companyData.Id)
if err != nil {
e := fmt.Errorf("获取用户和公司的对应关系数据失败,user_id:%d,company_id:%d", userData.Id, companyData.Id)
log.Error(e.Error())
return e
}
companyData.AdminId = userData.Id
err = models.UpdateCompanyById(companyData, []string{"AdminId"})
if err != nil {
e := fmt.Errorf("更新公司数据失败,err:%s", err)
log.Error(e.Error())
return e
}
return nil
}
... ...