陈少旭 4 months ago
parent
commit
b81791cf62
3 changed files with 282 additions and 116 deletions
  1. 219 61
      controllers/sg/his_api_controller.go
  2. 57 54
      models/new_stock_models.go
  3. 6 1
      service/his_service.go

+ 219 - 61
controllers/sg/his_api_controller.go View File

323
 			struct3502.FixmedinsCode = miConfig.Code
323
 			struct3502.FixmedinsCode = miConfig.Code
324
 			struct3502.Opter = roles.UserName
324
 			struct3502.Opter = roles.UserName
325
 			struct3502.RxFlag = "0"
325
 			struct3502.RxFlag = "0"
326
-			struct3502.InvChgTime = time.Unix(drug.Ctime, 0).Format("2006-01-02 15:04:05")
326
+			struct3502.InvChgTime = time.Now().Format("2006-01-02")
327
 			struct3502.OrgName = miConfig.OrgName
327
 			struct3502.OrgName = miConfig.OrgName
328
 			struct3502.AccessKey = miConfig.AccessKey
328
 			struct3502.AccessKey = miConfig.AccessKey
329
 			struct3502.RequestUrl = miConfig.Url
329
 			struct3502.RequestUrl = miConfig.Url
548
 	for _, item := range drugs {
548
 	for _, item := range drugs {
549
 		if item.IsPc == 1 && item.IsBg == 1 {
549
 		if item.IsPc == 1 && item.IsBg == 1 {
550
 			var struct3507 models.Struct3507
550
 			var struct3507 models.Struct3507
551
-			struct3507.FixmedinsBchno = ""
551
+			struct3507.FixmedinsBchno =
552
 			struct3507.InvDataType = "1"
552
 			struct3507.InvDataType = "1"
553
 			struct3507.Opter = roles.UserName
553
 			struct3507.Opter = roles.UserName
554
 			struct3507.OrgName = miConfig.OrgName
554
 			struct3507.OrgName = miConfig.OrgName
615
 
615
 
616
 	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
616
 	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
617
 
617
 
618
+	var err []string
618
 	for _, item := range flows {
619
 	for _, item := range flows {
620
+		var res3 ResultSix
619
 		if item.ConsumableType == 3 { //3为自动出库 7为自动退库
621
 		if item.ConsumableType == 3 { //3为自动出库 7为自动退库
620
 			prescription := service.GetHisPrescriptionByID(item.HisDoctorAdviceInfo.PrescriptionId)
622
 			prescription := service.GetHisPrescriptionByID(item.HisDoctorAdviceInfo.PrescriptionId)
621
-			if prescription.OrderStatus == 2 { //已经结算
623
+			if prescription.OrderStatus == 2 {
624
+				//已经结算
622
 				//判断是否已经销售
625
 				//判断是否已经销售
623
 				if item.IsSale == 1 { //是否已经销售,1是   0否
626
 				if item.IsSale == 1 { //是否已经销售,1是   0否
624
 					//是否已经变更 1是  0否
627
 					//是否已经变更 1是  0否
625
 					if item.IsChange == 0 { //没变更,进行变更操作
628
 					if item.IsChange == 0 { //没变更,进行变更操作
626
-						ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
629
+						result, result2  := ChangeStock(item.Count, item, miConfig, "107", roles)
630
+						saveLog(result, result2, "3502", "自动出库,已经销售,未变更3502")
631
+						var respJSON3 map[string]interface{}
632
+						if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
633
+							utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
634
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
635
+							return
636
+						}
637
+						userJSONBytes3, _ := json.Marshal(respJSON3)
638
+						if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
639
+							utils.ErrorLog("解析失败:%v", err)
640
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
641
+							return
642
+						}
643
+						if res3.Infcode != -1{
644
+							item.IsChange = 1
645
+							item.Bchno = item.NewDrugWarehouseInfo.Bchno
646
+							service.SaveDF(item)
647
+						}else{
648
+							err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
649
+						}
627
 					}
650
 					}
628
 				} else { //没销售,
651
 				} else { //没销售,
629
-					//进行商品销售接口
630
-					SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item.HisDoctorAdviceInfo, miConfig, "", roles)
652
+					var res FJ3507Result
631
 
653
 
632
-					if item.IsChange == 0 { //没变更,进行变更操作
633
-						ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
654
+					//进行商品销售接口
655
+					result3, result4  := SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles)
656
+					saveLog(result3, result4, "3505", "自动出库,未销售进行销售行为,3505")
657
+					var respJSON3 map[string]interface{}
658
+					if err := json.Unmarshal([]byte(string(result3)), &respJSON3); err != nil {
659
+						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
660
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
661
+						return
662
+					}
663
+					userJSONBytes3, _ := json.Marshal(respJSON3)
664
+					if err := json.Unmarshal(userJSONBytes3, &res); err != nil {
665
+						utils.ErrorLog("解析失败:%v", err)
666
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
667
+						return
668
+					}
669
+					if res.Infcode != -1 {
670
+						item.IsSale = 1
671
+						item.SaleDate = time.Now().Format("2006-01-02")
672
+						err5 := service.SaveDF(item)
673
+						if err5 == nil {
674
+							if item.IsChange == 0 { //没变更,进行变更操作
675
+								result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
676
+								saveLog(result, result2, "3502", "自动出库,没销售,未变更3502")
677
+
678
+								var respJSON3 map[string]interface{}
679
+								if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
680
+									utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
681
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
682
+									return
683
+								}
684
+								userJSONBytes3, _ := json.Marshal(respJSON3)
685
+								if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
686
+									utils.ErrorLog("解析失败:%v", err)
687
+									c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
688
+									return
689
+								}
690
+								if res3.Infcode != -1 {
691
+									item.IsChange = 1
692
+									item.Bchno = item.NewDrugWarehouseInfo.Bchno
693
+									service.SaveDF(item)
694
+								} else {
695
+									err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
696
+								}
697
+							}
698
+						}
699
+					}else{
700
+						err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售失败:"+res.ErrMsg)
634
 					}
701
 					}
635
 				}
702
 				}
636
 			} else { //还没结算
703
 			} else { //还没结算
637
 				if item.IsChange == 0 { //没变更,进行变更操作
704
 				if item.IsChange == 0 { //没变更,进行变更操作
638
-					ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
705
+					result, result2  :=ChangeStock(item.Count, item, miConfig, "107", roles)
706
+					saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
639
 
707
 
708
+					var respJSON3 map[string]interface{}
709
+					if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
710
+						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
711
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
712
+						return
713
+					}
714
+					userJSONBytes3, _ := json.Marshal(respJSON3)
715
+					if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
716
+						utils.ErrorLog("解析失败:%v", err)
717
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
718
+						return
719
+					}
720
+					if res3.Infcode != -1{
721
+						item.IsChange = 1
722
+						item.Bchno = item.NewDrugWarehouseInfo.Bchno
723
+						service.SaveDF(item)
724
+					}else{
725
+						err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
726
+					}
640
 				}
727
 				}
641
 			}
728
 			}
