Browse Source

2024/6/17

28169 7 months ago
parent
commit
14fd860240

+ 1 - 1
conf/app.conf View File

@@ -1,6 +1,6 @@
1 1
 appname = 血透
2 2
 httpport = 9531
3
-runmode = prod
3
+runmode = dev
4 4
 #dev/prod
5 5
 
6 6
 #

+ 4 - 4
controllers/base_api_controller.go View File

@@ -83,7 +83,7 @@ func (this *BaseAuthAPIController) Prepare() {
83 83
 		userAdmin.ModifyTime = 1530786071
84 84
 		var subscibe models.ServeSubscibe
85 85
 		subscibe.ID = 11
86
-		subscibe.OrgId = 10633 //机构id
86
+		subscibe.OrgId = 9675 //机构id
87 87
 		subscibe.PeriodStart = 1547447814
88 88
 		subscibe.PeriodEnd = 1550039814
89 89
 		subscibe.State = 1
@@ -93,7 +93,7 @@ func (this *BaseAuthAPIController) Prepare() {
93 93
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
94 94
 		subscibes[4] = &subscibe
95 95
 		var adminUserInfo service.AdminUserInfo
96
-		adminUserInfo.CurrentOrgId = 10633 //机构id小英9675或4
96
+		adminUserInfo.CurrentOrgId = 9675  //机构id小英9675或4
97 97
 		adminUserInfo.CurrentAppId = 17876 //4
98 98
 		adminUserInfo.AdminUser = &userAdmin
99 99
 		adminUserInfo.Subscibes = subscibes
@@ -329,7 +329,7 @@ func (this *BaseServeAPIController) Prepare() {
329 329
 		userAdmin.ModifyTime = 1530786071
330 330
 		var subscibe models.ServeSubscibe
331 331
 		subscibe.ID = 11
332
-		subscibe.OrgId = 10633 //机构id小英9675或4
332
+		subscibe.OrgId = 9675 //机构id小英9675或4
333 333
 		subscibe.PeriodStart = 1538035409
334 334
 		subscibe.PeriodEnd = 1569571409
335 335
 		subscibe.State = 1
@@ -339,7 +339,7 @@ func (this *BaseServeAPIController) Prepare() {
339 339
 		subscibes := make(map[int64]*models.ServeSubscibe, 0)
340 340
 		subscibes[4] = &subscibe
341 341
 		var adminUserInfo service.AdminUserInfo
342
-		adminUserInfo.CurrentOrgId = 10633 //机构id小英9675或4
342
+		adminUserInfo.CurrentOrgId = 9675  //机构id小英9675或4
343 343
 		adminUserInfo.CurrentAppId = 17876 //4
344 344
 		adminUserInfo.AdminUser = &userAdmin
345 345
 		adminUserInfo.Subscibes = subscibes

+ 5 - 6
controllers/his_api_controller.go View File

@@ -3366,7 +3366,7 @@ func (c *HisApiController) CreateHisPrescription() {
3366 3366
 								if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
3367 3367
 									total_count += prescribingNumberSeven
3368 3368
 								}
3369
-								if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
3369
+								if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
3370 3370
 									storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
3371 3371
 									lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
3372 3372
 									if s.Price != lastWarehouse.RetailPrice {
@@ -4985,7 +4985,7 @@ func (c *HisApiController) CreateHisPrescription() {
4985 4985
 
4986 4986
 					//查询该病人的该药品是否已经入库
4987 4987
 					selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
4988
-					selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
4988
+					selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
4989 4989
 					var in_count int64
4990 4990
 					if len(selfdruginfo) > 0 {
4991 4991
 						for _, item := range selfdruginfo {
@@ -5689,7 +5689,6 @@ func (c *HisApiController) DeletePrescription() {
5689 5689
 	////同步到自备药
5690 5690
 	selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
5691 5691
 
5692
-	fmt.Println("selfPrescriptionOpen=---------------------------", selfPrescriptionOpen)
5693 5692
 	var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
5694 5693
 
5695 5694
 	if selfPrescriptionOpen.IsOpen == 1 {
@@ -5712,7 +5711,7 @@ func (c *HisApiController) DeletePrescription() {
5712 5711
 
5713 5712
 			total = total + 1
5714 5713
 			warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
5715
-			fmt.Println("warehousing_out_order--------------------------------------", warehousing_out_order)
5714
+
5716 5715
 			number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
5717 5716
 			number = number + total
5718 5717
 			warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
@@ -5740,7 +5739,7 @@ func (c *HisApiController) DeletePrescription() {
5740 5739
 			if lastWarehouseOut.ID == 0 {
5741 5740
 				service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
5742 5741
 			}
5743
-			selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId)
5742
+			selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
5744 5743
 
5745 5744
 			var total_count int64
5746 5745
 			prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
@@ -6383,7 +6382,7 @@ func (c *HisApiController) DeleteDoctorAdvice() {
6383 6382
 			}
6384 6383
 		}()
6385 6384
 
6386
-		selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
6385
+		selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
6387 6386
 
6388 6387
 		var total_count int64
6389 6388
 		prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)

+ 205 - 0
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -10672,3 +10672,208 @@ func (c *DialysisAPIController) BatchCheckAdvice() {
10672 10672
 
10673 10673
 	return
10674 10674
 }
10675
+
10676
+func (c *DialysisAPIController) GetAllMobileDrugList() {
10677
+
10678
+	org_id := c.GetMobileAdminUserInfo().Org.Id
10679
+
10680
+	drugList, _ := service.GetAllDrugList(org_id)
10681
+
10682
+	c.ServeSuccessJSON(map[string]interface{}{
10683
+		"drugList": drugList,
10684
+	})
10685
+}
10686
+
10687
+func (c *DialysisAPIController) SaveLongMobileAdvice() {
10688
+
10689
+	org_id := c.GetMobileAdminUserInfo().Org.Id
10690
+
10691
+	dataBody := make(map[string]interface{}, 0)
10692
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
10693
+	if err != nil {
10694
+		utils.ErrorLog(err.Error())
10695
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10696
+		return
10697
+	}
10698
+
10699
+	timeLayout := "2006-01-02"
10700
+	loc, _ := time.LoadLocation("Local")
10701
+
10702
+	if dataBody["advice_type"] == nil || reflect.TypeOf(dataBody["advice_type"]).String() != "float64" {
10703
+		utils.ErrorLog("advice_type")
10704
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10705
+		return
10706
+	}
10707
+	adviceType := int64(dataBody["advice_type"].(float64))
10708
+
10709
+	if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
10710
+		utils.ErrorLog("start_time")
10711
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10712
+		return
10713
+	}
10714
+
10715
+	startTime2, _ := dataBody["start_time"].(string)
10716
+	time_arr := strings.Split(startTime2, " ")
10717
+	if len(time_arr) > 0 {
10718
+		startTime2 = time_arr[0]
10719
+	}
10720
+	if dataBody["advice_date"] == nil || reflect.TypeOf(dataBody["advice_date"]).String() != "string" {
10721
+		utils.ErrorLog("advice_date")
10722
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10723
+		return
10724
+	}
10725
+	advice_date, _ := dataBody["advice_date"].(string)
10726
+
10727
+	var advicedateunix int64
10728
+	if len(advice_date) > 0 {
10729
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", advice_date+" 00:00:00", loc)
10730
+		if err != nil {
10731
+			fmt.Println(err)
10732
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10733
+			return
10734
+		}
10735
+		advicedateunix = theTime.Unix()
10736
+	}
10737
+
10738
+	adviceDate := startTime2
10739
+	if len(adviceDate) == 0 {
10740
+		utils.ErrorLog("len(adviceDate) == 0")
10741
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10742
+		return
10743
+	}
10744
+	theTime, err := time.ParseInLocation(timeLayout, adviceDate, loc)
10745
+	if err != nil {
10746
+		utils.ErrorLog(err.Error())
10747
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10748
+		return
10749
+	}
10750
+	AdviceDate := advicedateunix
10751
+	RecordDate := advicedateunix
10752
+
10753
+	if dataBody["start_time"] == nil || reflect.TypeOf(dataBody["start_time"]).String() != "string" {
10754
+		utils.ErrorLog("start_time")
10755
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10756
+		return
10757
+	}
10758
+	startTime, _ := dataBody["start_time"].(string)
10759
+
10760
+	if len(startTime) == 0 {
10761
+		utils.ErrorLog("len(start_time) == 0")
10762
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10763
+		return
10764
+	}
10765
+	theTime, err = time.ParseInLocation(timeLayout+" 15:04:05", startTime, loc)
10766
+
10767
+	if err != nil {
10768
+		utils.ErrorLog(err.Error())
10769
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
10770
+		return
10771
+	}
10772
+	StartTime := theTime.Unix()
10773
+
10774
+	advice_name, _ := dataBody["advice_name"].(string)
10775
+
10776
+	advice_desc, _ := dataBody["advice_desc"].(string)
10777
+
10778
+	delivery_way, _ := dataBody["delivery_way"].(string)
10779
+
10780
+	execution_frequency, _ := dataBody["execution_frequency"].(string)
10781
+
10782
+	frequency_type := int64(dataBody["frequency_type"].(float64))
10783
+
10784
+	frequency_week, _ := dataBody["frequency_week"].(string)
10785
+
10786
+	prescribing_number := dataBody["prescribing_number"].(float64)
10787
+
10788
+	prescribing_number_unit := dataBody["prescribing_number_unit"].(string)
10789
+
10790
+	remark := dataBody["remark"].(string)
10791
+
10792
+	single_dose := dataBody["single_dose"].(float64)
10793
+
10794
+	single_dose_unit := dataBody["single_dose_unit"].(string)
10795
+
10796
+	patient_id := int64(dataBody["patient_id"].(float64))
10797
+
10798
+	day_count := int64(dataBody["day_count"].(float64))
10799
+	advice_doctor := c.GetMobileAdminUserInfo().AdminUser.Id
10800
+
10801
+	adviceLast, _ := service.GetLastLongAdviceList(org_id)
10802
+	var template_id = ""
10803
+	adviceLastId := strconv.FormatInt(adviceLast.ID, 10)
10804
+	template_id = "M" + adviceLastId
10805
+	advice := models.DoctorAdvice{
10806
+		UserOrgId:             org_id,
10807
+		PatientId:             patient_id,
10808
+		AdviceType:            adviceType,
10809
+		AdviceDate:            AdviceDate,
10810
+		StartTime:             StartTime,
10811
+		AdviceName:            advice_name,
10812
+		AdviceDesc:            advice_desc,
10813
+		ReminderDate:          0,
10814
+		SingleDose:            single_dose,
10815
+		SingleDoseUnit:        single_dose_unit,
10816
+		DrugSpec:              0,
10817
+		DrugSpecUnit:          "",
10818
+		PrescribingNumber:     prescribing_number,
10819
+		PrescribingNumberUnit: prescribing_number_unit,
10820
+		DeliveryWay:           delivery_way,
10821
+		ExecutionFrequency:    execution_frequency,
10822
+		AdviceDoctor:          advice_doctor,
10823
+		Status:                1,
10824
+		CreatedTime:           time.Now().Unix(),
10825
+		UpdatedTime:           0,
10826
+		AdviceAffirm:          "",
10827
+		Remark:                remark,
10828
+		StopTime:              0,
10829
+		StopReason:            "",
10830
+		StopDoctor:            0,
10831
+		StopState:             0,
10832
+		ParentId:              0,
10833
+		ExecutionTime:         0,
10834
+		ExecutionStaff:        0,
10835
+		ExecutionState:        0,
10836
+		Checker:               0,
10837
+		RecordDate:            RecordDate,
10838
+		DialysisOrderId:       0,
10839
+		CheckTime:             0,
10840
+		CheckState:            0,
10841
+		AdviceId:              0,
10842
+		RemindType:            0,
10843
+		FrequencyType:         frequency_type,
10844
+		DayCount:              day_count,
10845
+		WeekDay:               frequency_week,
10846
+		ChildDoctorAdvice:     nil,
10847
+		TemplateId:            template_id,
10848
+		Modifier:              0,
10849
+		IsCheck:               0,
10850
+		Way:                   0,
10851
+		DrugId:                0,
10852
+		DrugNameId:            0,
10853
+		IsMedicine:            0,
10854
+		PushStartTime:         0,
10855
+		IsSettle:              0,
10856
+		IsPrescription:        0,
10857
+	}
10858
+
10859
+	service.CreateMobileAdivce(advice)
10860
+
10861
+	c.ServeSuccessJSON(map[string]interface{}{
10862
+		"msg": "保存成功!",
10863
+	})
10864
+
10865
+}
10866
+
10867
+func (c *DialysisAPIController) GetLongDoctorAdviceByPatient() {
10868
+
10869
+	patient_id, _ := c.GetInt64("patient_id")
10870
+
10871
+	org_id := c.GetMobileAdminUserInfo().Org.Id
10872
+	app_id := c.GetMobileAdminUserInfo().App.Id
10873
+	adviceList, _ := service.GetLongDoctorAdviceByPatient(patient_id, org_id)
10874
+	adminRoles, _ := service.GetAllDoctorTwo(org_id, app_id)
10875
+	c.ServeSuccessJSON(map[string]interface{}{
10876
+		"adviceList": adviceList,
10877
+		"adminRoles": adminRoles,
10878
+	})
10879
+}

+ 6 - 0
controllers/mobile_api_controllers/mobile_api_router_register.go View File

@@ -213,4 +213,10 @@ func MobileAPIControllersRegisterRouters() {
213 213
 	beego.Router("/m/api/sch/coversch", &DialysisAPIController{}, "Get:MobileCoverSch")
214 214
 
215 215
 	beego.Router("/m/api/batchcheckadvice", &DialysisAPIController{}, "Get:BatchCheckAdvice")
216
+
217
+	beego.Router("/m/api/getallmobiledruglist", &DialysisAPIController{}, "Get:GetAllMobileDrugList")
218
+
219
+	beego.Router("/m/api/savelongmobileadvice", &DialysisAPIController{}, "Post:SaveLongMobileAdvice")
220
+
221
+	beego.Router("/m/api/getlongdoctoradvicebypatient", &DialysisAPIController{}, "Get:GetLongDoctorAdviceByPatient")
216 222
 }

+ 373 - 230
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -10,8 +10,6 @@ import (
10 10
 	"XT_New/models"
11 11
 	"XT_New/service"
12 12
 	"XT_New/utils"
13
-	"github.com/jinzhu/gorm"
14
-
15 13
 	// "fmt"
16 14
 	"reflect"
17 15
 	"strconv"
@@ -582,6 +580,20 @@ func (c *PatientApiController) DeleteDoctorAdvice() {
582 580
 		return
583 581
 	}
584 582
 
583
+	//自备药
584
+	selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
585
+
586
+	if selfPrescriptionOutOpenOne.IsOpen == 1 {
587
+		//查询库存是否是自备药
588
+		selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
589
+
590
+		if selfBasedrug.IsSelfDrug == 1 {
591
+			creater := adminUserInfo.AdminUser.Id
592
+			//退库
593
+			service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
594
+		}
595
+	}
596
+
585 597
 	//if !adminUserInfo.AdminUser.IsSuperAdmin && advice.AdviceDoctor != adminUserInfo.AdminUser.Id {
586 598
 	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDialysisPermissionDeniedModify)
587 599
 	//	return
@@ -659,6 +671,50 @@ func (c *PatientApiController) ExecDoctorAdvice() {
659 671
 			advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
660 672
 
661 673
 			for _, item := range advices {
674
+
675
+				//自备药
676
+				selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
677
+
678
+				if selfPrescriptionOutOpenOne.IsOpen == 1 {
679
+					//查询库存是否
680
+					selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
681
+
682
+					if selfBasedrug.IsSelfDrug == 1 {
683
+						selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
684
+						var prescribing_number_total_one int64
685
+						//判断单位是否相等
686
+						if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
687
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
688
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
689
+							//转化为最小单位
690
+							prescribing_number_total_one = count * selfBasedrug.MinNumber
691
+						}
692
+
693
+						if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
694
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
695
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
696
+							prescribing_number_total_one = count
697
+
698
+						}
699
+
700
+						if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
701
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
702
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
703
+							prescribing_number_total_one = count
704
+						}
705
+						if prescribing_number_total_one > selfDrugStockCount.FlushCount {
706
+							c.ServeSuccessJSON(map[string]interface{}{
707
+								"msg":    "2",
708
+								"advice": advice,
709
+								"ids":    ids,
710
+							})
711
+							return
712
+
713
+						}
714
+					}
715
+
716
+				}
717
+
662 718
 				//恒泰中医院
663 719
 				if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
664 720
 					if item.DrugId == 0 || item.DrugNameId == 0 {
@@ -692,6 +748,47 @@ func (c *PatientApiController) ExecDoctorAdvice() {
692 748
 		} else {
693 749
 			advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
694 750
 			for _, item := range advices {
751
+				//自备药
752
+				selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
753
+
754
+				if selfPrescriptionOutOpenOne.IsOpen == 1 {
755
+					//查询库存是否
756
+					selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
757
+
758
+					if selfBasedrug.IsSelfDrug == 1 {
759
+						selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
760
+						var prescribing_number_total_one int64
761
+						//判断单位是否相等
762
+						if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
763
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
764
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
765
+							//转化为最小单位
766
+							prescribing_number_total_one = count * selfBasedrug.MinNumber
767
+						}
768
+
769
+						if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
770
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
771
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
772
+							prescribing_number_total_one = count
773
+
774
+						}
775
+
776
+						if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
777
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
778
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
779
+							prescribing_number_total_one = count
780
+						}
781
+						if prescribing_number_total_one > selfDrugStockCount.FlushCount {
782
+							c.ServeSuccessJSON(map[string]interface{}{
783
+								"msg":    "2",
784
+								"advice": advice,
785
+								"ids":    ids,
786
+							})
787
+							return
788
+						}
789
+					}
790
+
791
+				}
695 792
 				//恒泰中医院
696 793
 				if item.UserOrgId == 10490 || item.UserOrgId == 10602 {
697 794
 					if item.DrugId == 0 || item.DrugNameId == 0 {
@@ -861,7 +958,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
861 958
 		_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.Org.Id)
862 959
 
863 960
 		//自备药信息
864
-		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
961
+		//privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
865 962
 
866 963
 		storeHouseConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.Org.Id)
867 964
 
@@ -1162,107 +1259,107 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1162 1259
 			}
1163 1260
 		}
1164 1261
 
1165
-		if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
1166
-			if groupno > 0 {
1167
-				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
1168
-				for _, item := range advices {
1169
-
1170
-					if item.ExecutionState == 1 && item.Way == 2 {
1171
-						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1172
-						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1173
-
1174
-						timeStr := time.Now().Format("2006-01-02")
1175
-						timeArr := strings.Split(timeStr, "-")
1176
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
1177
-
1178
-						total = total + 1
1179
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1180
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1181
-						number = number + total
1182
-						warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1183
-						//插入自备药出库单
1184
-						outStock := models.XtSelfOutStock{
1185
-							DrugName:       item.AdviceName,
1186
-							DrugNameId:     item.DrugNameId,
1187
-							DrugSpec:       item.AdviceDesc,
1188
-							OutstoreNumber: count,
1189
-							AdminUserId:    adminUserInfo.AdminUser.Id,
1190
-							StorckTime:     item.AdviceDate,
1191
-							UserOrgId:      adminUserInfo.Org.Id,
1192
-							CreatedTime:    time.Now().Unix(),
1193
-							Status:         1,
1194
-							PatientId:      item.PatientId,
1195
-							ExitMode:       2,
1196
-							MedicId:        item.DrugId,
1197
-							StockOutNumber: warehousing_out_order,
1198
-						}
1199
-						//查询 该患者是否已出库
1200
-						out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1201
-
1202
-						if errcode == gorm.ErrRecordNotFound {
1203
-							service.CreateOutStock(&outStock)
1204
-						} else if errcode == nil {
1205
-							err := service.UpdatedSelfOutSatock(out.ID, &outStock)
1206
-							fmt.Println("err", err)
1207
-						}
1208
-					}
1209
-				}
1210
-			} else {
1211
-
1212
-				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
1213
-				for _, item := range advices {
1214
-
1215
-					if item.ExecutionState == 1 && item.Way == 2 {
1216
-
1217
-						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1218
-						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1219
-
1220
-						timeStr := time.Now().Format("2006-01-02")
1221
-						timeArr := strings.Split(timeStr, "-")
1222
-						total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
1223
-
1224
-						total = total + 1
1225
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1226
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1227
-						number = number + total
1228
-						warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1229
-
1230
-						//插入自备药出库单
1231
-						outStock := models.XtSelfOutStock{
1232
-							DrugName:       item.AdviceName,
1233
-							DrugNameId:     item.DrugNameId,
1234
-							DrugSpec:       item.AdviceDesc,
1235
-							OutstoreNumber: count,
1236
-							AdminUserId:    adminUserInfo.AdminUser.Id,
1237
-							StorckTime:     item.AdviceDate,
1238
-							UserOrgId:      adminUserInfo.Org.Id,
1239
-							CreatedTime:    time.Now().Unix(),
1240
-							Status:         1,
1241
-							PatientId:      item.PatientId,
1242
-							ExitMode:       2,
1243
-							MedicId:        item.DrugId,
1244
-							StockOutNumber: warehousing_out_order,
1245
-						}
1246
-
1247
-						//查询 该患者是否已出库
1248
-						out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1249
-
1250
-						if errcode == gorm.ErrRecordNotFound {
1251
-							service.CreateOutStock(&outStock)
1252
-						} else if errcode == nil {
1253
-							err := service.UpdatedSelfOutSatock(out.ID, &outStock)
1254
-							fmt.Println("err", err)
1255
-						}
1256
-					}
1257
-				}
1258
-				c.ServeSuccessJSON(map[string]interface{}{
1259
-					"msg":    "1",
1260
-					"advice": advice,
1261
-					"ids":    ids,
1262
-				})
1263
-				return
1264
-			}
1265
-		}
1262
+		//if privateDrugConfig != nil && privateDrugConfig.DrugStart == 1 {
1263
+		//	if groupno > 0 {
1264
+		//		advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
1265
+		//		for _, item := range advices {
1266
+		//
1267
+		//			if item.ExecutionState == 1 && item.Way == 2 {
1268
+		//				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1269
+		//				count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1270
+		//
1271
+		//				timeStr := time.Now().Format("2006-01-02")
1272
+		//				timeArr := strings.Split(timeStr, "-")
1273
+		//				total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
1274
+		//
1275
+		//				total = total + 1
1276
+		//				warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1277
+		//				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1278
+		//				number = number + total
1279
+		//				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1280
+		//				//插入自备药出库单
1281
+		//				outStock := models.XtSelfOutStock{
1282
+		//					DrugName:       item.AdviceName,
1283
+		//					DrugNameId:     item.DrugNameId,
1284
+		//					DrugSpec:       item.AdviceDesc,
1285
+		//					OutstoreNumber: count,
1286
+		//					AdminUserId:    adminUserInfo.AdminUser.Id,
1287
+		//					StorckTime:     item.AdviceDate,
1288
+		//					UserOrgId:      adminUserInfo.Org.Id,
1289
+		//					CreatedTime:    time.Now().Unix(),
1290
+		//					Status:         1,
1291
+		//					PatientId:      item.PatientId,
1292
+		//					ExitMode:       2,
1293
+		//					MedicId:        item.DrugId,
1294
+		//					StockOutNumber: warehousing_out_order,
1295
+		//				}
1296
+		//				//查询 该患者是否已出库
1297
+		//				out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1298
+		//
1299
+		//				if errcode == gorm.ErrRecordNotFound {
1300
+		//					service.CreateOutStock(&outStock)
1301
+		//				} else if errcode == nil {
1302
+		//					err := service.UpdatedSelfOutSatock(out.ID, &outStock)
1303
+		//					fmt.Println("err", err)
1304
+		//				}
1305
+		//			}
1306
+		//		}
1307
+		//	} else {
1308
+		//
1309
+		//		advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
1310
+		//		for _, item := range advices {
1311
+		//
1312
+		//			if item.ExecutionState == 1 && item.Way == 2 {
1313
+		//
1314
+		//				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1315
+		//				count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1316
+		//
1317
+		//				timeStr := time.Now().Format("2006-01-02")
1318
+		//				timeArr := strings.Split(timeStr, "-")
1319
+		//				total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.Org.Id)
1320
+		//
1321
+		//				total = total + 1
1322
+		//				warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1323
+		//				number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1324
+		//				number = number + total
1325
+		//				warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1326
+		//
1327
+		//				//插入自备药出库单
1328
+		//				outStock := models.XtSelfOutStock{
1329
+		//					DrugName:       item.AdviceName,
1330
+		//					DrugNameId:     item.DrugNameId,
1331
+		//					DrugSpec:       item.AdviceDesc,
1332
+		//					OutstoreNumber: count,
1333
+		//					AdminUserId:    adminUserInfo.AdminUser.Id,
1334
+		//					StorckTime:     item.AdviceDate,
1335
+		//					UserOrgId:      adminUserInfo.Org.Id,
1336
+		//					CreatedTime:    time.Now().Unix(),
1337
+		//					Status:         1,
1338
+		//					PatientId:      item.PatientId,
1339
+		//					ExitMode:       2,
1340
+		//					MedicId:        item.DrugId,
1341
+		//					StockOutNumber: warehousing_out_order,
1342
+		//				}
1343
+		//
1344
+		//				//查询 该患者是否已出库
1345
+		//				out, errcode := service.GetSelfOutStock(adminUserInfo.Org.Id, item.AdviceDate, item.PatientId, item.AdviceName, item.AdviceDesc)
1346
+		//
1347
+		//				if errcode == gorm.ErrRecordNotFound {
1348
+		//					service.CreateOutStock(&outStock)
1349
+		//				} else if errcode == nil {
1350
+		//					err := service.UpdatedSelfOutSatock(out.ID, &outStock)
1351
+		//					fmt.Println("err", err)
1352
+		//				}
1353
+		//			}
1354
+		//		}
1355
+		//		c.ServeSuccessJSON(map[string]interface{}{
1356
+		//			"msg":    "1",
1357
+		//			"advice": advice,
1358
+		//			"ids":    ids,
1359
+		//		})
1360
+		//		return
1361
+		//	}
1362
+		//}
1266 1363
 
1267 1364
 		//自备药
1268 1365
 		selfPrescriptionOutOpen, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
@@ -1279,149 +1376,150 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1279 1376
 				}
1280 1377
 			}()
1281 1378
 
1282
-			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
1379
+			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
1283 1380
 
1284 1381
 			if selfBasedrug.IsSelfDrug == 1 {
1285 1382
 
1286 1383
 				//查询是否有库存
1287
-				info, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
1384
+				infoList, _ := service.GetSelfWarehouseInfoByWarehouseInfoTwo(advice.DrugId, advice.PatientId, advice.UserOrgId, tx)
1288 1385
 
1289
-				if len(info) > 0 {
1290
-					var total_count int64
1291
-					var prescribing_number_total int64
1292
-					for _, item := range info {
1293
-						if item.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1294
-							item.StockMaxNumber = item.StockMaxNumber * selfBasedrug.MinNumber
1295
-						}
1296
-
1297
-						total_count += item.StockMaxNumber + item.StockMinNumber
1386
+				var total_count int64
1387
+				var prescribing_number_total int64
1388
+				for _, items := range infoList {
1389
+					if items.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1390
+						items.StockMaxNumber = items.StockMaxNumber * selfBasedrug.MinNumber
1298 1391
 					}
1299 1392
 
1300
-					//判断单位是否相等
1301
-					if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1302
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1303
-						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1304
-						//转化为最小单位
1305
-						prescribing_number_total = count * selfBasedrug.MinNumber
1306
-					}
1393
+					total_count += items.StockMaxNumber + items.StockMinNumber
1394
+				}
1307 1395
 
1308
-					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1309
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1310
-						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1311
-						prescribing_number_total = count
1396
+				if total_count == 0 {
1397
+					c.ServeSuccessJSON(map[string]interface{}{
1398
+						"msg":    "2",
1399
+						"advice": advice,
1400
+						"ids":    ids,
1401
+					})
1402
+					return
1403
+				}
1312 1404
 
1313
-					}
1405
+				//判断单位是否相等
1406
+				if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1407
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1408
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1409
+					//转化为最小单位
1410
+					prescribing_number_total = count * selfBasedrug.MinNumber
1411
+				}
1314 1412
 
