Просмотр исходного кода

Merge branch '20201014_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20201014_xt_api_new_branch

csx 3 лет назад
Родитель
Сommit
2ff81db145

+ 59 - 61
controllers/base_api_controller.go Просмотреть файл

@@ -2,8 +2,6 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
-	"XT_New/models"
6
-
7 5
 	//"XT_New/models"
8 6
 
9 7
 	//"XT_New/models"
@@ -69,36 +67,36 @@ type BaseAuthAPIController struct {
69 67
 func (this *BaseAuthAPIController) Prepare() {
70 68
 	this.BaseAPIController.Prepare()
71 69
 	if this.GetAdminUserInfo() == nil {
72
-		var userAdmin models.AdminUser
73
-		userAdmin.Id = 1448
74
-		userAdmin.Mobile = "13318599895"
75
-
76
-		userAdmin.Id = 597
77
-		userAdmin.Mobile = "19874122664"
78
-		userAdmin.IsSuperAdmin = false
79
-		userAdmin.Status = 1
80
-		userAdmin.CreateTime = 1530786071
81
-		userAdmin.ModifyTime = 1530786071
82
-		var subscibe models.ServeSubscibe
83
-		subscibe.ID = 1
84
-		subscibe.OrgId = 3877
85
-		subscibe.PeriodStart = 1538035409
86
-		subscibe.PeriodEnd = 1569571409
87
-		subscibe.State = 1
88
-		subscibe.Status = 1
89
-		subscibe.CreatedTime = 1538035409
90
-		subscibe.UpdatedTime = 1538035409
91
-		subscibes := make(map[int64]*models.ServeSubscibe, 0)
92
-		subscibes[4] = &subscibe
93
-		var adminUserInfo service.AdminUserInfo
94
-		adminUserInfo.CurrentOrgId = 3877
95
-		adminUserInfo.CurrentAppId = 4
96
-		adminUserInfo.AdminUser = &userAdmin
97
-		adminUserInfo.Subscibes = subscibes
98
-		this.SetSession("admin_user_info", &adminUserInfo)
99
-
100
-		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
101
-		//this.StopRun()
70
+		//var userAdmin models.AdminUser
71
+		//userAdmin.Id = 1448
72
+		//userAdmin.Mobile = "13318599895"
73
+		//
74
+		//userAdmin.Id = 597
75
+		//userAdmin.Mobile = "19874122664"
76
+		//userAdmin.IsSuperAdmin = false
77
+		//userAdmin.Status = 1
78
+		//userAdmin.CreateTime = 1530786071
79
+		//userAdmin.ModifyTime = 1530786071
80
+		//var subscibe models.ServeSubscibe
81
+		//subscibe.ID = 1
82
+		//subscibe.OrgId = 3877
83
+		//subscibe.PeriodStart = 1538035409
84
+		//subscibe.PeriodEnd = 1569571409
85
+		//subscibe.State = 1
86
+		//subscibe.Status = 1
87
+		//subscibe.CreatedTime = 1538035409
88
+		//subscibe.UpdatedTime = 1538035409
89
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
90
+		//subscibes[4] = &subscibe
91
+		//var adminUserInfo service.AdminUserInfo
92
+		//adminUserInfo.CurrentOrgId = 3877
93
+		//adminUserInfo.CurrentAppId = 4
94
+		//adminUserInfo.AdminUser = &userAdmin
95
+		//adminUserInfo.Subscibes = subscibes
96
+		//this.SetSession("admin_user_info", &adminUserInfo)
97
+
98
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
99
+		this.StopRun()
102 100
 
103 101
 	}
104 102
 
@@ -315,35 +313,35 @@ type BaseServeAPIController struct {
315 313
 func (this *BaseServeAPIController) Prepare() {
316 314
 	this.BaseAPIController.Prepare()
317 315
 	if this.GetAdminUserInfo() == nil {
318
-		var userAdmin models.AdminUser
319
-		userAdmin.Id = 1448
320
-		userAdmin.Mobile = "13318599895"
321
-
322
-		userAdmin.Id = 597
323
-		userAdmin.Mobile = "19874122664"
324
-		userAdmin.IsSuperAdmin = false
325
-		userAdmin.Status = 1
326
-		userAdmin.CreateTime = 1530786071
327
-		userAdmin.ModifyTime = 1530786071
328
-		var subscibe models.ServeSubscibe
329
-		subscibe.ID = 1
330
-		subscibe.OrgId = 3877
331
-		subscibe.PeriodStart = 1538035409
332
-		subscibe.PeriodEnd = 1569571409
333
-		subscibe.State = 1
334
-		subscibe.Status = 1
335
-		subscibe.CreatedTime = 1538035409
336
-		subscibe.UpdatedTime = 1538035409
337
-		subscibes := make(map[int64]*models.ServeSubscibe, 0)
338
-		subscibes[4] = &subscibe
339
-		var adminUserInfo service.AdminUserInfo
340
-		adminUserInfo.CurrentOrgId = 3877
341
-		adminUserInfo.CurrentAppId = 4
342
-		adminUserInfo.AdminUser = &userAdmin
343
-		adminUserInfo.Subscibes = subscibes
344
-		this.SetSession("admin_user_info", &adminUserInfo)
345
-		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
346
-		//this.StopRun()
316
+		//var userAdmin models.AdminUser
317
+		//userAdmin.Id = 1448
318
+		//userAdmin.Mobile = "13318599895"
319
+		//
320
+		//userAdmin.Id = 597
321
+		//userAdmin.Mobile = "19874122664"
322
+		//userAdmin.IsSuperAdmin = false
323
+		//userAdmin.Status = 1
324
+		//userAdmin.CreateTime = 1530786071
325
+		//userAdmin.ModifyTime = 1530786071
326
+		//var subscibe models.ServeSubscibe
327
+		//subscibe.ID = 1
328
+		//subscibe.OrgId = 3877
329
+		//subscibe.PeriodStart = 1538035409
330
+		//subscibe.PeriodEnd = 1569571409
331
+		//subscibe.State = 1
332
+		//subscibe.Status = 1
333
+		//subscibe.CreatedTime = 1538035409
334
+		//subscibe.UpdatedTime = 1538035409
335
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
336
+		//subscibes[4] = &subscibe
337
+		//var adminUserInfo service.AdminUserInfo
338
+		//adminUserInfo.CurrentOrgId = 3877
339
+		//adminUserInfo.CurrentAppId = 4
340
+		//adminUserInfo.AdminUser = &userAdmin
341
+		//adminUserInfo.Subscibes = subscibes
342
+		//this.SetSession("admin_user_info", &adminUserInfo)
343
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
344
+		this.StopRun()
347 345
 	}
348 346
 
349 347
 	//if adminUserInfo.AppRole != nil {

+ 1 - 1
controllers/data_api_controller.go Просмотреть файл

@@ -400,7 +400,7 @@ func configFormData(dataconfig *models.Dataconfig, data []byte) (code int) {
400 400
 	}
401 401
 	dataconfig.Module = module
402 402
 
403
-	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" {
403
+	if module == "education" || module == "summary" || module == "course_disease" || module == "rescue_record" || module == "nursing_record" || module == "special_record" || module == "special_treatment" || module == "template_summary" || module == "template_plan" {
404 404
 		if configBody["title"] == nil || reflect.TypeOf(configBody["title"]).String() != "string" {
405 405
 			utils.ErrorLog("title")
406 406
 			code = enums.ErrorCodeParamWrong

+ 630 - 52
controllers/drug_stock_api_contorller.go Просмотреть файл

@@ -87,9 +87,11 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
87 87
 	}
88 88
 	timeStr := time.Now().Format("2006-01-02")
89 89
 	timeArr := strings.Split(timeStr, "-")
90
-	total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
90
+	total, _ := service.FindAllWarehouseTotalOne(adminUserInfo.CurrentOrgId)
91 91
 	total = total + 1
92
+	fmt.Println("total2323232323232", total)
92 93
 	warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
94
+	fmt.Println("r入库单据好  2323232322223", warehousing_order)
93 95
 	operation_time := time.Now().Unix()
94 96
 	creater := adminUserInfo.AdminUser.Id
95 97
 	warehousing := models.DrugWarehouse{
@@ -1235,12 +1237,42 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1235 1237
 			}
1236 1238
 		}
1237 1239
 	}
1238
-
1240
+	var total_count int64
1241
+	var prescribing_number_total int64
1239 1242
 	//调用出库逻辑
1240 1243
 	for _, item := range warehousingOutInfo {
1241 1244
 		//获取药品库存
1242 1245
 		info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1243
-		if item.Count > info.Count {
1246
+		//查询改药品信息
1247
+		medical, _ := service.GetBaseDrugMedical(item.DrugId)
1248
+		//判断单位是否相等
1249
+		if medical.MaxUnit == item.CountUnit {
1250
+			//转化为最小单位
1251
+			total_count = info.Count * medical.MinNumber
1252
+			prescribing_number_total = item.Count * medical.MinNumber
1253
+		}
1254
+		if medical.MinUnit == item.CountUnit {
1255
+			total_count = info.Count
1256
+			prescribing_number_total = item.Count
1257
+		}
1258
+
1259
+		fmt.Println("数量一", prescribing_number_total)
1260
+		fmt.Println("数量二", total_count)
1261
+		//判断单位
1262
+		if total_count == 0 {
1263
+			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1264
+			c.ServeSuccessJSON(map[string]interface{}{
1265
+				"msg":        "1",
1266
+				"drug_name":  goodObj.DrugName,
1267
+				"dose":       goodObj.Dose,
1268
+				"dose_unit":  goodObj.DoseUnit,
1269
+				"min_number": goodObj.MinNumber,
1270
+				"min_unit":   goodObj.MinUnit,
1271
+				"max_unit":   goodObj.MaxUnit,
1272
+			})
1273
+			return
1274
+		}
1275
+		if prescribing_number_total > total_count {
1244 1276
 
1245 1277
 			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1246 1278
 			c.ServeSuccessJSON(map[string]interface{}{
@@ -1267,14 +1299,6 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1267 1299
 
1268 1300
 	}
1269 1301
 
1270
-	//errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1271
-	//info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1272
-	//if errs != nil {
1273
-	//	utils.ErrorLog(errs.Error())
1274
-	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1275
-	//	return
1276
-	//}
1277
-
1278 1302
 	c.ServeSuccessJSON(map[string]interface{}{
1279 1303
 		"msg":        "2",
1280 1304
 		"drug_name":  "",
@@ -1440,7 +1464,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1440 1464
 
1441 1465
 	var warehousingOutInfo []*models.DrugWarehouseOutInfo
1442 1466
 	var upDateWarehouseOutInfos []*models.DrugWarehouseOutInfo
1443
-	//var drugFlow  []*models.DrugFlow
1467
+
1468
+	var drugFlow []*models.DrugFlow
1444 1469
 	if dataBody["stockOut"] != nil && reflect.TypeOf(dataBody["stockOut"]).String() == "[]interface {}" {
1445 1470
 		thisStockOut, _ := dataBody["stockOut"].([]interface{})
1446 1471
 		if len(thisStockOut) > 0 {
@@ -1495,6 +1520,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1495 1520
 
1496 1521
 				batch_number := items["batch_number"].(string)
1497 1522
 				number := items["number"].(string)
1523
+				max_unit := items["count_unit"].(string)
1498 1524
 
1499 1525
 				var productDates int64
1500 1526
 				var expiryDates int64
@@ -1525,6 +1551,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1525 1551
 					}
1526 1552
 
1527 1553
 				}
1554
+				fmt.Println("生产日期22222222222222222222222222", expiryDates)
1555
+				fmt.Println("生产日期22222222222222222222222222", productDates)
1528 1556
 				if id == 0 {
1529 1557
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1530 1558
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1552,30 +1580,31 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1552 1580
 					}
1553 1581
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1554 1582
 
1555
-					//drugflow := &models.DrugFlow{
1556
-					//  WarehousingOrder: warehousing.WarehousingOrder,
1557
-					//  WarehousingId:    warehousing.ID,
1558
-					//  DrugId:           drug_id,
1559
-					//  Number:           number,
1560
-					//  ProductDate:      productDates,
1561
-					//  ExpireDate:       expiryDates,
1562
-					//  Count:            warehousing_count,
1563
-					//  Price:            last_price,
1564
-					//  Status:           1,
1565
-					//  Ctime:            ctime,
1566
-					//  UserOrgId:        adminUserInfo.CurrentOrgId,
1567
-					//  Manufacturer:     manufacturer,
1568
-					//  Dealer:           dealer,
1569
-					//  BatchNumber:      batch_number,
1570
-					//  MaxUnit:          max_unit,
1571
-					//  MinUnit:          min_unit,
1572
-					//  ConsumableType:   1,
1573
-					//  IsEdit:           1,
1574
-					//  Creator:          adminUserInfo.AdminUser.Id,
1575
-					//  IsSys:0,
1576
-					//}
1577
-					//
1578
-					//drugFlow = append(drugFlow,drugflow)
1583
+					drugflow := &models.DrugFlow{
1584
+						WarehousingOrder:        "",
1585
+						WarehousingId:           0,
1586
+						DrugId:                  drug_id,
1587
+						Number:                  number,
1588
+						ProductDate:             productDates,
1589
+						ExpireDate:              expiryDates,
1590
+						Count:                   count,
1591
+						Price:                   price,
1592
+						Status:                  1,
1593
+						Ctime:                   ctime,
1594
+						UserOrgId:               adminUserInfo.CurrentOrgId,
1595
+						Manufacturer:            manufacturer,
1596
+						Dealer:                  dealer,
1597
+						BatchNumber:             batch_number,
1598
+						MaxUnit:                 max_unit,
1599
+						ConsumableType:          1,
1600
+						IsEdit:                  1,
1601
+						Creator:                 adminUserInfo.AdminUser.Id,
1602
+						IsSys:                   0,
1603
+						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1604
+						WarehouseOutId:          warehouseOut.ID,
1605
+					}
1606
+
1607
+					drugFlow = append(drugFlow, drugflow)
1579 1608
 
1580 1609
 				} else {
1581 1610
 					if items["is_sys"] == nil || reflect.TypeOf(items["is_sys"]).String() != "float64" {
@@ -1619,18 +1648,286 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1619 1648
 						CountUnit:               count_unit,
1620 1649
 					}
1621 1650
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1651
+
1652
+					drugflow := &models.DrugFlow{
1653
+						WarehousingOrder:        "",
1654
+						WarehousingId:           0,
1655
+						DrugId:                  drug_id,
1656
+						Number:                  number,
1657
+						ProductDate:             productDates,
1658
+						ExpireDate:              expiryDates,
1659
+						Count:                   count,
1660
+						Price:                   price,
1661
+						Status:                  1,
1662
+						Ctime:                   ctime,
1663
+						UserOrgId:               adminUserInfo.CurrentOrgId,
1664
+						Manufacturer:            manufacturer,
1665
+						Dealer:                  dealer,
1666
+						BatchNumber:             batch_number,
1667
+						MaxUnit:                 max_unit,
1668
+						ConsumableType:          1,
1669
+						IsEdit:                  1,
1670
+						Creator:                 adminUserInfo.AdminUser.Id,
1671
+						IsSys:                   0,
1672
+						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1673
+						WarehouseOutId:          warehouseOut.ID,
1674
+					}
1675
+
1676
+					drugFlow = append(drugFlow, drugflow)
1622 1677
 				}
1623 1678
 			}
1624 1679
 		}
1625 1680
 	}
1626 1681
 	var errs error
1627 1682
 	if len(warehousingOutInfo) > 0 {
1628
-		errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1683
+
1684
+		var total_count int64
1685
+		var prescribing_number_total int64
1686
+		//调用出库逻辑
1687
+		for _, item := range warehousingOutInfo {
1688
+			//获取药品库存
1689
+			info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1690
+			//查询改药品信息
1691
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
1692
+			//判断单位是否相等
1693
+			if medical.MaxUnit == item.CountUnit {
1694
+				//转化为最小单位
1695
+				total_count = info.Count * medical.MinNumber
1696
+				prescribing_number_total = item.Count * medical.MinNumber
1697
+			}
1698
+			if medical.MinUnit == item.CountUnit {
1699
+				total_count = info.Count
1700
+				prescribing_number_total = item.Count
1701
+			}
1702
+
1703
+			fmt.Println("数量一", prescribing_number_total)
1704
+			fmt.Println("数量二", total_count)
1705
+			//判断单位
1706
+			if total_count == 0 {
1707
+				goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1708
+				c.ServeSuccessJSON(map[string]interface{}{
1709
+					"msg":        "1",
1710
+					"drug_name":  goodObj.DrugName,
1711
+					"dose":       goodObj.Dose,
1712
+					"dose_unit":  goodObj.DoseUnit,
1713
+					"min_number": goodObj.MinNumber,
1714
+					"min_unit":   goodObj.MinUnit,
1715
+					"max_unit":   goodObj.MaxUnit,
1716
+				})
1717
+				return
1718
+			}
1719
+			if prescribing_number_total > total_count {
1720
+
1721
+				goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1722
+				c.ServeSuccessJSON(map[string]interface{}{
1723
+					"msg":        "1",
1724
+					"drug_name":  goodObj.DrugName,
1725
+					"dose":       goodObj.Dose,
1726
+					"dose_unit":  goodObj.DoseUnit,
1727
+					"min_number": goodObj.MinNumber,
1728
+					"min_unit":   goodObj.MinUnit,
1729
+					"max_unit":   goodObj.MaxUnit,
1730
+				})
1731
+				return
1732
+			} else {
1733
+				errs = service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1734
+				service.CreateDrugFlow(drugFlow)
1735
+				// 出库流程
1736
+				// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1737
+				drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1738
+				if drup.ID > 0 {
1739
+					prescribingNumber := item.Count
1740
+					service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &tempWarehouseOut, &drup, item)
1741
+				}
1742
+			}
1743
+
1744
+		}
1629 1745
 	}
1630 1746
 
1631 1747
 	if len(upDateWarehouseOutInfos) > 0 {
1632 1748
 		for _, item := range upDateWarehouseOutInfos {
1633
-			errs = service.UpDateDrugWarehouseOutInfo(item)
1749
+			//获取药品库存
1750
+			info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1751
+			//查询改药品信息
1752
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
1753
+			//查询最后一次出库记录
1754
+			outInfo, _ := service.GetLastDrugWarehouseOutInfo(item.DrugId, item.WarehouseOutId, item.OrgId)
1755
+			var min_number int64 //最后一次库存
1756
+			var max_number int64 //当前库存
1757
+			var all_number int64 //总库存
1758
+			var cha_number int64 //库存差
1759
+			var maxNumber int64
1760
+			var minNumber int64
1761
+
1762
+			if medical.MaxUnit == outInfo.CountUnit {
1763
+				//转为最小单位
1764
+				min_number = outInfo.Count * medical.MinNumber
1765
+			}
1766
+
1767
+			if medical.MinUnit == outInfo.CountUnit {
1768
+				min_number = outInfo.Count
1769
+			}
1770
+
1771
+			fmt.Println("单位1", medical.MaxUnit)
1772
+			fmt.Println("单位2", item.CountUnit)
1773
+			if medical.MaxUnit == item.CountUnit {
1774
+				max_number = item.Count * medical.MinNumber
1775
+			}
1776
+
1777
+			if medical.MinUnit == item.CountUnit {
1778
+				max_number = item.Count
1779
+			}
1780
+
1781
+			all_number = info.Count*medical.MinNumber + info.StockMinNumber
1782
+			fmt.Println("总库存223232", all_number)
1783
+			fmt.Println("当前库存00000000000000000000000000000000000000000", max_number)
1784
+			////比较当前出库数量 和 最后一次出库数量,正常出库
1785
+			if max_number <= min_number {
1786
+				errs = service.UpDateDrugWarehouseOutInfo(item)
1787
+				cha_number = min_number - max_number
1788
+				fmt.Println("差库存", cha_number)
1789
+				fmt.Println("最后一次库存0000000000000000000000000000000000000000", min_number)
1790
+				if item.CountUnit == medical.MaxUnit {
1791
+					maxNumber = cha_number / medical.MinNumber
1792
+					parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1793
+					if parseDateErr != nil {
1794
+						utils.ErrorLog(errs.Error())
1795
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1796
+						return
1797
+					}
1798
+
1799
+					c.ServeSuccessJSON(map[string]interface{}{
1800
+						"msg":        "2",
1801
+						"drug_name":  "",
1802
+						"dose":       "",
1803
+						"dose_unit":  "",
1804
+						"min_number": "",
1805
+						"min_unit":   "",
1806
+						"max_unit":   "",
1807
+					})
1808
+					minNumber = cha_number % medical.MinNumber
1809
+					parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId)
1810
+					if parseDateErr != nil {
1811
+						utils.ErrorLog(errs.Error())
1812
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1813
+						return
1814
+					}
1815
+
1816
+					c.ServeSuccessJSON(map[string]interface{}{
1817
+						"msg":        "2",
1818
+						"drug_name":  "",
1819
+						"dose":       "",
1820
+						"dose_unit":  "",
1821
+						"min_number": "",
1822
+						"min_unit":   "",
1823
+						"max_unit":   "",
1824
+					})
1825
+				}
1826
+				if item.CountUnit == medical.MinUnit {
1827
+					parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId)
1828
+					if parseDateErr != nil {
1829
+						utils.ErrorLog(errs.Error())
1830
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1831
+						return
1832
+					}
1833
+
1834
+					c.ServeSuccessJSON(map[string]interface{}{
1835
+						"msg":        "2",
1836
+						"drug_name":  "",
1837
+						"dose":       "",
1838
+						"dose_unit":  "",
1839
+						"min_number": "",
1840
+						"min_unit":   "",
1841
+						"max_unit":   "",
1842
+					})
1843
+				}
1844
+
1845
+			}
1846
+
1847
+			fmt.Println("当前出库", max_number)
1848
+			fmt.Println("最后一次232233", min_number)
1849
+			//退库操作
1850
+			if max_number > min_number {
1851
+
1852
+				cha_number = min_number - max_number
1853
+				//如果总库存大于差,正常出库
1854
+				if all_number >= cha_number {
1855
+
1856
+					errs = service.UpDateDrugWarehouseOutInfo(item)
1857
+					fmt.Println("232322332233232", item.CountUnit, medical.MaxUnit)
1858
+					if item.CountUnit == medical.MaxUnit {
1859
+						maxNumber = cha_number / medical.MinNumber
1860
+						fmt.Println("maxNumber232323232323232232", maxNumber)
1861
+						parseDateErr := service.UpdateWarehouseInfo(maxNumber, item.DrugId, item.OrgId)
1862
+						fmt.Println("parseDateErr9999999999999999999999", parseDateErr)
1863
+						if parseDateErr != nil {
1864
+							utils.ErrorLog(errs.Error())
1865
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1866
+							return
1867
+						}
1868
+
1869
+						c.ServeSuccessJSON(map[string]interface{}{
1870
+							"msg":        "2",
1871
+							"drug_name":  "",
1872
+							"dose":       "",
1873
+							"dose_unit":  "",
1874
+							"min_number": "",
1875
+							"min_unit":   "",
1876
+							"max_unit":   "",
1877
+						})
1878
+						minNumber = cha_number % medical.MinNumber
1879
+						parseDateErr = service.UpdateWarehouseInfoOne(minNumber, item.DrugId, item.OrgId)
1880
+						if parseDateErr != nil {
1881
+							utils.ErrorLog(errs.Error())
1882
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1883
+							return
1884
+						}
1885
+
1886
+						c.ServeSuccessJSON(map[string]interface{}{
1887
+							"msg":        "2",
1888
+							"drug_name":  "",
1889
+							"dose":       "",
1890
+							"dose_unit":  "",
1891
+							"min_number": "",
1892
+							"min_unit":   "",
1893
+							"max_unit":   "",
1894
+						})
1895
+					}
1896
+					if item.CountUnit == medical.MinUnit {
1897
+						parseDateErr := service.UpdateWarehouseInfoOne(cha_number, item.DrugId, item.OrgId)
1898
+						if parseDateErr != nil {
1899
+							utils.ErrorLog(errs.Error())
1900
+							c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1901
+							return
1902
+						}
1903
+
1904
+						c.ServeSuccessJSON(map[string]interface{}{
1905
+							"msg":        "2",
1906
+							"drug_name":  "",
1907
+							"dose":       "",
1908
+							"dose_unit":  "",
1909
+							"min_number": "",
1910
+							"min_unit":   "",
1911
+							"max_unit":   "",
1912
+						})
1913
+					}
1914
+				}
1915
+
1916
+				if all_number < cha_number {
1917
+					goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1918
+					c.ServeSuccessJSON(map[string]interface{}{
1919
+						"msg":        "1",
1920
+						"drug_name":  goodObj.DrugName,
1921
+						"dose":       goodObj.Dose,
1922
+						"dose_unit":  goodObj.DoseUnit,
1923
+						"min_number": goodObj.MinNumber,
1924
+						"min_unit":   goodObj.MinUnit,
1925
+						"max_unit":   goodObj.MaxUnit,
1926
+					})
1927
+					return
1928
+				}
1929
+			}
1930
+
1634 1931
 		}
1635 1932
 	}
1636 1933
 
@@ -1641,7 +1938,13 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1641 1938
 	}
1642 1939
 
1643 1940
 	c.ServeSuccessJSON(map[string]interface{}{
1644
-		"msg": "编辑成功",
1941
+		"msg":        "2",
1942
+		"drug_name":  "",
1943
+		"dose":       "",
1944
+		"dose_unit":  "",
1945
+		"min_number": "",
1946
+		"min_unit":   "",
1947
+		"max_unit":   "",
1645 1948
 	})
1646 1949
 
1647 1950
 }