642
 		} else if item.ConsumableType == 7 {
729
 		} else if item.ConsumableType == 7 {
648
 				if item.IsSale == 1 { //是否已经销售,1是   0否
735
 				if item.IsSale == 1 { //是否已经销售,1是   0否
649
 					//是否已经变更 1是  0否
736
 					//是否已经变更 1是  0否
650
 					if item.IsChange == 0 { //没变更,进行变更操作
737
 					if item.IsChange == 0 { //没变更,进行变更操作
651
-						ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
738
+						result, result2  :=ChangeStock(item.Count, item, miConfig, "107", roles)
739
+						saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
740
+
741
+						var respJSON3 map[string]interface{}
742
+						if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
743
+							utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
744
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
745
+							return
746
+						}
747
+						userJSONBytes3, _ := json.Marshal(respJSON3)
748
+						if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
749
+							utils.ErrorLog("解析失败:%v", err)
750
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
751
+							return
752
+						}
753
+						if res3.Infcode != -1{
754
+							item.IsChange = 1
755
+							item.Bchno = item.NewDrugWarehouseInfo.Bchno
756
+							service.SaveDF(item)
757
+						}else{
758
+							err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
759
+						}
652
 					}
760
 					}
653
 				} else { //没销售,
761
 				} else { //没销售,
654
 					//进行商品销售退货接口
762
 					//进行商品销售退货接口
655
-					CancleSaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item.HisDoctorAdviceInfo, miConfig, "")
763
+					result111, result222 := CancleSaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "",roles)
764
+					saveLog(result111,result222,"3506","销售退货")
656
 					if item.IsChange == 0 { //没变更,进行变更操作
765
 					if item.IsChange == 0 { //没变更,进行变更操作
657
-						ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
766
+						result, result2  :=ChangeStock(item.Count, item, miConfig, "107", roles)
767
+						saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
768
+
769
+						var respJSON3 map[string]interface{}
770
+						if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
771
+							utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
772
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
773
+							return
774
+						}
775
+						userJSONBytes3, _ := json.Marshal(respJSON3)
776
+						if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
777
+							utils.ErrorLog("解析失败:%v", err)
778
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
779
+							return
780
+						}
781
+						if res3.Infcode != -1{
782
+							item.IsChange = 1
783
+							item.Bchno = item.NewDrugWarehouseInfo.Bchno
784
+							service.SaveDF(item)
785
+						}else{
786
+							err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
787
+						}
658
 					}
