作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into dev

... ... @@ -35,5 +35,25 @@ func (command CreatePartnerInfoCommand) ValidateCommand() error {
command.PartnerCategory == domain.PARTNER_CATEGORY_3) {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
}
if len(command.PartnerName) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人名称必填")
}
if len(command.Account) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人账号必填")
}
if command.RegionInfo == nil {
return lib.ThrowError(lib.ARG_ERROR, "区域必填")
}
if len(command.Salesman) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "关联业务员必填")
}
for i := range command.Salesman {
if len(command.Salesman[i].Name) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "关联业务员名称必填")
}
if len(command.Salesman[i].Telephone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "关联业务员电话必填")
}
}
return nil
}
... ...
... ... @@ -15,5 +15,8 @@ func (command *StatusPartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
return nil
}
... ...
... ... @@ -9,7 +9,7 @@ import (
type UpdatePartnerInfoCommand struct {
// 合伙人Id
Id int64 `json:"id,omitempty"`
Id int64 `json:"id"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
... ... @@ -31,5 +31,22 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
command.PartnerCategory == domain.PARTNER_CATEGORY_3) {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
}
if command.RegionInfo == nil {
return lib.ThrowError(lib.ARG_ERROR, "区域必填")
}
if len(command.Salesman) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "关联业务员必填")
}
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
}
for i := range command.Salesman {
if len(command.Salesman[i].Name) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "关联业务员名称必填")
}
if len(command.Salesman[i].Telephone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "关联业务员电话必填")
}
}
return nil
}
... ...
... ... @@ -19,7 +19,7 @@ type PartnerInfo struct {
// 登录密码
Password string
// 状态(1:启用或者0:禁用)
Status int `pg:",notnull,default:1"`
Status int `pg:",use_zero,default:1"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `pg:",default:1"` //partner_category
//所属区域信息
... ...
... ... @@ -33,9 +33,12 @@ func (controller BaseController) ResponseError(err error) {
Data: struct{}{},
}
controller.ServeJSON()
logs.Error(err)
logs.Error(e.Prefix, e.Message)
return
} else {
logs.Error(e.Prefix, e.Message)
}
}
controller.Data["json"] = protocol.ResponseData{
Code: -1,
... ...
... ... @@ -40,7 +40,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
PartnerType int `json:"partnerType"`
Area string `json:"area"`
Account string `json:"account"`
State string `json:"state"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
... ... @@ -55,10 +55,9 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
return
}
defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456")))
state, _ := strconv.Atoi(param.State)
cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
if err != nil {
e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
e := lib.ThrowError(lib.ARG_ERROR, err.Error())
c.ResponseError(e)
return
}
... ... @@ -66,12 +65,9 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
PartnerName: param.PartnerName,
Account: param.Account,
Password: defaultPwd,
Status: state,
Status: param.State,
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
RegionInfo: &domain.RegionInfo{
RegionName: param.Area,
},
Salesman: []domain.Salesman{
domain.Salesman{
Name: param.SalesmanName,
... ... @@ -79,6 +75,11 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
},
},
}
if len(param.Area) > 0 {
cmd.RegionInfo = &domain.RegionInfo{
RegionName: param.Area,
}
}
serve := partnerInfoService.NewPartnerInfoService(nil)
_, err = serve.CreatePartnerInfo(&cmd)
if err != nil {
... ... @@ -96,7 +97,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
ID int64 `json:"id"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
State string `json:"state"`
State int `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
... ... @@ -110,7 +111,6 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
state, _ := strconv.Atoi(param.State)
cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
if err != nil {
e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -118,7 +118,8 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
return
}
cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
Status: state,
Id: param.ID,
Status: param.State,
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
RegionInfo: &domain.RegionInfo{
... ... @@ -168,13 +169,13 @@ func (c *PartnerInfoController) GetPartnerInfo() {
rspResult := map[string]interface{}{
"account": partnerInfo.Account,
"partnerName": partnerInfo.PartnerName,
"partnertype": partnerInfo.PartnerCategory,
"partnerType": partnerInfo.PartnerCategory,
"area": partnerInfo.RegionInfo.RegionName,
"salesmanName": "",
"phone": "",
"createTime": partnerInfo.CreateAt.Format("2006-01-02 15:04:05"),
"cooperationTime": partnerInfo.CooperateTime.Format("2006-01-02"),
"state": fmt.Sprint(partnerInfo.Status),
"createTime": partnerInfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"),
"state": partnerInfo.Status,
"id": partnerInfo.Id,
}
if len(partnerInfo.Salesman) > 0 {
... ... @@ -185,12 +186,12 @@ func (c *PartnerInfoController) GetPartnerInfo() {
return
}
//GetPartnerInfo 移除合伙人
//PartnerInfoSetState 合伙人禁用启用
func (c *PartnerInfoController) PartnerInfoSetState() {
//用与适配前端定义的数据结构
type Parameter struct {
Id int64 `json:"id"`
status string `json:"status"`
Id int64 `json:"id"`
Status int `json:"status"`
}
var (
param Parameter
... ... @@ -205,10 +206,10 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
cmd := partnerInfoCmd.StatusPartnerInfoCommand{
Id: param.Id,
}
if param.status == "1" {
if param.Status == 1 {
//禁用操作
cmd.Status = domain.PARTNER_STATUS_NO
} else if param.status == "2" {
} else if param.Status == 2 {
//启用操作
cmd.Status = domain.PARTNER_STATUS_YES
} else {
... ... @@ -272,9 +273,10 @@ func (c *PartnerInfoController) ListPartnerInfo() {
"account": partners[i].Account,
"partnerName": partners[i].PartnerName,
"area": partners[i].RegionInfo.RegionName,
"createTime": partners[i].CreateAt.Format("2006-01-02 15:04:05"),
"cooperationTime": partners[i].CooperateTime.Format("2006-01-02"),
"state": fmt.Sprint(partners[i].Status),
"createTime": partners[i].CreateAt.Local().Format("2006-01-02 15:04:05"),
"cooperationTime": partners[i].CooperateTime.Local().Format("2006-01-02"),
"state": partners[i].Status,
"partnerType": partners[i].PartnerCategory,
"salesmanName": "",
"phone": "",
}
... ...