作者 yangfu

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

@@ -35,5 +35,25 @@ func (command CreatePartnerInfoCommand) ValidateCommand() error { @@ -35,5 +35,25 @@ func (command CreatePartnerInfoCommand) ValidateCommand() error {
35 command.PartnerCategory == domain.PARTNER_CATEGORY_3) { 35 command.PartnerCategory == domain.PARTNER_CATEGORY_3) {
36 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误") 36 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
37 } 37 }
  38 + if len(command.PartnerName) == 0 {
  39 + return lib.ThrowError(lib.ARG_ERROR, "合伙人名称必填")
  40 + }
  41 + if len(command.Account) == 0 {
  42 + return lib.ThrowError(lib.ARG_ERROR, "合伙人账号必填")
  43 + }
  44 + if command.RegionInfo == nil {
  45 + return lib.ThrowError(lib.ARG_ERROR, "区域必填")
  46 + }
  47 + if len(command.Salesman) == 0 {
  48 + return lib.ThrowError(lib.ARG_ERROR, "关联业务员必填")
  49 + }
  50 + for i := range command.Salesman {
  51 + if len(command.Salesman[i].Name) == 0 {
  52 + return lib.ThrowError(lib.ARG_ERROR, "关联业务员名称必填")
  53 + }
  54 + if len(command.Salesman[i].Telephone) == 0 {
  55 + return lib.ThrowError(lib.ARG_ERROR, "关联业务员电话必填")
  56 + }
  57 + }
38 return nil 58 return nil
39 } 59 }
@@ -15,5 +15,8 @@ func (command *StatusPartnerInfoCommand) ValidateCommand() error { @@ -15,5 +15,8 @@ func (command *StatusPartnerInfoCommand) ValidateCommand() error {
15 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) { 15 if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
16 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误") 16 return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
17 } 17 }
  18 + if command.Id == 0 {
  19 + return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
  20 + }
18 return nil 21 return nil
19 } 22 }
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 9
10 type UpdatePartnerInfoCommand struct { 10 type UpdatePartnerInfoCommand struct {
11 // 合伙人Id 11 // 合伙人Id
12 - Id int64 `json:"id,omitempty"` 12 + Id int64 `json:"id"`
13 // 状态(1:启用或者0:禁用) 13 // 状态(1:启用或者0:禁用)
14 Status int `json:"status"` 14 Status int `json:"status"`
15 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) 15 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
@@ -31,5 +31,22 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error { @@ -31,5 +31,22 @@ func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
31 command.PartnerCategory == domain.PARTNER_CATEGORY_3) { 31 command.PartnerCategory == domain.PARTNER_CATEGORY_3) {
32 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误") 32 return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
33 } 33 }
  34 + if command.RegionInfo == nil {
  35 + return lib.ThrowError(lib.ARG_ERROR, "区域必填")
  36 + }
  37 + if len(command.Salesman) == 0 {
  38 + return lib.ThrowError(lib.ARG_ERROR, "关联业务员必填")
  39 + }
  40 + if command.Id == 0 {
  41 + return lib.ThrowError(lib.ARG_ERROR, "合伙人id错误")
  42 + }
  43 + for i := range command.Salesman {
  44 + if len(command.Salesman[i].Name) == 0 {
  45 + return lib.ThrowError(lib.ARG_ERROR, "关联业务员名称必填")
  46 + }
  47 + if len(command.Salesman[i].Telephone) == 0 {
  48 + return lib.ThrowError(lib.ARG_ERROR, "关联业务员电话必填")
  49 + }
  50 + }
34 return nil 51 return nil
35 } 52 }
@@ -19,7 +19,7 @@ type PartnerInfo struct { @@ -19,7 +19,7 @@ type PartnerInfo struct {
19 // 登录密码 19 // 登录密码
20 Password string 20 Password string
21 // 状态(1:启用或者0:禁用) 21 // 状态(1:启用或者0:禁用)
22 - Status int `pg:",notnull,default:1"` 22 + Status int `pg:",use_zero,default:1"`
23 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) 23 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
24 PartnerCategory int `pg:",default:1"` //partner_category 24 PartnerCategory int `pg:",default:1"` //partner_category
25 //所属区域信息 25 //所属区域信息
@@ -33,9 +33,12 @@ func (controller BaseController) ResponseError(err error) { @@ -33,9 +33,12 @@ func (controller BaseController) ResponseError(err error) {
33 Data: struct{}{}, 33 Data: struct{}{},
34 } 34 }
35 controller.ServeJSON() 35 controller.ServeJSON()
36 - logs.Error(err) 36 + logs.Error(e.Prefix, e.Message)
37 return 37 return
  38 + } else {
  39 + logs.Error(e.Prefix, e.Message)
38 } 40 }
  41 +
