Просмотр исходного кода

Merge branch '20211122' of http://git.shengws.com/csx/XT_New into 20211122

csx 3 лет назад
Родитель
Сommit
6333b0afd2
2 измененных файлов: 148 добавлений и 44 удалений
  1. 111 20
      controllers/supply_order_api_contorller.go
  2. 37 24
      service/supply_service.go

+ 111 - 20
controllers/supply_order_api_contorller.go Просмотреть файл

@@ -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 {

+ 37 - 24
service/supply_service.go Просмотреть файл

@@ -3,7 +3,6 @@ package service
3 3
 import (
4 4
 	"XT_New/models"
5 5
 	"github.com/jinzhu/gorm"
6
-	"strconv"
7 6
 	"time"
8 7
 )
9 8
 
@@ -14,28 +13,20 @@ func FindName(code string) (fistname models.SpSupplierContacts, err error) {
14 13
 }
15 14
 
16 15
 //供应商分页
17
-func GetSupplyList(ctype int64, page int64, limit int64, code string, sname string, cname string) (supplylist []*models.SpSupplierName, total int64, err error) {
18
-	db := XTReadDB().Model(&supplylist).Where("sgj_xt.xt_supplier_name.status = 1 ")
16
+func GetSupplyList(ctype int64, page int64, limit int64, keyword string) (supplylist []*models.SpSupplierName, total int64, err error) {
17
+	db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 ")
19 18
 
20 19
 	offset := (page - 1) * limit
21 20
 
22
-	if cname != "" {
23
-		cname = "%" + cname + "%" //联系人
24
-		db = db.Joins("join sgj_xt.xt_supplier_contacts on sgj_xt.xt_supplier_contacts.supplier_code = sgj_xt.xt_supplier_name.supplier_code")
25
-		db = db.Where("sgj_xt.xt_supplier_contacts.name like ? and sgj_xt.xt_supplier_contacts.status = 1 ", cname).Group("sgj_xt.xt_supplier_name.id")
21
+	if len(keyword) > 0 {
22
+		keyword = "%" + keyword + "%" //联系人
23
+		db = db.Joins("join xt_supplier_contacts on xt_supplier_contacts.supplier_code = xt_supplier_name.supplier_code")
24
+		db = db.Where("xt_supplier_contacts.name like ? or xt_supplier_name.supplier_code like ? or xt_supplier_name.supplier_name like ? ", keyword, keyword, keyword).Group("xt_supplier_name.id")
26 25
 	}
27 26
 	if ctype > 0 {
28
-		db = db.Where("sgj_xt.xt_supplier_name.supplier_type = ?", ctype)
29
-	}
30
-	if code != "" {
31
-		code = "%" + code + "%" //供应商编码
32
-		db = db.Where("sgj_xt.xt_supplier_name.supplier_code = ?", code)
33
-	}
34
-	if sname != "" {
35
-		sname = "%" + sname + "%" //供应商名称
36
-		db = db.Where("sgj_xt.xt_supplier_name.supplier_name = ?", sname)
27
+		db = db.Where("xt_supplier_name.supplier_type = ?", ctype)
37 28
 	}
38
-	err = db.Count(&total).Offset(offset).Limit(limit).Find(&supplylist).Error
29
+	err = db.Count(&total).Offset(offset).Order("xt_supplier_name.id desc").Limit(limit).Find(&supplylist).Error
39 30
 	return supplylist, total, err
40 31
 }
41 32
 
@@ -52,11 +43,26 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
52 43
 	for _, item := range thisStockIn {
53 44
 		items := item.(map[string]interface{})
54 45
 		//查询是否
55
-		id, _ := strconv.ParseInt(items["id"].(string), 10, 64)
46
+		if items["id"] == "" || items["id"] == 0 {
47
+			var tmp float64 = 0
48
+			items["id"] = tmp
49
+		}
50
+		//id, _ := strconv.ParseInt(items["id"].(string), 10, 64)
51
+		id := int64(items["id"].(float64))
56 52
 		name := items["name"].(string)
57 53
 		phone := items["phone"].(string)
58 54
 		address := items["address"].(string)
59
-		isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
55
+		var tmpfirst int64
56
+		//tmptype :=  reflect.TypeOf(items["is_first"])
57
+		switch items["is_first"].(type) {
58
+		case int:
59
+			var aint int = items["is_first"].(int)
60
+			tmpfirst = int64(aint)
61
+		case float64:
62
+			tmpfirst = int64(items["is_first"].(float64))
63
+		}
64
+		isfirst := tmpfirst
65
+
60 66
 		updatecontacts := models.SpSupplierContacts{
61 67
 			ID:           id,
62 68
 			Name:         name,
@@ -93,7 +99,6 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
93 99
 			if id == 0 {
94 100
 				var spconid []*models.SpSupplierContacts
95 101
 				spconid, err = SaveContactsId(tx)
96
-
97 102
 				if err != nil {
98 103
 					return err
99 104
 				}
@@ -180,7 +185,17 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
180 185
 		name := items["name"].(string)
181 186
 		phone := items["phone"].(string)
182 187
 		address := items["address"].(string)
183
-		isfirst, _ := strconv.ParseInt(items["isfirst"].(string), 10, 64)
188
+		//isfirst := int64(items["is_first"].(float64))
189
+		var tmpfirst int64
190
+		//tmptype :=  reflect.TypeOf(items["is_first"])
191
+		switch items["is_first"].(type) {
192
+		case int:
193
+			var aint int = items["is_first"].(int)
194
+			tmpfirst = int64(aint)
195
+		case float64:
196
+			tmpfirst = int64(items["is_first"].(float64))
197
+		}
198
+		isfirst := tmpfirst
184 199
 
185 200
 		spcontacts := models.SpSupplierContacts{
186 201
 			Name:         name,
@@ -197,7 +212,6 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
197 212
 		if isfirst == 1 {
198 213
 			var spconid []*models.SpSupplierContacts
199 214
 			spconid, err = SaveContactsId(tx)
200
-
201 215
 			if err != nil {
202 216
 				return err
203 217
 			}
@@ -223,7 +237,6 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
223 237
 			if err != nil {
224 238
 				return err
225 239
 			}
226
-
227 240
 		}
228 241
 		if err != nil {
229 242
 			return err
@@ -271,7 +284,7 @@ func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
271 284
 
272 285
 //获取联系人的id
273 286
 func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
274
-	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("and status = 1").Order("id desc").First(&spconid).Error
287
+	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1").Order("id desc").First(&spconid).Error
275 288
 	return
276 289
 }
277 290