소스 검색

给更多的接口添加了机构id,同事修改了

mainqaq 3 년 전
부모
커밋
cdd4980ba2
2개의 변경된 파일27개의 추가작업 그리고 26개의 파일을 삭제
  1. 13 12
      controllers/supply_order_api_contorller.go
  2. 14 14
      service/supply_service.go

+ 13 - 12
controllers/supply_order_api_contorller.go 파일 보기

@@ -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")
@@ -148,7 +148,7 @@ func (this *SupplyOrderApiController) GetSupplyList() {
148 148
 	if err == nil {
149 149
 		for i := 0; i < len(list); i++ {
150 150
 			code := list[i].SupplierCode
151
-			fistname, errs := service.FindName(code)
151
+			fistname, errs := service.FindName(code, orgId)
152 152
 			if errs != nil && errs.Error() != "record not found" {
153 153
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
154 154
 				return
@@ -211,6 +211,7 @@ func (this *SupplyOrderApiController) GetSupplyList() {
211 211
 
212 212
 //保存供应商及联系人(用于更改)
213 213
 func (this *SupplyOrderApiController) UpdateSupply() {
214
+	orgId := this.GetAdminUserInfo().CurrentOrgId
214 215
 	dataBody := make(map[string]interface{}, 0)
215 216
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
216 217
 	if err != nil {
@@ -248,7 +249,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
248 249
 	}
249 250
 	if supplierName != supply.SupplierName {
250 251
 		//判断供应商名称是否有重复的
251
-		sbool, _ := service.FindSupplierName(supplierName)
252
+		sbool, _ := service.FindSupplierName(supplierName, orgId)
252 253
 		if sbool { //有重复的
253 254
 			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
254 255
 			return
@@ -256,7 +257,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
256 257
 	}
257 258
 	if supplierCode != supply.SupplierCode {
258 259
 		//判断供应商编号是否有重复的
259
-		codebool, _ := service.FindSupplierCode(supplierCode, supplierid)
260
+		codebool, _ := service.FindSupplierCode(supplierCode, supplierid, orgId)
260 261
 		if codebool {
261 262
 			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
262 263
 			return
@@ -279,7 +280,6 @@ func (this *SupplyOrderApiController) UpdateSupply() {
279 280
 	bank := dataBody["bank"].(string) //纳税人识别号
280 281
 	//bankAccount := this.GetString("bankAccount")     //银行账号
281 282
 	bankAccount := dataBody["bankaccount"].(string)
282
-	orgId := this.GetAdminUserInfo().CurrentOrgId
283 283
 	//contacts := this.Get("contacts")//联系人
284 284
 	//dataBody := make(map[string]interface{}, 0)
285 285
 	//err = json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
@@ -317,6 +317,7 @@ func (this *SupplyOrderApiController) UpdateSupply() {
317 317
 
318 318
 //获取单条供应商和涉及到的联系人记录
319 319
 func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
320
+	orgId := this.GetAdminUserInfo().CurrentOrgId
320 321
 	id, _ := this.GetInt64("id")
321 322
 	check := map[string][]string{
322 323
 		"id": {"must", "string", "id"},
@@ -329,9 +330,8 @@ func (this *SupplyOrderApiController) GetSupplyAndContactOne() {
329 330
 	//	this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商id不能为空")
330 331
 	//	return
331 332
 	//}
332
-	supply, contact, err := service.GetSupplyAndContactOne(id)
333
+	supply, contact, err := service.GetSupplyAndContactOne(id, orgId)
333 334
 	//获取供应商类别
334
-	orgId := this.GetAdminUserInfo().CurrentOrgId
335 335
 	costClassify := "供应商类别"
336 336
 	drugTypeParent, _ := service.GetDrugDataConfig(0, costClassify)
337 337
 	drugTypeList, _ := service.GetParentDataConfig(drugTypeParent.ID, orgId)
@@ -478,6 +478,7 @@ func (this *SupplyOrderApiController) GetSupplyCode() {
478 478
 
479 479
 //保存供应商
480 480
 func (this *SupplyOrderApiController) SaveSupply() {
481
+	orgId := this.GetAdminUserInfo().CurrentOrgId
481 482
 	//supplierName := this.GetString("suppliername") //供应商名称
482 483
 	dataBody := make(map[string]interface{}, 0)
483 484
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
@@ -492,7 +493,7 @@ func (this *SupplyOrderApiController) SaveSupply() {
492 493
 		return
493 494
 	}
494 495
 	//判断供应商名称是否有重复的
495
-	sbool, _ := service.FindSupplierName(supplierName)
496
+	sbool, _ := service.FindSupplierName(supplierName, orgId)
496 497
 	if sbool { //有重复的
497 498
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商名称重复")
498 499
 		return
@@ -504,7 +505,7 @@ func (this *SupplyOrderApiController) SaveSupply() {
504 505
 		return
505 506
 	}
506 507
 	//判断供应商编号是否有重复的
507
-	codebool, _ := service.FindSupplierCodes(supplierCode)
508
+	codebool, _ := service.FindSupplierCodes(supplierCode, orgId)
508 509
 	if codebool {
509 510
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "供应商编号重复")
510 511
 		return
@@ -530,7 +531,7 @@ func (this *SupplyOrderApiController) SaveSupply() {
530 531
 	bank := dataBody["bank"].(string)
531 532
 	//bankAccount := this.GetString("bankAccount")
532 533
 	bankAccount := dataBody["bankaccount"].(string)
533
-	orgId := this.GetAdminUserInfo().CurrentOrgId
534
+
534 535
 	//contacts := this.Get("contacts")//联系人
535 536
 	//err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
536 537
 	//if err != nil {

+ 14 - 14
service/supply_service.go 파일 보기

@@ -8,8 +8,8 @@ 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
 
@@ -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
 			}
@@ -253,7 +253,7 @@ func GetSuppliyCode(orgId int64) (spcode []*models.SpSupplierName, err error) {
253 253
 }
254 254
 
255 255
 //查询供应商的名字是否有重复
256
-func FindSupplierName(supplierName string) (sbool bool, err error) {
256
+func FindSupplierName(supplierName string, orgId int64) (sbool bool, err error) {
257 257
 	var total int
258 258
 	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
259 259
 	if total != 0 {
@@ -265,9 +265,9 @@ func FindSupplierName(supplierName string) (sbool bool, err error) {
265 265
 }
266 266
 
267 267
 //查询供应商的编号是否有重复(用于修改)
268
-func FindSupplierCode(supplierCode string, supplierid int64) (codebool bool, err error) {
268
+func FindSupplierCode(supplierCode string, supplierid, orgid int64) (codebool bool, err error) {
269 269
 	var total int
270
-	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and id != ? and status = 1", supplierCode, supplierid).Count(&total).Error
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 271
 	if total > 0 {
272 272
 		codebool = true
273 273
 	} else {
@@ -277,9 +277,9 @@ func FindSupplierCode(supplierCode string, supplierid int64) (codebool bool, err
277 277
 }
278 278
 
279 279
 //查询供应商的编号是否有重复(用于新增)
280
-func FindSupplierCodes(supplierCode string) (codebool bool, err error) {
280
+func FindSupplierCodes(supplierCode string, orgid int64) (codebool bool, err error) {
281 281
 	var total int
282
-	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and status = 1", supplierCode).Count(&total).Error
282
+	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_code = ? and status = 1 and user_org_id = ?", supplierCode, orgid).Count(&total).Error
283 283
 	if total > 0 {
284 284
 		codebool = true
285 285
 	} else {
@@ -295,8 +295,8 @@ func SaveSupply(supply models.SpSupplierName, tx *gorm.DB) error {
295 295
 }
296 296
 
297 297
 //获取联系人的id
298
-func SaveContactsId(tx *gorm.DB) (spconid []*models.SpSupplierContacts, err error) {
299
-	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
300 300
 	return
301 301
 }
302 302