39 } 42 }
40 controller.Data["json"] = protocol.ResponseData{ 43 controller.Data["json"] = protocol.ResponseData{
41 Code: -1, 44 Code: -1,
@@ -40,7 +40,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -40,7 +40,7 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
40 PartnerType int `json:"partnerType"` 40 PartnerType int `json:"partnerType"`
41 Area string `json:"area"` 41 Area string `json:"area"`
42 Account string `json:"account"` 42 Account string `json:"account"`
43 - State string `json:"state"` 43 + State int `json:"state"`
44 CooperationTime string `json:"cooperationTime"` 44 CooperationTime string `json:"cooperationTime"`
45 SalesmanName string `json:"salesmanName"` 45 SalesmanName string `json:"salesmanName"`
46 Phone string `json:"phone"` 46 Phone string `json:"phone"`
@@ -55,10 +55,9 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -55,10 +55,9 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
55 return 55 return
56 } 56 }
57 defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456"))) 57 defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456")))
58 - state, _ := strconv.Atoi(param.State)  
59 cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local) 58 cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
60 if err != nil { 59 if err != nil {
61 - e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 60 + e := lib.ThrowError(lib.ARG_ERROR, err.Error())
62 c.ResponseError(e) 61 c.ResponseError(e)
63 return 62 return
64 } 63 }
@@ -66,12 +65,9 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -66,12 +65,9 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
66 PartnerName: param.PartnerName, 65 PartnerName: param.PartnerName,
67 Account: param.Account, 66 Account: param.Account,
68 Password: defaultPwd, 67 Password: defaultPwd,
69 - Status: state, 68 + Status: param.State,
70 PartnerCategory: param.PartnerType, 69 PartnerCategory: param.PartnerType,
71 CooperateTime: cooperateTime, 70 CooperateTime: cooperateTime,
72 - RegionInfo: &domain.RegionInfo{  
73 - RegionName: param.Area,  
74 - },  
75 Salesman: []domain.Salesman{ 71 Salesman: []domain.Salesman{
76 domain.Salesman{ 72 domain.Salesman{
77 Name: param.SalesmanName, 73 Name: param.SalesmanName,
@@ -79,6 +75,11 @@ func (c *PartnerInfoController) CreatePartnerInfo() { @@ -79,6 +75,11 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
79 }, 75 },
80 }, 76 },
81 } 77 }
  78 + if len(param.Area) > 0 {
  79 + cmd.RegionInfo = &domain.RegionInfo{
  80 + RegionName: param.Area,
  81 + }
  82 + }