1315
-					if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
1316
-						prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1317
-						count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1318
-						prescribing_number_total = count
1413
+				if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
1414
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1415
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1416
+					prescribing_number_total = count
1319 1417
 
1320
-					}
1418
+				}
1321 1419
 
1322
-					if prescribing_number_total > total_count {
1323
-						c.ServeSuccessJSON(map[string]interface{}{
1324
-							"msg":    "3",
1325
-							"advice": advice,
1326
-						})
1327
-						return
1420
+				if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
1421
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1422
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1423
+					prescribing_number_total = count
1424
+
1425
+				}
1426
+
1427
+				if prescribing_number_total > total_count {
1428
+					c.ServeSuccessJSON(map[string]interface{}{
1429
+						"msg":    "3",
1430
+						"advice": advice,
1431
+					})
1432
+					return
1433
+				}
1434
+				var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
1435
+				//出库
1436
+				if prescribing_number_total <= total_count {
1437
+					timeStr := time.Now().Format("2006-01-02")
1438
+					timeArr := strings.Split(timeStr, "-")
1439
+					total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
1440
+
1441
+					total = total + 1
1442
+					warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1443
+					number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1444
+					number = number + total
1445
+					warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1446
+					operation_time := time.Now().Unix()
1447
+
1448
+					creater := c.GetMobileAdminUserInfo().AdminUser.Id
1449
+					//创建一个出库单
1450
+					drugWarehouseOut := models.XtSelfDrugWarehouseOut{
1451
+						WarehouseOutOrderNumber: warehousing_out_order,
1452
+						OperationTime:           operation_time,
1453
+						OrgId:                   adminUserInfo.Org.Id,
1454
+						Creater:                 creater,
1455
+						Ctime:                   time.Now().Unix(),
1456
+						Status:                  1,
1457
+						WarehouseOutTime:        advice.AdviceDate,
1458
+						Type:                    0,
1459
+						PatientId:               advice.PatientId,
1460
+						IsCheck:                 1,
1461
+						IsSys:                   1,
1328 1462
 					}
1329
-					var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
1330
-					//出库
1331
-					if prescribing_number_total <= total_count {
1332
-						timeStr := time.Now().Format("2006-01-02")
1333
-						timeArr := strings.Split(timeStr, "-")
1334
-						total, _ := service.FindAllSelfDrugWarehouseOut(adminUserInfo.Org.Id, tx)
1335
-
1336
-						total = total + 1
1337
-						warehousing_out_order := strconv.FormatInt(adminUserInfo.Org.Id, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1338
-						number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1339
-						number = number + total
1340
-						warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1341
-						operation_time := time.Now().Unix()
1342
-
1343
-						creater := c.GetAdminUserInfo().AdminUser.Id
1344
-						//创建一个出库单
1345
-						drugWarehouseOut := models.XtSelfDrugWarehouseOut{
1346
-							WarehouseOutOrderNumber: warehousing_out_order,
1347
-							OperationTime:           operation_time,
1348
-							OrgId:                   adminUserInfo.Org.Id,
1349
-							Creater:                 creater,
1350
-							Ctime:                   time.Now().Unix(),
1351
-							Status:                  1,
1352
-							WarehouseOutTime:        advice.AdviceDate,
1353
-							Type:                    0,
1354
-							PatientId:               advice.PatientId,
1355
-							IsCheck:                 1,
1356
-							IsSys:                   1,
1357
-						}
1358 1463
 
1359
-						//查询今日是否有出库数据
1360
-						lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, advice.AdviceDate, tx, 1)
1464
+					//查询今日是否有出库数据
1465
+					lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(adminUserInfo.Org.Id, advice.AdviceDate, tx, 1)
1361 1466
 
1362
-						if lastWarehouseOut.ID == 0 {
1363
-							service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
1364
-						}
1365
-						//出库
1366
-						warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
1367
-							WarehouseOutOrderNumber: warehousing_out_order,
1368
-							DrugId:                  advice.DrugId,
1369
-							Count:                   total_count,
1370
-							Price:                   0,
1371
-							TotalPrice:              0,
1372
-							Status:                  1,
1373
-							Ctime:                   advice.AdviceDate,
1374
-							Mtime:                   advice.AdviceDate,
1375
-							Remark:                  "",
1376
-							OrgId:                   advice.UserOrgId,
1377
-							Type:                    0,
1378
-							Manufacturer:            selfBasedrug.Manufacturer,
1379
-							Dealer:                  selfBasedrug.Dealer,
1380
-							RetailPrice:             0,
1381
-							RetailTotalPrice:        0,
1382
-							CountUnit:               advice.PrescribingNumberUnit,
1383
-							ExpiryDate:              0,
1384
-							ProductDate:             0,
1385
-							Number:                  "",
1386
-							BatchNumber:             "",
1387
-							IsSys:                   0,
1388
-							WarehouseInfoId:         0,
1389
-							AdminUserId:             0,
1390
-							StockCount:              "",
1391
-							IsCheck:                 1,
1392
-							SysRecordTime:           advice.AdviceDate,
1393
-							PatientId:               advice.PatientId,
1394
-							AdviceId:                advice.ID,
1395
-							ClassType:               "",
1396
-						}
1397
-						warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1467
+					if lastWarehouseOut.ID == 0 {
1468
+						service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
1469
+					}
1470
+					//出库
1471
+					warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
1472
+						WarehouseOutId:          lastWarehouseOut.ID,
1473
+						WarehouseOutOrderNumber: warehousing_out_order,
1474
+						DrugId:                  advice.DrugId,
1475
+						Count:                   prescribing_number_total,
1476
+						Price:                   0,
1477
+						TotalPrice:              0,
1478
+						Status:                  1,
1479
+						Ctime:                   advice.AdviceDate,
1480
+						Mtime:                   advice.AdviceDate,
1481
+						Remark:                  "",
1482
+						OrgId:                   advice.UserOrgId,
1483
+						Type:                    0,
1484
+						Manufacturer:            selfBasedrug.Manufacturer,
1485
+						Dealer:                  selfBasedrug.Dealer,
1486
+						RetailPrice:             0,
1487
+						RetailTotalPrice:        0,
1488
+						CountUnit:               selfBasedrug.MinUnit,
1489
+						ExpiryDate:              0,
1490
+						ProductDate:             0,
1491
+						Number:                  "",
1492
+						BatchNumber:             "",
1493
+						IsSys:                   0,
1494
+						WarehouseInfoId:         0,
1495
+						AdminUserId:             0,
1496
+						StockCount:              "",
1497
+						IsCheck:                 1,
1498
+						SysRecordTime:           advice.AdviceDate,
1499
+						PatientId:               advice.PatientId,
1500
+						AdviceId:                advice.ID,
1501
+						ClassType:               "",
1502
+					}
1503
+					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1398 1504
 
