|
@@ -90,21 +90,40 @@ func SupplyOrderApiRegistRouters() {
|
90
|
90
|
beego.Router("/api/supply/getsupplywarehouseoutbyid", &SupplyOrderApiController{}, "Get:GetSupplyWarehouseById")
|
91
|
91
|
}
|
92
|
92
|
|
|
93
|
+//判断前端参数是否为空
|
|
94
|
+func CheckParams(this *SupplyOrderApiController, m *map[string][]string) (map[string]string, error) {
|
|
95
|
+ tmp := make(map[string]string)
|
|
96
|
+ for k, v := range *m {
|
|
97
|
+ t := this.GetString(k)
|
|
98
|
+ if v[0] == "must" && t == "" {
|
|
99
|
+ return nil, fmt.Errorf(v[2] + "不能为空")
|
|
100
|
+ }
|
|
101
|
+ tmp[k] = t
|
|
102
|
+ }
|
|
103
|
+ return tmp, nil
|
|
104
|
+}
|
|
105
|
+
|
93
|
106
|
//获取供应商列表GetSupplyList
|
94
|
107
|
func (this *SupplyOrderApiController) GetSupplyList() {
|
95
|
108
|
ctype, _ := this.GetInt64("ctype") //供应商类别
|
96
|
109
|
page, _ := this.GetInt64("page") //页码
|
97
|
110
|
limit, _ := this.GetInt64("limit") //每一页查出来的条数
|
98
|
|
- if page == 0 || limit == 0 {
|
99
|
|
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
|
100
|
|
- return
|
|
111
|
+ check := map[string][]string{
|
|
112
|
+ "page": {"must", "string", "page"},
|
|
113
|
+ "limit": {"must", "string", "limit"},
|
101
|
114
|
}
|
102
|
|
- code := this.GetString("code") //供应商编号
|
103
|
|
- sname := this.GetString("sname") //供应商名称
|
104
|
|
- cname := this.GetString("cname") //联系人名字
|
|
115
|
+ _, err := CheckParams(this, &check)
|
|
116
|
+ if err != nil {
|
|
117
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
|
118
|
+ }
|
|
119
|
+ //if page == 0 || limit == 0 {
|
|
120
|
+ // this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "page或limit参数不能为空")
|
|
121
|
+ // return
|
|
122
|
+ //}
|
|
123
|
+ keyword := this.GetString("keyword") //供应商编号\供应商名称\联系人名字
|
105
|
124
|
orgId := this.GetAdminUserInfo().CurrentOrgId
|
106
|
125
|
//获取分页的数据
|
107
|
|
- list, total, err := service.GetSupplyList(ctype, page, limit, code, sname, cname)
|
|
126
|
+ list, total, err := service.GetSupplyList(ctype, page, limit, keyword)
|
108
|
127
|
//获取供应商类别
|
109
|
128
|
costClassify := "供应商类别"
|
110
|
129
|
drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
|
|
@@ -183,7 +202,6 @@ func (this *SupplyOrderApiController) GetSupplyList() {
|
183
|
202
|
|
184
|
203
|
//保存供应商及联系人(用于更改)
|
185
|
204
|
func (this *SupplyOrderApiController) UpdateSupply() {
|
186
|
|
- fmt.Printf("HAHHAH")
|
187
|
205
|
dataBody := make(map[string]interface{}, 0)
|
188
|
206
|
err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
189
|
207
|
if err != nil {
|
|
@@ -191,6 +209,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
|
191
|
209
|
this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
192
|
210
|
return
|
193
|
211
|
}
|
|
212
|
+
|
194
|
213
|
supplierName := dataBody["suppliername"].(string)
|
195
|
214
|
if supplierName == "" {
|
196
|
215
|
this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称不能为空")
|
|
@@ -204,9 +223,9 @@ func (this *SupplyOrderApiController) UpdateSupply() {
|
204
|
223
|
}
|
205
|
224
|
//supplierid, _ := this.GetInt64("id") //供应商id
|
206
|
225
|
//fmt.Println(dataBody["id"])
|
207
|
|
- utils.InfoLog("+++++++++++++前++++++++++++++++++", dataBody["id"])
|
|
226
|
+ //utils.InfoLog("+++++++++++++前++++++++++++++++++", dataBody["id"])
|
208
|
227
|
supplierid := int64(dataBody["id"].(float64))
|
209
|
|
- utils.InfoLog("+++++++++++++后++++++++++++++++++", supplierid)
|
|
228
|
+ //utils.InfoLog("+++++++++++++后++++++++++++++++++", supplierid)
|
210
|
229
|
if supplierid == 0 {
|
211
|
230
|
this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
|
212
|
231
|
return
|
|
@@ -235,6 +254,13 @@ func (this *SupplyOrderApiController) UpdateSupply() {
|
235
|
254
|
}
|
236
|
255
|
}
|
237
|
256
|
//supplierType, _ := this.GetInt64("suppliertype") //供应商类别
|
|
257
|
+ if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
|
|
258
|
+ var tmp float64 = 0
|
|
259
|
+ dataBody["suppliertype"] = tmp
|
|
260
|
+ }
|
|
261
|
+ if dataBody["vatrate"] == "" {
|
|
262
|
+ dataBody["vatrate"] = 0
|
|
263
|
+ }
|
238
|
264
|
supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
|
239
|
265
|
//vatRate, _ := this.GetFloat("vatrate") //增值税税率
|
240
|
266
|
vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
|
|
@@ -260,13 +286,13 @@ func (this *SupplyOrderApiController) UpdateSupply() {
|
260
|
286
|
if len(thisStockIn) == 1 {
|
261
|
287
|
for _, item := range thisStockIn {
|
262
|
288
|
items := item.(map[string]interface{})
|
263
|
|
- items["isfirst"] = 1
|
|
289
|
+ items["is_first"] = 1
|
264
|
290
|
}
|
265
|
291
|
}
|
266
|
292
|
tmodify := this.GetAdminUserInfo().AdminUser.Id
|
267
|
293
|
err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
|
268
|
294
|
if err != nil {
|
269
|
|
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
295
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
270
|
296
|
return
|
271
|
297
|
}
|
272
|
298
|
} else {
|
|
@@ -283,18 +309,72 @@ func (this *SupplyOrderApiController) UpdateSupply() {
|
283
|
309
|
//获取单条供应商和涉及到的联系人记录
|
284
|
310
|
func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
|
285
|
311
|
id, _ := this.GetInt64("id")
|
286
|
|
- if id == 0 {
|
287
|
|
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
|
288
|
|
- return
|
|
312
|
+ check := map[string][]string{
|
|
313
|
+ "id": {"must", "string", "id"},
|
|
314
|
+ }
|
|
315
|
+ _, err := CheckParams(this, &check)
|
|
316
|
+ if err != nil {
|
|
317
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
289
|
318
|
}
|
|
319
|
+ //if id == 0 {
|
|
320
|
+ // this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
|
|
321
|
+ // return
|
|
322
|
+ //}
|
290
|
323
|
supply, contact, err := service.GetSupplyAndContactOne(id)
|
|
324
|
+ //获取供应商类别
|
|
325
|
+ orgId := this.GetAdminUserInfo().CurrentOrgId
|
|
326
|
+ costClassify := "供应商类别"
|
|
327
|
+ drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
|
|
328
|
+ drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
|
|
329
|
+ tmpmap := make(map[int64]string) //储存供应商类别
|
|
330
|
+ for i := 0; i < len(drugTypeList); i++ {
|
|
331
|
+ k := int64(drugTypeList[i].Value)
|
|
332
|
+ v := drugTypeList[i].Name
|
|
333
|
+ tmpmap[k] = v
|
|
334
|
+ }
|
|
335
|
+ type SpSupplierNameList struct { //基于SpSupplierName结构体修改的,为了方便前端取数据整合了一下,删除了几个用不到的字段,添加了联系人名字和供应商类别两个字段
|
|
336
|
+ Id int64 `json:"id"`
|
|
337
|
+ Suppliercode string `json:"suppliercode"`
|
|
338
|
+ Suppliername string `json:"suppliername"`
|
|
339
|
+ Suppliertype int64 `json:"suppliertype"`
|
|
340
|
+ Vatrate float64 `json:"vatrate"`
|
|
341
|
+ Number string `json:"number"`
|
|
342
|
+ Bank string `json:"bank"`
|
|
343
|
+ Bankaccount string `json:"bankaccount"`
|
|
344
|
+ Userorgid int64 `json:"userorgid"`
|
|
345
|
+ Status int64 `json:"status"`
|
|
346
|
+ Contactsid int64 `json:"contactsid"`
|
|
347
|
+ Typename string `json:"typename"` //供应商类别
|
|
348
|
+ }
|
|
349
|
+
|
|
350
|
+ var typename string //类别名称
|
|
351
|
+ if supply.SupplierType == 0 {
|
|
352
|
+ typename = ""
|
|
353
|
+ } else {
|
|
354
|
+ typename = tmpmap[supply.SupplierType]
|
|
355
|
+ }
|
|
356
|
+ tlist := &SpSupplierNameList{
|
|
357
|
+ supply.ID,
|
|
358
|
+ supply.SupplierCode,
|
|
359
|
+ supply.SupplierName,
|
|
360
|
+ supply.SupplierType,
|
|
361
|
+ supply.VatRate,
|
|
362
|
+ supply.Number,
|
|
363
|
+ supply.Bank,
|
|
364
|
+ supply.BankAccount,
|
|
365
|
+ supply.UserOrgId,
|
|
366
|
+ supply.Status,
|
|
367
|
+ supply.ContactsId,
|
|
368
|
+ typename,
|
|
369
|
+ }
|
291
|
370
|
if err != nil {
|
292
|
371
|
utils.ErrorLog(err.Error())
|
293
|
372
|
this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
294
|
373
|
return
|
295
|
374
|
}
|
|
375
|
+ fmt.Println(tlist)
|
296
|
376
|
this.ServeSuccessJSON(map[string]interface{}{
|
297
|
|
- "supply": supply,
|
|
377
|
+ "supply": tlist,
|
298
|
378
|
"contact": contact,
|
299
|
379
|
})
|
300
|
380
|
return
|
|
@@ -419,9 +499,20 @@ func (this *SupplyOrderApiController) SaveSupply() {
|
419
|
499
|
this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
|
420
|
500
|
return
|
421
|
501
|
}
|
422
|
|
- //supplierType, _ := this.GetInt64("suppliertype") //供应商类别
|
|
502
|
+ if dataBody["suppliertype"] == "" {
|
|
503
|
+ var tmp int64 = 0
|
|
504
|
+ dataBody["suppliertype"] = tmp
|
|
505
|
+ }
|
|
506
|
+ if dataBody["vatrate"] == "" {
|
|
507
|
+ dataBody["vatrate"] = 0
|
|
508
|
+ }
|
|
509
|
+ //supplierType, _ := this.GetInt64("suppliertype")
|
|
510
|
+ if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
|
|
511
|
+ var tmp float64 = 0
|
|
512
|
+ dataBody["suppliertype"] = tmp
|
|
513
|
+ }
|
423
|
514
|
supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
|
424
|
|
- //vatRate, _ := this.GetFloat("vatrate") //增值税税率
|
|
515
|
+ //vatRate, _ := this.GetFloat("vatrate")
|
425
|
516
|
vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
|
426
|
517
|
//number := this.GetString("number")
|
427
|
518
|
number := dataBody["number"].(string)
|
|
@@ -444,13 +535,13 @@ func (this *SupplyOrderApiController) SaveSupply() {
|
444
|
535
|
if len(thisStockIn) == 1 {
|
445
|
536
|
for _, item := range thisStockIn {
|
446
|
537
|
items := item.(map[string]interface{})
|
447
|
|
- items["isfirst"] = 1
|
|
538
|
+ items["is_first"] = 1
|
448
|
539
|
}
|
449
|
540
|
}
|
450
|
541
|
tcreater := this.GetAdminUserInfo().AdminUser.Id
|
451
|
542
|
err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
|
452
|
543
|
if err != nil {
|
453
|
|
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
544
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
454
|
545
|
return
|
455
|
546
|
}
|
456
|
547
|
} else {
|