Browse Source

耗材参数

XMLWAN 3 years ago
parent
commit
bb353aa978

+ 59 - 61
controllers/base_api_controller.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"XT_New/enums"
4
 	"XT_New/enums"
5
-	"XT_New/models"
6
-
7
 	//"XT_New/models"
5
 	//"XT_New/models"
8
 
6
 
9
 	//"XT_New/models"
7
 	//"XT_New/models"
69
 func (this *BaseAuthAPIController) Prepare() {
67
 func (this *BaseAuthAPIController) Prepare() {
70
 	this.BaseAPIController.Prepare()
68
 	this.BaseAPIController.Prepare()
71
 	if this.GetAdminUserInfo() == nil {
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
 func (this *BaseServeAPIController) Prepare() {
313
 func (this *BaseServeAPIController) Prepare() {
316
 	this.BaseAPIController.Prepare()
314
 	this.BaseAPIController.Prepare()
317
 	if this.GetAdminUserInfo() == nil {
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
 	//if adminUserInfo.AppRole != nil {
347
 	//if adminUserInfo.AppRole != nil {

+ 156 - 4
controllers/drug_stock_api_contorller.go View File

1660
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1660
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1661
 		return
1661
 		return
1662
 	}
1662
 	}
1663
+	fmt.Println("cancelStockDate232323223233223", cancelStockDate.Unix())
1663
 
1664
 
1664
 	adminUserInfo := c.GetAdminUserInfo()
1665
 	adminUserInfo := c.GetAdminUserInfo()
1665
 	operation_time := time.Now().Unix()
1666
 	operation_time := time.Now().Unix()
1685
 		Type:         types,
1686
 		Type:         types,
1686
 	}
1687
 	}
1687
 	service.AddSigleDrugCancelStock(&cancelStock)
1688
 	service.AddSigleDrugCancelStock(&cancelStock)
1689
+	fmt.Println("hh232323232323232323232323232322332", parseDateErr)
1688
 	dataBody := make(map[string]interface{}, 0)
1690
 	dataBody := make(map[string]interface{}, 0)
1689
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1691
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1690
 	if err != nil {
1692
 	if err != nil {
1868
 			//创建退库详情
1870
 			//创建退库详情
1869
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
1871
 			errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
1870
 			//创建库存明细
1872
 			//创建库存明细
1871
-			service.CreateDrugFlow(drugFlow)
1873
+			errs = service.CreateDrugFlow(drugFlow)
1872
 
1874
 
1873
 			var total int64
1875
 			var total int64
1874
 			//退库到当前批次,获取当前退库批次的库存
1876
 			//退库到当前批次,获取当前退库批次的库存
1908
 					"msg": "1",
1910
 					"msg": "1",
1909
 				})
1911
 				})
1910
 			}
1912
 			}
1913
+			if errs != nil {
1914
+				utils.ErrorLog(errs.Error())
1915
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
1916
+				return
1917
+			}
1918
+
1919
+			c.ServeSuccessJSON(map[string]interface{}{
1920
+				"msg": "1",
1921
+			})
1911
 		}
1922
 		}
1912
 	}
1923
 	}
1913
 }
1924
 }
1916
 	adminUserInfo := c.GetAdminUserInfo()
1927
 	adminUserInfo := c.GetAdminUserInfo()
1917
 
1928
 
1918
 	cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
1929
 	cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
1919
-	info, _ := service.FindCancelStockById(id, adminUserInfo.CurrentOrgId)
1920
 
1930
 
