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

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

XMLWAN 2 лет назад
Родитель
Сommit
be5b60dc39

+ 10 - 10
controllers/data_api_controller.go Просмотреть файл

@@ -512,11 +512,11 @@ func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int)
512 512
 			return
513 513
 		}
514 514
 		parent_id := int64(configBody["parent_id"].(float64))
515
-		if parent_id <= 0 {
516
-			utils.ErrorLog("parent_id <= 0")
517
-			code = enums.ErrorCodeParamWrong
518
-			return
519
-		}
515
+		//if parent_id <= 0 {
516
+		//	utils.ErrorLog("parent_id <= 0")
517
+		//	code = enums.ErrorCodeParamWrong
518
+		//	return
519
+		//}
520 520
 		dataconfig.ParentId = parent_id
521 521
 
522 522
 		if configBody["name"] == nil || reflect.TypeOf(configBody["name"]).String() != "string" {
@@ -525,11 +525,11 @@ func configChildFormData(dataconfig *models.Dataconfig, data []byte) (code int)
525 525
 			return
526 526
 		}
527 527
 		name, _ := configBody["name"].(string)
528
-		if len(name) == 0 {
529
-			utils.ErrorLog("len(name) == 0")
530
-			code = enums.ErrorCodeParamWrong
531
-			return
532
-		}
528
+		//if len(name) == 0 {
529
+		//	utils.ErrorLog("len(name) == 0")
530
+		//	code = enums.ErrorCodeParamWrong
531
+		//	return
532
+		//}
533 533
 		dataconfig.Name = name
534 534
 	}
535 535
 	return

+ 2 - 2
controllers/device_api_controller.go Просмотреть файл

