|
@@ -289,25 +289,72 @@ func (this *SupplyOrderApiController) UpdateSupply() {
|
289
|
289
|
bank := dataBody["bank"].(string) //纳税人识别号
|
290
|
290
|
//bankAccount := this.GetString("bankAccount") //银行账号
|
291
|
291
|
bankAccount := dataBody["bankaccount"].(string)
|
|
292
|
+ tmodify := this.GetAdminUserInfo().AdminUser.Id //修改者
|
292
|
293
|
//保存联系人
|
293
|
294
|
if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
|
294
|
295
|
thisStockIn, _ := dataBody["contacts"].([]interface{})
|
295
|
296
|
if len(thisStockIn) > 0 {
|
296
|
|
- if len(thisStockIn) == 1 {
|
|
297
|
+ for _, v := range thisStockIn { //这个循环是用来检测当填了手机号时联系人不能为空
|
|
298
|
+ vtem := v.(map[string]interface{})
|
|
299
|
+ if vtem["phone"].(string) != "" && vtem["name"].(string) == "" {
|
|
300
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
|
|
301
|
+ return
|
|
302
|
+ }
|
|
303
|
+ }
|
|
304
|
+ if len(thisStockIn) == 1 { //当只有一条联系人时强制设为首要联系人
|
297
|
305
|
for _, item := range thisStockIn {
|
298
|
306
|
items := item.(map[string]interface{})
|
299
|
307
|
items["is_first"] = 1
|
|
308
|
+ //如果电话和联系人都为空,不保存联系人
|
|
309
|
+ if items["phone"] == "" && items["name"] == "" {
|
|
310
|
+ upsupply := models.SpSupplierName{
|
|
311
|
+ ID: supplierid,
|
|
312
|
+ SupplierCode: supplierCode,
|
|
313
|
+ SupplierName: supplierName,
|
|
314
|
+ SupplierType: supplierType,
|
|
315
|
+ VatRate: vatRate,
|
|
316
|
+ Number: number,
|
|
317
|
+ Bank: bank,
|
|
318
|
+ BankAccount: bankAccount,
|
|
319
|
+ Status: 1,
|
|
320
|
+ Mtime: time.Now().Unix(),
|
|
321
|
+ Modify: tmodify,
|
|
322
|
+ }
|
|
323
|
+ err = service.UpdateSupplyName(upsupply)
|
|
324
|
+ if err != nil {
|
|
325
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
|
326
|
+ return
|
|
327
|
+ }
|
|
328
|
+ }
|
300
|
329
|
}
|
301
|
330
|
}
|
302
|
|
- tmodify := this.GetAdminUserInfo().AdminUser.Id
|
303
|
331
|
err = service.UpdateSupplyAndContact(thisStockIn, supplierid, orgId, supplierType, tmodify, supplierCode, supplierName, number, bank, bankAccount, vatRate)
|
304
|
332
|
if err != nil {
|
305
|
333
|
this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
306
|
334
|
return
|
307
|
335
|
}
|
308
|
336
|
} else {
|
309
|
|
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
|
310
|
|
- return
|
|
337
|
+ //如果联系人是空的,直接保存供应商
|
|
338
|
+ //更新供应商
|
|
339
|
+ upsupply := models.SpSupplierName{
|
|
340
|
+ ID: supplierid,
|
|
341
|
+ SupplierCode: supplierCode,
|
|
342
|
+ SupplierName: supplierName,
|
|
343
|
+ SupplierType: supplierType,
|
|
344
|
+ VatRate: vatRate,
|
|
345
|
+ Number: number,
|
|
346
|
+ Bank: bank,
|
|
347
|
+ BankAccount: bankAccount,
|
|
348
|
+ Status: 1,
|
|
349
|
+ Mtime: time.Now().Unix(),
|
|
350
|
+ Modify: tmodify,
|
|
351
|
+ }
|
|
352
|
+ err = service.UpdateSupplyName(upsupply)
|
|
353
|
+ if err != nil {
|
|
354
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
|
355
|
+ return
|
|
356
|
+ }
|
|
357
|
+
|
311
|
358
|
}
|
312
|
359
|
}
|
313
|
360
|
this.ServeSuccessJSON(map[string]interface{}{
|
|
@@ -520,7 +567,7 @@ func (this *SupplyOrderApiController) SaveSupply() {
|
520
|
567
|
dataBody["suppliertype"] = tmp
|
521
|
568
|
}
|
522
|
569
|
if dataBody["vatrate"] == "" {
|
523
|
|
- dataBody["vatrate"] = 0
|
|
570
|
+ dataBody["vatrate"] = "0"
|
524
|
571
|
}
|
525
|
572
|
//supplierType, _ := this.GetInt64("suppliertype")
|
526
|
573
|
if dataBody["suppliertype"] == "" || dataBody["suppliertype"] == 0 {
|
|
@@ -544,33 +591,74 @@ func (this *SupplyOrderApiController) SaveSupply() {
|
544
|
591
|
bank := dataBody["bank"].(string)
|
545
|
592
|
//bankAccount := this.GetString("bankAccount")
|
546
|
593
|
bankAccount := dataBody["bankaccount"].(string)
|
547
|
|
-
|
548
|
|
- //contacts := this.Get("contacts")//联系人
|
549
|
|
- //err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
|
550
|
|
- //if err != nil {
|
551
|
|
- // utils.ErrorLog(err.Error())
|
552
|
|
- // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
553
|
|
- // return
|
554
|
|
- //}
|
|
594
|
+ tcreater := this.GetAdminUserInfo().AdminUser.Id
|
555
|
595
|
//保存联系人
|
556
|
596
|
if dataBody["contacts"] != nil && reflect.TypeOf(dataBody["contacts"]).String() == "[]interface {}" {
|
557
|
597
|
thisStockIn, _ := dataBody["contacts"].([]interface{})
|
558
|
598
|
if len(thisStockIn) > 0 {
|
559
|
|
- if len(thisStockIn) == 1 {
|
|
599
|
+ for _, v := range thisStockIn { //这个循环是用来检测当填了手机号时联系人不能为空
|
|
600
|
+ vtem := v.(map[string]interface{})
|
|
601
|
+ if vtem["phone"] != "" && vtem["name"] == nil {
|
|
602
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
|
|
603
|
+ return
|
|
604
|
+ }
|
|
605
|
+ }
|
|
606
|
+ if len(thisStockIn) == 1 { //当只有一条联系人时强制设为首要联系人,
|
560
|
607
|
for _, item := range thisStockIn {
|
561
|
608
|
items := item.(map[string]interface{})
|
562
|
609
|
items["is_first"] = 1
|
|
610
|
+ //如果电话和联系人都为空,不保存联系人
|
|
611
|
+ if items["phone"] == "" && items["name"] == "" {
|
|
612
|
+ supply := models.SpSupplierName{
|
|
613
|
+ SupplierCode: supplierCode,
|
|
614
|
+ SupplierName: supplierName,
|
|
615
|
+ SupplierType: supplierType,
|
|
616
|
+ VatRate: vatRate,
|
|
617
|
+ Number: number,
|
|
618
|
+ Bank: bank,
|
|
619
|
+ BankAccount: bankAccount,
|
|
620
|
+ UserOrgId: orgId,
|
|
621
|
+ Status: 1,
|
|
622
|
+ Ctime: time.Now().Unix(),
|
|
623
|
+ Mtime: 0,
|
|
624
|
+ Creater: tcreater,
|
|
625
|
+ Modify: tcreater,
|
|
626
|
+ }
|
|
627
|
+ err = service.SaveSupply(supply)
|
|
628
|
+ if err != nil {
|
|
629
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
|
630
|
+ return
|
|
631
|
+ }
|
|
632
|
+ }
|
563
|
633
|
}
|
564
|
634
|
}
|
565
|
|
- tcreater := this.GetAdminUserInfo().AdminUser.Id
|
566
|
635
|
err = service.SaveSupplyAndContact(thisStockIn, orgId, supplierType, tcreater, supplierCode, supplierName, number, bank, bankAccount, vatRate)
|
567
|
636
|
if err != nil {
|
568
|
637
|
this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
569
|
638
|
return
|
570
|
639
|
}
|
571
|
640
|
} else {
|
572
|
|
- this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "联系人不能为空")
|
573
|
|
- return
|
|
641
|
+ //如果联系人是空的,这里直接保存供应商
|
|
642
|
+ supply := models.SpSupplierName{
|
|
643
|
+ SupplierCode: supplierCode,
|
|
644
|
+ SupplierName: supplierName,
|
|
645
|
+ SupplierType: supplierType,
|
|
646
|
+ VatRate: vatRate,
|
|
647
|
+ Number: number,
|
|
648
|
+ Bank: bank,
|
|
649
|
+ BankAccount: bankAccount,
|
|
650
|
+ UserOrgId: orgId,
|
|
651
|
+ Status: 1,
|
|
652
|
+ Ctime: time.Now().Unix(),
|
|
653
|
+ Mtime: 0,
|
|
654
|
+ Creater: tcreater,
|
|
655
|
+ Modify: tcreater,
|
|
656
|
+ }
|
|
657
|
+ err = service.SaveSupply(supply)
|
|
658
|
+ if err != nil {
|
|
659
|
+ this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
|
|
660
|
+ return
|
|
661
|
+ }
|
574
|
662
|
}
|
575
|
663
|
}
|
576
|
664
|
this.ServeSuccessJSON(map[string]interface{}{
|