XMLWAN 3 年 前
コミット
630a29f712

+ 58 - 31
controllers/drug_stock_api_contorller.go ファイルの表示

1775
 			}
1775
 			}
1776
 
1776
 
1777
 			if medical.MinUnit == item.CountUnit {
1777
 			if medical.MinUnit == item.CountUnit {
1778
-				max_number = outInfo.Count
1778
+				max_number = item.Count
1779
 			}
1779
 			}
1780
 
1780
 
1781
 			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1781
 			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1782
 			fmt.Println("总库存223232", all_number)
1782
 			fmt.Println("总库存223232", all_number)
1783
-			fmt.Println("当前库存", max_number)
1783
+			fmt.Println("当前库存00000000000000000000000000000000000000000", max_number)
1784
 			////比较当前出库数量 和 最后一次出库数量,正常出库
1784
 			////比较当前出库数量 和 最后一次出库数量,正常出库
1785
 			if max_number <= min_number {
1785
 			if max_number <= min_number {
1786
 				errs = service.UpDateDrugWarehouseOutInfo(item)
1786
 				errs = service.UpDateDrugWarehouseOutInfo(item)
1787
 				cha_number = min_number - max_number
1787
 				cha_number = min_number - max_number
1788
 				fmt.Println("差库存", cha_number)
1788
 				fmt.Println("差库存", cha_number)
1789
-				fmt.Println("最后一次库存", min_number)
1789
+				fmt.Println("最后一次库存0000000000000000000000000000000000000000", min_number)
1790
 				if item.CountUnit == medical.MaxUnit {
1790
 				if item.CountUnit == medical.MaxUnit {
1791
 					maxNumber = cha_number / medical.MinNumber
1791
 					maxNumber = cha_number / medical.MinNumber
1792
 					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1792
 					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1844
 
1844
 
1845
 			}
1845
 			}
1846
 
1846
 
1847
+			fmt.Println("当前出库", max_number)
1848
+			fmt.Println("最后一次232233", min_number)
1847
 			//退库操作
1849
 			//退库操作
1848
 			if max_number > min_number {
1850
 			if max_number > min_number {
1851
+
1849
 				cha_number = min_number - max_number
1852
 				cha_number = min_number - max_number
1850
 				//如果总库存大于差,正常出库
1853
 				//如果总库存大于差,正常出库
1851
 				if all_number >= cha_number {
1854
 				if all_number >= cha_number {
1852
-					fmt.Println("金立2323323322323233232323", all_number, cha_number)
1855
+
1853
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1856
 					errs = service.UpDateDrugWarehouseOutInfo(item)
1854
 					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1857
 					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1855
 					if item.CountUnit == medical.MaxUnit {
1858
 					if item.CountUnit == medical.MaxUnit {
2077
 				batch_number := items["batch_number"].(string)
2080
 				batch_number := items["batch_number"].(string)
2078
 				max_unit := items["max_unit"].(string)
2081
 				max_unit := items["max_unit"].(string)
2079
 				batch_number_id := int64(items["batch_number_id"].(float64))
2082
 				batch_number_id := int64(items["batch_number_id"].(float64))
2083
+
2084
+				fmt.Println("99999999999999999999", batch_number_id)
2080
 				cancelStockInfo := &models.DrugCancelStockInfo{
2085
 				cancelStockInfo := &models.DrugCancelStockInfo{
2081
 					OrderNumber:      cancelStock.OrderNumber,
2086
 					OrderNumber:      cancelStock.OrderNumber,
2082
 					CancelStockId:    cancelStock.ID,
2087
 					CancelStockId:    cancelStock.ID,
2141
 	}
2146
 	}
2142
 	//扣减库存逻辑
2147
 	//扣减库存逻辑
2143
 	for _, item := range cancelStockInfos {
2148
 	for _, item := range cancelStockInfos {
2149
+		var total_number int64
2144
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
2150
 		medical, _ := service.GetBaseDrugMedical(item.DrugId)
2145
-		//查询当前药品退库的批次号的总入库数
2146
-		infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2147
-		fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2148
-		var total_count int64
2151
+		//将当前退库数转为最小单位
2149
 		if item.MaxUnit == medical.MaxUnit {
2152
 		if item.MaxUnit == medical.MaxUnit {
2150
-			total_count = infoWareInfo.WarehousingCount
2151
-			fmt.Println("进来了吗发大发阿道夫阿方阿道夫撒发大发阿方阿方阿方阿道夫阿方暗示法", total_count)
2153
+			total_number = item.Count * medical.MinNumber
2152
 		}
2154
 		}
2153
-		//转化为最小库存
2154
 		if item.MaxUnit == medical.MinUnit {
2155
 		if item.MaxUnit == medical.MinUnit {
2155
-			total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2156
+			total_number = item.Count
2156
 		}
2157
 		}
2157
-		fmt.Println("itme.count2323232323232323232332", item.Count)
2158
-		fmt.Println("23232322322323232332", total_count)
2158
+		fmt.Println("当前库存", total_number)
2159
+		//查询当前药品退库的批次号的总入库数
2160
+		infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2161
+		fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit, infoWareInfo.StockMaxNumber, infoWareInfo.StockMinNumber)
2162
+		var total_count int64
2163
+		total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2164
+		fmt.Println("当前批次总库存", total_count)
2165
+
2159
 		//判断退库数量是否大于总入库数量
2166
 		//判断退库数量是否大于总入库数量
2160
-		if item.Count > total_count {
2167
+		if total_number > total_count {
2161
 			c.ServeSuccessJSON(map[string]interface{}{
2168
 			c.ServeSuccessJSON(map[string]interface{}{
2162
 				"msg": "2",
2169
 				"msg": "2",
2163
 			})
2170
 			})
2164
 			return
2171
 			return
2165
 		}
2172
 		}
2166
 		//正常退库
2173
 		//正常退库
2167
-		if item.Count <= infoWareInfo.WarehousingCount {
2174
+		if total_number <= total_count {
2168
 			//创建退库详情
2175
 			//创建退库详情
2169
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2176
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2170
 			//创建库存明细
2177
 			//创建库存明细
2171
 			errs = service.CreateDrugFlow(drugFlow)
2178
 			errs = service.CreateDrugFlow(drugFlow)
2172
 
2179
 
2173
 			var total int64
2180
 			var total int64
2174
-			//退库到当前批次,获取当前退库批次的库存
2175
-			info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2181
+			////退库到当前批次,获取当前退库批次的库存
2182
+			//info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2176
 
2183
 
2177
-			if info.MaxUnit == item.MaxUnit {
2178
-				total = item.Count + info.StockMaxNumber
2184
+			if medical.MaxUnit == item.MaxUnit {
2185
+				total = item.Count
2179
 
2186
 
2180
 				warehouseInfo := models.XtDrugWarehouseInfo{
2187
 				warehouseInfo := models.XtDrugWarehouseInfo{
2181
 					StockMaxNumber: total,
2188
 					StockMaxNumber: total,
2192
 				})
2199
 				})
2193
 			}
2200
 			}
2194
 			if medical.MinUnit == item.MaxUnit {
2201
 			if medical.MinUnit == item.MaxUnit {
2195
-				total = item.Count + info.StockMinNumber
2202
+				fmt.Println("hhhhhh2323323232322332232332999999999进来", item.Count)
2203
+				total = item.Count
2196
 				warehouseInfo := models.XtDrugWarehouseInfo{
2204
 				warehouseInfo := models.XtDrugWarehouseInfo{
2197
 					StockMinNumber: total,
2205
 					StockMinNumber: total,
2198
 				}
2206
 				}
2550
 			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2558
 			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2551
 			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2559
 			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2552
 			var total_count int64
2560
 			var total_count int64
2561
+			total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2562
+			//转化为最小单位
2563
+			var total_number int64
2553
 			if item.MaxUnit == medical.MaxUnit {
2564
 			if item.MaxUnit == medical.MaxUnit {
2554
-				total_count = infoWareInfo.WarehousingCount
2565
+				total_number = item.Count * medical.MinNumber
2555
 			}
2566
 			}
2556
-			//转化为最小库存
2557
 			if item.MaxUnit == medical.MinUnit {
2567
 			if item.MaxUnit == medical.MinUnit {
2558
-				total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2568
+				total_number = item.Count
2559
 			}
2569
 			}
2570
+			//if item.MaxUnit == medical.MaxUnit {
2571
+			//	total_count = infoWareInfo.WarehousingCount
2572
+			//}
2573
+			////转化为最小库存
2574
+			//if item.MaxUnit == medical.MinUnit {
2575
+			//	total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2576
+			//}
2560
 			//判断退库数量是否大于总入库数量
2577
 			//判断退库数量是否大于总入库数量
2561
-			if item.Count > total_count {
2578
+			if total_number > total_count {
2562
 				c.ServeSuccessJSON(map[string]interface{}{
2579
 				c.ServeSuccessJSON(map[string]interface{}{
2563
 					"msg": "2",
2580
 					"msg": "2",
2564
 				})
2581
 				})
2565
 				return
2582
 				return
2566
 			}
2583
 			}
2584
+
2567
 			//正常退库
2585
 			//正常退库
2568
-			if item.Count <= infoWareInfo.WarehousingCount {
2586
+			if total_number <= total_count {
2569
 				//创建退库详情
2587
 				//创建退库详情
2570
 				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2588
 				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2571
 				//创建库存明细
2589
 				//创建库存明细
2572
 				errs = service.CreateDrugFlow(drugFlow)
2590
 				errs = service.CreateDrugFlow(drugFlow)
2573
 
2591
 
2592
+				//获取该批次最后一条退库详情
2593
+				lastCancel, _ := service.GetLastCancelStockInfo(id)
2594
+				var cancel_number int64
2595
+				if lastCancel.MaxUnit == medical.MaxUnit {
2596
+					cancel_number = lastCancel.Count * medical.MinNumber
2597
+				}
2598
+
2599
+				if lastCancel.MaxUnit == medical.MinUnit {
2600
+					cancel_number = lastCancel.Count
2601
+				}
2602
+				fmt.Println("999999232323232232232323232323", lastCancel)
2574
 				var total int64
2603
 				var total int64
2575
-				//退库到当前批次,获取当前退库批次的库存
2576
-				info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2577
 
2604
 
2578
-				if info.MaxUnit == item.MaxUnit {
2579
-					total = item.Count + info.StockMaxNumber
2605
+				if medical.MaxUnit == item.MaxUnit {
2606
+					total = item.Count - cancel_number
2580
 
2607
 
2581
 					warehouseInfo := models.XtDrugWarehouseInfo{
2608
 					warehouseInfo := models.XtDrugWarehouseInfo{
2582
 						StockMaxNumber: total,
2609
 						StockMaxNumber: total,
2593
 					})
2620
 					})
2594
 				}
2621
 				}
2595
 				if medical.MinUnit == item.MaxUnit {
2622
 				if medical.MinUnit == item.MaxUnit {
2596
-					total = item.Count + info.StockMinNumber
2623
+					total = item.Count - cancel_number
2597
 					warehouseInfo := models.XtDrugWarehouseInfo{
2624
 					warehouseInfo := models.XtDrugWarehouseInfo{
2598
 						StockMinNumber: total,
2625
 						StockMinNumber: total,
2599
 					}
2626
 					}

+ 15 - 9
controllers/mobile_api_controllers/patient_api_controller.go ファイルの表示

638
 								prescribing_number_total = count * medical.MinNumber
638
 								prescribing_number_total = count * medical.MinNumber
639
 							}
639
 							}
640
 							if medical.MinUnit == item.PrescribingNumberUnit {
640
 							if medical.MinUnit == item.PrescribingNumberUnit {
641
-								total = list.Count
642
-								prescribing_number_total = list.Count
641
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
642
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
643
+								total = list.Count*medical.MinNumber + list.StockMinNumber
644
+								prescribing_number_total = count
643
 							}
645
 							}
644
 
646
 
645
 							fmt.Println("数量一", prescribing_number_total)
647
 							fmt.Println("数量一", prescribing_number_total)
646
 							fmt.Println("数量二", total)
648
 							fmt.Println("数量二", total)
647
 
649
 
648
-							if list.Count == 0 {
650
+							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
649
 								c.ServeSuccessJSON(map[string]interface{}{
651
 								c.ServeSuccessJSON(map[string]interface{}{
650
 									"msg":    "3",
652
 									"msg":    "3",
651
 									"advice": advice,
653
 									"advice": advice,
705
 								prescribing_number_total = count * medical.MinNumber
707
 								prescribing_number_total = count * medical.MinNumber
706
 							}
708
 							}
707
 							if medical.MinUnit == item.PrescribingNumberUnit {
709
 							if medical.MinUnit == item.PrescribingNumberUnit {
708
-								total = list.Count
709
-								prescribing_number_total = list.Count
710
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
711
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
712
+								total = list.Count*medical.MinNumber + list.StockMinNumber
713
+								prescribing_number_total = count
710
 							}
714
 							}
711
 
715
 
712
 							fmt.Println("数量一", prescribing_number_total)
716
 							fmt.Println("数量一", prescribing_number_total)
713
 							fmt.Println("数量二", total)
717
 							fmt.Println("数量二", total)
714
 
718
 
715
-							if list.Count == 0 {
719
+							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
716
 								c.ServeSuccessJSON(map[string]interface{}{
720
 								c.ServeSuccessJSON(map[string]interface{}{
717
 									"msg":    "3",
721
 									"msg":    "3",
718
 									"advice": advice,
722
 									"advice": advice,
922
 					prescribing_number_total = count * medical.MinNumber
926
 					prescribing_number_total = count * medical.MinNumber
923
 				}
927
 				}
924
 				if medical.MinUnit == advice.PrescribingNumberUnit {
928
 				if medical.MinUnit == advice.PrescribingNumberUnit {
925
-					total = list.Count
926
-					prescribing_number_total = list.Count
929
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
930
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
931
+					total = list.Count*medical.MinNumber + list.StockMinNumber
932
+					prescribing_number_total = count
927
 				}
933
 				}
928
 
934
 
929
 				fmt.Println("数量一", prescribing_number_total)
935
 				fmt.Println("数量一", prescribing_number_total)
930
 				fmt.Println("数量二", total)
936
 				fmt.Println("数量二", total)
931
 
937
 
932
-				if list.Count == 0 {
938
+				if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
933
 					c.ServeSuccessJSON(map[string]interface{}{
939
 					c.ServeSuccessJSON(map[string]interface{}{
934
 						"msg":    "3",
940
 						"msg":    "3",
935
 						"advice": advice,
941
 						"advice": advice,

+ 120 - 19
controllers/patient_api_controller.go ファイルの表示

1659
 		fmt.Println("999999992322322323232", drugStockConfig.IsOpen)
1659
 		fmt.Println("999999992322322323232", drugStockConfig.IsOpen)
1660
 		//自备药信息
1660
 		//自备药信息
1661
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1661
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1662
-
1662
+		fmt.Println("drugStockConfig2323232332232332", drugStockConfig.IsOpen)
1663
 		if drugStockConfig.IsOpen == 1 {
1663
 		if drugStockConfig.IsOpen == 1 {
1664
-
1664
+			var total int64
1665
+			var prescribing_number_total int64
1665
 			advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1666
 			advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1666
 			for _, item := range advices {
1667
 			for _, item := range advices {
1667
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1668
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1668
-
1669
 				//查询该药品是否有库存
1669
 				//查询该药品是否有库存
1670
 				list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1670
 				list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1671
-				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1672
-				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1673
-				if list.Count == 0 {
1671
+				fmt.Println("list23232323232232323232323232", list)
1672
+				//查询改药品信息
1673
+				medical, _ := service.GetBaseDrugMedical(item.DrugId)
1674
+				//判断单位是否相等
1675
+				if medical.MaxUnit == item.PrescribingNumberUnit {
1676
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1677
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1678
+					//转化为最小单位
1679
+					total = list.Count * medical.MinNumber
1680
+					prescribing_number_total = count * medical.MinNumber
1681
+				}
1682
+				if medical.MinUnit == item.PrescribingNumberUnit {
1683
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1684
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1685
+					total = list.Count*medical.MinNumber + list.StockMinNumber
1686
+					prescribing_number_total = count
1687
+				}
1688
+
1689
+				fmt.Println("数量一", prescribing_number_total)
1690
+				fmt.Println("数量二", total)
1691
+
1692
+				if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1674
 					c.ServeSuccessJSON(map[string]interface{}{
1693
 					c.ServeSuccessJSON(map[string]interface{}{
1675
-						"msg":    "1",
1694
+						"msg":    "3",
1676
 						"advice": advice,
1695
 						"advice": advice,
1677
 					})
1696
 					})
1678
 					return
1697
 					return
1679
 				}
1698
 				}
1680
-				if count > list.Count {
1699
+				if prescribing_number_total > total {
1681
 					c.ServeSuccessJSON(map[string]interface{}{
1700
 					c.ServeSuccessJSON(map[string]interface{}{
1682
 						"msg":    "2",
1701
 						"msg":    "2",
1683
 						"advice": advice,
1702
 						"advice": advice,
1684
 					})
1703
 					})
1685
 					return
1704
 					return
1686
 				}
1705
 				}
1687
-				//调用药品出库接口
1688
-				service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1706
+				if prescribing_number_total <= total {
1707
+					service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1708
+					break
1709
+					c.ServeSuccessJSON(map[string]interface{}{
1710
+						"msg":    "1",
1711
+						"advice": advice,
1712
+					})
1713
+					return
1714
+				}
1715
+
1716
+				////查询该药品是否有库存
1717
+				//list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1718
+				//prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1719
+				//count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1720
+				//if list.Count == 0 {
1721
+				//	c.ServeSuccessJSON(map[string]interface{}{
1722
+				//		"msg":    "1",
1723
+				//		"advice": advice,
1724
+				//	})
1725
+				//	return
1726
+				//}
1727
+				//if count > list.Count {
1728
+				//	c.ServeSuccessJSON(map[string]interface{}{
1729
+				//		"msg":    "2",
1730
+				//		"advice": advice,
1731
+				//	})
1732
+				//	return
1733
+				//}
1734
+				////调用药品出库接口
1735
+				//service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1689
 
1736
 
1690
 			}
1737
 			}
1691
 		}
1738
 		}
1735
 		}
1782
 		}
1736
 
1783
 
1737
 		c.ServeSuccessJSON(map[string]interface{}{
1784
 		c.ServeSuccessJSON(map[string]interface{}{
1738
-			"msg":    "ok",
1785
+			"msg":    "1",
1739
 			"advice": advice,
1786
 			"advice": advice,
1740
 		})
1787
 		})
1741
 		return
1788
 		return
1818
 			//查询已经执行的医嘱
1865
 			//查询已经执行的医嘱
1819
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1866
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1820
 			for _, item := range advices {
1867
 			for _, item := range advices {
1868
+				var total int64
1869
+				var prescribing_number_total int64
1821
 				//查询该药品是否有库存
1870
 				//查询该药品是否有库存
1822
-				list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1823
-				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1824
-				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1825
-				if list.Count == 0 {
1871
+				list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
1872
+
1873
+				//查询改药品信息
1874
+				medical, _ := service.GetBaseDrugMedical(advice.DrugId)
1875
+				//判断单位是否相等
1876
+				if medical.MaxUnit == advice.PrescribingNumberUnit {
1877
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1878
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1879
+					//转化为最小单位
1880
+					total = list.Count * medical.MinNumber
1881
+					prescribing_number_total = count * medical.MinNumber
1882
+				}
1883
+				fmt.Println("单位1", medical.MinUnit)
1884
+				fmt.Println("d单位23", advice.PrescribingNumberUnit)
1885
+				fmt.Println("hhhhhhh", list.Count)
1886
+				if medical.MinUnit == advice.PrescribingNumberUnit {
1887
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
1888
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1889
+					total = list.Count*medical.MinNumber + list.StockMinNumber
1890
+					fmt.Println("23232322323322323233223", total)
1891
+					prescribing_number_total = count
1892
+					fmt.Println("7777777777777777", prescribing_number_total)
1893
+				}
1894
+
1895
+				fmt.Println("数量一", prescribing_number_total)
1896
+				fmt.Println("数量二", total)
1897
+
1898
+				if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
1826
 					c.ServeSuccessJSON(map[string]interface{}{
1899
 					c.ServeSuccessJSON(map[string]interface{}{
1827
-						"msg":    "1",
1900
+						"msg":    "3",
1828
 						"advice": advice,
1901
 						"advice": advice,
1829
 					})
1902
 					})
1830
 					return
1903
 					return
1831
 				}
1904
 				}
1832
-				if count > list.Count {
1905
+				if prescribing_number_total > total {
1833
 					c.ServeSuccessJSON(map[string]interface{}{
1906
 					c.ServeSuccessJSON(map[string]interface{}{
1834
 						"msg":    "2",
1907
 						"msg":    "2",
1835
 						"advice": advice,
1908
 						"advice": advice,
1836
 					})
1909
 					})
1837
 					return
1910
 					return
1838
 				}
1911
 				}
1839
-				service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1912
+				if prescribing_number_total <= total {
1913
+					service.HisDrugsDelivery(adminUserInfo.CurrentOrgId, item.ExecutionStaff, item)
1914
+					break
1915
+					c.ServeSuccessJSON(map[string]interface{}{
1916
+						"msg":    "1",
1917
+						"advice": advice,
1918
+					})
1919
+					return
1920
+				}
1840
 			}
1921
 			}
1922
+			//	//查询该药品是否有库存
1923
+			//	list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1924
+			//	prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1925
+			//	count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1926
+			//	if list.Count == 0 {
1927
+			//		c.ServeSuccessJSON(map[string]interface{}{
1928
+			//			"msg":    "1",
1929
+			//			"advice": advice,
1930
+			//		})
1931
+			//		return
1932
+			//	}
1933
+			//	if count > list.Count {
1934
+			//		c.ServeSuccessJSON(map[string]interface{}{
1935
+			//			"msg":    "2",
1936
+			//			"advice": advice,
1937
+			//		})
1938
+			//		return
1939
+			//	}
1940
+			//	service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1941
+			//}
1841
 		}
1942
 		}
1842
 		c.ServeSuccessJSON(map[string]interface{}{
1943
 		c.ServeSuccessJSON(map[string]interface{}{
1843
-			"msg":    "ok",
1944
+			"msg":    "1",
1844
 			"advice": advice,
1945
 			"advice": advice,
1845
 		})
1946
 		})
1846
 		return
1947
 		return

+ 107 - 43
controllers/stock_in_api_controller.go ファイルの表示

1822
 
1822
 
1823
 				dealer, _ := items["dealer"].(string)
1823
 				dealer, _ := items["dealer"].(string)
1824
 
1824
 
1825
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1826
+
1825
 				var expiryDates int64
1827
 				var expiryDates int64
1826
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1828
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1827
 					expiryDates = 0
1829
 					expiryDates = 0
1874
 					RegisterAccount: register_account,
1876
 					RegisterAccount: register_account,
1875
 					Remark:          remark,
1877
 					Remark:          remark,
1876
 					Price:           price,
1878
 					Price:           price,
1879
+					WarehouseInfoId: warehouse_info_id,
1877
 				}
1880
 				}
1878
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1881
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1879
 
1882
 
1912
 			}
1915
 			}
1913
 		}
1916
 		}
1914
 	}
1917
 	}
1915
-	errs := service.CreateCancelStockInfo(cancelStockInfos)
1916
-
1917
-	if len(stockFLow) > 0 {
1918
-		service.CreateStockFlow(stockFLow)
1919
-	}
1920
 
1918
 
1921
 	for _, item := range cancelStockInfos {
1919
 	for _, item := range cancelStockInfos {
1922
 
1920
 
1937
 			})
1935
 			})
1938
 			return
1936
 			return
1939
 		}
1937
 		}
1940
-	}
1941
 
1938
 
1942
-	// 改变入库单的值
1943
-	for _, item := range cancelStockInfos {
1939
+		//查询该批次入库的值
1940
+		infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
1944
 
1941
 
1945
-		//查询该耗材的入库记录
1946
-		list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1947
-		//调用退库的方法
1948
-		parseDateErr := service.UpdateCancelOut(list, item.Count)
1949
-		fmt.Println("999999999999", parseDateErr)
1950
-		if parseDateErr != nil {
1951
-			utils.ErrorLog(parseDateErr.Error())
1952
-			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
1942
+		if item.Count > infolist.WarehousingCount {
1943
+			c.ServeSuccessJSON(map[string]interface{}{
1944
+				"msg": "4",
1945
+			})
1953
 			return
1946
 			return
1954
 		}
1947
 		}
1955
-	}
1956
 
1948
 
1957
-	if errs != nil {
1958
-		utils.ErrorLog(errs.Error())
1959
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
1960
-		return
1949
+		if item.Count <= infolist.WarehousingCount {
1950
+
1951
+			errs := service.CreateCancelStockInfo(cancelStockInfos)
1952
+			if len(stockFLow) > 0 {
1953
+				service.CreateStockFlow(stockFLow)
1954
+			}
1955
+			if errs != nil {
1956
+				utils.ErrorLog(errs.Error())
1957
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
1958
+				return
1959
+			}
1960
+
1961
+			//更改入库数量
1962
+			errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
1963
+
1964
+			//查询该耗材的入库记录
1965
+			//list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1966
+			////调用退库的方法
1967
+			//parseDateErr := service.UpdateCancelOut(list, item.Count)
1968
+			//fmt.Println("999999999999", parseDateErr)
1969
+			break
1970
+		}
1961
 	}
1971
 	}
1962
 
1972
 
1963
 	c.ServeSuccessJSON(map[string]interface{}{
1973
 	c.ServeSuccessJSON(map[string]interface{}{
1964
 		"msg": "3",
1974
 		"msg": "3",
1965
 	})
1975
 	})
1976
+	return
1966
 
1977
 
1967
 }
1978
 }