1399
-						for _, it := range warehousingOutInfo {
1505
+					for _, it := range warehousingOutInfo {
1400 1506
 
1401
-							medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
1402
-							drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
1403
-							//出库逻辑
1404
-							service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
1507
+						medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
1508
+						drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
1509
+						//出库逻辑
1510
+						service.AutoSelfDrugDeliverInfoFourtyTwo(adminUserInfo.Org.Id, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
1405 1511
 
1406
-							//查询剩余库存
1407
-							stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
1408
-							var sum_count int64
1409
-							for _, its := range stockInfo {
1410
-								if its.MaxUnit == medical.MaxUnit {
1411
-									its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
1412
-								}
1413
-								sum_count += its.StockMaxNumber + its.StockMinNumber
1512
+						//查询剩余库存
1513
+						stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
1514
+						var sum_count int64
1515
+						for _, its := range stockInfo {
1516
+							if its.MaxUnit == medical.MaxUnit {
1517
+								its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
1414 1518
 							}
1415
-							service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
1519
+							sum_count += its.StockMaxNumber + its.StockMinNumber
1416 1520
 						}
1521
+						service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
1417 1522
 					}
1418
-
1419
-				} else {
1420
-					c.ServeSuccessJSON(map[string]interface{}{
1421
-						"msg":    "3",
1422
-						"advice": advice,
1423
-					})
1424
-					return
1425 1523
 				}
1426 1524
 
1427 1525
 			}
@@ -1982,7 +2080,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1982 2080
 
1983 2081
 				if selfPrescriptionOutOpen.IsOpen == 1 {
1984 2082
 
1985
-					selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
2083
+					selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
1986 2084
 
1987 2085
 					if selfBasedrug.IsSelfDrug == 1 {
1988 2086
 
@@ -2043,7 +2141,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2043 2141
 								warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
2044 2142
 								operation_time := time.Now().Unix()
2045 2143
 
2046
-								creater := adminInfo.AdminUser.Id
2144
+								creater := c.GetMobileAdminUserInfo().AdminUser.Id
2047 2145
 								//创建一个出库单
2048 2146
 								drugWarehouseOut := models.XtSelfDrugWarehouseOut{
2049 2147
 									WarehouseOutOrderNumber: warehousing_out_order,
@@ -2067,9 +2165,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2067 2165
 								}
2068 2166
 								//出库
2069 2167
 								warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
2168
+									WarehouseOutId:          lastWarehouseOut.ID,
2070 2169
 									WarehouseOutOrderNumber: warehousing_out_order,
2071 2170
 									DrugId:                  advice.DrugId,
2072
-									Count:                   total_count,
2171
+									Count:                   prescribing_number_total,
2073 2172
 									Price:                   0,
2074 2173
 									TotalPrice:              0,
2075 2174
 									Status:                  1,
@@ -2082,7 +2181,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2082 2181
 									Dealer:                  selfBasedrug.Dealer,
2083 2182
 									RetailPrice:             0,
2084 2183
 									RetailTotalPrice:        0,
2085
-									CountUnit:               advice.PrescribingNumberUnit,
2184
+									CountUnit:               selfBasedrug.MinUnit,
2086 2185
 									ExpiryDate:              0,
2087 2186
 									ProductDate:             0,
2088 2187
 									Number:                  "",
@@ -5956,6 +6055,20 @@ func (c *PatientApiController) DelDoctorAdvice() {
5956 6055
 
5957 6056
 			}
5958 6057
 		}
6058
+
6059
+		//自备药
6060
+		selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
6061
+
6062
+		if selfPrescriptionOutOpenOne.IsOpen == 1 {
6063
+			//查询库存是否是自备药
6064
+			selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
6065
+
6066
+			if selfBasedrug.IsSelfDrug == 1 {
6067
+				creater := adminUserInfo.AdminUser.Id
6068
+				//退库
6069
+				service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
6070
+			}
6071
+		}
5959 6072
 		err := service.DeleteDoctorAdvice(&advice)
5960 6073
 		//记录日志
5961 6074
 		byterequest, _ := json.Marshal(advice)
@@ -6058,6 +6171,21 @@ func (c *PatientApiController) DelDoctorAdvice() {
6058 6171
 
6059 6172
 				}
6060 6173
 			}
6174
+
6175
+			//自备药
6176
+			selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
6177
+
6178
+			if selfPrescriptionOutOpenOne.IsOpen == 1 {
6179
+				//查询库存是否是自备药
6180
+				selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
6181
+
6182
+				if selfBasedrug.IsSelfDrug == 1 {
6183
+					creater := adminUserInfo.AdminUser.Id
6184
+					//退库
6185
+					service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
6186
+				}
6187
+			}
6188
+
6061 6189
 			err = service.DeleteDoctorAdviceByGroupNo(&advice)
6062 6190
 			//记录日志
6063 6191
 			byterequest, _ := json.Marshal(advice)
@@ -6114,6 +6242,21 @@ func (c *PatientApiController) DelDoctorAdvice() {
6114 6242
 			advicelist, _ := service.GetBatchDoctorAdviceList(ids, adminUserInfo.Org.Id)
6115 6243
 
6116 6244
 			for _, item := range advicelist {
6245
+
6246
+				//自备药
6247
+				selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.Org.Id)
6248
+
6249
+				if selfPrescriptionOutOpenOne.IsOpen == 1 {
6250
+					//查询库存是否是自备药
6251
+					selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(item.DrugId, item.UserOrgId)
6252
+
6253
+					if selfBasedrug.IsSelfDrug == 1 {
6254
+						creater := adminUserInfo.AdminUser.Id
6255
+						//退库
6256
+						service.SelfDrugAutoAddCancelInfoOne(item, creater)
6257
+					}
6258
+				}
6259
+
6117 6260
 				//记录日志
6118 6261
 				byterequest, _ := json.Marshal(item)
6119 6262
 				adviceLog := models.XtDoctorAdviceLog{

+ 0 - 2
controllers/new_mobile_api_controllers/new_dialysis_api_controller.go View File

@@ -1419,7 +1419,6 @@ func (this *NewDialysisApiController) UpdatedPatient() {
1419 1419
 			DeathTime:         death_time,
1420 1420
 			OutReason:         out_reason,
1421 1421
 			RelativePhone:     relative_phone,
1422
-			Remark:            "",
1423 1422
 			SchRemark:         remark,
1424 1423
 			TreatmentPlan:     treatment_plan,
1425 1424
 		}
@@ -1452,7 +1451,6 @@ func (this *NewDialysisApiController) UpdatedPatient() {
1452 1451
 			OutReason:         out_reason,
1453 1452
 			DeathTime:         death_time,
1454 1453
 			RelativePhone:     relative_phone,
1455
-			Remark:            "",
1456 1454
 			SchRemark:         remark,
1457 1455
 			TreatmentPlan:     treatment_plan,
1458 1456
 		}

+ 81 - 8
controllers/patient_api_controller.go View File

@@ -2295,6 +2295,51 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2295 2295
 
2296 2296
 		advice, _ := service.FindDoctorAdvice(adminUserInfo.CurrentOrgId, id)
2297 2297
 
2298
+		//自备药
2299
+		selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
2300
+
2301
+		if selfPrescriptionOutOpenOne.IsOpen == 1 {
2302
+			//查询库存是否
2303
+			selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
2304
+
2305
+			if selfBasedrug.IsSelfDrug == 1 {
2306
+				selfDrugStockCount, _ := service.GetSelfDrugStockCountByPatientId(advice.DrugId, advice.PatientId, advice.UserOrgId)
2307
+				var prescribing_number_total_one int64
2308
+				//判断单位是否相等
2309
+				if selfBasedrug.MaxUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2310
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2311
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2312
+					//转化为最小单位
2313
+					prescribing_number_total_one = count * selfBasedrug.MinNumber
2314
+				}
2315
+
2316
+				if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
2317
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2318
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2319
+					prescribing_number_total_one = count
2320
+
2321
+				}
2322
+
2323
+				if selfBasedrug.MinUnit == advice.PrescribingNumberUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
2324
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
2325
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
2326
+					prescribing_number_total_one = count
2327
+				}
2328
+
2329
+				fmt.Println("prescribing_number_total_one------------------", prescribing_number_total_one)
2330
+				fmt.Println("selfDrugStockCount.FlushCount", selfDrugStockCount.FlushCount)
2331
+				//库存不足
2332
+				if prescribing_number_total_one > selfDrugStockCount.FlushCount {
2333
+					c.ServeSuccessJSON(map[string]interface{}{
2334
+						"msg":    "2",
2335
+						"advice": advice,
2336
+					})
2337
+					return
2338
+				}
2339
+			}
2340
+
2341
+		}
2342
+
2298 2343
 		if advice.ID == 0 || advice.PatientId != patient {
2299 2344
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceNotExist)
2300 2345
 			return
