Quellcode durchsuchen

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

XMLWAN vor 3 Jahren
Ursprung
Commit
53597dc034
2 geänderte Dateien mit 47 neuen und 34 gelöschten Zeilen
  1. 17 15
      controllers/supply_order_api_contorller.go
  2. 30 19
      service/supply_service.go

+ 17 - 15
controllers/supply_order_api_contorller.go Datei anzeigen

@@ -20,11 +20,11 @@ type SupplyOrderApiController struct {
20 20
 }
21 21
 
22 22
 func SupplyOrderApiRegistRouters() {
23
-	//获取供应商列表GetSupplyList
23
+	//获取供应商列表(orgid)
24 24
 	beego.Router("/api/supply/getsupplylist", &SupplyOrderApiController{}, "get:GetSupplyList")
25
-	//保存供应商及联系人(用于更改)
25
+	//保存供应商及联系人(用于更改N
26 26
 	beego.Router("/api/supply/updatesupply", &SupplyOrderApiController{}, "post:UpdateSupply")
27
-	//删除单条联系人
27
+	//删除单条联系人(N)
28 28
 	beego.Router("/api/supply/delcontactone", &SupplyOrderApiController{}, "get:DelContactOne")
29 29
 	//获取单条供应商和涉及到的联系人记录
30 30
 	beego.Router("/api/supply/getsupplyandcontactone", &SupplyOrderApiController{}, "get:GetSupplyAndContactOne")
@@ -138,7 +138,7 @@ func (this *SupplyOrderApiController) GetSupplyList() {
138 138
 	keyword := this.GetString("keyword") //供应商编号\供应商名称\联系人名字
139 139
 	orgId := this.GetAdminUserInfo().CurrentOrgId
140 140
 	//获取分页的数据
141
-	list, total, err := service.GetSupplyList(ctype, page, limit, keyword)
141
+	list, total, err := service.GetSupplyList(ctype, page, limit, keyword, orgId)
142 142
 	//获取供应商类别
143 143
 	costClassify := "供应商类别"
144 144
 	drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
@@ -154,7 +154,7 @@ func (this *SupplyOrderApiController) GetSupplyList() {
154 154
 	if err == nil {
155 155
 		for i := 0; i < len(list); i++ {
156 156
 			code := list[i].SupplierCode
157
-			fistname, errs := service.FindName(code)
157
+			fistname, errs := service.FindName(code, orgId)
158 158
 			if errs != nil && errs.Error() != "record not found" {
159 159
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
160 160
 				return
@@ -217,6 +217,7 @@ func (this *SupplyOrderApiController) GetSupplyList() {
217 217
 
218 218
 //保存供应商及联系人(用于更改)
219 219
 func (this *SupplyOrderApiController) UpdateSupply() {
220
+	orgId := this.GetAdminUserInfo().CurrentOrgId
220 221
 	dataBody := make(map[string]interface{}, 0)
221 222
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
222 223
 	if err != nil {
@@ -254,7 +255,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
254 255
 	}
255 256
 	if supplierName != supply.SupplierName {
256 257
 		//判断供应商名称是否有重复的
257
-		sbool, _ := service.FindSupplierName(supplierName)
258
+		sbool, _ := service.FindSupplierName(supplierName, orgId)
258 259
 		if sbool { //有重复的
259 260
 			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
260 261
 			return
@@ -262,7 +263,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
262 263
 	}
263 264
 	if supplierCode != supply.SupplierCode {
264 265
 		//判断供应商编号是否有重复的
265
-		codebool, _ := service.FindSupplierCode(supplierCode)
266
+		codebool, _ := service.FindSupplierCode(supplierCode, supplierid, orgId)
266 267
 		if codebool {
267 268
 			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
268 269
 			return
@@ -285,7 +286,6 @@ func (this *SupplyOrderApiController) UpdateSupply() {
285 286
 	bank := dataBody["bank"].(string) //纳税人识别号
286 287
 	//bankAccount := this.GetString("bankAccount")     //银行账号
287 288
 	bankAccount := dataBody["bankaccount"].(string)
288
-	orgId := this.GetAdminUserInfo().CurrentOrgId
289 289
 	//contacts := this.Get("contacts")//联系人
290 290
 	//dataBody := make(map[string]interface{}, 0)
291 291
 	//err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
@@ -323,6 +323,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
323 323
 
324 324
 //获取单条供应商和涉及到的联系人记录
325 325
 func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
326
+	orgId := this.GetAdminUserInfo().CurrentOrgId
326 327
 	id, _ := this.GetInt64("id")
327 328
 	check := map[string][]string{
328 329
 		"id": {"must", "string", "id"},
@@ -335,9 +336,8 @@ func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
335 336
 	//	this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
336 337
 	//	return
337 338
 	//}
338
-	supply, contact, err := service.GetSupplyAndContactOne(id)
339
+	supply, contact, err := service.GetSupplyAndContactOne(id, orgId)
339 340
 	//获取供应商类别
340
-	orgId := this.GetAdminUserInfo().CurrentOrgId
341 341
 	costClassify := "供应商类别"
342 342
 	drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
343 343
 	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
@@ -451,7 +451,8 @@ func (this *SupplyOrderApiController) DelContactOne() {
451 451
 
452 452
 //获取供应商编码
453 453
 func (this *SupplyOrderApiController) GetSupplyCode() {
454
-	supply, err := service.GetSuppliyCode()
454
+	orgId := this.GetAdminUserInfo().CurrentOrgId
455
+	supply, err := service.GetSuppliyCode(orgId)
455 456
 	if err != nil {
456 457
 		return
457 458
 	}
@@ -483,6 +484,7 @@ func (this *SupplyOrderApiController) GetSupplyCode() {
483 484
 
484 485
 //保存供应商
485 486
 func (this *SupplyOrderApiController) SaveSupply() {
487
+	orgId := this.GetAdminUserInfo().CurrentOrgId
486 488
 	//supplierName := this.GetString("suppliername") //供应商名称
487 489
 	dataBody := make(map[string]interface{}, 0)
488 490
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
@@ -497,7 +499,7 @@ func (this *SupplyOrderApiController) SaveSupply() {
497 499
 		return
498 500
 	}
499 501
 	//判断供应商名称是否有重复的
500
-	sbool, _ := service.FindSupplierName(supplierName)
502
+	sbool, _ := service.FindSupplierName(supplierName, orgId)
501 503
 	if sbool { //有重复的
502 504
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
503 505
 		return
@@ -509,7 +511,7 @@ func (this *SupplyOrderApiController) SaveSupply() {
509 511
 		return
510 512
 	}
511 513
 	//判断供应商编号是否有重复的
512
-	codebool, _ := service.FindSupplierCode(supplierCode)
514
+	codebool, _ := service.FindSupplierCodes(supplierCode, orgId)
513 515
 	if codebool {
514 516
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
515 517
 		return
@@ -528,14 +530,14 @@ func (this *SupplyOrderApiController) SaveSupply() {
528 530
 	}
529 531
 	supplierType := int64(dataBody["suppliertype"].(float64)) //供应商类别
530 532
 	//vatRate, _ := this.GetFloat("vatrate")
531
-	vatRate, _ := dataBody["suppliertype"].(float64) //增值税税率
533
+	vatRate, _ := dataBody["vatrate"].(float64) //增值税税率
532 534
 	//number := this.GetString("number")
533 535
 	number := dataBody["number"].(string)
534 536
 	//bank := this.GetString("bank")
535 537
 	bank := dataBody["bank"].(string)
536 538
 	//bankAccount := this.GetString("bankAccount")
537 539
 	bankAccount := dataBody["bankaccount"].(string)
538
-	orgId := this.GetAdminUserInfo().CurrentOrgId
540
+
539 541
 	//contacts := this.Get("contacts")//联系人
540 542
 	//err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
541 543
 	//if err != nil {

+ 30 - 19
service/supply_service.go Datei anzeigen

@@ -8,14 +8,14 @@ import (
8 8
 )
9 9
 
10 10
 //根据供应商编号获取首要联系人
11
-func FindName(code string) (fistname models.SpSupplierContacts, err error) {
12
-	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).First(&fistname).Error
11
+func FindName(code string, orgid int64) (fistname models.SpSupplierContacts, err error) {
12
+	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and is_first = 1 and user_org_id = ?", code, orgid).First(&fistname).Error
13 13
 	return fistname, err
14 14
 }
15 15
 
16 16
 //供应商分页
17
-func GetSupplyList(ctype int64, page int64, limit int64, keyword string) (supplylist []*models.SpSupplierName, total int64, err error) {
18
-	db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 ")
17
+func GetSupplyList(ctype int64, page int64, limit int64, keyword string, orgid int64) (supplylist []*models.SpSupplierName, total int64, err error) {
18
+	db := XTReadDB().Model(&supplylist).Where("xt_supplier_name.status = 1 and xt_supplier_name.user_org_id = ?", orgid)
19 19
 
20 20
 	offset := (page - 1) * limit
21 21
 
@@ -99,7 +99,7 @@ func UpdateSupplyAndContact(thisStockIn []interface{}, suid, orgId, supplierType
99 99
 		if isfirst == 1 {
100 100
 			if id == 0 {
101 101
 				var spconid []*models.SpSupplierContacts
102
-				spconid, err = SaveContactsId(tx)
102
+				spconid, err = SaveContactsId(tx, orgId)
103 103
 				if err != nil {
104 104
 					return err
105 105
 				}
@@ -158,10 +158,10 @@ func DelContactOne(id int64) error {
158 158
 }
159 159
 
160 160
 //获取单条供应商和涉及到的联系人记录
161
-func GetSupplyAndContactOne(id int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
162
-	err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1", id).First(&supply).Error
161
+func GetSupplyAndContactOne(id, orgId int64) (supply models.SpSupplierName, contact []*models.SpSupplierContacts, err error) {
162
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("id = ? and status = 1 and user_org_id = ?", id, orgId).First(&supply).Error
163 163
 	code := supply.SupplierCode
164
-	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1", code).Find(&contact).Error
164
+	err = XTReadDB().Model(&models.SpSupplierContacts{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", code, orgId).Find(&contact).Error
165 165
 	return supply, contact, err
166 166
 }
167 167
 
@@ -212,7 +212,7 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
212 212
 		err = SaveContacts(spcontacts, tx)
213 213
 		if isfirst == 1 {
214 214
 			var spconid []*models.SpSupplierContacts
215
-			spconid, err = SaveContactsId(tx)
215
+			spconid, err = SaveContactsId(tx, orgId)
216 216
 			if err != nil {
217 217
 				return err
218 218
 			}
@@ -247,14 +247,13 @@ func SaveSupplyAndContact(thisStockIn []interface{}, orgId, supplierType, tcreat
247 247
 }
248 248
 
249 249
 //获取供应商编码
250
-func GetSuppliyCode() (spcode []*models.SpSupplierName, err error) {
251
-
252
-	err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 ").Order("supplier_code desc").First(&spcode).Error
250
+func GetSuppliyCode(orgId int64) (spcode []*models.SpSupplierName, err error) {
251
+	err = XTReadDB().Model(&models.SpSupplierName{}).Select("supplier_code").Where("supplier_code like 'gys%' and status = 1 and user_org_id = ? ", orgId).Order("supplier_code desc").First(&spcode).Error
253 252
 	return spcode, err
254 253
 }
255 254
 
256 255
 //查询供应商的名字是否有重复
257
-func FindSupplierName(supplierName string) (sbool bool, err error) {
256
+func FindSupplierName(supplierName string, orgId int64) (sbool bool, err error) {
258 257
 	var total int
259 258
 	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
260 259
 	if total != 0 {
@@ -265,11 +264,23 @@ func FindSupplierName(supplierName string) (sbool bool, err error) {
265 264
 	return sbool, err
266 265
 }
267 266
 
268
-//查询供应商的编号是否有重复
269
-func FindSupplierCode(supplierCode string) (codebool bool, err error) {
267
+//查询供应商的编号是否有重复(用于修改)
268
+func FindSupplierCode(supplierCode string, supplierid, orgid int64) (codebool bool, err error) {
270 269
 	var total int
271
-	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierCode).Count(&total).Error
272
-	if total != 0 {
270
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and id != ? and user_org_id = ? and status = 1", supplierCode, supplierid, orgid).Count(&total).Error
271
+	if total > 0 {
272
+		codebool = true
273
+	} else {
274
+		codebool = false
275
+	}
276
+	return codebool, err
277
+}
278
+
279
+//查询供应商的编号是否有重复(用于新增)
280
+func FindSupplierCodes(supplierCode string, orgid int64) (codebool bool, err error) {
281
+	var total int
282
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", supplierCode, orgid).Count(&total).Error
283
+	if total > 0 {
273 284
 		codebool = true
274 285
 	} else {
275 286
 		codebool = false
@@ -284,8 +295,8 @@ func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
284 295
 }
285 296
 
286 297
 //获取联系人的id
287
-func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
288
-	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1").Order("id desc").First(&spconid).Error
298
+func SaveContactsId(tx *gorm.DB, orgid int64) (spconid []*models.SpSupplierContacts, err error) {
299
+	err = tx.Model(&models.SpSupplierContacts{}).Select("id").Where("status = 1 and user_org_id = ?", orgid).Order("id desc").First(&spconid).Error
289 300
 	return
290 301
 }
291 302