Browse Source

11月8日库存管理

XMLWAN 2 years ago
parent
commit
8839b53796

+ 24 - 0
controllers/drug_stock_api_contorller.go View File

@@ -1578,6 +1578,15 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1578 1578
 
1579 1579
 				admin_user_id := int64(items["admin_user_id"].(float64))
1580 1580
 
1581
+				//if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
1582
+				//  utils.ErrorLog("last_price")
1583
+				//  c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1584
+				//  return
1585
+				//}
1586
+				//last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
1587
+
1588
+				stock_count, _ := items["stock_count"].(string)
1589
+
1581 1590
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1582 1591
 
1583 1592
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1604,6 +1613,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1604 1613
 					WarehouseInfoId:         warehouse_info_id,
1605 1614
 					StorehouseId:            storehouse_id,
1606 1615
 					AdminUserId:             admin_user_id,
1616
+					StockCount:              stock_count,
1607 1617
 				}
1608 1618
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1609 1619
 
@@ -2003,6 +2013,15 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2003 2013
 
2004 2014
 				admin_user_id := int64(items["admin_user_id"].(float64))
2005 2015
 
2016
+				//if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
2017
+				//  utils.ErrorLog("last_price")
2018
+				//  c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
2019
+				//  return
2020
+				//}
2021
+				//last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
2022
+
2023
+				stock_count, _ := items["stock_count"].(string)
2024
+
2006 2025
 				if id == 0 {
2007 2026
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
2008 2027
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -2030,6 +2049,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2030 2049
 						WarehouseInfoId:         warehouse_info_id,
2031 2050
 						StorehouseId:            storehouse_id,
2032 2051
 						AdminUserId:             admin_user_id,
2052
+						StockCount:              stock_count,
2033 2053
 					}
2034 2054
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
2035 2055
 
@@ -2057,6 +2077,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2057 2077
 						WarehouseOutId:          id,
2058 2078
 						StorehouseId:            storehouse_id,
2059 2079
 						AdminUserId:             admin_user_id,
2080
+						StockCount:              stock_count,
2060 2081
 					}
2061 2082
 
2062 2083
 					drugFlow = append(drugFlow, drugflow)
@@ -2104,6 +2125,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2104 2125
 						WarehouseInfoId:         warehouse_info_id,
2105 2126
 						StorehouseId:            storehouse_id,
2106 2127
 						AdminUserId:             admin_user_id,
2128
+						StockCount:              stock_count,
2107 2129
 					}
2108 2130
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
2109 2131
 
@@ -2131,6 +2153,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2131 2153
 						WarehouseOutId:          warehouseOut.ID,
2132 2154
 						StorehouseId:            storehouse_id,
2133 2155
 						AdminUserId:             admin_user_id,
2156
+						StockCount:              stock_count,
2134 2157
 					}
2135 2158
 
2136 2159
 					drugFlow = append(drugFlow, drugflow)
@@ -2250,6 +2273,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
2250 2273
 					WarehouseOutId: item.WarehouseOutId,
2251 2274
 					StorehouseId:   item.StorehouseId,
2252 2275
 					AdminUserId:    item.AdminUserId,
2276
+					StockCount:     item.StockCount,
2253 2277
 				}
2254 2278
 				service.UpdateDrugFlowSix(item.WarehouseOutId, item.DrugId, item.WarehouseOutOrderNumber, flow)
2255 2279
 				cha_number = min_number - max_number

+ 2 - 1
controllers/manager_center_api_controller.go View File