1931
+	info, _ := service.FindCancelDrugById(id, adminUserInfo.CurrentOrgId)
1921
 	c.ServeSuccessJSON(map[string]interface{}{
1932
 	c.ServeSuccessJSON(map[string]interface{}{
1922
 		"list": cancelStockInfoList,
1933
 		"list": cancelStockInfoList,
1923
 		"info": info,
1934
 		"info": info,
2047
 
2058
 
2048
 	var cancelStockInfos []*models.DrugCancelStockInfo
2059
 	var cancelStockInfos []*models.DrugCancelStockInfo
2049
 	var upDateCancelStockInfos []*models.DrugCancelStockInfo
2060
 	var upDateCancelStockInfos []*models.DrugCancelStockInfo
2050
-
2061
+	var drugFlow []*models.DrugFlow
2051
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
2062
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
2052
 		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
2063
 		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
2053
 		if len(thisCancelStock) > 0 {
2064
 		if len(thisCancelStock) > 0 {
2134
 
2145
 
2135
 				}
2146
 				}
2136
 
2147
 
2148
+				batch_number_id := int64(items["batch_number_id"].(float64))
2137
 				if id == 0 {
2149
 				if id == 0 {
2138
 					cancelStockInfo := &models.DrugCancelStockInfo{
2150
 					cancelStockInfo := &models.DrugCancelStockInfo{
2139
 						DrugId:           drug_id,
2151
 						DrugId:           drug_id,
2157
 						Remark:           remark,
2169
 						Remark:           remark,
2158
 						ProductDate:      productDates,
2170
 						ProductDate:      productDates,
2159
 						ExpiryDate:       expiryDates,
2171
 						ExpiryDate:       expiryDates,
2172
+						BatchNumberId:    batch_number_id,
2160
 					}
2173
 					}
2161
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
2174
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
2162
 
2175
 
2184
 						Remark:           remark,
2197
 						Remark:           remark,
2185
 						ProductDate:      productDates,
2198
 						ProductDate:      productDates,
2186
 						ExpiryDate:       expiryDates,
2199
 						ExpiryDate:       expiryDates,
2200
+						BatchNumberId:    batch_number_id,
2187
 					}
2201
 					}
2188
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
2202
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
2189
 				}
2203
 				}
2204
+
2205
+				flow := &models.DrugFlow{
2206
+					WarehousingId:           0,
2207
+					DrugId:                  drug_id,
2208
+					Number:                  "",
2209
+					BatchNumber:             batch_number,
2210
+					Count:                   count,
2211
+					UserOrgId:               adminUserInfo.CurrentOrgId,
2212
+					PatientId:               0,
2213
+					SystemTime:              time.Now().Unix(),
2214
+					ConsumableType:          4,
2215
+					IsSys:                   0,
2216
+					WarehousingOrder:        "",
2217
+					WarehouseOutId:          0,
2218
+					WarehouseOutOrderNumber: "",
2219
+					IsEdit:                  0,
2220
+					CancelStockId:           cancelStock.ID,
2221
+					CancelOrderNumber:       cancelStock.OrderNumber,
2222
+					Manufacturer:            0,
2223
+					Dealer:                  0,
2224
+					Creator:                 adminUserInfo.AdminUser.Id,
2225
+					UpdateCreator:           adminUserInfo.AdminUser.Id,
2226
+					Status:                  1,
2227
+					Ctime:                   time.Now().Unix(),
2228
+					Mtime:                   0,
2229
+					Price:                   price,
2230
+					WarehousingDetailId:     0,
2231
+					WarehouseOutDetailId:    0,
2232
+					CancelOutDetailId:       0,
2233
+					ExpireDate:              expiryDates,
2234
+					ProductDate:             productDates,
2235
+					MaxUnit:                 max_unit,
2236
+					MinUnit:                 "",
2237
+				}
2238
+				drugFlow = append(drugFlow, flow)
2190
 			}
2239
 			}
2191
 		}
2240
 		}
2192
 	}
2241
 	}
2193
 	var errs error
2242
 	var errs error