1968
 func (c *StockManagerApiController) GetCancelStockInfoList() {
1979
 func (c *StockManagerApiController) GetCancelStockInfoList() {
2300
 	fmt.Println("出库22322333223", cancelStockInfos)
2311
 	fmt.Println("出库22322333223", cancelStockInfos)
2301
 	fmt.Println("更新23232323232323233", upDateCancelStockInfos)
2312
 	fmt.Println("更新23232323232323233", upDateCancelStockInfos)
2302
 	if len(cancelStockInfos) > 0 {
2313
 	if len(cancelStockInfos) > 0 {
2303
-		errs = service.CreateCancelStockInfo(cancelStockInfos)
2304
 
2314
 
2305
-		service.CreateStockFlow(stockFlow)
2306
-		// 改变入库单的值
2307
 		for _, item := range cancelStockInfos {
2315
 		for _, item := range cancelStockInfos {
2308
-			//查询该耗材的入库记录
2309
-			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
2310
-			//调用退库的方法
2311
-			parseDateErr := service.UpdateCancelOut(list, item.Count)
2312
-			if parseDateErr != nil {
2313
-				utils.ErrorLog(errs.Error())
2314
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2316
+			//统计该耗材的出库数量
2317
+			info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
2318
+			if item.Count > info.Count {
2319
+				c.ServeSuccessJSON(map[string]interface{}{
2320
+					"msg": "2",
2321
+				})
2315
 				return
2322
 				return
2316
 			}
2323
 			}
2324
+			//查询该批次入库的值
2325
+			infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2326
+
2327
+			if item.Count > infolist.WarehousingCount {
2328
+				c.ServeSuccessJSON(map[string]interface{}{
2329
+					"msg": "4",
2330
+				})
2331
+				return
2332
+			}
2333
+
2334
+			if item.Count <= infolist.WarehousingCount {
2335
+
2336
+				errs := service.CreateCancelStockInfo(cancelStockInfos)
2337
+				if len(stockFlow) > 0 {
2338
+					service.CreateStockFlow(stockFlow)
2339
+				}
2340
+				if errs != nil {
2341
+					utils.ErrorLog(errs.Error())
2342
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2343
+					return
2344
+				}
2345
+
2346
+				//更改入库数量
2347
+				errs = service.UpdateWareInfoById(item.WarehouseInfoId, item.Count)
2348
+
2349
+				break
2350
+			}
2317
 
2351
 
2318
-			c.ServeSuccessJSON(map[string]interface{}{
2319
-				"msg": "编辑成功",
2320
-			})
2321
 		}
2352
 		}
2322
 	}
2353
 	}
2323
 
2354
 
2324
 	if len(upDateCancelStockInfos) > 0 {
2355
 	if len(upDateCancelStockInfos) > 0 {
2325
 		for _, item := range upDateCancelStockInfos {
2356
 		for _, item := range upDateCancelStockInfos {
2326
-			service.CreateStockFlow(stockFlow)
2327
-			errs = service.UpDateCancelStockInfo(item)
2328
-			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
2329
-			//调用退库的方法
2330
-			parseDateErr := service.UpdateCancelOut(list, item.Count)
2331
-			fmt.Println("999999999999", parseDateErr)
2332
-			break
2357
+
2358
+			//获取该批次最后一套出库记录
2359
+			info, _ := service.GetLastCancelInfo(item.WarehouseInfoId, item.GoodId)
2360
+			fmt.Println("info232332322332233223", info.Count, item.Count)
2361
+			//比较出库数量和最后一次出库数据大小
2362
+			//退库(加)
2363
+			if item.Count < info.Count {
2364
+				var total = info.Count - item.Count
2365
+				errs = service.UpDateCancelStockInfo(item)
2366
+
2367
+				service.CreateStockFlow(stockFlow)
2368
+				parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total)
2369
+				if parseDateErr != nil {
2370
+					utils.ErrorLog(errs.Error())
2371
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2372
+					break
2373
+				}
2374
+			}
2375
+			//(减)
2376
+			if item.Count > info.Count {
2377
+				errs = service.UpDateCancelStockInfo(item)
2378
+				service.CreateStockFlow(stockFlow)
2379
+				//查询该批次入库的值
2380
+				infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
2381
+				if item.Count > infolist.WarehousingCount {
2382
+					c.ServeSuccessJSON(map[string]interface{}{
2383
+						"msg": "4",
2384
+					})
2385
+					return
2386
+				}
2387
+				if item.Count <= infolist.WarehousingCount {
2388
+					var total_count = info.Count - item.Count
2389
+					parseDateErr := service.UpdateWareInfoById(item.WarehouseInfoId, total_count)
2390
+					if parseDateErr != nil {
2391
+						utils.ErrorLog(errs.Error())
2392
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2393
+						return
2394
+					}
2395
+				}
2396
+			}
2333
 		}
2397
 		}
2334
 		if errs != nil {
2398
 		if errs != nil {
2335
 			utils.ErrorLog(errs.Error())
2399
 			utils.ErrorLog(errs.Error())
2338
 		}
2402
 		}
2339
 
2403
 
2340
 		c.ServeSuccessJSON(map[string]interface{}{
2404
 		c.ServeSuccessJSON(map[string]interface{}{
2341
-			"msg": "编辑成功",
2405
+			"msg": "3",
2342
 		})
2406
 		})
2343
 	}
2407
 	}
2344
 
2408
 
2349
 	}