@@ -1658,6 +1961,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1658 1961
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1659 1962
 		return
1660 1963
 	}
1964
+	fmt.Println("cancelStockDate232323223233223", cancelStockDate.Unix())
1661 1965
 
1662 1966
 	adminUserInfo := c.GetAdminUserInfo()
1663 1967
 	operation_time := time.Now().Unix()
@@ -1683,6 +1987,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1683 1987
 		Type:         types,
1684 1988
 	}
1685 1989
 	service.AddSigleDrugCancelStock(&cancelStock)
1990
+	fmt.Println("hh232323232323232323232323232322332", parseDateErr)
1686 1991
 	dataBody := make(map[string]interface{}, 0)
1687 1992
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1688 1993
 	if err != nil {
@@ -1692,6 +1997,7 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1692 1997
 	}
1693 1998
 
1694 1999
 	var cancelStockInfos []*models.DrugCancelStockInfo
2000
+	var drugFlow []*models.DrugFlow
1695 2001
 
1696 2002
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
1697 2003
 		thisStockIn, _ := dataBody["cancelStock"].([]interface{})
@@ -1773,6 +2079,9 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1773 2079
 
1774 2080
 				batch_number := items["batch_number"].(string)
1775 2081
 				max_unit := items["max_unit"].(string)
2082
+				batch_number_id := int64(items["batch_number_id"].(float64))
2083
+
2084
+				fmt.Println("99999999999999999999", batch_number_id)
1776 2085
 				cancelStockInfo := &models.DrugCancelStockInfo{
1777 2086
 					OrderNumber:      cancelStock.OrderNumber,
1778 2087
 					CancelStockId:    cancelStock.ID,
@@ -1794,31 +2103,138 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1794 2103
 					MaxUnit:          max_unit,
1795 2104
 					ProductDate:      productDates,
1796 2105
 					ExpiryDate:       expiryDates,
2106
+					BatchNumberId:    batch_number_id,
1797 2107
 				}
1798 2108
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1799 2109
 