2194
 	if len(cancelStockInfos) > 0 {
2243
 	if len(cancelStockInfos) > 0 {
2195
 		errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
2244
 		errs = service.CreateDrugCancelStockInfo(cancelStockInfos)
2245
+
2246
+		//扣减库存逻辑
2247
+		for _, item := range cancelStockInfos {
2248
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2249
+			//查询当前药品退库的批次号的总入库数
2250
+			infoWareInfo, _ := service.GetDrugWarehouseInfo(item.BatchNumberId)
2251
+			fmt.Println("hhh2h3h2hh3233", item.MaxUnit, medical.MaxUnit)
2252
+			var total_count int64
2253
+			if item.MaxUnit == medical.MaxUnit {
2254
+				total_count = infoWareInfo.WarehousingCount
2255
+			}
2256
+			//转化为最小库存
2257
+			if item.MaxUnit == medical.MinUnit {
2258
+				total_count = infoWareInfo.WarehousingCount * medical.MinNumber
2259
+			}
2260
+			//判断退库数量是否大于总入库数量
2261
+			if item.Count > total_count {
2262
+				c.ServeSuccessJSON(map[string]interface{}{
2263
+					"msg": "2",
2264
+				})
2265
+				return
2266
+			}
2267
+			//正常退库
2268
+			if item.Count <= infoWareInfo.WarehousingCount {
2269
+				//创建退库详情
2270
+				errs := service.CreateDrugCancelStockInfo(cancelStockInfos)
2271
+				//创建库存明细
2272
+				errs = service.CreateDrugFlow(drugFlow)
2273
+
2274
+				var total int64
2275
+				//退库到当前批次,获取当前退库批次的库存
2276
+				info, _ := service.GetDrugWarehouseInfoById(item.BatchNumberId)
2277
+
2278
+				if info.MaxUnit == item.MaxUnit {
2279
+					total = item.Count + info.StockMaxNumber
2280
+
2281
+					warehouseInfo := models.XtDrugWarehouseInfo{
2282
+						StockMaxNumber: total,
2283
+					}
2284
+					errs = service.UpdateDrugWarehouseInfo(&warehouseInfo, item.BatchNumberId)
2285
+					if errs != nil {
2286
+						utils.ErrorLog(errs.Error())
2287
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2288
+						return
2289
+					}
2290
+
2291
+					c.ServeSuccessJSON(map[string]interface{}{
2292
+						"msg": "1",
2293
+					})
2294
+				}
2295
+				if medical.MinUnit == item.MaxUnit {
2296
+					total = item.Count + info.StockMinNumber
2297
+					warehouseInfo := models.XtDrugWarehouseInfo{
2298
+						StockMinNumber: total,
2299
+					}
2300
+
2301
+					errs = service.UpdateDrugWarehouseInfoOne(&warehouseInfo, item.BatchNumberId)
2302
+					if errs != nil {
2303
+						utils.ErrorLog(errs.Error())
2304
+						c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2305
+						return
2306
+					}
2307
+
2308
+					c.ServeSuccessJSON(map[string]interface{}{
2309
+						"msg": "1",
2310
+					})
2311
+				}
2312
+				if errs != nil {
2313
+					utils.ErrorLog(errs.Error())
2314
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
2315
+					return
2316
+				}
2317
+
2318
+				c.ServeSuccessJSON(map[string]interface{}{
2319
+					"msg": "1",
2320
+				})
2321
+			}
2322
+		}
2323
+	}
2324
+	if len(drugFlow) > 0 {
2325
+		parseDateErr := service.CreateDrugFlow(drugFlow)
2326
+		fmt.Println(parseDateErr)
2196
 	}
2327
 	}
2197
 
2328
 
2198
 	if len(upDateCancelStockInfos) > 0 {
2329
 	if len(upDateCancelStockInfos) > 0 {
2330
+		var total int64
2199
 		for _, item := range upDateCancelStockInfos {
2331
 		for _, item := range upDateCancelStockInfos {
2200
 			errs = service.UpDateDrugCancelStockInfo(item)
2332
 			errs = service.UpDateDrugCancelStockInfo(item)
2333
+			//查询该批次最后一条退库记录
2334
+			info, _ := service.GetLastCancelStockInfo(id)
2335
+			//查询该药品的信息
2336
+			medical, _ := service.GetBaseDrugMedical(item.DrugId)
2337
+
2338
+			if item.MaxUnit == medical.MaxUnit {
2339
+				item.Count = item.Count * medical.MinNumber
2340
+				//更新库存
2341
+				total = item.Count - info.Count
2342
+				fmt.Println("total232323232323232232323", total)
2343
+				service.UpdatedDrugInfo(item.BatchNumberId, total)
2344
+				break
2345
+			}
2346
+
2347
+			if item.MaxUnit == medical.MinUnit {
2348
+				item.Count = item.Count
2349
+				total = item.Count - info.Count
2350
+				service.UpdatedDrugInfoOne(item.BatchNumberId, total)
2351
+				break
2352
+			}
2201
 		}
2353
 		}
2202
 	}
2354
 	}
2203
 
2355
 
2208
 	}
2360
 	}
2209
 
2361
 
2210
 	c.ServeSuccessJSON(map[string]interface{}{
2362
 	c.ServeSuccessJSON(map[string]interface{}{
2211
-		"msg": "编辑成功",
2363
+		"msg": "1",
2212
 	})
2364
 	})
2213
 
2365
 
2214
 }
2366
 }

+ 10 - 1
controllers/mobile_api_controllers/dialysis_api_controller.go View File

3332
 		//查询是否有库存
3332
 		//查询是否有库存
