|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
"crypto/sha1"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
|
|
|
partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
|
|
|
|
|
|
partnerInfoCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
|
|
|
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
|
...
|
...
|
@@ -47,57 +54,237 @@ func (c *PartnerInfoController) CreatePartnerInfo() { |
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
cmd := partnerInfoCmd.CreatePartnerInfoCommand{}
|
|
|
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())
|
|
|
c.ResponseError(e)
|
|
|
return
|
|
|
}
|
|
|
cmd := partnerInfoCmd.CreatePartnerInfoCommand{
|
|
|
PartnerName: param.PartnerName,
|
|
|
Account: param.Account,
|
|
|
Password: defaultPwd,
|
|
|
Status: state,
|
|
|
PartnerCategory: param.PartnerType,
|
|
|
CooperateTime: cooperateTime,
|
|
|
RegionInfo: &domain.RegionInfo{
|
|
|
RegionName: param.Area,
|
|
|
},
|
|
|
Salesman: []domain.Salesman{
|
|
|
domain.Salesman{
|
|
|
Name: param.SalesmanName,
|
|
|
Telephone: param.Phone,
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
serve := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
serve.CreatePartnerInfo(&cmd)
|
|
|
_, err = serve.CreatePartnerInfo(&cmd)
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
c.ResponseData(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//UpdatePartnerInfo 更新合伙人
|
|
|
func (c *PartnerInfoController) UpdatePartnerInfo() {
|
|
|
// var (
|
|
|
// service = service.NewPartnerInfoService(nil)
|
|
|
// command = &command.UpdatePartnerInfoCommand{}
|
|
|
// )
|
|
|
// controller.JsonUnmarshal(command)
|
|
|
// id, _ := controller.GetInt(":id")
|
|
|
// command.Id = id
|
|
|
// controller.HandlerResponse(service.UpdatePartnerInfo(command))
|
|
|
//用与适配前端定义的数据结构
|
|
|
type Parameter struct {
|
|
|
ID int64 `json:"id"`
|
|
|
PartnerType int `json:"partnerType"`
|
|
|
Area string `json:"area"`
|
|
|
State string `json:"state"`
|
|
|
CooperationTime string `json:"cooperationTime"`
|
|
|
SalesmanName string `json:"salesmanName"`
|
|
|
Phone string `json:"phone"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
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())
|
|
|
c.ResponseError(e)
|
|
|
return
|
|
|
}
|
|
|
cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
|
|
|
Status: state,
|
|
|
PartnerCategory: param.PartnerType,
|
|
|
CooperateTime: cooperateTime,
|
|
|
RegionInfo: &domain.RegionInfo{
|
|
|
RegionName: param.Area,
|
|
|
},
|
|
|
Salesman: []domain.Salesman{
|
|
|
domain.Salesman{
|
|
|
Name: param.SalesmanName,
|
|
|
Telephone: param.Phone,
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
serve := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
err = serve.UpdatePartnerInfo(&cmd)
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
c.ResponseData(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//GetPartnerInfo 获取合伙人
|
|
|
func (c *PartnerInfoController) GetPartnerInfo() {
|
|
|
// var (
|
|
|
// service = service.NewPartnerInfoService(nil)
|
|
|
// command = &query.GetPartnerInfoQuery{}
|
|
|
// )
|
|
|
// uid, _ := controller.GetInt(":id")
|
|
|
// command.Id = uid
|
|
|
// controller.HandlerResponse(service.GetPartnerInfo(command))
|
|
|
//用与适配前端定义的数据结构
|
|
|
type Parameter struct {
|
|
|
Id int64 `json:"id"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
partnerInfo, err := newPartnerService.GetPartnerInfo(partnerQuery.GetPartnerInfoQuery{
|
|
|
Id: param.Id,
|
|
|
})
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
//数据适配
|
|
|
rspResult := map[string]interface{}{
|
|
|
"account": partnerInfo.Account,
|
|
|
"partnerName": partnerInfo.PartnerName,
|
|
|
"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),
|
|
|
"id": partnerInfo.Id,
|
|
|
}
|
|
|
if len(partnerInfo.Salesman) > 0 {
|
|
|
rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
|
|
|
rspResult["phone"] = partnerInfo.Salesman[0].Telephone
|
|
|
}
|
|
|
c.ResponseData(rspResult)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//GetPartnerInfo 移除合伙人
|
|
|
func (controller *PartnerInfoController) RemovePartnerInfo() {
|
|
|
// var (
|
|
|
// service = service.NewPartnerInfoService(nil)
|
|
|
// command = &command.RemovePartnerInfoCommand{}
|
|
|
// )
|
|
|
// uid, _ := controller.GetInt(":id")
|
|
|
// command.Id = uid
|
|
|
// controller.HandlerResponse(service.RemovePartnerInfo(command))
|
|
|
func (c *PartnerInfoController) PartnerInfoSetState() {
|
|
|
//用与适配前端定义的数据结构
|
|
|
type Parameter struct {
|
|
|
Id int64 `json:"id"`
|
|
|
status string `json:"status"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
cmd := partnerInfoCmd.StatusPartnerInfoCommand{
|
|
|
Id: param.Id,
|
|
|
}
|
|
|
if param.status == "1" {
|
|
|
//禁用操作
|
|
|
cmd.Status = domain.PARTNER_STATUS_NO
|
|
|
} else if param.status == "2" {
|
|
|
//启用操作
|
|
|
cmd.Status = domain.PARTNER_STATUS_YES
|
|
|
} else {
|
|
|
//错误
|
|
|
c.ResponseError(lib.ThrowError(lib.ARG_ERROR, "状态错误"))
|
|
|
return
|
|
|
}
|
|
|
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
err = newPartnerService.UpdateStatus(cmd)
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
c.ResponseData(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//ListPartnerInfo 合伙人列表
|
|
|
func (controller *PartnerInfoController) ListPartnerInfo() {
|
|
|
// var (
|
|
|
// service = service.NewPartnerInfoService(nil)
|
|
|
// command = &query.ListPartnerInfoQuery{}
|
|
|
// )
|
|
|
// command.PartnerCategory, _ = controller.GetInt("partnerCategory")
|
|
|
// command.Status, _ = controller.GetInt("status")
|
|
|
// command.SortByCreateTime = controller.GetString("sortByCreateTime")
|
|
|
// command.SortByUpdateTime = controller.GetString("sortByUpdateTime")
|
|
|
// command.Offset, command.Limit = controller.GetLimitInfo()
|
|
|
// controller.HandlerResponse(service.ListPartnerInfo(command))
|
|
|
func (c *PartnerInfoController) ListPartnerInfo() {
|
|
|
type Parameter struct {
|
|
|
Partnertype string `json:"partnerType"`
|
|
|
Area string `json:"area"`
|
|
|
PartnerName string `json:"partnerName"`
|
|
|
PageSize int `json:"pageSize"`
|
|
|
PageNumber int `json:"pageNumber"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
partnertype, _ := strconv.Atoi(param.Partnertype)
|
|
|
if param.PageNumber == 0 {
|
|
|
param.PageNumber = 20
|
|
|
}
|
|
|
query := partnerQuery.ListPartnerInfoQuery{
|
|
|
Partnertype: partnertype,
|
|
|
PartnerName: param.PartnerName,
|
|
|
RegionInfo: param.Area,
|
|
|
Limit: param.PageNumber,
|
|
|
}
|
|
|
|
|
|
if param.PageSize == 0 {
|
|
|
query.Offset = 0
|
|
|
} else {
|
|
|
query.Offset = (param.PageNumber - 1) * param.PageSize
|
|
|
}
|
|
|
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
count, partners, err := newPartnerService.ListPartnerInfo(&query)
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
resp := []map[string]interface{}{}
|
|
|
for i := range partners {
|
|
|
m := map[string]interface{}{
|
|
|
"id": partners[i].Id,
|
|
|
"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),
|
|
|
"salesmanName": "",
|
|
|
"phone": "",
|
|
|
}
|
|
|
if len(partners[i].Salesman) > 0 {
|
|
|
m["salesmanName"] = partners[i].Salesman[0].Name
|
|
|
m["phone"] = partners[i].Salesman[0].Telephone
|
|
|
}
|
|
|
resp = append(resp, m)
|
|
|
}
|
|
|
c.ResponsePageList(resp, count, param.PageNumber)
|
|
|
return
|
|
|
} |
...
|
...
|
|