@@ -2643,9 +2688,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2643 2688
 				}
2644 2689
 			}()
2645 2690
 
2646
-			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
2647
-
2648
-			fmt.Println("selfBasedrug-----------------------------------------", selfBasedrug.IsSelfDrug)
2691
+			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
2649 2692
 
2650 2693
 			if selfBasedrug.IsSelfDrug == 1 {
2651 2694
 
@@ -2730,9 +2773,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2730 2773
 						}
2731 2774
 						//出库
2732 2775
 						warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
2776
+							WarehouseOutId:          lastWarehouseOut.ID,
2733 2777
 							WarehouseOutOrderNumber: warehousing_out_order,
2734 2778
 							DrugId:                  advice.DrugId,
2735
-							Count:                   total_count,
2779
+							Count:                   prescribing_number_total,
2736 2780
 							Price:                   0,
2737 2781
 							TotalPrice:              0,
2738 2782
 							Status:                  1,
@@ -2745,7 +2789,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2745 2789
 							Dealer:                  selfBasedrug.Dealer,
2746 2790
 							RetailPrice:             0,
2747 2791
 							RetailTotalPrice:        0,
2748
-							CountUnit:               advice.PrescribingNumberUnit,
2792
+							CountUnit:               selfBasedrug.MinUnit,
2749 2793
 							ExpiryDate:              0,
2750 2794
 							ProductDate:             0,
2751 2795
 							Number:                  "",
@@ -3457,7 +3501,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
3457 3501
 				}
3458 3502
 			}()
3459 3503
 
3460
-			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId)
3504
+			selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
3461 3505
 
3462 3506
 			if selfBasedrug.IsSelfDrug == 1 {
3463 3507
 
@@ -3542,9 +3586,10 @@ func (c *PatientApiController) ExecDoctorAdvice() {
3542 3586
 						}
3543 3587
 						//出库
3544 3588
 						warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
3589
+							WarehouseOutId:          lastWarehouseOut.ID,
3545 3590
 							WarehouseOutOrderNumber: warehousing_out_order,
3546 3591
 							DrugId:                  advice.DrugId,
3547
-							Count:                   total_count,
3592
+							Count:                   prescribing_number_total,
3548 3593
 							Price:                   0,
3549 3594
 							TotalPrice:              0,
3550 3595
 							Status:                  1,
@@ -3557,7 +3602,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
3557 3602
 							Dealer:                  selfBasedrug.Dealer,
3558 3603
 							RetailPrice:             0,
3559 3604
 							RetailTotalPrice:        0,
3560
-							CountUnit:               advice.PrescribingNumberUnit,
3605
+							CountUnit:               selfBasedrug.MinUnit,
3561 3606
 							ExpiryDate:              0,
3562 3607
 							ProductDate:             0,
3563 3608
 							Number:                  "",
@@ -4246,6 +4291,20 @@ func (c *PatientApiController) DeleteDoctorAdvice() {
4246 4291
 
4247 4292
 		}
4248 4293
 	}
4294
+	//自备药
4295
+	selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
4296
+
4297
+	if selfPrescriptionOutOpenOne.IsOpen == 1 {
4298
+		//查询库存是否是自备药
4299
+		selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
4300
+
4301
+		if selfBasedrug.IsSelfDrug == 1 {
4302
+			creater := adminUserInfo.AdminUser.Id
4303
+			//退库
4304
+			service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
4305
+		}
4306
+	}
4307
+
4249 4308
 	err := service.DeleteDoctorAdvice(&advice)
4250 4309
 
4251 4310
 	//记录日志
@@ -4297,6 +4356,20 @@ func (c *PatientApiController) DeleteGroupAdvice() {
4297 4356
 		return
4298 4357
 	}
4299 4358
 
4359
+	//自备药
4360
+	selfPrescriptionOutOpenOne, _ := service.GetSelfPrescriptionOutOpen(adminUserInfo.CurrentOrgId)
4361
+
4362
+	if selfPrescriptionOutOpenOne.IsOpen == 1 {
4363
+		//查询库存是否是自备药
4364
+		selfBasedrug, _ := service.GetSelfBasedrugByIdTwo(advice.DrugId, advice.UserOrgId)
4365
+
4366
+		if selfBasedrug.IsSelfDrug == 1 {
4367
+			creater := adminUserInfo.AdminUser.Id
4368
+			//退库
4369
+			service.SelfDrugAutoAddCancelInfoOne(&advice, creater)
4370
+		}
4371
+	}
4372
+
4300 4373
 	//appRole, _ := service.FindAdminRoleTypeById(adminUserInfo.CurrentOrgId, adminUserInfo.AdminUser.Id, adminUserInfo.CurrentAppId)
4301 4374
 	//if appRole.UserType == 3 {
4302 4375
 	//	headNursePermission, getPermissionErr := service.GetAdminUserSpecialPermission(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id, models.SpecialPermissionTypeHeadNurse)

+ 7 - 26
controllers/self_drug_api_congtroller.go View File

@@ -5644,7 +5644,7 @@ func (c *SelfDrugApiController) GetSelfDrugQuery() {
5644 5644
 	keyword := c.GetString("keyword")
5645 5645
 	var goodIds []int64
5646 5646
 	org_id := c.GetAdminUserInfo().CurrentOrgId
5647
-	drugList, _ := service.GetDrugNameByword(org_id, keyword)
5647
+	drugList, _ := service.GetDrugNameBywordOne(org_id, keyword)
5648 5648
 	orgId := c.GetAdminUserInfo().CurrentOrgId
5649 5649
 	for _, it := range drugList {
5650 5650
 		goodIds = append(goodIds, it.ID)
@@ -5678,7 +5678,7 @@ func (c *SelfDrugApiController) CheckSelfDrugOutQuery() {
5678 5678
 	}()
5679 5679
 	warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
5680 5680
 
5681
-	patient_id, _ := c.GetInt64("patient_id")
5681
+	//patient_id, _ := c.GetInt64("patient_id")
5682 5682
 
5683 5683
 	orgId := c.GetAdminUserInfo().CurrentOrgId
5684 5684
 	warehousingOutInfoList, _ := service.GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id, orgId, tx)
@@ -5726,33 +5726,13 @@ func (c *SelfDrugApiController) CheckSelfDrugOutQuery() {
5726 5726
 			return
5727 5727
 		}
5728 5728
 	}
5729
-	warehousingOutInfoListTwo, _ := service.GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id, orgId, tx)
5730
-
5731
-	for _, it := range warehousingOutInfoListTwo {
5732
-		medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5733
-		////出库数量累加
5734
-		var out_count_one int64
5735 5729
 
5736
-		if it.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5737
-			out_count_one = it.Count * medical.MinNumber
5738
-		}
5739
-
5740
-		if it.CountUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
5741
-			out_count_one = it.Count
5742
-		}
5743
-
5744
-		if it.CountUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
5745
-			out_count_one = it.Count
5746
-		}
5747
-		service.AddSelfDrugCount(it.DrugId, it.OrgId, patient_id, out_count_one, tx)
5748
-
5749
-	}
5750 5730
 	warehousingOutInfoListThree, _ := service.GetSelfDrugWarehouseOutListByIdOne(warehouse_out_id, orgId, tx)