3333
 		for _, item := range dialysisBefor {
3333
 		for _, item := range dialysisBefor {
3334
 			warehouse, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId)
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
 			if err != nil {
3345
 			if err != nil {
3337
 				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3346
 				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3338
 				c.ServeSuccessJSON(map[string]interface{}{
3347
 				c.ServeSuccessJSON(map[string]interface{}{

+ 69 - 14
controllers/mobile_api_controllers/patient_api_controller.go View File

608
 
608
 
609
 		//自备药信息
609
 		//自备药信息
610
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
610
 		privateDrugConfig, _ := service.GetDrugSetByUserOrgId(adminUserInfo.Org.Id)
611
-
611
+		fmt.Println("2323232323232323232开关", drugStockConfig.IsOpen)
612
 		if drugStockConfig.IsOpen == 1 {
612
 		if drugStockConfig.IsOpen == 1 {
613
 			if groupno > 0 {
613
 			if groupno > 0 {
614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
614
 				advices, _ := service.FindAllDoctorAdviceByGoroupNo(adminUserInfo.Org.Id, groupno)
620
 				}
620
 				}
621
 
621
 
622
 				if isHasWay {
622
 				if isHasWay {
623
+					var total int64
624
+					var prescribing_number_total int64
623
 					for _, item := range advices {
625
 					for _, item := range advices {
624
 						if item.Way == 1 {
626
 						if item.Way == 1 {
625
 							//查询该药品是否有库存
627
 							//查询该药品是否有库存
626
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
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
+							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
+								total = list.Count
642
+								prescribing_number_total = list.Count
643
+							}
644
+
645
+							fmt.Println("数量一", prescribing_number_total)
646
+							fmt.Println("数量二", total)
647
+
629
 							if list.Count == 0 {
648
 							if list.Count == 0 {
630
 								c.ServeSuccessJSON(map[string]interface{}{
649
 								c.ServeSuccessJSON(map[string]interface{}{
631
-									"msg":    "1",
650
+									"msg":    "3",
632
 									"advice": advice,
651
 									"advice": advice,
633
 									"ids":    ids,
652
 									"ids":    ids,
634
 								})
653
 								})
635
 								return
654
 								return
636
 							}
655
 							}
637
-							if count > list.Count {
656
+							if prescribing_number_total > total {
638
 								c.ServeSuccessJSON(map[string]interface{}{
657
 								c.ServeSuccessJSON(map[string]interface{}{
639
 									"msg":    "2",
658
 									"msg":    "2",
640
 									"advice": advice,
659
 									"advice": advice,
642
 								})
661
 								})
643
 								return
662
 								return
644
 							}
663
 							}
645
-							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
664
+							if prescribing_number_total <= total {
665
+								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
666
+								c.ServeSuccessJSON(map[string]interface{}{
667
+									"msg":    "1",
668
+									"advice": advice,
669
+									"ids":    ids,
670
+								})
671
+								return
672
+							}
673
+
646
 						}
674
 						}
647
 					}
675
 					}
648
 				}
676
 				}
649
 			} else {
677
 			} else {
678
+
650
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
679
 				advices, _ := service.FindDoctorAdviceByIds(adminUserInfo.Org.Id, ids)
651
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
680
 				isHasWay := false //用来判断是否包含来自药品库的医嘱
652
 
681
 
655
 						isHasWay = true
684
 						isHasWay = true
656
 					}
685
 					}
657
 				}
686
 				}
687
+				fmt.Println("hh2h32323232323232323", isHasWay)
658
 				if isHasWay {
688
 				if isHasWay {
689
+					var total int64
690
+					var prescribing_number_total int64
659
 					for _, item := range advices {
691
 					for _, item := range advices {
692
+						fmt.Println("hhh23h2h3h232323", item.Way)
660
 						if item.Way == 1 {
693
 						if item.Way == 1 {
661
 							//查询该药品是否有库存
694
 							//查询该药品是否有库存
662
 							list, _ := service.GetDrugTotalCount(item.DrugId, item.UserOrgId)
695
 							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)
696
+
697
+							//查询改药品信息
698
+							medical, _ := service.GetBaseDrugMedical(item.DrugId)
699
+							//判断单位是否相等
700
+							if medical.MaxUnit == item.PrescribingNumberUnit {
701
+								prescribingNumber_temp := strconv.FormatFloat(math.Abs(item.PrescribingNumber), 'f', 0, 64)
702
+								count, _ := strconv.ParseInt(prescribingNumber_temp, 10, 64)
703
+								//转化为最小单位
704
+								total = list.Count * medical.MinNumber
705
+								prescribing_number_total = count * medical.MinNumber
706
+							}
707
+							if medical.MinUnit == item.PrescribingNumberUnit {
708
+								total = list.Count
709
+								prescribing_number_total = list.Count
710
+							}
711
+
712
+							fmt.Println("数量一", prescribing_number_total)
713
+							fmt.Println("数量二", total)
667
 
714
 
668
 							if list.Count == 0 {
715
 							if list.Count == 0 {
669
 								c.ServeSuccessJSON(map[string]interface{}{
716
 								c.ServeSuccessJSON(map[string]interface{}{
670
-									"msg":    "1",
717
+									"msg":    "3",
671
 									"advice": advice,
718
 									"advice": advice,
672
 									"ids":    ids,
719
 									"ids":    ids,
673
 								})
720
 								})
674
 								return
721
 								return
675
 							}
722
 							}
676
-							if count > list.Count {
723
+							if prescribing_number_total > total {
677
 								c.ServeSuccessJSON(map[string]interface{}{
724
 								c.ServeSuccessJSON(map[string]interface{}{
678
 									"msg":    "2",
725
 									"msg":    "2",
679
 									"advice": advice,
726
 									"advice": advice,
681
 								})
728
 								})
682
 								return
729
 								return
683
 							}
730
 							}
684
-							service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
731
+							if prescribing_number_total <= total {
732
+								service.DrugsDelivery(item.UserOrgId, item.ExecutionStaff, &item)
733
+								c.ServeSuccessJSON(map[string]interface{}{
734
+									"msg":    "1",
735
+									"advice": advice,
736
+									"ids":    ids,
737
+								})
738
+								return
739
+							}
685
 						}
740
 						}
686
 					}
741
 					}
687
 				}
742
 				}
784
 			}
839
 			}
785
 		}
