소스 검색

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

XMLWAN 3 년 전
부모
커밋
53597dc034
2개의 변경된 파일47개의 추가작업 그리고 34개의 파일을 삭제
  1. 17 15
      controllers/supply_order_api_contorller.go
  2. 30 19
      service/supply_service.go

+ 17 - 15
controllers/supply_order_api_contorller.go 파일 보기

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

+ 30 - 19
service/supply_service.go 파일 보기

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
 
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
 	offset := (page - 1) * limit
20
 	offset := (page - 1) * limit
21
 
21
 
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
 			}
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
 	return spcode, err
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
 	var total int
257
 	var total int
259
 	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
260
 	if total != 0 {
259
 	if total != 0 {
265
 	return sbool, err
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
 	var total int
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
 		codebool = true
284
 		codebool = true
274
 	} else {
285
 	} else {
275
 		codebool = false
286
 		codebool = false
284
 }
295
 }
285
 
296
 
286
 //获取联系人的id
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
 	return
300
 	return
290
 }
301
 }
291
 
302