@@ -53,7 +53,7 @@ type DeviceAPIController struct {
53 53
 // /api/device/initdata [get] GetDeviceManageInitData
54 54
 func (this *DeviceAPIController) GetDeviceManageInitData() {
55 55
 	adminInfo := this.GetAdminUserInfo()
56
-	zones, getZonesErr := service.GetAllValidDeviceZones(adminInfo.CurrentOrgId)
56
+	zones, getZonesErr := service.GetAllValidDeviceZonesOne(adminInfo.CurrentOrgId)
57 57
 	if getZonesErr != nil {
58 58
 		this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
59 59
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -503,7 +503,7 @@ func (this *DeviceAPIController) DisableDevice() {
503 503
 // /api/device/zones [get] GetZones
504 504
 func (this *DeviceAPIController) GetZones() {
505 505
 	adminInfo := this.GetAdminUserInfo()
506
-	zones, getZonesErr := service.GetAllValidDeviceZones(adminInfo.CurrentOrgId)
506
+	zones, getZonesErr := service.GetAllValidDeviceZonesOne(adminInfo.CurrentOrgId)
507 507
 	if getZonesErr != nil {
508 508
 		this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
509 509
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)

+ 80 - 0
controllers/his_summary_controller.go Просмотреть файл

@@ -3,6 +3,7 @@ package controllers
3 3
 import (
4 4
 	"XT_New/enums"
5 5
 	"XT_New/service"
6
+	"fmt"
6 7
 	"github.com/astaxie/beego"
7 8
 	"time"
8 9
 )
@@ -16,6 +17,9 @@ func HisSummaryApiRegistRouters() {
16 17
 	beego.Router("/api/gethissummarydetaillist", &HisSummaryApiController{}, "Get:GetHisSummaryDetailList")
17 18
 	beego.Router("/api/his/getgatherdetailist", &HisSummaryApiController{}, "Get:GetGatherDetaiList")
18 19
 	beego.Router("/api/his/getdetailpatients", &HisSummaryApiController{}, "Get:GetDetailPatients")
20
+
21
+	beego.Router("/api/his/gethisorderlist", &HisSummaryApiController{}, "Get:GetHisOrderList")
22
+	beego.Router("/api/his/gethisadviceorderlist", &HisSummaryApiController{}, "Get:GetHisAdviceOrderList")
19 23
 }
20 24
 
21 25
 func (this *HisSummaryApiController) GetHisSummaryDetailList() {
@@ -633,3 +637,79 @@ func (this *HisSummaryApiController) GetDetailPatients() {
633 637
 
634 638
 	}
635 639
 }
640
+
641
+func (this *HisSummaryApiController) GetHisOrderList() {
642
+
643
+	patient_id, _ := this.GetInt64("patient_id")
644
+	start_time := this.GetString("start_time")
645
+	end_time := this.GetString("end_time")
646
+	timeLayout := "2006-01-02"
647
+	loc, _ := time.LoadLocation("Local")
648
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
649
+	if err != nil {
650
+
651
+	}
652
+	startRecordDateTime := startTime.Unix()
653
+
654
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
655
+	if err != nil {
656
+
657
+	}
658
+	endRecordDateTime := endTime.Unix()
659
+	orgId := this.GetAdminUserInfo().CurrentOrgId
660
+	groupList, _ := service.GetOrderInfoList(patient_id, startRecordDateTime, endRecordDateTime, orgId)
661
+	fmt.Println("groupList32332323232232332322323", groupList)
662
+	//list, err := service.GetHisOrderListTwenty(patient_id, startRecordDateTime, endRecordDateTime, orgId)
663
+	if err == nil {
664
+		this.ServeSuccessJSON(map[string]interface{}{
665
+			"groupList": groupList,
666
+			//   "list": list,
667
+
668
+		})
669
+		return
670
+	} else {
671
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
672
+		return
673
+
674
+	}
675
+}
676
+
677
+func (this *HisSummaryApiController) GetHisAdviceOrderList() {
678
+
679
+	patient_id, _ := this.GetInt64("patient_id")
680
+	start_time := this.GetString("start_time")
681
+	end_time := this.GetString("end_time")
682
+	timeLayout := "2006-01-02"
683
+	loc, _ := time.LoadLocation("Local")
684
+	startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
685
+	if err != nil {
686
+
687
+	}
688
+	startRecordDateTime := startTime.Unix()
689
+
690
+	endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
691
+	if err != nil {
692
+
693
+	}
694
+	endRecordDateTime := endTime.Unix()
695
+	orgId := this.GetAdminUserInfo().CurrentOrgId
696
+
697
+	list, err := service.GetOrderInfoList(patient_id, startRecordDateTime, endRecordDateTime, orgId)
698
+
699
+	//drugList, err := service.GetAllDrugLibList(orgId)
700
+	//
701
+	//goodList, err := service.GetAllGoodList(orgId)
702
+
703
+	if err == nil {
704
+		this.ServeSuccessJSON(map[string]interface{}{
705
+			"list": list,
706
+			//"drugList":drugList,
707
+			//"goodList":goodList,
708
+		})
709
+		return
710
+	} else {
711
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
712
+		return
713
+
714
+	}
715
+}

+ 6 - 0
controllers/mobile_api_controllers/check_weight_api_controller.go Просмотреть файл

@@ -115,6 +115,11 @@ func (c *CheckWeightApiController) SaveBloodPressure() {
115 115
 				evaluation.BloodAccessPartId = lastPredialysisEvaluation.BloodAccessPartId
116 116
 				evaluation.BloodAccessPartOperaId = lastPredialysisEvaluation.BloodAccessPartOperaId
117 117
 				evaluation.AdditionalWeight = lastPredialysisEvaluation.AdditionalWeight // 衣物重
118
+
119
+				//从化益达 备注默认上一次数据
120
+				if adminUserInfo.Org.Id == 10318 {
121
+					evaluation.Remark = lastPredialysisEvaluation.Remark
122
+				}
118 123
 			}
119 124
 		} else {
120 125
 			evaluation.UpdatedTime = time.Now().Unix()
@@ -264,6 +269,7 @@ func (c *CheckWeightApiController) SavePatientInfoDialysis() {
264 269
 
265 270
 	template, _ := service.GetOrgInfoTemplate(adminUserInfo.Org.Id)
266 271
 
272
+	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 53 {
267 273
 	if template.TemplateId == 22 || template.TemplateId == 17 || template.TemplateId == 21 || template.TemplateId == 26 || template.TemplateId == 27 || template.TemplateId == 34 || template.TemplateId == 30 || template.TemplateId == 32 || template.TemplateId == 36 || template.TemplateId == 40 || template.TemplateId == 38 || template.TemplateId == 43 || template.TemplateId == 46 || template.TemplateId == 48 || adminUserInfo.Org.Id == 10345 {
268 274
 		dewater_amount = dewater_amount * 1000
269 275
 	}

+ 1 - 1
controllers/mobile_api_controllers/dialysis_api_controller.go Просмотреть файл

@@ -391,7 +391,7 @@ func (this *DialysisAPIController) DialysisRecord() {
391 391
 	schedual, _ := service.MobileGetSchedualDetailOne(adminInfo.Org.Id, patientID, date.Unix())
392 392
 	go func() {
393 393
 		patient, _ = service.FindPatientByIdWithDiseases(adminInfo.Org.Id, patientID)
394
-		fmt.Println("patient23333223322323", patient.TrobleShoot)
394
+
395 395
 		ch <- struct{}{}
396 396
 	}()
397 397
 

+ 1 - 1
controllers/mobile_api_controllers/patient_api_controller.go Просмотреть файл

@@ -1137,7 +1137,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1137 1137
 					}
1138 1138
 					if prescribing_number_total <= total {
1139 1139
 						if medical.IsUse == 2 {
1140
-							config, _ := service.GetDrugOpenConfig(adminInfo.Org.Id)
1140
+							config, _ := service.GetDrugOpenConfigOne(adminInfo.Org.Id)
1141 1141
 							if config.IsOpen != 1 {
1142 1142
 								service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1143 1143
 								//更新字典里面的库存

+ 522 - 0
controllers/stock_in_api_controller.go Просмотреть файл

@@ -288,6 +288,8 @@ func (c *StockManagerApiController) CreateWarehouse() {
288 288
 
289 289
 				license_number, _ := items["license_number"].(string)
290 290
 
291
+
292
+				register_number, _ := items["register_number"].(string)
291 293
 				//入库单表格
292 294
 				warehouseInfo := &models.WarehousingInfo{
293 295
 					ID:               id,
@@ -313,9 +315,34 @@ func (c *StockManagerApiController) CreateWarehouse() {
313 315
 					PackingPrice:     packing_price,
314 316
 					StorehouseId:     storehouse_id,
315 317
 					IsCheck:          2,
318
+					RegisterNumber:   register_number,
316 319
 				}
317 320
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
318 321
 
322
+				flow := &models.VmStockFlow{
323
+					WarehousingOrder:    warehousing.WarehousingOrder,
324
+					WarehousingId:       warehousing.ID,
325
+					GoodId:              good_id,
326
+					Number:              number,
327
+					ProductDate:         productDates,
328
+					ExpireDate:          expiryDates,
329
+					Count:               warehousing_count,
330
+					Price:               price,
331
+					Status:              1,
332
+					Ctime:               ctime,
333
+					UserOrgId:           adminUserInfo.CurrentOrgId,
334
+					Manufacturer:        manufacturer,
335
+					Dealer:              dealer,
336
+					LicenseNumber:       license_number,
337
+					IsEdit:              1,
338
+					Creator:             adminUserInfo.AdminUser.Id,
339
+					SystemTime:          operation_time,
340
+					ConsumableType:      1,
341
+					WarehousingDetailId: warehouseInfo.ID,
342
+					StorehouseId:        storehouse_id,
343
+					RegisterNumber:      register_number,
344
+				}
345
+				stockFlow = append(stockFlow, flow)
319 346
 			}
320 347
 		}
321 348
 	}
@@ -323,6 +350,30 @@ func (c *StockManagerApiController) CreateWarehouse() {
323 350
 	for _, item := range warehousingInfo {
324 351
 		if item.ID == 0 {
325 352
 			service.CreatedWarehouseingDetail(item)
353
+		service.CreatedWarehouseingDetail(item)
354
+		warehousinginfo, _ := service.GetLastWarehousingInfo(item.GoodId)
355
+		flow := models.VmStockFlow{
356
+			WarehousingOrder:    item.WarehousingOrder,
357
+			WarehousingId:       item.WarehousingId,
358
+			GoodId:              item.GoodId,
359
+			Number:              item.Number,
360
+			ProductDate:         item.ProductDate,
361
+			ExpireDate:          item.ExpiryDate,
362
+			Count:               item.StockCount,
363
+			Price:               item.Price,
364
+			Status:              1,
365
+			Ctime:               ctime,
366
+			UserOrgId:           item.OrgId,
367
+			Manufacturer:        item.Manufacturer,
368
+			Dealer:              item.Dealer,
369
+			LicenseNumber:       item.LicenseNumber,
370
+			IsEdit:              1,
371
+			Creator:             adminUserInfo.AdminUser.Id,
372
+			SystemTime:          operation_time,
373
+			ConsumableType:      1,
374
+			WarehousingDetailId: warehousinginfo.ID,
375
+			StorehouseId:        storehouse_id,
376
+			RegisterNumber:      item.RegisterNumber,
326 377
 		}
327 378
 		if item.ID > 0 {
328 379
 			service.UpdateWarehouseDetail(item, item.ID)
@@ -564,6 +615,7 @@ func (c *StockManagerApiController) EditWarehouse() {
564 615
 				manufacturer := int64(items["manufacturer"].(float64))
565 616
 				dealer := int64(items["dealer"].(float64))
566 617
 				license_number, _ := items["license_number"].(string)
618
+				register_number, _ := items["register_number"].(string)
567 619
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
568 620
 					utils.ErrorLog("id")
569 621
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -595,6 +647,7 @@ func (c *StockManagerApiController) EditWarehouse() {
595 647
 						PackingPrice:     packing_price,
596 648
 						StorehouseId:     storehouse_id,
597 649
 						IsCheck:          2,
650
+						RegisterNumber:   register_number,
598 651
 					}
599 652
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
600 653
 
@@ -622,6 +675,7 @@ func (c *StockManagerApiController) EditWarehouse() {
622 675
 						LicenseNumber:    license_number,
623 676
 						PackingPrice:     packing_price,
624 677
 						StorehouseId:     storehouse_id,
678
+						RegisterNumber:   register_number,
625 679
 					}
626 680
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
627 681
 
@@ -646,6 +700,7 @@ func (c *StockManagerApiController) EditWarehouse() {
646 700
 						ConsumableType:      1,
647 701
 						WarehousingDetailId: warehouseInfo.ID,
648 702
 						StorehouseId:        storehouse_id,
703
+						RegisterNumber:      register_number,
649 704
 					}
650 705
 
651 706
 					stockFlow = append(stockFlow, flow)
@@ -656,11 +711,202 @@ func (c *StockManagerApiController) EditWarehouse() {
656 711
 	var errs error
657 712
 	if len(warehousingInfo) > 0 {
658 713
 		errs = service.CreateWarehousingInfo(warehousingInfo)
714
+
715
+		for _, its := range warehousingInfo {
716
+			//查询
717
+			info, _ := service.GetLastGoodWarehouseInfo(its.GoodId)
718
+			flows := models.VmStockFlow{
719
+				WarehousingOrder:    info.WarehousingOrder,
720
+				WarehousingId:       info.ID,
721
+				GoodId:              info.GoodId,
722
+				Number:              info.Number,
723
+				ProductDate:         info.ProductDate,
724
+				ExpireDate:          info.ExpiryDate,
725
+				Count:               info.WarehousingCount,
726
+				Price:               info.Price,
727
+				Status:              1,
728
+				Ctime:               ctime,
729
+				UserOrgId:           adminUserInfo.CurrentOrgId,
730
+				Manufacturer:        info.Manufacturer,
731
+				Dealer:              info.Dealer,
732
+				LicenseNumber:       info.LicenseNumber,
733
+				IsEdit:              1,
734
+				Creator:             adminUserInfo.AdminUser.Id,
735
+				SystemTime:          ctime,
736
+				ConsumableType:      1,
737
+				WarehousingDetailId: info.ID,
738
+				StorehouseId:        storehouse_id,
739
+				RegisterNumber:      info.RegisterNumber,
740
+			}
741
+			_, errcodescode := service.GetGoodStockFlowInfo(info.ID, info.GoodId)
742
+
743
+			if errcodescode == gorm.ErrRecordNotFound {
744
+				service.CreateStockFlowOne(flows)
745
+			}
746
+
747
+			//改变库存
748
+			good, _ := service.GetLastInfoMationById(info.GoodId)
749
+			warhouseCount := strconv.FormatInt(info.WarehousingCount, 10)
750
+			total, _ := strconv.ParseFloat(warhouseCount, 64)
751
+			goodInfo := models.GoodInfo{
752
+				Total: good.Total + total,
753
+			}
754
+			errcodescode = service.UpdateGoodInfoMation(info.GoodId, goodInfo)
755
+			fmt.Println(errcodescode)
756
+
757
+			//查询该机构默认仓库
758
+			storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
759
+			//查询剩余库存
760
+			goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, info.GoodId, adminUserInfo.CurrentOrgId)
761
+			var sum_count int64
762
+			var sum_in_count int64
763
+			for _, item := range goodList {
764
+				sum_count += item.StockCount
765
+				sum_in_count += item.WarehousingCount
766
+			}
767
+			service.UpdateGoodByGoodId(info.GoodId, sum_count, sum_in_count, info.OrgId)
768
+		}
659 769
 	}
660 770
 
661 771
 	if len(upDateWarehousingInfo) > 0 {
662 772
 		for _, item := range upDateWarehousingInfo {
663 773
 			service.UpdateWarehouseInfoByGoodIdOne(item, item.ID)
774
+			var total int64
775
+			//获取该批次该型号的库存
776
+			info, _ := service.GetLastWarehousingByIdOne(item.ID, item.GoodId)
777
+
778
+			//增加库存
779
+			if item.WarehousingCount > info.WarehousingCount {
780
+
781
+				total = item.WarehousingCount - info.WarehousingCount
782
+				goodinfo := models.WarehousingInfo{
783
+					WarehousingCount: item.WarehousingCount,
784
+					StockCount:       info.StockCount + total,
785
+					Price:            item.Price,
786
+					Manufacturer:     item.Manufacturer,
787
+					Number:           item.Number,
788
+					ProductDate:      item.ProductDate,
789
+					ExpiryDate:       item.ExpiryDate,
790
+					LicenseNumber:    item.LicenseNumber,
791
+					Dealer:           item.Dealer,
792
+					Remark:           item.Remark,
793
+					PackingPrice:     item.PackingPrice,
794
+					StorehouseId:     storehouse_id,
795
+					RegisterNumber:   item.RegisterNumber,
796
+				}
797
+
798
+				//改变库存
799
+				good, _ := service.GetLastInfoMationById(info.GoodId)
800
+				warhouseCount := strconv.FormatInt(total, 10)
801
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
802
+				goodInfo := models.GoodInfo{
803
+					Total: good.Total + all_total,
804
+				}
805
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
806
+				service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
807
+				//查询该机构默认仓库
808
+				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
809
+				//查询剩余库存
810
+				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
811
+				var sum_count int64
812
+				var sum_in_count int64
813
+				for _, item := range goodList {
814
+					sum_count += item.StockCount
815
+					sum_in_count += item.WarehousingCount
816
+				}
817
+				service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
818
+			}
819
+
820
+			if item.WarehousingCount < info.WarehousingCount {
821
+
822
+				total = info.WarehousingCount - item.WarehousingCount
823
+				goodinfo := models.WarehousingInfo{
824
+					WarehousingCount: item.WarehousingCount,
825
+					StockCount:       info.StockCount - total,
826
+					Price:            item.Price,
827
+					Manufacturer:     item.Manufacturer,
828
+					Number:           item.Number,
829
+					ProductDate:      item.ProductDate,
830
+					ExpiryDate:       item.ExpiryDate,
831
+					LicenseNumber:    item.LicenseNumber,
832
+					Dealer:           item.Dealer,
833
+					Remark:           item.Remark,
834
+					PackingPrice:     item.PackingPrice,
835
+					StorehouseId:     storehouse_id,
836
+					RegisterNumber:   item.RegisterNumber,
837
+				}
838
+
839
+				//改变库存
840
+				good, _ := service.GetLastInfoMationById(info.GoodId)
841
+				warhouseCount := strconv.FormatInt(total, 10)
842
+				all_total, _ := strconv.ParseFloat(warhouseCount, 64)
843
+				goodInfo := models.GoodInfo{
844
+					Total: good.Total - all_total,
845
+				}
846
+				service.UpdateGoodInfoMation(info.GoodId, goodInfo)
847
+				service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
848
+				//查询该机构默认仓库
849
+				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
850
+				//查询剩余库存
851
+				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
852
+				var sum_count int64
853
+				var sum_in_count int64
854
+				for _, item := range goodList {
855
+					sum_count += item.StockCount
856
+					sum_in_count += item.WarehousingCount
857
+				}
858
+				service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
859
+			}
860
+
861
+			if item.WarehousingCount == info.WarehousingCount {
862
+				goodinfo := models.WarehousingInfo{
863
+					WarehousingCount: item.WarehousingCount,
864
+					StockCount:       info.StockCount,
865
+					Price:            item.Price,
866
+					Manufacturer:     item.Manufacturer,
867
+					Number:           item.Number,
868
+					ProductDate:      item.ProductDate,
869
+					ExpiryDate:       item.ExpiryDate,
870
+					LicenseNumber:    item.LicenseNumber,
871
+					Dealer:           item.Dealer,
872
+					Remark:           item.Remark,
873
+					PackingPrice:     item.PackingPrice,
874
+					StorehouseId:     storehouse_id,
875
+					RegisterNumber:   item.RegisterNumber,
876
+				}
877
+				service.UpdateWarehouseInfoByGoodIdOne(goodinfo, item.ID)
878
+				//查询该机构默认仓库
879
+				storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
880
+				//查询剩余库存
881
+				goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
882
+				var sum_count int64
883
+				var sum_in_count int64
884
+				for _, item := range goodList {
885
+					sum_count += item.StockCount
886
+					sum_in_count += item.WarehousingCount
887
+				}
888
+				service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
889
+			}
890
+
891
+		}
892
+	}
893
+
894
+	if len(stockFlow) > 0 {
895
+		for _, item := range stockFlow {
896
+			flow := models.VmStockFlow{
897
+				Count:          item.Count,
898
+				Number:         item.Number,
899
+				ProductDate:    item.ProductDate,
900
+				ExpireDate:     item.ExpireDate,
901
+				Price:          item.Price,
902
+				Manufacturer:   item.Manufacturer,
903
+				Dealer:         item.Dealer,
904
+				LicenseNumber:  item.LicenseNumber,
905
+				StorehouseId:   storehouse_id,
906
+				RegisterNumber: item.RegisterNumber,
907
+			}
908
+			parseDateErr := service.UpdatedStockFlowByGoodIdOne(item.WarehousingId, item.GoodId, flow)
909
+			fmt.Println(parseDateErr)
664 910
 		}
665 911
 	}
666 912
 
@@ -1220,6 +1466,8 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1220 1466
 				}
1221 1467
 				license_number := items["license_number"].(string)
1222 1468
 
1469
+
1470
+				register_number := items["register_number"].(string)
1223 1471
 				warehouseOutInfo := &models.WarehouseOutInfo{
1224 1472
 					ID:                      id,
1225 1473
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1246,6 +1494,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1246 1494
 					BuyPrice:                buy_price,
1247 1495
 					StockCount:              stock_count,
1248 1496
 					IsCheck:                 2,
1497
+					RegisterNumber:          register_number,
1249 1498
 				}
1250 1499
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1251 1500
 
@@ -1576,6 +1825,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1576 1825
 
1577 1826
 				license_number := items["license_number"].(string)
1578 1827
 
1828
+				register_number := items["register_number"].(string)
1829
+
1579 1830
 				timeLayout := "2006-01-02"
1580 1831
 				loc, _ := time.LoadLocation("Local")
1581 1832
 				expiry_date := items["expiry_date"].(string)
@@ -1688,6 +1939,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1688 1939
 						StorehouseId:            storehouse_id,
1689 1940
 						AdminUserId:             admin_user_id,
1690 1941
 						StockCount:              stock_count,
1942
+						RegisterNumber:          register_number,
1691 1943
 					}
1692 1944
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1693 1945
 				}
@@ -1980,6 +2232,276 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1980 2232
 			//}
1981 2233
 			//service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
1982 2234
 
2235
+			//1.查询该耗材该批次的最后一次出库记录
2236
+			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, item.OrgId)
2237
+
2238
+			//如果出库数量大于 最后一次批次的数量(那么要进行出库)
2239
+
2240
+			if item.Count > lastGood.Count {
2241
+
2242
+				//查询该耗材是否还有库存
2243
+				warehouseinfo, _ := service.GetTotalCountByGoodId(item.GoodId, item.StorehouseId)
2244
+
2245
+				//无库存
2246
+				if warehouseinfo.StockCount <= 0 {
2247
+					c.ServeSuccessJSON(map[string]interface{}{
2248
+						"msg": "5",
2249
+					})
2250
+					return
2251
+				}
2252
+
2253
+				//有库存,进行出库,调用出库接口
2254
+				if warehouseinfo.StockCount > 0 {
2255
+					var total int64
2256
+					var stock_cout int64
2257
+					var total_count int64
2258
+					//计算和最后一次出库数据的差
2259
+					total = item.Count - lastGood.Count
2260
+
2261
+					if total > warehouseinfo.StockCount {
2262
+						c.ServeSuccessJSON(map[string]interface{}{
2263
+							"msg": "6",
2264
+						})
2265
+						return
2266
+					}
2267
+					//获取该耗材该批次的剩余库存量
2268
+					info, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
2269
+
2270
+					//判断该批次的剩余库存 和出库的库存进行比较
2271
+					//如果出库的库存大于该批次的剩余库存,那么需要出库下一批次的库存
2272
+
2273
+					if total > info.StockCount {
2274
+						//计算出库和该批次相差的库存
2275
+						total_count = item.Count - info.StockCount
2276
+						//清空本批次次库存
2277
+						service.DeleteWarehouseInfo(item.WarehouseInfotId)
2278
+						//调用出库逻辑
2279
+						parseDateErr := service.ConsumablesDeliveryTwo(item.OrgId, item, total_count)
2280
+						if parseDateErr != nil {
2281
+							utils.ErrorLog(errs.Error())
2282
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2283
+							return
2284
+						}
2285
+					}
2286
+					//如果与上次比的库存小于或等于于该批次的剩余库存,那么需要该批次出库
2287
+					if total <= info.StockCount {
2288
+						stock_cout = lastGood.Count + total
2289
+						fmt.Println(stock_cout)
2290
+						//扣减库存
2291
+						warehouse := models.WarehousingInfo{
2292
+							StockCount: info.StockCount - total,
2293
+						}
2294
+						errs := service.UpdateWarehousingInfo(warehouse, info.ID)
2295
+
2296
+						warehouseOutInfo := &models.WarehouseOutInfo{
2297
+							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2298
+							WarehouseOutId:          id,
2299
+							WarehouseInfotId:        item.WarehouseInfotId,
2300
+							Status:                  1,
2301
+							Ctime:                   time.Now().Unix(),
2302
+							Remark:                  item.Remark,
2303
+							OrgId:                   item.OrgId,
2304
+							Type:                    1,
2305
+							Manufacturer:            item.Manufacturer,
2306
+							Dealer:                  item.Dealer,
2307
+							IsSys:                   0,
2308
+							SysRecordTime:           item.SysRecordTime,
2309
+							GoodTypeId:              item.GoodTypeId,
2310
+							GoodId:                  item.GoodId,
2311
+							ExpiryDate:              item.ExpiryDate,
2312
+							ProductDate:             item.ProductDate,
2313
+							Number:                  item.Number,
2314
+							Price:                   item.Price,
2315
+							LicenseNumber:           item.LicenseNumber,
2316
+							Count:                   item.Count,
2317
+							ConsumableType:          2,
2318
+							StorehouseId:            item.StorehouseId,
2319
+							AdminUserId:             item.AdminUserId,
2320
+							StockCount:              item.StockCount,
2321
+							RegisterNumber:          item.RegisterNumber,
2322
+						}
2323
+
2324
+						//查询是否存在
2325
+						_, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
2326
+						if errcode == gorm.ErrRecordNotFound {
2327
+
2328
+							errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
2329
+							if errOne != nil {
2330
+								utils.ErrorLog(errs.Error())
2331
+								c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2332
+								return
2333
+							}
2334
+						} else if errcode == nil {
2335
+							service.UpDateWarehouseOutInfo(item)
2336
+							//更新流水
2337
+							flow := models.VmStockFlow{
2338
+								Number:         item.Number,
2339
+								LicenseNumber:  item.LicenseNumber,
2340
+								Count:          item.Count,
2341
+								Manufacturer:   item.Manufacturer,
2342
+								Dealer:         item.Dealer,
2343
+								ProductDate:    item.ProductDate,
2344
+								ExpireDate:     item.ExpiryDate,
2345
+								Price:          item.Price,
2346
+								StorehouseId:   item.StorehouseId,
2347
+								AdminUserId:    item.AdminUserId,
2348
+								StockCount:     item.StockCount,
2349
+								RegisterNumber: item.RegisterNumber,
2350
+							}
2351
+							service.UpdateStockFlowByDetailId(flow, item.ID)
2352
+
2353
+							goodInfo := models.GoodInfo{
2354
+								Manufacturer: item.Manufacturer,
2355
+								Dealer:       item.Dealer,
2356
+							}
2357
+							service.UpdatedGoodInfo(goodInfo, item.GoodId)
2358
+						}
2359
+					}
2360
+				}
2361
+			}
2362
+
2363
+			var last_count int64
2364
+			var all_total int64
2365
+			var stock_total int64
2366
+			//如果退库数量小于最后一次批次的数量(要么要进行退库)
2367
+			if item.Count < lastGood.Count {
2368
+
2369
+				//退库数量和最后一次出库数据进行计算
2370
+				last_count = lastGood.Count - item.Count
2371
+
2372
+				//获取该耗材该批次的剩余库存量
2373
+				infoInfo, _ := service.GetLastGoodCountById(item.GoodId, item.WarehouseInfotId)
2374
+
2375
+				//退库数量和最后一次出库数据进行计算的差 加上 剩余库存的数量与 该批次的入库数量进行比较
2376
+				all_total = last_count + infoInfo.StockCount
2377
+
2378
+				//如果库存大于总数量,则退回到这个批次
2379
+
2380
+				if infoInfo.WarehousingCount > all_total {
2381
+					stock_total = last_count + infoInfo.StockCount
2382
+
2383
+					//退回该批次,计算数量
2384
+					warehousingInfoOne := models.WarehousingInfo{
2385
+						StockCount:   stock_total,
2386
+						ID:           item.WarehouseInfotId,
2387
+						OrgId:        item.OrgId,
2388
+						StorehouseId: item.StorehouseId,
2389
+					}
2390
+
2391
+					parseDateErr := service.UpdateWarehousingInfo(warehousingInfoOne, item.WarehouseInfotId)
2392
+
2393
+					fmt.Println("parseDateErr", parseDateErr)
2394
+					//插入一条新纪录
2395
+					warehouseOutInfoThree := &models.WarehouseOutInfo{
2396
+						WarehouseOutOrderNumber: item.WarehouseOutOrderNumber,
2397
+						WarehouseOutId:          id,
2398
+						WarehouseInfotId:        item.WarehouseInfotId,
2399
+						Status:                  1,
2400
+						Ctime:                   time.Now().Unix(),
2401
+						Remark:                  item.Remark,
2402
+						OrgId:                   item.OrgId,
2403
+						Type:                    1,
2404
+						Manufacturer:            item.Manufacturer,
2405
+						Dealer:                  item.Dealer,
2406
+						IsSys:                   0,
2407
+						GoodTypeId:              item.GoodTypeId,
2408
+						GoodId:                  item.GoodId,
2409
+						ExpiryDate:              item.ExpiryDate,
2410
+						ProductDate:             item.ProductDate,
2411
+						Number:                  item.Number,
2412
+						Price:                   item.Price,
2413
+						LicenseNumber:           item.LicenseNumber,
2414
+						ConsumableType:          2,
2415
+						Count:                   item.Count,
2416
+						StorehouseId:            item.StorehouseId,
2417
+						AdminUserId:             item.AdminUserId,
2418
+						StockCount:              item.StockCount,
2419
+						RegisterNumber:          item.RegisterNumber,
2420
+					}
2421
+					//查询是否存在
2422
+					_, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
2423
+					if errcode == gorm.ErrRecordNotFound {
2424
+						errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfoThree)
2425
+						if errOne != nil {
2426
+							utils.ErrorLog(errs.Error())
2427
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2428
+							return
2429
+						}
2430
+
2431
+					} else if errcode == nil {
2432
+						service.UpDateWarehouseOutInfo(item)
2433
+						flow := models.VmStockFlow{
2434
+							Number:         item.Number,
2435
+							LicenseNumber:  item.LicenseNumber,
2436
+							Count:          item.Count,
2437
+							Manufacturer:   item.Manufacturer,
2438
+							Dealer:         item.Dealer,
2439
+							ProductDate:    item.ProductDate,
2440
+							ExpireDate:     item.ExpiryDate,
2441
+							Price:          item.Price,
2442
+							StorehouseId:   item.StorehouseId,
2443
+							AdminUserId:    item.AdminUserId,
2444
+							StockCount:     item.StockCount,
2445
+							RegisterNumber: item.RegisterNumber,
2446
+						}
2447
+						service.UpdateStockFlowByDetailId(flow, item.ID)
2448
+						goodInfo := models.GoodInfo{
2449
+							Manufacturer: item.Manufacturer,
2450
+							Dealer:       item.Dealer,
2451
+						}
2452
+						service.UpdatedGoodInfo(goodInfo, item.GoodId)
2453
+
2454
+					}
2455
+				}
2456
+
2457
+				//如果库存小于总数量,则报错提醒,该批次的退库数据大于入库数据了无法退库,则需要退库到另一个批次
2458
+				if infoInfo.WarehousingCount < all_total {
2459
+					c.ServeSuccessJSON(map[string]interface{}{
2460
+						"msg": "6",
2461
+					})
2462
+					return
2463
+				}
2464
+			}
2465
+
2466
+			if item.Count == lastGood.Count {
2467
+
2468
+				errs = service.UpDateWarehouseOutInfo(item)
2469
+				flow := models.VmStockFlow{
2470
+					Number:         item.Number,
2471
+					LicenseNumber:  item.LicenseNumber,
2472
+					Count:          item.Count,
2473
+					Manufacturer:   item.Manufacturer,
2474
+					Dealer:         item.Dealer,
2475
+					ProductDate:    item.ProductDate,
2476
+					ExpireDate:     item.ExpiryDate,
2477
+					Price:          item.Price,
2478
+					StorehouseId:   item.StorehouseId,
2479
+					AdminUserId:    item.AdminUserId,
2480
+					BuyPrice:       item.BuyPrice,
2481
+					StockCount:     item.StockCount,
2482
+					RegisterNumber: item.RegisterNumber,
2483
+				}
2484
+				service.UpdateStockFlowByDetailId(flow, item.ID)
2485
+				goodInfo := models.GoodInfo{
2486
+					Manufacturer: item.Manufacturer,
2487
+					Dealer:       item.Dealer,
2488
+				}
2489
+				service.UpdatedGoodInfo(goodInfo, item.GoodId)
2490
+
2491
+			}
2492
+
2493
+			//查询该机构默认仓库
2494
+			storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
2495
+			//查询剩余库存
2496
+			goodList, _ := service.GetGoodSumCountByStoreId(storeConfig.StorehouseOutInfo, item.GoodId, adminUserInfo.CurrentOrgId)
2497
+			var sum_count int64
2498
+			var sum_in_count int64
2499
+			for _, item := range goodList {
2500
+				sum_count += item.StockCount
2501
+				sum_in_count += item.WarehousingCount
2502
+			}
2503
+			service.UpdateGoodByGoodId(item.GoodId, sum_count, sum_in_count, item.OrgId)
2504
+
1983 2505
 		}
1984 2506
 	}
1985 2507
 

+ 21 - 0
models/drug_stock.go Просмотреть файл

@@ -541,6 +541,27 @@ type DrugWarehouseInfoTwenty struct {
541 541
 	SecondWarehouseInfoId     int64       `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
542 542
 	IsCheck                   int64       `gorm:"column:is_check" json:"is_check" form:"is_check"`
543 543
 	BaseDrugLib               BaseDrugLib `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId"json:"drug" `
544
+type DrugWarehouseOutTwenty struct {
545
+	ID                        int64                        `gorm:"column:id" json:"id" form:"id"`
546
+	WarehouseOutOrderNumber   string                       `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
547
+	OperationTime             int64                        `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
548
+	Creater                   int64                        `gorm:"column:creater" json:"creater" form:"creater"`
549
+	OrgId                     int64                        `gorm:"column:org_id" json:"org_id" form:"org_id"`
550
+	Modifier                  int64                        `gorm:"column:modifier" json:"modifier" form:"modifier"`
551
+	Remark                    string                       `gorm:"column:remark" json:"remark" form:"remark"`
552
+	Ctime                     int64                        `gorm:"column:ctime" json:"ctime" form:"ctime"`
553
+	Mtime                     int64                        `gorm:"column:mtime" json:"mtime" form:"mtime"`
554
+	Status                    int64                        `gorm:"column:status" json:"status" form:"status"`
555
+	WarehouseOutTime          int64                        `gorm:"column:warehouse_out_time" json:"warehouse_out_time" form:"warehouse_out_time"`
556
+	Dealer                    int64                        `gorm:"column:dealer" json:"dealer" form:"dealer"`
557
+	Manufacturer              int64                        `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
558
+	Type                      int64                        `gorm:"column:type" json:"type" form:"type"`
559
+	IsSys                     int64                        `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
560
+	SupplyCancelOutId         int64                        `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
561
+	SupplyWarehouseId         int64                        `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
562
+	StorehouseId              int64                        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
563
+	SecondWarehouseId         int64                        `gorm:"column:second_warehouse_id" json:"second_warehouse_id" form:"second_warehouse_id"`
564
+	DrugWarehouseOutInfoTenty []*DrugWarehouseOutInfoTenty `gorm:"ForeignKey:WarehouseOutId;AssociationForeignKey:ID"json:"xt_drug_warehouse_out_info" `
544 565
 }
545 566
 
546 567
 func (DrugWarehouseInfoTwenty) TableName() string {

+ 1 - 0
models/his_charge_models.go Просмотреть файл

@@ -100,6 +100,7 @@ type HisChargeOrder struct {
100 100
 	MafPay             float64               `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
101 101
 	FundPaySumamt      float64               `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
102 102
 	AcctPay            float64               `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
103
+	PsnCashPay         float64               `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
103 104
 	HisChargeOrderInfo []*HisChargeOrderInfo `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"order_info"`
104 105
 }
105 106
 

+ 1 - 1
models/patient_schedule_template_models.go Просмотреть файл

@@ -19,7 +19,7 @@ type PatientScheduleTemplateId struct {
19 19
 	OrgID      int64 `gorm:"column:org_id" json:"-" form:"org_id"`
20 20
 	Status     int8  `gorm:"column:status" json:"-" form:"status"`
21 21
 	CreateTime int64 `gorm:"column:ctime" json:"-" form:"ctime"`
22
-	ModifyTime int64 `gorm:"column:mtime" json:"-" form:"mtime"`
22
+	ModifyTime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
23 23
 }
24 24
 
25 25
 func (PatientScheduleTemplateId) TableName() string {

+ 1 - 0
models/self_drug_models.go Просмотреть файл

@@ -647,6 +647,7 @@ type StDrugWarehouseInfo struct {
647 647
 	LastPrice        string  `json:"last_price"`
648 648
 	PackingUnit      string  `json:"packing_unit"`
649 649
 	Dosage           int64   `json:"dosage"`
650
+	LimaxUnit        string  `json:"limax_unit"`
650 651
 }
651 652
 
652 653
 type VmDrugWarehouseOutInfo struct {

+ 2 - 0
models/stock_models.go Просмотреть файл

@@ -265,6 +265,7 @@ type WarehouseOutInfo struct {
265 265
 	StockCount              string       `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
266 266
 	IsCheck                 int64        `gorm:"column:is_check" json:"is_check" form:"is_check"`
267 267
 	RegisterNumber          string       `gorm:"column:register_number" json:"register_number" form:"register_number"`
268
+
268 269
 }
269 270
 
270 271
 func (WarehouseOutInfo) TableName() string {
@@ -517,6 +518,7 @@ type WarehouseOutInfoOne struct {
517 518
 	AdminUserId                 int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
518 519
 	BuyPrice                    float64 `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
519 520
 	StockCount                  string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
521
+	RegisterNumber              string  `gorm:"column:register_number" json:"register_number" form:"register_number"`
520 522
 }
521 523
 
522 524
 type WarehouseOutInfoTwo struct {

+ 9 - 0
service/device_service.go Просмотреть файл

@@ -261,6 +261,15 @@ func GetAllValidDeviceZones(orgID int64) ([]*models.DeviceZone, error) {
261 261
 	return zones, nil
262 262
 }
263 263
 
264
+func GetAllValidDeviceZonesOne(orgID int64) ([]*models.DeviceZone, error) {
265
+	var zones []*models.DeviceZone
266
+	err := readDb.Model(&models.DeviceZone{}).Where("org_id = ? and status = 1", orgID).Find(&zones).Error
267
+	if err != nil {
268
+		return nil, err
269
+	}
270
+	return zones, nil
271
+}
272
+
264 273
 func GetDeviceZoneByID(orgID int64, zoneID int64) (*models.DeviceZone, error) {
265 274
 	var zone models.DeviceZone
266 275
 	err := readDb.Model(&models.DeviceZone{}).Where("org_id = ? AND id = ?", orgID, zoneID).First(&zone).Error

+ 70 - 1
service/his_summary_service.go Просмотреть файл

@@ -9,7 +9,7 @@ import (
9 9
 func GetHisSummaryDetailList(keyword string, item_type int64, patient_id int64, org_id int64, start_time int64, end_time int64) (patients []*models.ChargePatient, err error) {
10 10
 
11 11
 	err = XTReadDB().Table("xt_patients as p").Select("p.id,p.user_org_id,p.name,p.lapseto,p.status").Joins("JOIN his_order AS orders ON orders.patient_id = p.id AND orders.status = 1  AND orders.ctime >= ? AND orders.ctime <= ? AND orders.user_org_id = ? AND orders.order_status = 2 and orders.patient_id = ?", start_time, end_time, org_id, patient_id).Preload("HisChargeOrder", func(db *gorm.DB) *gorm.DB {
12
-		return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id").
12
+		return db.Select("id,user_org_id,his_patient_id,settle_accounts_date,status,number,order_status,mdtrt_id,patient_id,psn_cash_pay,acct_pay,fund_pay_sumamt").
13 13
 			Preload("HisChargeOrderInfo", func(db *gorm.DB) *gorm.DB {
14 14
 				return db.Select("id,order_number,advice_id,det_item_fee_sumamt,cnt,pric,med_chrgitm_type,status,chld_medc_flag,chrgitm_lv,user_org_id,project_id,type").Where("status = 1").
15 15
 					Preload("HisChargeDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
@@ -352,3 +352,72 @@ func GetAllHisOrderList(org_id int64, patient_id int64, start_time int64, end_ti
352 352
 
353 353
 	return order, err
354 354
 }
355
+
356
+func GetHisOrderListByMedChrgitemType(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderInfoTwenty, err error) {
357
+
358
+	db := XTReadDB().Model(&models.HisOrderInfoTwenty{}).Where("status = 1")
359
+
360
+	if patient_id > 0 {
361
+		db = db.Where("patient_id = ?", patient_id)
362
+	}
363
+	if startime > 0 {
364
+		db = db.Where("settle_accounts_date >= ?", startime)
365
+	}
366
+	if endtime > 0 {
367
+		db = db.Where("settle_accounts_date<=?", endtime)
368
+	}
369
+	if orgid > 0 {
370
+		db = db.Where("user_org_id = ?", orgid)
371
+	}
372
+	err = db.Group("med_chrgitm_type").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status = 1").Find(&info).Error
373
+	return info, err
374
+}
375
+
376
+func GetOrderInfoList(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderInfoTwenty, err error) {
377
+	db := XTReadDB().Model(&models.HisOrderInfoTwenty{}).Where("status = 1")
378
+
379
+	if patient_id > 0 {
380
+		db = db.Where("patient_id = ?", patient_id)
381
+	}
382
+	if startime > 0 {
383
+		db = db.Where("upload_date >= ?", startime)
384
+	}
385
+	if endtime > 0 {
386
+		db = db.Where("upload_date<=?", endtime)
387
+	}
388
+	if orgid > 0 {
389
+		db = db.Where("user_org_id = ?", orgid)
390
+	}
391
+	err = db.Preload("HisOrderTenty", "status = 1").Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
392
+		return db.Where("status = 1 AND user_org_id = ?", orgid).Preload("HisProject").Preload("GoodInfo", "status=1")
393
+	}).Preload("HisDoctorAdvice", "status = 1").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status = 1").Find(&info).Error
394
+	return info, err
395
+}
396
+
397
+func GetHisOrderListTwenty(patient_id int64, startime int64, endtime int64, orgid int64) (info []*models.HisOrderTenty, err error) {
398
+
399
+	db := XTReadDB().Model(&models.HisOrderTenty{}).Where("status = 1")
400
+
401
+	if patient_id > 0 {
402
+		db = db.Where("patient_id = ?", patient_id)
403
+	}
404
+
405
+	if startime > 0 {
406
+		db = db.Where("settle_accounts_date>=?", startime)
407
+	}
408
+
409
+	if endtime > 0 {
410
+		db = db.Where("settle_accounts_date<=?", endtime)
411
+	}
412
+
413
+	if orgid > 0 {
414
+		db = db.Where("user_org_id = ?", orgid)
415
+	}
416
+
417
+	err = db.Preload("HisOrderInfoTwenty", "status=1").Preload("Patients", "status = 1").Preload("HisHospitalCheckRecordTwenty", "status=1").Order("settle_accounts_date asc").Find(&info).Error
418
+	return info, err
419
+}
420
+
421
+func GetHisAdviceOrderList() {
422
+
423
+}

+ 99 - 7
service/stock_service.go Просмотреть файл

@@ -730,6 +730,13 @@ func CreateDrugFlowOne(flow models.DrugFlow) error {
730 730
 }
731 731
 
732 732
 func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64, id int64, warhouse_out_id int64) (models.DrugAutomaticReduceDetail, error) {
733
+//func CreateDrugFlowOneTX(flow models.DrugFlow,tx *gorm.DB) error {
734
+//	err := tx.Create(&flow).Error
735
+//	return err
736
+//}
737
+
738
+func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64) (models.DrugAutomaticReduceDetail, error) {
739
+
733 740
 	detail := models.DrugAutomaticReduceDetail{}
734 741
 	err := XTWriteDB().Model(&detail).Where("patient_id = ? and record_time = ? and drug_id = ? and status= 1 and advice_id =? ", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
735 742
 	err = XTWriteDB().Model(&models.DrugWarehouseOutInfo{}).Where("patient_id =? and sys_record_time =? and drug_id = ? and status = 1 and advice_id =? and id = ?", patientid, recorddate, drugid, advice_id, id).Updates(map[string]interface{}{"status": 0}).Error
@@ -1161,7 +1168,7 @@ func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.S
1161 1168
 	if org_id > 0 {
1162 1169
 		db = db.Where("x.org_id = ?", org_id)
1163 1170
 	}
1164
-	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,x.manufacturer,x.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
1171
+	err = db.Select("x.id,x.max_unit as limax_unit,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,x.manufacturer,x.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
1165 1172
 	return list, err
1166 1173
 }
1167 1174
 
@@ -1303,9 +1310,13 @@ func FindAllCancelStockTotal(org_id int64) (total int64, err error) {
1303 1310
 func FindAllDrugCancelStockTotal(org_id int64) (total int64, err error) {
1304 1311
 	err = readDb.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
1305 1312
 	return total, err
1306
-
1307 1313
 }
1308 1314
 
1315
+//func FindAllDrugCancelStockTotalTX(org_id int64,tx *gorm.DB) (total int64, err error) {
1316
+//	err = tx.Model(&models.DrugCancelStock{}).Where("org_id = ?", org_id).Count(&total).Error
1317
+//	return total, err
1318
+//}
1319
+
1309 1320
 func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
1310 1321
 	db := readDb.Model(&models.SalesReturn{})
1311 1322
 	db = db.Where("xt_sales_return.org_id = ? AND xt_sales_return.status = 1 AND xt_sales_return.type = ?", orgId, types)
@@ -1827,6 +1838,12 @@ func GetLastDrugCancelStockById(orgid int64) (models.DrugCancelStock, error) {
1827 1838
 	return stock, err
1828 1839
 }
1829 1840
 
1841
+//func GetLastDrugCancelStockByIdTX(orgid int64,tx *gorm.DB) (models.DrugCancelStock, error) {
1842
+//	stock := models.DrugCancelStock{}
1843
+//	err := tx.Where("org_id = ? and status = 1", orgid).Last(&stock).Error
1844
+//	return stock, err
1845
+//}
1846
+
1830 1847
 func GetManufactureById(id int64) (models.Manufacturer, error) {
1831 1848
 	manufacturer := models.Manufacturer{}
1832 1849
 	err := XTReadDB().Model(&manufacturer).Where("id = ? and status = 1", id).Find(&manufacturer).Error
@@ -1842,9 +1859,13 @@ func GetDealerById(id int64) (models.Dealer, error) {
1842 1859
 func AddSigleDrugCancelStock(cancelStock *models.DrugCancelStock) error {
1843 1860
 	err := writeDb.Create(&cancelStock).Error
1844 1861
 	return err
1845
-
1846 1862
 }
1847 1863
 
1864
+//func AddSigleDrugCancelStockTX(cancelStock *models.DrugCancelStock,tx *gorm.DB) error {
1865
+//	err := tx.Create(&cancelStock).Error
1866
+//	return err
1867
+//}
1868
+
1848 1869
 func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error) {
1849 1870
 	if len(cancelStockInfo) > 0 {
1850 1871
 		utx := writeDb.Begin()
@@ -1894,6 +1915,11 @@ func CreateCancelStockInfoTwo(info *models.DrugCancelStockInfo) error {
1894 1915
 	return err
1895 1916
 }
1896 1917
 
1918
+//func CreateCancelStockInfoTwoTX(info *models.DrugCancelStockInfo,tx *gorm.DB) error {
1919
+//	err := tx.Create(&info).Error
1920
+//	return err
1921
+//}
1922
+
1897 1923
 func GetLastStockInfoThree(drugid int64) (models.DrugCancelStockInfo, error) {
1898 1924
 
1899 1925
 	info := models.DrugCancelStockInfo{}
@@ -1902,6 +1928,12 @@ func GetLastStockInfoThree(drugid int64) (models.DrugCancelStockInfo, error) {
1902 1928
 	return info, err
1903 1929
 }
1904 1930
 
1931
+//func GetLastStockInfoThreeTX(drugid int64,tx *gorm.DB) (models.DrugCancelStockInfo, error) {
1932
+//	info := models.DrugCancelStockInfo{}
1933
+//	err := tx.Model(&info).Where("drug_id = ? and status = 1", drugid).Find(&info).Error
1934
+//	return info, err
1935
+//}
1936
+
1905 1937
 func CreateCancelStockInfoOne(info *models.CancelStockInfo) error {
1906 1938
 
1907 1939
 	err := XTWriteDB().Create(&info).Error
@@ -3516,11 +3548,22 @@ func GetAllManufacturerList(orgid int64) (list []*models.Manufacturer, err error
3516 3548
 	return list, err
3517 3549
 }
3518 3550
 
3551
+//func GetAllManufacturerListTX(orgid int64,tx *gorm.DB) (list []*models.Manufacturer, err error) {
3552
+//
3553
+//	err = tx.Where("org_id = ? and status = 1", orgid).Find(&list).Error
3554
+//	return list, err
3555
+//}
3556
+
3519 3557
 func GetAllDealerList(orgid int64) (list []*models.Dealer, err error) {
3520 3558
 
3521 3559
 	err = XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&list).Error
3522 3560
 	return list, err
3523 3561
 }
3562
+
3563
+//func GetAllDealerListTX(orgid int64,tx *gorm.DB) (list []*models.Dealer, err error) {
3564
+//	err = tx.Where("org_id = ? and status = 1", orgid).Find(&list).Error
3565
+//	return list, err
3566
+//}
3524 3567
 func GetDealerByName(orgid int64, name string) (*models.Dealer, error) {
3525 3568
 	var dealer models.Dealer
3526 3569
 	var err error
@@ -4113,7 +4156,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
4113 4156
 	if orgid > 0 {
4114 4157
 		db = db.Where("x.org_id = ?", orgid)
4115 4158
 	}
4116
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.supply_cancel_out_id,x.supply_warehouse_id,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
4159
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.supply_cancel_out_id,x.supply_warehouse_id,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,x.register_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
4117 4160
 	return out, err
4118 4161
 }
4119 4162
 
@@ -4146,6 +4189,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
4146 4189
 	}
4147 4190
 
4148 4191
 	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,t.social_security_directory_code,x.is_sys,x.sys_record_time,n.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price").Joins("left join xt_warehouse_info as n on n.id=x.warehouse_info_id").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
4192
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,t.social_security_directory_code,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,x.register_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
4149 4193
 	return out, err
4150 4194
 }
4151 4195
 
@@ -5130,6 +5174,16 @@ func GetDrugWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
5130 5174
 	return info, err
5131 5175
 }
5132 5176
 
5177
+//func GetDrugWarehouseInfoTX(id int64,tx *gorm.DB) (models.XtDrugWarehouseInfo, error) {
5178
+//	info := models.XtDrugWarehouseInfo{}
5179
+//	db := tx.Model(&info).Where("status = 1")
5180
+//	if id > 0 {
5181
+//		db = db.Where("id = ?", id)
5182
+//	}
5183
+//	err := db.Select("drug_id,warehousing_count,stock_max_number,stock_min_number").Find(&info).Error
5184
+//	return info, err
5185
+//}
5186
+
5133 5187
 func GetDrugWarehouseInfoPrescription(drugid int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
5134 5188
 
5135 5189
 	err = XTReadDB().Where("drug_id = ? and org_id =? and status = 1", drugid, orgid).Find(&info).Error
@@ -5222,6 +5276,11 @@ func UpdateDrugWarehouseInfo(info *models.XtDrugWarehouseInfo, id int64) error {
5222 5276
 	return err
5223 5277
 }
5224 5278
 
5279
+//func UpdateDrugWarehouseInfoTX(info *models.XtDrugWarehouseInfo, id int64,tx *gorm.DB) error {
5280
+//	err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
5281
+//	return err
5282
+//}
5283
+
5225 5284
 func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
5226 5285
 
5227 5286
 	//err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
@@ -5231,6 +5290,11 @@ func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) erro
5231 5290
 	return err
5232 5291
 }
5233 5292
 
5293
+//func UpdateDrugWarehouseInfoOneTX(info *models.XtDrugWarehouseInfo, id int64,tx *gorm.DB) error {
5294
+//	err = tx.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
5295
+//	return err
5296
+//}
5297
+
5234 5298
 func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
5235 5299
 
5236 5300
 	info := models.DrugCancelStockInfo{}
@@ -5399,6 +5463,12 @@ func UpdateDrugCancel(id int64) (models.DrugCancelStock, error) {
5399 5463
 	return stock, err
5400 5464
 }
5401 5465
 
5466
+//func UpdateDrugCancelTX(id int64,tx *gorm.DB) (models.DrugCancelStock, error) {
5467
+//	stock := models.DrugCancelStock{}
5468
+//	err := tx.Model(&stock).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
5469
+//	return stock, err
5470
+//}
5471
+
5402 5472
 func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugWarehouseOutInfo, err error) {
5403 5473
 
5404 5474
 	db := XTReadDB().Model(&info)
@@ -5413,12 +5483,29 @@ func GetDrugWarehouseOutInfo(warehouse_info_id int64, drug_id int64) (info []*mo
5413 5483
 	return info, err
5414 5484
 }
5415 5485
 
5486
+//func GetDrugWarehouseOutInfoTX(warehouse_info_id int64, drug_id int64,tx *gorm.DB) (info []*models.DrugWarehouseOutInfo, err error) {
5487
+//	db := tx.Model(&info)
5488
+//	if warehouse_info_id > 0 {
5489
+//		db = db.Where("warehouse_info_id = ?", warehouse_info_id)
5490
+//	}
5491
+//	if drug_id > 0 {
5492
+//		db = db.Where("drug_id = ? and status =1", drug_id)
5493
+//	}
5494
+//	err = db.Find(&info).Error
5495
+//	return info, err
5496
+//}
5497
+
5416 5498
 func GetCancelDrugStockOutInfo(warehouse_info_id int64, drug_id int64) (info []*models.DrugCancelStockInfo, err error) {
5417 5499
 
5418 5500
 	err = XTReadDB().Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
5419 5501
 	return info, err
5420 5502
 }
5421 5503
 
5504
+//func GetCancelDrugStockOutInfoTX(warehouse_info_id int64, drug_id int64,tx *gorm.DB) (info []*models.DrugCancelStockInfo, err error) {
5505
+//	err = tx.Model(&info).Where("batch_number_id =? and drug_id = ? and status = 1", warehouse_info_id, drug_id).Find(&info).Error
5506
+//	return info, err
5507
+//}
5508
+
5422 5509
 func GetTemplateSummary(orgid int64) (config []*models.Dataconfig, err error) {
5423 5510
 
5424 5511
 	err = XTReadDB().Model(&config).Where("module='template_summary' and parent_id=? and org_id in (?)", 0, orgid).Find(&config).Error
@@ -5954,7 +6041,7 @@ func UpdateWarehouseInfoByGoodId(info models.WarehousingInfo, id int64) error {
5954 6041
 
5955 6042
 func UpdateWarehouseInfoByGoodIdOne(info *models.WarehousingInfo, id int64) error {
5956 6043
 
5957
-	err := XTWriteDB().Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount, "price": info.Price, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "license_number": info.LicenseNumber, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "remark": info.Remark, "packing_price": info.PackingPrice, "storehouse_id": info.StorehouseId}).Error
6044
+	err := XTWriteDB().Model(&info).Where("id =? and status = 1", id).Updates(map[string]interface{}{"warehousing_count": info.WarehousingCount, "stock_count": info.StockCount, "price": info.Price, "number": info.Number, "product_date": info.ProductDate, "expiry_date": info.ExpiryDate, "license_number": info.LicenseNumber, "manufacturer": info.Manufacturer, "dealer": info.Dealer, "remark": info.Remark, "packing_price": info.PackingPrice, "storehouse_id": info.StorehouseId, "register_number": info.RegisterNumber}).Error
5958 6045
 	return err
5959 6046
 }
5960 6047
 
@@ -5966,12 +6053,12 @@ func UpdatedStockFlowByGoodId(warehousing_id int64, good_id int64, flow models.V
5966 6053
 
5967 6054
 func UpdatedStockFlowByGoodIdOne(warehousing_id int64, good_id int64, flow models.VmStockFlow) error {
5968 6055
 
5969
-	err := XTWriteDB().Model(&flow).Where("warehousing_id = ? and good_id = ? and status = 1", warehousing_id, good_id).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "storehouse_id": flow.StorehouseId}).Error
6056
+	err := XTWriteDB().Model(&flow).Where("warehousing_id = ? and good_id = ? and status = 1", warehousing_id, good_id).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "storehouse_id": flow.StorehouseId, "register_number": flow.RegisterNumber}).Error
5970 6057
 	return err
5971 6058
 }
5972 6059
 
5973 6060
 func UpdateStockFlowByDetailId(flow models.VmStockFlow, wareoutdetailid int64) error {
5974
-	err := XTWriteDB().Model(&flow).Where("warehouse_out_detail_id = ? and status = 1", wareoutdetailid).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "price": flow.Price, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId, "stock_count": flow.StockCount}).Error
6061
+	err := XTWriteDB().Model(&flow).Where("warehouse_out_detail_id = ? and status = 1", wareoutdetailid).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "price": flow.Price, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId, "stock_count": flow.StockCount, "register_number": flow.RegisterNumber}).Error
5975 6062
 	return err
5976 6063
 }
5977 6064
 
@@ -6457,6 +6544,11 @@ func UpdateMedicalSumCount(drug_id int64, sum_count int64, sum_in_count int64, o
6457 6544
 	return err
6458 6545
 }
6459 6546
 
6547
+//func UpdateMedicalSumCountTX(drug_id int64, sum_count int64, sum_in_count int64, orgid int64,tx *gorm.DB) error {
6548
+//	err := tx.Model(&models.BaseDrugLib{}).Where("id = ? and org_id = ? and status = 1", drug_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
6549
+//	return err
6550
+//}
6551
+
6460 6552
 func UpdateGoodByGoodId(good_id int64, sum_count int64, sum_in_count int64, orgid int64) error {
6461 6553
 	err := XTWriteDB().Model(&models.GoodInfo{}).Where("id = ? and org_id = ? and status = 1", good_id, orgid).Update(map[string]interface{}{"sum_count": sum_count, "sum_in_count": sum_in_count}).Error
6462 6554
 	return err

+ 5 - 4
service/user_service.go Просмотреть файл

@@ -25,12 +25,13 @@ type AdminUserList struct {
25 25
 	Id       int64  `json:"id"`
26 26
 	Name     string `json:"name"`
27 27
 	UserType int64  `json:"user_type"`
28
+	Status   int64  `json:"status"`
28 29
 }
29 30
 
30 31
 func GetAllDoctorAndNurse(orgId, appid int64) (doctors []AdminUserList, nurses []AdminUserList, err error) {
31 32
 
32 33
 	var users []AdminUserList
33
-	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and org_id=? and app_id =? and uar.user_type IN (2,3) and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&users).Error
34
+	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and org_id=? and app_id =? and uar.user_type IN (2,3) and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&users).Error
34 35
 	if err != nil {
35 36
 		return
36 37
 	}
@@ -49,14 +50,14 @@ func GetAllDoctorAndNurse(orgId, appid int64) (doctors []AdminUserList, nurses [
49 50
 
50 51
 func GetAllAdminUsers(orgId, appid int64) (list []*AdminUserList, err error) {
51 52
 
52
-	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
53
+	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.org_id=? and uar.app_id =? and ua.status=1", orgId, appid).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&list).Error
53 54
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
54 55
 	return
55 56
 }
56 57
 
57 58
 func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
58 59
 
59
-	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=?  and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
60
+	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=?  and ua.status=1", orgId).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Scan(&list).Error
60 61
 	//err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1  and ua.status=1").Select("ua.id, uar.user_name as name, uar.user_type").Scan(&list).Error
61 62
 	return
62 63
 }
@@ -64,7 +65,7 @@ func GetAllAdminUsersTwo(orgId int64) (list []*AdminUserList, err error) {
64 65
 func GetAdminUser(orgId, appid, id int64) (*AdminUserList, error) {
65 66
 	var err error
66 67
 	var user AdminUserList
67
-	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and uar.admin_user_id = ? and ua.status=1", orgId, appid, id).Select("ua.id, uar.user_name as name, uar.user_type").Order("uar.id ASC").Take(&user).Error
68
+	err = readUserDb.Table("sgj_user_admin_role as uar").Joins("JOIN sgj_user_admin as ua ON ua.id = uar.admin_user_id").Where("uar.status=1 and uar.org_id=? and uar.app_id =? and uar.admin_user_id = ? and ua.status=1", orgId, appid, id).Select("ua.id, uar.user_name as name, uar.user_type,uar.status").Order("uar.id ASC").Take(&user).Error
68 69
 
69 70
 	if err == gorm.ErrRecordNotFound {
70 71
 		return nil, nil

+ 99 - 8
service/warhouse_service.go Просмотреть файл

@@ -274,6 +274,9 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
274 274
 				if warehouse.StockMinNumber > 0 {
275 275
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
276 276
 				}
277
+				if (warehouse.StockMinNumber - deliver_number) > 0 {
278
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
279
+				}
277 280
 
278 281
 			}
279 282
 
@@ -286,6 +289,12 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
286 289
 				//if warehouse.StockMinNumber == 0 {
287 290
 				//  warehouse.StockMaxNumber = stock_max_number
288 291
 				//}
292
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
293
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
294
+
295
+				//if warehouse.StockMinNumber == 0 {
296
+				//	warehouse.StockMaxNumber = stock_max_number
297
+				//}
289 298
 			}
290 299
 
291 300
 		}
@@ -530,9 +539,13 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
530 539
 	prescribingNumber_temp := strconv.FormatFloat(math.Abs(prescribingNumber), 'f', 0, 64)
531 540
 	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
532 541
 
533
-	if advice.PrescribingNumberUnit == drup.MaxUnit {
542
+	if advice.PrescribingNumberUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
534 543
 		deliver_number = count * drup.MinNumber
535
-	} else {
544
+	}
545
+	if advice.PrescribingNumberUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
546
+		deliver_number = count * drup.MinNumber
547
+	}
548
+	if advice.PrescribingNumberUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
536 549
 		deliver_number = count
537 550
 	}
538 551
 
@@ -570,12 +583,10 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
570 583
 	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId, storeConfig.DrugStorehouseOut)
571 584
 
572 585
 	if err != nil {
573
-
574 586
 		return err
575 587
 	}
576 588
 
577 589
 	// 将该批次的剩余库存数量转换为拆零数量
578
-
579 590
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
580 591
 	fmt.Println("查询剩余库存", stock_number)
581 592
 
@@ -670,6 +681,9 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
670 681
 		// 判断处方里药品单位是拆零单位还是包装单位,	如果是拆零单位,则根据规格,将拆零数量转为包装数量
671 682
 		var maxNumber int64 = 0
672 683
 		var minNumber int64 = 0
684
+		//var stock_max_number int64 = 0
685
+		//
686
+		//stock_max_number = warehouse.StockMaxNumber
673 687
 
674 688
 		maxNumber = deliver_number / drup.MinNumber
675 689
 		minNumber = deliver_number % drup.MinNumber
@@ -683,9 +697,12 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
683 697
 				return errors.New("库存数量不足")
684 698
 			}
685 699
 		}
700
+		fmt.Println("max_number23323232323232232323", maxNumber)
701
+		fmt.Println("minNumber", minNumber)
686 702
 		fmt.Println("查询库存", warehouse.StockMaxNumber)
687 703
 		fmt.Println("扣减库存我的", maxNumber)
688 704
 		warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
705
+		fmt.Println("max_number23323232323232232323", warehouse.StockMaxNumber)
689 706
 		fmt.Println("剩余库存我的", warehouse.StockMaxNumber)
690 707
 
691 708
 		if warehouse.StockMaxNumber < 0 {
@@ -698,20 +715,25 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
698 715
 		warehouse.Mtime = time.Now().Unix()
699 716
 
700 717
 		if warehouse.StockMinNumber < minNumber {
701
-
702 718
 			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
703 719
 			warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
704 720
 		} else {
705
-
706 721
 			if minNumber > 0 {
707 722
 				warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
708 723
 			}
709 724
 
725
+			fmt.Println("deliver_number2332322323323232", deliver_number)
726
+
727
+			fmt.Println("warehouse.StockMinNumber", warehouse.StockMinNumber)
710 728
 			if minNumber == 0 && maxNumber != 1 {
711 729
 				if warehouse.StockMinNumber > 0 {
712 730
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
713 731
 				}
714 732
 
733
+				if (warehouse.StockMinNumber - deliver_number) > 0 {
734
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
735
+				}
736
+
715 737
 			}
716 738
 		}
717 739
 
@@ -727,6 +749,12 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
727 749
 				//if warehouse.StockMinNumber == 0 {
728 750
 				//  warehouse.StockMaxNumber = stock_max_number
729 751
 				//}
752
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
753
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
754
+
755
+				//if warehouse.StockMinNumber == 0 {
756
+				//	 warehouse.StockMaxNumber = stock_max_number
757
+				//}
730 758
 			}
731 759
 
732 760
 		}
@@ -739,6 +767,10 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
739 767
 		if warehouse.StockMinNumber <= 0 {
740 768
 			warehouse.StockMinNumber = 0
741 769
 		}
770
+
771
+		fmt.Println("warehouse.StockMinNumber 2323323232233", warehouse.StockMinNumber)
772
+		fmt.Println("warehouse.StockMaxNumber 2323323232233", warehouse.StockMaxNumber)
773
+
742 774
 		fmt.Println("stock_max_233232323223323233223323223", warehouse.StockMinNumber)
743 775
 		fmt.Println("stock_max_233232323223323233223323223", warehouse.StockMaxNumber)
744 776
 		//扣减库存232332332332
@@ -1903,6 +1935,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1903 1935
 			AdminUserId:             goods.AdminUserId,
1904 1936
 			BuyPrice:                warehouse.Price,
1905 1937
 			StockCount:              goods.StockCount,
1938
+			RegisterNumber:          goods.RegisterNumber,
1906 1939
 		}
1907 1940
 		warehouseOutInfo.Count = goods.Count
1908 1941
 		//添加出库单详情
@@ -1946,6 +1979,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1946 1979
 			AdminUserId:             goods.AdminUserId,
1947 1980
 			BuyPrice:                warehouse.Price,
1948 1981
 			StockCount:              goods.StockCount,
1982
+			RegisterNumber:          goods.RegisterNumber,
1949 1983
 		}
1950 1984
 
1951 1985
 		//创建出库流水
@@ -2013,6 +2047,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
2013 2047
 			AdminUserId:             goods.AdminUserId,
2014 2048
 			BuyPrice:                warehouse.Price,
2015 2049
 			StockCount:              goods.StockCount,
2050
+			RegisterNumber:          goods.RegisterNumber,
2016 2051
 		}
2017 2052
 		warehouseOutInfo.Count = stock_number
2018 2053
 
@@ -2065,6 +2100,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
2065 2100
 			AdminUserId:             goods.AdminUserId,
2066 2101
 			BuyPrice:                warehouse.Price,
2067 2102
 			StockCount:              goods.StockCount,
2103
+			RegisterNumber:          goods.RegisterNumber,
2068 2104
 		}
2069 2105
 
2070 2106
 		//创建出库明细
@@ -2419,6 +2455,9 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2419 2455
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2420 2456
 				}
2421 2457
 
2458
+				if (warehouse.StockMinNumber - deliver_number) > 0 {
2459
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2460
+				}
2422 2461
 			}
2423 2462
 		}
2424 2463
 
@@ -2429,6 +2468,12 @@ func NewDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
2429 2468
 				//if warehouse.StockMinNumber == 0 {
2430 2469
 				//  warehouse.StockMaxNumber = stock_max_number
2431 2470
 				//}
2471
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
2472
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2473
+
2474
+				//if warehouse.StockMinNumber == 0 {
2475
+				//	warehouse.StockMaxNumber = stock_max_number
2476
+				//}
2432 2477
 			}