840
 		}
786
 		c.ServeSuccessJSON(map[string]interface{}{
841
 		c.ServeSuccessJSON(map[string]interface{}{
787
-			"msg":    "ok",
842
+			"msg":    "1",
788
 			"advice": advice,
843
 			"advice": advice,
789
 			"ids":    ids,
844
 			"ids":    ids,
790
 		})
845
 		})

+ 7 - 0
controllers/patient_api_controller.go View File

714
 	//		return
714
 	//		return
715
 	//	}
715
 	//	}
716
 	//}
716
 	//}
717
+
717
 	err = service.EditPatientLapseto(&patient, &lapseto)
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
 	if err != nil {
725
 	if err != nil {
719
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
726
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeEditLapsetoFail)
720
 		return
727
 		return

+ 46 - 0
controllers/print_data_api_controller.go View File

16
 	beego.Router("/api/print/stock", &PrintDataAPIController{}, "get:StockRecordPrintData")
16
 	beego.Router("/api/print/stock", &PrintDataAPIController{}, "get:StockRecordPrintData")
17
 	beego.Router("/api/print/course", &PrintDataAPIController{}, "get:CourseRecordPrintData")
17
 	beego.Router("/api/print/course", &PrintDataAPIController{}, "get:CourseRecordPrintData")
18
 	beego.Router("/api/print/getlastafterweight", &PrintDataAPIController{}, "get:GetLastAfterWeight")
18
 	beego.Router("/api/print/getlastafterweight", &PrintDataAPIController{}, "get:GetLastAfterWeight")
19
+	beego.Router("/api/stock/getgooddetailprintlist", &PrintDataAPIController{}, "get:GetGoodDetailPrintList")
19
 }
20
 }
20
 
21
 
21
 type PrintDataAPIController struct {
22
 type PrintDataAPIController struct {
159
 		"weight": weight,
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 View File

2087
 			item.ScheduleDate = copy_startime + 432000
2087
 			item.ScheduleDate = copy_startime + 432000
2088
 		}
2088
 		}
2089
 		//礼拜天
2089
 		//礼拜天
2090
-		if item.ScheduleWeek == 0 {
2090
+		if item.ScheduleWeek == 7 {
2091
 			item.ScheduleDate = copy_endtime
2091
 			item.ScheduleDate = copy_endtime
2092
 		}
2092
 		}
2093
 		schedule := models.XtSchedule{
2093
 		schedule := models.XtSchedule{

+ 116 - 11
controllers/stock_in_api_controller.go View File

1773
 	}
1773
 	}
1774
 
1774
 
1775
 	var cancelStockInfos []*models.CancelStockInfo
1775
 	var cancelStockInfos []*models.CancelStockInfo
1776
-
1776
+	var stockFLow []*models.VmStockFlow
1777
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
1777
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
1778
 		thisStockIn, _ := dataBody["cancelStock"].([]interface{})
1778
 		thisStockIn, _ := dataBody["cancelStock"].([]interface{})
1779
 		if len(thisStockIn) > 0 {
1779
 		if len(thisStockIn) > 0 {
1867
 				}
1867
 				}
1868
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1868
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1869
 
1869
 
