Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
4db80d8823

+ 0 - 15
controllers/drug_stock_api_contorller.go View File

@@ -183,18 +183,8 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
183 183
 
184 184
 				}
185 185
 
186
-				if items["lot_number"] == nil || reflect.TypeOf(items["lot_number"]).String() != "string" {
187
-					utils.ErrorLog("lot_number")
188
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
189
-					return
190
-				}
191 186
 				lot_number, _ := items["lot_number"].(string)
192 187
 
193
-				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
194
-					utils.ErrorLog("batch_number")
195
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
196
-					return
197
-				}
198 188
 				batch_number, _ := items["batch_number"].(string)
199 189
 
200 190
 				if items["max_unit"] == nil || reflect.TypeOf(items["max_unit"]).String() != "string" {
@@ -613,11 +603,6 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
613 603
 				}
614 604
 				number, _ := items["lot_number"].(string)
615 605
 
616
-				if items["batch_number"] == nil || reflect.TypeOf(items["batch_number"]).String() != "string" {
617
-					utils.ErrorLog("batch_number")
618
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
619
-					return
620
-				}
621 606
 				batch_number, _ := items["batch_number"].(string)
622 607
 
623 608
 				max_unit, _ := items["max_unit"].(string)

+ 7 - 3
controllers/gobal_config_api_controller.go View File