2110
+				flow := &models.DrugFlow{
2111
+					WarehousingId:           0,
2112
+					DrugId:                  drug_id,
2113
+					Number:                  "",
2114
+					BatchNumber:             batch_number,
2115
+					Count:                   count,
2116
+					UserOrgId:               adminUserInfo.CurrentOrgId,
2117
+					PatientId:               0,
2118
+					SystemTime:              ctime,
2119
+					ConsumableType:          4,
2120
+					IsSys:                   0,
2121
+					WarehousingOrder:        "",
2122
+					WarehouseOutId:          0,
2123
+					WarehouseOutOrderNumber: "",
2124
+					IsEdit:                  0,
2125
+					CancelStockId:           cancelStock.ID,
2126
+					CancelOrderNumber:       cancelStock.OrderNumber,
2127
+					Manufacturer:            0,
2128
+					Dealer:                  0,
2129
+					Creator:                 adminUserInfo.AdminUser.Id,
2130
+					UpdateCreator:           0,
2131
+					Status:                  1,
2132
+					Ctime:                   time.Now().Unix(),
2133
+					Mtime:                   0,
2134
+					Price:                   price,
2135
+					WarehousingDetailId:     0,
2136
+					WarehouseOutDetailId:    0,
2137
+					CancelOutDetailId:       0,
2138
+					ExpireDate:              expiryDates,
2139
+					ProductDate:             productDates,
2140
+					MaxUnit:                 max_unit,
2141
+					MinUnit:                 "",
2142
+				}
2143
+				drugFlow = append(drugFlow, flow)
1800 2144
 			}
1801 2145
 		}
1802 2146
 	}
1803
-	errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
1804
-	if errs != nil {
1805
-		utils.ErrorLog(errs.Error())
1806
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
1807
-		return
1808
-	}
2147
+	//扣减库存逻辑
2148
+	for _, item := range cancelStockInfos {
2149
+		var total_number int64
2150
+		medical, _ := service.GetBaseDrugMedical(item.DrugId)
2151
+		//将当前退库数转为最小单位
2152
+		if item.MaxUnit == medical.MaxUnit {
2153
+			total_number = item.Count * medical.MinNumber
2154
+		}
2155
+		if item.MaxUnit == medical.MinUnit {
2156
+			total_number = item.Count
2157
+		}
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
+
2166
+		//判断退库数量是否大于总入库数量
2167
+		if total_number > total_count {
2168
+			c.ServeSuccessJSON(map[string]interface{}{
2169
+				"msg": "2",
2170
+			})
2171
+			return
2172
+		}
2173
+		//正常退库
2174
+		if total_number <= total_count {
2175
+			//创建退库详情
2176
+			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2177
+			//创建库存明细
2178
+			errs = service.CreateDrugFlow(drugFlow)
2179
+
2180
+			var total int64
2181
+			////退库到当前批次,获取当前退库批次的库存
2182
+			//info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2183
+
2184
+			if medical.MaxUnit == item.MaxUnit {
2185
+				total = item.Count
2186
+
2187
+				warehouseInfo := models.XtDrugWarehouseInfo{
2188
+					StockMaxNumber: total,
2189
+				}
2190
+				errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
2191
+				if errs != nil {
2192
+					utils.ErrorLog(errs.Error())
2193
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2194
+					return
2195
+				}
1809 2196
 
1810
-	c.ServeSuccessJSON(map[string]interface{}{
1811
-		"msg": "退库成功",
1812
-	})
2197
+				c.ServeSuccessJSON(map[string]interface{}{
2198
+					"msg": "1",
2199
+				})
2200
+			}
2201
+			if medical.MinUnit == item.MaxUnit {
2202
+				fmt.Println("hhhhhh2323323232322332232332999999999进来", item.Count)
2203
+				total = item.Count
2204
+				warehouseInfo := models.XtDrugWarehouseInfo{
2205
+					StockMinNumber: total,
2206
+				}
2207
+
2208
+				errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
2209
+				if errs != nil {
2210
+					utils.ErrorLog(errs.Error())
2211
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2212
+					return
2213
+				}
2214
+
2215
+				c.ServeSuccessJSON(map[string]interface{}{
2216
+					"msg": "1",
2217
+				})
2218
+			}
2219
+			if errs != nil {
2220
+				utils.ErrorLog(errs.Error())
2221
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2222
+				return
2223
+			}
1813 2224
 
2225
+			c.ServeSuccessJSON(map[string]interface{}{
2226
+				"msg": "1",
2227
+			})
2228
+		}
2229
+	}
1814 2230
 }
1815 2231
 func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
1816 2232
 	id, _ := c.GetInt64("id", 0)
1817 2233
 	adminUserInfo := c.GetAdminUserInfo()
1818 2234
 
1819 2235
 	cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
1820
-	info, _ := service.FindCancelStockById(id, adminUserInfo.CurrentOrgId)
1821 2236
 
2237
+	info, _ := service.FindCancelDrugById(id, adminUserInfo.CurrentOrgId)
1822 2238
 	c.ServeSuccessJSON(map[string]interface{}{
1823 2239
 		"list": cancelStockInfoList,
1824 2240
 		"info": info,
@@ -1948,7 +2364,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1948 2364
 
1949 2365
 	var cancelStockInfos []*models.DrugCancelStockInfo
1950 2366
 	var upDateCancelStockInfos []*models.DrugCancelStockInfo
1951
-
2367
+	var drugFlow []*models.DrugFlow
1952 2368
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
1953 2369
 		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
1954 2370
 		if len(thisCancelStock) > 0 {
@@ -2035,6 +2451,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2035 2451
 
2036 2452
 				}
2037 2453
 
2454
+				batch_number_id := int64(items["batch_number_id"].(float64))
2038 2455
 				if id == 0 {
2039 2456
 					cancelStockInfo := &models.DrugCancelStockInfo{
2040 2457
 						DrugId:           drug_id,
@@ -2058,6 +2475,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2058 2475
 						Remark:           remark,
2059 2476
 						ProductDate:      productDates,
2060 2477
 						ExpiryDate:       expiryDates,
2478
+						BatchNumberId:    batch_number_id,
2061 2479
 					}
2062 2480
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
2063 2481
 
@@ -2085,20 +2503,180 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2085 2503
 						Remark:           remark,
2086 2504
 						ProductDate:      productDates,
2087 2505
 						ExpiryDate:       expiryDates,
2506
+						BatchNumberId:    batch_number_id,
2088 2507
 					}
2089 2508
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
2090 2509
 				}
2510
+
2511
+				flow := &models.DrugFlow{
2512
+					WarehousingId:           0,
2513
+					DrugId:                  drug_id,
2514
+					Number:                  "",
2515
+					BatchNumber:             batch_number,
2516
+					Count:                   count,
2517
+					UserOrgId:               adminUserInfo.CurrentOrgId,
2518
+					PatientId:               0,
2519
+					SystemTime:              time.Now().Unix(),
2520
+					ConsumableType:          4,
2521
+					IsSys:                   0,
2522
+					WarehousingOrder:        "",
2523
+					WarehouseOutId:          0,
2524
+					WarehouseOutOrderNumber: "",
2525
+					IsEdit:                  0,
2526
+					CancelStockId:           cancelStock.ID,
2527
+					CancelOrderNumber:       cancelStock.OrderNumber,
2528
+					Manufacturer:            0,
2529
+					Dealer:                  0,
2530
+					Creator:                 adminUserInfo.AdminUser.Id,
2531
+					UpdateCreator:           adminUserInfo.AdminUser.Id,
2532
+					Status:                  1,
2533
+					Ctime:                   time.Now().Unix(),
2534
+					Mtime:                   0,
2535
+					Price:                   price,
2536
+					WarehousingDetailId:     0,
2537
+					WarehouseOutDetailId:    0,
2538
+					CancelOutDetailId:       0,
2539
+					ExpireDate:              expiryDates,
2540
+					ProductDate:             productDates,
2541
+					MaxUnit:                 max_unit,
2542
+					MinUnit:                 "",
2543
+				}
2544
+				drugFlow = append(drugFlow, flow)
2091 2545
 			}
2092 2546
 		}
2093 2547
 	}
2548
+	fmt.Println("cancelStockInfos232323223323223322323223", cancelStockInfos)
2549
+	fmt.Println("cancelStockInfos232323223323223322323223", upDateCancelStockInfos)
2550
+
2094 2551
 	var errs error
2095 2552
 	if len(cancelStockInfos) > 0 {
2096
-		errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
2553
+
2554
+		//扣减库存逻辑
2555
+		for _, item := range cancelStockInfos {
2556
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2557
+			//查询当前药品退库的批次号的总入库数
2558
+			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2559
+			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2560
+			var total_count int64
2561
+			total_count = infoWareInfo.StockMaxNumber*medical.MinNumber + infoWareInfo.StockMinNumber
2562
+			//转化为最小单位
2563
+			var total_number int64
2564
+			if item.MaxUnit == medical.MaxUnit {
2565
+				total_number = item.Count * medical.MinNumber
2566
+			}
2567
+			if item.MaxUnit == medical.MinUnit {
2568
+				total_number = item.Count
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
+			//}
2577
+			//判断退库数量是否大于总入库数量
2578
+			if total_number > total_count {
2579
+				c.ServeSuccessJSON(map[string]interface{}{
2580
+					"msg": "2",
2581
+				})
2582
+				return
2583
+			}
2584
+
2585
+			//正常退库
2586
+			if total_number <= total_count {
2587
+				//创建退库详情
2588
+				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2589
+				//创建库存明细
2590
+				errs = service.CreateDrugFlow(drugFlow)
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)
2603
+				var total int64
2604
+
2605
+				if medical.MaxUnit == item.MaxUnit {
2606
+					total = item.Count - cancel_number
2607
+
2608
+					warehouseInfo := models.XtDrugWarehouseInfo{
2609
+						StockMaxNumber: total,
2610
+					}
2611
+					errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
2612
+					if errs != nil {
2613
+						utils.ErrorLog(errs.Error())
2614
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2615
+						return
2616
+					}
2617
+
2618
+					c.ServeSuccessJSON(map[string]interface{}{
2619
+						"msg": "1",
2620
+					})
2621
+				}
2622
+				if medical.MinUnit == item.MaxUnit {
2623
+					total = item.Count - cancel_number
2624
+					warehouseInfo := models.XtDrugWarehouseInfo{
2625
+						StockMinNumber: total,
2626
+					}
2627
+
2628
+					errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
2629
+					if errs != nil {
2630
+						utils.ErrorLog(errs.Error())
2631
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2632
+						return
2633
+					}
2634
+
2635
+					c.ServeSuccessJSON(map[string]interface{}{
2636
+						"msg": "1",
2637
+					})
2638
+				}
2639
+				if errs != nil {
2640
+					utils.ErrorLog(errs.Error())
2641
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2642
+					return
2643
+				}
2644
+
2645
+				c.ServeSuccessJSON(map[string]interface{}{
2646
+					"msg": "1",
2647
+				})
2648
+			}
2649
+		}
2650
+	}
2651
+	if len(drugFlow) > 0 {
2652
+		parseDateErr := service.CreateDrugFlow(drugFlow)
2653
+		fmt.Println(parseDateErr)
2097 2654
 	}
2098 2655
 
2099 2656
 	if len(upDateCancelStockInfos) > 0 {
2657
+		var total int64
2100 2658
 		for _, item := range upDateCancelStockInfos {
2101 2659
 			errs = service.UpDateDrugCancelStockInfo(item)
2660
+			//查询该批次最后一条退库记录
2661
+			info, _ := service.GetLastCancelStockInfo(id)
2662
+			//查询该药品的信息
2663
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2664
+
2665
+			if item.MaxUnit == medical.MaxUnit {
2666
+				item.Count = item.Count * medical.MinNumber
2667
+				//更新库存
2668
+				total = item.Count - info.Count
2669
+				fmt.Println("total232323232323232232323", total)
2670
+				service.UpdatedDrugInfo(item.BatchNumberId, total)
2671
+				break
2672
+			}
2673
+
2674
+			if item.MaxUnit == medical.MinUnit {
2675
+				item.Count = item.Count
2676
+				total = item.Count - info.Count
2677
+				service.UpdatedDrugInfoOne(item.BatchNumberId, total)
2678
+				break
2679
+			}
2102 2680
 		}
2103 2681
 	}
2104 2682
 
@@ -2109,7 +2687,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
2109 2687
 	}
2110 2688
 
2111 2689
 	c.ServeSuccessJSON(map[string]interface{}{
2112
-		"msg": "编辑成功",
2690
+		"msg": "1",
2113 2691
 	})
2114 2692
 
2115 2693
 }

+ 13 - 8
controllers/gobal_config_api_controller.go Просмотреть файл

@@ -2010,16 +2010,18 @@ func (c *GobalConfigApiController) GetDrugCountList() {
2010 2010
 	outCountList, _ := service.GetOutDrugCountList(startTime, endTime, orgId)
2011 2011
 	auCountList, err := service.GetAutoDrugCountList(startTime, endTime, orgId)
2012 2012
 	info, _ := service.GetDrugWarehouOrderInfo(startTime, endTime, orgId)
2013
+	cancelCountList, _ := service.GetCancelDrugCountList(startTime, endTime, orgId)
2013 2014
 	if err != nil {
2014 2015
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2015 2016
 		return
2016 2017
 	}
2017 2018
 	c.ServeSuccessJSON(map[string]interface{}{
2018
-		"countList":    list,
2019
-		"outCountList": outCountList,
2020
-		"auCountList":  auCountList,
2021
-		"minCount":     countList,
2022
-		"info":         info,
2019
+		"countList":       list,
2020
+		"outCountList":    outCountList,
2021
+		"auCountList":     auCountList,
2022
+		"minCount":        countList,
2023
+		"info":            info,
2024
+		"cancelCountList": cancelCountList,
2023 2025
 	})
2024 2026
 }
2025 2027
 
@@ -2053,14 +2055,17 @@ func (c *GobalConfigApiController) GetAutoDrugDetail() {
2053 2055
 	list, err, total := service.FindDrugStockUserDetailByIdThree(id, record_time, orgId)
2054 2056
 	//获取手动出库
2055 2057
 	outList, err := service.FindeDrugWarehouserInfo(warehouse_out_id, id, orgId)
2058
+
2059
+	batchNumber, err := service.GetDrugFlowBatch(warehouse_out_id, id, orgId)
2056 2060
 	if err != nil {
2057 2061
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2058 2062
 		return
2059 2063
 	}
2060 2064
 	c.ServeSuccessJSON(map[string]interface{}{
2061
-		"list":    list,
2062
-		"total":   total,
2063
-		"outList": outList,
2065
+		"list":        list,
2066
+		"total":       total,
2067
+		"outList":     outList,
2068
+		"batchNumber": batchNumber,
2064 2069
 	})
2065 2070
 }
