Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
6eb17f844a

+ 21 - 3
controllers/gobal_config_api_controller.go View File

@@ -101,6 +101,7 @@ func GobalConfigRegistRouters() {
101 101
 	beego.Router("/api/drug/getautodrugdetial", &GobalConfigApiController{}, "Get:GetAutoDrugDetail")
102 102
 	beego.Router("/api/drug/getdrugorderinprint", &GobalConfigApiController{}, "Get:GetDrugOrderInPrint")
103 103
 	beego.Router("/api/drug/getdrugoutorderdetailprint", &GobalConfigApiController{}, "Get:GetDrugOutOrderPrint")
104
+	beego.Router("/api/drug/getdrugbatchnumber", &GobalConfigApiController{}, "Get:GetDrugBatchNumber")
104 105
 }
105 106
 
106 107
 //provinces, _ := service.GetDistrictsByUpid(0)21
@@ -1942,7 +1943,7 @@ func (c *GobalConfigApiController) GetDrugOutStockFlow() {
1942 1943
 	orgId := c.GetAdminUserInfo().CurrentOrgId
1943 1944
 
1944 1945
 	outList, total, err := service.GetDrugStockOutFlow(drug_id, startTime, endTime, page, limit, orgId, stock_type)
1945
-
1946
+	fmt.Println("outList22233333333333333333333", outList)
1946 1947
 	if err != nil {
1947 1948
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
1948 1949
 		return
@@ -2023,6 +2024,7 @@ func (c *GobalConfigApiController) GetSingleOrderDetail() {
2023 2024
 	id, _ := c.GetInt64("id")
2024 2025
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2025 2026
 	list, err := service.GetSingleOrderDetail(id, orgId)
2027
+	outList, err := service.GetAllSingleDrugDetail(id, orgId)
2026 2028
 	dealerList, err := service.GetAllDealerList(orgId)
2027 2029
 	manufacturerList, err := service.GetAllManufacturerList(orgId)
2028 2030
 	if err != nil {
@@ -2033,22 +2035,28 @@ func (c *GobalConfigApiController) GetSingleOrderDetail() {
2033 2035
 		"list":             list,
2034 2036
 		"dealerList":       dealerList,
2035 2037
 		"manufacturerList": manufacturerList,
2038
+		"outList":          outList,
2036 2039
 	})
2037 2040
 }
2038 2041
 
2039 2042
 func (c *GobalConfigApiController) GetAutoDrugDetail() {
2040 2043
 
2044
+	warehouse_out_id, _ := c.GetInt64("warehouse_out_id")
2041 2045
 	id, _ := c.GetInt64("drug_id")
2042 2046
 	record_time, _ := c.GetInt64("record_time")
2043 2047
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2048
+	//获取自动出库
2044 2049
 	list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
2050
+	//获取手动出库
2051
+	outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
2045 2052
 	if err != nil {
2046 2053
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2047 2054
 		return
2048 2055
 	}
2049 2056
 	c.ServeSuccessJSON(map[string]interface{}{
2050
-		"list":  list,
2051
-		"total": total,
2057
+		"list":    list,
2058
+		"total":   total,
2059
+		"outList": outList,
2052 2060
 	})
2053 2061
 }
2054 2062
 
@@ -2083,3 +2091,13 @@ func (c *GobalConfigApiController) GetDrugOutOrderPrint() {
2083 2091
 		"manufacturerList": manufacturerList,
2084 2092
 	})
2085 2093
 }
2094
+
2095
+func (c *GobalConfigApiController) GetDrugBatchNumber() {
2096
+
2097
+	id, _ := c.GetInt64("id")
2098
+	orgId := c.GetAdminUserInfo().CurrentOrgId
2099
+	list, _ := service.GetDrugBatchNumber(id, orgId)
2100
+	c.ServeSuccessJSON(map[string]interface{}{
2101
+		"list": list,
2102
+	})
2103
+}

+ 4 - 2
controllers/manager_center_api_controller.go View File

@@ -1456,6 +1456,7 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1456 1456
 	good_kind, _ := c.GetInt64("good_kind", 0)
1457 1457
 	medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
1458 1458
 	retail_price, _ := c.GetFloat("retail_price", 0)
1459
+	fmt.Println(retail_price)
1459 1460
 	medical_insurance_number := c.GetString("medical_insurance_number")
1460 1461
 	is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
1461 1462
 	is_record, _ := c.GetInt64("is_record")
@@ -1530,7 +1531,7 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1530 1531
 		Agent:                       agent,
1531 1532
 		GoodNumber:                  good_number,
1532 1533
 		MedicalInsuranceLevel:       medical_insurance_level,
1533
-		RetailPrice:                 retail_price,
1534
+		RetailPrice:                 packing_price,
1534 1535
 		SocialSecurityDirectoryCode: social_security_directory_code,
1535 1536
 		ProductionType:              production_type,
1536 1537
 		SpecialMedical:              special_medical,
@@ -1572,6 +1573,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1572 1573
 	good_kind, _ := c.GetInt64("good_kind", 0)
1573 1574
 	medical_insurance_level, _ := c.GetInt64("medical_insurance_level", 0)
1574 1575
 	retail_price, _ := c.GetFloat("retail_price", 0)
1576
+	fmt.Println(retail_price)
1575 1577
 	medical_insurance_number := c.GetString("medical_insurance_number")
1576 1578
 	is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
1577 1579
 	is_record, _ := c.GetInt64("is_record")
@@ -1640,7 +1642,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1640 1642
 		Agent:                       agent,
1641 1643
 		GoodNumber:                  good_number,
1642 1644
 		MedicalInsuranceLevel:       medical_insurance_level,
1643
-		RetailPrice:                 retail_price,
1645
+		RetailPrice:                 packing_price,
1644 1646
 		SpecialMedical:              special_medical,
1645 1647
 		SocialSecurityDirectoryCode: social_security_directory_code,
1646 1648
 		ProductionType:              production_type,

+ 64 - 1
controllers/mobile_api_controllers/patient_api_controller.go View File