2433 2478
 
2434 2479
 		}
@@ -2786,6 +2831,10 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2786 2831
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2787 2832
 				}
2788 2833
 
2834
+				if (warehouse.StockMinNumber - deliver_number) > 0 {
2835
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2836
+				}
2837
+
2789 2838
 			}
2790 2839
 		}
2791 2840
 
@@ -2796,6 +2845,12 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2796 2845
 				//if warehouse.StockMinNumber == 0 {
2797 2846
 				//  warehouse.StockMaxNumber = stock_max_number
2798 2847
 				//}
2848
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
2849
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
2850
+
2851
+				//if warehouse.StockMinNumber == 0 {
2852
+				//	warehouse.StockMaxNumber = stock_max_number
2853
+				//}
2799 2854
 			}
2800 2855
 
2801 2856
 		}
@@ -4542,7 +4597,10 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4542 4597
 		} else {
4543 4598
 			if minNumber > 0 {
4544 4599
 				if minNumber == 1 && maxNumber == 1 && drup.MaxUnit != drup.MinUnit {
4545
-					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4600
+					if (warehouse.StockMinNumber - deliver_number) > 0 {
4601
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4602
+					}
4603
+
4546 4604
 				} else {
4547 4605
 					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
4548 4606
 				}
@@ -4552,6 +4610,9 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4552 4610
 				if warehouse.StockMinNumber > 0 {
4553 4611
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4554 4612
 				}
4613
+				if (warehouse.StockMinNumber - deliver_number) > 0 {
4614
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4615
+				}
4555 4616
 
4556 4617
 			}
4557 4618
 
@@ -4564,6 +4625,12 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4564 4625
 				//if warehouse.StockMinNumber == 0 {
4565 4626
 				//  warehouse.StockMaxNumber = stock_max_number
4566 4627
 				//}
4628
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
4629
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4630
+
4631
+				//if warehouse.StockMinNumber == 0 {
4632
+				//	warehouse.StockMaxNumber = stock_max_number
4633
+				//}
4567 4634
 			}
