Browse Source

Merge branch 'master' of http://git.shengws.com/csx/gdyb

csx 3 years ago
parent
commit
547003e64b
2 changed files with 289 additions and 407 deletions
  1. 284 407
      controllers/zh/zh_his_api_controller.go
  2. 5 0
      service/zh_his_service.go

+ 284 - 407
controllers/zh/zh_his_api_controller.go View File

@@ -245,9 +245,13 @@ func ZHHisManagerApiRegistRouters() {
245 245
 	beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
246 246
 	beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
247 247
 	beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
248
+	beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
249
+
248 250
 	beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
249 251
 	beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
250 252
 	beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
253
+	beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
254
+
251 255
 }
252 256
 
253 257
 func (c *ZHHisApiController) GetZHInHospitalCheck() {
@@ -597,10 +601,11 @@ func (this *ZHHisApiController) GetZHOutHospitalCheck() {
597 601
 	}
598 602
 
599 603
 }
600
-func (c *ZHHisApiController) GetUploadInfo() {
601
-	id, _ := c.GetInt64("id")
602
-	record_time := c.GetString("record_time")
604
+func (c *ZHHisApiController) GetSettleInfo() {
605
+	order_id, _ := c.GetInt64("order_id")
606
+	patient_id, _ := c.GetInt64("patient_id")
603 607
 	in_hospital_id, _ := c.GetInt64("in_hospital_id")
608
+	admin_user_id, _ := c.GetInt64("admin_user_id")
604 609
 	pay_way, _ := c.GetInt64("pay_way")
605 610
 	pay_price, _ := c.GetFloat("pay_price")
606 611
 	pay_card_no := c.GetString("pay_card_no")
@@ -610,12 +615,180 @@ func (c *ZHHisApiController) GetUploadInfo() {
610 615
 	found_price, _ := c.GetFloat("found_price")
611 616
 	medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
612 617
 	private_price, _ := c.GetFloat("private_price")
613
-	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
614
-	admin_user_id, _ := c.GetInt64("admin_user_id")
615
-
616 618
 	fapiao_code := c.GetString("fapiao_code")
617 619
 	fapiao_number := c.GetString("fapiao_number")
618 620
 
621
+	order, _ := service.GetHisOrderByID(order_id)
622
+	record, _ := service.GetInHospitalRecord(in_hospital_id)
623
+
624
+	miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
625
+
626
+	allTotal := fmt.Sprintf("%.2f", order.MedfeeSumamt)
627
+	roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
628
+
629
+	var rf []*ResultFive
630
+	json.Unmarshal([]byte(record.Iinfo), &rf)
631
+	chrg_bchno := order.Number
632
+	cert_no := record.Certno
633
+
634
+	var insutypes []string
635
+
636
+	var insutype string
637
+	var is390 int = 0
638
+	var is310 int = 0
639
+
640
+	for _, item := range rf {
641
+		if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
642
+			insutypes = append(insutypes, item.Insutype)
643
+		}
644
+	}
645
+
646
+	if len(insutypes) == 1 {
647
+		insutype = insutypes[0]
648
+	} else {
649
+		for _, i := range insutypes {
650
+			if i == "390" {
651
+				is390 = 1
652
+			}
653
+
654
+			if i == "310" {
655
+				is310 = 1
656
+			}
657
+		}
658
+	}
659
+	if is390 == 1 {
660
+		insutype = "390"
661
+	}
662
+
663
+	if is310 == 1 {
664
+		insutype = "310"
665
+	}
666
+
667
+	if len(insutypes) == 0 {
668
+		insutype = "310"
669
+	}
670
+
671
+	if record.IdCardType == 1 {
672
+
673
+	} else {
674
+
675
+		cert_no = record.Certno
676
+
677
+	}
678
+
679
+	result, src_resquest := service.ZHGdyb2304(record.PsnNo, record.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(record.MedType, 10), record.IdCardType, 0, 0, 0, 0, record.Certificates)
680
+	var dat map[string]interface{}
681
+	if err := json.Unmarshal([]byte(result), &dat); err == nil {
682
+		fmt.Println(dat)
683
+	} else {
684
+		fmt.Println(err)
685
+	}
686
+
687
+	userJSONBytes, _ := json.Marshal(dat)
688
+
689
+	var res ResultSeven
690
+	if err := json.Unmarshal(userJSONBytes, &res); err != nil {
691
+		utils.ErrorLog("解析失败:%v", err)
692
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
693
+		return
694
+	}
695
+
696
+	if res.Infcode == -1 {
697
+		errlog := &models.HisOrderError{
698
+			UserOrgId:  c.GetAdminUserInfo().CurrentOrgId,
699
+			Ctime:      time.Now().Unix(),
700
+			Mtime:      time.Now().Unix(),
701
+			Number:     chrg_bchno,
702
+			ErrMsg:     res.ErrMsg,
703
+			Status:     1,
704
+			PatientId:  patient_id,
705
+			RecordTime: time.Now().Unix(),
706
+			Stage:      6,
707
+		}
708
+		service.CreateErrMsgLog(errlog)
709
+		c.ServeSuccessJSON(map[string]interface{}{
710
+			"failed_code": -10,
711
+			"msg":         res.ErrMsg,
712
+		})
713
+		return
714
+	} else {
715
+		//order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
716
+		order.OrderStatus = 2
717
+		order.DiscountPrice = discount_price
718
+		order.MedicalInsurancePrice = medical_insurance_price
719
+		order.FaPiaoNumber = fapiao_number
720
+		order.FaPiaoCode = fapiao_code
721
+		order.PayWay = pay_way
722
+		order.PayPrice = pay_price
723
+		order.PayCardNo = pay_card_no
724
+		order.PreferentialPrice = preferential_price
725
+		order.RealityPrice = reality_price
726
+		order.FoundPrice = found_price
727
+		order.PrivatePrice = private_price
728
+		order.MdtrtId = res.Output.Setlinfo.MdtrtID
729
+		order.SetlId = res.Output.Setlinfo.SetlID
730
+		order.PsnNo = res.Output.Setlinfo.PsnNo
731
+		order.PsnName = res.Output.Setlinfo.PsnName
732
+		order.PsnCertType = res.Output.Setlinfo.PsnCertType
733
+		order.Certno = res.Output.Setlinfo.Certno
734
+		order.Gend = res.Output.Setlinfo.Gend
735
+		order.Naty = res.Output.Setlinfo.Naty
736
+		order.Age = res.Output.Setlinfo.Age
737
+		order.Insutype = res.Output.Setlinfo.Insutype
738
+		order.PsnType = res.Output.Setlinfo.PsnType
739
+		order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
740
+		order.SetlTime = res.Output.Setlinfo.SetlTime
741
+		order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
742
+		order.MedType = res.Output.Setlinfo.MedType
743
+		order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
744
+		order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
745
+		order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
746
+		order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
747
+		order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
748
+		order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
749
+		order.HifpPay = res.Output.Setlinfo.HifpPay
750
+		order.CvlservPay = res.Output.Setlinfo.CvlservPay
751
+		order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
752
+		order.HifesPay = res.Output.Setlinfo.HifesPay
753
+		order.HifobPay = res.Output.Setlinfo.HifobPay
754
+		order.MafPay = res.Output.Setlinfo.MafPay
755
+		order.OthPay = res.Output.Setlinfo.OthPay
756
+		order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
757
+		order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
758
+		order.AcctPay = res.Output.Setlinfo.AcctPay
759
+		order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
760
+		order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
761
+		order.Balc = res.Output.Setlinfo.Balc
762
+		order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
763
+		order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
764
+		order.ClrOptins = res.Output.Setlinfo.ClrOptins
765
+		order.ClrWay = res.Output.Setlinfo.ClrWay
766
+		order.Creator = order.Creator
767
+		order.Modify = roles.AdminUserId
768
+		order.RequestLog = src_resquest
769
+		setlDetail, _ := json.Marshal(res.Output.Setldetail)
770
+		detailStr := string(setlDetail)
771
+		order.SetlDetail = detailStr
772
+		err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
773
+		err = service.UpDateOrder(order)
774
+		if err == nil {
775
+			c.ServeSuccessJSON(map[string]interface{}{
776
+				"msg": "结算成功",
777
+			})
778
+		} else {
779
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
780
+			return
781
+		}
782
+	}
783
+
784
+}
785
+func (c *ZHHisApiController) GetUploadInfo() {
786
+	id, _ := c.GetInt64("id")
787
+	record_time := c.GetString("record_time")
788
+	in_hospital_id, _ := c.GetInt64("in_hospital_id")
789
+	settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
790
+	admin_user_id, _ := c.GetInt64("admin_user_id")
791
+
619 792
 	timeLayout := "2006-01-02"
620 793
 	loc, _ := time.LoadLocation("Local")
621 794
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
@@ -731,40 +904,55 @@ func (c *ZHHisApiController) GetUploadInfo() {
731 904
 			return
732 905
 		}
733 906
 
907
+		var total float64
908
+		for _, item := range prescriptions {
909
+			if item.Type == 1 { //药品
910
+				for _, subItem := range item.HisDoctorAdviceInfo {
911
+					total = total + (subItem.Price * subItem.PrescribingNumber)
912
+				}
913
+			}
914
+			if item.Type == 2 { //项目
915
+				for _, subItem := range item.HisPrescriptionProject {
916
+					total = total + (subItem.Price * float64(subItem.Count))
917
+				}
918
+			}
919
+		}
920
+
921
+		for _, item := range prescriptions {
922
+			for _, subItem := range item.HisAdditionalCharge {
923
+				total = total + (subItem.Price * float64(subItem.Count))
924
+			}
925
+		}
926
+
927
+		allTotal := fmt.Sprintf("%.2f", total)
928
+
929
+		totals, _ := strconv.ParseFloat(allTotal, 64)
734 930
 		if res.Infcode == 0 {
735 931
 			order := &models.HisOrder{
736
-				UserOrgId:             adminUser.CurrentOrgId,
737
-				HisPatientId:          record.ID,
738
-				PatientId:             record.PatientId,
739
-				SettleAccountsDate:    recordDateTime,
740
-				Ctime:                 time.Now().Unix(),
741
-				Mtime:                 time.Now().Unix(),
742
-				Status:                1,
743
-				Number:                chrg_bchno,
744
-				Infcode:               res.Infcode,
745
-				WarnMsg:               res.WarnMsg,
746
-				Cainfo:                res.Cainfo,
747
-				ErrMsg:                res.ErrMsg,
748
-				RespondTime:           res.RefmsgTime,
749
-				InfRefmsgid:           res.InfRefmsgid,
750
-				OrderStatus:           1,
751
-				PayWay:                pay_way,
752
-				PayPrice:              pay_price,
753
-				PayCardNo:             pay_card_no,
754
-				DiscountPrice:         discount_price,
755
-				PreferentialPrice:     preferential_price,
756
-				RealityPrice:          reality_price,
757
-				FoundPrice:            found_price,
758
-				MedicalInsurancePrice: medical_insurance_price,
759
-				PrivatePrice:          private_price,
760
-				IsMedicineInsurance:   1,
761
-				SettleType:            settle_accounts_type,
762
-				SettleStartTime:       start_time,
763
-				SettleEndTime:         end_time,
764
-				Creator:               roles.AdminUserId,
765
-				Modify:                roles.AdminUserId,
766
-				FaPiaoNumber:          fapiao_number,
767
-				FaPiaoCode:            fapiao_code,
932
+				UserOrgId:          adminUser.CurrentOrgId,
933
+				HisPatientId:       record.ID,
934
+				PatientId:          record.PatientId,
935
+				SettleAccountsDate: recordDateTime,
936
+				Ctime:              time.Now().Unix(),
937
+				Mtime:              time.Now().Unix(),
938
+				Status:             1,
939
+				Number:             chrg_bchno,
940
+				Infcode:            res.Infcode,
941
+				WarnMsg:            res.WarnMsg,
942
+				Cainfo:             res.Cainfo,
943
+				ErrMsg:             res.ErrMsg,
944
+				RespondTime:        res.RefmsgTime,
945
+				InfRefmsgid:        res.InfRefmsgid,
946
+				OrderStatus:        1,
947
+
948
+				IsMedicineInsurance: 1,
949
+				SettleType:          settle_accounts_type,
950
+				SettleStartTime:     start_time,
951
+				SettleEndTime:       end_time,
952
+				Creator:             roles.AdminUserId,
953
+				Modify:              roles.AdminUserId,
954
+
955
+				MedfeeSumamt: totals,
768 956
 			}
769 957
 			err = service.CreateOrder(order)
770 958
 			if err != nil {
@@ -788,7 +976,6 @@ func (c *ZHHisApiController) GetUploadInfo() {
788 976
 					advice_id = 0
789 977
 					project_id = id
790 978
 				}
791
-
792 979
 				info := &models.HisOrderInfo{
793 980
 					OrderNumber:      order.Number,
794 981
 					FeedetlSn:        item.FeedetlSn,
@@ -823,193 +1010,12 @@ func (c *ZHHisApiController) GetUploadInfo() {
823 1010
 					Type:             types,
824 1011
 				}
825 1012
 				service.CreateOrderInfo(info)
826
-
827 1013
 			}
828 1014
 			service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
829 1015
 			service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
830
-
831
-			var total float64
832
-			for _, item := range prescriptions {
833
-				if item.Type == 1 { //药品
834
-					for _, subItem := range item.HisDoctorAdviceInfo {
835
-						total = total + (subItem.Price * subItem.PrescribingNumber)
836
-					}
837
-				}
838
-				if item.Type == 2 { //项目
839
-					for _, subItem := range item.HisPrescriptionProject {
840
-						total = total + (subItem.Price * float64(subItem.Count))
841
-					}
842
-				}
843
-			}
844
-
845
-			for _, item := range prescriptions {
846
-				for _, subItem := range item.HisAdditionalCharge {
847
-					total = total + (subItem.Price * float64(subItem.Count))
848
-				}
849
-			}
850
-
851
-			allTotal := fmt.Sprintf("%.2f", total)
852
-			if res.Infcode == 0 {
853
-				var rf []*ResultFive
854
-				json.Unmarshal([]byte(record.Iinfo), &rf)
855
-				chrg_bchno := chrg_bchno
856
-				cert_no := record.Certno
857
-
858
-				var insutypes []string
859
-
860
-				var insutype string
861
-				var is390 int = 0
862
-				var is310 int = 0
863
-
864
-				for _, item := range rf {
865
-					if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
866
-						insutypes = append(insutypes, item.Insutype)
867
-					}
868
-				}
869
-
870
-				if len(insutypes) == 1 {
871
-					insutype = insutypes[0]
872
-				} else {
873
-					for _, i := range insutypes {
874
-						if i == "390" {
875
-							is390 = 1
876
-						}
877
-
878
-						if i == "310" {
879
-							is310 = 1
880
-						}
881
-					}
882
-				}
883
-				if is390 == 1 {
884
-					insutype = "390"
885
-				}
886
-
887
-				if is310 == 1 {
888
-					insutype = "310"
889
-				}
890
-
891
-				if len(insutypes) == 0 {
892
-					insutype = "310"
893
-				}
894
-
895
-				if record.IdCardType == 1 {
896
-
897
-				} else {
898
-
899
-					cert_no = record.Certno
900
-
901
-				}
902
-
903
-				result, src_resquest := service.ZHGdyb2304(record.PsnNo, record.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10), record.IdCardType, 0, 0, 0, 0, record.Certificates)
904
-				var dat map[string]interface{}
905
-				if err := json.Unmarshal([]byte(result), &dat); err == nil {
906
-					fmt.Println(dat)
907
-				} else {
908
-					fmt.Println(err)
909
-				}
910
-
911
-				userJSONBytes, _ := json.Marshal(dat)
912
-
913
-				var res ResultSeven
914
-				if err := json.Unmarshal(userJSONBytes, &res); err != nil {
915
-					utils.ErrorLog("解析失败:%v", err)
916
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
917
-					return
918
-				}
919
-
920
-				if res.Infcode == -1 {
921
-					errlog := &models.HisOrderError{
922
-						UserOrgId:  adminUser.CurrentOrgId,
923
-						Ctime:      time.Now().Unix(),
924
-						Mtime:      time.Now().Unix(),
925
-						Number:     chrg_bchno,
926
-						ErrMsg:     res.ErrMsg,
927
-						Status:     1,
928
-						PatientId:  id,
929
-						RecordTime: recordDateTime,
930
-						Stage:      6,
931
-					}
932
-					service.CreateErrMsgLog(errlog)
933
-					c.ServeSuccessJSON(map[string]interface{}{
934
-						"failed_code": -10,
935
-						"msg":         res.ErrMsg,
936
-					})
937
-					return
938
-				} else {
939
-					order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
940
-					order.OrderStatus = 2
941
-					order.MdtrtId = res.Output.Setlinfo.MdtrtID
942
-					order.SetlId = res.Output.Setlinfo.SetlID
943
-					order.PsnNo = res.Output.Setlinfo.PsnNo
944
-					order.PsnName = res.Output.Setlinfo.PsnName
945
-					order.PsnCertType = res.Output.Setlinfo.PsnCertType
946
-					order.Certno = res.Output.Setlinfo.Certno
947
-					order.Gend = res.Output.Setlinfo.Gend
948
-					order.Naty = res.Output.Setlinfo.Naty
949
-					order.Age = res.Output.Setlinfo.Age
950
-					order.Insutype = res.Output.Setlinfo.Insutype
951
-					order.PsnType = res.Output.Setlinfo.PsnType
952
-					order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
953
-					order.SetlTime = res.Output.Setlinfo.SetlTime
954
-					order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
955
-					order.MedType = res.Output.Setlinfo.MedType
956
-					order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
957
-					order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
958
-					order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
959
-					order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
960
-					order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
961
-					order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
962
-					order.HifpPay = res.Output.Setlinfo.HifpPay
963
-					order.CvlservPay = res.Output.Setlinfo.CvlservPay
964
-					order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
965
-					order.HifesPay = res.Output.Setlinfo.HifesPay
966
-					order.HifobPay = res.Output.Setlinfo.HifobPay
967
-					order.MafPay = res.Output.Setlinfo.MafPay
968
-					order.OthPay = res.Output.Setlinfo.OthPay
969
-					order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
970
-					order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
971
-					order.AcctPay = res.Output.Setlinfo.AcctPay
972
-					order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
973
-					order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
974
-					order.Balc = res.Output.Setlinfo.Balc
975
-					order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
976
-					order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
977
-					order.ClrOptins = res.Output.Setlinfo.ClrOptins
978
-					order.ClrWay = res.Output.Setlinfo.ClrWay
979
-					order.Creator = order.Creator
980
-					order.Modify = roles.AdminUserId
981
-					order.RequestLog = src_resquest
982
-					setlDetail, _ := json.Marshal(res.Output.Setldetail)
983
-					detailStr := string(setlDetail)
984
-					order.SetlDetail = detailStr
985
-					err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
986
-					err = service.UpDateOrder(order)
987
-					if err == nil {
988
-						c.ServeSuccessJSON(map[string]interface{}{
989
-							"msg": "结算成功",
990
-						})
991
-					} else {
992
-						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
993
-						return
994
-					}
995
-				}
996
-			} else {
997
-				adminUser := c.GetAdminUserInfo()
998
-				errlog := &models.HisOrderError{
999
-					UserOrgId:  adminUser.CurrentOrgId,
1000
-					Ctime:      time.Now().Unix(),
1001
-					Mtime:      time.Now().Unix(),
1002
-					ErrMsg:     res.ErrMsg,
1003
-					Status:     1,
1004
-					PatientId:  id,
1005
-					RecordTime: recordDateTime,
1006
-					Stage:      4,
1007
-				}
1008
-				service.CreateErrMsgLog(errlog)
1009
-
1010
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
1011
-				return
1012
-			}
1016
+			c.ServeSuccessJSON(map[string]interface{}{
1017
+				"msg": "上传费用明细成功",
1018
+			})
1013 1019
 		} else {
1014 1020
 			adminUser := c.GetAdminUserInfo()
1015 1021
 			errlog := &models.HisOrderError{
@@ -1028,174 +1034,68 @@ func (c *ZHHisApiController) GetUploadInfo() {
1028 1034
 				"msg":         res.ErrMsg,
1029 1035
 			})
1030 1036
 			return
1031
-			//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
1032
-			//return
1033 1037
 		}
1038
+	}
1039
+}
1040
+func (c *ZHHisApiController) ZHRefund() {
1041
+	order_id, _ := c.GetInt64("order_id")
1042
+	admin_user_id, _ := c.GetInt64("admin_user_id")
1043
+	adminUser := c.GetAdminUserInfo()
1044
+	var order models.HisOrder
1045
+	order, _ = service.GetHisOrderByID(order_id)
1046
+	roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
1047
+	miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
1048
+	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
1049
+	if config.IsOpen == 1 { //对接了医保,走医保流程
1034 1050
 
1035
-	} else {
1036
-		var total float64
1037
-		for _, item := range prescriptions {
1038
-			if item.Type == 1 { //药品
1039
-				for _, subItem := range item.HisDoctorAdviceInfo {
1040
-					total = total + (subItem.Price * subItem.PrescribingNumber)
1041
-				}
1042
-			}
1043
-			if item.Type == 2 { //项目
1044
-				for _, subItem := range item.HisPrescriptionProject {
1045
-					total = total + (subItem.Price * float64(subItem.Count))
1046
-				}
1047
-			}
1051
+		result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
1048 1052
 
1049
-			for _, subItem := range item.HisAdditionalCharge {
1050
-				total = total + (subItem.Price * float64(subItem.Count))
1051
-			}
1053
+		var dat map[string]interface{}
1054
+		if err := json.Unmarshal([]byte(result), &dat); err == nil {
1055
+			fmt.Println(dat)
1056
+		} else {
1057
+			fmt.Println(err)
1052 1058
 		}
1053 1059
 
1054
-		allTotal := fmt.Sprintf("%.2f", total)
1055
-		totals, _ := strconv.ParseFloat(allTotal, 64)
1056
-		order := &models.HisOrder{
1057
-			UserOrgId:             adminUser.CurrentOrgId,
1058
-			HisPatientId:          record.ID,
1059
-			PatientId:             id,
1060
-			SettleAccountsDate:    recordDateTime,
1061
-			Ctime:                 time.Now().Unix(),
1062
-			Mtime:                 time.Now().Unix(),
1063
-			Status:                1,
1064
-			OrderStatus:           2,
1065
-			Number:                chrg_bchno,
1066
-			MedfeeSumamt:          totals,
1067
-			PayWay:                pay_way,
1068
-			PayPrice:              pay_price,
1069
-			PayCardNo:             pay_card_no,
1070
-			DiscountPrice:         discount_price,
1071
-			PreferentialPrice:     preferential_price,
1072
-			RealityPrice:          reality_price,
1073
-			FoundPrice:            found_price,
1074
-			MedicalInsurancePrice: medical_insurance_price,
1075
-			PrivatePrice:          private_price,
1076
-		}
1077
-		err = service.CreateOrder(order)
1078
-		if err != nil {
1079
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
1060
+		userJSONBytes, _ := json.Marshal(dat)
1061
+
1062
+		var res ResultSixteen
1063
+		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1064
+			utils.ErrorLog("解析失败:%v", err)
1065
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1080 1066
 			return
1081 1067
 		}
1082
-
1083
-		var customs []*Custom
1084
-		for _, item := range prescriptions {
1085
-
1086
-			if item.Type == 1 { //药品
1087
-				for _, subItem := range item.HisDoctorAdviceInfo {
1088
-					cus := &Custom{
1089
-						AdviceId:         subItem.ID,
1090
-						ProjectId:        0,
1091
-						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
1092
-						Cut:              fmt.Sprintf("%.2f", subItem.PrescribingNumber),
1093
-						FeedetlSn:        subItem.FeedetlSn,
1094
-						Price:            fmt.Sprintf("%.2f", subItem.Price),
1095
-						MedListCodg:      subItem.MedListCodg,
1096
-						Type:             1,
1097
-					}
1098
-					customs = append(customs, cus)
1099
-				}
1100
-			}
1101
-
1102
-			if item.Type == 2 { //项目
1103
-				for _, subItem := range item.HisPrescriptionProject {
1104
-
1105
-					cus := &Custom{
1106
-						AdviceId:         0,
1107
-						ProjectId:        subItem.ID,
1108
-						DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
1109
-						Cut:              fmt.Sprintf("%.2f", float64(subItem.Count)),
1110
-						FeedetlSn:        subItem.FeedetlSn,
1111
-						Price:            fmt.Sprintf("%.2f", float64(subItem.Price)),
1112
-						MedListCodg:      subItem.MedListCodg,
1113
-						Type:             2,
1114
-					}
1115
-
1116
-					customs = append(customs, cus)
1117
-				}
1118
-			}
1119
-
1120
-			for _, item := range item.HisAdditionalCharge {
1121
-				cus := &Custom{
1122
-					ItemId:           item.ID,
1123
-					AdviceId:         0,
1124
-					ProjectId:        0,
1125
-					DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
1126
-					Cut:              fmt.Sprintf("%.2f", float64(item.Count)),
1127
-					FeedetlSn:        item.FeedetlSn,
1128
-					Price:            fmt.Sprintf("%.2f", float64(item.Price)),
1129
-					MedListCodg:      item.XtHisAddtionConfig.Code,
1130
-					Type:             3,
1131
-				}
1132
-
1133
-				customs = append(customs, cus)
1068
+		if res.Infcode == 0 {
1069
+			err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
1070
+			if err == nil {
1071
+				c.ServeSuccessJSON(map[string]interface{}{
1072
+					"msg": "退费成功",
1073
+				})
1074
+			} else {
1075
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1076
+				return
1134 1077
 			}
1135
-
1078
+		} else {
1079
+			c.ServeSuccessJSON(map[string]interface{}{
1080
+				"code": -10,
1081
+				"msg":  res.ErrMsg,
1082
+			})
1136 1083
 		}
1137 1084
 
1138
-		for _, item := range customs {
1139
-			var advice_id int64 = 0
1140
-			var project_id int64 = 0
1141
-			var item_id int64 = 0
1142
-
1143
-			var types int64 = 0
1144
-
1145
-			if item.Type == 1 {
1146
-				advice_id = item.AdviceId
1147
-				project_id = 0
1148
-				item_id = 0
1149
-			} else if item.Type == 2 {
1150
-				advice_id = 0
1151
-				item_id = 0
1152
-
1153
-				project_id = item.ProjectId
1154
-			} else if item.Type == 3 {
1155
-				advice_id = 0
1156
-				item_id = item.ItemId
1157
-				project_id = 0
1158
-			}
1159
-
1160
-			detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
1161
-			cut, _ := strconv.ParseFloat(item.Cut, 32)
1162
-			pric, _ := strconv.ParseFloat(item.Price, 32)
1163
-
1164
-			info := &models.HisOrderInfo{
1165
-				OrderNumber:      order.Number,
1166
-				UploadDate:       time.Now().Unix(),
1167
-				AdviceId:         advice_id,
1168
-				DetItemFeeSumamt: detItemFeeSumamt,
1169
-				Cnt:              cut,
1170
-				Pric:             pric,
1171
-				PatientId:        id,
1172
-				Status:           1,
1173
-				Mtime:            time.Now().Unix(),
1174
-				Ctime:            time.Now().Unix(),
1175
-				UserOrgId:        adminUser.CurrentOrgId,
1176
-				HisPatientId:     record.ID,
1177
-				OrderId:          order.ID,
1178
-				ProjectId:        project_id,
1179
-				Type:             types,
1180
-				ItemId:           item_id,
1181
-			}
1182
-			service.CreateOrderInfo(info)
1183
-		}
1184
-		//err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
1185
-		err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
1186
-		err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
1187
-		err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
1085
+	} else {
1086
+		err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
1188 1087
 		if err == nil {
1189 1088
 			c.ServeSuccessJSON(map[string]interface{}{
1190
-				"msg": "结算成功",
1089
+				"msg": "退费成功",
1191 1090
 			})
1192 1091
 		} else {
1193
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
1092
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1194 1093
 			return
1195 1094
 		}
1196 1095
 	}
1096
+
1197 1097
 }
1198
-func (c *ZHHisApiController) ZHRefund() {
1098
+func (c *ZHHisApiController) ZHRefundDetail() {
1199 1099
 	order_id, _ := c.GetInt64("order_id")
1200 1100
 	admin_user_id, _ := c.GetInt64("admin_user_id")
1201 1101
 	adminUser := c.GetAdminUserInfo()
@@ -1206,8 +1106,7 @@ func (c *ZHHisApiController) ZHRefund() {
1206 1106
 	config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
1207 1107
 	if config.IsOpen == 1 { //对接了医保,走医保流程
1208 1108
 
1209
-		result, src_resquest := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
1210
-
1109
+		result := service.Gdyb2302(order.PsnNo, order.MdtrtId, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
1211 1110
 		var dat map[string]interface{}
1212 1111
 		if err := json.Unmarshal([]byte(result), &dat); err == nil {
1213 1112
 			fmt.Println(dat)
@@ -1217,49 +1116,26 @@ func (c *ZHHisApiController) ZHRefund() {
1217 1116
 
1218 1117
 		userJSONBytes, _ := json.Marshal(dat)
1219 1118
 
1220
-		var res ResultSixteen
1221
-		if err := json.Unmarshal(userJSONBytes, &res); err != nil {
1119
+		var res2 ResultEmpty
1120
+		if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
1222 1121
 			utils.ErrorLog("解析失败:%v", err)
1223 1122
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1224 1123
 			return
1225 1124
 		}
1226
-		if res.Infcode == 0 {
1227
-			result := service.Gdyb2302(order.PsnNo, order.MdtrtId, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
1228
-			var dat map[string]interface{}
1229
-			if err := json.Unmarshal([]byte(result), &dat); err == nil {
1230
-				fmt.Println(dat)
1125
+		if res2.Infcode == 0 {
1126
+			err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", result)
1127
+			if err == nil {
1128
+				c.ServeSuccessJSON(map[string]interface{}{
1129
+					"msg": "退费成功",
1130
+				})
1231 1131
 			} else {
1232
-				fmt.Println(err)
1233
-			}
1234
-
1235
-			userJSONBytes, _ := json.Marshal(dat)
1236
-
1237
-			var res2 ResultEmpty
1238
-			if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
1239
-				utils.ErrorLog("解析失败:%v", err)
1240 1132
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1241 1133
 				return
1242 1134
 			}
1243
-			if res2.Infcode == 0 {
1244
-				err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
1245
-				if err == nil {
1246
-					c.ServeSuccessJSON(map[string]interface{}{
1247
-						"msg": "退费成功",
1248
-					})
1249
-				} else {
1250
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1251
-					return
1252
-				}
1253
-			} else {
1254
-				c.ServeSuccessJSON(map[string]interface{}{
1255
-					"code": -10,
1256
-					"msg":  res2.ErrMsg,
1257
-				})
1258
-			}
1259 1135
 		} else {
1260 1136
 			c.ServeSuccessJSON(map[string]interface{}{
1261 1137
 				"code": -10,
1262
-				"msg":  res.ErrMsg,
1138
+				"msg":  res2.ErrMsg,
1263 1139
 			})
1264 1140
 		}
1265 1141
 	} else {
@@ -1275,6 +1151,7 @@ func (c *ZHHisApiController) ZHRefund() {
1275 1151
 	}
1276 1152
 
1277 1153
 }
1154
+
1278 1155
 func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
1279 1156
 	id, _ := this.GetInt64("id")
1280 1157
 	admin_user_id, _ := this.GetInt64("admin_user_id")

+ 5 - 0
service/zh_his_service.go View File

@@ -926,6 +926,11 @@ func GetInHospitalRecord(id int64) (record models.HisHospitalCheckRecord, err er
926 926
 	return
927 927
 }
928 928
 
929
+func GetInHospitalRecordByNumber(number string) (record models.HisHospitalCheckRecord, err error) {
930
+	err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("number = ? AND status = 1", number).First(&record).Error
931
+	return
932
+}
933
+
929 934
 func GetLastHospitalRecord(id int64, user_org_id int64) (record models.HisHospitalCheckRecord, err error) {
930 935
 	err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("id = ? AND status = 1 AND user_org_id = ?", id, user_org_id).Last(&record).Error
931 936
 	return