2066 2071
 

+ 33 - 6
controllers/mobile_api_controllers/dialysis_api_controller.go Просмотреть файл

@@ -3332,7 +3332,16 @@ func (c *DialysisAPIController) CreateConsumables() {
3332 3332
 		//查询是否有库存
3333 3333
 		for _, item := range dialysisBefor {
3334 3334
 			warehouse, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId)
3335
-			fmt.Println("库存数量00000000000000000000", warehouse.StockCount)
3335
+			fmt.Println("库存数量00000000000000000000", warehouse.StockCount, err)
3336
+			if err == gorm.ErrRecordNotFound {
3337
+				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3338
+				c.ServeSuccessJSON(map[string]interface{}{
3339
+					"message":            "1",
3340
+					"good_name":          goodObj.GoodName,
3341
+					"specification_name": goodObj.SpecificationName,
3342
+				})
3343
+				return
3344
+			}
3336 3345
 			if err != nil {
3337 3346
 				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3338 3347
 				c.ServeSuccessJSON(map[string]interface{}{
@@ -3344,7 +3353,8 @@ func (c *DialysisAPIController) CreateConsumables() {
3344 3353
 			}
3345 3354
 		}
3346 3355
 
3347
-		fmt.Println("dialysisBefor9999999999999999999", dialysisBefor)
3356
+		fmt.Println("dialysisBefor9999999999999999999", dialysisBefor, active)
3357
+
3348 3358
 		//新增
3349 3359
 		if active == 1 && len(goods) > 0 {
3350 3360
 			for _, item := range dialysisBefor {
@@ -3367,7 +3377,8 @@ func (c *DialysisAPIController) CreateConsumables() {
3367 3377
 			}
3368 3378
 			if err == nil {
3369 3379
 				c.ServeSuccessJSON(map[string]interface{}{
3370
-					"msg": "保存成功",
3380
+					"msg":     "保存成功",
3381
+					"message": "2",
3371 3382
 				})
3372 3383
 				return
3373 3384
 
@@ -3801,7 +3812,20 @@ func (c *DialysisAPIController) EditConsumables() {
3801 3812
 
3802 3813
 						//查询该批次剩余库存
3803 3814
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
3815
+						if lastInfo.StockCount == 0 {
3816
+							//查询该耗材的总库存
3817
+							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
3818
+							if wareinfo.StockCount == 0 {
3819
+								goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3820
+								c.ServeSuccessJSON(map[string]interface{}{
3821
+									"message":            "1",
3822
+									"good_name":          goodObj.GoodName,
3823
+									"specification_name": goodObj.SpecificationName,
3824
+								})
3825
+								return
3826
+							}
3804 3827
 
3828
+						}
3805 3829
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
3806 3830
 						fmt.Println("剩余库存", lastInfo.StockCount)
3807 3831
 						fmt.Println("差", last_total)
@@ -4500,6 +4524,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4500 4524
 	// 先根据相关信息查询当天该耗材的出库信息
4501 4525
 	warehouseOutInfos, err := service.FindStockOutInfoByStockTwo(orgID, good_yc.GoodTypeId, good_yc.GoodId, record_time, good_yc.PatientId)
4502 4526
 	fmt.Println("errr232323232323232323232323232", err)
4527
+
4503 4528
 	if err != nil {
4504 4529
 		return err
4505 4530
 	}
@@ -4532,7 +4557,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4532 4557
 	warehouseOutInfo.Manufacturer = stockInInfo.Manufacturer
4533 4558
 	warehouseOutInfo.ExpiryDate = stockInInfo.ExpiryDate
4534 4559
 	warehouseOutInfo.ProductDate = stockInInfo.ProductDate
4535
-	warehouseOutInfo.Number = stockInInfo.Number
4560
+	warehouseOutInfo.Number = warehouseOutInfos.Number
4536 4561
 	warehouseOutInfo.LicenseNumber = stockInInfo.LicenseNumber
4537 4562
 	warehouseOutInfo.WarehouseInfotId = stockInInfo.ID
4538 4563
 	//查找当天是否存在出库记录
@@ -4546,7 +4571,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4546 4571
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4547 4572
 			WarehouseOutId:          warehouseOut.ID,
4548 4573
 			GoodId:                  good_yc.GoodId,
4549
-			Number:                  stockInInfo.Number,
4574
+			Number:                  warehouseOutInfos.Number,
4550 4575
 			ProductDate:             stockInInfo.ProductDate,
4551 4576
 			ExpireDate:              stockInInfo.ExpiryDate,
4552 4577
 			Count:                   count,
@@ -4564,6 +4589,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4564 4589
 			WarehousingDetailId:     0,
4565 4590
 			IsSys:                   1,
4566 4591
 			UpdateCreator:           creater,
4592
+			PatientId:               patient_id,
4567 4593
 		}
4568 4594
 		//创建流水表
4569 4595
 		err := service.CreateStockFlowOne(stockFlow)
@@ -4578,7 +4604,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4578 4604
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
4579 4605
 			WarehouseOutId:          warehouseOut.ID,
4580 4606
 			GoodId:                  good_yc.GoodId,
4581
-			Number:                  stockInInfo.Number,
4607
+			Number:                  warehouseOutInfos.Number,
4582 4608
 			ProductDate:             stockInInfo.ProductDate,
4583 4609
 			ExpireDate:              stockInInfo.ExpiryDate,
4584 4610
 			Count:                   count,
@@ -4596,6 +4622,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
4596 4622
 			WarehousingDetailId:     0,
4597 4623
 			IsSys:                   1,
4598 4624
 			UpdateCreator:           creater,
4625
+			PatientId:               patient_id,
4599 4626
 		}
4600 4627
 		//创建流水表
4601 4628
 		service.CreateStockFlowOne(stockFlow)

+ 131 - 23
controllers/mobile_api_controllers/patient_api_controller.go Просмотреть файл

@@ -608,7 +608,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
608 608
 
609 609
 		//自备药信息
610 610
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
611
-
611
+		fmt.Println("2323232323232323232开关", drugStockConfig.IsOpen)
612 612
 		if drugStockConfig.IsOpen == 1 {
613 613
 			if groupno > 0 {
614 614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
@@ -620,21 +620,42 @@ func (c *PatientApiController) ExecDoctorAdvice() {
620 620
 				}
621 621
 
622 622
 				if isHasWay {
623
+					var total int64
624
+					var prescribing_number_total int64
623 625
 					for _, item := range advices {
624 626
 						if item.Way == 1 {
625 627
 							//查询该药品是否有库存
626 628
 							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 {
629
+							fmt.Println("list23232323232232323232323232", list)
630
+							//查询改药品信息
631
+							medical, _ := service.GetBaseDrugMedical(item.DrugId)
632
+							//判断单位是否相等
633
+							if medical.MaxUnit == item.PrescribingNumberUnit {
634
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
635
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
636
+								//转化为最小单位
637
+								total = list.Count * medical.MinNumber
638
+								prescribing_number_total = count * medical.MinNumber
639
+							}
640
+							if medical.MinUnit == item.PrescribingNumberUnit {
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
645
+							}
646
+
647
+							fmt.Println("数量一", prescribing_number_total)
648
+							fmt.Println("数量二", total)
649
+
650
+							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
630 651
 								c.ServeSuccessJSON(map[string]interface{}{
631
-									"msg":    "1",
652
+									"msg":    "3",
632 653
 									"advice": advice,
633 654
 									"ids":    ids,
634 655
 								})
635 656
 								return
636 657
 							}
637
-							if count > list.Count {
658
+							if prescribing_number_total > total {
638 659
 								c.ServeSuccessJSON(map[string]interface{}{
639 660
 									"msg":    "2",
640 661
 									"advice": advice,
@@ -642,11 +663,21 @@ func (c *PatientApiController) ExecDoctorAdvice() {
642 663
 								})
643 664
 								return
644 665
 							}
645
-							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
666
+							if prescribing_number_total <= total {
667
+								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
668
+								c.ServeSuccessJSON(map[string]interface{}{
669
+									"msg":    "1",
670
+									"advice": advice,
671
+									"ids":    ids,
672
+								})
673
+								return
674
+							}
675
+
646 676
 						}
647 677
 					}
648 678
 				}
649 679
 			} else {
680
+
650 681
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
651 682
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
652 683
 
@@ -655,25 +686,45 @@ func (c *PatientApiController) ExecDoctorAdvice() {
655 686
 						isHasWay = true
656 687
 					}
657 688
 				}
689
+				fmt.Println("hh2h32323232323232323", isHasWay)
658 690
 				if isHasWay {
691
+					var total int64
692
+					var prescribing_number_total int64
659 693
 					for _, item := range advices {
694
+						fmt.Println("hhh23h2h3h232323", item.Way)
660 695
 						if item.Way == 1 {
661 696
 							//查询该药品是否有库存
662 697
 							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 698
 
668
-							if list.Count == 0 {
699
+							//查询改药品信息
700
+							medical, _ := service.GetBaseDrugMedical(item.DrugId)
701
+							//判断单位是否相等
702
+							if medical.MaxUnit == item.PrescribingNumberUnit {
703
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
704
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
705
+								//转化为最小单位
706
+								total = list.Count * medical.MinNumber
707
+								prescribing_number_total = count * medical.MinNumber
708
+							}
709
+							if medical.MinUnit == item.PrescribingNumberUnit {
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
714
+							}
715
+
716
+							fmt.Println("数量一", prescribing_number_total)
717
+							fmt.Println("数量二", total)
718
+
719
+							if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
669 720
 								c.ServeSuccessJSON(map[string]interface{}{
670
-									"msg":    "1",
721
+									"msg":    "3",
671 722
 									"advice": advice,
672 723
 									"ids":    ids,
673 724
 								})
674 725
 								return
675 726
 							}
676
-							if count > list.Count {
727
+							if prescribing_number_total > total {
677 728
 								c.ServeSuccessJSON(map[string]interface{}{
678 729
 									"msg":    "2",
679 730
 									"advice": advice,
@@ -681,7 +732,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
681 732
 								})
682 733
 								return
683 734
 							}
684
-							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
735
+							if prescribing_number_total <= total {
736
+								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
737
+								c.ServeSuccessJSON(map[string]interface{}{
738
+									"msg":    "1",
739
+									"advice": advice,
740
+									"ids":    ids,
741
+								})
742
+								return
743
+							}
685 744
 						}
686 745
 					}
687 746
 				}
@@ -784,7 +843,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
784 843
 			}
785 844
 		}
786 845
 		c.ServeSuccessJSON(map[string]interface{}{
787
-			"msg":    "ok",
846
+			"msg":    "1",
788 847
 			"advice": advice,
789 848
 			"ids":    ids,
790 849
 		})
@@ -832,18 +891,59 @@ func (c *PatientApiController) ExecDoctorAdvice() {
832 891
 			if drugStockConfig.IsOpen == 1 {
833 892
 				advice, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)
834 893
 				//查询该药品是否有库存
894
+				//  list, _ := service.GetDrugTotalCount(advice.DrugId, advice.UserOrgId)
895
+				//  prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
896
+				//  count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
897
+				//  if list.Count == 0 {
898
+				//    c.ServeSuccessJSON(map[string]interface{}{
899
+				//      "msg":    "1",
900
+				//      "advice": advice,
901
+				//      "ids":    ids,
902
+				//    })
903
+				//    return
904
+				//  }
905
+				//  if count > list.Count {
906
+				//    c.ServeSuccessJSON(map[string]interface{}{
907
+				//      "msg":    "2",
908
+				//      "advice": advice,
909
+				//      "ids":    ids,
910
+				//    })
911
+				//    return
912
+				//}
913
+				var total int64
914
+				var prescribing_number_total int64
915
+				//查询该药品是否有库存
835 916
 				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 {
917
+
918
+				//查询改药品信息
919
+				medical, _ := service.GetBaseDrugMedical(advice.DrugId)
920
+				//判断单位是否相等
921
+				if medical.MaxUnit == advice.PrescribingNumberUnit {
922
+					prescribingNumber_temp := strconv.FormatFloat(math.Abs(advice.PrescribingNumber), 'f', 0, 64)
923
+					count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
924
+					//转化为最小单位
925
+					total = list.Count * medical.MinNumber
926
+					prescribing_number_total = count * medical.MinNumber
927
+				}
928
+				if medical.MinUnit == advice.PrescribingNumberUnit {
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
933
+				}
934
+
935
+				fmt.Println("数量一", prescribing_number_total)
936
+				fmt.Println("数量二", total)
937
+
938
+				if (list.Count*medical.MinNumber + list.StockMinNumber) == 0 {
839 939
 					c.ServeSuccessJSON(map[string]interface{}{
840
-						"msg":    "1",
940
+						"msg":    "3",
841 941
 						"advice": advice,
842 942
 						"ids":    ids,
843 943
 					})
844 944
 					return
845 945
 				}
846
-				if count > list.Count {
946
+				if prescribing_number_total > total {
847 947
 					c.ServeSuccessJSON(map[string]interface{}{
848 948
 						"msg":    "2",
849 949
 						"advice": advice,
@@ -851,8 +951,15 @@ func (c *PatientApiController) ExecDoctorAdvice() {
851 951
 					})
852 952
 					return
853 953
 				}
854
-
855
-				service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
954
+				if prescribing_number_total <= total {
955
+					service.HisDrugsDelivery(adminInfo.Org.Id, creater, &advice)
956
+					c.ServeSuccessJSON(map[string]interface{}{
957
+						"msg":    "1",
958
+						"advice": advice,
959
+						"ids":    ids,
960
+					})
961
+					return
962
+				}
856 963
 			}
857 964
 			c.ServeSuccessJSON(map[string]interface{}{
858 965
 				"msg":    "ok",
@@ -1069,6 +1176,7 @@ func (c *PatientApiController) CheckDoctorAdvice() {
1069 1176
 			"advice": advice,
1070 1177
 		})
1071 1178
 	} else if origin == 2 {
1179
+		fmt.Println("金鳌地方 大房贷首付地方阿凡达阿方")
1072 1180
 		adminInfo := c.GetMobileAdminUserInfo()
1073 1181
 		advice_id, _ := c.GetInt64("advice_id")
1074 1182
 		advices, _ := service.FindHisDoctorAdviceById(adminInfo.Org.Id, advice_id)

+ 127 - 19
controllers/patient_api_controller.go Просмотреть файл

@@ -714,7 +714,14 @@ func (c *PatientApiController) EditLapseto() {
714 714
 	//		return
715 715
 	//	}
716 716
 	//}
717
+
717 718
 	err = service.EditPatientLapseto(&patient, &lapseto)
719
+
720
+	if lapseto.LapsetoType == 3 {
721
+		service.UpdateScheduleByDeathTime(id, lapsetoTimeUnix.Unix())
722
+		service.UpdateScheduleItemByPatientId(id)
723
+	}
724
+
718 725
 	if err != nil {
719 726
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
720 727
 		return
@@ -1652,33 +1659,80 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1652 1659
 		fmt.Println("999999992322322323232", drugStockConfig.IsOpen)
1653 1660
 		//自备药信息
1654 1661
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.CurrentOrgId)
1655
-
1662
+		fmt.Println("drugStockConfig2323232332232332", drugStockConfig.IsOpen)
1656 1663
 		if drugStockConfig.IsOpen == 1 {
1657
-
1664
+			var total int64
1665
+			var prescribing_number_total int64
1658 1666
 			advices, _ := service.GetExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1659 1667
 			for _, item := range advices {
1660 1668
 				fmt.Println("imte00000000000000", item.PrescribingNumber)
1661
-
1662 1669
 				//查询该药品是否有库存
1663 1670
 				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 {
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 {
1667 1693
 					c.ServeSuccessJSON(map[string]interface{}{
1668
-						"msg":    "1",
1694
+						"msg":    "3",
1669 1695
 						"advice": advice,
1670 1696
 					})
1671 1697
 					return
1672 1698
 				}
1673
-				if count > list.Count {
1699
+				if prescribing_number_total > total {
1674 1700
 					c.ServeSuccessJSON(map[string]interface{}{
1675 1701
 						"msg":    "2",
1676 1702
 						"advice": advice,
1677 1703
 					})
1678 1704
 					return
1679 1705
 				}
1680
-				//调用药品出库接口
1681
-				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)
1682 1736
 
1683 1737
 			}
1684 1738
 		}
@@ -1728,7 +1782,7 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1728 1782
 		}
1729 1783
 
1730 1784
 		c.ServeSuccessJSON(map[string]interface{}{
1731
-			"msg":    "ok",
1785
+			"msg":    "1",
1732 1786
 			"advice": advice,
1733 1787
 		})
1734 1788
 		return
@@ -1811,29 +1865,83 @@ func (c *PatientApiController) ExecDoctorAdvice() {
1811 1865
 			//查询已经执行的医嘱
1812 1866
 			advices, _ := service.GetHisExecutionDoctors(adminUserInfo.CurrentOrgId, patient, id)
1813 1867
 			for _, item := range advices {
1868
+				var total int64
1869
+				var prescribing_number_total int64
1814 1870
 				//查询该药品是否有库存
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 {
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 {
1819 1899
 					c.ServeSuccessJSON(map[string]interface{}{
1820
-						"msg":    "1",
1900
+						"msg":    "3",
1821 1901
 						"advice": advice,
1822 1902
 					})
1823 1903
 					return
1824 1904
 				}
1825
-				if count > list.Count {
1905
+				if prescribing_number_total > total {
1826 1906
 					c.ServeSuccessJSON(map[string]interface{}{
1827 1907
 						"msg":    "2",
1828 1908
 						"advice": advice,
1829 1909
 					})
1830 1910
 					return
1831 1911
 				}
1832
-				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
+				}
1833 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
+			//}
1834 1942
 		}
1835 1943
 		c.ServeSuccessJSON(map[string]interface{}{
1836
-			"msg":    "ok",
1944
+			"msg":    "1",
1837 1945
 			"advice": advice,
1838 1946
 		})
1839 1947
 		return

+ 46 - 0
controllers/print_data_api_controller.go Просмотреть файл

@@ -16,6 +16,7 @@ func PrintDataAPIControllerRegistRouters() {
16 16
 	beego.Router("/api/print/stock", &PrintDataAPIController{}, "get:StockRecordPrintData")
17 17
 	beego.Router("/api/print/course", &PrintDataAPIController{}, "get:CourseRecordPrintData")
18 18
 	beego.Router("/api/print/getlastafterweight", &PrintDataAPIController{}, "get:GetLastAfterWeight")
19
+	beego.Router("/api/stock/getgooddetailprintlist", &PrintDataAPIController{}, "get:GetGoodDetailPrintList")
19 20
 }
20 21
 
21 22
 type PrintDataAPIController struct {
@@ -159,3 +160,48 @@ func (this *PrintDataAPIController) GetLastAfterWeight() {
159 160
 		"weight": weight,
160 161
 	})
161 162
 }
163
+
164
+func (this *PrintDataAPIController) GetGoodDetailPrintList() {
165
+
166
+	types, _ := this.GetInt("type", 0)
167
+	start_time := this.GetString("start_time")
168
+	end_time := this.GetString("end_time")
169
+	adminUserInfo := this.GetAdminUserInfo()
170
+
171
+	timeLayout := "2006-01-02"
172
+	loc, _ := time.LoadLocation("Local")
173
+	var startTime int64
174
+	if len(start_time) > 0 {
175
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
176
+		if err != nil {
177
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
178
+			return
179
+		}
180
+		startTime = theTime.Unix()
181
+	}
182
+	var endTime int64
183
+	if len(end_time) > 0 {
184
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
185
+		if err != nil {
186
+			utils.ErrorLog(err.Error())
187
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
188
+			return
189
+		}
190
+		endTime = theTime.Unix()
191
+	}
192
+	limit, _ := this.GetInt64("limit")
193
+	page, _ := this.GetInt64("page")
194
+
195
+	//入库详情
196
+	if types == 1 {
197
+		list, err := service.GetWarehouseInfoGoodDetailPrintList(adminUserInfo.CurrentOrgId, startTime, endTime, limit, page)
198
+		if err != nil {
199
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
200
+			return
201
+		}
202
+		this.ServeSuccessJSON(map[string]interface{}{
203
+			"list": list,
204
+		})
205
+	}
206
+
207
+}

+ 1 - 1
controllers/schedule_api_controller.go Просмотреть файл

@@ -2087,7 +2087,7 @@ func (this *ScheduleApiController) GetCopyPatientSchedules() {
2087 2087
 			item.ScheduleDate = copy_startime + 432000
2088 2088
 		}
2089 2089
 		//礼拜天
2090
-		if item.ScheduleWeek == 0 {
2090
+		if item.ScheduleWeek == 7 {
2091 2091
 			item.ScheduleDate = copy_endtime
2092 2092
 		}
2093 2093
 		schedule := models.XtSchedule{

+ 247 - 61
controllers/stock_in_api_controller.go Просмотреть файл

@@ -1539,6 +1539,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1539 1539
 
1540 1540
 			//1.查询该耗材该批次的最后一次出库记录
1541 1541
 			lastGood, _ := service.GetLastGoodInformationByGoodId(item.GoodId, item.WarehouseInfotId, adminUserInfo.CurrentOrgId)
1542
+			fmt.Println("lastGood", lastGood.Count)
1543
+			fmt.Println("item2323232", item.Count)
1542 1544
 
1543 1545
 			// 退库的库存和该耗材该批次最后一次出库数量进行比较
1544 1546
 			//如果退库数量大于 最后一次批次的数量(要么要进行出库)
@@ -1622,7 +1624,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1622 1624
 								return
1623 1625
 							}
1624 1626
 							c.ServeSuccessJSON(map[string]interface{}{
1625
-								"msg": "编辑成功",
1627
+								"msg": "1",
1626 1628
 							})
1627 1629
 						} else if errcode == nil {
1628 1630
 							service.UpDateWarehouseOutInfo(item)
@@ -1695,7 +1697,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1695 1697
 							return
1696 1698
 						}
1697 1699
 						c.ServeSuccessJSON(map[string]interface{}{
1698
-							"msg": "编辑成功",
1700
+							"msg": "1",
1699 1701
 						})
1700 1702
 					} else if errcode == nil {
1701 1703
 						service.UpDateWarehouseOutInfo(item)
@@ -1713,6 +1715,14 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1713 1715
 
1714 1716
 			if item.Count == lastGood.Count {
1715 1717
 				errs = service.UpDateWarehouseOutInfo(item)
1718
+				if errs != nil {
1719
+					utils.ErrorLog(errs.Error())
1720
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1721
+					return
1722
+				}
1723
+				c.ServeSuccessJSON(map[string]interface{}{
1724
+					"msg": "1",
1725
+				})
1716 1726
 			}
1717 1727
 
1718 1728
 		}
@@ -1773,7 +1783,7 @@ func (c *StockManagerApiController) CreateCancelStock() {
1773 1783
 	}
1774 1784
 
1775 1785
 	var cancelStockInfos []*models.CancelStockInfo
1776
-
1786
+	var stockFLow []*models.VmStockFlow
1777 1787
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
1778 1788
 		thisStockIn, _ := dataBody["cancelStock"].([]interface{})
1779 1789
 		if len(thisStockIn) > 0 {
@@ -1812,11 +1822,8 @@ func (c *StockManagerApiController) CreateCancelStock() {
1812 1822
 
1813 1823
 				dealer, _ := items["dealer"].(string)
1814 1824
 
1815
-				//productDate, _ := items["product_date"].(string)
1816
-				//product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1817
-				//
1818
-				//expiryDate, _ := items["expiry_date"].(string)
1819
-				//expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1825
+				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1826
+
1820 1827
 				var expiryDates int64
1821 1828
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1822 1829
 					expiryDates = 0
@@ -1869,24 +1876,56 @@ func (c *StockManagerApiController) CreateCancelStock() {
1869 1876
 					RegisterAccount: register_account,
1870 1877
 					Remark:          remark,
1871 1878
 					Price:           price,
1879
+					WarehouseInfoId: warehouse_info_id,
1872 1880
 				}
1873 1881
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1874 1882
 
1883
+				flow := &models.VmStockFlow{
1884
+					WarehousingId:           0,
1885
+					GoodId:                  good_id,
1886
+					Number:                  number,
1887
+					LicenseNumber:           "",
1888
+					Count:                   count,
1889
+					UserOrgId:               adminUserInfo.CurrentOrgId,
1890
+					PatientId:               0,
1891
+					SystemTime:              time.Now().Unix(),
1892
+					ConsumableType:          4,
1893
+					IsSys:                   0,
1894
+					WarehousingOrder:        "",
1895
+					WarehouseOutId:          0,
1896
+					WarehouseOutOrderNumber: "",
1897
+					IsEdit:                  0,
1898
+					CancelStockId:           cancelStock.ID,
1899
+					CancelOrderNumber:       cancelStock.OrderNumber,
1900
+					Manufacturer:            0,
1901
+					Dealer:                  0,
1902
+					Creator:                 adminUserInfo.AdminUser.Id,
1903
+					UpdateCreator:           0,
1904
+					Status:                  1,
1905
+					Ctime:                   time.Now().Unix(),
1906
+					Mtime:                   0,
1907
+					Price:                   price,
1908
+					WarehousingDetailId:     0,
1909
+					WarehouseOutDetailId:    0,
1910
+					CancelOutDetailId:       0,
1911
+					ProductDate:             productDates,
1912
+					ExpireDate:              expiryDates,
1913
+				}
1914
+				stockFLow = append(stockFLow, flow)
1875 1915
 			}
1876 1916
 		}
1877 1917
 	}
1878
-	errs := service.CreateCancelStockInfo(cancelStockInfos)
1879 1918
 
1880 1919
 	for _, item := range cancelStockInfos {
1881 1920
 
1882
-		//查找该耗材是否有出库记录
1883
-		_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
1884
-		if errcode == gorm.ErrRecordNotFound {
1885
-			c.ServeSuccessJSON(map[string]interface{}{
1886
-				"msg": "1",
1887
-			})
1888
-			return
1889
-		}
1921
+		////查找该耗材是否有出库记录
1922
+		//_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
1923
+		//if errcode == gorm.ErrRecordNotFound {
1924
+		//	c.ServeSuccessJSON(map[string]interface{}{
1925
+		//		"msg": "1",
1926
+		//	})
1927
+		//	return
1928
+		//}
1890 1929
 
1891 1930
 		//统计该耗材的出库数量
1892 1931
 		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
@@ -1896,27 +1935,45 @@ func (c *StockManagerApiController) CreateCancelStock() {
1896 1935
 			})
1897 1936
 			return
1898 1937
 		}
1899
-	}
1900 1938
 
1901
-	// 改变入库单的值
1902
-	for _, item := range cancelStockInfos {
1939
+		//查询该批次入库的值
1940
+		infolist, _ := service.GetWarehouseInfoById(item.WarehouseInfoId)
1903 1941
 
1904
-		//查询该耗材的入库记录
1905
-		list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1906
-		//调用退库的方法
1907
-		parseDateErr := service.UpdateCancelOut(list, item.Count)
1908
-		fmt.Println("999999999999", parseDateErr)
1909
-	}
1942
+		if item.Count > infolist.WarehousingCount {
1943
+			c.ServeSuccessJSON(map[string]interface{}{
1944
+				"msg": "4",
1945
+			})
1946
+			return
1947
+		}
1910 1948
 
1911
-	if errs != nil {
1912
-		utils.ErrorLog(errs.Error())
1913
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
1914
-		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
+		}
1915 1971
 	}
1916 1972
 
1917 1973
 	c.ServeSuccessJSON(map[string]interface{}{
1918 1974
 		"msg": "3",
1919 1975
 	})
1976
+	return
1920 1977
 
1921 1978
 }
1922 1979
 func (c *StockManagerApiController) GetCancelStockInfoList() {
@@ -2052,7 +2109,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2052 2109
 
2053 2110
 	var cancelStockInfos []*models.CancelStockInfo
2054 2111
 	var upDateCancelStockInfos []*models.CancelStockInfo
2055
-
2112
+	var stockFlow []*models.VmStockFlow
2056 2113
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
2057 2114
 		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
2058 2115
 		if len(thisCancelStock) > 0 {
@@ -2156,6 +2213,40 @@ func (c *StockManagerApiController) EditCancelStock() {
2156 2213
 					}
2157 2214
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
2158 2215
 
2216
+					flow := &models.VmStockFlow{
2217
+						WarehousingId:           0,
2218
+						GoodId:                  good_id,
2219
+						Number:                  number,
2220
+						LicenseNumber:           "",
2221
+						Count:                   count,
2222
+						UserOrgId:               adminUserInfo.CurrentOrgId,
2223
+						PatientId:               0,
2224
+						SystemTime:              time.Now().Unix(),
2225
+						ConsumableType:          4,
2226
+						IsSys:                   0,
2227
+						WarehousingOrder:        "",
2228
+						WarehouseOutId:          0,
2229
+						WarehouseOutOrderNumber: "",
2230
+						IsEdit:                  2,
2231
+						CancelStockId:           cancelStock.ID,
2232
+						CancelOrderNumber:       cancelStock.OrderNumber,
2233
+						Manufacturer:            0,
2234
+						Dealer:                  0,
2235
+						Creator:                 adminUserInfo.AdminUser.Id,
2236
+						UpdateCreator:           0,
2237
+						Status:                  1,
2238
+						Ctime:                   time.Now().Unix(),
2239
+						Mtime:                   0,
2240
+						Price:                   price,
2241
+						WarehousingDetailId:     0,
2242
+						WarehouseOutDetailId:    0,
2243
+						CancelOutDetailId:       0,
2244
+						ProductDate:             productDates,
2245
+						ExpireDate:              expiryDates,
2246
+					}
2247
+
2248
+					stockFlow = append(stockFlow, flow)
2249
+
2159 2250
 				} else {
2160 2251
 					cancelStockInfo := &models.CancelStockInfo{
2161 2252
 						ID:              id,
@@ -2178,50 +2269,141 @@ func (c *StockManagerApiController) EditCancelStock() {
2178 2269
 						Price:           price,
2179 2270
 					}
2180 2271
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
2272
+
2273
+					flow := &models.VmStockFlow{
2274
+						WarehousingId:           0,
2275
+						GoodId:                  good_id,
2276
+						Number:                  number,
2277
+						LicenseNumber:           "",
2278
+						Count:                   count,
2279
+						UserOrgId:               adminUserInfo.CurrentOrgId,
2280
+						PatientId:               0,
2281
+						SystemTime:              time.Now().Unix(),
2282
+						ConsumableType:          4,
2283
+						IsSys:                   0,
2284
+						WarehousingOrder:        "",
2285
+						WarehouseOutId:          0,
2286
+						WarehouseOutOrderNumber: "",
2287
+						IsEdit:                  2,
2288
+						CancelStockId:           cancelStock.ID,
2289
+						CancelOrderNumber:       cancelStock.OrderNumber,
2290
+						Manufacturer:            0,
2291
+						Dealer:                  0,
2292
+						Creator:                 adminUserInfo.AdminUser.Id,
2293
+						UpdateCreator:           0,
2294
+						Status:                  1,
2295
+						Ctime:                   time.Now().Unix(),
2296
+						Mtime:                   0,
2297
+						Price:                   price,
2298
+						WarehousingDetailId:     0,
2299
+						WarehouseOutDetailId:    0,
2300
+						CancelOutDetailId:       0,
2301
+						ProductDate:             productDates,
2302
+						ExpireDate:              expiryDates,
2303
+					}
2304
+
2305
+					stockFlow = append(stockFlow, flow)
2181 2306
 				}
2182 2307
 			}
2183 2308
 		}
2184 2309
 	}
2185 2310
 	var errs error
2311
+	fmt.Println("出库22322333223", cancelStockInfos)
2312
+	fmt.Println("更新23232323232323233", upDateCancelStockInfos)
2186 2313
 	if len(cancelStockInfos) > 0 {
2187
-		errs = service.CreateCancelStockInfo(cancelStockInfos)
2188
-		// 改变入库单的值
2314
+
2189 2315
 		for _, item := range cancelStockInfos {
2190
-			//查询该耗材的入库记录
2191
-			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
2192
-			//调用退库的方法
2193
-			parseDateErr := service.UpdateCancelOut(list, item.Count)
2194
-			if parseDateErr != nil {
2195
-				utils.ErrorLog(errs.Error())
2196
-				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
+				})
2197 2322
 				return
2198 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
+			}
2199 2351
 
2200
-			c.ServeSuccessJSON(map[string]interface{}{
2201
-				"msg": "编辑成功",
2202
-			})
2203 2352
 		}
2204 2353
 	}
2205 2354
 
2206 2355
 	if len(upDateCancelStockInfos) > 0 {
2207 2356
 		for _, item := range upDateCancelStockInfos {
2208 2357
 
2209
-			errs = service.UpDateCancelStockInfo(item)
2210
-			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
2211
-			//调用退库的方法
2212
-			parseDateErr := service.UpdateCancelOut(list, item.Count)
2213
-			fmt.Println("999999999999", parseDateErr)
2214
-
2215
-			if parseDateErr != nil {
2216
-				utils.ErrorLog(errs.Error())
2217
-				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2218
-				return
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
+				}
2219 2374
 			}
2220
-
2221
-			c.ServeSuccessJSON(map[string]interface{}{
2222
-				"msg": "编辑成功",
2223
-			})
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
+			}
2397
+		}
2398
+		if errs != nil {
2399
+			utils.ErrorLog(errs.Error())
2400
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
2401
+			return
2224 2402
 		}
2403
+
2404
+		c.ServeSuccessJSON(map[string]interface{}{
2405
+			"msg": "3",
2406
+		})
2225 2407
 	}
2226 2408
 
2227 2409
 	if errs != nil {
@@ -2231,7 +2413,7 @@ func (c *StockManagerApiController) EditCancelStock() {
2231 2413
 	}
2232 2414
 
2233 2415
 	c.ServeSuccessJSON(map[string]interface{}{
2234
-		"msg": "编辑成功",
2416
+		"msg": "3",
2235 2417
 	})
2236 2418
 
2237 2419
 }
@@ -4254,13 +4436,17 @@ func (this *StockManagerApiController) GetOrderDetailById() {
4254 4436
 	orgId := this.GetAdminUserInfo().CurrentOrgId
4255 4437
 	//自动出库
4256 4438
 	userDetails, err, total := service.FindUserDetailByIdOne(good_id, record_time, orgId)
4439
+
4257 4440
 	//手动出库
4258 4441
 	info, _ := service.GetWarehouseOutInfoById(id, good_id)
4442
+
4443
+	stockFlowList, err := service.GetStockFlowBatchNumber(id, good_id)
4259 4444
 	if err == nil {
4260 4445
 		this.ServeSuccessJSON(map[string]interface{}{
4261
-			"list":  userDetails,
4262
-			"total": total,
4263
-			"info":  info,
4446
+			"list":          userDetails,
4447
+			"total":         total,
4448
+			"info":          info,
4449
+			"stockFlowList": stockFlowList,
4264 4450
 		})
4265 4451
 	} else {
4266 4452
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)

+ 8 - 3
models/drug_stock.go Просмотреть файл

@@ -238,6 +238,7 @@ type DrugCancelStockInfo struct {
238 238
 	BatchNumber      string      `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
239 239
 	MaxUnit          string      `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
240 240
 	BaseDrugLib      BaseDrugLib `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
241
+	BatchNumberId    int64       `gorm:"column:batch_number_id" json:"batch_number_id" form:"batch_number_id"`
241 242
 }
242 243
 
243 244
 func (DrugCancelStockInfo) TableName() string {
@@ -274,8 +275,12 @@ type VmDrugAutomaticReduceDetail struct {
274 275
 }
275 276
 
276 277
 type VmDrugWarehouseInfo struct {
277
-	DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
278
-	Count  int64 `gorm:"column:count" json:"count" form:"count"`
278
+	DrugId         int64  `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
279
+	Count          int64  `gorm:"column:count" json:"count" form:"count"`
280
+	MaxUnit        string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
281
+	MinUnit        string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
282
+	StockMinNumber int64  `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
283
+	StockMaxNumber int64  `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
279 284
 }
280 285
 
281 286
 type StDrugWarehouseOutInfo struct {
@@ -336,7 +341,7 @@ type DrugFlow struct {
336 341
 	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
337 342
 	IsEdit                  int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
338 343
 	CancelStockId           int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
339
-	CancelOrderNumber       int64   `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
344
+	CancelOrderNumber       string  `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
340 345
 	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
341 346
 	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
342 347
 	Creator                 int64   `gorm:"column:creator" json:"creator" form:"creator"`

+ 21 - 18
models/good_models.go Просмотреть файл

@@ -107,24 +107,27 @@ func (GoodsTypeOne) TableName() string {
107 107
 }
108 108
 
109 109
 type XtCancelStockInfo struct {
110
-	ID            int64       `gorm:"column:id" json:"id"`
111
-	GoodId        int64       `gorm:"column:good_id" json:"good_id"`
112
-	CancelStockId int64       `gorm:"column:cancel_stock_id" json:"cancel_stock_id"`
113
-	GoodTypeId    int64       `gorm:"column:good_type_id" json:"good_type_id"`
114
-	Count         int64       `gorm:"column:count" json:"count"`
115
-	Price         float64     `gorm:"column:price" json:"price"`
116
-	Total         float64     `gorm:"column:total" json:"total"`
117
-	ProductDate   int64       `gorm:"column:product_date" json:"product_date"`
118
-	ExpiryDate    int64       `gorm:"column:expiry_date" json:"expiry_date"`
119
-	Ctime         int64       `gorm:"column:ctime" json:"ctime"`
120
-	Mtime         int64       `gorm:"column:mtime" json:"mtime"`
121
-	Status        int64       `gorm:"column:status" json:"status"`
122
-	OrgId         int64       `gorm:"column:org_id" json:"org_id"`
123
-	OrderNumber   string      `gorm:"column:order_number" json:"order_number"`
124
-	Type          int64       `gorm:"column:type" json:"type"`
125
-	CancelStock   CancelStock `ForeignKey:CancelStockId json:"CancelStock"`
126
-	Dealer        int64       `gorm:"column:dealer" json:"dealer"`
127
-	Manufacturer  int64       `gorm:"column:manufacturer" json:"manufacturer"`
110
+	ID              int64    `gorm:"column:id" json:"id"`
111
+	GoodId          int64    `gorm:"column:good_id" json:"good_id"`
112
+	CancelStockId   int64    `gorm:"column:cancel_stock_id" json:"cancel_stock_id"`
113
+	GoodTypeId      int64    `gorm:"column:good_type_id" json:"good_type_id"`
114
+	Count           int64    `gorm:"column:count" json:"count"`
115
+	Price           float64  `gorm:"column:price" json:"price"`
116
+	Total           float64  `gorm:"column:total" json:"total"`
117
+	ProductDate     int64    `gorm:"column:product_date" json:"product_date"`
118
+	ExpiryDate      int64    `gorm:"column:expiry_date" json:"expiry_date"`
119
+	Ctime           int64    `gorm:"column:ctime" json:"ctime"`
120
+	Mtime           int64    `gorm:"column:mtime" json:"mtime"`
121
+	Status          int64    `gorm:"column:status" json:"status"`
122
+	OrgId           int64    `gorm:"column:org_id" json:"org_id"`
123
+	OrderNumber     string   `gorm:"column:order_number" json:"order_number"`
124
+	Type            int64    `gorm:"column:type" json:"type"`
125
+	Dealer          string   `gorm:"column:dealer" json:"dealer"`
126
+	Manufacturer    string   `gorm:"column:manufacturer" json:"manufacturer"`
127
+	GoodInfo        GoodInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"GoodInfo"`
128
+	Number          string   `gorm:"column:number" json:"number" form:"number"`
129
+	RegisterAccount string   `gorm:"column:register_account" json:"register_account" form:"register_account"`
130
+	Remark          string   `gorm:"column:remark" json:"remark" form:"remark"`
128 131
 }
129 132
 
130 133
 func (XtCancelStockInfo) TableName() string {

+ 12 - 2
models/self_drug_models.go Просмотреть файл

@@ -67,6 +67,7 @@ type XtBaseDrug struct {
67 67
 	LmtUsedFlag            int64   `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
68 68
 	Total                  float64 `gorm:"column:total" json:"total" form:"total"`
69 69
 	PrescribingNumberUnit  string  `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
70
+	MinNumber              int64   `gorm:"column:min_number" json:"min_number" form:"min_number"`
70 71
 }
71 72
 
72 73
 func (XtBaseDrug) TableName() string {
@@ -344,6 +345,10 @@ type XtDrugWarehouseOutInfo struct {
344 345
 	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
345 346
 	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
346 347
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
348
+	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
349
+	WarehouseInfoId         int64   `gorm:"column:warehouse_info_id" json:"warehouse_info_id" form:"warehouse_info_id"`
350
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
351
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
347 352
 }
348 353
 
349 354
 func (XtDrugWarehouseOutInfo) TableName() string {
@@ -394,6 +399,7 @@ type XtDrugWarehouseInfo struct {
394 399
 	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number"`
395 400
 	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number"`
396 401
 	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
402
+	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
397 403
 }
398 404
 
399 405
 func (XtDrugWarehouseInfo) TableName() string {
@@ -474,8 +480,8 @@ type BloodDrugCancelStockInfo struct {
474 480
 	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
475 481
 	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
476 482
 	Type             int64   `gorm:"column:type" json:"type" form:"type"`
477
-	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
478
-	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
483
+	Dealer           string  `gorm:"column:dealer" json:"dealer" form:"dealer"`
484
+	Manufacturer     string  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
479 485
 	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
480 486
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
481 487
 	Number           string  `gorm:"column:number" json:"number" form:"number"`
@@ -484,6 +490,10 @@ type BloodDrugCancelStockInfo struct {
484 490
 	DrugSpec         string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
485 491
 	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
486 492
 	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
493
+	MaxUnit          string  `json:"max_unit"`
494
+	MinNumber        int64   `json:"min_number"`
495
+	Dose             float64 `json:"dose"`
496
+	DoseUnit         string  `json:"dose_unit"`
487 497
 }
488 498
 
489 499
 type BloodDrugSalesReturnInfo struct {

+ 16 - 15
models/stock_models.go Просмотреть файл

@@ -282,20 +282,20 @@ type VmCancelStockInfo struct {
282 282
 }
283 283
 
284 284
 type CancelStock struct {
285
-	ID              int64  `gorm:"column:id" json:"id"`
286
-	OrderNumber     string `gorm:"column:order_number" json:"order_number"`
287
-	OperaTime       int64  `gorm:"column:opera_time" json:"opera_time"`
288
-	Total           int64  `gorm:"column:total" json:"total"`
289
-	Creater         int64  `gorm:"column:creater" json:"creater"`
290
-	Ctime           int64  `gorm:"column:ctime" json:"ctime"`
291
-	Mtime           int64  `gorm:"column:mtime" json:"mtime"`
292
-	Status          int64  `gorm:"column:status" json:"status"`
293
-	OrgId           int64  `gorm:"column:org_id" json:"org_id"`
294
-	ReturnTime      int64  `gorm:"column:return_time" json:"return_time"`
295
-	Dealer          int64  `gorm:"column:dealer" json:"dealer"`
296
-	Manufacturer    int64  `gorm:"column:manufacturer" json:"manufacturer"`
297
-	Type            int64  `gorm:"column:type" json:"type"`
298
-	CancelStockInfo []*XtCancelStockInfo
285
+	ID                int64                `gorm:"column:id" json:"id"`
286
+	OrderNumber       string               `gorm:"column:order_number" json:"order_number"`
287
+	OperaTime         int64                `gorm:"column:opera_time" json:"opera_time"`
288
+	Total             int64                `gorm:"column:total" json:"total"`
289
+	Creater           int64                `gorm:"column:creater" json:"creater"`
290
+	Ctime             int64                `gorm:"column:ctime" json:"ctime"`
291
+	Mtime             int64                `gorm:"column:mtime" json:"mtime"`
292
+	Status            int64                `gorm:"column:status" json:"status"`
293
+	OrgId             int64                `gorm:"column:org_id" json:"org_id"`
294
+	ReturnTime        int64                `gorm:"column:return_time" json:"return_time"`
295
+	Dealer            int64                `gorm:"column:dealer" json:"dealer"`
296
+	Manufacturer      int64                `gorm:"column:manufacturer" json:"manufacturer"`
297
+	Type              int64                `gorm:"column:type" json:"type"`
298
+	XtCancelStockInfo []*XtCancelStockInfo `gorm:"ForeignKey:CancelStockId;AssociationForeignKey:ID" json:"XtCancelStockInfo"`
299 299
 }
300 300
 
301 301
 func (CancelStock) TableName() string {
@@ -506,7 +506,7 @@ type VmStockFlow struct {
506 506
 	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
507 507
 	IsEdit                  int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
508 508
 	CancelStockId           int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
509
-	CancelOrderNumber       int64   `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
509
+	CancelOrderNumber       string  `gorm:"column:cancel_order_number" json:"cancel_order_number" form:"cancel_order_number"`
510 510
 	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
511 511
 	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
512 512
 	Creator                 int64   `gorm:"column:creator" json:"creator" form:"creator"`
@@ -548,6 +548,7 @@ type CancelStockInfo struct {
548 548
 	Number          string      `gorm:"column:number" json:"number" form:"number"`
549 549
 	RegisterAccount string      `gorm:"column:register_account" json:"register_account" form:"register_account"`
550 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 552
 	GoodInfo        GoodInfo    `gorm:"ForeignKey:ID;AssociationForeignKey:GoodId" `
552 553
 }
553 554
 

+ 25 - 2
service/gobal_config_service.go Просмотреть файл

@@ -364,9 +364,9 @@ func GetDrugCancelOrder(startime int64, endtime int64, orgid int64, orderType in
364 364
 	}
365 365
 
366 366
 	if manufacturerId > 0 {
367
-		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
367
+		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
368 368
 	} else {
369
-		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
369
+		err = db.Select("x.id,x.drug_id,x.cancel_stock_id,x.count,x.price,x.total,x.product_date,x.expiry_date,x.ctime,x.org_id,x.order_number,x.type,x.dealer,x.manufacturer,x.retail_price,x.retail_total_price,x.number,s.drug_name,s.drug_type,s.drug_spec,s.min_unit,t.creater,s.dose,s.dose_unit,s.min_number,s.max_unit").Joins("left join xt_base_drug as s on s.id = x.drug_id and s.org_id = ? and s.status = 1", orgid).Joins("left join xt_drug_cancel_stock as t on t.id = x.cancel_stock_id and t.org_id = ? and t.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&cancel).Error
370 370
 	}
371 371
 
372 372
 	return cancel, total, err
@@ -664,6 +664,23 @@ func GetAutoDrugCountList(startime int64, endtime int64, orgid int64) (info []*m
664 664
 
665 665
 }
666 666
 
667
+func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
668
+
669
+	db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
670
+
671
+	if startime > 0 {
672
+		db = db.Where("x.ctime >=?", startime)
673
+	}
674
+	if endtime > 0 {
675
+		db = db.Where("x.ctime<=?", endtime)
676
+	}
677
+	if orgid > 0 {
678
+		db = db.Where("x.org_id = ?", orgid)
679
+	}
680
+	err = db.Select("sum(x.count) as count,x.drug_id").Group("x.drug_id").Scan(&info).Error
681
+	return info, err
682
+}
683
+
667 684
 func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouseOutInfo, err error) {
668 685
 
669 686
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
@@ -714,3 +731,9 @@ func FindeDrugWarehouserInfo(ware_out_id int64, drug_id int64, orgid int64) (out
714 731
 
715 732
 	return outInfo, err
716 733
 }
734
+
735
+func GetDrugFlowBatch(ware_out_id int64, drug_id int64, orgid int64) (flow []*models.DrugFlow, err error) {
736
+
737
+	err = XTReadDB().Where("warehouse_out_id = ? and drug_id = ? and user_org_id = ? and status = 1", ware_out_id, drug_id, orgid).Group("number").Find(&flow).Error
738
+	return flow, err
739
+}

+ 11 - 0
service/patient_service.go Просмотреть файл

@@ -1504,3 +1504,14 @@ func FindRemindAdvice(user_org_id int64, advice_name string, advice_desc string,
1504 1504
 	err = XTWriteDB().Model(&models.DoctorAdvice{}).Where("patient_id = ? and user_org_id = ? and record_date = ? and advice_name = ? and advice_desc = ? and template_id = ? and frequency_type = ? AND advice_type = 2 ", patient_id, user_org_id, record_date, advice_name, advice_desc, template_id, fre_type).First(&advice).Error
1505 1505
 	return
1506 1506
 }
1507
+
1508
+func UpdateScheduleByDeathTime(patientid int64, shcheduledate int64) error {
1509
+	err := XTWriteDB().Model(models.XtSchedule{}).Where("patient_id = ? and schedule_date>?", patientid, shcheduledate).Updates(map[string]interface{}{"status": 0}).Error
1510
+	return err
1511
+}
1512
+
1513
+func UpdateScheduleItemByPatientId(id int64) error {
1514
+
1515
+	err := XTWriteDB().Model(models.PatientScheduleTemplateItem{}).Where("patient_id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
1516
+	return err
1517
+}

+ 20 - 0
service/print_data_service/schedule_dialysis/print_schedule_dialysis_service.go Просмотреть файл

@@ -214,3 +214,23 @@ func GetGoodInfomationList(orgid int64) (goodInfo []*models.GoodInfo, err error)
214 214
 	err = p_service.XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&goodInfo).Error
215 215
 	return goodInfo, err
216 216
 }
217
+
218
+func GetWarehouseInfoGoodDetailPrintList(orgid int64, startime int64, endtime int64, limit int64, page int64) (info []*models.VmWarehousingInfo, err error) {
219
+	offset := (page - 1) * limit
220
+	db := p_service.XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
221
+	table := p_service.XTReadDB().Table("xt_good_information as t").Where("t.status = 1")
222
+	fmt.Println(table)
223
+	if orgid > 0 {
224
+		db = db.Where("x.org_id = ?", orgid)
225
+	}
226
+	if startime > 0 {
227
+		db = db.Where("x.ctime>=?", startime)
228
+	}
229
+
230
+	if endtime > 0 {
231
+		db = db.Where("x.ctime<=?", endtime)
232
+	}
233
+
234
+	err = db.Select("x.id,x.warehousing_id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehousing_unit,x.stock_count,x.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.is_return,x.warehousing_order,x.type,x.license_number,t.good_name,t.specification_name,t.min_number,t.packing_unit").Joins("left join xt_good_information as t on t.id = x.good_id").Offset(offset).Limit(limit).Scan(&info).Error
235
+	return info, err
236
+}

+ 9 - 0
service/self_drug_service.go Просмотреть файл

@@ -799,3 +799,12 @@ func GetSelfOutStockQuery(startTime int64, endTime int64, orgid int64) (selfouts
799 799
 	err = db.Select("x.drug_name_id,Sum(x.outstore_number) as count").Group("x.drug_name").Scan(&selfoutstock).Error
800 800
 	return selfoutstock, err
801 801
 }
802
+
803
+func GetLastDrugWarehouseOutInfo(drugid int64, warehouseOutId int64, orgid int64) (models.XtDrugWarehouseOutInfo, error) {
804
+
805
+	info := models.XtDrugWarehouseOutInfo{}
806
+
807
+	err = XTReadDB().Model(&info).Where("drug_id = ? and  warehouse_out_id = ? and org_id = ? and status = 1", drugid, warehouseOutId, orgid).Last(&info).Error
808
+
809
+	return info, err
810
+}

+ 139 - 11
service/stock_service.go Просмотреть файл

@@ -337,6 +337,11 @@ func FindAllWarehouseTotal(org_id int64) (total int64, err error) {
337 337
 	err = readDb.Model(&models.Warehousing{}).Where("org_id = ?", org_id).Count(&total).Error
338 338
 	return total, err
339 339
 }
340
+
341
+func FindAllWarehouseTotalOne(org_id int64) (total int64, err error) {
342
+	err = readDb.Model(&models.XtDrugWarehouse{}).Where("org_id = ?", org_id).Count(&total).Error
343
+	return total, err
344
+}
340 345
 func AddSigleWarehouse(warehouse *models.Warehousing) error {
341 346
 	err := writeDb.Create(&warehouse).Error
342 347
 	return err
@@ -505,7 +510,7 @@ func CreateDrugFlow(drugflow []*models.DrugFlow) (err error) {
505 510
 	if len(drugflow) > 0 {
506 511
 		utx := writeDb.Begin()
507 512
 		if len(drugflow) > 0 {
508
-			thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit ) VALUES "
513
+			thisSQL := "INSERT INTO xt_drug_flow (warehousing_id, drug_id, number,batch_number,count,user_org_id,patient_id,system_time,consumable_type,is_sys,warehousing_order,warehouse_out_id,warehouse_out_order_number,is_edit,cancel_stock_id,cancel_order_number,manufacturer,dealer,creator,update_creator,status,ctime,mtime,price,warehousing_detail_id,warehouse_out_detail_id,cancel_out_detail_id,expire_date,product_date,max_unit,min_unit) VALUES "
509 514
 			insertParams := make([]string, 0)
510 515
 			insertData := make([]interface{}, 0)
511 516
 			for _, info := range drugflow {
@@ -1112,6 +1117,7 @@ type DrugCancelStockInfo struct {
1112 1117
 	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1113 1118
 	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
1114 1119
 	Drug             *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1120
+	BatchNumberId    int64   `gorm:"column:batch_number_id" json:"batch_number_id" form:"batch_number_id"`
1115 1121
 }
1116 1122
 
1117 1123
 func (DrugCancelStockInfo) TableName() string {
@@ -1465,11 +1471,11 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
1465 1471
 	if len(cancelStockInfo) > 0 {
1466 1472
 		utx := writeDb.Begin()
1467 1473
 		if len(cancelStockInfo) > 0 {
1468
-			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 "
1469 1475
 			insertParams := make([]string, 0)
1470 1476
 			insertData := make([]interface{}, 0)
1471 1477
 			for _, info := range cancelStockInfo {
1472
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1478
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1473 1479
 				insertData = append(insertData, info.GoodId)
1474 1480
 				insertData = append(insertData, info.CancelStockId)
1475 1481
 				insertData = append(insertData, info.GoodTypeId)
@@ -1488,6 +1494,7 @@ func CreateCancelStockInfo(cancelStockInfo []*models.CancelStockInfo) (err error
1488 1494
 				insertData = append(insertData, info.Remark)
1489 1495
 				insertData = append(insertData, info.ProductDate)
1490 1496
 				insertData = append(insertData, info.ExpiryDate)
1497
+				insertData = append(insertData, info.WarehouseInfoId)
1491 1498
 			}
1492 1499
 			thisSQL += strings.Join(insertParams, ", ")
1493 1500
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1506,11 +1513,11 @@ func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (e
1506 1513
 	if len(cancelStockInfo) > 0 {
1507 1514
 		utx := writeDb.Begin()
1508 1515
 		if len(cancelStockInfo) > 0 {
1509
-			thisSQL := "INSERT INTO xt_drug_cancel_stock_info (drug_id,cancel_stock_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price,register_account,batch_number,remark,max_unit,product_date,expiry_date) VALUES "
1516
+			thisSQL := "INSERT INTO xt_drug_cancel_stock_info (drug_id,cancel_stock_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price,register_account,batch_number,remark,max_unit,product_date,expiry_date,batch_number_id) VALUES "
1510 1517
 			insertParams := make([]string, 0)
1511 1518
 			insertData := make([]interface{}, 0)
1512 1519
 			for _, info := range cancelStockInfo {
1513
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1520
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1514 1521
 				insertData = append(insertData, info.DrugId)
1515 1522
 				insertData = append(insertData, info.CancelStockId)
1516 1523
 				insertData = append(insertData, info.Count)
@@ -1531,6 +1538,7 @@ func CreateDrugCancelStockInfo(cancelStockInfo []*models.DrugCancelStockInfo) (e
1531 1538
 				insertData = append(insertData, info.MaxUnit)
1532 1539
 				insertData = append(insertData, info.ProductDate)
1533 1540
 				insertData = append(insertData, info.ExpiryDate)
1541
+				insertData = append(insertData, info.BatchNumberId)
1534 1542
 			}
1535 1543
 			thisSQL += strings.Join(insertParams, ", ")
1536 1544
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -2145,6 +2153,12 @@ func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock
2145 2153
 
2146 2154
 }
2147 2155
 
2156
+func FindCancelDrugById(id int64, org_id int64) (cancelStock models.DrugCancelStock, err error) {
2157
+	err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
2158
+	return cancelStock, err
2159
+
2160
+}
2161
+
2148 2162
 func FindDrugCancelStockById(id int64) (cancelStock models.DrugCancelStock, err error) {
2149 2163
 	err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
2150 2164
 	return cancelStock, err
@@ -2441,7 +2455,7 @@ func FindDrugStockOutByIsSys(org_id int64, is_sys int, record_time int64) (out m
2441 2455
 }
2442 2456
 
2443 2457
 func FindLastStockInInfoRecord(good_id int64, org_id int64) (in models.WarehousingInfo, err error) {
2444
-	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).Last(&in).Error
2458
+	err = readDb.Model(&models.WarehousingInfo{}).Where("status = 1 AND org_id = ? AND good_id = ?", org_id, good_id).First(&in).Error
2445 2459
 	return
2446 2460
 }
2447 2461
 
@@ -3496,7 +3510,7 @@ func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseIn
3496 3510
 	if orgid > 0 {
3497 3511
 		db = db.Where("x.org_id = ?", orgid)
3498 3512
 	}
3499
-	err = db.Select("x.drug_id,sum(x.stock_max_number) as count").Find(&info).Error
3513
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as count,sum(x.stock_min_number) as stock_min_number,x.max_unit,x.min_unit").Find(&info).Error
3500 3514
 	return info, err
3501 3515
 }
3502 3516
 
@@ -3525,7 +3539,7 @@ func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.Wareho
3525 3539
 
3526 3540
 func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
3527 3541
 
3528
-	err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
3542
+	err := XTWriteDB().Model(models.WarehousingInfo{}).Where("good_id = ? and org_id = ? and status = 1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
3529 3543
 	return err
3530 3544
 }
3531 3545
 
@@ -3548,8 +3562,9 @@ func UpdateCancelOut(list []*models.WarehousingInfo, count int64) error {
3548 3562
 				WarehousingId: item.WarehousingId,
3549 3563
 				StockCount:    item.StockCount + count,
3550 3564
 			}
3551
-			UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
3552
-			break
3565
+			err2 := UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
3566
+			fmt.Println("2323233232323232323232323232323", err2)
3567
+			return err
3553 3568
 		}
3554 3569
 
3555 3570
 		if (item.WarehousingCount - item.StockCount) < count {
@@ -3602,7 +3617,7 @@ func GetCancelStockOrderPrintOne(idstr []string, orgid int64) (info []*models.Ca
3602 3617
 
3603 3618
 	if len(idstr) > 0 {
3604 3619
 		err = XTReadDB().Model(&info).Where("id in(?)", idstr).
3605
-			Preload("CancelStockInfo", func(db *gorm.DB) *gorm.DB {
3620
+			Preload("XtCancelStockInfo", func(db *gorm.DB) *gorm.DB {
3606 3621
 				return XTReadDB().Where("org_id=? and status = 1", orgid).Preload("GoodInfo", "status = 1 and org_id = ?", orgid)
3607 3622
 			}).Find(&info).Error
3608 3623
 	}
@@ -3665,6 +3680,12 @@ func GetWarehouseOutInfoById(id int64, goodid int64) (info []*models.WarehouseOu
3665 3680
 	return info, err
3666 3681
 }
3667 3682
 
3683
+func GetStockFlowBatchNumber(id int64, goodid int64) (stock []*models.VmStockFlow, err error) {
3684
+
3685
+	err = XTReadDB().Model(&stock).Where("warehouse_out_id = ? and good_id = ? and status = 1", id, goodid).Group("patient_id,number").Find(&stock).Error
3686
+	return stock, err
3687
+}
3688
+
3668 3689
 func GetDrugBatchNumber(drug_id int64, orgid int64) (info []*models.DrugWarehouseInfo, err error) {
3669 3690
 
3670 3691
 	err = XTReadDB().Model(&info).Where("drug_id = ? and org_id = ? and status = 1 and batch_number <>''", drug_id, orgid).Find(&info).Error
@@ -3840,6 +3861,11 @@ func GetStockFlowList(limit int64, page int64, consumable_type int64, orgId int6
3840 3861
 		if consumable_type == 3 {
3841 3862
 			db = db.Where(" consumable_type = ? and is_sys = 1", consumable_type)
3842 3863
 		}
3864
+
3865
+		//4.手动退库
3866
+		if consumable_type == 4 {
3867
+			db = db.Where(" consumable_type = ?", consumable_type)
3868
+		}
3843 3869
 	}
3844 3870
 	if orgId > 0 {
3845 3871
 		db = db.Where("user_org_id = ?", orgId)
@@ -3901,6 +3927,16 @@ func GetLastStockOut(id int64) (models.WarehousingInfo, error) {
3901 3927
 	return info, err
3902 3928
 }
3903 3929
 
3930
+func GetStockGoodCount(good_id int64) (models.WarehousingInfo, error) {
3931
+	info := models.WarehousingInfo{}
3932
+	db := XTReadDB().Model(&info)
3933
+	if good_id > 0 {
3934
+		db = db.Where("good_id = ? and status = 1", good_id)
3935
+	}
3936
+	err := db.Select("sum(stock_count) as stock_count").Find(&info).Error
3937
+	return info, err
3938
+}
3939
+
3904 3940
 func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime int64, endTime int64, stock_type int64) (drug_flow []*models.DrugFlow, total int64, err error) {
3905 3941
 
3906 3942
 	offset := (page - 1) * limit
@@ -3933,6 +3969,9 @@ func GetDrugFlow(drugid int64, orgid int64, limit int64, page int64, startTime i
3933 3969
 		if stock_type == 3 {
3934 3970
 			db = db.Where("consumable_type = 3 and is_sys = 1")
3935 3971
 		}
3972
+		if stock_type == 4 {
3973
+			db = db.Where("consumable_type = 4")
3974
+		}
3936 3975
 	}
3937 3976
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&drug_flow).Error
3938 3977
 	return drug_flow, total, err
@@ -3991,3 +4030,92 @@ func GetCancelStockDetail(id int64) (info []*models.DrugCancelStockInfo, err err
3991 4030
 	err = db.Find(&info).Error
3992 4031
 	return info, err
3993 4032
 }
4033
+
4034
+func GetDrugWarehouseInfo(id int64) (models.XtDrugWarehouseInfo, error) {
4035
+
4036
+	info := models.XtDrugWarehouseInfo{}
4037
+
4038
+	db := XTReadDB().Model(&info).Where("status = 1")
4039
+	if id > 0 {
4040
+		db = db.Where("id = ?", id)
4041
+	}
4042
+	err := db.Select("drug_id,warehousing_count,stock_max_number,stock_min_number").Find(&info).Error
4043
+
4044
+	return info, err
4045
+}
4046
+
4047
+func GetDrugWarehouseInfoById(id int64) (models.XtDrugWarehouseInfo, error) {
4048
+
4049
+	info := models.XtDrugWarehouseInfo{}
4050
+	err := XTReadDB().Model(&info).Where("id=? and status =1", id).Find(&info).Error
4051
+	return info, err
4052
+}
4053
+
4054
+func UpdateDrugWarehouseInfo(info *models.XtDrugWarehouseInfo, id int64) error {
4055
+
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
4059
+	return err
4060
+}
4061
+
4062
+func UpdateDrugWarehouseInfoOne(info *models.XtDrugWarehouseInfo, id int64) error {
4063
+
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
4068
+	return err
4069
+}
4070
+
4071
+func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
4072
+
4073
+	info := models.DrugCancelStockInfo{}
4074
+
4075
+	err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
4076
+	return info, err
4077
+}
4078
+
4079
+func UpdatedDrugInfo(id int64, count int64) (err error) {
4080
+
4081
+	err = writeDb.Model(&models.DrugWarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4082
+	return err
4083
+}
4084
+
4085
+func UpdatedDrugInfoOne(id int64, count int64) (err error) {
4086
+
4087
+	err = writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4088
+	return err
4089
+}
4090
+
4091
+func UpdateWarehouseInfo(count int64, drugid int64, orgid int64) error {
4092
+
4093
+	err := writeDb.Model(&models.XtDrugWarehouseInfo{}).Where("drug_id = ?  and org_id = ? and status = 1", drugid, orgid).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4094
+
4095
+	return err
4096
+}
4097
+
4098
+func UpdateWarehouseInfoOne(count int64, drugid int64, orgid int64) error {
4099
+
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
4101
+	return err
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
+}

+ 16 - 12
service/warhouse_service.go Просмотреть файл

@@ -957,8 +957,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
957 957
 				Number:                  warehouse.Number,
958 958
 				ProductDate:             warehouse.ProductDate,
959 959
 				ExpireDate:              warehouse.ExpiryDate,
960
-				Count:                   count,
961
-				Price:                   warehouse.Price,
960
+				Count:                   deliver_number,
961
+				Price:                   info.PackingPrice,
962 962
 				Status:                  1,
963 963
 				Ctime:                   time.Now().Unix(),
964 964
 				UserOrgId:               orgID,
@@ -972,6 +972,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
972 972
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
973 973
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
974 974
 				IsSys:                   1,
975
+				PatientId:               patient_id,
975 976
 			}
976 977
 			CreateStockFlowOne(flow)
977 978
 			if errTwo != nil {
@@ -988,8 +989,8 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
988 989
 				Number:                  warehouse.Number,
989 990
 				ProductDate:             warehouse.ProductDate,
990 991
 				ExpireDate:              warehouse.ExpiryDate,
991
-				Count:                   count,
992
-				Price:                   warehouse.Price,
992
+				Count:                   deliver_number,
993
+				Price:                   info.PackingPrice,
993 994
 				Status:                  1,
994 995
 				Ctime:                   time.Now().Unix(),
995 996
 				UserOrgId:               orgID,
@@ -1003,6 +1004,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1003 1004
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
1004 1005
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1005 1006
 				IsSys:                   1,
1007
+				PatientId:               patient_id,
1006 1008
 			}
1007 1009
 			CreateStockFlowOne(flow)
1008 1010
 		}
@@ -1069,7 +1071,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1069 1071
 				Number:                  warehouse.Number,
1070 1072
 				ProductDate:             warehouse.ProductDate,
1071 1073
 				ExpireDate:              warehouse.ExpiryDate,
1072
-				Count:                   count,
1074
+				Count:                   stock_number,
1073 1075
 				Price:                   warehouse.Price,
1074 1076
 				Status:                  1,
1075 1077
 				Ctime:                   time.Now().Unix(),
@@ -1084,6 +1086,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1084 1086
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
1085 1087
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1086 1088
 				IsSys:                   1,
1089
+				PatientId:               patient_id,
1087 1090
 			}
1088 1091
 			CreateStockFlowOne(flow)
1089 1092
 		} else if errcodes == nil {
@@ -1099,7 +1102,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1099 1102
 				Number:                  warehouse.Number,
1100 1103
 				ProductDate:             warehouse.ProductDate,
1101 1104
 				ExpireDate:              warehouse.ExpiryDate,
1102
-				Count:                   count,
1105
+				Count:                   goods.Count + stock_number,
1103 1106
 				Price:                   warehouse.Price,
1104 1107
 				Status:                  1,
1105 1108
 				Ctime:                   time.Now().Unix(),
@@ -1114,6 +1117,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1114 1117
 				WarehouseOutDetailId:    warehouseOutInfo.ID,
1115 1118
 				WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1116 1119
 				IsSys:                   1,
1120
+				PatientId:               patient_id,
1117 1121
 			}
1118 1122
 			CreateStockFlowOne(flow)
1119 1123
 		}
@@ -1258,7 +1262,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1258 1262
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
1259 1263
 	fmt.Println("err222222222222222222222", warehouse.StockCount)
1260 1264
 	if err != nil {
1261
-		fmt.Println("232323232323进来")
1265
+
1262 1266
 		return err
1263 1267
 	}
1264 1268
 
@@ -1306,14 +1310,14 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1306 1310
 			UserOrgId:               goods.OrgId,
1307 1311
 			PatientId:               goods.PatientId,
1308 1312
 			SystemTime:              record_time,
1309
-			ConsumableType:          3,
1313
+			ConsumableType:          2,
1310 1314
 			IsSys:                   goods.IsSys,
1311 1315
 			WarehousingOrder:        "",
1312 1316
 			WarehouseOutId:          warehouseOut.ID,
1313 1317
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1314 1318
 			IsEdit:                  1,
1315 1319
 			CancelStockId:           0,
1316
-			CancelOrderNumber:       0,
1320
+			CancelOrderNumber:       "",
1317 1321
 			Manufacturer:            goods.Manufacturer,
1318 1322
 			Dealer:                  goods.Dealer,
1319 1323
 			Creator:                 creator,
@@ -1394,14 +1398,14 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1394 1398
 			UserOrgId:               goods.OrgId,
1395 1399
 			PatientId:               0,
1396 1400
 			SystemTime:              record_time,
1397
-			ConsumableType:          3,
1401
+			ConsumableType:          2,
1398 1402
 			IsSys:                   0,
1399 1403
 			WarehousingOrder:        "",
1400 1404
 			WarehouseOutId:          warehouseOut.ID,
1401 1405
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1402 1406
 			IsEdit:                  1,
1403 1407
 			CancelStockId:           0,
1404
-			CancelOrderNumber:       0,
1408
+			CancelOrderNumber:       "",
1405 1409
 			Manufacturer:            goods.Manufacturer,
1406 1410
 			Dealer:                  goods.Dealer,
1407 1411
 			Creator:                 creator,
@@ -1610,7 +1614,7 @@ func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count i
1610 1614
 }
1611 1615
 
1612 1616
 func DeleteWarehouseInfo(id int64) error {
1613
-	err := XTWriteDB().Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": 0}).Error
1617
+	err := XTWriteDB().Model(models.WarehousingInfo{}).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_count": 0}).Error
1614 1618
 	return err
1615 1619
 }
1616 1620