Browse Source

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

mainqaq 3 years ago
parent
commit
cdd4980ba2
2 changed files with 27 additions and 26 deletions
  1. 13 12
      controllers/supply_order_api_contorller.go
  2. 14 14
      service/supply_service.go

+ 13 - 12
controllers/supply_order_api_contorller.go View File

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

+ 14 - 14
service/supply_service.go View File

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
 	return fistname, err
13
 	return fistname, err
14
 }
14
 }
15
 
15
 
99
 		if isfirst == 1 {
99
 		if isfirst == 1 {
100
 			if id == 0 {
100
 			if id == 0 {
101
 				var spconid []*models.SpSupplierContacts
101
 				var spconid []*models.SpSupplierContacts
102
-				spconid, err = SaveContactsId(tx)
102
+				spconid, err = SaveContactsId(tx, orgId)
103
 				if err != nil {
103
 				if err != nil {
104
 					return err
104
 					return err
105
 				}
105
 				}
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
 	code := supply.SupplierCode
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
 	return supply, contact, err
165
 	return supply, contact, err
166
 }
166
 }
167
 
167
 
212
 		err = SaveContacts(spcontacts, tx)
212
 		err = SaveContacts(spcontacts, tx)
213
 		if isfirst == 1 {
213
 		if isfirst == 1 {
214
 			var spconid []*models.SpSupplierContacts
214
 			var spconid []*models.SpSupplierContacts
215
-			spconid, err = SaveContactsId(tx)
215
+			spconid, err = SaveContactsId(tx, orgId)
216
 			if err != nil {
216
 			if err != nil {
217
 				return err
217
 				return err
218
 			}
218
 			}
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
 	var total int
257
 	var total int
258
 	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
258
 	err = XTReadDB().Model(&models.SpSupplierName{}).Where("supplier_name = ? and status = 1", supplierName).Count(&total).Error
259
 	if total != 0 {
259
 	if total != 0 {
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
 	var total int
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
 	if total > 0 {
271
 	if total > 0 {
272
 		codebool = true
272
 		codebool = true
273
 	} else {
273
 	} else {
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
 	var total int
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
 	if total > 0 {
283
 	if total > 0 {
284
 		codebool = true
284
 		codebool = true
285
 	} else {
285
 	} else {
295
 }
295
 }
296
 
296
 
297
 //获取联系人的id
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
 	return
300
 	return
301
 }
301
 }
302
 
302