1870
+				flow := &models.VmStockFlow{
1871
+					WarehousingId:           0,
1872
+					GoodId:                  good_id,
1873
+					Number:                  number,
1874
+					LicenseNumber:           "",
1875
+					Count:                   count,
1876
+					UserOrgId:               adminUserInfo.CurrentOrgId,
1877
+					PatientId:               0,
1878
+					SystemTime:              time.Now().Unix(),
1879
+					ConsumableType:          4,
1880
+					IsSys:                   0,
1881
+					WarehousingOrder:        "",
1882
+					WarehouseOutId:          0,
1883
+					WarehouseOutOrderNumber: "",
1884
+					IsEdit:                  0,
1885
+					CancelStockId:           cancelStock.ID,
1886
+					CancelOrderNumber:       cancelStock.OrderNumber,
1887
+					Manufacturer:            0,
1888
+					Dealer:                  0,
1889
+					Creator:                 adminUserInfo.AdminUser.Id,
1890
+					UpdateCreator:           0,
1891
+					Status:                  1,
1892
+					Ctime:                   time.Now().Unix(),
1893
+					Mtime:                   0,
1894
+					Price:                   price,
1895
+					WarehousingDetailId:     0,
1896
+					WarehouseOutDetailId:    0,
1897
+					CancelOutDetailId:       0,
1898
+					ProductDate:             productDates,
1899
+					ExpireDate:              expiryDates,
1900
+				}
1901
+				stockFLow = append(stockFLow, flow)
1870
 			}
1902
 			}
1871
 		}
1903
 		}
1872
 	}
1904
 	}
1873
 	errs := service.CreateCancelStockInfo(cancelStockInfos)
1905
 	errs := service.CreateCancelStockInfo(cancelStockInfos)
1874
 
1906
 
1907
+	if len(stockFLow) > 0 {
1908
+		service.CreateStockFlow(stockFLow)
1909
+	}
1910
+
1875
 	for _, item := range cancelStockInfos {
1911
 	for _, item := range cancelStockInfos {
1876
 
1912
 
1877
-		//查找该耗材是否有出库记录
1878
-		_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
1879
-		if errcode == gorm.ErrRecordNotFound {
1880
-			c.ServeSuccessJSON(map[string]interface{}{
1881
-				"msg": "1",
1882
-			})
1883
-			return
1884
-		}
1913
+		////查找该耗材是否有出库记录
1914
+		//_, errcode := service.GetWarehoureOutOrderInfo(item.GoodId, item.OrgId)
1915
+		//if errcode == gorm.ErrRecordNotFound {
1916
+		//	c.ServeSuccessJSON(map[string]interface{}{
1917
+		//		"msg": "1",
1918
+		//	})
1919
+		//	return
1920
+		//}
1885
 
1921
 
1886
 		//统计该耗材的出库数量
1922
 		//统计该耗材的出库数量
1887
 		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
1923
 		info, _ := service.GetWarehoureOrderInfoCount(item.GoodId, item.OrgId)
2052
 
2088
 
2053
 	var cancelStockInfos []*models.CancelStockInfo
2089
 	var cancelStockInfos []*models.CancelStockInfo
2054
 	var upDateCancelStockInfos []*models.CancelStockInfo
2090
 	var upDateCancelStockInfos []*models.CancelStockInfo
2055
-
2091
+	var stockFlow []*models.VmStockFlow
2056
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
2092
 	if dataBody["cancelStock"] != nil && reflect.TypeOf(dataBody["cancelStock"]).String() == "[]interface {}" {
2057
 		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
2093
 		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
2058
 		if len(thisCancelStock) > 0 {
2094
 		if len(thisCancelStock) > 0 {
2156
 					}
2192
 					}
2157
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
2193
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
2158
 
2194
 
2195
+					flow := &models.VmStockFlow{
2196
+						WarehousingId:           0,
2197
+						GoodId:                  good_id,
2198
+						Number:                  number,
2199
+						LicenseNumber:           "",
2200
+						Count:                   count,
2201
+						UserOrgId:               adminUserInfo.CurrentOrgId,
2202
+						PatientId:               0,
2203
+						SystemTime:              time.Now().Unix(),
2204
+						ConsumableType:          4,
2205
+						IsSys:                   0,
2206
+						WarehousingOrder:        "",
2207
+						WarehouseOutId:          0,
2208
+						WarehouseOutOrderNumber: "",
2209
+						IsEdit:                  2,
2210
+						CancelStockId:           cancelStock.ID,
2211
+						CancelOrderNumber:       cancelStock.OrderNumber,
2212
+						Manufacturer:            0,
2213
+						Dealer:                  0,
2214
+						Creator:                 adminUserInfo.AdminUser.Id,
2215
+						UpdateCreator:           0,
2216
+						Status:                  1,
2217
+						Ctime:                   time.Now().Unix(),
2218
+						Mtime:                   0,
2219
+						Price:                   price,
2220
+						WarehousingDetailId:     0,
2221
+						WarehouseOutDetailId:    0,
2222
+						CancelOutDetailId:       0,
2223
+						ProductDate:             productDates,
2224
+						ExpireDate:              expiryDates,
2225
+					}
2226
+
2227
+					stockFlow = append(stockFlow, flow)
2228
+
2159
 				} else {
2229
 				} else {
2160
 					cancelStockInfo := &models.CancelStockInfo{
2230
 					cancelStockInfo := &models.CancelStockInfo{
2161
 						ID:              id,
2231
 						ID:              id,
2178
 						Price:           price,
2248
 						Price:           price,
2179
 					}
2249
 					}
2180
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
2250
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
2251
+
2252
+					flow := &models.VmStockFlow{
2253
+						WarehousingId:           0,
2254
+						GoodId:                  good_id,
2255
+						Number:                  number,
2256
+						LicenseNumber:           "",
2257
+						Count:                   count,
2258
+						UserOrgId:               adminUserInfo.CurrentOrgId,
2259
+						PatientId:               0,
2260
+						SystemTime:              time.Now().Unix(),
2261
+						ConsumableType:          4,
2262
+						IsSys:                   0,
2263
+						WarehousingOrder:        "",
2264
+						WarehouseOutId:          0,
2265
+						WarehouseOutOrderNumber: "",
2266
+						IsEdit:                  2,
2267
+						CancelStockId:           cancelStock.ID,
2268
+						CancelOrderNumber:       cancelStock.OrderNumber,
2269
+						Manufacturer:            0,
2270
+						Dealer:                  0,
2271
+						Creator:                 adminUserInfo.AdminUser.Id,
2272
+						UpdateCreator:           0,
2273
+						Status:                  1,
2274
+						Ctime:                   time.Now().Unix(),
2275
+						Mtime:                   0,
2276
+						Price:                   price,
2277
+						WarehousingDetailId:     0,
2278
+						WarehouseOutDetailId:    0,
2279
+						CancelOutDetailId:       0,
2280
+						ProductDate:             productDates,
2281
+						ExpireDate:              expiryDates,
2282
+					}
2283
+
2284
+					stockFlow = append(stockFlow, flow)
2181
 				}
2285
 				}
2182
 			}