2413
 	}
2350
 
2414
 
2351
 	c.ServeSuccessJSON(map[string]interface{}{
2415
 	c.ServeSuccessJSON(map[string]interface{}{
2352
-		"msg": "编辑成功",
2416
+		"msg": "3",
2353
 	})
2417
 	})
2354
 
2418
 
2355
 }
2419
 }

+ 1 - 0
models/stock_models.go ファイルの表示

548
 	Number          string      `gorm:"column:number" json:"number" form:"number"`
548
 	Number          string      `gorm:"column:number" json:"number" form:"number"`
549
 	RegisterAccount string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
549
 	RegisterAccount string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
550
 	Remark          string      `gorm:"column:remark" json:"remark" form:"remark"`
550
 	Remark          string      `gorm:"column:remark" json:"remark" form:"remark"`
551
+	WarehouseInfoId int64       `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
551
 	GoodInfo        GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
552
 	GoodInfo        GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
552
 }
553
 }
553
 
554
 

+ 30 - 5
service/stock_service.go ファイルの表示

1471
 	if len(cancelStockInfo) > 0 {
1471
 	if len(cancelStockInfo) > 0 {
1472
 		utx := writeDb.Begin()
1472
 		utx := writeDb.Begin()
1473
 		if len(cancelStockInfo) > 0 {
1473
 		if len(cancelStockInfo) > 0 {
1474
-			thisSQL := "INSERT INTO xt_cancel_stock_info (good_id, cancel_stock_id, good_type_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,number,register_account,remark,product_date,expiry_date) VALUES "
1474
+			thisSQL := "INSERT INTO xt_cancel_stock_info (good_id, cancel_stock_id, good_type_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,number,register_account,remark,product_date,expiry_date,warehouse_info_id) VALUES "
1475
 			insertParams := make([]string, 0)
1475
 			insertParams := make([]string, 0)
1476
 			insertData := make([]interface{}, 0)
1476
 			insertData := make([]interface{}, 0)
1477
 			for _, info := range cancelStockInfo {
1477
 			for _, info := range cancelStockInfo {
1478
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1478
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1479
 				insertData = append(insertData, info.GoodId)
1479
 				insertData = append(insertData, info.GoodId)
1480
 				insertData = append(insertData, info.CancelStockId)
1480
 				insertData = append(insertData, info.CancelStockId)
1481
 				insertData = append(insertData, info.GoodTypeId)
1481
 				insertData = append(insertData, info.GoodTypeId)
1494
 				insertData = append(insertData, info.Remark)
1494
 				insertData = append(insertData, info.Remark)
1495
 				insertData = append(insertData, info.ProductDate)
1495
 				insertData = append(insertData, info.ProductDate)
1496
 				insertData = append(insertData, info.ExpiryDate)
1496
 				insertData = append(insertData, info.ExpiryDate)
1497
+				insertData = append(insertData, info.WarehouseInfoId)
1497
 			}
1498
 			}
1498
 			thisSQL += strings.Join(insertParams, ", ")
1499
 			thisSQL += strings.Join(insertParams, ", ")
1499
 			err = utx.Exec(thisSQL, insertData...).Error
1500
 			err = utx.Exec(thisSQL, insertData...).Error
4038
 	if id > 0 {
4039
 	if id > 0 {
4039
 		db = db.Where("id = ?", id)
4040
 		db = db.Where("id = ?", id)
4040
 	}
4041
 	}
4041
-	err := db.Select("drug_id,warehousing_count").Find(&info).Error
4042
+	err := db.Select("drug_id,warehousing_count,stock_max_number,stock_min_number").Find(&info).Error
4042
 
4043
 
4043
 	return info, err
4044
 	return info, err
4044
 }
4045
 }
4052
 
4053
 
4053
 func UpdateDrugWarehouseInfo(info *models.XtDrugWarehouseInfo, id int64) error {
4054
 func UpdateDrugWarehouseInfo(info *models.XtDrugWarehouseInfo, id int64) error {
4054
 
4055
 
4055
-	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
4056
+	//err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_max_number": info.StockMaxNumber}).Error
4057
+	//return err
4058
+	err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", info.StockMaxNumber)).Error
4056
 	return err
4059
 	return err
4057
 }
4060
 }
4058
 
4061
 
4059
 func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
4062
 func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
4060
 
4063
 
4061
-	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
4064
+	//err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
4065
+	//return err
4066
+
4067
+	err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ? and status = 1", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", info.StockMinNumber)).Error
4062
 	return err
4068
 	return err
4063
 }
4069
 }
4064
 
4070
 
4094
 	err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ?  and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4100
 	err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ?  and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4095
 	return err
4101
 	return err
4096
 }
4102
 }
4103
+
4104
+func GetWarehouseInfoById(id int64) (models.WarehousingInfo, error) {
4105
+
4106
+	info := models.WarehousingInfo{}
4107
+	err := XTReadDB().Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
4108
+	return info, err
4109
+}
4110
+
4111
+func UpdateWareInfoById(id int64, count int64) error {
4112
+
4113
+	err = XTWriteDB().Model(&models.WarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_count", gorm.Expr("stock_count + ?", count)).Error
4114
+	return err
4115
+}
4116
+
4117
+func GetLastCancelInfo(id int64, goodid int64) (models.CancelStockInfo, error) {
4118
+	info := models.CancelStockInfo{}
4119
+	err := XTReadDB().Model(&info).Where("warehouse_info_id  = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
4120
+	return info, err
4121
+}