5751 5731
 	for _, it := range warehousingOutInfoListThree {
5752 5732
 		medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
5753 5733
 		drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
5754 5734
 		//出库逻辑
5755
-		service.AutoSelfDrugDeliverInfoFourtyOne(orgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
5735
+		service.AutoSelfDrugDeliverInfoFourtyThree(orgId, it.Count, &drugWarehouseOut, &drup, it, it.CountUnit, tx)
5756 5736
 
5757 5737
 		//查询剩余库存
5758 5738
 		stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
@@ -5816,6 +5796,7 @@ func (c *SelfDrugApiController) ReturnCheckSelfOutDrugQuery() {
5816 5796
 		medical, _ := service.GetSelfBaseDrugMedical(item.DrugId, tx)
5817 5797
 		if item.CountUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5818 5798
 			service.UpdateSelfDrugMaxNumber(item.Count, item.WarehouseInfoId, tx)
5799
+			service.DeleteSelfDrugOutFlow(item.ID, item.OrgId, tx)
5819 5800
 			drugInfoList, _ := service.FindSelfDrugWarehouseInfoList(item.DrugId, item.OrgId, tx)
5820 5801
 			var drug_max_number int64
5821 5802
 			var drug_min_number int64
@@ -5900,7 +5881,7 @@ func (c *SelfDrugApiController) ReturnSelfCheckWarehouse() {
5900 5881
 	}
5901 5882
 	for _, item := range list {
5902 5883
 		//删除流水
5903
-		service.UpdateSelfWarehousingInfoFlow(item.ID, orgId, tx)
5884
+		service.UpdateSelfWarehousingInfoFlow(item.WarehousingId, orgId, tx)
5904 5885
 		medical, _ := service.GetSelfBaseDrugMedical(item.DrugId, tx)
5905 5886
 		if item.MaxUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
5906 5887
 			//新增库存
@@ -5982,7 +5963,7 @@ func (c *SelfDrugApiController) GetSelfDrugFlow() {
5982 5963
 		endTime = theTime.Unix()
5983 5964
 	}
5984 5965
 	list, total, _ := service.GetSelfDrugFlow(drug_id, startTime, endTime, orgId, page, limit, patient_id)
5985
-	drug, _ := service.GetSelfBasedrugById(drug_id, orgId)
5966
+	drug, _ := service.GetSelfBasedrugByIdOne(drug_id, orgId)
5986 5967
 	patients, _ := service.GetAllpatient(orgId)
5987 5968
 	c.ServeSuccessJSON(map[string]interface{}{
5988 5969
 		"list":     list,
@@ -6025,7 +6006,7 @@ func (c *SelfDrugApiController) GetSelfDrugBatchNumberList() {
6025 6006
 	}
6026 6007
 
6027 6008
 	list, total, _ := service.GetSelfDrugBatchNumberList(drug_id, startTime, endTime, orgId, page, limit, patient_id)
6028
-	drug, _ := service.GetSelfBasedrugById(drug_id, orgId)
6009
+	drug, _ := service.GetSelfBasedrugByIdOne(drug_id, orgId)
6029 6010
 	c.ServeSuccessJSON(map[string]interface{}{
6030 6011
 		"list":  list,
6031 6012
 		"total": total,

+ 1 - 0
models/self_drug_models.go View File

@@ -80,6 +80,7 @@ type XtBaseDrug struct {
80 80
 	TotalCountOne          int64   `gorm:"column:total_count_one" json:"total_count" form:"total_count_one"`
81 81
 	TotalCountTwo          int64   `gorm:"column:total_count_two" json:"total_count_two" form:"total_count_two"`
82 82
 	IsShow                 int64   `gorm:"column:is_show" json:"is_show" form:"is_show"`
83
+	IsSelfDrug             int64   `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
83 84
 }
84 85
 
85 86
 func (XtBaseDrug) TableName() string {

+ 24 - 0
service/dialysis_service.go View File

@@ -2576,3 +2576,27 @@ func GetHisExecutionDoctorsThree(orgid int64, patientid int64, id int64, tx *gor
2576 2576
 	}
2577 2577
 	return doctorAdvice, err
2578 2578
 }
2579
+
2580
+func CreateMobileAdivce(advice models.DoctorAdvice) error {
2581
+
2582
+	err := XTWriteDB().Create(&advice).Error
2583
+
2584
+	return err
2585
+}
2586
+
2587
+func GetLongDoctorAdviceByPatient(patient_id int64, org_id int64) (advice []*models.XtDoctorAdvice, err error) {
2588
+
2589
+	err = XTReadDB().Where("patient_id = ? and user_org_id = ? and status=1 and advice_type =1", patient_id, org_id).Order("start_time desc").Find(&advice).Error
2590
+
2591
+	return advice, err
2592
+}
2593
+
2594
+func GetLastLongAdviceList(user_org_id int64) (models.XtDoctorAdvice, error) {
2595
+
2596
+	advice := models.XtDoctorAdvice{}
2597
+
2598
+	err := XTReadDB().Where("user_org_id =? and stauts=1 and advice_type =1", user_org_id).Last(&advice).Error
2599
+
2600
+	return advice, err
2601
+
2602
+}

+ 28 - 0
service/manage_center_service.go View File

@@ -223,28 +223,56 @@ func GetDrugAutoWarehouseOutEight(patient_id int64, advicedate int64, drugid int
223 223
 	return detail, err
224 224
 }
225 225
 
226
+func GetSelfDrugAutoWarehouseOutEight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (models.XtSelfDrugWarehouseOutInfo, error) {
227
+	detail := models.XtSelfDrugWarehouseOutInfo{}
228
+	err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&detail).Error
229
+	return detail, err
230
+}
231
+
226 232
 func GetDrugAutoWarehouseOutTen(patient_id int64, advicedate int64, drugid int64, adviceid int64, warehouse_info_id int64) (models.DrugWarehouseOutInfo, error) {
227 233
 	detail := models.DrugWarehouseOutInfo{}
228 234
 	err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", patient_id, advicedate, drugid, adviceid, warehouse_info_id).Find(&detail).Error
229 235
 	return detail, err
230 236
 }
231 237
 
238
+func GetSelfDrugAutoWarehouseOutTen(patient_id int64, advicedate int64, drugid int64, adviceid int64, warehouse_info_id int64) (models.XtSelfDrugWarehouseOutInfo, error) {
239
+	detail := models.XtSelfDrugWarehouseOutInfo{}
240
+	err = XTReadDB().Model(&detail).Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ? and warehouse_info_id = ?", patient_id, advicedate, drugid, adviceid, warehouse_info_id).Find(&detail).Error
241
+	return detail, err
242
+}
243
+
232 244
 func GetDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.DrugWarehouseOutInfo, err error) {
233 245
 
234 246
 	err = XTReadDB().Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&night).Error
235 247
 	return night, err
236 248
 }
237 249
 
250
+func GetSelfDrugAutoWarehouseOutNight(patient_id int64, advicedate int64, drugid int64, adviceid int64) (night []*models.XtSelfDrugWarehouseOutInfo, err error) {
251
+
252
+	err = XTReadDB().Where("patient_id = ? and sys_record_time =? and drug_id = ? and status = 1 and advice_id = ?", patient_id, advicedate, drugid, adviceid).Find(&night).Error
253
+	return night, err
254
+}
255
+
238 256
 func UpdateDrugWarehouse(id int64, info models.DrugWarehouseInfo) error {
239 257
 	err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
240 258
 	return err
241 259
 }
242 260
 
261
+func UpdateSelfDrugWarehouseOne(id int64, info models.XtSelfDrugWarehouseInfo) error {
262
+	err := writeDb.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
263
+	return err
264
+}
265
+
243 266
 func UpdateDrugWarehouseOne(id int64, info models.DrugWarehouseInfo) error {
244 267
 	err := writeDb.Model(&models.DrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
245 268
 	return err
246 269
 }
247 270
 
271
+func UpdateSelfDrugWarehouseTwo(id int64, info models.XtSelfDrugWarehouseInfo) error {
272
+	err := writeDb.Model(&models.XtSelfDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
273
+	return err
274
+}
275
+
248 276
 func GetBaseDrugLibList(org_id int64, keyword string, page int64, limit int64, is_use int64, is_charge int64, is_inject int64, manufacturer int64, isRecord int64) (list []*models.BaseDrugLib, total int64, err error) {
249 277
 
250 278
 	db := readDb.Model(&models.BaseDrugLib{}).Where("org_id = ?  AND status = 1", org_id)

+ 34 - 0
service/new_stock_service.go View File

@@ -379,6 +379,18 @@ func AddCancelSumCountOne(storehouse_id int64, drug_id int64, user_org_id int64,
379 379
 	return err
380 380
 }
381 381
 
382
+func AddSelfCancelSumCountOne(patient_id int64, drug_id int64, user_org_id int64, cancel_count int64) error {
383
+
384
+	db := writeDb.Begin()
385
+	err = db.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id  = ? and drug_id = ? and status = 1", user_org_id, patient_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
386
+	if err != nil {
387
+		db.Rollback()
388
+		return err
389
+	}
390
+	db.Commit()
391
+	return err
392
+}
393
+
382 394
 func AddNewCancelSumCountOne(storehouse_id int64, drug_id int64, user_org_id int64, cancel_count int64, tx *gorm.DB) error {
383 395
 
384 396
 	err = tx.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id  = ? and drug_id = ? and status = 1", user_org_id, storehouse_id, drug_id).UpdateColumn("sum_cancel_count", gorm.Expr("sum_cancel_count + ?", cancel_count)).Error
@@ -416,6 +428,17 @@ func UpdateSumDrug(orgid int64, storehouse_id int64, drug_id int64, flush_count
416 428
 	return err
417 429
 }
418 430
 
431
+func UpdateSumDrugTwo(orgid int64, patient_id int64, drug_id int64, flush_count int64) error {
432
+	db := writeDb.Begin()
433
+	err := db.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1", orgid, patient_id, drug_id).Update(map[string]interface{}{"flush_count": flush_count}).Error
434
+	if err != nil {
435
+		db.Rollback()
436
+		return err
437
+	}
438
+	db.Commit()
439
+	return err
440
+}
441
+
419 442
 func UpdateSumOutDrug(orgid int64, storehouse_id int64, drug_id int64, sum_out_count int64) error {
420 443
 	db := writeDb.Begin()
421 444
 	err := db.Model(&models.XtDrugStockCount{}).Where("user_org_id = ? and storehouse_id = ? and drug_id = ? and status = 1", orgid, storehouse_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", sum_out_count)).Error
@@ -427,6 +450,17 @@ func UpdateSumOutDrug(orgid int64, storehouse_id int64, drug_id int64, sum_out_c
427 450
 	return err
428 451
 }
429 452
 
453
+func UpdateSelfSumOutDrug(orgid int64, patient_id int64, drug_id int64, sum_out_count int64) error {
454
+	db := writeDb.Begin()
455
+	err := db.Model(&models.XtSelfDrugStockCount{}).Where("user_org_id = ? and patient_id = ? and drug_id = ? and status = 1", orgid, patient_id, drug_id).UpdateColumn("sum_out_count", gorm.Expr("sum_out_count - ?", sum_out_count)).Error
456
+	if err != nil {
457
+		db.Rollback()
458
+		return err
459
+	}
460
+	db.Commit()
461
+	return err
462
+}
463
+
430 464
 func GetAutoGoodLastCount(goodid int64, count int64, record_time int64, patient_id int64) (models.AutomaticReduceDetail, error) {
431 465
 
432 466
 	detail := models.AutomaticReduceDetail{}

+ 5 - 4
service/patientmanage_service.go View File

@@ -1,13 +1,14 @@
1 1
 package service
2 2
 
3 3
 import (
4
-	"XT_New/models"
5 4
 	"encoding/json"
6 5
 	"fmt"
7
-	"github.com/jinzhu/gorm"
8 6
 	"strconv"
9 7
 	"strings"
10 8
 	"time"
9
+
10
+	"XT_New/models"
11
+	"github.com/jinzhu/gorm"
11 12
 )
12 13
 
13 14
 func GetIllnessListTwo() (ills []*models.Illness, err error) {
@@ -950,14 +951,14 @@ func GetNewPatient(id int64) (models.XtPatientsNew, error) {
950 951
 
951 952
 func UpdatedPatient(patients models.Patients, id int64) error {
952 953
 
953
-	err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "remark": patients.Remark, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan}).Error
954
+	err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan}).Error
954 955
 
955 956
 	return err
956 957
 }
957 958
 
958 959
 func UpdateXtPatientNew(patients models.XtPatientsNew, id int64) error {
959 960
 
960
-	err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "remark": patients.Remark, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan}).Error
961
+	err := XTWriteDB().Model(&patients).Where("id=?", id).Update(map[string]interface{}{"name": patients.Name, "gender": patients.Gender, "birthday": patients.Birthday, "age": patients.Age, "phone": patients.Phone, "lapseto": patients.Lapseto, "admission_number": patients.AdmissionNumber, "first_dialysis_date": patients.FirstDialysisDate, "diagnose": patients.Diagnose, "source": patients.Source, "dialysis_no": patients.DialysisNo, "avatar": patients.Avatar, "id_card_no": patients.IdCardNo, "is_infectious": patients.IsInfectious, "out_reason": patients.OutReason, "death_time": patients.DeathTime, "relative_phone": patients.RelativePhone, "sch_remark": patients.SchRemark, "treatment_plan": patients.TreatmentPlan}).Error
961 962
 
962 963
 	return err
963 964
 }

+ 669 - 3
service/self_drug_service.go View File

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"strconv"
5 6
 	"time"
6 7
 
7 8
 	"XT_New/models"
@@ -1293,6 +1294,19 @@ func GetDrugNameByword(orgid int64, keyword string) (list []*models.XtBaseDrug,
1293 1294
 	return list, err
1294 1295
 }
1295 1296
 
1297
+func GetDrugNameBywordOne(orgid int64, keyword string) (list []*models.XtBaseDrug, err error) {
1298
+	likeKey := "%" + keyword + "%"
1299
+	db := XTReadDB().Model(&list).Where("status = 1 and is_self_drug =1")
1300
+	if orgid > 0 {
1301
+		db = db.Where("org_id = ?", orgid)
1302
+	}
1303
+	if len(keyword) > 0 {
1304
+		db = db.Where("drug_name like ?", likeKey)
1305
+	}
1306
+	err = db.Find(&list).Error
1307
+	return list, err
1308
+}
1309
+
1296 1310
 func GetGoodWarehouseInfoByOrgId(orgid int64, storehouse_id int64) (info []*models.WarehousingInfo, err error) {
1297 1311
 	db := XTReadDB().Model(&info).Where("is_check =1 and status =1")
1298 1312
 	if orgid > 0 {
@@ -3841,8 +3855,11 @@ func GetSelfDrugQuery(user_org_id int64, ids []int64) (drug []*models.XtSelfDrug
3841 3855
 	if len(ids) > 0 {
3842 3856
 		db = db.Where("drug_id in(?)", ids)
3843 3857
 	}
3858
+	if user_org_id > 0 {
3859
+		db = db.Where("user_org_id = ?", user_org_id)
3860
+	}
3844 3861
 
3845
-	err = db.Count(&total).Where("user_org_id = ? and status=1", user_org_id).Preload("BaseDrugLib", "org_id = ? and status =1", user_org_id).Find(&drug).Error
3862
+	err = db.Preload("BaseDrugLib", "org_id = ? and status =1", user_org_id).Find(&drug).Error
3846 3863
 
3847 3864
 	return drug, total, err
3848 3865
 }
@@ -4249,7 +4266,7 @@ func GetSelfDrugFlow(drug_id int64, start_time int64, end_time int64, user_org_i
4249 4266
 	return flow, total, err
4250 4267
 }
4251 4268
 
4252
-func GetSelfBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
4269
+func GetSelfBasedrugByIdOne(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
4253 4270
 
4254 4271
 	lib := models.BaseDrugLib{}
4255 4272
 
@@ -4258,6 +4275,29 @@ func GetSelfBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib,
4258 4275
 	return lib, err
4259 4276
 }
4260 4277
 
4278
+func GetSelfDrugStockCountByPatientId(drug_id int64, patient_id int64, user_org_id int64) (models.XtSelfDrugStockCount, error) {
4279
+
4280
+	selfDrugStockCount := models.XtSelfDrugStockCount{}
4281
+	err := XTReadDB().Where("drug_id = ? and patient_id = ? and user_org_id = ? and status =1", drug_id, patient_id, user_org_id).Find(&selfDrugStockCount).Error
4282
+	return selfDrugStockCount, err
4283
+}
4284
+
4285
+func GetSelfBasedrugById(drug_id int64, user_org_id int64, tx *gorm.DB) (models.BaseDrugLib, error) {
4286
+
4287
+	lib := models.BaseDrugLib{}
4288
+
4289
+	err := tx.Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
4290
+
4291
+	if err != gorm.ErrRecordNotFound {
4292
+		if err != nil {
4293
+			tx.Rollback()
4294
+			return lib, err
4295
+		}
4296
+	}
4297
+
4298
+	return lib, err
4299
+}
4300
+
4261 4301
 func GetSelfDrugBatchNumberList(drug_id int64, start_time int64, end_time int64, user_org_id int64, page int64, limit int64, patient_id int64) (flow []*models.XtSelfDrugFlow, total int64, err error) {
4262 4302
 
4263 4303
 	db := XTReadDB().Model(&flow).Where("status=1 and consumable_type =1")
@@ -4481,7 +4521,7 @@ func UpdateSelfDrugWarehouseOutInfoTen(patient_id int64, sys_record_time int64,
4481 4521
 
4482 4522
 func GetSelfWarehouseInfoByWarehouseInfoTwo(drug_id int64, patient_id int64, org_id int64, tx *gorm.DB) (info []*models.XtSelfDrugWarehouseInfo, err error) {
4483 4523
 
4484
-	err = tx.Where("drug_id =? and patient_id =? and status=1 and org_id =?", drug_id, patient_id, org_id).Find(&info).Error
4524
+	err = tx.Where("drug_id =? and patient_id =? and status=1 and org_id =? and is_check=1", drug_id, patient_id, org_id).Find(&info).Error
4485 4525
 
4486 4526
 	if err != gorm.ErrRecordNotFound {
4487 4527
 		if err != nil {
@@ -4509,3 +4549,629 @@ func GetSelfDrugWarehouseOutDetailByPatientId(patient_id int64, page int64, limi
4509 4549
 
4510 4550
 	return out, total, err
4511 4551
 }
4552
+
4553
+func GetSelfBasedrugByIdTwo(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
4554
+
4555
+	lib := models.BaseDrugLib{}
4556
+
4557
+	err := XTReadDB().Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
4558
+
4559
+	return lib, err
4560
+}
4561
+
4562
+//自动退库分装方法
4563
+
4564
+func SelfDrugAutoAddCancelInfo(advice *models.HisDoctorAdviceInfo, creater int64) error {
4565
+
4566
+	//查询该批次病人该药品出库数据
4567
+	info, _ := GetSelfDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
4568
+	list, _ := GetSelfDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
4569
+
4570
+	//退库
4571
+	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
4572
+
4573
+	//如果剩余数量 + 退库数量 < 总入库数量
4574
+	if len(list) > 0 {
4575
+		for _, its := range list {
4576
+			//查询该批次病人该药品出库数据
4577
+			infos, _ := GetSelfDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
4578
+
4579
+			//查询该药品出库批次总入库数量
4580
+			druginfo, _ := GetSelfDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
4581
+
4582
+			var out_count int64  //该批次出库库存
4583
+			var sum_count int64  //该批次总库存
4584
+			var over_count int64 //剩余数量
4585
+
4586
+			if druginfo.MaxUnit != druginfo.MinUnit {
4587
+				over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
4588
+			}
4589
+			if druginfo.MaxUnit == druginfo.MinUnit {
4590
+				over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
4591
+			}
4592
+
4593
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4594
+				out_count = infos.Count * drug.MinNumber
4595
+
4596
+			}
4597
+			if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4598
+				out_count = infos.Count
4599
+			}
4600
+
4601
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4602
+				out_count = infos.Count
4603
+			}
4604
+
4605
+			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4606
+				sum_count = druginfo.WarehousingCount * drug.MinNumber
4607
+			}
4608
+
4609
+			if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4610
+				sum_count = druginfo.WarehousingCount
4611
+			}
4612
+
4613
+			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4614
+				sum_count = druginfo.WarehousingCount
4615
+			}
4616
+
4617
+			if (over_count + out_count) <= sum_count {
4618
+				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4619
+					//退库
4620
+					warehouseInfo := models.XtSelfDrugWarehouseInfo{
4621
+						StockMinNumber: its.Count,
4622
+					}
4623
+					UpdateSelfDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
4624
+
4625
+					//增加退库数量
4626
+					AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count)
4627
+					//出库数量减少
4628
+					UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count)
4629
+
4630
+				}
4631
+				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4632
+					warehouseInfo := models.XtSelfDrugWarehouseInfo{
4633
+						StockMaxNumber: its.Count,
4634
+					}
4635
+					UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
4636
+
4637
+					//增加退库数量
4638
+					AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
4639
+					//出库数量减少
4640
+					UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
4641
+				}
4642
+
4643
+				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4644
+					warehouseInfo := models.XtSelfDrugWarehouseInfo{
4645
+						StockMaxNumber: its.Count,
4646
+					}
4647
+					UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
4648
+					//增加退库数量
4649
+					AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
4650
+					//出库数量减少
4651
+					UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
4652
+				}
4653
+
4654
+			}
4655
+		}
4656
+
4657
+		floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
4658
+		prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
4659
+
4660
+		if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4661
+
4662
+			//查询剩余库存
4663
+			stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
4664
+			var sum_count int64
4665
+			for _, its := range stockInfo {
4666
+				if its.MaxUnit == drug.MaxUnit {
4667
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
4668
+				}
4669
+				sum_count += its.StockMaxNumber + its.StockMinNumber
4670
+			}
4671
+			var count_one int64
4672
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4673
+				count_one = prescribingNumber * drug.MinNumber
4674
+			}
4675
+			if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4676
+				count_one = prescribingNumber
4677
+			}
4678
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4679
+				count_one = prescribingNumber * drug.MinNumber
4680
+			}
4681
+			flow := models.XtSelfDrugFlow{
4682
+				WarehousingId:           info.WarehouseInfoId,
4683
+				DrugId:                  info.DrugId,
4684
+				Number:                  "",
4685
+				BatchNumber:             info.BatchNumber,
4686
+				Count:                   count_one,
4687
+				UserOrgId:               advice.UserOrgId,
4688
+				PatientId:               advice.PatientId,
4689
+				SystemTime:              info.SysRecordTime,
4690
+				ConsumableType:          7,
4691
+				IsSys:                   0,
4692
+				WarehousingOrder:        "",
4693
+				WarehouseOutId:          0,
4694
+				WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
4695
+				IsEdit:                  0,
4696
+				CancelStockId:           0,
4697
+				CancelOrderNumber:       "",
4698
+				Manufacturer:            info.Manufacturer,
4699
+				Dealer:                  info.Dealer,
4700
+				Creator:                 creater,
4701
+				UpdateCreator:           0,
4702
+				Status:                  1,
4703
+				Ctime:                   info.SysRecordTime,
4704
+				Mtime:                   0,
4705
+				Price:                   info.Price,
4706
+				WarehousingDetailId:     info.WarehouseInfoId,
4707
+				WarehouseOutDetailId:    0,
4708
+				CancelOutDetailId:       0,
4709
+				ExpireDate:              info.ExpiryDate,
4710
+				ProductDate:             info.ProductDate,
4711
+				MaxUnit:                 drug.MinUnit,
4712
+				MinUnit:                 "",
4713
+				AdviceId:                info.AdviceId,
4714
+				StorehouseId:            0,
4715
+				OverCount:               sum_count,
4716
+				OperateTime:             time.Now().Unix(),
4717
+			}
4718
+			CreateSelfDrugFlowTwo(flow)
4719
+
4720
+			//删除出库记录
4721
+			UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
4722
+			//删除流水
4723
+			UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
4724
+		}
4725
+		if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4726
+
4727
+			//查询剩余库存
4728
+			stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
4729
+			var sum_count int64
4730
+			for _, its := range stockInfo {
4731
+				if its.MaxUnit == drug.MaxUnit {
4732
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
4733
+				}
4734
+				sum_count += its.StockMaxNumber + its.StockMinNumber
4735
+			}
4736
+
4737
+			var count_one int64
4738
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4739
+				count_one = prescribingNumber * drug.MinNumber
4740
+			}
4741
+			if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4742
+				count_one = prescribingNumber
4743
+			}
4744
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4745
+				count_one = prescribingNumber * drug.MinNumber
4746
+			}
4747
+
4748
+			flow := models.XtSelfDrugFlow{
4749
+				WarehousingId:           info.WarehouseInfoId,
4750
+				DrugId:                  info.DrugId,
4751
+				Number:                  "",
4752
+				BatchNumber:             info.BatchNumber,
4753
+				Count:                   count_one,
4754
+				UserOrgId:               advice.UserOrgId,
4755
+				PatientId:               advice.PatientId,
4756
+				SystemTime:              info.SysRecordTime,
4757
+				ConsumableType:          7,
4758
+				IsSys:                   0,
4759
+				WarehousingOrder:        "",
4760
+				WarehouseOutId:          0,
4761
+				WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
4762
+				IsEdit:                  0,
4763
+				CancelStockId:           0,
4764
+				CancelOrderNumber:       "",
4765
+				Manufacturer:            info.Manufacturer,
4766
+				Dealer:                  info.Dealer,
4767
+				Creator:                 creater,
4768
+				UpdateCreator:           0,
4769
+				Status:                  1,
4770
+				Ctime:                   info.SysRecordTime,
4771
+				Mtime:                   0,
4772
+				Price:                   info.Price,
4773
+				WarehousingDetailId:     info.WarehouseInfoId,
4774
+				WarehouseOutDetailId:    0,
4775
+				CancelOutDetailId:       0,
4776
+				ExpireDate:              info.ExpiryDate,
4777
+				ProductDate:             info.ProductDate,
4778
+				MaxUnit:                 drug.MinUnit,
4779
+				MinUnit:                 "",
4780
+				AdviceId:                info.AdviceId,
4781
+				StorehouseId:            0,
4782
+				OverCount:               sum_count,
4783
+				OperateTime:             time.Now().Unix(),
4784
+			}
4785
+
4786
+			CreateSelfDrugFlowTwo(flow)
4787
+			//删除出库记录
4788
+			UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
4789
+			//删除流水
4790
+			UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
4791
+		}
4792
+
4793
+		if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4794
+
4795
+			//查询剩余库存
4796
+			stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
4797
+			var sum_count int64
4798
+			for _, its := range stockInfo {
4799
+				if its.MaxUnit == drug.MaxUnit {
4800
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
4801
+				}
4802
+				sum_count += its.StockMaxNumber + its.StockMinNumber
4803
+			}
4804
+
4805
+			flow := models.XtSelfDrugFlow{
4806
+				WarehousingId:           info.WarehouseInfoId,
4807
+				DrugId:                  info.DrugId,
4808
+				Number:                  "",
4809
+				BatchNumber:             info.BatchNumber,
4810
+				Count:                   prescribingNumber,
4811
+				UserOrgId:               advice.UserOrgId,
4812
+				PatientId:               advice.PatientId,
4813
+				SystemTime:              info.SysRecordTime,
4814
+				ConsumableType:          7,
4815
+				IsSys:                   0,
4816
+				WarehousingOrder:        "",
4817
+				WarehouseOutId:          0,
4818
+				WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
4819
+				IsEdit:                  0,
4820
+				CancelStockId:           0,
4821
+				CancelOrderNumber:       "",
4822
+				Manufacturer:            info.Manufacturer,
4823
+				Dealer:                  info.Dealer,
4824
+				Creator:                 creater,
4825
+				UpdateCreator:           0,
4826
+				Status:                  1,
4827
+				Ctime:                   info.SysRecordTime,
4828
+				Mtime:                   0,
4829
+				Price:                   info.Price,
4830
+				WarehousingDetailId:     info.WarehouseInfoId,
4831
+				WarehouseOutDetailId:    0,
4832
+				CancelOutDetailId:       0,
4833
+				ExpireDate:              info.ExpiryDate,
4834
+				ProductDate:             info.ProductDate,
4835
+				MaxUnit:                 advice.PrescribingNumberUnit,
4836
+				MinUnit:                 "",
4837
+				AdviceId:                info.AdviceId,
4838
+				StorehouseId:            0,
4839
+				OverCount:               sum_count,
4840
+				OperateTime:             time.Now().Unix(),
4841
+			}
4842
+
4843
+			CreateSelfDrugFlowTwo(flow)
4844
+			//删除出库记录
4845
+			UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
4846
+			//删除流水
4847
+			UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
4848
+		}
4849
+
4850
+		//更新字典里面的库存
4851
+		stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
4852
+		//查询改药品信息
4853
+		medical, _ := GetBaseDrugMedical(advice.DrugId)
4854
+		var sum_count_one int64
4855
+		for _, its := range stockInfo {
4856
+			if its.MaxUnit == medical.MaxUnit {
4857
+				its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
4858
+			}
4859
+			sum_count_one += its.StockMaxNumber + its.StockMinNumber
4860
+		}
4861
+
4862
+		//更新库存
4863
+		UpdateSumDrugTwo(advice.UserOrgId, advice.PatientId, advice.DrugId, sum_count_one)
4864
+
4865
+	}
4866
+	return err
4867
+}
4868
+
4869
+func SelfDrugAutoAddCancelInfoOne(advice *models.DoctorAdvice, creater int64) error {
4870
+
4871
+	//查询该批次病人该药品出库数据
4872
+	info, _ := GetSelfDrugAutoWarehouseOutEight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
4873
+	list, _ := GetSelfDrugAutoWarehouseOutNight(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
4874
+
4875
+	//退库
4876
+	drug, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
4877
+
4878
+	//如果剩余数量 + 退库数量 < 总入库数量
4879
+	if len(list) > 0 {
4880
+		for _, its := range list {
4881
+			//查询该批次病人该药品出库数据
4882
+			infos, _ := GetSelfDrugAutoWarehouseOutTen(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID, its.WarehouseInfoId)
4883
+
4884
+			//查询该药品出库批次总入库数量
4885
+			druginfo, _ := GetSelfDrugInfoSix(its.WarehouseInfoId, infos.OrgId)
4886
+
4887
+			var out_count int64  //该批次出库库存
4888
+			var sum_count int64  //该批次总库存
4889
+			var over_count int64 //剩余数量
4890
+
4891
+			if druginfo.MaxUnit != druginfo.MinUnit {
4892
+				over_count = druginfo.StockMaxNumber*drug.MinNumber + druginfo.StockMinNumber
4893
+			}
4894
+			if druginfo.MaxUnit == druginfo.MinUnit {
4895
+				over_count = druginfo.StockMaxNumber + druginfo.StockMinNumber
4896
+			}
4897
+
4898
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4899
+				out_count = infos.Count * drug.MinNumber
4900
+
4901
+			}
4902
+			if infos.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4903
+				out_count = infos.Count
4904
+			}
4905
+
4906
+			if infos.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4907
+				out_count = infos.Count
4908
+			}
4909
+
4910
+			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4911
+				sum_count = druginfo.WarehousingCount * drug.MinNumber
4912
+			}
4913
+
4914
+			if druginfo.MaxUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4915
+				sum_count = druginfo.WarehousingCount
4916
+			}
4917
+
4918
+			if druginfo.MaxUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4919
+				sum_count = druginfo.WarehousingCount
4920
+			}
4921
+			fmt.Println("over_count-----------", over_count)
4922
+			fmt.Println("out_count-----------", out_count)
4923
+			fmt.Println("sum_count-----------", sum_count)
4924
+			fmt.Println("its.count-------------", its.CountUnit)
4925
+			fmt.Println("drug.MaxUnit-------------", drug.MaxUnit)
4926
+			fmt.Println("drug.MinUnit-------------", drug.MinUnit)
4927
+			if (over_count + out_count) <= sum_count {
4928
+				if its.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4929
+					//退库
4930
+					warehouseInfo := models.XtSelfDrugWarehouseInfo{
4931
+						StockMinNumber: its.Count,
4932
+					}
4933
+					UpdateSelfDrugWarehouseOne(its.WarehouseInfoId, warehouseInfo)
4934
+
4935
+					//增加退库数量
4936
+					AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count)
4937
+					//出库数量减少
4938
+					UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count)
4939
+
4940
+				}
4941
+				if its.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4942
+					warehouseInfo := models.XtSelfDrugWarehouseInfo{
4943
+						StockMaxNumber: its.Count,
4944
+					}
4945
+					UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
4946
+
4947
+					//增加退库数量
4948
+					AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
4949
+					//出库数量减少
4950
+					UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
4951
+				}
4952
+
4953
+				if its.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4954
+					warehouseInfo := models.XtSelfDrugWarehouseInfo{
4955
+						StockMaxNumber: its.Count,
4956
+					}
4957
+					UpdateSelfDrugWarehouseTwo(its.WarehouseInfoId, warehouseInfo)
4958
+					//增加退库数量
4959
+					AddSelfCancelSumCountOne(advice.PatientId, advice.DrugId, advice.UserOrgId, its.Count*drug.MinNumber)
4960
+					//出库数量减少
4961
+					UpdateSelfSumOutDrug(advice.UserOrgId, advice.PatientId, advice.DrugId, its.Count*drug.MinNumber)
4962
+				}
4963
+
4964
+			}
4965
+		}
4966
+
4967
+		floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
4968
+		prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
4969
+
4970
+		if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4971
+
4972
+			//查询剩余库存
4973
+			stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
4974
+			var sum_count int64
4975
+			for _, its := range stockInfo {
4976
+				if its.MaxUnit == drug.MaxUnit {
4977
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
4978
+				}
4979
+				sum_count += its.StockMaxNumber + its.StockMinNumber
4980
+			}
4981
+			var count_one int64
4982
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
4983
+				count_one = prescribingNumber * drug.MinNumber
4984
+			}
4985
+			if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
4986
+				count_one = prescribingNumber
4987
+			}
4988
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
4989
+				count_one = prescribingNumber * drug.MinNumber
4990
+			}
4991
+			flow := models.XtSelfDrugFlow{
4992
+				WarehousingId:           info.WarehouseInfoId,
4993
+				DrugId:                  info.DrugId,
4994
+				Number:                  "",
4995
+				BatchNumber:             info.BatchNumber,
4996
+				Count:                   count_one,
4997
+				UserOrgId:               advice.UserOrgId,
4998
+				PatientId:               advice.PatientId,
4999
+				SystemTime:              info.SysRecordTime,
5000
+				ConsumableType:          7,
5001
+				IsSys:                   0,
5002
+				WarehousingOrder:        "",
5003
+				WarehouseOutId:          0,
5004
+				WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
5005
+				IsEdit:                  0,
5006
+				CancelStockId:           0,
5007
+				CancelOrderNumber:       "",
5008
+				Manufacturer:            info.Manufacturer,
5009
+				Dealer:                  info.Dealer,
5010
+				Creator:                 creater,
5011
+				UpdateCreator:           0,
5012
+				Status:                  1,
5013
+				Ctime:                   info.SysRecordTime,
5014
+				Mtime:                   0,
5015
+				Price:                   info.Price,
5016
+				WarehousingDetailId:     info.WarehouseInfoId,
5017
+				WarehouseOutDetailId:    0,
5018
+				CancelOutDetailId:       0,
5019
+				ExpireDate:              info.ExpiryDate,
5020
+				ProductDate:             info.ProductDate,
5021
+				MaxUnit:                 drug.MinUnit,
5022
+				MinUnit:                 "",
5023
+				AdviceId:                info.AdviceId,
5024
+				StorehouseId:            0,
5025
+				OverCount:               sum_count,
5026
+				OperateTime:             time.Now().Unix(),
5027
+			}
5028
+			CreateSelfDrugFlowTwo(flow)
5029
+
5030
+			//删除出库记录
5031
+			UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
5032
+			//删除流水
5033
+			UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
5034
+		}
5035
+		if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
5036
+
5037
+			//查询剩余库存
5038
+			stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
5039
+			var sum_count int64
5040
+			for _, its := range stockInfo {
5041
+				if its.MaxUnit == drug.MaxUnit {
5042
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
5043
+				}
5044
+				sum_count += its.StockMaxNumber + its.StockMinNumber
5045
+			}
5046
+
5047
+			var count_one int64
5048
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
5049
+				count_one = prescribingNumber * drug.MinNumber
5050
+			}
5051
+			if advice.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
5052
+				count_one = prescribingNumber
5053
+			}
5054
+			if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
5055
+				count_one = prescribingNumber * drug.MinNumber
5056
+			}
5057
+
5058
+			flow := models.XtSelfDrugFlow{
5059
+				WarehousingId:           info.WarehouseInfoId,
5060
+				DrugId:                  info.DrugId,
5061
+				Number:                  "",
5062
+				BatchNumber:             info.BatchNumber,
5063
+				Count:                   count_one,
5064
+				UserOrgId:               advice.UserOrgId,
5065
+				PatientId:               advice.PatientId,
5066
+				SystemTime:              info.SysRecordTime,
5067
+				ConsumableType:          7,
5068
+				IsSys:                   0,
5069
+				WarehousingOrder:        "",
5070
+				WarehouseOutId:          0,
5071
+				WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
5072
+				IsEdit:                  0,
5073
+				CancelStockId:           0,
5074
+				CancelOrderNumber:       "",
5075
+				Manufacturer:            info.Manufacturer,
5076
+				Dealer:                  info.Dealer,
5077
+				Creator:                 creater,
5078
+				UpdateCreator:           0,
5079
+				Status:                  1,
5080
+				Ctime:                   info.SysRecordTime,
5081
+				Mtime:                   0,
5082
+				Price:                   info.Price,
5083
+				WarehousingDetailId:     info.WarehouseInfoId,
5084
+				WarehouseOutDetailId:    0,
5085
+				CancelOutDetailId:       0,
5086
+				ExpireDate:              info.ExpiryDate,
5087
+				ProductDate:             info.ProductDate,
5088
+				MaxUnit:                 drug.MinUnit,
5089
+				MinUnit:                 "",
5090
+				AdviceId:                info.AdviceId,
5091
+				StorehouseId:            0,
5092
+				OverCount:               sum_count,
5093
+				OperateTime:             time.Now().Unix(),
5094
+			}
5095
+
5096
+			CreateSelfDrugFlowTwo(flow)
5097
+			//删除出库记录
5098
+			UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
5099
+			//删除流水
5100
+			UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
5101
+		}
5102
+
5103
+		if advice.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
5104
+
5105
+			//查询剩余库存
5106
+			stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
5107
+			var sum_count int64
5108
+			for _, its := range stockInfo {
5109
+				if its.MaxUnit == drug.MaxUnit {
5110
+					its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
5111
+				}
5112
+				sum_count += its.StockMaxNumber + its.StockMinNumber
5113
+			}
5114
+
5115
+			flow := models.XtSelfDrugFlow{
5116
+				WarehousingId:           info.WarehouseInfoId,
5117
+				DrugId:                  info.DrugId,
5118
+				Number:                  "",
5119
+				BatchNumber:             info.BatchNumber,
5120
+				Count:                   prescribingNumber,
5121
+				UserOrgId:               advice.UserOrgId,
5122
+				PatientId:               advice.PatientId,
5123
+				SystemTime:              info.SysRecordTime,
5124
+				ConsumableType:          7,
5125
+				IsSys:                   0,
5126
+				WarehousingOrder:        "",
5127
+				WarehouseOutId:          0,
5128
+				WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
5129
+				IsEdit:                  0,
5130
+				CancelStockId:           0,
5131
+				CancelOrderNumber:       "",
5132
+				Manufacturer:            info.Manufacturer,
5133
+				Dealer:                  info.Dealer,
5134
+				Creator:                 creater,
5135
+				UpdateCreator:           0,
5136
+				Status:                  1,
5137
+				Ctime:                   info.SysRecordTime,
5138
+				Mtime:                   0,
5139
+				Price:                   info.Price,
5140
+				WarehousingDetailId:     info.WarehouseInfoId,
5141
+				WarehouseOutDetailId:    0,
5142
+				CancelOutDetailId:       0,
5143
+				ExpireDate:              info.ExpiryDate,
5144
+				ProductDate:             info.ProductDate,
5145
+				MaxUnit:                 advice.PrescribingNumberUnit,
5146
+				MinUnit:                 "",
5147
+				AdviceId:                info.AdviceId,
5148
+				StorehouseId:            0,
5149
+				OverCount:               sum_count,
5150
+				OperateTime:             time.Now().Unix(),
5151
+			}
5152
+
5153
+			CreateSelfDrugFlowTwo(flow)
5154
+			//删除出库记录
5155
+			UpdateSelfDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID, info.ID)
5156
+			//删除流水
5157
+			UpdateDrugFlowTensOne(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
5158
+		}
5159
+
5160
+		//更新字典里面的库存
5161
+		stockInfo, _ := GetSelfDrugAllStockInfoOne(advice.PatientId, advice.UserOrgId, advice.DrugId)
5162
+		//查询改药品信息
5163
+		medical, _ := GetBaseDrugMedical(advice.DrugId)
5164
+		var sum_count_one int64
5165
+		for _, its := range stockInfo {
5166
+			if its.MaxUnit == medical.MaxUnit {
5167
+				its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
5168
+			}
5169
+			sum_count_one += its.StockMaxNumber + its.StockMinNumber
5170
+		}
5171
+
5172
+		//更新库存
5173
+		UpdateSumDrugTwo(advice.UserOrgId, advice.PatientId, advice.DrugId, sum_count_one)
5174
+
5175
+	}
5176
+	return err
5177
+}

+ 37 - 0
service/stock_service.go View File

@@ -750,6 +750,17 @@ func CreateDrugFlowOne(flow models.DrugFlow) error {
750 750
 	return err
751 751
 }
752 752
 
753
+func CreateSelfDrugFlowTwo(flow models.XtSelfDrugFlow) error {
754
+	ut := writeDb.Begin()
755
+	err := ut.Create(&flow).Error
756
+	if err != nil {
757
+		ut.Rollback()
758
+		return err
759
+	}
760
+	ut.Commit()
761
+	return err
762
+}
763
+
753 764
 func CreateNewDrugFlowOne(flow models.DrugFlow, tx *gorm.DB) error {
754 765
 
755 766
 	err := tx.Create(&flow).Error
@@ -767,12 +778,25 @@ func UpdateDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice
767 778
 	return detail, err
768 779
 }
769 780
 
781
+func UpdateSelfDrugFlowSeven(patientid int64, recorddate int64, drugid int64, advice_id int64, id int64) (models.XtSelfDrugWarehouseOutInfo, error) {
782
+
783
+	detail := models.XtSelfDrugWarehouseOutInfo{}
784
+	err = XTWriteDB().Model(&models.XtSelfDrugWarehouseOutInfo{}).Where("patient_id =? and sys_record_time =? and drug_id = ? and status = 1 and advice_id =?", patientid, recorddate, drugid, advice_id).Updates(map[string]interface{}{"status": 0}).Error
785
+	return detail, err
786
+}
787
+
770 788
 func UpdateDrugFlowTens(patientid int64, warehouse_out_number string, drug_id int64, advice_id int64) (models.DrugFlow, error) {
771 789
 	flow := models.DrugFlow{}
772 790
 	err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"is_read": 1}).Error
773 791
 	return flow, err
774 792
 }
775 793
 
794
+func UpdateDrugFlowTensOne(patientid int64, warehouse_out_number string, drug_id int64, advice_id int64) (models.XtSelfDrugFlow, error) {
795
+	flow := models.XtSelfDrugFlow{}
796
+	err := XTWriteDB().Model(&flow).Where("patient_id =? and warehouse_out_order_number = ? and drug_id = ? and status = 1 and advice_id =?", patientid, warehouse_out_number, drug_id, advice_id).Updates(map[string]interface{}{"is_read": 1}).Error
797
+	return flow, err
798
+}
799
+
776 800
 func CreateDrugFlowTwo(flow *models.DrugFlow) error {
777 801
 	tx := XTWriteDB().Begin()
778 802
 	err := tx.Create(&flow).Error
@@ -8444,6 +8468,12 @@ func GetDrugAllStockInfo(storehouse_id int64, orgid int64, drugid int64) (info [
8444 8468
 	return info, err
8445 8469
 }
8446 8470
 
8471
+func GetSelfDrugAllStockInfoOne(patient_id int64, orgid int64, drugid int64) (info []*models.XtSelfDrugWarehouseInfo, err error) {
8472
+
8473
+	err = XTReadDB().Where("patient_id  = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", patient_id, orgid, drugid).Find(&info).Error
8474
+	return info, err
8475
+}
8476
+
8447 8477
 func GetNewDrugAllStockInfo(storehouse_id int64, orgid int64, drugid int64, tx *gorm.DB) (info []*models.DrugWarehouseInfo, err error) {
8448 8478
 
8449 8479
 	err = tx.Where("storehouse_id  = ? and org_id = ? and status = 1 and drug_id = ? and is_check = 1", storehouse_id, orgid, drugid).Find(&info).Error
@@ -8604,6 +8634,13 @@ func GetDrugInfoSix(id int64, orgid int64) (models.DrugWarehouseInfo, error) {
8604 8634
 	return info, err
8605 8635
 }
8606 8636
 
8637
+func GetSelfDrugInfoSix(id int64, orgid int64) (models.XtSelfDrugWarehouseInfo, error) {
8638
+
8639
+	info := models.XtSelfDrugWarehouseInfo{}
8640
+	err := XTReadDB().Where("id = ? and org_id = ? and status = 1 and is_check = 1", id, orgid).Find(&info).Error
8641
+	return info, err
8642
+}
8643
+
8607 8644
 func GetPrintList(storehouse_id int64, good_name string, orgid int64, limit int64, page int64) (storeinventory []*models.XtStockInventory, err error) {
8608 8645
 
8609 8646
 	db := XTReadDB().Model(&storeinventory).Where("status = 1")

+ 328 - 11
service/warhouse_service.go View File

@@ -9915,10 +9915,11 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
9915 9915
 		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
9916 9916
 
9917 9917
 		if lastDrugOutInfo.ID == 0 {
9918
+			advice.WarehouseInfoId = lastWarehouse.ID
9918 9919
 			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
9919 9920
 		}
9920 9921
 		if lastDrugOutInfo.ID > 0 {
9921
-
9922
+			advice.WarehouseInfoId = lastWarehouse.ID
9922 9923
 			//删除在新增
9923 9924
 			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
9924 9925
 
@@ -9973,10 +9974,6 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
9973 9974
 		//出库数量相加
9974 9975
 		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
9975 9976
 
9976
-		fmt.Println("advice-------------------------------------", advice.ID)
9977
-		fmt.Println("warehouse-------------------------------------", warehouse.ID)
9978
-		fmt.Println("over_count====================================", over_count)
9979
-
9980 9977
 		return nil
9981 9978
 
9982 9979
 	} else {
@@ -10006,10 +10003,11 @@ func AutoSelfDrugDeliverInfoFourtyOne(orgID int64, prescribingNumber int64, ware
10006 10003
 		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10007 10004
 
10008 10005
 		if lastDrugOutInfo.ID == 0 {
10006
+			advice.WarehouseInfoId = lastWarehouse.ID
10009 10007
 			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10010 10008
 		}
10011 10009
 		if lastDrugOutInfo.ID > 0 {
10012
-
10010
+			advice.WarehouseInfoId = lastWarehouse.ID
10013 10011
 			//删除在新增
10014 10012
 			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10015 10013
 
@@ -10250,10 +10248,11 @@ func AutoSelfDrugDeliverInfoFourtyTwo(orgID int64, prescribingNumber int64, ware
10250 10248
 		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10251 10249
 
10252 10250
 		if lastDrugOutInfo.ID == 0 {
10251
+			advice.WarehouseInfoId = lastWarehouse.ID
10253 10252
 			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10254 10253
 		}
10255 10254
 		if lastDrugOutInfo.ID > 0 {
10256
-
10255
+			advice.WarehouseInfoId = lastWarehouse.ID
10257 10256
 			//删除在新增
10258 10257
 			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10259 10258
 
@@ -10308,9 +10307,9 @@ func AutoSelfDrugDeliverInfoFourtyTwo(orgID int64, prescribingNumber int64, ware
10308 10307
 		//出库数量相加
10309 10308
 		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
10310 10309
 
10311
-		fmt.Println("advice-------------------------------------", advice.ID)
10312
-		fmt.Println("warehouse-------------------------------------", warehouse.ID)
10313
-		fmt.Println("over_count====================================", over_count)
10310
+		//fmt.Println("advice-------------------------------------", advice.ID)
10311
+		//fmt.Println("warehouse-------------------------------------", warehouse.ID)
10312
+		//fmt.Println("over_count====================================", over_count)
10314 10313
 
10315 10314
 		return nil
10316 10315
 
@@ -10341,10 +10340,11 @@ func AutoSelfDrugDeliverInfoFourtyTwo(orgID int64, prescribingNumber int64, ware
10341 10340
 		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10342 10341
 
10343 10342
 		if lastDrugOutInfo.ID == 0 {
10343
+			advice.WarehouseInfoId = lastWarehouse.ID
10344 10344
 			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10345 10345
 		}
10346 10346
 		if lastDrugOutInfo.ID > 0 {
10347
-
10347
+			advice.WarehouseInfoId = lastWarehouse.ID
10348 10348
 			//删除在新增
10349 10349
 			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10350 10350
 
@@ -10404,3 +10404,320 @@ func AutoSelfDrugDeliverInfoFourtyTwo(orgID int64, prescribingNumber int64, ware
10404 10404
 
10405 10405
 	return
10406 10406
 }
10407
+
10408
+func AutoSelfDrugDeliverInfoFourtyThree(orgID int64, prescribingNumber int64, warehouseout *models.XtSelfDrugWarehouseOut, drup *models.BaseDrugLib, advice *models.XtSelfDrugWarehouseOutInfo, unit string, tx *gorm.DB) (err error) {
10409
+
10410
+	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
10411
+	var deliver_number int64 = 0
10412
+
10413
+	var stock_number int64 = 0
10414
+
10415
+	var drug_price float64
10416
+	if advice.CountUnit == drup.MaxUnit {
10417
+		deliver_number = prescribingNumber * drup.MinNumber
10418
+
10419
+	} else {
10420
+		deliver_number = prescribingNumber
10421
+
10422
+	}
10423
+	if advice.CountUnit == drup.MaxUnit {
10424
+		drug_price = drup.RetailPrice
10425
+	}
10426
+	fmt.Println(drug_price)
10427
+
10428
+	if advice.CountUnit == drup.MinUnit {
10429
+		drug_price = drup.MinPrice
10430
+	}
10431
+
10432
+	if advice.CountUnit != drup.MaxUnit || advice.CountUnit != drup.MinUnit {
10433
+		drug_price = drup.RetailPrice
10434
+	}
10435
+
10436
+	// 根据先进先出原则,查询最先入库的批次,进行出库
10437
+	// 如果没有对应的库存,则报错
10438
+	lastWarehouse, _ := FindSelfLastDrugWarehousingInfoByID(advice.DrugId, advice.PatientId, tx)
10439
+
10440
+	if lastWarehouse.MaxUnit != lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
10441
+		if lastWarehouse.StockMinNumber >= drup.MinNumber {
10442
+			var stockMax int64
10443
+			var stockMin int64
10444
+			stockMax = lastWarehouse.StockMinNumber / drup.MinNumber
10445
+			stockMin = lastWarehouse.StockMinNumber % drup.MinNumber
10446
+
10447
+			ChangeSelfMaxNumber(lastWarehouse.ID, stockMax, tx)
10448
+			UpdateSelfMinNumber(lastWarehouse.ID, stockMin, tx)
10449
+
10450
+		}
10451
+	}
10452
+
10453
+	if lastWarehouse.MaxUnit == lastWarehouse.MinUnit && drup.MaxUnit != drup.MinUnit && lastWarehouse.MinUnit != "" {
10454
+
10455
+		lastWarehouse.StockMaxNumber = lastWarehouse.StockMaxNumber + lastWarehouse.StockMinNumber
10456
+		ChangeSelfMaxNumberOne(lastWarehouse.ID, lastWarehouse.StockMaxNumber, tx)
10457
+
10458
+	}
10459
+
10460
+	warehouse, err := FindSelfLastDrugWarehousingInfoByID(advice.DrugId, advice.PatientId, tx)
10461
+
10462
+	// 将该批次的剩余库存数量转换为拆零数量
10463
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit != drup.MinUnit {
10464
+
10465
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
10466
+
10467
+	}
10468
+	if warehouse.MaxUnit == drup.MinUnit && drup.MaxUnit != drup.MinUnit {
10469
+
10470
+		stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
10471
+
10472
+	}
10473
+	if warehouse.MaxUnit == drup.MaxUnit && drup.MaxUnit == drup.MinUnit {
10474
+
10475
+		stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
10476
+
10477
+	}
10478
+	if stock_number >= deliver_number {
10479
+
10480
+		var maxNumber int64 = 0
10481
+		var minNumber int64 = 0
10482
+
10483
+		maxNumber = deliver_number / drup.MinNumber
10484
+		minNumber = deliver_number % drup.MinNumber
10485
+
10486
+		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
10487
+			minNumber = maxNumber
10488
+		}
10489
+
10490
+		if drup.MaxUnit != drup.MinUnit {
10491
+			if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
10492
+				return errors.New("库存数量不足")
10493
+			}
10494
+		}
10495
+
10496
+		if drup.MinUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
10497
+
10498
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*drup.MinNumber
10499
+		}
10500
+
10501
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit != drup.MinUnit {
10502
+
10503
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
10504
+		}
10505
+		if drup.MaxUnit == warehouse.MaxUnit && drup.MaxUnit == drup.MinUnit {
10506
+
10507
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
10508
+		}
10509
+
10510
+		if warehouse.StockMaxNumber < 0 {
10511
+			warehouse.StockMaxNumber = 0
10512
+		}
10513
+		if warehouse.StockMinNumber < 0 {
10514
+			warehouse.StockMinNumber = 0
10515
+		}
10516
+
10517
+		warehouse.Mtime = time.Now().Unix()
10518
+
10519
+		if warehouse.StockMinNumber < minNumber {
10520
+			//fmt.Println("金4")
10521
+			warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
10522
+			if warehouse.MaxUnit != warehouse.MinUnit {
10523
+				warehouse.StockMinNumber = warehouse.StockMinNumber + drup.MinNumber - minNumber
10524
+			}
10525
+			if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
10526
+				warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
10527
+			}
10528
+		} else {
10529
+			//fmt.Println("金5")
10530
+			if minNumber > 0 {
10531
+				if (warehouse.StockMinNumber - minNumber) >= 0 {
10532
+					warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
10533
+				}
10534
+
10535
+			}
10536
+
10537
+			if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
10538
+				//fmt.Println("6")
10539
+				if warehouse.StockMinNumber > 0 {
10540
+					if warehouse.StockMinNumber-deliver_number >= 0 {
10541
+						warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
10542
+					}
10543
+
10544
+				}
10545
+
10546
+			}
10547
+
10548
+		}
10549
+
10550
+		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
10551
+			if (warehouse.StockMinNumber - deliver_number) >= 0 {
10552
+				warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
10553
+			}
10554
+
10555
+		}
10556
+
10557
+		if drup.MaxUnit != drup.MinUnit {
10558
+			if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
10559
+				return errors.New("库存数量不足")
10560
+			}
10561
+		}
10562
+		if warehouse.StockMinNumber <= 0 {
10563
+			warehouse.StockMinNumber = 0
10564
+		}
10565
+
10566
+		errThree := UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
10567
+
10568
+		if errThree != nil {
10569
+			return errors.New("扣减库存失败")
10570
+		}
10571
+
10572
+		//查询该药品剩余库存
10573
+		infolist, _ := FindSelfDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId, tx)
10574
+		var over_count int64
10575
+		for _, its := range infolist {
10576
+			if its.MaxUnit == drup.MaxUnit {
10577
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
10578
+			}
10579
+			over_count += its.StockMaxNumber + its.StockMinNumber
10580
+		}
10581
+
10582
+		//drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
10583
+		drugflow := models.XtSelfDrugFlow{
10584
+			WarehouseOutId:          warehouseout.ID,
10585
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
10586
+			DrugId:                  advice.DrugId,
10587
+			Number:                  warehouse.Number,
10588
+			ProductDate:             advice.ProductDate,
10589
+			ExpireDate:              advice.ExpiryDate,
10590
+			Count:                   deliver_number,
10591
+			Price:                   warehouse.RetailPrice,
10592
+			Status:                  1,
10593
+			Ctime:                   advice.SysRecordTime,
10594
+			Mtime:                   time.Now().Unix(),
10595
+			UserOrgId:               advice.OrgId,
10596
+			Manufacturer:            advice.Manufacturer,
10597
+			Dealer:                  advice.Dealer,
10598
+			BatchNumber:             warehouse.BatchNumber,
10599
+			MaxUnit:                 drup.MinUnit,
10600
+			ConsumableType:          2,
10601
+			IsEdit:                  1,
10602
+			Creator:                 0,
10603
+			IsSys:                   0,
10604
+			WarehouseOutDetailId:    advice.ID,
10605
+			AdviceId:                advice.ID,
10606
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10607
+			StorehouseId:            advice.StorehouseId,
10608
+			AdminUserId:             advice.AdminUserId,
10609
+			LastPrice:               warehouse.Price,
10610
+			StockCount:              advice.StockCount,
10611
+			WarehousingDetailId:     warehouse.ID,
10612
+			OverCount:               over_count,
10613
+			RetailPrice:             drug_price, //手动出库出库价格
10614
+			WarehousingId:           warehouse.ID,
10615
+			SystemTime:              advice.SysRecordTime,
10616
+			PatientId:               advice.PatientId,
10617
+			Remark:                  advice.Remark,
10618
+			OperateTime:             time.Now().Unix(),
10619
+		}
10620
+		if warehouse.RetailPrice == 0 {
10621
+			drugflow.Price = advice.Price
10622
+		}
10623
+
10624
+		CreateSelfDrugFlowOne(drugflow, tx)
10625
+
10626
+		//更新出库id
10627
+		UpdateSelfDrugWarehouseOutInfo(advice.ID, warehouse.ID, advice.OrgId, over_count, drug_price, tx)
10628
+
10629
+		//出库数量相加
10630
+		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
10631
+
10632
+		return nil
10633
+
10634
+	} else {
10635
+		stock_number_int := strconv.FormatInt(stock_number, 10)
10636
+		stock_number_int_count, _ := strconv.ParseFloat(stock_number_int, 64)
10637
+		drug_price = stock_number_int_count * advice.Price
10638
+		//扣减库存
10639
+		warehouse.StockMaxNumber = 0
10640
+		warehouse.StockMinNumber = 0
10641
+		warehouse.Mtime = time.Now().Unix()
10642
+
10643
+		errThree := UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
10644
+		if errThree != nil {
10645
+			return errThree
10646
+		}
10647
+
10648
+		//查询该药品剩余库存
10649
+		infolist, _ := FindDrugWarehouseInfoFlushCount(advice.DrugId, advice.OrgId)
10650
+		var over_count int64
10651
+		for _, its := range infolist {
10652
+			if its.MaxUnit == drup.MaxUnit {
10653
+				its.StockMaxNumber = its.StockMaxNumber * drup.MinNumber
10654
+			}
10655
+			over_count += its.StockMaxNumber + its.StockMinNumber
10656
+		}
10657
+		//查询今日该药品该患者是否有出库数据
10658
+		lastDrugOutInfo, _ := GetSelfNewDrugWarehouseOutInfoSix(advice.DrugId, advice.PatientId, advice.SysRecordTime, advice.OrgId, advice.AdviceId, warehouse.ID, tx)
10659
+
10660
+		if lastDrugOutInfo.ID == 0 {
10661
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10662
+		}
10663
+		if lastDrugOutInfo.ID > 0 {
10664
+
10665
+			//删除在新增
10666
+			UpdateSelfDrugWarehouseOutInfoTen(lastDrugOutInfo.PatientId, lastDrugOutInfo.SysRecordTime, advice.ID, tx)
10667
+
10668
+			AddSelfSigleDrugWarehouseOutInfo(advice, tx)
10669
+
10670
+		}
10671
+		//drugWareInfo, _ := GetSelfLastWarehouseOutInfoById(advice.DrugId, tx)
10672
+		drugflow := models.XtSelfDrugFlow{
10673
+			WarehouseOutId:          warehouseout.ID,
10674
+			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
10675
+			DrugId:                  advice.DrugId,
10676
+			Number:                  warehouse.Number,
10677
+			ProductDate:             advice.ProductDate,
10678
+			ExpireDate:              advice.ExpiryDate,
10679
+			Count:                   stock_number,
10680
+			Price:                   warehouse.RetailPrice,
10681
+			Status:                  1,
10682
+			Ctime:                   advice.SysRecordTime,
10683
+			Mtime:                   time.Now().Unix(),
10684
+			UserOrgId:               advice.OrgId,
10685
+			Manufacturer:            advice.Manufacturer,
10686
+			Dealer:                  advice.Dealer,
10687
+			BatchNumber:             warehouse.BatchNumber,
10688
+			MaxUnit:                 drup.MinUnit,
10689
+			ConsumableType:          2,
10690
+			IsEdit:                  1,
10691
+			Creator:                 0,
10692
+			IsSys:                   0,
10693
+			WarehouseOutDetailId:    advice.ID,
10694
+			AdviceId:                advice.ID,
10695
+			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
10696
+			StorehouseId:            advice.StorehouseId,
10697
+			AdminUserId:             advice.AdminUserId,
10698
+			LastPrice:               warehouse.Price,
10699
+			StockCount:              advice.StockCount,
10700
+			OverCount:               over_count,
10701
+			RetailPrice:             drug_price, //手动出库出库价格
10702
+			WarehousingId:           warehouse.ID,
10703
+			WarehousingDetailId:     warehouse.ID,
10704
+			SystemTime:              advice.SysRecordTime,
10705
+			PatientId:               advice.PatientId,
10706
+			Remark:                  advice.Remark,
10707
+			OperateTime:             time.Now().Unix(),
10708
+		}
10709
+
10710
+		CreateSelfDrugFlowOne(drugflow, tx)
10711
+
10712
+		AddSelfDrugCount(advice.DrugId, orgID, advice.PatientId, drugflow.Count, tx)
10713
+		// 出库完成后,要将该批次库存清零
10714
+
10715
+		prescribingNumber_two_temp := deliver_number - stock_number
10716
+
10717
+		advice.CountUnit = drup.MinUnit
10718
+
10719
+		AutoSelfDrugDeliverInfoFourtyOne(orgID, prescribingNumber_two_temp, warehouseout, drup, advice, unit, tx)
10720
+	}
10721
+
10722
+	return
10723
+}