2286
 			}
2183
 		}
2287
 		}
2185
 	var errs error
2289
 	var errs error
2186
 	if len(cancelStockInfos) > 0 {
2290
 	if len(cancelStockInfos) > 0 {
2187
 		errs = service.CreateCancelStockInfo(cancelStockInfos)
2291
 		errs = service.CreateCancelStockInfo(cancelStockInfos)
2292
+		service.CreateStockFlow(stockFlow)
2188
 		// 改变入库单的值
2293
 		// 改变入库单的值
2189
 		for _, item := range cancelStockInfos {
2294
 		for _, item := range cancelStockInfos {
2190
 			//查询该耗材的入库记录
2295
 			//查询该耗材的入库记录
2205
 
2310
 
2206
 	if len(upDateCancelStockInfos) > 0 {
2311
 	if len(upDateCancelStockInfos) > 0 {
2207
 		for _, item := range upDateCancelStockInfos {
2312
 		for _, item := range upDateCancelStockInfos {
2208
-
2313
+			service.CreateStockFlow(stockFlow)
2209
 			errs = service.UpDateCancelStockInfo(item)
2314
 			errs = service.UpDateCancelStockInfo(item)
2210
 			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
2315
 			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
2211
 			//调用退库的方法
2316
 			//调用退库的方法

+ 1 - 1
models/stock_models.go View File

506
 	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
506
 	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
507
 	IsEdit                  int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
507
 	IsEdit                  int64   `gorm:"column:is_edit" json:"is_edit" form:"is_edit"`
508
 	CancelStockId           int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
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
 	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
510
 	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
511
 	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
511
 	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
512
 	Creator                 int64   `gorm:"column:creator" json:"creator" form:"creator"`
512
 	Creator                 int64   `gorm:"column:creator" json:"creator" form:"creator"`

+ 1 - 1
service/gobal_config_service.go View File

664
 
664
 
665
 }
665
 }
666
 
666
 
667
-func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.XtCancelStockInfo, err error) {
667
+func GetCancelDrugCountList(startime int64, endtime int64, orgid int64) (info []*models.DrugCancelStockInfo, err error) {
668
 
668
 
669
 	db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
669
 	db := XTReadDB().Table(" xt_drug_cancel_stock_info as x").Where("x.status = 1")
670
 
670
 

+ 11 - 0
service/patient_service.go View File

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
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
 	return
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 View File

214
 	err = p_service.XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&goodInfo).Error
214
 	err = p_service.XTReadDB().Where("org_id = ? and status = 1", orgid).Find(&goodInfo).Error
215
 	return goodInfo, err
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
+}

+ 35 - 0
service/stock_service.go View File

1117
 	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1117
 	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1118
 	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
1118
 	MaxUnit          string  `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
1119
 	Drug             *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
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"`
1120
 }
1121
 }
1121
 
1122
 
1122
 func (DrugCancelStockInfo) TableName() string {
1123
 func (DrugCancelStockInfo) TableName() string {
2151
 
2152
 
2152
 }
2153
 }
2153
 
2154
 
2155
+func FindCancelDrugById(id int64, org_id int64) (cancelStock models.DrugCancelStock, err error) {
2156
+	err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
2157
+	return cancelStock, err
2158
+
2159
+}
2160
+
2154
 func FindDrugCancelStockById(id int64) (cancelStock models.DrugCancelStock, err error) {
2161
 func FindDrugCancelStockById(id int64) (cancelStock models.DrugCancelStock, err error) {
2155
 	err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
2162
 	err = readDb.Model(&models.DrugCancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
2156
 	return cancelStock, err
2163
 	return cancelStock, err
3846
 		if consumable_type == 3 {
3853
 		if consumable_type == 3 {
3847
 			db = db.Where(" consumable_type = ? and is_sys = 1", consumable_type)
3854
 			db = db.Where(" consumable_type = ? and is_sys = 1", consumable_type)
3848
 		}
3855
 		}
3856
+
3857
+		//4.手动退库
3858
+		if consumable_type == 4 {
3859
+			db = db.Where(" consumable_type = ?", consumable_type)
3860
+		}
3849
 	}
3861
 	}
3850
 	if orgId > 0 {
3862
 	if orgId > 0 {
3851
 		db = db.Where("user_org_id = ?", orgId)
3863
 		db = db.Where("user_org_id = ?", orgId)
3939
 		if stock_type == 3 {
3951
 		if stock_type == 3 {
3940
 			db = db.Where("consumable_type = 3 and is_sys = 1")
3952
 			db = db.Where("consumable_type = 3 and is_sys = 1")
3941
 		}
3953
 		}
3954
+		if stock_type == 4 {
3955
+			db = db.Where("consumable_type = 4")
3956
+		}
3942
 	}
3957
 	}
3943
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&drug_flow).Error
3958
 	err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&drug_flow).Error
3944
 	return drug_flow, total, err
3959
 	return drug_flow, total, err
4029
 	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
4044
 	err := XTWriteDB().Model(&info).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"stock_min_number": info.StockMaxNumber}).Error
