platform.go 1.5 KB
package controllers

import (
	"encoding/json"
	"fmt"
	"oppmg/common/log"
	"oppmg/protocol"
	"oppmg/services/platform"
)

type PlatformController struct {
	BaseController
}

//
func (c PlatformController) UpdateData() {
	defer func() {
		c.Data["json"] = map[string]interface{}{
			"code": 0,
			"msg":  "ok",
		}
		c.ServeJSON()
	}()
	var param platform.CommonProtocol
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
		log.Error("json 解析失败 err:%s", err)
		return
	}
	m, err := platform.NewPlatformAction(param.Module)
	if err != nil {
		log.Error("同步数据发生错误,err%s", err)
		return
	}
	bt, err := json.Marshal(param.Data)
	if err != nil {
		log.Error("解析param.data数据失败")
	}
	err = m.DoAction(param.Action, bt)
	if err != nil {
		log.Error("同步数据发生错误,module=%s,action=%s,err:%s", param.Module, param.Action, 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
}