788
 					}
659
 				}
789
 				}
660
 			} else { //还没结算
790
 			} else { //还没结算
661
 				if item.IsChange == 0 { //没变更,进行变更操作
791
 				if item.IsChange == 0 { //没变更,进行变更操作
662
-					ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
792
+					result, result2  := ChangeStock(item.Count, item, miConfig, "107", roles)
793
+					saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
794
+
795
+					var respJSON3 map[string]interface{}
796
+					if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
797
+						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
798
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
799
+						return
800
+					}
801
+					userJSONBytes3, _ := json.Marshal(respJSON3)
802
+					if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
803
+						utils.ErrorLog("解析失败:%v", err)
804
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
805
+						return
806
+					}
807
+					if res3.Infcode != -1{
808
+						item.IsChange = 1
809
+						item.Bchno = item.NewDrugWarehouseInfo.Bchno
810
+						service.SaveDF(item)
811
+					}else{
812
+						err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
813
+					}
663
 
814
 
664
 				}
815
 				}
665
 			}
816
 			}
666
 
817
 
667
 		} else { //其他方式
818
 		} else { //其他方式
668
 			if item.IsChange == 0 { //没变更,进行变更操作
819
 			if item.IsChange == 0 { //没变更,进行变更操作
669
-				ChangeStock(item.Count, item.HisDoctorAdviceInfo, miConfig, "102", roles)
820
+				result, result2  := ChangeStock(item.Count, item, miConfig, "107", roles)
821
+				saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
822
+
823
+				var respJSON3 map[string]interface{}
824
+				if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
825
+					utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
826
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
827
+					return
828
+				}
829
+				userJSONBytes3, _ := json.Marshal(respJSON3)
830
+				if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
831
+					utils.ErrorLog("解析失败:%v", err)
832
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
833
+					return
834
+				}
835
+				if res3.Infcode != -1{
836
+					item.IsChange = 1
837
+					item.Bchno = item.NewDrugWarehouseInfo.Bchno
838
+					service.SaveDF(item)
839
+				}else{
840
+					err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
841
+				}
670
 			}
842
 			}
671
 		}
843
 		}
672
 	}
844
 	}
673
 }
845
 }
674
 
846
 