4030
 	return err
4045
 	return err
4031
 }
4046
 }
4047
+
4048
+func GetLastCancelStockInfo(id int64) (models.DrugCancelStockInfo, error) {
4049
+
4050
+	info := models.DrugCancelStockInfo{}
4051
+
4052
+	err := XTReadDB().Where("id = ? and status = 1", id).Find(&info).Error
4053
+	return info, err
4054
+}
4055
+
4056
+func UpdatedDrugInfo(id int64, count int64) (err error) {
4057
+
4058
+	err = writeDb.Model(&models.DrugWarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_max_number", gorm.Expr("stock_max_number + ?", count)).Error
4059
+	return err
4060
+}
4061
+
4062
+func UpdatedDrugInfoOne(id int64, count int64) (err error) {
4063
+
4064
+	err = writeDb.Model(&models.DrugWarehousingInfo{}).Where("id = ?", id).UpdateColumn("stock_min_number", gorm.Expr("stock_min_number + ?", count)).Error
4065
+	return err
4066
+}

+ 2 - 2
service/warhouse_service.go View File

1313
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1313
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1314
 			IsEdit:                  1,
1314
 			IsEdit:                  1,
1315
 			CancelStockId:           0,
1315
 			CancelStockId:           0,
1316
-			CancelOrderNumber:       0,
1316
+			CancelOrderNumber:       "",
1317
 			Manufacturer:            goods.Manufacturer,
1317
 			Manufacturer:            goods.Manufacturer,
1318
 			Dealer:                  goods.Dealer,
1318
 			Dealer:                  goods.Dealer,
1319
 			Creator:                 creator,
1319
 			Creator:                 creator,
1401
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1401
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1402
 			IsEdit:                  1,
1402
 			IsEdit:                  1,
1403
 			CancelStockId:           0,
1403
 			CancelStockId:           0,
1404
-			CancelOrderNumber:       0,
1404
+			CancelOrderNumber:       "",
1405
 			Manufacturer:            goods.Manufacturer,
1405
 			Manufacturer:            goods.Manufacturer,
1406
 			Dealer:                  goods.Dealer,
1406
 			Dealer:                  goods.Dealer,
1407
 			Creator:                 creator,
1407
 			Creator:                 creator,