@@ -622,6 +622,26 @@ func (c *PatientApiController) ExecDoctorAdvice() {
622 622
 				if isHasWay {
623 623
 					for _, item := range advices {
624 624
 						if item.Way == 1 {
625
+							//查询该药品是否有库存
626
+							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
627
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
628
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
629
+							if list.Count == 0 {
630
+								c.ServeSuccessJSON(map[string]interface{}{
631
+									"msg":    "1",
632
+									"advice": advice,
633
+									"ids":    ids,
634
+								})
635
+								return
636
+							}
637
+							if count > list.Count {
638
+								c.ServeSuccessJSON(map[string]interface{}{
639
+									"msg":    "2",
640
+									"advice": advice,
641
+									"ids":    ids,
642
+								})
643
+								return
644
+							}
625 645
 							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
626 646
 						}
627 647
 					}
@@ -638,6 +658,29 @@ func (c *PatientApiController) ExecDoctorAdvice() {
638 658
 				if isHasWay {
639 659
 					for _, item := range advices {
640 660
 						if item.Way == 1 {
661
+							//查询该药品是否有库存
662
+							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
663
+							//获取该药品的信息
664
+							//medical, _ := service.GetBaseDrugMedical(item.DrugId)
665
+							prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
666
+							count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
667
+
668
+							if list.Count == 0 {
669
+								c.ServeSuccessJSON(map[string]interface{}{
670
+									"msg":    "1",
671
+									"advice": advice,
672
+									"ids":    ids,
673
+								})
674
+								return
675
+							}
676
+							if count > list.Count {
677
+								c.ServeSuccessJSON(map[string]interface{}{
678
+									"msg":    "2",
679
+									"advice": advice,
680
+									"ids":    ids,
681
+								})
682
+								return
683
+							}
641 684
 							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
642 685
 						}
643 686
 					}
@@ -786,9 +829,29 @@ func (c *PatientApiController) ExecDoctorAdvice() {
786 829
 		if err == nil {
787 830
 			//药品管理信息
788 831
 			_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(adminInfo.Org.Id)
789
-			fmt.Println("drugstockconfig000000000000000000000000", drugStockConfig.IsOpen)
790 832
 			if drugStockConfig.IsOpen == 1 {
791 833
 				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
834
+				//查询该药品是否有库存
835
+				list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
836
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
837
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
838
+				if list.Count == 0 {
839
+					c.ServeSuccessJSON(map[string]interface{}{
840
+						"msg":    "1",
841
+						"advice": advice,
842
+						"ids":    ids,
843
+					})
844
+					return
845
+				}
846
+				if count > list.Count {
847
+					c.ServeSuccessJSON(map[string]interface{}{
848
+						"msg":    "2",
849
+						"advice": advice,
850
+						"ids":    ids,
851
+					})
852
+					return
853
+				}
854
+
792 855
 				service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
793 856
 			}
794 857
 			c.ServeSuccessJSON(map[string]interface{}{

+ 38 - 572
controllers/patient_api_controller.go View File

@@ -1654,400 +1654,32 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1654 1654
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1655 1655
 
1656 1656
 		if drugStockConfig.IsOpen == 1 {
1657
-			//查询已经执行的医嘱
1658
-			//advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1659
-			//for _, item := range advices {
1660
-			//
1661
-			//	//调用药品出库接口
1662
-			//	//service.DrugsDelivery(item.UserOrgId, item)
1663
-			//
1664
-			//	//if item.Way == 1 {
1665
-			//	//	out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1666
-			//	//	if err == gorm.ErrRecordNotFound {
1667
-			//	//		//没有记录,则创建出库单
1668
-			//	//		timeStr := time.Now().Format("2006-01-02")
1669
-			//	//		timeArr := strings.Split(timeStr, "-")
1670
-			//	//		total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
1671
-			//	//		total = total + 1
1672
-			//	//		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1673
-			//	//		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1674
-			//	//		number = number + total
1675
-			//	//		warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1676
-			//	//		creater := adminUserInfo.AdminUser.Id
1677
-			//	//		warehouseOut := models.DrugWarehouseOut{
1678
-			//	//			WarehouseOutOrderNumber: warehousing_out_order,
1679
-			//	//			OperationTime:           time.Now().Unix(),
1680
-			//	//			OrgId:                   adminUserInfo.CurrentOrgId,
1681
-			//	//			Creater:                 creater,
1682
-			//	//			Ctime:                   time.Now().Unix(),
1683
-			//	//			Status:                  1,
1684
-			//	//			WarehouseOutTime:        item.RecordDate,
1685
-			//	//			Dealer:                  0,
1686
-			//	//			Manufacturer:            0,
1687
-			//	//			Type:                    1,
1688
-			//	//			IsSys:                   1,
1689
-			//	//		}
1690
-			//	//
1691
-			//	//		err := service.AddSigleDrugWarehouseOut(&warehouseOut)
1692
-			//	//		if err != nil {
1693
-			//	//			utils.TraceLog("创建出库单失败 err = %v", err)
1694
-			//	//		} else {
1695
-			//	//			if item.Way == 1 {
1696
-			//	//				if item.PrescribingNumber > 0 {
1697
-			//	//					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1698
-			//	//						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1699
-			//	//						WarehouseOutId:          warehouseOut.ID,
1700
-			//	//						Status:                  1,
1701
-			//	//						Ctime:                   time.Now().Unix(),
1702
-			//	//						Remark:                  "",
1703
-			//	//						OrgId:                   adminUserInfo.CurrentOrgId,
1704
-			//	//						Type:                    1,
1705
-			//	//						Manufacturer:            0,
1706
-			//	//						Dealer:                  0,
1707
-			//	//						IsSys:                   1,
1708
-			//	//						SysRecordTime:           item.RecordDate,
1709
-			//	//						DrugId:                  item.DrugId,
1710
-			//	//					}
1711
-			//	//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1712
-			//	//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1713
-			//	//					warehouseOutInfo.Count = count
1714
-			//	//					stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1715
-			//	//					warehouseOutInfo.Price = stockInInfo.Price
1716
-			//	//					err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1717
-			//	//					if err == nil {
1718
-			//	//						details := &models.DrugAutomaticReduceDetail{
1719
-			//	//							WarehouseOutId:          warehouseOutInfo.ID,
1720
-			//	//							WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1721
-			//	//							PatientId:               item.PatientId,
1722
-			//	//							Ctime:                   time.Now().Unix(),
1723
-			//	//							Mtime:                   time.Now().Unix(),
1724
-			//	//							Status:                  1,
1725
-			//	//							RecordTime:              item.RecordDate,
1726
-			//	//							OrgId:                   adminUserInfo.CurrentOrgId,
1727
-			//	//							DrugId:                  item.DrugId,
1728
-			//	//							Count:                   count,
1729
-			//	//						}
1730
-			//	//						service.AddSigleDrugAutoReduceRecordInfo(details)
1731
-			//	//						if err != nil {
1732
-			//	//							utils.TraceLog("创建出库单失败 err = %v", err)
1733
-			//	//						} else {
1734
-			//	//							if item.Way == 1 {
1735
-			//	//								if item.PrescribingNumber > 0 {
1736
-			//	//									warehouseOutInfo := &models.DrugWarehouseOutInfo{
1737
-			//	//										WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1738
-			//	//										WarehouseOutId:          warehouseOut.ID,
1739
-			//	//										Status:                  1,
1740
-			//	//										Ctime:                   time.Now().Unix(),
1741
-			//	//										Remark:                  "",
1742
-			//	//										OrgId:                   adminUserInfo.CurrentOrgId,
1743
-			//	//										Type:                    1,
1744
-			//	//										Manufacturer:            0,
1745
-			//	//										Dealer:                  0,
1746
-			//	//										IsSys:                   1,
1747
-			//	//										SysRecordTime:           item.RecordDate,
1748
-			//	//										DrugId:                  item.DrugId,
1749
-			//	//									}
1750
-			//	//									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1751
-			//	//									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1752
-			//	//									warehouseOutInfo.Count = count
1753
-			//	//									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1754
-			//	//									warehouseOutInfo.Price = stockInInfo.Price
1755
-			//	//									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1756
-			//	//									if err == nil {
1757
-			//	//										details := &models.DrugAutomaticReduceDetail{
1758
-			//	//											WarehouseOutId:          warehouseOutInfo.ID,
1759
-			//	//											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1760
-			//	//											PatientId:               item.PatientId,
1761
-			//	//											Ctime:                   time.Now().Unix(),
1762
-			//	//											Mtime:                   time.Now().Unix(),
1763
-			//	//											Status:                  1,
1764
-			//	//											RecordTime:              item.RecordDate,
1765
-			//	//											OrgId:                   adminUserInfo.CurrentOrgId,
1766
-			//	//											DrugId:                  item.DrugId,
1767
-			//	//											Count:                   count,
1768
-			//	//										}
1769
-			//	//										service.AddSigleDrugAutoReduceRecordInfo(details)
1770
-			//	//									}
1771
-			//	//								}
1772
-			//	//							}
1773
-			//	//						}
1774
-			//	//
1775
-			//	//					}
1776
-			//	//				}
1777
-			//	//			}
1778
-			//	//		}
1779
-			//	//	} else if err == nil {
1780
-			//	//		if item.Way == 1 {
1781
-			//	//			outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
1782
-			//	//			if err == gorm.ErrRecordNotFound {
1783
-			//	//				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1784
-			//	//					WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1785
-			//	//					WarehouseOutId:          out.ID,
1786
-			//	//					Status:                  1,
1787
-			//	//					Ctime:                   time.Now().Unix(),
1788
-			//	//					Remark:                  "",
1789
-			//	//					OrgId:                   adminUserInfo.CurrentOrgId,
1790
-			//	//					Type:                    1,
1791
-			//	//					Manufacturer:            0,
1792
-			//	//					Dealer:                  0,
1793
-			//	//					IsSys:                   1,
1794
-			//	//					SysRecordTime:           item.RecordDate,
1795
-			//	//				}
1796
-			//	//
1797
-			//	//				stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1798
-			//	//				warehouseOutInfo.Price = stockInInfo.Price
1799
-			//	//				warehouseOutInfo.DrugId = item.DrugId
1800
-			//	//				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1801
-			//	//				count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1802
-			//	//				warehouseOutInfo.Count = count
1803
-			//	//				err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1804
-			//	//				if err == nil {
1805
-			//	//					details := &models.DrugAutomaticReduceDetail{
1806
-			//	//						WarehouseOutId:          warehouseOutInfo.ID,
1807
-			//	//						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1808
-			//	//						PatientId:               item.PatientId,
1809
-			//	//						Ctime:                   time.Now().Unix(),
1810
-			//	//						Mtime:                   time.Now().Unix(),
1811
-			//	//						Status:                  1,
1812
-			//	//						RecordTime:              item.RecordDate,
1813
-			//	//						OrgId:                   adminUserInfo.CurrentOrgId,
1814
-			//	//						DrugId:                  item.DrugId,
1815
-			//	//						Count:                   count,
1816
-			//	//					}
1817
-			//	//					service.AddSigleDrugAutoReduceRecordInfo(details)
1818
-			//	//				}
1819
-			//	//
1820
-			//	//			} else if err == nil { //记录存在,则将增加数量
1821
-			//	//				if outInfo.ID > 0 {
1822
-			//	//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1823
-			//	//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1824
-			//	//					service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
1825
-			//	//				}
1826
-			//	//
1827
-			//	//				count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
1828
-			//	//				if count == 0 {
1829
-			//	//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1830
-			//	//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1831
-			//	//					details := &models.DrugAutomaticReduceDetail{
1832
-			//	//						WarehouseOutId:          outInfo.ID,
1833
-			//	//						WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
1834
-			//	//						PatientId:               item.PatientId,
1835
-			//	//						Ctime:                   time.Now().Unix(),
1836
-			//	//						Mtime:                   time.Now().Unix(),
1837
-			//	//						Status:                  1,
1838
-			//	//						RecordTime:              item.RecordDate,
1839
-			//	//						OrgId:                   adminUserInfo.CurrentOrgId,
1840
-			//	//						DrugId:                  item.DrugId,
1841
-			//	//						Count:                   count,
1842
-			//	//					}
1843
-			//	//					service.AddSigleDrugAutoReduceRecordInfo(details)
1844
-			//	//				} else if count == 1 {
1845
-			//	//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1846
-			//	//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1847
-			//	//					service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
1848
-			//	//				}
1849
-			//	//
1850
-			//	//			}
1851
-			//	//		}
1852
-			//	//	}
1853
-			//	//}
1854
-			//}
1657
+
1855 1658
 			advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1856 1659
 			for _, item := range advices {
1857 1660
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1661
+
1662
+				//查询该药品是否有库存
1663
+				list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1664
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1665
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1666
+				if list.Count == 0 {
1667
+					c.ServeSuccessJSON(map[string]interface{}{
1668
+						"msg":    "1",
1669
+						"advice": advice,
1670
+					})
1671
+					return
1672
+				}
1673
+				if count > list.Count {
1674
+					c.ServeSuccessJSON(map[string]interface{}{
1675
+						"msg":    "2",
1676
+						"advice": advice,
1677
+					})
1678
+					return
1679
+				}
1858 1680
 				//调用药品出库接口
1859 1681
 				service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
1860 1682
 
1861
-				//if item.Way == 1 {
1862
-				//	out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
1863
-				//	if err == gorm.ErrRecordNotFound {
1864
-				//		//没有记录,则创建出库单
1865
-				//		timeStr := time.Now().Format("2006-01-02")
1866
-				//		timeArr := strings.Split(timeStr, "-")
1867
-				//		total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
1868
-				//		total = total + 1
1869
-				//		warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1870
-				//		number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1871
-				//		number = number + total
1872
-				//		warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1873
-				//		creater := adminUserInfo.AdminUser.Id
1874
-				//		warehouseOut := models.DrugWarehouseOut{
1875
-				//			WarehouseOutOrderNumber: warehousing_out_order,
1876
-				//			OperationTime:           time.Now().Unix(),
1877
-				//			OrgId:                   adminUserInfo.CurrentOrgId,
1878
-				//			Creater:                 creater,
1879
-				//			Ctime:                   time.Now().Unix(),
1880
-				//			Status:                  1,
1881
-				//			WarehouseOutTime:        item.RecordDate,
1882
-				//			Dealer:                  0,
1883
-				//			Manufacturer:            0,
1884
-				//			Type:                    1,
1885
-				//			IsSys:                   1,
1886
-				//		}
1887
-				//
1888
-				//		err := service.AddSigleDrugWarehouseOut(&warehouseOut)
1889
-				//		if err != nil {
1890
-				//			utils.TraceLog("创建出库单失败 err = %v", err)
1891
-				//		} else {
1892
-				//			if item.Way == 1 {
1893
-				//				if item.PrescribingNumber > 0 {
1894
-				//					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1895
-				//						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1896
-				//						WarehouseOutId:          warehouseOut.ID,
1897
-				//						Status:                  1,
1898
-				//						Ctime:                   time.Now().Unix(),
1899
-				//						Remark:                  "",
1900
-				//						OrgId:                   adminUserInfo.CurrentOrgId,
1901
-				//						Type:                    1,
1902
-				//						Manufacturer:            0,
1903
-				//						Dealer:                  0,
1904
-				//						IsSys:                   1,
1905
-				//						SysRecordTime:           item.RecordDate,
1906
-				//						DrugId:                  item.DrugId,
1907
-				//					}
1908
-				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1909
-				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1910
-				//					warehouseOutInfo.Count = count
1911
-				//					stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1912
-				//					warehouseOutInfo.Price = stockInInfo.Price
1913
-				//					err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1914
-				//					if err == nil {
1915
-				//						details := &models.DrugAutomaticReduceDetail{
1916
-				//							WarehouseOutId:          warehouseOutInfo.ID,
1917
-				//							WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1918
-				//							PatientId:               item.PatientId,
1919
-				//							Ctime:                   time.Now().Unix(),
1920
-				//							Mtime:                   time.Now().Unix(),
1921
-				//							Status:                  1,
1922
-				//							RecordTime:              item.RecordDate,
1923
-				//							OrgId:                   adminUserInfo.CurrentOrgId,
1924
-				//							DrugId:                  item.DrugId,
1925
-				//							Count:                   count,
1926
-				//						}
1927
-				//						service.AddSigleDrugAutoReduceRecordInfo(details)
1928
-				//						if err != nil {
1929
-				//							utils.TraceLog("创建出库单失败 err = %v", err)
1930
-				//						} else {
1931
-				//							if item.Way == 1 {
1932
-				//								if item.PrescribingNumber > 0 {
1933
-				//									warehouseOutInfo := &models.DrugWarehouseOutInfo{
1934
-				//										WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1935
-				//										WarehouseOutId:          warehouseOut.ID,
1936
-				//										Status:                  1,
1937
-				//										Ctime:                   time.Now().Unix(),
1938
-				//										Remark:                  "",
1939
-				//										OrgId:                   adminUserInfo.CurrentOrgId,
1940
-				//										Type:                    1,
1941
-				//										Manufacturer:            0,
1942
-				//										Dealer:                  0,
1943
-				//										IsSys:                   1,
1944
-				//										SysRecordTime:           item.RecordDate,
1945
-				//										DrugId:                  item.DrugId,
1946
-				//									}
1947
-				//									prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1948
-				//									count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1949
-				//									warehouseOutInfo.Count = count
1950
-				//									stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1951
-				//									warehouseOutInfo.Price = stockInInfo.Price
1952
-				//									err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
1953
-				//									if err == nil {
1954
-				//										details := &models.DrugAutomaticReduceDetail{
1955
-				//											WarehouseOutId:          warehouseOutInfo.ID,
1956
-				//											WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
1957
-				//											PatientId:               item.PatientId,
1958
-				//											Ctime:                   time.Now().Unix(),
1959
-				//											Mtime:                   time.Now().Unix(),
1960
-				//											Status:                  1,
1961
-				//											RecordTime:              item.RecordDate,
1962
-				//											OrgId:                   adminUserInfo.CurrentOrgId,
1963
-				//											DrugId:                  item.DrugId,
1964
-				//											Count:                   count,
1965
-				//										}
1966
-				//										service.AddSigleDrugAutoReduceRecordInfo(details)
1967
-				//									}
1968
-				//								}
1969
-				//							}
1970
-				//						}
1971
-				//
1972
-				//					}
1973
-				//				}
1974
-				//			}
1975
-				//		}
1976
-				//	} else if err == nil {
1977
-				//		if item.Way == 1 {
1978
-				//			outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
1979
-				//			if err == gorm.ErrRecordNotFound {
1980
-				//				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1981
-				//					WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
1982
-				//					WarehouseOutId:          out.ID,
1983
-				//					Status:                  1,
1984
-				//					Ctime:                   time.Now().Unix(),
1985
-				//					Remark:                  "",
1986
-				//					OrgId:                   adminUserInfo.CurrentOrgId,
1987
-				//					Type:                    1,
1988
-				//					Manufacturer:            0,
1989
-				//					Dealer:                  0,
1990
-				//					IsSys:                   1,
1991
-				//					SysRecordTime:           item.RecordDate,
1992
-				//				}
1993
-				//
1994
-				//				stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
1995
-				//				warehouseOutInfo.Price = stockInInfo.Price
1996
-				//				warehouseOutInfo.DrugId = item.DrugId
1997
-				//				prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1998
-				//				count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
1999
-				//				warehouseOutInfo.Count = count
2000
-				//				err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2001
-				//				if err == nil {
2002
-				//					details := &models.DrugAutomaticReduceDetail{
2003
-				//						WarehouseOutId:          warehouseOutInfo.ID,
2004
-				//						WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2005
-				//						PatientId:               item.PatientId,
2006
-				//						Ctime:                   time.Now().Unix(),
2007
-				//						Mtime:                   time.Now().Unix(),
2008
-				//						Status:                  1,
2009
-				//						RecordTime:              item.RecordDate,
2010
-				//						OrgId:                   adminUserInfo.CurrentOrgId,
2011
-				//						DrugId:                  item.DrugId,
2012
-				//						Count:                   count,
2013
-				//					}
2014
-				//					service.AddSigleDrugAutoReduceRecordInfo(details)
2015
-				//				}
2016
-				//
2017
-				//			} else if err == nil { //记录存在,则将增加数量
2018
-				//				if outInfo.ID > 0 {
2019
-				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2020
-				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2021
-				//					service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
2022
-				//				}
2023
-				//
2024
-				//				count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
2025
-				//				if count == 0 {
2026
-				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2027
-				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2028
-				//					details := &models.DrugAutomaticReduceDetail{
2029
-				//						WarehouseOutId:          outInfo.ID,
2030
-				//						WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
2031
-				//						PatientId:               item.PatientId,
2032
-				//						Ctime:                   time.Now().Unix(),
2033
-				//						Mtime:                   time.Now().Unix(),
2034
-				//						Status:                  1,
2035
-				//						RecordTime:              item.RecordDate,
2036
-				//						OrgId:                   adminUserInfo.CurrentOrgId,
2037
-				//						DrugId:                  item.DrugId,
2038
-				//						Count:                   count,
2039
-				//					}
2040
-				//					service.AddSigleDrugAutoReduceRecordInfo(details)
2041
-				//				} else if count == 1 {
2042
-				//					prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2043
-				//					count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2044
-				//					service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
2045
-				//				}
2046
-				//
2047
-				//			}
2048
-				//		}
2049
-				//	}
2050
-				//}
2051 1683
 			}
2052 1684
 		}
2053 1685
 
@@ -2179,191 +1811,25 @@ func (c *PatientApiController) ExecDoctorAdvice() {
2179 1811
 			//查询已经执行的医嘱
2180 1812
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
2181 1813
 			for _, item := range advices {
2182
-
1814
+				//查询该药品是否有库存
1815
+				list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
1816
+				prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
1817
+				count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
1818
+				if list.Count == 0 {
1819
+					c.ServeSuccessJSON(map[string]interface{}{
1820
+						"msg":    "1",
1821
+						"advice": advice,
1822
+					})
1823
+					return
1824
+				}
1825
+				if count > list.Count {
1826
+					c.ServeSuccessJSON(map[string]interface{}{
1827
+						"msg":    "2",
1828
+						"advice": advice,
1829
+					})
1830
+					return
1831
+				}
2183 1832
 				service.HisDrugsDelivery(item.UserOrgId, item.ExecutionStaff, item)
2184
-
2185
-				//out, err := service.FindDrugStockOutByIsSys(adminUserInfo.CurrentOrgId, 1, item.RecordDate)
2186
-				//if err == gorm.ErrRecordNotFound {
2187
-				//	//没有记录,则创建出库单
2188
-				//	timeStr := time.Now().Format("2006-01-02")
2189
-				//	timeArr := strings.Split(timeStr, "-")
2190
-				//	total, _ := service.FindAllDrugWarehouseOut(adminUserInfo.CurrentOrgId)
2191
-				//	total = total + 1
2192
-				//	warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
2193
-				//	number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
2194
-				//	number = number + total
2195
-				//	warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
2196
-				//	creater := adminUserInfo.AdminUser.Id
2197
-				//	warehouseOut := models.DrugWarehouseOut{
2198
-				//		WarehouseOutOrderNumber: warehousing_out_order,
2199
-				//		OperationTime:           time.Now().Unix(),
2200
-				//		OrgId:                   adminUserInfo.CurrentOrgId,
2201
-				//		Creater:                 creater,
2202
-				//		Ctime:                   time.Now().Unix(),
2203
-				//		Status:                  1,
2204
-				//		WarehouseOutTime:        item.RecordDate,
2205
-				//		Dealer:                  0,
2206
-				//		Manufacturer:            0,
2207
-				//		Type:                    1,
2208
-				//		IsSys:                   1,
2209
-				//	}
2210
-				//
2211
-				//	err := service.AddSigleDrugWarehouseOut(&warehouseOut)
2212
-				//	if err != nil {
2213
-				//		utils.TraceLog("创建出库单失败 err = %v", err)
2214
-				//	} else {
2215
-				//		if item.PrescribingNumber > 0 {
2216
-				//			warehouseOutInfo := &models.DrugWarehouseOutInfo{
2217
-				//				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2218
-				//				WarehouseOutId:          warehouseOut.ID,
2219
-				//				Status:                  1,
2220
-				//				Ctime:                   time.Now().Unix(),
2221
-				//				Remark:                  "",
2222
-				//				OrgId:                   adminUserInfo.CurrentOrgId,
2223
-				//				Type:                    1,
2224
-				//				Manufacturer:            0,
2225
-				//				Dealer:                  0,
2226
-				//				IsSys:                   1,
2227
-				//				SysRecordTime:           item.RecordDate,
2228
-				//				DrugId:                  item.DrugId,
2229
-				//			}
2230
-				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2231
-				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2232
-				//			warehouseOutInfo.Count = count
2233
-				//			stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2234
-				//			warehouseOutInfo.Price = stockInInfo.Price
2235
-				//			err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2236
-				//			if err == nil {
2237
-				//				details := &models.DrugAutomaticReduceDetail{
2238
-				//					WarehouseOutId:          warehouseOutInfo.ID,
2239
-				//					WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2240
-				//					PatientId:               item.PatientId,
2241
-				//					Ctime:                   time.Now().Unix(),
2242
-				//					Mtime:                   time.Now().Unix(),
2243
-				//					Status:                  1,
2244
-				//					RecordTime:              item.RecordDate,
2245
-				//					OrgId:                   adminUserInfo.CurrentOrgId,
2246
-				//					DrugId:                  item.DrugId,
2247
-				//					Count:                   count,
2248
-				//				}
2249
-				//				service.AddSigleDrugAutoReduceRecordInfo(details)
2250
-				//				if err != nil {
2251
-				//					utils.TraceLog("创建出库单失败 err = %v", err)
2252
-				//				} else {
2253
-				//					if item.PrescribingNumber > 0 {
2254
-				//						warehouseOutInfo := &models.DrugWarehouseOutInfo{
2255
-				//							WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
2256
-				//							WarehouseOutId:          warehouseOut.ID,
2257
-				//							Status:                  1,
2258
-				//							Ctime:                   time.Now().Unix(),
2259
-				//							Remark:                  "",
2260
-				//							OrgId:                   adminUserInfo.CurrentOrgId,
2261
-				//							Type:                    1,
2262
-				//							Manufacturer:            0,
2263
-				//							Dealer:                  0,
2264
-				//							IsSys:                   1,
2265
-				//							SysRecordTime:           item.RecordDate,
2266
-				//							DrugId:                  item.DrugId,
2267
-				//						}
2268
-				//						prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2269
-				//						count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2270
-				//						warehouseOutInfo.Count = count
2271
-				//						stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2272
-				//						warehouseOutInfo.Price = stockInInfo.Price
2273
-				//						err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2274
-				//						if err == nil {
2275
-				//							details := &models.DrugAutomaticReduceDetail{
2276
-				//								WarehouseOutId:          warehouseOutInfo.ID,
2277
-				//								WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2278
-				//								PatientId:               item.PatientId,
2279
-				//								Ctime:                   time.Now().Unix(),
2280
-				//								Mtime:                   time.Now().Unix(),
2281
-				//								Status:                  1,
2282
-				//								RecordTime:              item.RecordDate,
2283
-				//								OrgId:                   adminUserInfo.CurrentOrgId,
2284
-				//								DrugId:                  item.DrugId,
2285
-				//								Count:                   count,
2286
-				//							}
2287
-				//							service.AddSigleDrugAutoReduceRecordInfo(details)
2288
-				//						}
2289
-				//					}
2290
-				//				}
2291
-				//
2292
-				//			}
2293
-				//		}
2294
-				//	}
2295
-				//} else if err == nil {
2296
-				//	outInfo, err := service.FindDrugStockOutInfoByTypeId(adminUserInfo.CurrentOrgId, item.DrugId, out.ID, out.WarehouseOutOrderNumber)
2297
-				//	if err == gorm.ErrRecordNotFound {
2298
-				//		warehouseOutInfo := &models.DrugWarehouseOutInfo{
2299
-				//			WarehouseOutOrderNumber: out.WarehouseOutOrderNumber,
2300
-				//			WarehouseOutId:          out.ID,
2301
-				//			Status:                  1,
2302
-				//			Ctime:                   time.Now().Unix(),
2303
-				//			Remark:                  "",
2304
-				//			OrgId:                   adminUserInfo.CurrentOrgId,
2305
-				//			Type:                    1,
2306
-				//			Manufacturer:            0,
2307
-				//			Dealer:                  0,
2308
-				//			IsSys:                   1,
2309
-				//			SysRecordTime:           item.RecordDate,
2310
-				//		}
2311
-				//
2312
-				//		stockInInfo, _ := service.FindLastDrugStockInInfoRecord(item.DrugId, adminUserInfo.CurrentOrgId)
2313
-				//		warehouseOutInfo.Price = stockInInfo.Price
2314
-				//		warehouseOutInfo.DrugId = item.DrugId
2315
-				//		prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2316
-				//		count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2317
-				//		warehouseOutInfo.Count = count
2318
-				//		err := service.AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
2319
-				//		if err == nil {
2320
-				//			details := &models.DrugAutomaticReduceDetail{
2321
-				//				WarehouseOutId:          warehouseOutInfo.ID,
2322
-				//				WarehouseOutOrderNumber: warehouseOutInfo.WarehouseOutOrderNumber,
2323
-				//				PatientId:               item.PatientId,
2324
-				//				Ctime:                   time.Now().Unix(),
2325
-				//				Mtime:                   time.Now().Unix(),
2326
-				//				Status:                  1,
2327
-				//				RecordTime:              item.RecordDate,
2328
-				//				OrgId:                   adminUserInfo.CurrentOrgId,
2329
-				//				DrugId:                  item.DrugId,
2330
-				//				Count:                   count,
2331
-				//			}
2332
-				//			service.AddSigleDrugAutoReduceRecordInfo(details)
2333
-				//		}
2334
-				//
2335
-				//	} else if err == nil { //记录存在,则将增加数量
2336
-				//		if outInfo.ID > 0 {
2337
-				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2338
-				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2339
-				//			service.UpdateDrugStockOutInfoCount2(adminUserInfo.CurrentOrgId, outInfo.ID, count)
2340
-				//		}
2341
-				//
2342
-				//		count, _ := service.FindPatientDrugAutomaticReduceRecord(adminUserInfo.CurrentOrgId, item.RecordDate, item.DrugId, item.PatientId)
2343
-				//		if count == 0 {
2344
-				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2345
-				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2346
-				//			details := &models.DrugAutomaticReduceDetail{
2347
-				//				WarehouseOutId:          outInfo.ID,
2348
-				//				WarehouseOutOrderNumber: outInfo.WarehouseOutOrderNumber,
2349
-				//				PatientId:               item.PatientId,
2350
-				//				Ctime:                   time.Now().Unix(),
2351
-				//				Mtime:                   time.Now().Unix(),
2352
-				//				Status:                  1,
2353
-				//				RecordTime:              item.RecordDate,
2354
-				//				OrgId:                   adminUserInfo.CurrentOrgId,
2355
-				//				DrugId:                  item.DrugId,
2356
-				//				Count:                   count,
2357
-				//			}
2358
-				//			service.AddSigleDrugAutoReduceRecordInfo(details)
2359
-				//		} else if count == 1 {
2360
-				//			prescribingNumber := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
2361
-				//			count, _ := strconv.ParseInt(prescribingNumber, 10, 64)
2362
-				//			service.UpdateDrugUserInfoDetails(item.DrugId, item.RecordDate, adminUserInfo.CurrentOrgId, item.PatientId, count, &outInfo)
2363
-				//		}
2364
-				//
2365
-				//	}
2366
-				//}
2367 1833
 			}
2368 1834
 		}
2369 1835
 		c.ServeSuccessJSON(map[string]interface{}{

+ 41 - 3
controllers/stock_in_api_controller.go View File

@@ -93,6 +93,7 @@ func StockManagerApiRegistRouters() {
93 93
 	beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
94 94
 	beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
95 95
 	beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
96
+	beego.Router("/api/stock/getstockbatchnumber", &StockManagerApiController{}, "Get:GetStockBatchNumber")
96 97
 
97 98
 }
98 99
 
@@ -1678,9 +1679,30 @@ func (c *StockManagerApiController) CreateCancelStock() {
1678 1679
 	}
1679 1680
 	errs := service.CreateCancelStockInfo(cancelStockInfos)
1680 1681
 
1682
+	for _, item := range cancelStockInfos {
1683
+
1684
+		//查找该耗材是否有出库记录
1685
+		_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
1686
+		if errcode == gorm.ErrRecordNotFound {
1687
+			c.ServeSuccessJSON(map[string]interface{}{
1688
+				"msg": "1",
1689
+			})
1690
+			return
1691
+		}
1692
+
1693
+		//统计该耗材的出库数量
1694
+		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
1695
+		if item.Count > info.Count {
1696
+			c.ServeSuccessJSON(map[string]interface{}{
1697
+				"msg": "2",
1698
+			})
1699
+			return
1700
+		}
1701
+	}
1702
+
1681 1703
 	// 改变入库单的值
1682 1704
 	for _, item := range cancelStockInfos {
1683
-		fmt.Println("经理俄2433444 我认为侮辱侮辱侮辱侮辱侮辱侮辱我无污染武荣", item.GoodId, item.OrgId)
1705
+
1684 1706
 		//查询该耗材的入库记录
1685 1707
 		list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1686 1708
 		//调用退库的方法
@@ -1695,7 +1717,7 @@ func (c *StockManagerApiController) CreateCancelStock() {
1695 1717
 	}
1696 1718
 
1697 1719
 	c.ServeSuccessJSON(map[string]interface{}{
1698
-		"msg": "退库成功",
1720
+		"msg": "3",
1699 1721
 	})
1700 1722
 
1701 1723
 }
@@ -2091,6 +2113,7 @@ func (this *StockManagerApiController) GetDetailInfo() {
2091 2113
 	if types == 1 {
2092 2114
 		list, total, err = service.FindStockInDetailList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, keywords, manufacturer, order_type, dealer)
2093 2115
 		_, total_price = service.GetStockInDetailTotal(adminUserInfo.CurrentOrgId, startTime, endTime, keywords, manufacturer, order_type, dealer)
2116
+
2094 2117
 		if err == nil {
2095 2118
 			this.ServeSuccessJSON(map[string]interface{}{
2096 2119
 				"list":        list,
@@ -3895,6 +3918,7 @@ func (this *StockManagerApiController) GetStockOutList() {
3895 3918
 		endTime = theTime.Unix()
3896 3919
 	}
3897 3920
 	outList, total, _ := service.GetStockOutList(id, orgId, limit, page, startTime, endTime, is_sys)
3921
+
3898 3922
 	this.ServeSuccessJSON(map[string]interface{}{
3899 3923
 		"outList": outList,
3900 3924
 		"total":   total,
@@ -3958,15 +3982,19 @@ func (this *StockManagerApiController) GetOrderDetialByOrderId() {
3958 3982
 
3959 3983
 func (this *StockManagerApiController) GetOrderDetailById() {
3960 3984
 
3985
+	id, _ := this.GetInt64("id")
3961 3986
 	good_id, _ := this.GetInt64("good_id")
3962 3987
 	record_time, _ := this.GetInt64("record_time")
3963 3988
 	orgId := this.GetAdminUserInfo().CurrentOrgId
3964
-
3989
+	//自动出库
3965 3990
 	userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
3991
+	//手动出库
3992
+	info, _ := service.GetWarehouseOutInfoById(id, good_id)
3966 3993
 	if err == nil {
3967 3994
 		this.ServeSuccessJSON(map[string]interface{}{
3968 3995
 			"list":  userDetails,
3969 3996
 			"total": total,
3997
+			"info":  info,
3970 3998
 		})
3971 3999
 	} else {
3972 4000
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -4083,3 +4111,13 @@ func (this *StockManagerApiController) GetCancelStockOrderPrint() {
4083 4111
 		"list": list,
4084 4112
 	})
4085 4113
 }
4114
+
4115
+func (this *StockManagerApiController) GetStockBatchNumber() {
4116
+
4117
+	id, _ := this.GetInt64("id")
4118
+	orgId := this.GetAdminUserInfo().CurrentOrgId
4119
+	list, _ := service.GetStockBatchNumber(id, orgId)
4120
+	this.ServeSuccessJSON(map[string]interface{}{
4121
+		"list": list,
4122
+	})
4123
+}

+ 1 - 0
models/drug_stock.go View File

@@ -104,6 +104,7 @@ type DrugWarehouseOutInfo struct {
104 104
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
105 105
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
106 106
 	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
107
+	PatientId               int64   `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
107 108
 }
108 109
 
109 110
 func (DrugWarehouseOutInfo) TableName() string {

+ 5 - 3
models/self_drug_models.go View File

@@ -392,6 +392,7 @@ type XtDrugWarehouseInfo struct {
392 392
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
393 393
 	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number"`
394 394
 	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number"`
395
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
395 396
 }
396 397
 
397 398
 func (XtDrugWarehouseInfo) TableName() string {
@@ -635,14 +636,15 @@ type VmDrugWarehouseOutInfo struct {
635 636
 	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
636 637
 	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
637 638
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
639
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
638 640
 	DrugType                int64   `json:"drug_type"`
639 641
 	MaxUnit                 string  `json:"max_unit"`
640 642
 	MinUnit                 string  `json:"min_unit"`
641 643
 	MinNumber               int64   `json:"min_number"`
642 644
 	Dose                    float64 `json:"dose"`
643 645
 	DoseUnit                string  `json:"dose_unit"`
644
-	LastPrice               string  `json:"last_price"`
646
+	LastPrice               float64 `json:"last_price"`
647
+	MinPrice                float64 `json:"min_price"`
645 648
 	DrugName                string  `json:"drug_name"`
646
-	Number                  string  `json:"number"`
647
-	BatchNumber             string  `json:"batch_number"`
649
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
648 650
 }

+ 17 - 16
models/stock_models.go View File

@@ -369,22 +369,23 @@ func (WarehousingOutInfoConfig) TableName() string {
369 369
 }
370 370
 
371 371
 type AutomaticReduceDetail struct {
372
-	ID                      int64     `gorm:"column:id" json:"id"`
373
-	WarehouseOutId          int64     `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
374
-	WarehouseOutOrderNumber string    `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
375
-	PatientId               int64     `gorm:"column:patient_id" json:"patient_id"`
376
-	Ctime                   int64     `gorm:"column:ctime" json:"ctime"`
377
-	Mtime                   int64     `gorm:"column:mtime" json:"mtime"`
378
-	Status                  int64     `gorm:"column:status" json:"status"`
379
-	RecordTime              int64     `gorm:"column:record_time" json:"record_time"`
380
-	OrgId                   int64     `gorm:"column:org_id" json:"org_id"`
381
-	GoodId                  int64     `gorm:"column:good_id" json:"good_id"`
382
-	GoodTypeId              int64     `gorm:"column:good_type_id" json:"good_type_id"`
383
-	GoodInfo                GoodInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
384
-	GoodsType               GoodsType `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
385
-	Patients                Patients  `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
386
-	Count                   int64     `gorm:"column:count" json:"count"`
387
-	Type                    int64     `gorm:"column:type" json:"type"`
372
+	ID                      int64               `gorm:"column:id" json:"id"`
373
+	WarehouseOutId          int64               `gorm:"column:warehouse_out_id" json:"warehouse_out_id"`
374
+	WarehouseOutOrderNumber string              `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number"`
375
+	PatientId               int64               `gorm:"column:patient_id" json:"patient_id"`
376
+	Ctime                   int64               `gorm:"column:ctime" json:"ctime"`
377
+	Mtime                   int64               `gorm:"column:mtime" json:"mtime"`
378
+	Status                  int64               `gorm:"column:status" json:"status"`
379
+	RecordTime              int64               `gorm:"column:record_time" json:"record_time"`
380
+	OrgId                   int64               `gorm:"column:org_id" json:"org_id"`
381
+	GoodId                  int64               `gorm:"column:good_id" json:"good_id"`
382
+	GoodTypeId              int64               `gorm:"column:good_type_id" json:"good_type_id"`
383
+	GoodInfo                GoodInfo            `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"info"`
384
+	GoodsType               GoodsType           `gorm:"ForeignKey:GoodTypeId;AssociationForeignKey:ID" json:"type"`
385
+	Patients                Patients            `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
386
+	Count                   int64               `gorm:"column:count" json:"count"`
387
+	Type                    int64               `gorm:"column:type" json:"type"`
388
+	WarehouseOutInfo        []*WarehouseOutInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"warehouseOutInfo"`
388 389
 }
389 390
 
390 391
 func (AutomaticReduceDetail) TableName() string {

+ 26 - 2
service/gobal_config_service.go View File

@@ -588,7 +588,7 @@ func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64
588 588
 	if stocktype == 2 {
589 589
 		db = db.Where("x.is_sys = 1")
590 590
 	}
591
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime,t.drug_name,t.drug_type,t.min_number,t.min_unit,t.max_unit").Joins("left join xt_base_drug as t on t.id = x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
591
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime,x.batch_number,x.count_unit,t.drug_name,t.drug_type,t.min_number,t.min_unit,t.max_unit").Joins("left join xt_base_drug as t on t.id = x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
592 592
 	return list, total, err
593 593
 }
594 594
 
@@ -676,17 +676,41 @@ func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouse
676 676
 		db = db.Where("x.warehouse_out_id = ?", id)
677 677
 	}
678 678
 
679
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
679
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
680 680
 	return info, err
681 681
 }
682 682
 
683
+func GetAllSingleDrugDetail(id int64, orgid int64) (outInfo []*models.VmDrugWarehouseOutInfo, err error) {
684
+
685
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
686
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
687
+	fmt.Println(table)
688
+	if orgid > 0 {
689
+		db = db.Where("x.org_id = ?", orgid)
690
+	}
691
+	if id > 0 {
692
+		db = db.Where("x.warehouse_out_id = ?", id)
693
+	}
694
+
695
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.count,x.count_unit,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price,t.min_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&outInfo).Error
696
+	return outInfo, err
697
+}
698
+
683 699
 func FindDrugStockUserDetailByIdThree(id int64, record_time int64, org_id int64) (user []*DrugAutomaticReduceDetail, err error, total int64) {
684 700
 
685 701
 	db := readDb.Model(&user)
686 702
 	db = db.Preload("Drug", "org_id = ? AND status = 1", org_id)
687 703
 	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
704
+	db = db.Preload("DrugWarehouseOutInfo", "drug_id = ? and sys_record_time = ? and status = 1 and org_id = ?", id, record_time, org_id)
688 705
 	db = db.Where("status = 1 AND org_id = ? AND drug_id = ? AND record_time =?", org_id, id, record_time)
689 706
 	db = db.Count(&total)
690 707
 	err = db.Find(&user).Error
691 708
 	return user, err, total
692 709
 }
710
+
711
+func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (outInfo []*models.DrugWarehouseOutInfo, err error) {
712
+
713
+	err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and org_id = ? and status = 1", ware_out_id, drug_id, orgid).Find(&outInfo).Error
714
+
715
+	return outInfo, err
716
+}

+ 68 - 18
service/stock_service.go View File

@@ -222,7 +222,7 @@ func ModifyGoodInfo(goodInfo *models.GoodInfo) (error, *models.GoodInfo) {
222 222
 		"wubi":                           goodInfo.Wubi,
223 223
 		"good_kind":                      goodInfo.GoodKind,
224 224
 		"medical_insurance_level":        goodInfo.MedicalInsuranceLevel,
225
-		"retail_price":                   goodInfo.RetailPrice,
225
+		"retail_price":                   goodInfo.PackingPrice,
226 226
 		"medical_insurance_number":       goodInfo.MedicalInsuranceNumber,
227 227
 		"is_special_diseases":            goodInfo.IsSpecialDiseases,
228 228
 		"is_record":                      goodInfo.IsRecord,
@@ -1221,6 +1221,7 @@ type DrugWarehouseOutInfo struct {
1221 1221
 	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
1222 1222
 	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
1223 1223
 	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
1224
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
1224 1225
 	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
1225 1226
 	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
1226 1227
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
@@ -2390,20 +2391,21 @@ func FindUserDetailById(org_id int64, id int64) (user []*models.AutomaticReduceD
2390 2391
 }
2391 2392
 
2392 2393
 type DrugAutomaticReduceDetail struct {
2393
-	ID                      int64            `gorm:"column:id" json:"id" form:"id"`
2394
-	WarehouseOutId          int64            `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
2395
-	WarehouseOutOrderNumber string           `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
2396
-	PatientId               int64            `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
2397
-	Ctime                   int64            `gorm:"column:ctime" json:"ctime" form:"ctime"`
2398
-	Mtime                   int64            `gorm:"column:mtime" json:"mtime" form:"mtime"`
2399
-	Status                  int64            `gorm:"column:status" json:"status" form:"status"`
2400
-	RecordTime              int64            `gorm:"column:record_time" json:"record_time" form:"record_time"`
2401
-	OrgId                   int64            `gorm:"column:org_id" json:"org_id" form:"org_id"`
2402
-	DrugId                  int64            `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
2403
-	Count                   int64            `gorm:"column:count" json:"count" form:"count"`
2404
-	CountUnit               string           `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
2405
-	Drug                    *Drug            `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
2406
-	Patients                *models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
2394
+	ID                      int64                          `gorm:"column:id" json:"id" form:"id"`
2395
+	WarehouseOutId          int64                          `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
2396
+	WarehouseOutOrderNumber string                         `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
2397
+	PatientId               int64                          `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
2398
+	Ctime                   int64                          `gorm:"column:ctime" json:"ctime" form:"ctime"`
2399
+	Mtime                   int64                          `gorm:"column:mtime" json:"mtime" form:"mtime"`
2400
+	Status                  int64                          `gorm:"column:status" json:"status" form:"status"`
2401
+	RecordTime              int64                          `gorm:"column:record_time" json:"record_time" form:"record_time"`
2402
+	OrgId                   int64                          `gorm:"column:org_id" json:"org_id" form:"org_id"`
2403
+	DrugId                  int64                          `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
2404
+	Count                   int64                          `gorm:"column:count" json:"count" form:"count"`
2405
+	CountUnit               string                         `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
2406
+	Drug                    *Drug                          `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
2407
+	Patients                *models.Patients               `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
2408
+	DrugWarehouseOutInfo    []*models.DrugWarehouseOutInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"drugwarehouseoutinfo"`
2407 2409
 }
2408 2410
 
2409 2411
 func (DrugAutomaticReduceDetail) TableName() string {
@@ -3011,7 +3013,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
3011 3013
 	if is_sys == 3 {
3012 3014
 		db = db.Where("x.is_sys = 0")
3013 3015
 	}
3014
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.is_sys").Offset(offset).Count(&total).Scan(&info).Error
3016
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.is_sys,x.number,x.dealer,x.manufacturer").Offset(offset).Count(&total).Scan(&info).Error
3015 3017
 	return info, total, err
3016 3018
 }
3017 3019
 
@@ -3105,7 +3107,8 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
3105 3107
 	if orgid > 0 {
3106 3108
 		db = db.Where("x.org_id = ?", orgid)
3107 3109
 	}
3108
-	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3110
+
3111
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
3109 3112
 	return out, err
3110 3113
 }
3111 3114
 
@@ -3114,9 +3117,11 @@ func FindUserDetailByIdOne(good_id int64, record_time int64, org_id int64) (user
3114 3117
 	db = db.Preload("GoodInfo", "org_id = ? AND status = 1", org_id)
3115 3118
 	db = db.Preload("GoodsType", "status = 1")
3116 3119
 	db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
3120
+	db = db.Preload("WarehouseOutInfo", "org_id = ? and status = 1 and good_id = ? and sys_record_time = ?", org_id, good_id, record_time)
3117 3121
 	db = db.Where("status = 1 AND org_id = ? AND good_id = ? AND record_time = ? ", org_id, good_id, record_time)
3118 3122
 	db = db.Count(&total)
3119 3123
 	err = db.Find(&user).Error
3124
+
3120 3125
 	return
3121 3126
 }
3122 3127
 
@@ -3146,7 +3151,7 @@ func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime i
3146 3151
 	if endtime > 0 {
3147 3152
 		db = db.Where("x.ctime<=?", endtime)
3148 3153
 	}
3149
-	err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
3154
+	err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
3150 3155
 
3151 3156
 	return info, err
3152 3157
 }
@@ -3411,3 +3416,48 @@ func GetCancelOutTotalCount(startime int64, endtime int64, orgid int64) (info []
3411 3416
 	err = db.Select("x.good_id,sum(x.count) as count").Group("x.good_id").Scan(&info).Error
3412 3417
 	return info, err
3413 3418
 }
3419
+
3420
+func GetWarehoureOutOrderInfo(goodid int64, orgid int64) (*models.WarehouseOutInfo, error) {
3421
+
3422
+	info := models.WarehouseOutInfo{}
3423
+	var err error
3424
+	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1", goodid, orgid).Find(&info).Error
3425
+	if err == gorm.ErrRecordNotFound {
3426
+		return nil, err
3427
+	}
3428
+	if err != nil {
3429
+		return nil, err
3430
+	}
3431
+	return &info, nil
3432
+}
3433
+
3434
+func GetWarehoureOrderInfoCount(goodid int64, orgid int64) (info models.WarehouseOutInfo, err error) {
3435
+
3436
+	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status =1")
3437
+	if goodid > 0 {
3438
+		db = db.Where("x.good_id = ?", goodid)
3439
+	}
3440
+	if orgid > 0 {
3441
+		db = db.Where("x.org_id = ?", orgid)
3442
+	}
3443
+	err = db.Select("x.good_id,sum(x.count) as count").Scan(&info).Error
3444
+	return info, err
3445
+}
3446
+
3447
+func GetStockBatchNumber(id int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3448
+
3449
+	err = XTReadDB().Model(&info).Where("good_id = ? and org_id = ? and status = 1 and number <> ''", id, orgid).Group("number").Find(&info).Error
3450
+	return info, err
3451
+}
3452
+
3453
+func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOutInfo, err error) {
3454
+
3455
+	err = XTReadDB().Model(&info).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Find(&info).Error
3456
+	return info, err
3457
+}
3458
+
3459
+func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
3460
+
3461
+	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
3462
+	return info, err
3463
+}

+ 106 - 73
service/warhouse_service.go View File

@@ -113,6 +113,10 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
113 113
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
114 114
 	fmt.Println("stock_number999999999999", stock_number)
115 115
 	fmt.Println("deliver_number88888888888", deliver_number)
116
+
117
+	//查找药品信息
118
+	baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
119
+
116 120
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
117 121
 	if stock_number >= deliver_number {
118 122
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
@@ -120,21 +124,27 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
120 124
 			WarehouseOutId:          warehouseout.ID,
121 125
 			Status:                  1,
122 126
 			Ctime:                   time.Now().Unix(),
123
-			Remark:                  "",
127
+			Remark:                  warehouse.Remark,
124 128
 			OrgId:                   orgID,
125 129
 			Type:                    1,
126
-			Manufacturer:            0,
127
-			Dealer:                  0,
130
+			Manufacturer:            warehouse.Manufacturer,
131
+			Dealer:                  warehouse.Dealer,
128 132
 			IsSys:                   1,
129 133
 			SysRecordTime:           advice.RecordDate,
130 134
 			DrugId:                  advice.DrugId,
135
+			Number:                  warehouse.Number,
136
+			BatchNumber:             warehouse.BatchNumber,
137
+			Price:                   baseInfo.RetailPrice,
138
+			CountUnit:               advice.PrescribingNumberUnit,
139
+			RetailPrice:             baseInfo.RetailPrice,
140
+			ProductDate:             warehouse.ProductDate,
141
+			ExpiryDate:              warehouse.ExpiryDate,
142
+			PatientId:               advice.PatientId,
143
+			Count:                   count,
131 144
 		}
132 145
 
133
-		warehouseOutInfo.Count = deliver_number
134
-		warehouseOutInfo.CountUnit = drup.MinUnit
135
-
136 146
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
137
-
147
+		fmt.Println("hhhhhhhhhhhhhhhhhhhhhhhh2323232323232322323")
138 148
 		if errOne != nil {
139 149
 			return errOne
140 150
 		} else {
@@ -149,8 +159,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
149 159
 				RecordTime:              advice.RecordDate,
150 160
 				OrgId:                   orgID,
151 161
 				DrugId:                  advice.DrugId,
152
-				Count:                   deliver_number,
153
-				CountUnit:               drup.MinUnit,
162
+				Count:                   count,
163
+				CountUnit:               advice.PrescribingNumberUnit,
154 164
 			}
155 165
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
156 166
 			if errTwo != nil {
@@ -169,7 +179,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
169 179
 		}
170 180
 
171 181
 		if warehouse.StockMaxNumber < maxNumber {
172
-
182
+			fmt.Println("尽量323223232")
173 183
 			return errors.New("库存数量不足")
174 184
 		}
175 185
 
@@ -199,20 +209,24 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
199 209
 			WarehouseOutId:          warehouseout.ID,
200 210
 			Status:                  1,
201 211
 			Ctime:                   time.Now().Unix(),
202
-			Remark:                  "",
212
+			Remark:                  warehouse.Remark,
203 213
 			OrgId:                   orgID,
204 214
 			Type:                    1,
205
-			Manufacturer:            0,
206
-			Dealer:                  0,
215
+			Manufacturer:            warehouse.Manufacturer,
216
+			Dealer:                  warehouse.Dealer,
207 217
 			IsSys:                   1,
208 218
 			SysRecordTime:           advice.RecordDate,
209 219
 			DrugId:                  advice.DrugId,
220
+			Number:                  warehouse.Number,
221
+			BatchNumber:             warehouse.BatchNumber,
222
+			Price:                   baseInfo.RetailPrice,
223
+			CountUnit:               advice.PrescribingNumberUnit,
224
+			ProductDate:             warehouse.ProductDate,
225
+			ExpiryDate:              warehouse.ExpiryDate,
226
+			PatientId:               advice.PatientId,
227
+			Count:                   count,
210 228
 		}
211 229
 
212
-		warehouseOutInfo.Count = stock_number
213
-
214
-		warehouseOutInfo.CountUnit = drup.MinUnit
215
-
216 230
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
217 231
 		if errOne != nil {
218 232
 			return errOne
@@ -227,8 +241,8 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
227 241
 				RecordTime:              advice.RecordDate,
228 242
 				OrgId:                   orgID,
229 243
 				DrugId:                  advice.DrugId,
230
-				Count:                   stock_number,
231
-				CountUnit:               drup.MinUnit,
244
+				Count:                   count,
245
+				CountUnit:               advice.PrescribingNumberUnit,
232 246
 			}
233 247
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
234 248
 			if errTwo != nil {
@@ -247,7 +261,7 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
247 261
 		prescribingNumber_two_temp := deliver_number - stock_number
248 262
 		overPlusNumber := float64(prescribingNumber_two_temp)
249 263
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
250
-		advice.PrescribingNumberUnit = drup.MinUnit
264
+		advice.PrescribingNumberUnit = advice.PrescribingNumberUnit
251 265
 
252 266
 		DrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
253 267
 	}
@@ -340,7 +354,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
340 354
 	//开启事物
341 355
 
342 356
 	warehouse, err := FindLastDrugWarehousingInfoByID(advice.DrugId)
343
-
357
+	//查找药品信息
358
+	baseInfo, _ := FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
344 359
 	if err != nil {
345 360
 
346 361
 		return err
@@ -358,17 +373,25 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
358 373
 			WarehouseOutId:          warehouseout.ID,
359 374
 			Status:                  1,
360 375
 			Ctime:                   time.Now().Unix(),
361
-			Remark:                  "",
376
+			Remark:                  warehouse.Remark,
362 377
 			OrgId:                   orgID,
363 378
 			Type:                    1,
364
-			Manufacturer:            0,
365
-			Dealer:                  0,
379
+			Manufacturer:            warehouse.Manufacturer,
380
+			Dealer:                  warehouse.Dealer,
366 381
 			IsSys:                   1,
367 382
 			SysRecordTime:           advice.RecordDate,
368 383
 			DrugId:                  advice.DrugId,
384
+			Number:                  warehouse.Number,
385
+			BatchNumber:             warehouse.BatchNumber,
386
+			Price:                   baseInfo.RetailPrice,
387
+			CountUnit:               baseInfo.MaxUnit,
388
+			RetailPrice:             baseInfo.RetailPrice,
389
+			ProductDate:             warehouse.ProductDate,
390
+			ExpiryDate:              warehouse.ExpiryDate,
391
+			PatientId:               advice.PatientId,
369 392
 		}
370 393
 
371
-		warehouseOutInfo.Count = deliver_number
394
+		warehouseOutInfo.Count = count
372 395
 		warehouseOutInfo.CountUnit = advice.PrescribingNumberUnit
373 396
 
374 397
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
@@ -387,7 +410,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
387 410
 				RecordTime:              advice.RecordDate,
388 411
 				OrgId:                   orgID,
389 412
 				DrugId:                  advice.DrugId,
390
-				Count:                   deliver_number,
413
+				Count:                   count,
391 414
 				CountUnit:               advice.PrescribingNumberUnit,
392 415
 			}
393 416
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
@@ -437,19 +460,26 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
437 460
 			WarehouseOutId:          warehouseout.ID,
438 461
 			Status:                  1,
439 462
 			Ctime:                   time.Now().Unix(),
440
-			Remark:                  "",
463
+			Remark:                  warehouse.Remark,
441 464
 			OrgId:                   orgID,
442 465
 			Type:                    1,
443
-			Manufacturer:            0,
444
-			Dealer:                  0,
466
+			Manufacturer:            warehouse.Manufacturer,
467
+			Dealer:                  warehouse.Dealer,
445 468
 			IsSys:                   1,
446 469
 			SysRecordTime:           advice.RecordDate,
447 470
 			DrugId:                  advice.DrugId,
471
+			Number:                  warehouse.Number,
472
+			BatchNumber:             warehouse.BatchNumber,
473
+			Price:                   baseInfo.RetailPrice,
474
+			RetailPrice:             baseInfo.RetailPrice,
475
+			ProductDate:             warehouse.ProductDate,
476
+			ExpiryDate:              warehouse.ExpiryDate,
477
+			PatientId:               advice.PatientId,
448 478
 		}
449 479
 
450
-		warehouseOutInfo.Count = stock_number
480
+		warehouseOutInfo.Count = count
451 481
 
452
-		warehouseOutInfo.CountUnit = drup.MinUnit
482
+		warehouseOutInfo.CountUnit = advice.PrescribingNumberUnit
453 483
 
454 484
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
455 485
 		if errOne != nil {
@@ -465,8 +495,8 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
465 495
 				RecordTime:              advice.RecordDate,
466 496
 				OrgId:                   orgID,
467 497
 				DrugId:                  advice.DrugId,
468
-				Count:                   stock_number,
469
-				CountUnit:               drup.MinUnit,
498
+				Count:                   count,
499
+				CountUnit:               advice.PrescribingNumberUnit,
470 500
 			}
471 501
 			errTwo := AddSigleDrugAutoReduceRecordInfo(details)
472 502
 			if errTwo != nil {
@@ -485,7 +515,7 @@ func HisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *mo
485 515
 		prescribingNumber_two_temp := deliver_number - stock_number
486 516
 		overPlusNumber := float64(prescribingNumber_two_temp)
487 517
 		advice.PrescribingNumber = float64(prescribingNumber_two_temp)
488
-		advice.PrescribingNumberUnit = drup.MinUnit
518
+		advice.PrescribingNumberUnit = advice.PrescribingNumberUnit
489 519
 
490 520
 		HisDrugDeliverInfo(orgID, overPlusNumber, warehouseout, drup, advice)
491 521
 	}
@@ -502,6 +532,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
502 532
 
503 533
 	fmt.Println("单位1", advice.CountUnit)
504 534
 	fmt.Println("单位2", drup.MaxUnit)
535
+
505 536
 	if advice.CountUnit == drup.MaxUnit {
506 537
 		deliver_number = prescribingNumber * drup.MinNumber
507 538
 	} else {
@@ -548,7 +579,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
548 579
 			Price:                   advice.Price,
549 580
 		}
550 581
 
551
-		warehouseOutInfo.Count = deliver_number
582
+		warehouseOutInfo.Count = prescribingNumber
552 583
 		warehouseOutInfo.CountUnit = advice.CountUnit
553 584
 
554 585
 		errOne := AddSigleDrugWarehouseOutInfo(warehouseOutInfo)
@@ -614,8 +645,7 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
614 645
 			RetailPrice:             advice.RetailPrice,
615 646
 			Price:                   advice.Price,
616 647
 		}
617
-
618
-		warehouseOutInfo.Count = stock_number
648
+		warehouseOutInfo.Count = prescribingNumber
619 649
 
620 650
 		warehouseOutInfo.CountUnit = advice.CountUnit
621 651
 
@@ -761,7 +791,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
761 791
 	// 如果没有对应的库存,则报错
762 792
 
763 793
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
764
-	fmt.Println("库存数量9999343434343434343434343434343434", warehouse.StockCount)
794
+
765 795
 	if err != nil {
766 796
 		return
767 797
 	}
@@ -769,6 +799,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
769 799
 	// 将该批次的剩余库存数量转换为拆零数量
770 800
 	stock_number = warehouse.StockCount
771 801
 
802
+	//获取耗材信息
803
+	info, _ := GetGoodInformationByGoodId(goods.GoodId)
772 804
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
773 805
 	if stock_number >= deliver_number {
774 806
 		warehouseOutInfo := &models.WarehouseOutInfo{
@@ -777,16 +809,21 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
777 809
 			WarehouseInfotId:        warehouse.ID,
778 810
 			Status:                  1,
779 811
 			Ctime:                   time.Now().Unix(),
780
-			Remark:                  "",
812
+			Remark:                  warehouse.Remark,
781 813
 			OrgId:                   orgID,
782 814
 			Type:                    1,
783
-			Manufacturer:            0,
784
-			Dealer:                  0,
815
+			Manufacturer:            warehouse.Manufacturer,
816
+			Dealer:                  warehouse.Dealer,
785 817
 			IsSys:                   1,
786 818
 			SysRecordTime:           record_time,
787 819
 			GoodTypeId:              goods.GoodTypeId,
788 820
 			GoodId:                  goods.GoodId,
789 821
 			PatientId:               patient_id,
822
+			Number:                  warehouse.Number,
823
+			LicenseNumber:           warehouse.LicenseNumber,
824
+			Price:                   info.PackingPrice,
825
+			ExpiryDate:              warehouse.ExpiryDate,
826
+			ProductDate:             warehouse.ProductDate,
790 827
 		}
791 828
 		warehouseOutInfo.Count = count
792 829
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
@@ -842,39 +879,35 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
842 879
 
843 880
 		return nil
844 881
 	} else {
845
-		fmt.Println("中国共产党万岁22322332323232322323232323232323")
882
+
846 883
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
847
-		//warehouseOutInfo := &models.WarehouseOutInfo{
848
-		//  WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
849
-		//  WarehouseOutId:          warehouseOut.ID,
850
-		//  WarehouseInfotId:        warehouse.ID,
851
-		//  Status:                  1,
852
-		//  Ctime:                   time.Now().Unix(),
853
-		//  Remark:                  goods.Remark,
854
-		//  OrgId:                   orgID,
855
-		//  Type:                    1,
856
-		//  Manufacturer:            goods.Manufacturer,
857
-		//  Dealer:                  goods.Dealer,
858
-		//  IsSys:                   0,
859
-		//  SysRecordTime:           record_time,
860
-		//  GoodTypeId:              goods.GoodTypeId,
861
-		//  GoodId:                  goods.GoodId,
862
-		//  ExpiryDate:              goods.ExpiryDate,
863
-		//  ProductDate:             goods.ProductDate,
864
-		//  Number:                  goods.Number,
865
-		//  Price:                   goods.Price,
866
-		//  LicenseNumber:           goods.LicenseNumber,
867
-		//}
868
-		//warehouseOutInfo.Count = stock_number
869
-		//stockInInfo, _ :=FindLastStockInInfoRecord(goods.GoodId, orgID)
870
-		//fmt.Println("stockINFO2232232323223322332323223323223",stockInInfo)
871
-		//warehouseOutInfo.Price = stockInInfo.Price
872
-		//
873
-		//errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
874
-		//fmt.Println("errOne2232323232323232333232323",errOne)
875
-		//if errOne != nil {
876
-		//  return errOne
877
-		//}
884
+		warehouseOutInfo := &models.WarehouseOutInfo{
885
+			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
886
+			WarehouseOutId:          warehouseOut.ID,
887
+			WarehouseInfotId:        warehouse.ID,
888
+			Status:                  1,
889
+			Ctime:                   time.Now().Unix(),
890
+			Remark:                  warehouse.Remark,
891
+			OrgId:                   orgID,
892
+			Type:                    1,
893
+			Manufacturer:            warehouse.Manufacturer,
894
+			Dealer:                  warehouse.Dealer,
895
+			IsSys:                   1,
896
+			SysRecordTime:           record_time,
897
+			GoodTypeId:              goods.GoodTypeId,
898
+			GoodId:                  goods.GoodId,
899
+			PatientId:               patient_id,
900
+			Number:                  warehouse.Number,
901
+			LicenseNumber:           warehouse.LicenseNumber,
902
+			Price:                   info.PackingPrice,
903
+			ExpiryDate:              warehouse.ExpiryDate,
904
+			ProductDate:             warehouse.ProductDate,
905
+		}
906
+		warehouseOutInfo.Count = stock_number
907
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
908
+		if errOne != nil {
909
+			return errOne
910
+		}
878 911
 		// 出库完成后,要将该批次库存清零
879 912
 		warehouse.StockCount = 0
880 913
 		warehouse.Mtime = time.Now().Unix()