1
|
package controllers
|
1
|
package controllers
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "crypto/sha1"
|
4
|
"errors"
|
5
|
"errors"
|
|
|
6
|
+ "fmt"
|
|
|
7
|
+ "strconv"
|
|
|
8
|
+ "time"
|
5
|
|
9
|
|
6
|
"github.com/astaxie/beego/logs"
|
10
|
"github.com/astaxie/beego/logs"
|
7
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
11
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
12
|
+ "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
13
|
+
|
|
|
14
|
+ partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
|
8
|
|
15
|
|
9
|
partnerInfoCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
|
16
|
partnerInfoCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
|
10
|
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
|
17
|
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
|
|
@@ -47,57 +54,237 @@ func (c *PartnerInfoController) CreatePartnerInfo() { |
|
@@ -47,57 +54,237 @@ func (c *PartnerInfoController) CreatePartnerInfo() { |
47
|
c.ResponseError(errors.New("json数据解析失败"))
|
54
|
c.ResponseError(errors.New("json数据解析失败"))
|
48
|
return
|
55
|
return
|
49
|
}
|
56
|
}
|
50
|
- cmd := partnerInfoCmd.CreatePartnerInfoCommand{}
|
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)
|
|
|
60
|
+ if err != nil {
|
|
|
61
|
+ e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
62
|
+ c.ResponseError(e)
|
|
|
63
|
+ return
|
|
|
64
|
+ }
|
|
|
65
|
+ cmd := partnerInfoCmd.CreatePartnerInfoCommand{
|
|
|
66
|
+ PartnerName: param.PartnerName,
|
|
|
67
|
+ Account: param.Account,
|
|
|
68
|
+ Password: defaultPwd,
|
|
|
69
|
+ Status: state,
|
|
|
70
|
+ PartnerCategory: param.PartnerType,
|
|
|
71
|
+ CooperateTime: cooperateTime,
|
|
|
72
|
+ RegionInfo: &domain.RegionInfo{
|
|
|
73
|
+ RegionName: param.Area,
|
|
|
74
|
+ },
|
|
|
75
|
+ Salesman: []domain.Salesman{
|
|
|
76
|
+ domain.Salesman{
|
|
|
77
|
+ Name: param.SalesmanName,
|
|
|
78
|
+ Telephone: param.Phone,
|
|
|
79
|
+ },
|
|
|
80
|
+ },
|
|
|
81
|
+ }
|
51
|
serve := partnerInfoService.NewPartnerInfoService(nil)
|
82
|
serve := partnerInfoService.NewPartnerInfoService(nil)
|
52
|
- serve.CreatePartnerInfo(&cmd)
|
83
|
+ _, err = serve.CreatePartnerInfo(&cmd)
|
|
|
84
|
+ if err != nil {
|
|
|
85
|
+ c.ResponseError(err)
|
|
|
86
|
+ return
|
|
|
87
|
+ }
|
53
|
c.ResponseData(nil)
|
88
|
c.ResponseData(nil)
|
54
|
return
|
89
|
return
|
55
|
}
|
90
|
}
|
56
|
|
91
|
|
57
|
//UpdatePartnerInfo 更新合伙人
|
92
|
//UpdatePartnerInfo 更新合伙人
|
58
|
func (c *PartnerInfoController) UpdatePartnerInfo() {
|
93
|
func (c *PartnerInfoController) UpdatePartnerInfo() {
|
59
|
- // var (
|
|
|
60
|
- // service = service.NewPartnerInfoService(nil)
|
|
|
61
|
- // command = &command.UpdatePartnerInfoCommand{}
|
|
|
62
|
- // )
|
|
|
63
|
- // controller.JsonUnmarshal(command)
|
|
|
64
|
- // id, _ := controller.GetInt(":id")
|
|
|
65
|
- // command.Id = id
|
|
|
66
|
- // controller.HandlerResponse(service.UpdatePartnerInfo(command))
|
94
|
+ //用与适配前端定义的数据结构
|
|
|
95
|
+ type Parameter struct {
|
|
|
96
|
+ ID int64 `json:"id"`
|
|
|
97
|
+ PartnerType int `json:"partnerType"`
|
|
|
98
|
+ Area string `json:"area"`
|
|
|
99
|
+ State string `json:"state"`
|
|
|
100
|
+ CooperationTime string `json:"cooperationTime"`
|
|
|
101
|
+ SalesmanName string `json:"salesmanName"`
|
|
|
102
|
+ Phone string `json:"phone"`
|
|
|
103
|
+ }
|
|
|
104
|
+ var (
|
|
|
105
|
+ param Parameter
|
|
|
106
|
+ err error
|
|
|
107
|
+ )
|
|
|
108
|
+ if err = c.BindJsonData(¶m); err != nil {
|
|
|
109
|
+ logs.Error(err)
|
|
|
110
|
+ c.ResponseError(errors.New("json数据解析失败"))
|
|
|
111
|
+ return
|
|
|
112
|
+ }
|
|
|
113
|
+ state, _ := strconv.Atoi(param.State)
|
|
|
114
|
+ cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
|
|
|
115
|
+ if err != nil {
|
|
|
116
|
+ e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
117
|
+ c.ResponseError(e)
|
|
|
118
|
+ return
|
|
|
119
|
+ }
|
|
|
120
|
+ cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
|
|
|
121
|
+ Status: state,
|
|
|
122
|
+ PartnerCategory: param.PartnerType,
|
|
|
123
|
+ CooperateTime: cooperateTime,
|
|
|
124
|
+ RegionInfo: &domain.RegionInfo{
|
|
|
125
|
+ RegionName: param.Area,
|
|
|
126
|
+ },
|
|
|
127
|
+ Salesman: []domain.Salesman{
|
|
|
128
|
+ domain.Salesman{
|
|
|
129
|
+ Name: param.SalesmanName,
|
|
|
130
|
+ Telephone: param.Phone,
|
|
|
131
|
+ },
|
|
|
132
|
+ },
|
|
|
133
|
+ }
|
|
|
134
|
+ serve := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
135
|
+ err = serve.UpdatePartnerInfo(&cmd)
|
|
|
136
|
+ if err != nil {
|
|
|
137
|
+ c.ResponseError(err)
|
|
|
138
|
+ return
|
|
|
139
|
+ }
|
|
|
140
|
+ c.ResponseData(nil)
|
|
|
141
|
+ return
|
67
|
}
|
142
|
}
|
68
|
|
143
|
|
69
|
//GetPartnerInfo 获取合伙人
|
144
|
//GetPartnerInfo 获取合伙人
|
70
|
func (c *PartnerInfoController) GetPartnerInfo() {
|
145
|
func (c *PartnerInfoController) GetPartnerInfo() {
|
71
|
- // var (
|
|
|
72
|
- // service = service.NewPartnerInfoService(nil)
|
|
|
73
|
- // command = &query.GetPartnerInfoQuery{}
|
|
|
74
|
- // )
|
|
|
75
|
- // uid, _ := controller.GetInt(":id")
|
|
|
76
|
- // command.Id = uid
|
|
|
77
|
- // controller.HandlerResponse(service.GetPartnerInfo(command))
|
146
|
+ //用与适配前端定义的数据结构
|
|
|
147
|
+ type Parameter struct {
|
|
|
148
|
+ Id int64 `json:"id"`
|
|
|
149
|
+ }
|
|
|
150
|
+ var (
|
|
|
151
|
+ param Parameter
|
|
|
152
|
+ err error
|
|
|
153
|
+ )
|
|
|
154
|
+ if err = c.BindJsonData(¶m); err != nil {
|
|
|
155
|
+ logs.Error(err)
|
|
|
156
|
+ c.ResponseError(errors.New("json数据解析失败"))
|
|
|
157
|
+ return
|
|
|
158
|
+ }
|
|
|
159
|
+ newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
160
|
+ partnerInfo, err := newPartnerService.GetPartnerInfo(partnerQuery.GetPartnerInfoQuery{
|
|
|
161
|
+ Id: param.Id,
|
|
|
162
|
+ })
|
|
|
163
|
+ if err != nil {
|
|
|
164
|
+ c.ResponseError(err)
|
|
|
165
|
+ return
|
|
|
166
|
+ }
|
|
|
167
|
+ //数据适配
|
|
|
168
|
+ rspResult := map[string]interface{}{
|
|
|
169
|
+ "account": partnerInfo.Account,
|
|
|
170
|
+ "partnerName": partnerInfo.PartnerName,
|
|
|
171
|
+ "partnertype": partnerInfo.PartnerCategory,
|
|
|
172
|
+ "area": partnerInfo.RegionInfo.RegionName,
|
|
|
173
|
+ "salesmanName": "",
|
|
|
174
|
+ "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),
|
|
|
178
|
+ "id": partnerInfo.Id,
|
|
|
179
|
+ }
|
|
|
180
|
+ if len(partnerInfo.Salesman) > 0 {
|
|
|
181
|
+ rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
|
|
|
182
|
+ rspResult["phone"] = partnerInfo.Salesman[0].Telephone
|
|
|
183
|
+ }
|
|
|
184
|
+ c.ResponseData(rspResult)
|
|
|
185
|
+ return
|
78
|
}
|
186
|
}
|
79
|
|
187
|
|
80
|
//GetPartnerInfo 移除合伙人
|
188
|
//GetPartnerInfo 移除合伙人
|
81
|
-func (controller *PartnerInfoController) RemovePartnerInfo() {
|
|
|
82
|
- // var (
|
|
|
83
|
- // service = service.NewPartnerInfoService(nil)
|
|
|
84
|
- // command = &command.RemovePartnerInfoCommand{}
|
|
|
85
|
- // )
|
|
|
86
|
- // uid, _ := controller.GetInt(":id")
|
|
|
87
|
- // command.Id = uid
|
|
|
88
|
- // controller.HandlerResponse(service.RemovePartnerInfo(command))
|
189
|
+func (c *PartnerInfoController) PartnerInfoSetState() {
|
|
|
190
|
+ //用与适配前端定义的数据结构
|
|
|
191
|
+ type Parameter struct {
|
|
|
192
|
+ Id int64 `json:"id"`
|
|
|
193
|
+ status string `json:"status"`
|
|
|
194
|
+ }
|
|
|
195
|
+ var (
|
|
|
196
|
+ param Parameter
|
|
|
197
|
+ err error
|
|
|
198
|
+ )
|
|
|
199
|
+ if err = c.BindJsonData(¶m); err != nil {
|
|
|
200
|
+ logs.Error(err)
|
|
|
201
|
+ c.ResponseError(errors.New("json数据解析失败"))
|
|
|
202
|
+ return
|
|
|
203
|
+ }
|
|
|
204
|
+
|
|
|
205
|
+ cmd := partnerInfoCmd.StatusPartnerInfoCommand{
|
|
|
206
|
+ Id: param.Id,
|
|
|
207
|
+ }
|
|
|
208
|
+ if param.status == "1" {
|
|
|
209
|
+ //禁用操作
|
|
|
210
|
+ cmd.Status = domain.PARTNER_STATUS_NO
|
|
|
211
|
+ } else if param.status == "2" {
|
|
|
212
|
+ //启用操作
|
|
|
213
|
+ cmd.Status = domain.PARTNER_STATUS_YES
|
|
|
214
|
+ } else {
|
|
|
215
|
+ //错误
|
|
|
216
|
+ c.ResponseError(lib.ThrowError(lib.ARG_ERROR, "状态错误"))
|
|
|
217
|
+ return
|
|
|
218
|
+ }
|
|
|
219
|
+ newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
220
|
+ err = newPartnerService.UpdateStatus(cmd)
|
|
|
221
|
+ if err != nil {
|
|
|
222
|
+ c.ResponseError(err)
|
|
|
223
|
+ return
|
|
|
224
|
+ }
|
|
|
225
|
+ c.ResponseData(nil)
|
|
|
226
|
+ return
|
89
|
}
|
227
|
}
|
90
|
|
228
|
|
91
|
//ListPartnerInfo 合伙人列表
|
229
|
//ListPartnerInfo 合伙人列表
|
92
|
-func (controller *PartnerInfoController) ListPartnerInfo() {
|
|
|
93
|
- // var (
|
|
|
94
|
- // service = service.NewPartnerInfoService(nil)
|
|
|
95
|
- // command = &query.ListPartnerInfoQuery{}
|
|
|
96
|
- // )
|
|
|
97
|
- // command.PartnerCategory, _ = controller.GetInt("partnerCategory")
|
|
|
98
|
- // command.Status, _ = controller.GetInt("status")
|
|
|
99
|
- // command.SortByCreateTime = controller.GetString("sortByCreateTime")
|
|
|
100
|
- // command.SortByUpdateTime = controller.GetString("sortByUpdateTime")
|
|
|
101
|
- // command.Offset, command.Limit = controller.GetLimitInfo()
|
|
|
102
|
- // controller.HandlerResponse(service.ListPartnerInfo(command))
|
230
|
+func (c *PartnerInfoController) ListPartnerInfo() {
|
|
|
231
|
+ type Parameter struct {
|
|
|
232
|
+ Partnertype string `json:"partnerType"`
|
|
|
233
|
+ Area string `json:"area"`
|
|
|
234
|
+ PartnerName string `json:"partnerName"`
|
|
|
235
|
+ PageSize int `json:"pageSize"`
|
|
|
236
|
+ PageNumber int `json:"pageNumber"`
|
|
|
237
|
+ }
|
|
|
238
|
+ var (
|
|
|
239
|
+ param Parameter
|
|
|
240
|
+ err error
|
|
|
241
|
+ )
|
|
|
242
|
+ if err = c.BindJsonData(¶m); err != nil {
|
|
|
243
|
+ logs.Error(err)
|
|
|
244
|
+ c.ResponseError(errors.New("json数据解析失败"))
|
|
|
245
|
+ return
|
|
|
246
|
+ }
|
|
|
247
|
+ partnertype, _ := strconv.Atoi(param.Partnertype)
|
|
|
248
|
+ if param.PageNumber == 0 {
|
|
|
249
|
+ param.PageNumber = 20
|
|
|
250
|
+ }
|
|
|
251
|
+ query := partnerQuery.ListPartnerInfoQuery{
|
|
|
252
|
+ Partnertype: partnertype,
|
|
|
253
|
+ PartnerName: param.PartnerName,
|
|
|
254
|
+ RegionInfo: param.Area,
|
|
|
255
|
+ Limit: param.PageNumber,
|
|
|
256
|
+ }
|
|
|
257
|
+
|
|
|
258
|
+ if param.PageSize == 0 {
|
|
|
259
|
+ query.Offset = 0
|
|
|
260
|
+ } else {
|
|
|
261
|
+ query.Offset = (param.PageNumber - 1) * param.PageSize
|
|
|
262
|
+ }
|
|
|
263
|
+ newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
|
|
|
264
|
+ count, partners, err := newPartnerService.ListPartnerInfo(&query)
|
|
|
265
|
+ if err != nil {
|
|
|
266
|
+ c.ResponseError(err)
|
|
|
267
|
+ return
|
|
|
268
|
+ }
|
|
|
269
|
+ resp := []map[string]interface{}{}
|
|
|
270
|
+ for i := range partners {
|
|
|
271
|
+ m := map[string]interface{}{
|
|
|
272
|
+ "id": partners[i].Id,
|
|
|
273
|
+ "account": partners[i].Account,
|
|
|
274
|
+ "partnerName": partners[i].PartnerName,
|
|
|
275
|
+ "area": partners[i].RegionInfo.RegionName,
|
|
|
276
|
+ "createTime": partners[i].CreateAt.Format("2006-01-02 15:04:05"),
|
|
|
277
|
+ "cooperationTime": partners[i].CooperateTime.Format("2006-01-02"),
|
|
|
278
|
+ "state": fmt.Sprint(partners[i].Status),
|
|
|
279
|
+ "salesmanName": "",
|
|
|
280
|
+ "phone": "",
|
|
|
281
|
+ }
|
|
|
282
|
+ if len(partners[i].Salesman) > 0 {
|
|
|
283
|
+ m["salesmanName"] = partners[i].Salesman[0].Name
|
|
|
284
|
+ m["phone"] = partners[i].Salesman[0].Telephone
|
|
|
285
|
+ }
|
|
|
286
|
+ resp = append(resp, m)
|
|
|
287
|
+ }
|
|
|
288
|
+ c.ResponsePageList(resp, count, param.PageNumber)
|
|
|
289
|
+ return
|
103
|
} |
290
|
} |