675
-func ChangeStock(count int64, drug models.HisDoctorAdviceInfo, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) {
847
+func ChangeStock(count int64, drug  *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) (string,string){
676
 	var struct3502 models.Struct3502
848
 	var struct3502 models.Struct3502
677
-	struct3502.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
849
+	struct3502.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
678
 	struct3502.FixmedinsHilistId = miConfig.Code
850
 	struct3502.FixmedinsHilistId = miConfig.Code
679
 	struct3502.FixmedinsHilistName = miConfig.OrgName
851
 	struct3502.FixmedinsHilistName = miConfig.OrgName
680
 	struct3502.FixmedinsCode = miConfig.Code
852
 	struct3502.FixmedinsCode = miConfig.Code
681
 	struct3502.Opter = role.UserName
853
 	struct3502.Opter = role.UserName
682
 	struct3502.RxFlag = "0"
854
 	struct3502.RxFlag = "0"
683
-	struct3502.InvChgTime = time.Unix(drug.CreatedTime, 0).Format("2006-01-02 15:04:05")
855
+	struct3502.InvChgTime =  time.Now().Format("2006-01-02")
684
 	struct3502.OrgName = miConfig.OrgName
856
 	struct3502.OrgName = miConfig.OrgName
685
 	struct3502.AccessKey = miConfig.AccessKey
857
 	struct3502.AccessKey = miConfig.AccessKey
686
 	struct3502.RequestUrl = miConfig.Url
858
 	struct3502.RequestUrl = miConfig.Url
687
 	struct3502.SecretKey = miConfig.SecretKey
859
 	struct3502.SecretKey = miConfig.SecretKey
688
 	struct3502.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
860
 	struct3502.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
689
 	struct3502.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
861
 	struct3502.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
690
-
691
 	struct3502.Url = miConfig.Url
862
 	struct3502.Url = miConfig.Url
692
 	struct3502.AppId = miConfig.Cainfo
863
 	struct3502.AppId = miConfig.Cainfo
693
 	struct3502.AppSecret = miConfig.AppSecret
864
 	struct3502.AppSecret = miConfig.AppSecret
694
 	struct3502.Enckey = miConfig.EncKey
865
 	struct3502.Enckey = miConfig.EncKey
695
 	struct3502.SignKey = miConfig.SignKey
866
 	struct3502.SignKey = miConfig.SignKey
696
 	struct3502.SecretKey = miConfig.SecretKey
867
 	struct3502.SecretKey = miConfig.SecretKey
697
-
698
 	struct3502.InvChgType = chgType
868
 	struct3502.InvChgType = chgType
699
-	struct3502.FixmedinsBchno = ""
869
+	struct3502.FixmedinsBchno = drug.NewDrugWarehouseInfo.Bchno
700
 	struct3502.Cnt = strconv.FormatInt(count, 10)
870
 	struct3502.Cnt = strconv.FormatInt(count, 10)
701
 	struct3502.Pric = fmt.Sprintf("%.2f", drug.Price)
871
 	struct3502.Pric = fmt.Sprintf("%.2f", drug.Price)
702
-	result1, result2, result3 := service.FJyb3502(struct3502)
703
-	fmt.Println(result1)
704
-	fmt.Println(result2)
705
-	fmt.Println(result3)
706
-
872
+	result1, result2, _ := service.FJyb3502(struct3502)
873
+	return result1,result2
707
 }
874
 }