4568 4635
 
4569 4636
 		}
@@ -4786,6 +4853,11 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4786 4853
 		warehouseOutInfo.Count = prescribingNumber
4787 4854
 		warehouseOutInfo.CountUnit = advice.CountUnit
4788 4855
 
4856
+		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
4857
+		if errOne != nil {
4858
+			return errOne
4859
+		}
4860
+
4789 4861
 		drugWareInfo, _ := GetLastWarehouseOutInfoById(advice.DrugId)
4790 4862
 		drugflow := models.DrugFlow{
4791 4863
 			WarehouseOutId:          warehouseout.ID,
@@ -4858,7 +4930,10 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4858 4930
 		} else {
4859 4931
 			if minNumber > 0 {
4860 4932
 				if minNumber == 1 && maxNumber == 1 && drup.MaxUnit != drup.MinUnit {
4861
-					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4933
+					if (warehouse.StockMinNumber - deliver_number) > 0 {
4934
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4935
+					}
4936
+
4862 4937
 				} else {
4863 4938
 					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
4864 4939
 				}
@@ -4868,11 +4943,21 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4868 4943
 				if warehouse.StockMinNumber > 0 {
4869 4944
 					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4870 4945
 				}
4946
+				if (warehouse.StockMinNumber - deliver_number) > 0 {
4947
+					warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4948
+				}
4871 4949
 
4872 4950
 			}
4873 4951
 
4874 4952
 		}
4875 4953
 
4954
+		}
4955
+
4956
+		fmt.Println("maxNumber2332323233223", maxNumber)
4957
+		fmt.Println("minNumber", minNumber)
4958
+		fmt.Println("warehouse.StockMinNumber2332322323", warehouse.StockMinNumber)
4959
+		fmt.Println("deliver_number233232323233223332", deliver_number)
4960
+
4876 4961
 		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
4877 4962
 			if (warehouse.StockMinNumber - deliver_number) > 0 {
4878 4963
 				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
@@ -4880,6 +4965,12 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4880 4965
 				//if warehouse.StockMinNumber == 0 {
4881 4966
 				//  warehouse.StockMaxNumber = stock_max_number
4882 4967
 				//}
4968
+			if (warehouse.StockMinNumber - deliver_number) > 0 {
4969
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4970
+
4971
+				//if warehouse.StockMinNumber == 0 {
4972
+				//	warehouse.StockMaxNumber = stock_max_number
4973
+				//}
4883 4974
 			}
4884 4975
 
4885 4976
 		}