82 serve := partnerInfoService.NewPartnerInfoService(nil) 83 serve := partnerInfoService.NewPartnerInfoService(nil)
83 _, err = serve.CreatePartnerInfo(&cmd) 84 _, err = serve.CreatePartnerInfo(&cmd)
84 if err != nil { 85 if err != nil {
@@ -96,7 +97,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -96,7 +97,7 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
96 ID int64 `json:"id"` 97 ID int64 `json:"id"`
97 PartnerType int `json:"partnerType"` 98 PartnerType int `json:"partnerType"`
98 Area string `json:"area"` 99 Area string `json:"area"`
99 - State string `json:"state"` 100 + State int `json:"state"`
100 CooperationTime string `json:"cooperationTime"` 101 CooperationTime string `json:"cooperationTime"`
101 SalesmanName string `json:"salesmanName"` 102 SalesmanName string `json:"salesmanName"`
102 Phone string `json:"phone"` 103 Phone string `json:"phone"`
@@ -110,7 +111,6 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -110,7 +111,6 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
110 c.ResponseError(errors.New("json数据解析失败")) 111 c.ResponseError(errors.New("json数据解析失败"))
111 return 112 return
112 } 113 }
113 - state, _ := strconv.Atoi(param.State)  
114 cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local) 114 cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
115 if err != nil { 115 if err != nil {
116 e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 116 e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
@@ -118,7 +118,8 @@ func (c *PartnerInfoController) UpdatePartnerInfo() { @@ -118,7 +118,8 @@ func (c *PartnerInfoController) UpdatePartnerInfo() {
118 return 118 return
119 } 119 }
120 cmd := partnerInfoCmd.UpdatePartnerInfoCommand{ 120 cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
121 - Status: state, 121 + Id: param.ID,
  122 + Status: param.State,
122 PartnerCategory: param.PartnerType, 123 PartnerCategory: param.PartnerType,
123 CooperateTime: cooperateTime, 124 CooperateTime: cooperateTime,
124 RegionInfo: &domain.RegionInfo{ 125 RegionInfo: &domain.RegionInfo{
@@ -168,13 +169,13 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -168,13 +169,13 @@ func (c *PartnerInfoController) GetPartnerInfo() {
168 rspResult := map[string]interface{}{ 169 rspResult := map[string]interface{}{
169 "account": partnerInfo.Account, 170 "account": partnerInfo.Account,
170 "partnerName": partnerInfo.PartnerName, 171 "partnerName": partnerInfo.PartnerName,
171 - "partnertype": partnerInfo.PartnerCategory, 172 + "partnerType": partnerInfo.PartnerCategory,
172 "area": partnerInfo.RegionInfo.RegionName, 173 "area": partnerInfo.RegionInfo.RegionName,
173 "salesmanName": "", 174 "salesmanName": "",
174 "phone": "", 175 "phone": "",
175 - "createTime": partnerInfo.CreateAt.Format("2006-01-02 15:04:05"),  
176 - "cooperationTime": partnerInfo.CooperateTime.Format("2006-01-02"),  
177 - "state": fmt.Sprint(partnerInfo.Status), 176 + "createTime": partnerInfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
  177 + "cooperationTime": partnerInfo.CooperateTime.Local().Format("2006-01-02"),
  178 + "state": partnerInfo.Status,
178 "id": partnerInfo.Id, 179 "id": partnerInfo.Id,
179 } 180 }
180 if len(partnerInfo.Salesman) > 0 { 181 if len(partnerInfo.Salesman) > 0 {
@@ -185,12 +186,12 @@ func (c *PartnerInfoController) GetPartnerInfo() { @@ -185,12 +186,12 @@ func (c *PartnerInfoController) GetPartnerInfo() {
185 return 186 return
186 } 187 }
187 188
188 -//GetPartnerInfo 移除合伙人 189 +//PartnerInfoSetState 合伙人禁用启用
189 func (c *PartnerInfoController) PartnerInfoSetState() { 190 func (c *PartnerInfoController) PartnerInfoSetState() {
190 //用与适配前端定义的数据结构 191 //用与适配前端定义的数据结构
191 type Parameter struct { 192 type Parameter struct {
192 Id int64 `json:"id"` 193 Id int64 `json:"id"`
193 - status string `json:"status"` 194 + Status int `json:"status"`
194 } 195 }
195 var ( 196 var (
196 param Parameter 197 param Parameter
@@ -205,10 +206,10 @@ func (c *PartnerInfoController) PartnerInfoSetState() { @@ -205,10 +206,10 @@ func (c *PartnerInfoController) PartnerInfoSetState() {
205 cmd := partnerInfoCmd.StatusPartnerInfoCommand{ 206 cmd := partnerInfoCmd.StatusPartnerInfoCommand{
206 Id: param.Id, 207 Id: param.Id,
207 } 208 }
208 - if param.status == "1" { 209 + if param.Status == 1 {
209 //禁用操作 210 //禁用操作
210 cmd.Status = domain.PARTNER_STATUS_NO 211 cmd.Status = domain.PARTNER_STATUS_NO
211 - } else if param.status == "2" { 212 + } else if param.Status == 2 {
212 //启用操作 213 //启用操作
213 cmd.Status = domain.PARTNER_STATUS_YES 214 cmd.Status = domain.PARTNER_STATUS_YES
214 } else { 215 } else {
@@ -272,9 +273,10 @@ func (c *PartnerInfoController) ListPartnerInfo() { @@ -272,9 +273,10 @@ func (c *PartnerInfoController) ListPartnerInfo() {
272 "account": partners[i].Account, 273 "account": partners[i].Account,
273 "partnerName": partners[i].PartnerName, 274 "partnerName": partners[i].PartnerName,
274 "area": partners[i].RegionInfo.RegionName, 275 "area": partners[i].RegionInfo.RegionName,
275 - "createTime": partners[i].CreateAt.Format("2006-01-02 15:04:05"),  
276 - "cooperationTime": partners[i].CooperateTime.Format("2006-01-02"),  
277 - "state": fmt.Sprint(partners[i].Status), 276 + "createTime": partners[i].CreateAt.Local().Format("2006-01-02 15:04:05"),
  277 + "cooperationTime": partners[i].CooperateTime.Local().Format("2006-01-02"),
  278 + "state": partners[i].Status,
  279 + "partnerType": partners[i].PartnerCategory,
278 "salesmanName": "", 280 "salesmanName": "",
279 "phone": "", 281 "phone": "",
280 } 282 }