708
-func SaleStock(org_id int64, pre models.HisPrescription, drug models.HisDoctorAdviceInfo, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) {
875
+func SaleStock(org_id int64, pre models.HisPrescription, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) (string, string){
709
 	var struct3505 models.Struct3505
876
 	var struct3505 models.Struct3505
710
-	struct3505.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
877
+	struct3505.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
711
 	struct3505.FixmedinsHilistId = miConfig.Code
878
 	struct3505.FixmedinsHilistId = miConfig.Code
712
 	struct3505.FixmedinsHilistName = miConfig.OrgName
879
 	struct3505.FixmedinsHilistName = miConfig.OrgName
880
+	struct3505.FixmedinsBchno = drug.NewDrugWarehouseInfo.Bchno
881
+
713
 	struct3505.FixmedinsCode = miConfig.Code
882
 	struct3505.FixmedinsCode = miConfig.Code
714
-	struct3505.FixmedinsBchno = ""
715
 	roles, _ := service.GetAdminUserInfoByID(org_id, pre.Creator)
883
 	roles, _ := service.GetAdminUserInfoByID(org_id, pre.Creator)
716
-	struct3505.PrscDrName = roles.UserName
717
-	struct3505.PharName = ""
718
-	struct3505.PharPracCertNo = ""
884
+	struct3505.PrscDrName =roles.UserName
885
+	struct3505.PharName = "刘水山"
886
+	struct3505.PharPracCertNo = "2015026350260000002611351127"
719
 	order := service.GetHisOrderByNumber(pre.BatchNumber)
887
 	order := service.GetHisOrderByNumber(pre.BatchNumber)
720
 	struct3505.SetlId = order.SetlId
888
 	struct3505.SetlId = order.SetlId
721
 	struct3505.MdtrtSn = order.MdtrtId
889
 	struct3505.MdtrtSn = order.MdtrtId
722
-	struct3505.ManuLotnum = ""
723
-	struct3505.ManuDate = ""
890
+	struct3505.ManuLotnum = drug.Number
891
+	struct3505.ManuDate = time.Unix(drug.ProductDate, 0).Format("2006-01-02 15:04:05")
724
 	struct3505.ExpyEnd = ""
892
 	struct3505.ExpyEnd = ""
725
 	struct3505.RxFlag = "0"
893
 	struct3505.RxFlag = "0"
726
 	struct3505.TrdnFlag = "1"
894
 	struct3505.TrdnFlag = "1"
727
-
895
+	struct3505.RtalDocno = order.Number
728
 	struct3505.Url = miConfig.Url
896
 	struct3505.Url = miConfig.Url
729
 	struct3505.AppId = miConfig.Cainfo
897
 	struct3505.AppId = miConfig.Cainfo
730
 	struct3505.AppSecret = miConfig.AppSecret
898
 	struct3505.AppSecret = miConfig.AppSecret
731
 	struct3505.Enckey = miConfig.EncKey
899
 	struct3505.Enckey = miConfig.EncKey
732
 	struct3505.SignKey = miConfig.SignKey
900
 	struct3505.SignKey = miConfig.SignKey
733
 	struct3505.SecretKey = miConfig.SecretKey
901
 	struct3505.SecretKey = miConfig.SecretKey
734
-
735
-	struct3505.RtalDocno = order.Number
736
-	strValue := fmt.Sprintf("%.2f", drug.PrescribingNumber)
902
+	strValue := fmt.Sprintf("%.2f", drug.HisDoctorAdviceInfo.PrescribingNumber)
737
 	struct3505.SelRetnCnt = strValue
903
 	struct3505.SelRetnCnt = strValue
738
-	struct3505.SelRetnTime = time.Unix(drug.CreatedTime, 0).Format("2006-01-02 15:04:05")
739
-	roles_two, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
740
-
741
-	struct3505.SelRetnOpterName = roles_two.UserName
904
+	struct3505.SelRetnTime = time.Unix(drug.HisDoctorAdviceInfo.CreatedTime, 0).Format("2006-01-02 15:04:05")
905
+	struct3505.SelRetnOpterName = role.UserName
742
 	if order.IsMedicineInsurance == 1 {
906
 	if order.IsMedicineInsurance == 1 {
743
 		struct3505.MdtrtSetlType = "1"
907
 		struct3505.MdtrtSetlType = "1"
744
 	} else {
908
 	} else {
750
 	struct3505.SecretKey = miConfig.SecretKey
914
 	struct3505.SecretKey = miConfig.SecretKey
751
 	struct3505.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
915
 	struct3505.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
752
 	struct3505.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
916
 	struct3505.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
753
-	result1, result2, result3 := service.FJyb3505(struct3505)
754
-	fmt.Println(result1)
755
-	fmt.Println(result2)
756
-	fmt.Println(result3)
917
+	result1, result2, _ := service.FJyb3505(struct3505)
918
+	return result1,result2
757
 
919
 
758
 }
920
 }
759
-func CancleSaleStock(org_id int64, pre models.HisPrescription, drug models.HisDoctorAdviceInfo, miConfig models.MedicalInsuranceOrgConfig, chgType string) {
921
+func CancleSaleStock(org_id int64, pre models.HisPrescription, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string,role models.UserAdminRole)  (string,string){
760
 	var struct3506 models.Struct3506
922
 	var struct3506 models.Struct3506
761
-	struct3506.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
923
+	struct3506.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
762
 	struct3506.FixmedinsHilistId = miConfig.Code
924
 	struct3506.FixmedinsHilistId = miConfig.Code
763
 	struct3506.FixmedinsHilistName = miConfig.OrgName
925
 	struct3506.FixmedinsHilistName = miConfig.OrgName
764
 	struct3506.FixmedinsCode = miConfig.Code
926
 	struct3506.FixmedinsCode = miConfig.Code
765
-	struct3506.FixmedinsBchno = ""
927
+	struct3506.FixmedinsBchno = drug.NewDrugWarehouseInfo.Bchno
928
+	struct3506.Opter = role.UserName
766
 	order := service.GetHisOrderByNumber(pre.BatchNumber)
929
 	order := service.GetHisOrderByNumber(pre.BatchNumber)
767
-	//roles, _ := service.GetAdminUserInfoByID(org_id, pre.Creator)
768
-	struct3506.ManuLotnum = ""
769
-	struct3506.ManuDate = ""
930
+	struct3506.ManuLotnum = drug.NewDrugWarehouseInfo.Number
931
+	struct3506.ManuDate = time.Unix(drug.ProductDate, 0).Format("2006-01-02")
770
 	struct3506.MdtrtSn = order.MdtrtId
932
 	struct3506.MdtrtSn = order.MdtrtId
771
 	struct3506.ExpyEnd = ""
933
 	struct3506.ExpyEnd = ""
772
 	struct3506.RxFlag = "0"
934
 	struct3506.RxFlag = "0"
773
 	struct3506.TrdnFlag = "1"
935
 	struct3506.TrdnFlag = "1"
774
-	strValue := fmt.Sprintf("%.2f", drug.PrescribingNumber)
936
+	strValue := fmt.Sprintf("%.2f", drug.HisDoctorAdviceInfo.PrescribingNumber)
775
 	struct3506.SelRetnCnt = strValue
937
 	struct3506.SelRetnCnt = strValue
776
-	struct3506.SelRetnTime = time.Unix(drug.CreatedTime, 0).Format("2006-01-02 15:04:05")
777
-	roles_two, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
778
-	struct3506.SelRetnOpterName = roles_two.UserName
938
+	struct3506.SelRetnTime = time.Unix(drug.HisDoctorAdviceInfo.CreatedTime, 0).Format("2006-01-02 15:04:05")
939
+	//roles_two, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
940
+	struct3506.SelRetnOpterName = role.UserName
779
 	struct3506.OrgName = miConfig.OrgName
941
 	struct3506.OrgName = miConfig.OrgName
780
 	struct3506.AccessKey = miConfig.AccessKey
942
 	struct3506.AccessKey = miConfig.AccessKey
781
 	struct3506.RequestUrl = miConfig.Url
943
 	struct3506.RequestUrl = miConfig.Url
789
 	struct3506.Enckey = miConfig.EncKey
951
 	struct3506.Enckey = miConfig.EncKey
790
 	struct3506.SignKey = miConfig.SignKey
952
 	struct3506.SignKey = miConfig.SignKey
791
 	struct3506.SecretKey = miConfig.SecretKey
953
 	struct3506.SecretKey = miConfig.SecretKey
792
-
793
-	result1, result2, result3 := service.FJyb3506(struct3506)
794
-	fmt.Println(result1)
795
-	fmt.Println(result2)
796
-	fmt.Println(result3)
797
-
954
+	result1, result2, _ := service.FJyb3506(struct3506)
955
+	return result1,result2
798
 }
956
 }
799
 
957
 
800
 func (c *HisApiController) Get1318() {
958
 func (c *HisApiController) Get1318() {

+ 57 - 54
models/new_stock_models.go View File

384
 }
384
 }
385
 
385
 
386
 type DrugFlow struct {
386
 type DrugFlow struct {
387
-	ID                        int64               `gorm:"column:id" json:"id" form:"id"`
388
-	WarehousingId             int64               `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
389
-	DrugId                    int64               `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
390
-	Number                    string              `gorm:"column:number" json:"number" form:"number"`
391
-	BatchNumber               string              `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
392
-	Count                     int64               `gorm:"column:count" json:"count" form:"count"`
393
-	UserOrgId                 int64               `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
394
-	PatientId                 int64               `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
395
-	SystemTime                int64               `gorm:"column:system_time" json:"system_time" form:"system_time"`
396
-	ConsumableType            int64               `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
397
-	IsSys                     int64               `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
398
-	WarehousingOrder          string              `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
399
-	WarehouseOutId            int64               `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
400
-	WarehouseOutOrderNumber   string              `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
401
-	IsEdit                    int64               `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
402
-	CancelStockId             int64               `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
403
-	CancelOrderNumber         string              `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
404
-	Manufacturer              int64               `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
405
-	Dealer                    int64               `gorm:"column:dealer" json:"dealer" form:"dealer"`
406
-	Creator                   int64               `gorm:"column:creator" json:"creator" form:"creator"`
407
-	UpdateCreator             int64               `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
408
-	Status                    int64               `gorm:"column:status" json:"status" form:"status"`
409
-	Ctime                     int64               `gorm:"column:ctime" json:"ctime" form:"ctime"`
410
-	Mtime                     int64               `gorm:"column:mtime" json:"mtime" form:"mtime"`
411
-	Price                     float64             `gorm:"column:price" json:"price" form:"price"`
412
-	WarehousingDetailId       int64               `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
413
-	WarehouseOutDetailId      int64               `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
414
-	CancelOutDetailId         int64               `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
415
-	ExpireDate                int64               `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
416
-	ProductDate               int64               `gorm:"column:product_date" json:"product_date" form:"product_date"`
417
-	MaxUnit                   string              `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
418
-	MinUnit                   string              `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
419
-	StockMaxNumber            int64               `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
420
-	StockMinNumber            int64               `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
421
-	LastStockMaxNumber        int64               `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
422
-	LastStockMinNumber        int64               `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
423
-	AdviceId                  int64               `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
424
-	HisDoctorAdviceInfo       HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
425
-	SupplyWarehouseId         int64               `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
426
-	SupplyCancelOutId         int64               `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
427
-	SupplyWarehouseDetailInfo int64               `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
428
-	StorehouseId              int64               `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
429
-	SecondWarehouseInfoId     int64               `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
430
-	AdminUserId               int64               `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
431
-	LastPrice                 float64             `gorm:"column:last_price" json:"last_price" form:"last_price"`
432
-	StockCount                string              `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
433
-	PharmacyId                int64               `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
434
-	IsRead                    int64               `gorm:"column:is_read" json:"is_read" form:"is_read"`
435
-	IsCheck                   int64               `gorm:"column:is_check" json:"is_check" form:"is_check"`
436
-	OverCount                 int64               `gorm:"column:over_count" json:"over_count" form:"over_count"`
437
-	RetailPrice               float64             `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
438
-	OrderId                   int64               `gorm:"column:order_id" json:"order_id" form:"order_id"`
439
-	IsSale                    int64               `gorm:"column:is_sale" json:"is_sale" form:"is_sale"`
440
-	IsChange                  int64               `gorm:"column:is_change" json:"is_change" form:"is_change"`
387
+	ID                        int64                `gorm:"column:id" json:"id" form:"id"`
388
+	WarehousingId             int64                `gorm:"column:warehousing_id" json:"warehousing_id" form:"warehousing_id"`
389
+	DrugId                    int64                `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
390
+	Number                    string               `gorm:"column:number" json:"number" form:"number"`
391
+	BatchNumber               string               `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
392
+	Count                     int64                `gorm:"column:count" json:"count" form:"count"`
393
+	UserOrgId                 int64                `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
394
+	PatientId                 int64                `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
395
+	SystemTime                int64                `gorm:"column:system_time" json:"system_time" form:"system_time"`
396
+	ConsumableType            int64                `gorm:"column:consumable_type" json:"consumable_type" form:"consumable_type"`
397
+	IsSys                     int64                `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
398
+	WarehousingOrder          string               `gorm:"column:warehousing_order" json:"warehousing_order" form:"warehousing_order"`
399
+	WarehouseOutId            int64                `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
400
+	WarehouseOutOrderNumber   string               `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
401
+	IsEdit                    int64                `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
402
+	CancelStockId             int64                `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
403
+	CancelOrderNumber         string               `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
404
+	Manufacturer              int64                `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
405
+	Dealer                    int64                `gorm:"column:dealer" json:"dealer" form:"dealer"`
406
+	Creator                   int64                `gorm:"column:creator" json:"creator" form:"creator"`
407
+	UpdateCreator             int64                `gorm:"column:update_creator" json:"update_creator" form:"update_creator"`
408
+	Status                    int64                `gorm:"column:status" json:"status" form:"status"`
409
+	Ctime                     int64                `gorm:"column:ctime" json:"ctime" form:"ctime"`
410
+	Mtime                     int64                `gorm:"column:mtime" json:"mtime" form:"mtime"`
411
+	Price                     float64              `gorm:"column:price" json:"price" form:"price"`
412
+	WarehousingDetailId       int64                `gorm:"column:warehousing_detail_id" json:"warehousing_detail_id" form:"warehousing_detail_id"`
413
+	WarehouseOutDetailId      int64                `gorm:"column:warehouse_out_detail_id" json:"warehouse_out_detail_id" form:"warehouse_out_detail_id"`
414
+	CancelOutDetailId         int64                `gorm:"column:cancel_out_detail_id" json:"cancel_out_detail_id" form:"cancel_out_detail_id"`
415
+	ExpireDate                int64                `gorm:"column:expire_date" json:"expire_date" form:"expire_date"`
416
+	ProductDate               int64                `gorm:"column:product_date" json:"product_date" form:"product_date"`
417
+	MaxUnit                   string               `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
418
+	MinUnit                   string               `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
419
+	StockMaxNumber            int64                `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
420
+	StockMinNumber            int64                `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
421
+	LastStockMaxNumber        int64                `gorm:"column:last_stock_max_number" json:"last_stock_max_number" form:"last_stock_max_number"`
422
+	LastStockMinNumber        int64                `gorm:"column:last_stock_min_number" json:"last_stock_min_number" form:"last_stock_min_number"`
423
+	AdviceId                  int64                `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
424
+	HisDoctorAdviceInfo       HisDoctorAdviceInfo  `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
425
+	SupplyWarehouseId         int64                `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
426
+	SupplyCancelOutId         int64                `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
427
+	SupplyWarehouseDetailInfo int64                `gorm:"column:supply_warehouse_detail_info" json:"supply_warehouse_detail_info" form:"supply_warehouse_detail_info"`
428
+	StorehouseId              int64                `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
429
+	SecondWarehouseInfoId     int64                `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
430
+	AdminUserId               int64                `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
431
+	LastPrice                 float64              `gorm:"column:last_price" json:"last_price" form:"last_price"`
432
+	StockCount                string               `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
433
+	PharmacyId                int64                `gorm:"column:pharmacy_id" json:"pharmacy_id" form:"pharmacy_id"`
434
+	IsRead                    int64                `gorm:"column:is_read" json:"is_read" form:"is_read"`
435
+	IsCheck                   int64                `gorm:"column:is_check" json:"is_check" form:"is_check"`
436
+	OverCount                 int64                `gorm:"column:over_count" json:"over_count" form:"over_count"`
437
+	RetailPrice               float64              `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
438
+	OrderId                   int64                `gorm:"column:order_id" json:"order_id" form:"order_id"`
439
+	IsSale                    int64                `gorm:"column:is_sale" json:"is_sale" form:"is_sale"`
440
+	IsChange                  int64                `gorm:"column:is_change" json:"is_change" form:"is_change"`
441
+	NewDrugWarehouseInfo      NewDrugWarehouseInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehousingId" json:"dw"`
442
+	Bchno                     string               `gorm:"column:bchno" json:"bchno" form:"bchno"`
443
+	SaleDate                  string               `gorm:"column:sale_date" json:"sale_date" form:"sale_date"`
441
 }
444
 }
442
 
445
 
443
 func (DrugFlow) TableName() string {
446
 func (DrugFlow) TableName() string {

+ 6 - 1
service/his_service.go View File

1710
 
1710
 
1711
 func GetNewDrugFlowInfo(id_arr []string) (flows []*models.DrugFlow, err error) {
1711
 func GetNewDrugFlowInfo(id_arr []string) (flows []*models.DrugFlow, err error) {
1712
 	err = readDb.Model(&models.DrugFlow{}).Where("org_id = ? and status = 1 and id in (?)", 10191, id_arr).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1712
 	err = readDb.Model(&models.DrugFlow{}).Where("org_id = ? and status = 1 and id in (?)", 10191, id_arr).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
1713
-		return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
1713
+		return db.Where("status = 1").Preload("BaseDrugLib", "status=1").Preload("NewDrugWarehouseInfo", "status = 1")
1714
 	}).Find(&flows).Error
1714
 	}).Find(&flows).Error
1715
 	return
1715
 	return
1716
 }
1716
 }
1724
 	err = readDb.Model(&models.HisOrder{}).Where("number = ? and status = 1", number).First(&order).Error
1724
 	err = readDb.Model(&models.HisOrder{}).Where("number = ? and status = 1", number).First(&order).Error
1725
 	return
1725
 	return
1726
 }
1726
 }
1727
+
1728
+func SaveDF(df *models.DrugFlow) (err error) {
1729
+	err = writeDb.Save(&df).Error
1730
+	return
1731
+}