@@ -2285,7 +2285,8 @@ func (c *ManagerCenterApiController) GetAllDrugList() {
2285 2285
 func (c *ManagerCenterApiController) GetSearchDrugList() {
2286 2286
 	keyword := c.GetString("keyword")
2287 2287
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2288
-	list, err := service.GetSearchDrugList(keyword, orgId)
2288
+	config, _ := service.GetAllStoreHouseConfig(orgId)
2289
+	list, err := service.GetSearchDrugListSix(keyword, orgId, config.DrugStorehouseOut)
2289 2290
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2290 2291
 	dealerList, _ := service.GetAllDealerList(orgId)
2291 2292
 	if err == nil {

+ 13 - 23
controllers/mobile_api_controllers/dialysis_api_controller.go View File

@@ -4459,9 +4459,6 @@ func (c *DialysisAPIController) EditConsumables() {
4459 4459
 					//判断当前出库数量和最后一次出库数量的大小
4460 4460
 					//如果当前出库数量小于最后一次出库数量 正常出库后 需要退库操作
4461 4461
 
4462
-					fmt.Println("当前出库数量", item.Count)
4463
-					fmt.Println("最后一次出库数量", goodInfo.Count)
4464
-
4465 4462
 					if item.Count < goodInfo.Count {
4466 4463
 						//出库
4467 4464
 						err = ConsumablesDeliveryTotalSeven(adminInfo.Org.Id, patient_id, record_time, beforePrepares, adminInfo.AdminUser.Id, item.Count)
@@ -4487,7 +4484,7 @@ func (c *DialysisAPIController) EditConsumables() {
4487 4484
 
4488 4485
 						//查询该批次剩余库存
4489 4486
 						lastInfo, _ := service.GetLastStockOut(goodInfo.WarehouseInfotId)
4490
-						fmt.Println("剩余库存333333333333333", lastInfo)
4487
+
4491 4488
 						if lastInfo.StockCount == 0 {
4492 4489
 							//查询该耗材的总库存
4493 4490
 							wareinfo, _ := service.GetStockGoodCount(item.GoodId)
@@ -4504,8 +4501,7 @@ func (c *DialysisAPIController) EditConsumables() {
4504 4501
 						}
4505 4502
 
4506 4503
 						//比较剩余库存 和 当前相差的数量,库存剩余量大于则正常出库
4507
-						fmt.Println("剩余库存", lastInfo.StockCount)
4508
-						fmt.Println("差", last_total)
4504
+
4509 4505
 						//查询该耗材的总库存
4510 4506
 						wareinfo, _ := service.GetStockGoodCount(item.GoodId)
4511 4507
 						// 如果库存差大于剩余库存则提示库存不足
@@ -4662,9 +4658,6 @@ func (c *DialysisAPIController) GetDialysisGoods() {
4662 4658
 				lastGoodUserDetial, _ := service.GetLastDialysisBeforePrepare(item.PatientId, adminUser.Org.Id, date.Unix())
4663 4659
 				item.Project = project
4664 4660
 
4665
-				fmt.Println(goodUser)
4666
-				fmt.Println(lastGoodUserDetial)
4667
-
4668 4661
 				item.LastAutomaticReduceDetail = goodUser
4669 4662
 				item.LastDialysisBeforePrepare = lastGoodUserDetial
4670 4663
 			}
@@ -4839,7 +4832,7 @@ func (c *DialysisAPIController) CreateOtherStockOutInfo() {
4839 4832
 			}
4840 4833
 		}
4841 4834
 	}
4842
-	fmt.Println("前端数据9999999999999", beforePrepares)
4835
+
4843 4836
 	//查询是否有库存
4844 4837
 	for _, item := range beforePrepares {
4845 4838
 		storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.Org.Id)
@@ -5053,13 +5046,13 @@ func (c *DialysisAPIController) BatchDeleteMonitor() {
5053 5046
 func (c *DialysisAPIController) GetPatientDialysisRecordList() {
5054 5047
 
5055 5048
 	id, _ := c.GetInt64("id")
5056
-	fmt.Println(id)
5049
+
5057 5050
 	timeLayout := "2006-01-02"
5058 5051
 	loc, _ := time.LoadLocation("Local")
5059 5052
 	start_time := time.Now().Format("2006-01-02")
5060 5053
 
5061 5054
 	startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
5062
-	fmt.Println("start_timestart_time", start_time)
5055
+
5063 5056
 	nowTime := time.Now()
5064 5057
 	endTime := nowTime.AddDate(-1, 0, 0)
5065 5058
 	endTimes := endTime.Format("2006-01-02")
@@ -5077,7 +5070,7 @@ func (c *DialysisAPIController) BathDeleteAdviceList() {
5077 5070
 	dataBody := make(map[string]interface{}, 0)
5078 5071
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
5079 5072
 	ids := c.GetString("ids")
5080
-	fmt.Println("dis22222222", ids)
5073
+
5081 5074
 	idArray := strings.Split(ids, ",")
5082 5075
 	origin, _ := c.GetInt64("origin")
5083 5076
 	if origin == 1 {
@@ -5112,9 +5105,8 @@ func (c *DialysisAPIController) DeleteAutoReduceDetail() {
5112 5105
 	good_id, _ := c.GetInt64("good_id")
5113 5106
 	record_time, _ := c.GetInt64("record_time")
5114 5107
 	patient_id, _ := c.GetInt64("patient_id")
5115
-	fmt.Println("0000000000000000", patient_id)
5116 5108
 	service.DeleteDialysisBeforOne(good_id, record_time, patient_id)
5117
-	fmt.Println()
5109
+
5118 5110
 	err := service.DeleteAutoReduceDetail(good_id, record_time, patient_id)
5119 5111
 	fmt.Print("err", err)
5120 5112
 	c.ServeSuccessJSON(map[string]interface{}{
@@ -5230,10 +5222,10 @@ func ConsumablesDeliveryTotalSeven(orgID int64, patient_id int64, record_time in
5230 5222
 				// 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
5231 5223
 				if goods_yc_temp.Count < goods_temp.Count {
5232 5224
 					temp_count := goods_temp.Count - goods_yc_temp.Count
5233
-					//fmt.Println("988888888888888", temp_count)
5225
+
5234 5226
 					goods[j].Count = temp_count
5235 5227
 					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
5236
-					//fmt.Println("888888888", goods_yc)
5228
+
5237 5229
 					break
5238 5230
 				}
5239 5231
 			}
@@ -5269,7 +5261,7 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
5269 5261
 	delete_count = warehouseOutInfos.Count - count
5270 5262
 
5271 5263
 	houseConfig, _ := service.GetAllStoreHouseConfig(orgID)
5272
-	fmt.Println("delete_count2323232", delete_count)
5264
+
5273 5265
 	// 在出库记录表里记录退库详情
5274 5266
 	warehouseOutInfo := &models.WarehouseOutInfo{
5275 5267
 		WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -5467,11 +5459,11 @@ func ConsumablesDeliveryDeleteFour(orgID int64, record_time int64, good_yc *mode
5467 5459
 		service.CreateAutoReduceRecord(&details)
5468 5460
 	}
5469 5461
 	// 删除出库完成后,要增加对应批次的库存数量
5470
-	fmt.Println("deletecount2323232323232323232323232323", delete_count)
5462
+
5471 5463
 	errThree := service.UpDateWarehouseInfoByStockDelete(warehouseOutInfos.WarehouseInfotId, delete_count)
5472 5464
 	service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
5473 5465
 	errOne := service.UpDateWarehouStockFlowByStockDelete(warehouseOutInfos.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
5474
-	fmt.Println("erron2332323232323232232323", errOne)
5466
+	fmt.Println("errOne", errOne)
5475 5467
 	if errThree != nil {
5476 5468
 		return errThree
5477 5469
 	}
@@ -5521,8 +5513,6 @@ func ConsumablesDeliveryTotalSix(orgID int64, patient_id int64, record_time int6
5521 5513
 
5522 5514
 	// goods_yc 这个数据就是需要已经出库了,但是现在需要删除出库的耗材数据
5523 5515
 	// goods 这个数据就是需要出库的耗材的数据(新增的数据)
5524
-	fmt.Println("goods222222222222", goods)
5525
-	fmt.Println("goodsy999999999999", goods_yc)
5526 5516
 
5527 5517
 	if len(goods) > 0 {
5528 5518
 		out, err := service.FindStockOutByIsSys(orgID, 1, record_time)
@@ -5638,7 +5628,7 @@ func ConsumablesDeliveryDeleteThree(orgID int64, record_time int64, good_yc *mod
5638 5628
 		// 删除出库完成后,要改变流水库存
5639 5629
 		errOne = service.UpDateWarehouStockFlowByStockDelete(ware.WarehouseInfotId, record_time, good_yc.GoodId, delete_count, good_yc.PatientId)
5640 5630
 
5641
-		fmt.Println("erron2332323232323232232323", errOne)
5631
+		fmt.Println("errOne", errOne)
5642 5632
 		errThree := service.UpDateWarehouseInfoByStockDelete(ware.WarehouseInfotId, delete_count)
5643 5633
 		service.ModifyGoodAddInformation(good_yc.GoodId, delete_count, good_yc.OrgId)
5644 5634
 		if errThree != nil {

+ 34 - 1
controllers/stock_in_api_controller.go View File

@@ -1408,6 +1408,16 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1408 1408
 				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1409 1409
 
1410 1410
 				admin_user_id := int64(items["admin_user_id"].(float64))
1411
+
1412
+				if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
1413
+					utils.ErrorLog("buy_price")
1414
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1415
+					return
1416
+				}
1417
+				buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
1418
+
1419
+				stock_count := items["stock_count"].(string)
1420
+
1411 1421
 				timeLayout := "2006-01-02"
1412 1422
 				loc, _ := time.LoadLocation("Local")
1413 1423
 				var expiryDate int64
@@ -1454,6 +1464,8 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1454 1464
 					WarehouseInfotId:        warehouse_info_id,
1455 1465
 					StorehouseId:            storehouse_id,
1456 1466
 					AdminUserId:             admin_user_id,
1467
+					BuyPrice:                buy_price,
1468
+					StockCount:              stock_count,
1457 1469
 				}
1458 1470
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1459 1471
 
@@ -1787,6 +1799,16 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1787 1799
 				warehouse_info_id := int64(items["warehouse_info_id"].(float64))
1788 1800
 
1789 1801
 				admin_user_id := int64(items["admin_user_id"].(float64))
1802
+
1803
+				//if items["buy_price"] == nil || reflect.TypeOf(items["buy_price"]).String() != "string" {
1804
+				//  utils.ErrorLog("buy_price")
1805
+				//  c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1806
+				//  return
1807
+				//}
1808
+				//buy_price, _ := strconv.ParseFloat(items["buy_price"].(string), 64)
1809
+
1810
+				stock_count := items["stock_count"].(string)
1811
+
1790 1812
 				var productDate int64
1791 1813
 				if len(product_date) > 0 {
1792 1814
 					theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", product_date+" 00:00:00", loc)
@@ -1823,6 +1845,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1823 1845
 						WarehouseInfotId:        warehouse_info_id,
1824 1846
 						StorehouseId:            storehouse_id,
1825 1847
 						AdminUserId:             admin_user_id,
1848
+						StockCount:              stock_count,
1826 1849
 					}
1827 1850
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1828 1851
 
@@ -1868,6 +1891,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1868 1891
 						WarehouseInfotId:        warehouse_info_id,
1869 1892
 						StorehouseId:            storehouse_id,
1870 1893
 						AdminUserId:             admin_user_id,
1894
+						StockCount:              stock_count,
1871 1895
 					}
1872 1896
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1873 1897
 				}
@@ -2007,6 +2031,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
2007 2031
 							ConsumableType:          2,
2008 2032
 							StorehouseId:            item.StorehouseId,
2009 2033
 							AdminUserId:             item.AdminUserId,
2034
+							StockCount:              item.StockCount,
2010 2035
 						}
2011 2036
 
2012 2037
 						//查询是否存在
@@ -2033,6 +2058,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
2033 2058
 								Price:         item.Price,
2034 2059
 								StorehouseId:  item.StorehouseId,
2035 2060
 								AdminUserId:   item.AdminUserId,
2061
+								StockCount:    item.StockCount,
2036 2062
 							}
2037 2063
 							service.UpdateStockFlowByDetailId(flow, item.ID)
2038 2064
 
@@ -2101,6 +2127,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
2101 2127
 						Count:                   item.Count,
2102 2128
 						StorehouseId:            item.StorehouseId,
2103 2129
 						AdminUserId:             item.AdminUserId,
2130
+						StockCount:              item.StockCount,
2104 2131
 					}
2105 2132
 					//查询是否存在
2106 2133
 					_, errcode := service.GetWarehouseOutInfoIsExist(item.ID)
@@ -2125,6 +2152,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
2125 2152
 							Price:         item.Price,
2126 2153
 							StorehouseId:  item.StorehouseId,
2127 2154
 							AdminUserId:   item.AdminUserId,
2155
+							StockCount:    item.StockCount,
2128 2156
 						}
2129 2157
 						service.UpdateStockFlowByDetailId(flow, item.ID)
2130 2158
 						goodInfo := models.GoodInfo{
@@ -2159,6 +2187,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
2159 2187
 					Price:         item.Price,
2160 2188
 					StorehouseId:  item.StorehouseId,
2161 2189
 					AdminUserId:   item.AdminUserId,
2190
+					BuyPrice:      item.BuyPrice,
2191
+					StockCount:    item.StockCount,
2162 2192
 				}
2163 2193
 				service.UpdateStockFlowByDetailId(flow, item.ID)
2164 2194
 				goodInfo := models.GoodInfo{
@@ -5479,7 +5509,10 @@ func (this *StockManagerApiController) PostSearchGoodList() {
5479 5509
 	keyword := this.GetString("keyword")
5480 5510
 	adminUserInfo := this.GetAdminUserInfo()
5481 5511
 	orgId := adminUserInfo.CurrentOrgId
5482
-	list, _ := service.GetSearchGoodList(keyword, orgId)
5512
+
5513
+	config, _ := service.GetAllStoreHouseConfig(orgId)
5514
+	list, _ := service.GetSearchGoodListSix(keyword, orgId, config.StorehouseOutInfo)
5515
+
5483 5516
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
5484 5517
 	dealerList, _ := service.GetAllDealerList(orgId)
5485 5518
 	this.ServeSuccessJSON(map[string]interface{}{

+ 4 - 0
models/drug_stock.go View File

@@ -165,6 +165,8 @@ type DrugWarehouseOutInfo struct {
165 165
 	StorehouseId            int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
166 166
 	SecondWarehouseInfoId   int64   `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
167 167
 	AdminUserId             int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
168
+	LastPrice               float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
169
+	StockCount              string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
168 170
 }
169 171
 
170 172
 func (DrugWarehouseOutInfo) TableName() string {
@@ -410,6 +412,8 @@ type DrugFlow struct {
410 412
 	StorehouseId              int64                `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
411 413
 	SecondWarehouseInfoId     int64                `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
412 414
 	AdminUserId               int64                `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
415
+	LastPrice                 float64              `gorm:"column:last_price" json:"last_price" form:"last_price"`
416
+	StockCount                string               `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
413 417
 }
414 418
 
415 419
 func (DrugFlow) TableName() string {

+ 2 - 1
models/self_drug_models.go View File

@@ -409,8 +409,8 @@ type XtDrugWarehouseInfo struct {
409 409
 	StockMaxNumber            int64      `gorm:"column:stock_max_number" json:"stock_max_number"`
410 410
 	StockMinNumber            int64      `gorm:"column:stock_min_number" json:"stock_min_number"`
411 411
 	BatchNumber               string     `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
412
-	MinUnit                   string     `gorm:"column:min_unit" json:"max_unit" form:"min_unit"`
413 412
 	MaxUnit                   string     `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
413
+	MinUnit                   string     `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
414 414
 	WarehousingInfoId         int64      `gorm:"column:warehousing_info_id" json:"warehousing_info_id" form:"warehousing_info_id"`
415 415
 	XtBaseDrug                XtBaseDrug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" `
416 416
 	SupplyWarehouseId         int64      `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
@@ -688,6 +688,7 @@ type VmDrugWarehouseOutInfo struct {
688 688
 	MedicalInsuranceNumber  string  `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
689 689
 	StorehouseId            int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
690 690
 	AdminUserId             int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
691
+	StockCount              string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
691 692
 }
692 693
 
693 694
 type XtDrugAdjustPrice struct {

+ 6 - 0
models/stock_models.go View File

@@ -256,6 +256,8 @@ type WarehouseOutInfo struct {
256 256
 	StorehouseId            int64        `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
257 257
 	SecondWarehouseInfoId   int64        `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
258 258
 	AdminUserId             int64        `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
259
+	BuyPrice                float64      `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
260
+	StockCount              string       `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
259 261
 }
260 262
 
261 263
 func (WarehouseOutInfo) TableName() string {
@@ -505,6 +507,8 @@ type WarehouseOutInfoOne struct {
505 507
 	SupplyWarehouseId           int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
506 508
 	StorehouseId                int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
507 509
 	AdminUserId                 int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
510
+	BuyPrice                    float64 `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
511
+	StockCount                  string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
508 512
 }
509 513
 
510 514
 type WarehouseOutInfoTwo struct {
@@ -617,6 +621,8 @@ type VmStockFlow struct {
617 621
 	StorehouseId              int64   `gorm:"column:storehouse_id" json:"storehouse_id" form:"storehouse_id"`
618 622
 	SecondWarehouseInfoId     int64   `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
619 623
 	AdminUserId               int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
624
+	BuyPrice                  float64 `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
625
+	StockCount                string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
620 626
 }
621 627
 
622 628
 func (VmStockFlow) TableName() string {

+ 1 - 1
service/gobal_config_service.go View File

@@ -859,7 +859,7 @@ func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouse
859 859
 		db = db.Where("x.warehouse_out_id = ?", id)
860 860
 	}
861 861
 
862
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price as total_price,x.retail_total_price,x.storehouse_id,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,x.admin_user_id,t.dose,t.dose_unit,t.last_price,t.min_price,t.medical_insurance_number,t.retail_price ,x.warehouse_info_id").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
862
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.count_unit,x.price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price as total_price,x.retail_total_price,x.storehouse_id,x.stock_count,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,x.admin_user_id,t.dose,t.dose_unit,t.last_price,t.min_price,t.medical_insurance_number,t.retail_price ,x.warehouse_info_id").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
863 863
 	return info, err
864 864
 }
865 865
 

+ 38 - 4
service/stock_service.go View File

@@ -1701,6 +1701,8 @@ type DrugWarehouseOutInfo struct {
1701 1701
 	SupplyCancelOutId       int64   `gorm:"column:supply_cancel_out_id" json:"supply_cancel_out_id" form:"supply_cancel_out_id"`
1702 1702
 	SupplyWarehouseId       int64   `gorm:"column:supply_warehouse_id" json:"supply_warehouse_id" form:"supply_warehouse_id"`
1703 1703
 	AdminUserId             int64   `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
1704
+	LastPrice               float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
1705
+	StockCount              string  `gorm:"column:stock_count" json:"stock_count" form:"stock_count"`
1704 1706
 }
1705 1707
 
1706 1708
 func (DrugWarehouseOutInfo) TableName() string {
@@ -2523,7 +2525,7 @@ func UpDateDrugWarehouseOutInfo(info *models.DrugWarehouseOutInfo) (err error) {
2523 2525
 
2524 2526
 func UpdateDrugFlowSix(warehousoutid int64, drugid int64, warehouse_out_order_number string, flow models.DrugFlow) error {
2525 2527
 
2526
-	err := XTWriteDB().Model(&flow).Where("warehouse_out_id = ? and drug_id = ? and warehouse_out_order_number = ?", warehousoutid, drugid, warehouse_out_order_number).Updates(map[string]interface{}{"count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "number": flow.Number, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId}).Error
2528
+	err := XTWriteDB().Model(&flow).Where("warehouse_out_id = ? and drug_id = ? and warehouse_out_order_number = ?", warehousoutid, drugid, warehouse_out_order_number).Updates(map[string]interface{}{"count": flow.Count, "expire_date": flow.ExpireDate, "product_date": flow.ProductDate, "price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "number": flow.Number, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId, "stock_count": flow.StockCount}).Error
2527 2529
 	return err
2528 2530
 }
2529 2531
 
@@ -3657,6 +3659,22 @@ func GetSearchDrugList(keywords string, orgid int64) (drug []*models.BaseDrugLib
3657 3659
 	return
3658 3660
 }
3659 3661
 
3662
+func GetSearchDrugListSix(keywords string, orgid int64, storehouse_id int64) (drug []*models.BaseDrugLib, err error) {
3663
+
3664
+	db := XTReadDB().Model(&drug).Where("org_id=? and status=1  and drug_status<>'停用'", orgid)
3665
+	if len(keywords) > 0 {
3666
+		likekey := "%" + keywords + "%"
3667
+		err = db.Where("(drug_name LIKE ?)", likekey).Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
3668
+			return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id = ?", orgid, storehouse_id).Group("id")
3669
+		}).Find(&drug).Error
3670
+	} else {
3671
+		err = db.Preload("DrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
3672
+			return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id = ?", orgid, storehouse_id).Group("id")
3673
+		}).Find(&drug).Error
3674
+	}
3675
+	return
3676
+}
3677
+
3660 3678
 func GetSearchGoodList(keywords string, orgid int64) (good []*models.GoodInfo, err error) {
3661 3679
 
3662 3680
 	db := XTReadDB().Model(&good).Where("org_id =? and status = 1 and good_status <> '停用'", orgid)
@@ -3673,6 +3691,22 @@ func GetSearchGoodList(keywords string, orgid int64) (good []*models.GoodInfo, e
3673 3691
 	return
3674 3692
 }
3675 3693
 
3694
+func GetSearchGoodListSix(keywords string, orgid int64, storehouse_id int64) (good []*models.GoodInfo, err error) {
3695
+
3696
+	db := XTReadDB().Model(&good).Where("org_id =? and status = 1 and good_status <> '停用'", orgid)
3697
+	if len(keywords) > 0 {
3698
+		likekey := "%" + keywords + "%"
3699
+		err = db.Where("(good_name Like ?)", likekey).Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
3700
+			return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id =?", orgid, storehouse_id)
3701
+		}).Find(&good).Error
3702
+	} else {
3703
+		err = db.Preload("StWarehousingInfo", func(db *gorm.DB) *gorm.DB {
3704
+			return XTReadDB().Where("org_id=? and status = 1 and warehousing_count <> 0 and storehouse_id = ?", orgid, storehouse_id)
3705
+		}).Find(&good).Error
3706
+	}
3707
+	return
3708
+}
3709
+
3676 3710
 func CreateAutoReduceRecord(detail *models.BloodAutomaticReduceDetail) error {
3677 3711
 	db := writeDb.Begin()
3678 3712
 	err := db.Create(&detail).Error
@@ -4046,7 +4080,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
4046 4080
 	if orgid > 0 {
4047 4081
 		db = db.Where("x.org_id = ?", orgid)
4048 4082
 	}
4049
-	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.supply_cancel_out_id,x.supply_warehouse_id,x.storehouse_id,x.admin_user_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
4083
+	err = db.Select("x.id,x.warehouse_out_id,x.warehouse_info_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.supply_cancel_out_id,x.supply_warehouse_id,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id,x.warehouse_info_id").Order("x.ctime desc").Scan(&out).Error
4050 4084
 	return out, err
4051 4085
 }
4052 4086
 
@@ -4075,7 +4109,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
4075 4109
 		db = db.Where("x.org_id = ?", orgid)
4076 4110
 	}
4077 4111
 
4078
-	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,t.social_security_directory_code,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
4112
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,t.social_security_directory_code,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,x.storehouse_id,x.admin_user_id,x.buy_price,x.stock_count,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit,t.packing_price").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.warehouse_out_id,x.good_id").Order("x.ctime desc").Scan(&out).Error
4079 4113
 	return out, err
4080 4114
 }
4081 4115
 
@@ -5881,7 +5915,7 @@ func UpdatedStockFlowByGoodIdOne(warehousing_id int64, good_id int64, flow model
5881 5915
 }
5882 5916
 
5883 5917
 func UpdateStockFlowByDetailId(flow models.VmStockFlow, wareoutdetailid int64) error {
5884
-	err := XTWriteDB().Model(&flow).Where("warehouse_out_detail_id = ? and status = 1", wareoutdetailid).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "price": flow.Price, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId}).Error
5918
+	err := XTWriteDB().Model(&flow).Where("warehouse_out_detail_id = ? and status = 1", wareoutdetailid).Updates(map[string]interface{}{"count": flow.Count, "number": flow.Number, "product_date": flow.ProductDate, "expire_date": flow.ExpireDate, "Price": flow.Price, "manufacturer": flow.Manufacturer, "dealer": flow.Dealer, "license_number": flow.LicenseNumber, "price": flow.Price, "storehouse_id": flow.StorehouseId, "admin_user_id": flow.AdminUserId, "stock_count": flow.StockCount}).Error
5885 5919
 	return err
5886 5920
 }
5887 5921
 

+ 72 - 26
service/warhouse_service.go View File

@@ -267,8 +267,6 @@ func DrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout *model
267 267
 
268 268
 		}
269 269
 
270
-		fmt.Println("max_number", maxNumber)
271
-		fmt.Println("min_number2332232332", minNumber)
272 270
 		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
273 271
 			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
274 272
 			if warehouse.StockMinNumber == 0 {
@@ -1132,10 +1130,10 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1132 1130
 				// 如果已经出库的数量 小于 新请求出库的梳理,则代表需要增加出库
1133 1131
 				if goods_yc_temp.Count < goods_temp.Count {
1134 1132
 					temp_count := goods_temp.Count - goods_yc_temp.Count
1135
-					//fmt.Println("988888888888888", temp_count)
1133
+
1136 1134
 					goods[j].Count = temp_count
1137 1135
 					goods_yc = append(goods_yc[:i], goods_yc[i+1:]...)
1138
-					//fmt.Println("888888888", goods_yc)
1136
+
1139 1137
 					break
1140 1138
 				}
1141 1139
 			}
@@ -1216,7 +1214,8 @@ func ConsumablesDeliveryTotal(orgID int64, patient_id int64, record_time int64,
1216 1214
 //耗材出库
1217 1215
 func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods *models.DialysisBeforePrepare, warehouseOut *models.WarehouseOut, count int64) (err error) {
1218 1216
 
1219
-	fmt.Println("count23323223233232323232332232323", count, goods.Count)
1217
+	//开事务
1218
+	tx := XTWriteDB().Begin()
1220 1219
 	var deliver_number int64 = 0
1221 1220
 	var stock_number int64 = 0
1222 1221
 	var maxNumber int64 = 0
@@ -1459,7 +1458,10 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1459 1458
 		ModifyGoodReduceInformationSix(goods.GoodId, goods.Count, orgID, warehouse.PackingPrice)
1460 1459
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
1461 1460
 		if errThree != nil {
1462
-			return errThree
1461
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
1462
+			tx.Rollback()
1463
+		} else {
1464
+			tx.Commit()
1463 1465
 		}
1464 1466
 
1465 1467
 		return nil
@@ -1648,8 +1650,12 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
1648 1650
 		warehouse.Mtime = time.Now().Unix()
1649 1651
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
1650 1652
 		if errThree != nil {
1651
-			return errThree
1653
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
1654
+			tx.Rollback()
1655
+		} else {
1656
+			tx.Commit()
1652 1657
 		}
1658
+
1653 1659
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1654 1660
 		goods.Count = deliver_number - stock_number
1655 1661
 
@@ -1781,6 +1787,9 @@ func GetWarehouseById(id int64) (models.WarehouseOut, error) {
1781 1787
 //耗材出库
1782 1788
 func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.WarehouseOutInfo, warehouseOut *models.WarehouseOut, count int64, creator int64) (err error) {
1783 1789
 
1790
+	//开事务
1791
+	tx := XTWriteDB().Begin()
1792
+
1784 1793
 	var deliver_number int64 = 0
1785 1794
 	var stock_number int64 = 0
1786 1795
 	var maxNumber int64 = 0
@@ -1824,6 +1833,8 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1824 1833
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1825 1834
 			StorehouseId:            goods.StorehouseId,
1826 1835
 			AdminUserId:             goods.AdminUserId,
1836
+			BuyPrice:                warehouse.Price,
1837
+			StockCount:              goods.StockCount,
1827 1838
 		}
1828 1839
 		warehouseOutInfo.Count = goods.Count
1829 1840
 		//添加出库单详情
@@ -1865,6 +1876,8 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1865 1876
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1866 1877
 			StorehouseId:            warehouse.StorehouseId,
1867 1878
 			AdminUserId:             goods.AdminUserId,
1879
+			BuyPrice:                warehouse.Price,
1880
+			StockCount:              goods.StockCount,
1868 1881
 		}
1869 1882
 
1870 1883
 		//创建出库流水
@@ -1881,7 +1894,12 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1881 1894
 
1882 1895
 		//扣减库存
1883 1896
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
1884
-		//扣减库存
1897
+		if errThree != nil {
1898
+			utils.ErrorLog("事务失败,原因为: %v", errThree.Error())
1899
+			tx.Rollback()
1900
+		} else {
1901
+			tx.Commit()
1902
+		}
1885 1903
 
1886 1904
 		//查询该机构默认仓库
1887 1905
 		storeConfig, _ := GetAllStoreHouseConfig(goods.OrgId)
@@ -1924,6 +1942,8 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1924 1942
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1925 1943
 			StorehouseId:            warehouse.StorehouseId,
1926 1944
 			AdminUserId:             goods.AdminUserId,
1945
+			BuyPrice:                warehouse.Price,
1946
+			StockCount:              goods.StockCount,
1927 1947
 		}
1928 1948
 		warehouseOutInfo.Count = stock_number
1929 1949
 
@@ -1974,6 +1994,8 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1974 1994
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
1975 1995
 			StorehouseId:            goods.StorehouseId,
1976 1996
 			AdminUserId:             goods.AdminUserId,
1997
+			BuyPrice:                warehouse.Price,
1998
+			StockCount:              goods.StockCount,
1977 1999
 		}
1978 2000
 
1979 2001
 		//创建出库明细
@@ -1996,7 +2018,10 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1996 2018
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
1997 2019
 
1998 2020
 		if errThree != nil {
1999
-			return errThree
2021
+			utils.ErrorLog("事务失败,原因为: %v", errThree.Error())
2022
+			tx.Rollback()
2023
+		} else {
2024
+			tx.Commit()
2000 2025
 		}
2001 2026
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
2002 2027
 		goods.Count = deliver_number - stock_number
@@ -2009,6 +2034,8 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
2009 2034
 //退库逻辑
2010 2035
 func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count int64) (err error) {
2011 2036
 
2037
+	//开事务
2038
+	tx := XTWriteDB().Begin()
2012 2039
 	var deliver_number int64 = 0
2013 2040
 	var stock_number int64 = 0
2014 2041
 	var maxNumber int64 = 0
@@ -2070,8 +2097,12 @@ func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count i
2070 2097
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
2071 2098
 
2072 2099
 		if errThree != nil {
2073
-			return errThree
2100
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
2101
+			tx.Rollback()
2102
+		} else {
2103
+			tx.Commit()
2074 2104
 		}
2105
+
2075 2106
 		return
2076 2107
 	} else {
2077 2108
 
@@ -2108,7 +2139,10 @@ func ConsumablesDeliveryTwo(orgID int64, goods *models.WarehouseOutInfo, count i
2108 2139
 		warehouse.Mtime = time.Now().Unix()
2109 2140
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
2110 2141
 		if errThree != nil {
2111
-			return errThree
2142
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
2143
+			tx.Rollback()
2144
+		} else {
2145
+			tx.Commit()
2112 2146
 		}
2113 2147
 
2114 2148
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
@@ -2507,6 +2541,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2507 2541
 	if advice.PrescribingNumberUnit != drup.MaxUnit && advice.PrescribingNumberUnit != drup.MinUnit {
2508 2542
 		min_price = drup.RetailPrice
2509 2543
 	}
2544
+
2510 2545
 	fmt.Println(min_price)
2511 2546
 	// 根据先进先出原则,查询最先入库的批次,进行出库
2512 2547
 	// 如果没有对应的库存,则报错
@@ -2673,7 +2708,7 @@ func NewHisDrugDeliverInfo(orgID int64, prescribingNumber float64, warehouseout
2673 2708
 		}
2674 2709
 
2675 2710
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
2676
-		fmt.Println("扣减2333333232323232323323223232323232323233223332233232323232322332", errThree)
2711
+
2677 2712
 		if errThree != nil {
2678 2713
 			return errThree
2679 2714
 		}
@@ -2837,7 +2872,6 @@ func HisAuToReduce(orgID int64, prescribingNumber float64, warehouseout *models.
2837 2872
 	//  比较数据大小
2838 2873
 	//如果当期医嘱数量小于最后一次出库则退库
2839 2874
 	if device_number < count_number {
2840
-		fmt.Println("进来了吗")
2841 2875
 		var cha_number int64
2842 2876
 		var maxNumber int64
2843 2877
 		var minNumber int64
@@ -2869,8 +2903,7 @@ func HisAuToReduce(orgID int64, prescribingNumber float64, warehouseout *models.
2869 2903
 		ModifyDrugFlow(flow, drugInfo.WarehouseOutOrderNumber, advice.DrugId, advice.PatientId)
2870 2904
 
2871 2905
 	}
2872
-	fmt.Println("医嘱数量44444444444444", device_number)
2873
-	fmt.Println("最后一次出库数量", count_number)
2906
+
2874 2907
 	//如果当期医嘱数量大于最后一次出库则需要出库
2875 2908
 	if device_number > count_number {
2876 2909
 		var cha_number int64
@@ -3541,7 +3574,7 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
3541 3574
 			StorehouseId:            goods.StorehouseId,
3542 3575
 			SecondWarehouseInfoId:   goods.SecondWarehouseInfoId,
3543 3576
 		}
3544
-		fmt.Println("goods23233232233223323232323223232333232323232", goods.Count)
3577
+
3545 3578
 		warehouseOutInfo.Count = goods.Count
3546 3579
 		//添加出库单详情
3547 3580
 		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
@@ -3599,7 +3632,6 @@ func ConsumablesDeliveryTwelve(orgID int64, record_time int64, goods *models.War
3599 3632
 		//扣减库存
3600 3633
 		errThree := UpDateWarehouseInfoByStock(&warehouse)
3601 3634
 
3602
-		fmt.Println("2332323232323223323232233232323", goods.Count)
3603 3635
 		//入库
3604 3636
 		warehouseInfo := &models.WarehousingInfo{
3605 3637
 			WarehousingOrder:      warehouseInfo.WarehousingOrder,
@@ -3990,7 +4022,7 @@ func AutoDrugDeliverInfoTwelve(orgID int64, prescribingNumber int64, warehouseou
3990 4022
 		if errThree != nil {
3991 4023
 			return errThree
3992 4024
 		}
3993
-		fmt.Println("出库数量2333333333333333333333333333333333333", deliver_number)
4025
+
3994 4026
 		//入库
3995 4027
 		drugInfo := models.DrugWarehouseInfo{
3996 4028
 			WarehousingOrder:      drugWarehouse.WarehousingOrder,
@@ -4332,8 +4364,7 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4332 4364
 
4333 4365
 		maxNumber = deliver_number / drup.MinNumber
4334 4366
 		minNumber = deliver_number % drup.MinNumber
4335
-		fmt.Println("maxNumber2323232233232332332323232323233232", maxNumber)
4336
-		fmt.Println("minNumber3223233232323233232332322332", minNumber)
4367
+
4337 4368
 		if warehouse.StockMaxNumber == 0 && drup.MaxUnit == drup.MinUnit {
4338 4369
 			minNumber = maxNumber
4339 4370
 		}
@@ -4374,8 +4405,6 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4374 4405
 
4375 4406
 		}
4376 4407
 
4377
-		fmt.Println("max_number", maxNumber)
4378
-		fmt.Println("min_number2332232332", minNumber)
4379 4408
 		if maxNumber == 1 && minNumber == 0 && drup.MaxUnit != drup.MinUnit {
4380 4409
 			warehouse.StockMinNumber = warehouse.StockMinNumber - deliver_number
4381 4410
 			if warehouse.StockMinNumber == 0 {
@@ -4392,9 +4421,8 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4392 4421
 			warehouse.StockMinNumber = 0
4393 4422
 		}
4394 4423
 
4395
-		fmt.Println("er2332323232232323233223322323233223322323", warehouse.StockMinNumber)
4396 4424
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
4397
-		fmt.Println("er2332323232232323233223322323233223322323", errThree)
4425
+
4398 4426
 		if errThree != nil {
4399 4427
 			return errThree
4400 4428
 		}
@@ -4530,7 +4558,8 @@ func AutoDrugDeliverInfoTwenty(orgID int64, prescribingNumber int64, warehouseou
4530 4558
 
4531 4559
 // 药品手动出库 递归方式
4532 4560
 func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehouseout *models.DrugWarehouseOut, drup *models.BaseDrugLib, advice *models.DrugWarehouseOutInfo) (err error) {
4533
-
4561
+	//开事务
4562
+	tx := XTWriteDB().Begin()
4534 4563
 	// 判断处方里药品单位是拆零单位还是包装单位,	如果是包装单位,则根据规格,将包装数量转为拆零数量
4535 4564
 	var deliver_number int64 = 0
4536 4565
 	var stock_number int64 = 0
@@ -4585,6 +4614,8 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4585 4614
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4586 4615
 			StorehouseId:            advice.StorehouseId,
4587 4616
 			AdminUserId:             advice.AdminUserId,
4617
+			LastPrice:               warehouse.Price,
4618
+			StockCount:              advice.StockCount,
4588 4619
 		}
4589 4620
 
4590 4621
 		warehouseOutInfo.Count = prescribingNumber
@@ -4621,6 +4652,8 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4621 4652
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4622 4653
 			StorehouseId:            advice.StorehouseId,
4623 4654
 			AdminUserId:             advice.AdminUserId,
4655
+			LastPrice:               warehouse.Price,
4656
+			StockCount:              advice.StockCount,
4624 4657
 		}
4625 4658
 		if warehouse.RetailPrice == 0 {
4626 4659
 			drugflow.Price = advice.Price
@@ -4696,7 +4729,10 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4696 4729
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
4697 4730
 
4698 4731
 		if errThree != nil {
4699
-			return errThree
4732
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
4733
+			tx.Rollback()
4734
+		} else {
4735
+			tx.Commit()
4700 4736
 		}
4701 4737
 
4702 4738
 		//查询默认仓库
@@ -4746,6 +4782,8 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4746 4782
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4747 4783
 			StorehouseId:            advice.StorehouseId,
4748 4784
 			AdminUserId:             advice.AdminUserId,
4785
+			LastPrice:               warehouse.Price,
4786
+			StockCount:              advice.StockCount,
4749 4787
 		}
4750 4788
 
4751 4789
 		warehouseOutInfo.Count = stock_number
@@ -4782,6 +4820,8 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4782 4820
 			SupplyWarehouseId:       warehouse.SupplyWarehouseId,
4783 4821
 			StorehouseId:            advice.StorehouseId,
4784 4822
 			AdminUserId:             advice.AdminUserId,
4823
+			LastPrice:               warehouse.Price,
4824
+			StockCount:              advice.StockCount,
4785 4825
 		}
4786 4826
 
4787 4827
 		CreateDrugFlowOne(drugflow)
@@ -4793,6 +4833,12 @@ func AutoDrugDeliverInfoTwentyOne(orgID int64, prescribingNumber int64, warehous
4793 4833
 		warehouse.Mtime = time.Now().Unix()
4794 4834
 
4795 4835
 		errThree := UpDateDrugWarehouseInfoByStock(&warehouse)
4836
+		if errThree != nil {
4837
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
4838
+			tx.Rollback()
4839
+		} else {
4840
+			tx.Commit()
4841
+		}
4796 4842
 
4797 4843
 		//查询默认仓库
4798 4844
 		houseConfig, _ := GetAllStoreHouseConfig(orgID)