@@ -1815,7 +1815,7 @@ func (c *GobalConfigApiController) GetDrugStockList() {
1815 1815
 	page, _ := c.GetInt64("page", -1)
1816 1816
 	limit, _ := c.GetInt64("limit", -1)
1817 1817
 	keyword := c.GetString("keyword")
1818
-	drug_category, _ := c.GetInt64("drug_category")
1818
+	drug_type, _ := c.GetInt64("drug_type")
1819 1819
 	start_time := c.GetString("start_time")
1820 1820
 	end_time := c.GetString("end_time")
1821 1821
 	timeLayout := "2006-01-02"
@@ -1844,7 +1844,7 @@ func (c *GobalConfigApiController) GetDrugStockList() {
1844 1844
 	adminUserInfo := c.GetAdminUserInfo()
1845 1845
 
1846 1846
 	//查询入库数量
1847
-	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_category, startTime, endTime, adminUserInfo.CurrentOrgId)
1847
+	list, total, err := service.GetDrugStockList(page, limit, keyword, drug_type, startTime, endTime, adminUserInfo.CurrentOrgId)
1848 1848
 	manufacturerList, _ := service.GetAllManufacturerList(adminUserInfo.CurrentOrgId)
1849 1849
 	if err != nil {
1850 1850
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
@@ -1958,7 +1958,7 @@ func (c *GobalConfigApiController) GetBatchOrderDetail() {
1958 1958
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1959 1959
 	limit, _ := c.GetInt64("limit")
1960 1960
 	page, _ := c.GetInt64("page")
1961
-	detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, limit, page)
1961
+	detail, total, err := service.GetBatchOrderDetail(drug_id, orgId, page, limit)
1962 1962
 	if err != nil {
1963 1963
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1964 1964
 		return
@@ -1999,8 +1999,10 @@ func (c *GobalConfigApiController) GetDrugCountList() {
1999 1999
 	}
2000 2000
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2001 2001
 	list, err := service.GetDrugCountList(startTime, endTime, orgId)
2002
+	countList, err := service.GetMinCountList(startTime, endTime, orgId)
2002 2003
 	outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2003 2004
 	auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2005
+	info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
2004 2006
 	if err != nil {
2005 2007
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2006 2008
 		return
@@ -2009,6 +2011,8 @@ func (c *GobalConfigApiController) GetDrugCountList() {
2009 2011
 		"countList":    list,
2010 2012
 		"outCountList": outCountList,
2011 2013
 		"auCountList":  auCountList,
2014
+		"minCount":     countList,
2015
+		"info":         info,
2012 2016
 	})
2013 2017
 }
2014 2018
 

+ 9 - 452
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -541,19 +541,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
541 541
 
542 542
 		adminUserInfo := c.GetMobileAdminUserInfo()
543 543
 
544
-		//appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id, adminUserInfo.App.Id)
545
-		//
546
-		//if appRole.UserType == 2 || appRole.UserType == 1 {
547
-		//	headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)
548
-		//	if getPermissionErr != nil {
549
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
550
-		//		return
551
-		//	} else if headNursePermission == nil {
552
-		//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
553
-		//		return
554
-		//	}
555
-		//}
556
-
557 544
 		var advice models.DoctorAdvice
558 545
 
559 546
 		if groupno > 0 {
@@ -561,7 +548,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
561 548
 			for _, item := range advices {
562 549
 				if item.ExecutionState == 2 {
563 550
 					advice = item
564
-
565 551
 				}
566 552
 			}
567 553
 		} else {
@@ -569,7 +555,6 @@ func (c *PatientApiController) ExecDoctorAdvice() {
569 555
 			for _, item := range advices {
570 556
 				if item.ExecutionState == 2 {
571 557
 					advice = item
572
-
573 558
 				}
574 559
 			}
575 560
 		}
@@ -628,327 +613,34 @@ func (c *PatientApiController) ExecDoctorAdvice() {
628 613
 			if groupno > 0 {
629 614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
630 615
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
631
-				record_time := int64(0)
632 616
 				for _, item := range advices {
633 617
 					if item.Way == 1 {
634 618
 						isHasWay = true
635
-						record_time = item.RecordDate
636 619
 					}
637 620
 				}
638 621
 
639 622
 				if isHasWay {
640
-					_, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
641
-					if err == gorm.ErrRecordNotFound {
642
-						//没有记录,则创建出库单
643
-						timeStr := time.Now().Format("2006-01-02")
644
-						timeArr := strings.Split(timeStr, "-")
645
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
646
-						total = total + 1
647
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
648
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
649
-						number = number + total
650
-						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
651
-						creater := adminUserInfo.AdminUser.Id
652
-						warehouseOut := models.DrugWarehouseOut{
653
-							WarehouseOutOrderNumber: warehousing_out_order,
654
-							OperationTime:           time.Now().Unix(),
655
-							OrgId:                   adminUserInfo.Org.Id,
656
-							Creater:                 creater,
657
-							Ctime:                   time.Now().Unix(),
658
-							Status:                  1,
659
-							WarehouseOutTime:        record_time,
660
-							Dealer:                  0,
661
-							Manufacturer:            0,
662
-							Type:                    1,
663
-							IsSys:                   1,
664
-						}
665
-						err := service.AddSigleDrugWarehouseOut(&warehouseOut)
666
-						if err != nil {
667
-							utils.TraceLog("创建出库单失败 err = %v", err)
668
-						} else {
669
-							for _, item := range advices {
670
-								if item.Way == 1 {
671
-
672
-									service.DrugsDelivery(item.UserOrgId, &item)
673
-
674
-									//if item.PrescribingNumber > 0 {
675
-									//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
676
-									//		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
677
-									//		WarehouseOutId:          warehouseOut.ID,
678
-									//		Status:                  1,
679
-									//		Ctime:                   time.Now().Unix(),
680
-									//		Remark:                  "",
681
-									//		OrgId:                   adminUserInfo.Org.Id,
682
-									//		Type:                    1,
683
-									//		Manufacturer:            0,
684
-									//		Dealer:                  0,
685
-									//		IsSys:                   1,
686
-									//		SysRecordTime:           record_time,
687
-									//		DrugId:                  item.DrugId,
688
-									//	}
689
-									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
690
-									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
691
-									//	warehouseOutInfo.Count = count
692
-									//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
693
-									//	warehouseOutInfo.Price = stockInInfo.Price
694
-									//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
695
-									//	if err == nil {
696
-									//		details := &models.DrugAutomaticReduceDetail{
697
-									//			WarehouseOutId:          warehouseOutInfo.ID,
698
-									//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
699
-									//			PatientId:               item.PatientId,
700
-									//			Ctime:                   time.Now().Unix(),
701
-									//			Mtime:                   time.Now().Unix(),
702
-									//			Status:                  1,
703
-									//			RecordTime:              record_time,
704
-									//			OrgId:                   adminUserInfo.Org.Id,
705
-									//			DrugId:                  item.DrugId,
706
-									//			Count:                   count,
707
-									//		}
708
-									//		service.AddSigleDrugAutoReduceRecordInfo(details)
709
-									//	}
710
-									//}
711
-								}
712
-
713
-							}
714
-						}
715
-
716
-					} else if err == nil {
717
-						for _, item := range advices {
718
-							if item.Way == 1 {
719
-								service.DrugsDelivery(item.UserOrgId, &item)
720
-								//outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
721
-								//if err == gorm.ErrRecordNotFound {
722
-								//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
723
-								//		WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
724
-								//		WarehouseOutId:          out.ID,
725
-								//		Status:                  1,
726
-								//		Ctime:                   time.Now().Unix(),
727
-								//		Remark:                  "",
728
-								//		OrgId:                   adminUserInfo.Org.Id,
729
-								//		Type:                    1,
730
-								//		Manufacturer:            0,
731
-								//		Dealer:                  0,
732
-								//		IsSys:                   1,
733
-								//		SysRecordTime:           record_time,
734
-								//	}
735
-								//
736
-								//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
737
-								//	warehouseOutInfo.Price = stockInInfo.Price
738
-								//	warehouseOutInfo.DrugId = item.DrugId
739
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
740
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
741
-								//	warehouseOutInfo.Count = count
742
-								//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
743
-								//	if err == nil {
744
-								//		details := &models.DrugAutomaticReduceDetail{
745
-								//			WarehouseOutId:          warehouseOutInfo.ID,
746
-								//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
747
-								//			PatientId:               item.PatientId,
748
-								//			Ctime:                   time.Now().Unix(),
749
-								//			Mtime:                   time.Now().Unix(),
750
-								//			Status:                  1,
751
-								//			RecordTime:              record_time,
752
-								//			OrgId:                   adminUserInfo.Org.Id,
753
-								//			DrugId:                  item.DrugId,
754
-								//			Count:                   count,
755
-								//		}
756
-								//		service.AddSigleDrugAutoReduceRecordInfo(details)
757
-								//	}
758
-								//
759
-								//} else if err == nil { //记录存在,则将增加数量
760
-								//	if outInfo.ID > 0 {
761
-								//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
762
-								//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
763
-								//		service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
764
-								//	}
765
-								//
766
-								//	//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
767
-								//	//if count == 0 {
768
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
769
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
770
-								//	details := &models.DrugAutomaticReduceDetail{
771
-								//		WarehouseOutId:          outInfo.ID,
772
-								//		WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
773
-								//		PatientId:               item.PatientId,
774
-								//		Ctime:                   time.Now().Unix(),
775
-								//		Mtime:                   time.Now().Unix(),
776
-								//		Status:                  1,
777
-								//		RecordTime:              record_time,
778
-								//		OrgId:                   adminUserInfo.Org.Id,
779
-								//		DrugId:                  item.DrugId,
780
-								//		Count:                   count,
781
-								//	}
782
-								//	service.AddSigleDrugAutoReduceRecordInfo(details)
783
-								//
784
-								//}
785
-							}
623
+					for _, item := range advices {
624
+						if item.Way == 1 {
625
+							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
786 626
 						}
787
-
788 627
 					}
789
-
790 628
 				}
791 629
 			} else {
792 630
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
793 631
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
794
-				record_time := int64(0)
632
+
795 633
 				for _, item := range advices {
796 634
 					if item.Way == 1 {
797 635
 						isHasWay = true
798
-						record_time = item.RecordDate
799 636
 					}
800 637
 				}
801
-
802 638
 				if isHasWay {
803
-					_, err := service.FindDrugStockOutByIsSys(adminUserInfo.Org.Id, 1, record_time)
804
-					if err == gorm.ErrRecordNotFound {
805
-						//没有记录,则创建出库单
806
-						timeStr := time.Now().Format("2006-01-02")
807
-						timeArr := strings.Split(timeStr, "-")
808
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
809
-						total = total + 1
810
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
811
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
812
-						number = number + total
813
-						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
814
-						creater := adminUserInfo.AdminUser.Id
815
-						warehouseOut := models.DrugWarehouseOut{
816
-							WarehouseOutOrderNumber: warehousing_out_order,
817
-							OperationTime:           time.Now().Unix(),
818
-							OrgId:                   adminUserInfo.Org.Id,
819
-							Creater:                 creater,
820
-							Ctime:                   time.Now().Unix(),
821
-							Status:                  1,
822
-							WarehouseOutTime:        record_time,
823
-							Dealer:                  0,
824
-							Manufacturer:            0,
825
-							Type:                    1,
826
-							IsSys:                   1,
827
-						}
828
-						err := service.AddSigleDrugWarehouseOut(&warehouseOut)
829
-						if err != nil {
830
-							utils.TraceLog("创建出库单失败 err = %v", err)
831
-						} else {
832
-							for _, item := range advices {
833
-								if item.Way == 1 {
834
-									service.DrugsDelivery(item.UserOrgId, &item)
835
-									//if item.PrescribingNumber > 0 {
836
-									//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
837
-									//		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
838
-									//		WarehouseOutId:          warehouseOut.ID,
839
-									//		Status:                  1,
840
-									//		Ctime:                   time.Now().Unix(),
841
-									//		Remark:                  "",
842
-									//		OrgId:                   adminUserInfo.Org.Id,
843
-									//		Type:                    1,
844
-									//		Manufacturer:            0,
845
-									//		Dealer:                  0,
846
-									//		IsSys:                   1,
847
-									//		SysRecordTime:           record_time,
848
-									//		DrugId:                  item.DrugId,
849
-									//	}
850
-									//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
851
-									//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
852
-									//	warehouseOutInfo.Count = count
853
-									//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
854
-									//	warehouseOutInfo.Price = stockInInfo.Price
855
-									//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
856
-									//	if err == nil {
857
-									//		details := &models.DrugAutomaticReduceDetail{
858
-									//			WarehouseOutId:          warehouseOutInfo.ID,
859
-									//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
860
-									//			PatientId:               item.PatientId,
861
-									//			Ctime:                   time.Now().Unix(),
862
-									//			Mtime:                   time.Now().Unix(),
863
-									//			Status:                  1,
864
-									//			RecordTime:              record_time,
865
-									//			OrgId:                   adminUserInfo.Org.Id,
866
-									//			DrugId:                  item.DrugId,
867
-									//			Count:                   count,
868
-									//		}
869
-									//		service.AddSigleDrugAutoReduceRecordInfo(details)
870
-									//	}
871
-									//}
872
-								}
873
-
874
-							}
639
+					for _, item := range advices {
640
+						if item.Way == 1 {
641
+							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
875 642
 						}
876
-
877
-					} else if err == nil {
878
-						for _, item := range advices {
879
-							if item.Way == 1 {
880
-								service.DrugsDelivery(item.UserOrgId, &item)
881
-								//outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.Org.Id, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
882
-								//if err == gorm.ErrRecordNotFound {
883
-								//	warehouseOutInfo := &models.DrugWarehouseOutInfo{
884
-								//		WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
885
-								//		WarehouseOutId:          out.ID,
886
-								//		Status:                  1,
887
-								//		Ctime:                   time.Now().Unix(),
888
-								//		Remark:                  "",
889
-								//		OrgId:                   adminUserInfo.Org.Id,
890
-								//		Type:                    1,
891
-								//		Manufacturer:            0,
892
-								//		Dealer:                  0,
893
-								//		IsSys:                   1,
894
-								//		SysRecordTime:           record_time,
895
-								//	}
896
-								//
897
-								//	stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.Org.Id)
898
-								//	warehouseOutInfo.Price = stockInInfo.Price
899
-								//	warehouseOutInfo.DrugId = item.DrugId
900
-								//	//warehouseOutInfo.Count = item.
901
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
902
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
903
-								//	err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
904
-								//	if err == nil {
905
-								//		details := &models.DrugAutomaticReduceDetail{
906
-								//			WarehouseOutId:          warehouseOutInfo.ID,
907
-								//			WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
908
-								//			PatientId:               item.PatientId,
909
-								//			Ctime:                   time.Now().Unix(),
910
-								//			Mtime:                   time.Now().Unix(),
911
-								//			Status:                  1,
912
-								//			RecordTime:              record_time,
913
-								//			OrgId:                   adminUserInfo.Org.Id,
914
-								//			DrugId:                  item.DrugId,
915
-								//			Count:                   count,
916
-								//		}
917
-								//		service.AddSigleDrugAutoReduceRecordInfo(details)
918
-								//	}
919
-								//
920
-								//} else if err == nil { //记录存在,则将增加数量
921
-								//	if outInfo.ID > 0 {
922
-								//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
923
-								//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
924
-								//		service.UpdateDrugStockOutInfoCount2(adminUserInfo.Org.Id, outInfo.ID, count)
925
-								//	}
926
-								//
927
-								//	//count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.Org.Id, record_time, item.DrugId, item.PatientId)
928
-								//	//if count == 0 {
929
-								//	prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
930
-								//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
931
-								//	details := &models.DrugAutomaticReduceDetail{
932
-								//		WarehouseOutId:          outInfo.ID,
933
-								//		WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
934
-								//		PatientId:               item.PatientId,
935
-								//		Ctime:                   time.Now().Unix(),
936
-								//		Mtime:                   time.Now().Unix(),
937
-								//		Status:                  1,
938
-								//		RecordTime:              record_time,
939
-								//		OrgId:                   adminUserInfo.Org.Id,
940
-								//		DrugId:                  item.DrugId,
941
-								//		Count:                   count,
942
-								//	}
943
-								//	service.AddSigleDrugAutoReduceRecordInfo(details)
944
-								//
945
-								//
946
-								//}
947
-							}
948
-						}
949
-
950 643
 					}
951
-
952 644
 				}
953 645
 			}
954 646
 		}
@@ -1070,6 +762,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1070 762
 			return
1071 763
 		}
1072 764
 		adminInfo := c.GetMobileAdminUserInfo()
765
+		creater := c.GetMobileAdminUserInfo().AdminUser.Id
1073 766
 		advice_id, _ := c.GetInt64("advice_id")
1074 767
 		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
1075 768
 		if advices.ExecutionState == 1 {
@@ -1096,143 +789,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1096 789
 			fmt.Println("drugstockconfig000000000000000000000000", drugStockConfig.IsOpen)
1097 790
 			if drugStockConfig.IsOpen == 1 {
1098 791
 				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
1099
-				record_time := advice.RecordDate
1100
-
1101
-				out, err := service.FindDrugStockOutByIsSys(adminInfo.Org.Id, 1, record_time)
1102
-				if err == gorm.ErrRecordNotFound {
1103
-					//没有记录,则创建出库单
1104
-					timeStr := time.Now().Format("2006-01-02")
1105
-					timeArr := strings.Split(timeStr, "-")
1106
-					total, _ := service.FindAllDrugWarehouseOut(adminInfo.Org.Id)
1107
-					total = total + 1
1108
-					warehousing_out_order := strconv.FormatInt(adminInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1109
-					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1110
-					number = number + total
1111
-					warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1112
-					creater := adminInfo.AdminUser.Id
1113
-					warehouseOut := models.DrugWarehouseOut{
1114
-						WarehouseOutOrderNumber: warehousing_out_order,
1115
-						OperationTime:           time.Now().Unix(),
1116
-						OrgId:                   adminInfo.Org.Id,
1117
-						Creater:                 creater,
1118
-						Ctime:                   time.Now().Unix(),
1119
-						Status:                  1,
1120
-						WarehouseOutTime:        record_time,
1121
-						Dealer:                  0,
1122
-						Manufacturer:            0,
1123
-						Type:                    1,
1124
-						IsSys:                   1,
1125
-					}
1126
-					err := service.AddSigleDrugWarehouseOut(&warehouseOut)
1127
-					if err != nil {
1128
-						utils.TraceLog("创建出库单失败 err = %v", err)
1129
-					} else {
1130
-						if advice.PrescribingNumber > 0 {
1131
-							warehouseOutInfo := &models.DrugWarehouseOutInfo{
1132
-								WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1133
-								WarehouseOutId:          warehouseOut.ID,
1134
-								Status:                  1,
1135
-								Ctime:                   time.Now().Unix(),
1136
-								Remark:                  "",
1137
-								OrgId:                   adminInfo.Org.Id,
1138
-								Type:                    1,
1139
-								Manufacturer:            0,
1140
-								Dealer:                  0,
1141
-								IsSys:                   1,
1142
-								SysRecordTime:           record_time,
1143
-								DrugId:                  advice.DrugId,
1144
-							}
1145
-							prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1146
-							count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1147
-							warehouseOutInfo.Count = count
1148
-							stockInInfo, _ := service.FindLastDrugStockInInfoRecord(advice.DrugId, adminInfo.Org.Id)
1149
-							warehouseOutInfo.Price = stockInInfo.Price
1150
-							err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1151
-
1152
-							if err == nil {
1153
-								service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1154
-								//details := &models.DrugAutomaticReduceDetail{
1155
-								//	WarehouseOutId:          warehouseOutInfo.ID,
1156
-								//	WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1157
-								//	PatientId:               advice.PatientId,
1158
-								//	Ctime:                   time.Now().Unix(),
1159
-								//	Mtime:                   time.Now().Unix(),
1160
-								//	Status:                  1,
1161
-								//	RecordTime:              record_time,
1162
-								//	OrgId:                   adminInfo.Org.Id,
1163
-								//	DrugId:                  advice.DrugId,
1164
-								//	Count:                   count,
1165
-								//}
1166
-								//service.AddSigleDrugAutoReduceRecordInfo(details)
1167
-							}
1168
-						}
1169
-					}
1170
-
1171
-				} else if err == nil {
1172
-					_, err := service.FindDrugStockOutInfoByTypeId(adminInfo.Org.Id, advice.DrugId, out.ID, out.WarehouseOutOrderNumber)
1173
-					if err == gorm.ErrRecordNotFound {
1174
-						warehouseOutInfo := &models.DrugWarehouseOutInfo{
1175
-							WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1176
-							WarehouseOutId:          out.ID,
1177
-							Status:                  1,
1178
-							Ctime:                   time.Now().Unix(),
1179
-							Remark:                  "",
1180
-							OrgId:                   adminInfo.Org.Id,
1181
-							Type:                    1,
1182
-							Manufacturer:            0,
1183
-							Dealer:                  0,
1184
-							IsSys:                   1,
1185
-							SysRecordTime:           record_time,
1186
-						}
1187
-
1188
-						stockInInfo, _ := service.FindLastDrugStockInInfoRecord(advice.DrugId, adminInfo.Org.Id)
1189
-						warehouseOutInfo.Price = stockInInfo.Price
1190
-						warehouseOutInfo.DrugId = advice.DrugId
1191
-						prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1192
-						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1193
-						warehouseOutInfo.Count = count
1194
-						err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1195
-						if err == nil {
1196
-							service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1197
-							//details := &models.DrugAutomaticReduceDetail{
1198
-							//	WarehouseOutId:          warehouseOutInfo.ID,
1199
-							//	WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1200
-							//	PatientId:               advice.PatientId,
1201
-							//	Ctime:                   time.Now().Unix(),
1202
-							//	Mtime:                   time.Now().Unix(),
1203
-							//	Status:                  1,
1204
-							//	RecordTime:              record_time,
1205
-							//	OrgId:                   adminInfo.Org.Id,
1206
-							//	DrugId:                  advice.DrugId,
1207
-							//	Count:                   count,
1208
-							//}
1209
-							//service.AddSigleDrugAutoReduceRecordInfo(details)
1210
-						}
1211
-
1212
-					} else if err == nil { //记录存在,则将增加数量
1213
-						service.HisDrugsDelivery(adminInfo.Org.Id, &advice)
1214
-						//if outInfo.ID > 0 {
1215
-						//	prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1216
-						//	count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1217
-						//	service.UpdateDrugStockOutInfoCount2(adminInfo.Org.Id, outInfo.ID, count)
1218
-						//}
1219
-						//prescribingNumber := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1220
-						//count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1221
-						//details := &models.DrugAutomaticReduceDetail{
1222
-						//	WarehouseOutId:          outInfo.ID,
1223
-						//	WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1224
-						//	PatientId:               advice.PatientId,
1225
-						//	Ctime:                   time.Now().Unix(),
1226
-						//	Mtime:                   time.Now().Unix(),
1227
-						//	Status:                  1,
1228
-						//	RecordTime:              record_time,
1229
-						//	OrgId:                   adminInfo.Org.Id,
1230
-						//	DrugId:                  advice.DrugId,
1231
-						//	Count:                   count,
1232
-						//}
1233
-						//service.AddSigleDrugAutoReduceRecordInfo(details)
1234
-					}
1235
-				}
792
+				service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
1236 793
 			}
1237 794
 			c.ServeSuccessJSON(map[string]interface{}{
1238 795
 				"msg":    "ok",

+ 2 - 2
controllers/patient_api_controller.go View File

@@ -1856,7 +1856,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1856 1856
 			for _, item := range advices {
1857 1857
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1858 1858
 				//调用药品出库接口
1859
-				service.DrugsDelivery(item.UserOrgId, item)
1859
+				service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1860 1860
 
1861 1861
 				//if item.Way == 1 {
1862 1862
 				//	out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
@@ -2180,7 +2180,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2180 2180
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
2181 2181
 			for _, item := range advices {
2182 2182
 
2183
-				service.HisDrugsDelivery(item.UserOrgId, item)
2183
+				service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
2184 2184
 
2185 2185
 				//out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
2186 2186
 				//if err == gorm.ErrRecordNotFound {

+ 39 - 0
controllers/stock_in_api_controller.go View File

@@ -89,6 +89,8 @@ func StockManagerApiRegistRouters() {
89 89
 	beego.Router("/api/good/getorderdetialbyorderid", &StockManagerApiController{}, "Get:GetOrderDetialByOrderId")
90 90
 	beego.Router("/api/good/getorderdetaibyid", &StockManagerApiController{}, "Get:GetOrderDetailById")
91 91
 	beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
92
+	beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
93
+
92 94
 }
93 95
 
94 96
 func (c *StockManagerApiController) CreateWarehouse() {
@@ -3788,6 +3790,7 @@ func (this *StockManagerApiController) GetStockDrugCount() {
3788 3790
 	count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
3789 3791
 	outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
3790 3792
 	autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
3793
+
3791 3794
 	this.ServeSuccessJSON(map[string]interface{}{
3792 3795
 		"count":     count,
3793 3796
 		"outList":   outList,
@@ -3838,3 +3841,39 @@ func (this *StockManagerApiController) GetSingleOutOrderDetail() {
3838 3841
 		"goodType":         goodType,
3839 3842
 	})
3840 3843
 }
3844
+
3845
+func (this *StockManagerApiController) GetExprotStockList() {
3846
+
3847
+	id, _ := this.GetInt64("id")
3848
+	adminUserInfo := this.GetAdminUserInfo()
3849
+	orgId := adminUserInfo.CurrentOrgId
3850
+	timeLayout := "2006-01-02"
3851
+	loc, _ := time.LoadLocation("Local")
3852
+	start_time := this.GetString("start_time")
3853
+	end_time := this.GetString("end_time")
3854
+
3855
+	var startTime int64
3856
+	if len(start_time) > 0 {
3857
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
3858
+		if err != nil {
3859
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3860
+			return
3861
+		}
3862
+		startTime = theTime.Unix()
3863
+	}
3864
+	var endTime int64
3865
+	if len(end_time) > 0 {
3866
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
3867
+		if err != nil {
3868
+			utils.ErrorLog(err.Error())
3869
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
3870
+			return
3871
+		}
3872
+		endTime = theTime.Unix()
3873
+	}
3874
+
3875
+	list, _ := service.GetExprotStockList(orgId, id, startTime, endTime)
3876
+	this.ServeSuccessJSON(map[string]interface{}{
3877
+		"list": list,
3878
+	})
3879
+}

+ 1 - 0
models/self_drug_models.go View File

@@ -606,6 +606,7 @@ type VmDrugWarehouseOutInfo struct {
606 606
 	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
607 607
 	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
608 608
 	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
609
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
609 610
 	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
610 611
 	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
611 612
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`

+ 26 - 22
models/stock_models.go View File

@@ -71,28 +71,32 @@ func (Warehousing) TableName() string {
71 71
 }
72 72
 
73 73
 type StWarehousingInfo struct {
74
-	ID               int64   `gorm:"column:id" json:"id"`
75
-	WarehousingId    int64   `gorm:"column:warehousing_id" json:"warehousing_id"`
76
-	GoodId           int64   `gorm:"column:good_id" json:"good_id"`
77
-	GoodTypeId       int64   `gorm:"column:good_type_id" json:"good_type_id"`
78
-	Number           string  `gorm:"column:number" json:"number"`
79
-	ProductDate      int64   `gorm:"column:product_date" json:"product_date"`
80
-	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date"`
81
-	WarehousingCount int64   `gorm:"column:warehousing_count" json:"warehousing_count"`
82
-	WarehousingUnit  string  `gorm:"column:warehousing_unit" json:"warehousing_unit"`
83
-	Price            float64 `gorm:"column:price" json:"price"`
84
-	TotalPrice       float64 `gorm:"column:total_price" json:"total_price"`
85
-	Dealer           int64   `gorm:"column:dealer" json:"dealer"`
86
-	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer"`
87
-	Remark           string  `gorm:"column:remark" json:"remark"`
88
-	Ctime            int64   `gorm:"column:ctime" json:"ctime"`
89
-	Mtime            int64   `gorm:"column:mtime" json:"mtime"`
90
-	Status           int64   `gorm:"column:status" json:"status"`
91
-	OrgId            int64   `gorm:"column:org_id" json:"org_id"`
92
-	IsReturn         int64   `gorm:"column:is_return" json:"is_return"`
93
-	StockCount       int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
94
-	WarehousingOrder string  `gorm:"column:warehousing_order" json:"warehousing_order"`
95
-	Type             int64   `gorm:"column:type" json:"type"`
74
+	ID                int64   `gorm:"column:id" json:"id"`
75
+	WarehousingId     int64   `gorm:"column:warehousing_id" json:"warehousing_id"`
76
+	GoodId            int64   `gorm:"column:good_id" json:"good_id"`
77
+	GoodTypeId        int64   `gorm:"column:good_type_id" json:"good_type_id"`
78
+	Number            string  `gorm:"column:number" json:"number"`
79
+	ProductDate       int64   `gorm:"column:product_date" json:"product_date"`
80
+	ExpiryDate        int64   `gorm:"column:expiry_date" json:"expiry_date"`
81
+	WarehousingCount  int64   `gorm:"column:warehousing_count" json:"warehousing_count"`
82
+	WarehousingUnit   string  `gorm:"column:warehousing_unit" json:"warehousing_unit"`
83
+	Price             float64 `gorm:"column:price" json:"price"`
84
+	TotalPrice        float64 `gorm:"column:total_price" json:"total_price"`
85
+	Dealer            int64   `gorm:"column:dealer" json:"dealer"`
86
+	Manufacturer      int64   `gorm:"column:manufacturer" json:"manufacturer"`
87
+	Remark            string  `gorm:"column:remark" json:"remark"`
88
+	Ctime             int64   `gorm:"column:ctime" json:"ctime"`
89
+	Mtime             int64   `gorm:"column:mtime" json:"mtime"`
90
+	Status            int64   `gorm:"column:status" json:"status"`
91
+	OrgId             int64   `gorm:"column:org_id" json:"org_id"`
92
+	IsReturn          int64   `gorm:"column:is_return" json:"is_return"`
93
+	StockCount        int64   `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
94
+	WarehousingOrder  string  `gorm:"column:warehousing_order" json:"warehousing_order"`
95
+	Type              int64   `gorm:"column:type" json:"type"`
96
+	GoodName          string  `json:"good_name"`
97
+	PackingUnit       string  `json:"packing_unit"`
98
+	TotalCount        int64   `json:"total_count"`
99
+	SpecificationName string  `json:"specification_name"`
96 100
 }
97 101
 
98 102
 func (StWarehousingInfo) TableName() string {

+ 34 - 10
service/gobal_config_service.go View File

@@ -511,18 +511,26 @@ func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int6
511 511
 	if endtime > 0 {
512 512
 		db = db.Where("x.ctime<=?", endtime)
513 513
 	}
514
-	if drugcategory > 0 {
515
-		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.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id =?", orgid).Where("t.drug_category = ?", drugcategory).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
516
-
517
-	} else {
518
-		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.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
514
+	if drugcategory > 0 && len(keyword) == 0 {
515
+		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.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id =?", orgid).Where("t.drug_type = ?", drugcategory).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
516
+		return
517
+	}
518
+	if drugcategory <= 0 && len(keyword) == 0 {
519
+		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.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
520
+		return
519 521
 	}
520 522
 
521
-	if len(keyword) > 0 {
522
-		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.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id=?", orgid).Where("t.drug_name like ?", likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
523
+	if len(keyword) > 0 && drugcategory == 0 {
524
+		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.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id=?", orgid).Where("t.drug_name like ?", likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
523 525
 		return
524
-	} else {
525
-		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.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
526
+	}
527
+	if len(keyword) <= 0 && drugcategory == 0 {
528
+		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.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
529
+		return
530
+	}
531
+
532
+	if len(keyword) > 0 && drugcategory > 0 {
533
+		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.total_price,x.dealer,x.remark,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,x.batch_number,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.manufacturer").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ?", orgid).Where("t.drug_type = ? or t.drug_name like ?", drugcategory, likeKey).Group("x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
526 534
 		return
527 535
 	}
528 536
 
@@ -582,7 +590,7 @@ func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64
582 590
 
583 591
 func GetBatchOrderDetail(drugid int64, orgid int64, page int64, limit int64) (drug []*models.DrugWarehouseInfo, total int64, err error) {
584 592
 	offset := (page - 1) * limit
585
-	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ?", drugid, orgid).Offset(offset).Count(&total).Find(&drug).Error
593
+	err = XTReadDB().Model(&drug).Where("drug_id = ? and org_id = ?", drugid, orgid).Count(&total).Offset(offset).Limit(limit).Find(&drug).Error
586 594
 	return drug, total, err
587 595
 }
588 596
 
@@ -603,6 +611,22 @@ func GetDrugCountList(startime int64, endtime int64, orgid int64) (info []*model
603 611
 	return info, err
604 612
 }
605 613
 
614
+func GetMinCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
615
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
616
+
617
+	if startime > 0 {
618
+		db = db.Where("x.ctime >=?", startime)
619
+	}
620
+	if endtime > 0 {
621
+		db = db.Where("c.time<=?", endtime)
622
+	}
623
+	if orgid > 0 {
624
+		db = db.Where("x.org_id = ?", orgid)
625
+	}
626
+	err = db.Select("sum(x.stock_min_number) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
627
+	return info, err
628
+}
629
+
606 630
 func GetOutDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseInfo, err error) {
607 631
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
608 632
 

+ 43 - 0
service/stock_service.go View File

@@ -2951,3 +2951,46 @@ func GetGoodInformationByGoodId(good_id int64) (models.GoodInfo, error) {
2951 2951
 	err := XTReadDB().Where("id = ? and status = 1", good_id).Find(&info).Error
2952 2952
 	return info, err
2953 2953
 }
2954
+
2955
+func GetExprotStockList(orgid int64, orderid int64, startime int64, endtime int64) (info []*models.StWarehousingInfo, err error) {
2956
+
2957
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
2958
+
2959
+	table := XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
2960
+	fmt.Println(table)
2961
+
2962
+	if orgid > 0 {
2963
+		db = db.Where("x.org_id = ?", orgid)
2964
+	}
2965
+	if orderid > 0 {
2966
+		db = db.Where("x.warehousing_id = ?", orgid)
2967
+	}
2968
+	if startime > 0 {
2969
+		db = db.Where("x.ctime>=?", startime)
2970
+	}
2971
+	if endtime > 0 {
2972
+		db = db.Where("x.ctime<=?", endtime)
2973
+	}
2974
+	err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,Sum(x.warehousing_count)as total_count,x.price,x.dealer,x.manufacturer,x.remark,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&info).Error
2975
+
2976
+	return info, err
2977
+}
2978
+
2979
+func GetDrugWarehouOrderInfo(startime int64, endtime int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
2980
+
2981
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
2982
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
2983
+	fmt.Println(table)
2984
+	if startime > 0 {
2985
+		db = db.Where("x.ctime>=?", startime)
2986
+	}
2987
+	if endtime > 0 {
2988
+		db = db.Where("x.ctime<=?", endtime)
2989
+	}
2990
+	if orgid > 0 {
2991
+		db = db.Where("x.org_id = ?", orgid)
2992
+	}
2993
+
2994
+	err = db.Select("x.drug_id,x.count,x.count_unit,t.max_unit,t.min_unit,t.min_number").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&info).Error
2995
+	return info, err
2996
+}

+ 8 - 7
service/warhouse_service.go View File

@@ -16,7 +16,7 @@ import (
16 16
 
17 17
 // 药品出库
18 18
 
19
-func DrugsDelivery(orgID int64, advice *models.DoctorAdvice) (err error) {
19
+func DrugsDelivery(orgID int64, creater int64, advice *models.DoctorAdvice) (err error) {
20 20
 	// 1.判断药品是否来自专用字典的药品库
21 21
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
22 22
 	// 3.创建出库流程
@@ -45,7 +45,7 @@ func DrugsDelivery(orgID int64, advice *models.DoctorAdvice) (err error) {
45 45
 				WarehouseOutOrderNumber: warehousing_out_order,
46 46
 				OperationTime:           time.Now().Unix(),
47 47
 				OrgId:                   orgID,
48
-				Creater:                 0,
48
+				Creater:                 creater,
49 49
 				Ctime:                   time.Now().Unix(),
50 50
 				Status:                  1,
51 51
 				WarehouseOutTime:        record_time,
@@ -258,7 +258,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
258 258
 
259 259
 // 药品出库
260 260
 
261
-func HisDrugsDelivery(orgID int64, advice *models.HisDoctorAdviceInfo) (err error) {
261
+func HisDrugsDelivery(orgID int64, creater int64, advice *models.HisDoctorAdviceInfo) (err error) {
262 262
 	// 1.判断药品是否来自专用字典的药品库
263 263
 	// 2.判断当天当前机构有没有创建出库单,没有则创建
264 264
 	// 3.创建出库流程
@@ -284,7 +284,7 @@ func HisDrugsDelivery(orgID int64, advice *models.HisDoctorAdviceInfo) (err erro
284 284
 				WarehouseOutOrderNumber: warehousing_out_order,
285 285
 				OperationTime:           time.Now().Unix(),
286 286
 				OrgId:                   orgID,
287
-				Creater:                 0,
287
+				Creater:                 creater,
288 288
 				Ctime:                   time.Now().Unix(),
289 289
 				Status:                  1,
290 290
 				WarehouseOutTime:        record_time,
@@ -350,7 +350,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
350 350
 	// 将该批次的剩余库存数量转换为拆零数量
351 351
 
352 352
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
353
-
353
+	fmt.Println("拆零数量2222222222222222222", stock_number)
354
+	fmt.Println("出库数量55555555555555555555", deliver_number)
354 355
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
355 356
 	if stock_number >= deliver_number {
356 357
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
@@ -369,7 +370,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
369 370
 		}
370 371
 
371 372
 		warehouseOutInfo.Count = deliver_number
372
-		warehouseOutInfo.CountUnit = drup.MinUnit
373
+		warehouseOutInfo.CountUnit = advice.PrescribingNumberUnit
373 374
 
374 375
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
375 376
 
@@ -388,7 +389,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
388 389
 				OrgId:                   orgID,
389 390
 				DrugId:                  advice.DrugId,
390 391
 				Count:                   deliver_number,
391
-				CountUnit:               drup.MinUnit,
392
+				CountUnit:               advice.PrescribingNumberUnit,
392 393
 			}
393 394
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
394 395
 			if errTwo != nil {