XMLWAN 3 år sedan
förälder
incheckning
9d182640c4

+ 1 - 1
conf/app.conf Visa fil

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9531
2
+httpport = 9529
3 3
 runmode = dev
4 4
 
5 5
 #

+ 194 - 94
controllers/drug_stock_api_contorller.go Visa fil

@@ -71,8 +71,6 @@ func DrugStockManagerApiRegistRouters() {
71 71
 func (c *StockDrugApiController) CreateDrugWarehouse() {
72 72
 
73 73
 	warehousing_time := c.GetString("warehousing_time")
74
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
75
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
76 74
 
77 75
 	types, _ := c.GetInt64("type", 0)
78 76
 
@@ -100,8 +98,6 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
100 98
 		Ctime:            ctime,
101 99
 		Status:           1,
102 100
 		WarehousingTime:  warehousingDate.Unix(),
103
-		Dealer:           dealer_id,
104
-		Manufacturer:     manufacturer_id,
105 101
 		Type:             types,
106 102
 	}
107 103
 	service.AddSigleDrugWarehouse(&warehousing)
@@ -144,12 +140,6 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
144 140
 				last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
145 141
 				total := float64(warehousing_count) * last_price
146 142
 
147
-				//if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
148
-				//	utils.ErrorLog("retail_price")
149
-				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
150
-				//	return
151
-				//}
152
-				//retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
153 143
 				retail_price_total := float64(warehousing_count) * last_price
154 144
 
155 145
 				var productDates int64
@@ -183,7 +173,7 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
183 173
 
184 174
 				}
185 175
 
186
-				lot_number, _ := items["lot_number"].(string)
176
+				number, _ := items["number"].(string)
187 177
 
188 178
 				batch_number, _ := items["batch_number"].(string)
189 179
 
@@ -193,14 +183,14 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
193 183
 					return
194 184
 				}
195 185
 				max_unit, _ := items["max_unit"].(string)
196
-				fmt.Println("最大单位00000000000000000000000000000000", max_unit)
186
+
197 187
 				if items["min_unit"] == nil || reflect.TypeOf(items["min_unit"]).String() != "string" {
198 188
 					utils.ErrorLog("min_unit")
199 189
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
200 190
 					return
201 191
 				}
202 192
 				min_unit, _ := items["min_unit"].(string)
203
-				fmt.Println("最下单位0090000000000000000000", min_unit)
193
+
204 194
 				var remark string
205 195
 				if items["remark"] == nil || reflect.TypeOf(items["remark"]).String() != "string" {
206 196
 					remark = ""
@@ -208,11 +198,15 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
208 198
 					remark = items["remark"].(string)
209 199
 				}
210 200
 
201
+				manufacturer := int64(items["manufacturer"].(float64))
202
+
203
+				dealer := int64(items["dealer"].(float64))
204
+
211 205
 				warehouseInfo := &models.DrugWarehouseInfo{
212 206
 					WarehousingOrder: warehousing.WarehousingOrder,
213 207
 					WarehousingId:    warehousing.ID,
214 208
 					DrugId:           drug_id,
215
-					Number:           lot_number,
209
+					Number:           number,
216 210
 					ProductDate:      productDates,
217 211
 					ExpiryDate:       expiryDates,
218 212
 					WarehousingCount: warehousing_count,
@@ -223,9 +217,8 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
223 217
 					Remark:           remark,
224 218
 					OrgId:            adminUserInfo.CurrentOrgId,
225 219
 					Type:             types,
226
-					Manufacturer:     manufacturer_id,
227
-					Dealer:           dealer_id,
228
-					//RetailPrice:      retail_price,
220
+					Manufacturer:     manufacturer,
221
+					Dealer:           dealer,
229 222
 					StockMaxNumber:   warehousing_count,
230 223
 					RetailTotalPrice: retail_price_total,
231 224
 					BatchNumber:      batch_number,
@@ -396,9 +389,6 @@ func (c *StockDrugApiController) GetDrugWarehouseList() {
396 389
 	types, _ := c.GetInt64("type", 0)
397 390
 	keywords := c.GetString("keywords")
398 391
 
399
-	fmt.Println(start_time)
400
-	fmt.Println(end_time)
401
-
402 392
 	timeLayout := "2006-01-02"
403 393
 	loc, _ := time.LoadLocation("Local")
404 394
 	var startTime int64
@@ -423,7 +413,24 @@ func (c *StockDrugApiController) GetDrugWarehouseList() {
423 413
 	}
424 414
 
425 415
 	adminUserInfo := c.GetAdminUserInfo()
426
-	warehouseList, total, err := service.FindAllDrugWarehousingList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
416
+	fmt.Println("hhh2h3h23h2h32h3h2h32h32h3h2h3", keywords)
417
+	//按药品名称搜索
418
+	var ids []int64
419
+	var idArray []int64
420
+	list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
421
+	for _, item := range list {
422
+		ids = append(ids, item.ID)
423
+	}
424
+
425
+	//查找入库单详情
426
+	if len(ids) > 0 {
427
+		info, _ := service.GetDrugWarehouseOrderDetailTwo(ids, adminUserInfo.CurrentOrgId, startTime, endTime)
428
+		for _, it := range info {
429
+			idArray = append(idArray, it.WarehousingId)
430
+		}
431
+	}
432
+
433
+	warehouseList, total, err := service.FindAllDrugWarehousingListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, idArray)
427 434
 	if err == nil {
428 435
 		c.ServeSuccessJSON(map[string]interface{}{
429 436
 			"list":  warehouseList,
@@ -445,6 +452,7 @@ func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
445 452
 	warehousing, err := service.FindDrugWarehousingById(id, admin.CurrentOrgId)
446 453
 
447 454
 	manufacturerList, _ := service.GetAllManufacturerList(admin.CurrentOrgId)
455
+	dealerList, _ := service.GetAllDealerList(admin.CurrentOrgId)
448 456
 	if err != nil {
449 457
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
450 458
 		return
@@ -461,6 +469,7 @@ func (c *StockDrugApiController) GetDrugWarehouseInfoList() {
461 469
 			"info":             warehousingInfo,
462 470
 			"warehousing":      warehousing,
463 471
 			"manufacturerList": manufacturerList,
472
+			"dealerList":       dealerList,
464 473
 		})
465 474
 	} else {
466 475
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -472,8 +481,6 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
472 481
 	warehousing_time := c.GetString("warehousing_time")
473 482
 	id, _ := c.GetInt64("id", 0)
474 483
 	types, _ := c.GetInt64("type", 0)
475
-	//manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
476
-	//dealer_id, _ := c.GetInt64("dealer_id", 0)
477 484
 
478 485
 	if id == 0 {
479 486
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -501,8 +508,6 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
501 508
 		Status:           1,
502 509
 		WarehousingTime:  warehousingDate.Unix(),
503 510
 		Type:             warehouse.Type,
504
-		//Dealer:           dealer_id,
505
-		//Manufacturer:     manufacturer_id,
506 511
 	}
507 512
 
508 513
 	service.EditDrugWarehousingOne(warehousing, id)
@@ -548,14 +553,6 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
548 553
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
549 554
 				total := float64(warehousing_count) * price
550 555
 
551
-				//if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
552
-				//	utils.ErrorLog("retail_price")
553
-				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
554
-				//	return
555
-				//}
556
-				//retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
557
-				//retail_price_total := float64(warehousing_count) * last_price
558
-
559 556
 				if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
560 557
 					utils.ErrorLog("last_price")
561 558
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -596,12 +593,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
596 593
 
597 594
 				}
598 595
 
599
-				if items["lot_number"] == nil || reflect.TypeOf(items["lot_number"]).String() != "string" {
600
-					utils.ErrorLog("lot_number")
601
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
602
-					return
603
-				}
604
-				number, _ := items["lot_number"].(string)
596
+				number, _ := items["number"].(string)
605 597
 
606 598
 				batch_number, _ := items["batch_number"].(string)
607 599
 
@@ -623,19 +615,9 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
623 615
 				}
624 616
 				id := int64(items["id"].(float64))
625 617
 
626
-				//if items["dealer"] == nil || reflect.TypeOf(items["dealer"]).String() != "float64" {
627
-				//	utils.ErrorLog("dealer")
628
-				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
629
-				//	return
630
-				//}
631
-				//dealer := int64(items["dealer"].(float64))
632
-				//
633
-				if items["manufacturer"] == nil || reflect.TypeOf(items["manufacturer"]).String() != "float64" {
634
-					utils.ErrorLog("manufacturer")
635
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
636
-					return
637
-				}
638 618
 				manufacturer := int64(items["manufacturer"].(float64))
619
+
620
+				dealer := int64(items["dealer"].(float64))
639 621
 				if id == 0 {
640 622
 					warehouseInfo := &models.DrugWarehouseInfo{
641 623
 						WarehousingOrder: warehouse.WarehousingOrder,
@@ -653,7 +635,7 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
653 635
 						OrgId:            adminUserInfo.CurrentOrgId,
654 636
 						Type:             types,
655 637
 						Manufacturer:     manufacturer,
656
-						//Dealer:           dealer,
638
+						Dealer:           dealer,
657 639
 						RetailPrice:      last_price,
658 640
 						RetailTotalPrice: retail_price_total,
659 641
 						BatchNumber:      batch_number,
@@ -680,12 +662,13 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
680 662
 						OrgId:            adminUserInfo.CurrentOrgId,
681 663
 						Type:             types,
682 664
 						Manufacturer:     manufacturer,
683
-						//Dealer:           dealer,
665
+						Dealer:           dealer,
684 666
 						RetailPrice:      last_price,
685 667
 						RetailTotalPrice: retail_price_total,
686 668
 						StockMaxNumber:   warehousing_count,
687 669
 						MaxUnit:          max_unit,
688 670
 						MinUnit:          min_unit,
671
+						BatchNumber:      batch_number,
689 672
 					}
690 673
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
691 674
 				}
@@ -1122,8 +1105,7 @@ func (c *StockDrugApiController) EditDrugReturnInfo() {
1122 1105
 }
1123 1106
 
1124 1107
 func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1125
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
1126
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
1108
+
1127 1109
 	types, _ := c.GetInt64("type", 0)
1128 1110
 
1129 1111
 	ctime := time.Now().Unix()
@@ -1156,11 +1138,9 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1156 1138
 		Ctime:                   ctime,
1157 1139
 		Status:                  1,
1158 1140
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1159
-		Dealer:                  dealer_id,
1160
-		Manufacturer:            manufacturer_id,
1161 1141
 		Type:                    types,
1162 1142
 	}
1163
-	service.AddSigleDrugWarehouseOut(&warehouseOut)
1143
+
1164 1144
 	dataBody := make(map[string]interface{}, 0)
1165 1145
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
1166 1146
 	if err != nil {
@@ -1212,6 +1192,42 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1212 1192
 				retail_price_total := float64(count) * last_price
1213 1193
 				remark := items["remark"].(string)
1214 1194
 				max_unit := items["max_unit"].(string)
1195
+				var productDates int64
1196
+				var expiryDates int64
1197
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1198
+					expiryDates = 0
1199
+				} else {
1200
+					if len(items["expiry_date"].(string)) == 0 {
1201
+						expiryDates = 0
1202
+
1203
+					} else {
1204
+						expiryDate, _ := items["expiry_date"].(string)
1205
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1206
+						expiryDates = expiry_date.Unix()
1207
+
1208
+					}
1209
+
1210
+				}
1211
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
1212
+					productDates = 0
1213
+				} else {
1214
+					if len(items["product_date"].(string)) == 0 {
1215
+						productDates = 0
1216
+
1217
+					} else {
1218
+						productDate, _ := items["product_date"].(string)
1219
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1220
+						productDates = product_date.Unix()
1221
+					}
1222
+
1223
+				}
1224
+
1225
+				dealer := int64(items["dealer"].(float64))
1226
+
1227
+				manufacturer := int64(items["manufacturer"].(float64))
1228
+
1229
+				number := items["number"].(string)
1230
+				batch_number := items["batch_number"].(string)
1215 1231
 
1216 1232
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1217 1233
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1225,11 +1241,15 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1225 1241
 					Remark:                  remark,
1226 1242
 					OrgId:                   adminUserInfo.CurrentOrgId,
1227 1243
 					Type:                    types,
1228
-					Manufacturer:            manufacturer_id,
1229
-					Dealer:                  dealer_id,
1244
+					Manufacturer:            manufacturer,
1245
+					Dealer:                  dealer,
1230 1246
 					RetailPrice:             last_price,
1231 1247
 					RetailTotalPrice:        retail_price_total,
1232 1248
 					CountUnit:               max_unit,
1249
+					ExpiryDate:              expiryDates,
1250
+					ProductDate:             productDates,
1251
+					Number:                  number,
1252
+					BatchNumber:             batch_number,
1233 1253
 				}
1234 1254
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1235 1255
 
@@ -1238,32 +1258,51 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1238 1258
 	}
1239 1259
 
1240 1260
 	//调用出库逻辑
1241
-	//for _, item := range warehousingOutInfo {
1242
-	//
1243
-	//	// 出库流程
1244
-	//	// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1245
-	//	drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1246
-	//	if drup.ID > 0 {
1247
-	//		prescribingNumber := item.Count
1248
-	//
1249
-	//		service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1250
-	//
1251
-	//	}
1252
-	//
1253
-	//}
1261
+	for _, item := range warehousingOutInfo {
1262
+		//获取药品库存
1263
+		info, _ := service.GetDrugTotalCount(item.DrugId, item.OrgId)
1264
+		if item.Count > info.Count {
1265
+
1266
+			goodObj, _ := service.GetDrugByGoodId(item.DrugId)
1267
+			c.ServeSuccessJSON(map[string]interface{}{
1268
+				"msg":        "1",
1269
+				"drug_name":  goodObj.DrugName,
1270
+				"dose":       goodObj.Dose,
1271
+				"dose_unit":  goodObj.DoseUnit,
1272
+				"min_number": goodObj.MinNumber,
1273
+				"min_unit":   goodObj.MinUnit,
1274
+				"max_unit":   goodObj.MaxUnit,
1275
+			})
1276
+			return
1277
+		} else {
1278
+			service.AddSigleDrugWarehouseOut(&warehouseOut)
1279
+			// 出库流程
1280
+			// 1.查询改药品在药品库的规格信息,并将处方里的规格进行换算(尽量将拆零单位转换成包装单位)
1281
+			drup, _ := service.FindBaseDrugLibRecord(item.OrgId, item.DrugId)
1282
+			if drup.ID > 0 {
1283
+				prescribingNumber := item.Count
1284
+				service.AutoDrugDeliverInfo(item.OrgId, prescribingNumber, &warehouseOut, &drup, item)
1285
+			}
1286
+		}
1254 1287
 
1255
-	errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1256
-	info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1257
-	if errs != nil {
1258
-		utils.ErrorLog(errs.Error())
1259
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1260
-		return
1261 1288
 	}
1262 1289
 
1290
+	//errs := service.CreateDrugWarehousingOutInfo(warehousingOutInfo)
1291
+	//info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1292
+	//if errs != nil {
1293
+	//	utils.ErrorLog(errs.Error())
1294
+	//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1295
+	//	return
1296
+	//}
1297
+
1263 1298
 	c.ServeSuccessJSON(map[string]interface{}{
1264
-		"info":                  info,
1265
-		"msg":                   "出库成功",
1266
-		"warehousing_out_order": warehousing_out_order,
1299
+		"msg":        "2",
1300
+		"drug_name":  "",
1301
+		"dose":       "",
1302
+		"dose_unit":  "",
1303
+		"min_number": "",
1304
+		"min_unit":   "",
1305
+		"max_unit":   "",
1267 1306
 	})
1268 1307
 
1269 1308
 }
@@ -1298,7 +1337,27 @@ func (c *StockDrugApiController) GetDrugWarehouseOutList() {
1298 1337
 	}
1299 1338
 
1300 1339
 	adminUserInfo := c.GetAdminUserInfo()
1301
-	warehouseOutList, total, err := service.FindAllDrugWarehouseOutList(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords)
1340
+
1341
+	var ids []int64
1342
+	var goodids []int64
1343
+	if len(keywords) > 0 {
1344
+		//查询商品名称
1345
+		list, _ := service.GetDrugNameByKeyword(keywords, adminUserInfo.CurrentOrgId)
1346
+		for _, item := range list {
1347
+			goodids = append(goodids, item.ID)
1348
+		}
1349
+
1350
+		if len(goodids) > 0 {
1351
+			//出库详情但里面查询
1352
+			info, _ := service.GetDrugWarehouseOrderDetail(goodids, adminUserInfo.CurrentOrgId, startTime, endTime)
1353
+			for _, it := range info {
1354
+				ids = append(ids, it.WarehouseOutId)
1355
+			}
1356
+		}
1357
+
1358
+	}
1359
+
1360
+	warehouseOutList, total, err := service.FindAllDrugWarehouseOutListOne(adminUserInfo.CurrentOrgId, page, limit, startTime, endTime, types, keywords, ids)
1302 1361
 	fmt.Println(err)
1303 1362
 	if err == nil {
1304 1363
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -1351,10 +1410,12 @@ func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
1351 1410
 	warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
1352 1411
 	warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
1353 1412
 	manulist, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
1413
+	dealerList, _ := service.GetAllDealerList(adminInfo.CurrentOrgId)
1354 1414
 	c.ServeSuccessJSON(map[string]interface{}{
1355
-		"list":     warehouseOutInfo,
1356
-		"info":     warehouseOut,
1357
-		"manulist": manulist,
1415
+		"list":       warehouseOutInfo,
1416
+		"info":       warehouseOut,
1417
+		"manulist":   manulist,
1418
+		"dealerList": dealerList,
1358 1419
 	})
1359 1420
 
1360 1421
 }
@@ -1362,8 +1423,6 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1362 1423
 	warehouse_out_time := c.GetString("warehouse_out_time")
1363 1424
 	id, _ := c.GetInt64("id", 0)
1364 1425
 	types, _ := c.GetInt64("type", 0)
1365
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
1366
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
1367 1426
 
1368 1427
 	if id == 0 {
1369 1428
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1387,8 +1446,6 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1387 1446
 		ID:               warehouseOut.ID,
1388 1447
 		Mtime:            mtime,
1389 1448
 		WarehouseOutTime: warehouseOutDate.Unix(),
1390
-		Manufacturer:     manufacturer_id,
1391
-		Dealer:           dealer_id,
1392 1449
 	}
1393 1450
 
1394 1451
 	service.EditDrugWarehouseOut(tempWarehouseOut)
@@ -1451,6 +1508,41 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1451 1508
 				}
1452 1509
 				id := int64(items["id"].(float64))
1453 1510
 
1511
+				dealer := int64(items["dealer"].(float64))
1512
+				manufacturer := int64(items["manufacturer"].(float64))
1513
+
1514
+				batch_number := items["batch_number"].(string)
1515
+				number := items["number"].(string)
1516
+
1517
+				var productDates int64
1518
+				var expiryDates int64
1519
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1520
+					expiryDates = 0
1521
+				} else {
1522
+					if len(items["expiry_date"].(string)) == 0 {
1523
+						expiryDates = 0
1524
+
1525
+					} else {
1526
+						expiryDate, _ := items["expiry_date"].(string)
1527
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1528
+						expiryDates = expiry_date.Unix()
1529
+
1530
+					}
1531
+
1532
+				}
1533
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
1534
+					productDates = 0
1535
+				} else {
1536
+					if len(items["product_date"].(string)) == 0 {
1537
+						productDates = 0
1538
+
1539
+					} else {
1540
+						productDate, _ := items["product_date"].(string)
1541
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1542
+						productDates = product_date.Unix()
1543
+					}
1544
+
1545
+				}
1454 1546
 				if id == 0 {
1455 1547
 					warehouseOutInfo := &models.DrugWarehouseOutInfo{
1456 1548
 						WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1464,12 +1556,16 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1464 1556
 						Remark:                  remark,
1465 1557
 						OrgId:                   adminUserInfo.CurrentOrgId,
1466 1558
 						Type:                    types,
1467
-						Manufacturer:            manufacturer_id,
1468
-						Dealer:                  dealer_id,
1559
+						Manufacturer:            manufacturer,
1560
+						Dealer:                  dealer,
1469 1561
 						IsSys:                   0,
1470 1562
 						SysRecordTime:           0,
1471 1563
 						RetailPrice:             retail_price,
1472 1564
 						RetailTotalPrice:        retail_price_total,
1565
+						BatchNumber:             batch_number,
1566
+						Number:                  number,
1567
+						ProductDate:             productDates,
1568
+						ExpiryDate:              expiryDates,
1473 1569
 					}
1474 1570
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1475 1571
 
@@ -1502,12 +1598,16 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1502 1598
 						OrgId:                   adminUserInfo.CurrentOrgId,
1503 1599
 						Mtime:                   time.Now().Unix(),
1504 1600
 						Type:                    types,
1505
-						Manufacturer:            manufacturer_id,
1506
-						Dealer:                  dealer_id,
1601
+						Manufacturer:            manufacturer,
1602
+						Dealer:                  dealer,
1507 1603
 						IsSys:                   is_sys,
1508 1604
 						SysRecordTime:           sys_record_time,
1509 1605
 						RetailPrice:             retail_price,
1510 1606
 						RetailTotalPrice:        retail_price_total,
1607
+						BatchNumber:             batch_number,
1608
+						Number:                  number,
1609
+						ProductDate:             productDates,
1610
+						ExpiryDate:              expiryDates,
1511 1611
 					}
1512 1612
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1513 1613
 				}

+ 5 - 1
controllers/gobal_config_api_controller.go Visa fil

@@ -2023,12 +2023,16 @@ func (c *GobalConfigApiController) GetSingleOrderDetail() {
2023 2023
 	id, _ := c.GetInt64("id")
2024 2024
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2025 2025
 	list, err := service.GetSingleOrderDetail(id, orgId)
2026
+	dealerList, err := service.GetAllDealerList(orgId)
2027
+	manufacturerList, err := service.GetAllManufacturerList(orgId)
2026 2028
 	if err != nil {
2027 2029
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
2028 2030
 		return
2029 2031
 	}
2030 2032
 	c.ServeSuccessJSON(map[string]interface{}{
2031
-		"list": list,
2033
+		"list":             list,
2034
+		"dealerList":       dealerList,
2035
+		"manufacturerList": manufacturerList,
2032 2036
 	})
2033 2037
 }
2034 2038
 

+ 4 - 0
controllers/manager_center_api_controller.go Visa fil

@@ -2198,10 +2198,12 @@ func (c *ManagerCenterApiController) GetAllDrugList() {
2198 2198
 
2199 2199
 	list, err := service.GetAllDrugList(orgId)
2200 2200
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2201
+	dealerList, _ := service.GetAllDealerList(orgId)
2201 2202
 	if err == nil {
2202 2203
 		c.ServeSuccessJSON(map[string]interface{}{
2203 2204
 			"list":             list,
2204 2205
 			"manufacturerList": manufacturerList,
2206
+			"dealerList":       dealerList,
2205 2207
 		})
2206 2208
 	} else {
2207 2209
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -2213,10 +2215,12 @@ func (c *ManagerCenterApiController) GetSearchDrugList() {
2213 2215
 	orgId := c.GetAdminUserInfo().CurrentOrgId
2214 2216
 	list, err := service.GetSearchDrugList(keyword, orgId)
2215 2217
 	manufacturerList, _ := service.GetAllManufacturerList(orgId)
2218
+	dealerList, _ := service.GetAllDealerList(orgId)
2216 2219
 	if err == nil {
2217 2220
 		c.ServeSuccessJSON(map[string]interface{}{
2218 2221
 			"list":             list,
2219 2222
 			"manufacturerList": manufacturerList,
2223
+			"dealerList":       dealerList,
2220 2224
 		})
2221 2225
 	} else {
2222 2226
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)

+ 6 - 6
controllers/mobile_api_controllers/dialysis_api_controller.go Visa fil

@@ -3633,9 +3633,9 @@ func (c *DialysisAPIController) CreateStockOutInfo() {
3633 3633
 
3634 3634
 		//查询是否有库存
3635 3635
 		for _, item := range consumables {
3636
-			warehouse, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId)
3637
-			fmt.Println("库存数量00000000000000000000", warehouse.StockCount)
3638
-			if err != nil {
3636
+			warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
3637
+
3638
+			if item.Count > warehouse.Count {
3639 3639
 				goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
3640 3640
 				c.ServeSuccessJSON(map[string]interface{}{
3641 3641
 					"message":            "1",
@@ -4260,9 +4260,9 @@ func (c *DialysisAPIController) CreateOtherStockOutInfo() {
4260 4260
 	fmt.Println("前端数据9999999999999", beforePrepares)
4261 4261
 	//查询是否有库存
4262 4262
 	for _, item := range beforePrepares {
4263
-		warehouse, err := service.FindFirstWarehousingInfoByStock(item.GoodId, item.GoodTypeId)
4264
-		fmt.Println("库存数量00000000000000000000", warehouse.StockCount)
4265
-		if err != nil {
4263
+		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
4264
+
4265
+		if item.Count > warehouse.Count {
4266 4266
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
4267 4267
 			c.ServeSuccessJSON(map[string]interface{}{
4268 4268
 				"message":            "1",

+ 34 - 10
controllers/stock_in_api_controller.go Visa fil

@@ -91,6 +91,7 @@ func StockManagerApiRegistRouters() {
91 91
 	beego.Router("/api/good/getsingleoutorderdetail", &StockManagerApiController{}, "Get:GetSingleOutOrderDetail")
92 92
 	beego.Router("/api/stock/getexportstocklist", &StockManagerApiController{}, "Get:GetExprotStockList")
93 93
 	beego.Router("/api/stock/getoutexprotlist", &StockManagerApiController{}, "Get:GetOutExprotList")
94
+	beego.Router("/api/stock/getsinglecancelorder", &StockManagerApiController{}, "Get:GetSingleCancelOrder")
94 95
 
95 96
 }
96 97
 
@@ -562,8 +563,6 @@ func (c *StockManagerApiController) EditWarehouse() {
562 563
 				var productDates int64
563 564
 				var expiryDates int64
564 565
 
565
-				fmt.Println()
566
-
567 566
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
568 567
 					expiryDates = 0
569 568
 				} else {
@@ -1087,7 +1086,6 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1087 1086
 	operation_time := time.Now().Unix()
1088 1087
 	creater := adminUserInfo.AdminUser.Id
1089 1088
 
1090
-	_, errcode := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1091 1089
 	warehouseOut := models.WarehouseOut{
1092 1090
 		WarehouseOutOrderNumber: warehousing_out_order,
1093 1091
 		OperationTime:           operation_time,
@@ -1098,9 +1096,6 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1098 1096
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1099 1097
 		Type:                    types,
1100 1098
 	}
1101
-	if errcode == gorm.ErrRecordNotFound {
1102
-		service.AddSigleWarehouseOut(&warehouseOut)
1103
-	}
1104 1099
 
1105 1100
 	dataBody := make(map[string]interface{}, 0)
1106 1101
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -1182,7 +1177,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1182 1177
 					}
1183 1178
 					productDate = theTime.Unix()
1184 1179
 				}
1185
-
1180
+				license_number := items["license_number"].(string)
1186 1181
 				warehouseOutInfo := &models.WarehouseOutInfo{
1187 1182
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1188 1183
 					WarehouseOutId:          warehouseOut.ID,
@@ -1201,6 +1196,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1201 1196
 					ExpiryDate:              expiryDate,
1202 1197
 					ProductDate:             productDate,
1203 1198
 					Dealer:                  dealer,
1199
+					LicenseNumber:           license_number,
1204 1200
 				}
1205 1201
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1206 1202
 
@@ -1225,9 +1221,9 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1225 1221
 	//出库逻辑
1226 1222
 	for _, item := range warehousingOutInfo {
1227 1223
 		//查询库存
1228
-		warehouse, err := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1224
+		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1229 1225
 		fmt.Println("库存数量组吗", warehouse.Count)
1230
-		if err != nil {
1226
+		if item.Count > warehouse.Count {
1231 1227
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1232 1228
 			c.ServeSuccessJSON(map[string]interface{}{
1233 1229
 				"msg":                "1",
@@ -1236,8 +1232,11 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1236 1232
 			})
1237 1233
 			return
1238 1234
 		} else {
1235
+			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1236
+			if errcodes == gorm.ErrRecordNotFound {
1237
+				service.AddSigleWarehouseOut(&warehouseOut)
1238
+			}
1239 1239
 			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1240
-			fmt.Println(parseDateErr)
1241 1240
 			if parseDateErr != nil {
1242 1241
 				utils.ErrorLog(parseDateErr.Error())
1243 1242
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
@@ -1461,6 +1460,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1461 1460
 
1462 1461
 				number := items["number"].(string)
1463 1462
 
1463
+				license_number := items["license_number"].(string)
1464
+				fmt.Println("hhh23h2h32h3h232h3h23h2h3h23h2h3h23h2h3", license_number)
1464 1465
 				timeLayout := "2006-01-02"
1465 1466
 				loc, _ := time.LoadLocation("Local")
1466 1467
 				expiry_date := items["expiry_date"].(string)
@@ -1507,6 +1508,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1507 1508
 						ProductDate:             productDate,
1508 1509
 						Dealer:                  dealer,
1509 1510
 						Manufacturer:            manufacturer,
1511
+						LicenseNumber:           license_number,
1510 1512
 					}
1511 1513
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1512 1514
 
@@ -1547,6 +1549,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1547 1549
 						ExpiryDate:              expiryDate,
1548 1550
 						ProductDate:             productDate,
1549 1551
 						Dealer:                  dealer,
1552
+						LicenseNumber:           license_number,
1550 1553
 					}
1551 1554
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1552 1555
 				}
@@ -1672,6 +1675,16 @@ func (c *StockManagerApiController) CreateCancelStock() {
1672 1675
 		}
1673 1676
 	}
1674 1677
 	errs := service.CreateCancelStockInfo(cancelStockInfos)
1678
+
1679
+	// 改变入库单的值
1680
+	for _, item := range cancelStockInfos {
1681
+
1682
+		//查询该耗材的入库记录
1683
+		list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1684
+		//调用退库的方法
1685
+		service.UpdateCancelOut(list, item.Count)
1686
+	}
1687
+
1675 1688
 	if errs != nil {
1676 1689
 		utils.ErrorLog(errs.Error())
1677 1690
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
@@ -4026,3 +4039,14 @@ func (this *StockManagerApiController) GetOutExprotList() {
4026 4039
 		"count": outCount,
4027 4040
 	})
4028 4041
 }
4042
+
4043
+func (this *StockManagerApiController) GetSingleCancelOrder() {
4044
+
4045
+	id, _ := this.GetInt64("id")
4046
+	adminUserInfo := this.GetAdminUserInfo()
4047
+	orgId := adminUserInfo.CurrentOrgId
4048
+	order, _ := service.GetSingleCancelOrder(id, orgId)
4049
+	this.ServeSuccessJSON(map[string]interface{}{
4050
+		"list": order,
4051
+	})
4052
+}

+ 2 - 0
models/drug_stock.go Visa fil

@@ -102,6 +102,8 @@ type DrugWarehouseOutInfo struct {
102 102
 	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
103 103
 	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
104 104
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
105
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
106
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
105 107
 }
106 108
 
107 109
 func (DrugWarehouseOutInfo) TableName() string {

+ 11 - 0
models/self_drug_models.go Visa fil

@@ -451,6 +451,10 @@ type BloodDrugWarehouseInfo struct {
451 451
 	DrugSpec         string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
452 452
 	Creater          int64   `gorm:"column:creater" json:"creater" form:"creater"`
453 453
 	MinUnit          string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
454
+	MaxUnit          string  `json:"max_unit"`
455
+	MinNumber        int64   `json:"min_number"`
456
+	Dose             float64 `json:"dose"`
457
+	DoseUnit         string  `json:"dose_unit"`
454 458
 }
455 459
 
456 460
 type BloodDrugCancelStockInfo struct {
@@ -536,6 +540,10 @@ type BloodDrugWarehouseOutInfo struct {
536 540
 	DrugSpec                string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
537 541
 	Creater                 int64   `gorm:"column:creater" json:"creater" form:"creater"`
538 542
 	MinUnit                 string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
543
+	MaxUnit                 string  `json:"max_unit"`
544
+	MinNumber               int64   `json:"min_number"`
545
+	Dose                    float64 `json:"dose"`
546
+	DoseUnit                string  `json:"dose_unit"`
539 547
 }
540 548
 
541 549
 type XtMonitorConfig struct {
@@ -608,6 +616,7 @@ type VmDrugWarehouseOutInfo struct {
608 616
 	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
609 617
 	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
610 618
 	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
619
+	BuyPrice                float64 `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
611 620
 	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
612 621
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
613 622
 	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
@@ -633,4 +642,6 @@ type VmDrugWarehouseOutInfo struct {
633 642
 	DoseUnit                string  `json:"dose_unit"`
634 643
 	LastPrice               string  `json:"last_price"`
635 644
 	DrugName                string  `json:"drug_name"`
645
+	Number                  string  `json:"number"`
646
+	BatchNumber             string  `json:"batch_number"`
636 647
 }

+ 3 - 0
models/stock_models.go Visa fil

@@ -146,6 +146,7 @@ type VmWarehousingInfo struct {
146 146
 	WarehousingCount  int64       `gorm:"column:warehousing_count" json:"warehousing_count"`
147 147
 	WarehousingUnit   string      `gorm:"column:warehousing_unit" json:"warehousing_unit"`
148 148
 	Price             float64     `gorm:"column:price" json:"price"`
149
+	BuyPrice          float64     `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
149 150
 	TotalPrice        float64     `gorm:"column:total_price" json:"total_price"`
150 151
 	Dealer            int64       `gorm:"column:dealer" json:"dealer"`
151 152
 	Manufacturer      int64       `gorm:"column:manufacturer" json:"manufacturer"`
@@ -219,6 +220,7 @@ type WarehouseOutInfo struct {
219 220
 	SysRecordTime           int64        `gorm:"column:sys_record_time" json:"sys_record_time"`
220 221
 	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
221 222
 	Number                  string       `gorm:"column:number" json:"number" form:"number"`
223
+	LicenseNumber           string       `gorm:"column:license_number" json:"license_number" form:"license_number"`
222 224
 }
223 225
 
224 226
 func (WarehouseOutInfo) TableName() string {
@@ -428,6 +430,7 @@ type WarehouseOutInfoOne struct {
428 430
 	MinUnit                 string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
429 431
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
430 432
 	PackingUnit             string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
433
+	LicenseNumber           string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
431 434
 }
432 435
 
433 436
 type WarehouseOutInfoTwo struct {

+ 11 - 7
service/gobal_config_service.go Visa fil

@@ -261,9 +261,9 @@ func GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType
261 261
 	}
262 262
 
263 263
 	if manufacturerId > 0 {
264
-		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,s.creater").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&drugInfo).Error
264
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_number,s.creater").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Where("t.manufacturer = ?", manufacturerId).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&drugInfo).Error
265 265
 	} else {
266
-		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,s.creater").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&drugInfo).Error
266
+		err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.total_price,x.dealer,t.manufacturer,x.remark,x.ctime,x.org_id,x.is_return,x.warehousing_order,x.type,x.retail_price,x.retail_total_price,t.drug_type,t.drug_name,t.drug_spec,t.min_unit,t.dose,t.dose_unit,t.max_unit,t.min_number,s.creater").Joins("left join xt_base_drug as t on t.id = x.drug_id and t.org_id = ? and t.status =1", orgid).Joins("left join xt_drug_warehouse as s on s.id = x.warehousing_id and s.org_id = ? and s.status =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&drugInfo).Error
267 267
 	}
268 268
 
269 269
 	return drugInfo, total, err
@@ -331,9 +331,9 @@ func GetDrugOutOrder(startime int64, endtime int64, orgid int64, orderType int64
331 331
 	}
332 332
 
333 333
 	if manufacturerId > 0 {
334
-		err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,t.creater").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status  =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
334
+		err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,b.max_unit,b.min_number,b.dose,b.dose_unit,t.creater").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status  =1", orgid).Where("t.manufacturer = ?", manufacturerId).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
335 335
 	} else {
336
-		err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,t.creater").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status  =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
336
+		err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,b.drug_name,b.drug_spec,b.drug_type,b.min_unit,b.max_unit,b.min_number,b.dose,b.dose_unit,t.creater").Joins("left join xt_base_drug as b on b.id = x.drug_id and b.org_id = ? and b.status =1", orgid).Joins("left join xt_drug_warehouse_out as t on t.id = x.warehouse_out_id and t.org_id = ? and t.status  =1", orgid).Order("x.ctime desc").Count(&total).Offset(offset).Limit(limit).Scan(&outinfo).Error
337 337
 	}
338 338
 
339 339
 	return outinfo, total, err
@@ -540,6 +540,8 @@ func GetDrugStockList(page int64, limit int64, keyword string, drugcategory int6
540 540
 func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64) (list []*models.StDrugWarehouseInfo, total int64, err error) {
541 541
 
542 542
 	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
543
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status =1 ")
544
+	fmt.Println(table)
543 545
 	offset := (page - 1) * limit
544 546
 	if startime > 0 {
545 547
 		db = db.Where("x.ctime >=?", startime)
@@ -560,9 +562,11 @@ func GetDrugStockFlow(drugid int64, startime int64, endtime int64, page int64, l
560 562
 	return list, total, err
561 563
 }
562 564
 
563
-func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64, stocktype int64) (list []*models.XtDrugWarehouseOutInfo, total int64, err error) {
565
+func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64, limit int64, orgid int64, stocktype int64) (list []*models.VmDrugWarehouseOutInfo, total int64, err error) {
564 566
 
565 567
 	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
568
+	table := XTReadDB().Table("xt_base_drug as t").Where("t.status = 1")
569
+	fmt.Println(table)
566 570
 	offset := (page - 1) * limit
567 571
 	if startime > 0 {
568 572
 		db = db.Where("x.ctime >=?", startime)
@@ -584,7 +588,7 @@ func GetDrugStockOutFlow(drugid int64, startime int64, endtime int64, page int64
584 588
 	if stocktype == 2 {
585 589
 		db = db.Where("x.is_sys = 1")
586 590
 	}
587
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
591
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.org_id,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,x.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,x.warehouse_info_id,x.ctime,t.drug_name,t.drug_type,t.min_number,t.min_unit,t.max_unit").Joins("left join xt_base_drug as t on t.id = x.drug_id").Count(&total).Offset(offset).Limit(limit).Order("x.ctime desc").Scan(&list).Error
588 592
 	return list, total, err
589 593
 }
590 594
 
@@ -672,7 +676,7 @@ func GetSingleOrderDetail(id int64, orgid int64) (info []*models.VmDrugWarehouse
672 676
 		db = db.Where("x.warehouse_out_id = ?", id)
673 677
 	}
674 678
 
675
-	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
679
+	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.remark,x.is_cancel,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.retail_price,x.retail_total_price,t.drug_name,t.drug_type,t.max_unit,t.min_unit,t.min_number,x.number,x.batch_number,t.dose,t.dose_unit,t.last_price").Joins("left join xt_base_drug as t on t.id = x.drug_id").Group("x.drug_id").Scan(&info).Error
676 680
 	return info, err
677 681
 }
678 682
 

+ 212 - 12
service/stock_service.go Visa fil

@@ -418,11 +418,11 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
418 418
 	if len(warehousingInfo) > 0 {
419 419
 		utx := writeDb.Begin()
420 420
 		if len(warehousingInfo) > 0 {
421
-			thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit) VALUES "
421
+			thisSQL := "INSERT INTO xt_drug_warehouse_info (warehousing_id, drug_id, number, product_date,expiry_date,warehousing_count,price,total_price,dealer,manufacturer,remark,ctime,mtime,status,org_id,warehousing_order,type,retail_price,retail_total_price,stock_max_number,max_unit,min_unit,batch_number) VALUES "
422 422
 			insertParams := make([]string, 0)
423 423
 			insertData := make([]interface{}, 0)
424 424
 			for _, info := range warehousingInfo {
425
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
425
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
426 426
 				insertData = append(insertData, info.WarehousingId)
427 427
 				insertData = append(insertData, info.DrugId)
428 428
 				insertData = append(insertData, info.Number)
@@ -445,6 +445,7 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
445 445
 				insertData = append(insertData, info.StockMaxNumber)
446 446
 				insertData = append(insertData, info.MaxUnit)
447 447
 				insertData = append(insertData, info.MinUnit)
448
+				insertData = append(insertData, info.BatchNumber)
448 449
 			}
449 450
 			thisSQL += strings.Join(insertParams, ", ")
450 451
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -694,6 +695,28 @@ func FindAllDrugWarehousingList(orgId int64, page int64, limit int64, startTime
694 695
 	return
695 696
 }
696 697
 
698
+func FindAllDrugWarehousingListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*VMDrugWarehouse, total int64, err error) {
699
+	db := readDb.Model(&VMDrugWarehouse{})
700
+	db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
701
+	db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
702
+	db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
703
+	if len(keywords) > 0 {
704
+		likeKey := "%" + keywords + "%"
705
+		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
706
+		db = db.Where(" sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse.warehousing_order LIKE ?  OR xt_drug_warehouse.id in(?)", likeKey, likeKey, ids).Group("xt_drug_warehouse.id")
707
+	}
708
+	if startTime > 0 {
709
+		db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
710
+	}
711
+	if endTime > 0 {
712
+		db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
713
+	}
714
+	db = db.Count(&total)
715
+	offset := (page - 1) * limit
716
+	err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
717
+	return
718
+}
719
+
697 720
 func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
698 721
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
699 722
 	return list, err
@@ -917,7 +940,7 @@ func FindReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
917 940
 }
918 941
 
919 942
 func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err error) {
920
-	err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
943
+	err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Preload("GoodInfo", "status = 1").Find(&list).Error
921 944
 	return list, err
922 945
 }
923 946
 
@@ -998,11 +1021,11 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
998 1021
 	if len(warehouseOutInfo) > 0 {
999 1022
 		utx := writeDb.Begin()
1000 1023
 		if len(warehouseOutInfo) > 0 {
1001
-			thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,number) VALUES "
1024
+			thisSQL := "INSERT INTO xt_warehouse_out_info (warehouse_out_id, good_id, good_type_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,number,license_number) VALUES "
1002 1025
 			insertParams := make([]string, 0)
1003 1026
 			insertData := make([]interface{}, 0)
1004 1027
 			for _, info := range warehouseOutInfo {
1005
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1028
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1006 1029
 				insertData = append(insertData, info.WarehouseOutId)
1007 1030
 				insertData = append(insertData, info.GoodId)
1008 1031
 				insertData = append(insertData, info.GoodTypeId)
@@ -1020,6 +1043,7 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
1020 1043
 				insertData = append(insertData, info.Dealer)
1021 1044
 				insertData = append(insertData, info.Manufacturer)
1022 1045
 				insertData = append(insertData, info.Number)
1046
+				insertData = append(insertData, info.LicenseNumber)
1023 1047
 			}
1024 1048
 			thisSQL += strings.Join(insertParams, ", ")
1025 1049
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1038,11 +1062,11 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
1038 1062
 	if len(warehouseOutInfo) > 0 {
1039 1063
 		utx := writeDb.Begin()
1040 1064
 		if len(warehouseOutInfo) > 0 {
1041
-			thisSQL := "INSERT INTO xt_drug_warehouse_out_info (warehouse_out_id, drug_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
1065
+			thisSQL := "INSERT INTO xt_drug_warehouse_out_info (warehouse_out_id, drug_id, product_date,expiry_date,count,price,total_price,remark,ctime,status,org_id,warehouse_out_order_number,type,dealer,manufacturer,retail_price,retail_total_price,number,batch_number) VALUES "
1042 1066
 			insertParams := make([]string, 0)
1043 1067
 			insertData := make([]interface{}, 0)
1044 1068
 			for _, info := range warehouseOutInfo {
1045
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1069
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1046 1070
 				insertData = append(insertData, info.WarehouseOutId)
1047 1071
 				insertData = append(insertData, info.DrugId)
1048 1072
 				insertData = append(insertData, info.ProductDate)
@@ -1060,7 +1084,8 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
1060 1084
 				insertData = append(insertData, info.Manufacturer)
1061 1085
 				insertData = append(insertData, info.RetailPrice)
1062 1086
 				insertData = append(insertData, info.RetailTotalPrice)
1063
-
1087
+				insertData = append(insertData, info.Number)
1088
+				insertData = append(insertData, info.BatchNumber)
1064 1089
 			}
1065 1090
 			thisSQL += strings.Join(insertParams, ", ")
1066 1091
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1161,6 +1186,30 @@ func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime
1161 1186
 
1162 1187
 }
1163 1188
 
1189
+func FindAllDrugWarehouseOutListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*models.DrugWarehouseOut, total int64, err error) {
1190
+	db := readDb.Model(&models.DrugWarehouseOut{})
1191
+	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
1192
+
1193
+	if len(keywords) > 0 {
1194
+		likeKey := "%" + keywords + "%"
1195
+		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
1196
+
1197
+		db = db.Where("sgj_user_admin_role.user_name LIKE ? OR xt_drug_warehouse_out.warehouse_out_order_number LIKE ? or xt_drug_warehouse_out.id in(?) ", likeKey, likeKey, ids).Group("xt_drug_warehouse_out.id")
1198
+	}
1199
+
1200
+	if startTime > 0 {
1201
+		db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
1202
+	}
1203
+	if endTime > 0 {
1204
+		db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
1205
+	}
1206
+	db = db.Count(&total)
1207
+	offset := (page - 1) * limit
1208
+	err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
1209
+	return list, total, err
1210
+
1211
+}
1212
+
1164 1213
 func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
1165 1214
 	err = readDb.Model(&models.WarehouseOutInfo{}).Where("warehouse_out_id = ? AND status = 1 AND count <> 0 AND good_id <> 0", id).Preload("GoodInfo", "status = 1").Order("good_type_id desc").Find(&list).Error
1166 1215
 	return list, err
@@ -1190,6 +1239,8 @@ type DrugWarehouseOutInfo struct {
1190 1239
 	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
1191 1240
 	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1192 1241
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
1242
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
1243
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1193 1244
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1194 1245
 }
1195 1246
 
@@ -1909,7 +1960,7 @@ func EditDrugCancelStock(sales models.DrugCancelStock) {
1909 1960
 }
1910 1961
 
1911 1962
 func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock, err error) {
1912
-	err = readDb.Model(&models.CancelStock{}).Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Where("id = ? AND status = 1", id).First(&cancelStock).Error
1963
+	err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
1913 1964
 	return cancelStock, err
1914 1965
 
1915 1966
 }
@@ -2350,6 +2401,7 @@ type DrugAutomaticReduceDetail struct {
2350 2401
 	OrgId                   int64            `gorm:"column:org_id" json:"org_id" form:"org_id"`
2351 2402
 	DrugId                  int64            `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
2352 2403
 	Count                   int64            `gorm:"column:count" json:"count" form:"count"`
2404
+	CountUnit               string           `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
2353 2405
 	Drug                    *Drug            `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
2354 2406
 	Patients                *models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
2355 2407
 }
@@ -2930,7 +2982,7 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
2930 2982
 	if good_id > 0 {
2931 2983
 		db = db.Where("x.good_id = ?", good_id)
2932 2984
 	}
2933
-	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,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
2985
+	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,t.manufacturer,x.remark,x.ctime,x.is_return,x.warehousing_order,x.type,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.min_unit,t.buy_price").Joins("left join xt_good_information as t on t.id = x.good_id").Count(&total).Offset(offset).Limit(limit).Scan(&info).Error
2934 2986
 	return info, total, err
2935 2987
 
2936 2988
 }
@@ -2939,6 +2991,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
2939 2991
 	offset := (page - 1) * limit
2940 2992
 
2941 2993
 	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
2994
+
2942 2995
 	if startime > 0 {
2943 2996
 		db = db.Where("x.ctime>=?", startime)
2944 2997
 	}
@@ -3024,7 +3077,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
3024 3077
 	if orgid > 0 {
3025 3078
 		db = db.Where("x.org_id = ?", orgid)
3026 3079
 	}
3027
-	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3080
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3028 3081
 	return out, err
3029 3082
 }
3030 3083
 
@@ -3052,7 +3105,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
3052 3105
 	if orgid > 0 {
3053 3106
 		db = db.Where("x.org_id = ?", orgid)
3054 3107
 	}
3055
-	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3108
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.warehouse_out_order_number,x.type,x.dealer,t.manufacturer,x.is_sys,x.sys_record_time,x.number,x.remark,x.license_number,t.good_name,t.good_type_id,t.specification_name,t.min_number,t.packing_unit,t.min_unit").Joins("left join xt_good_information as t on t.id=x.good_id").Group("x.good_id").Order("x.ctime desc").Scan(&out).Error
3056 3109
 	return out, err
3057 3110
 }
3058 3111
 
@@ -3170,3 +3223,150 @@ func FindeDrugWarehouseOutDetail(ids []string, orgid int64) (info []*models.VmDr
3170 3223
 	err = db.Select("x.id,x.warehouse_out_id,x.drug_id,x.warehousing_out_target,x.count,x.count_unit,x.price,x.product_date,x.expiry_date,x.number,x.batch_number,t.drug_type,t.max_unit,t.min_unit,t.min_number,t.dose,t.dose_unit,t.last_price,t.drug_name").Joins("left join xt_base_drug as t on t.id =x.drug_id").Scan(&info).Error
3171 3224
 	return info, err
3172 3225
 }
3226
+
3227
+func GetDrugNameByKeyword(keyword string, orgid int64) (basedrug []*models.XtBaseDrug, err error) {
3228
+
3229
+	db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
3230
+	likeKey := "%" + keyword + "%"
3231
+	if len(keyword) > 0 {
3232
+		db = db.Where("x.drug_name like ?", likeKey)
3233
+	}
3234
+	if orgid > 0 {
3235
+		db = db.Where("x.org_id = ?", orgid)
3236
+	}
3237
+	err = db.Find(&basedrug).Error
3238
+
3239
+	return basedrug, err
3240
+
3241
+}
3242
+
3243
+func GetDrugWarehouseOrderDetail(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
3244
+
3245
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
3246
+
3247
+	if len(ids) > 0 {
3248
+		db = db.Where("x.drug_id in(?)", ids)
3249
+	}
3250
+
3251
+	if orgid > 0 {
3252
+		db = db.Where("x.org_id = ?", orgid)
3253
+	}
3254
+	if startime > 0 {
3255
+		db = db.Where("x.ctime>=?", startime)
3256
+	}
3257
+	if endtime > 0 {
3258
+		db = db.Where("x.ctime<=?", endtime)
3259
+	}
3260
+
3261
+	err = db.Find(&info).Error
3262
+	return info, err
3263
+}
3264
+
3265
+func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseInfo, err error) {
3266
+
3267
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3268
+
3269
+	if len(ids) > 0 {
3270
+		db = db.Where("x.drug_id in(?)", ids)
3271
+	}
3272
+
3273
+	if orgid > 0 {
3274
+		db = db.Where("x.org_id = ?", orgid)
3275
+	}
3276
+	if startime > 0 {
3277
+		db = db.Where("x.ctime>=?", startime)
3278
+	}
3279
+	if endtime > 0 {
3280
+		db = db.Where("x.ctime<=?", endtime)
3281
+	}
3282
+
3283
+	err = db.Find(&info).Error
3284
+	return info, err
3285
+}
3286
+
3287
+func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
3288
+
3289
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3290
+	if drugid > 0 {
3291
+		db = db.Where("x.drug_id = ?", drugid)
3292
+	}
3293
+	if orgid > 0 {
3294
+		db = db.Where("x.org_id = ?", orgid)
3295
+	}
3296
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as count").Find(&info).Error
3297
+	return info, err
3298
+}
3299
+
3300
+func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3301
+
3302
+	lib := models.BaseDrugLib{}
3303
+	err := XTReadDB().Model(&lib).Where("id = ? and status = 1", drugid).Find(&lib).Error
3304
+	return lib, err
3305
+}
3306
+
3307
+func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3308
+
3309
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
3310
+
3311
+	if goodid > 0 {
3312
+		db = db.Where("x.good_id = ?", goodid)
3313
+	}
3314
+
3315
+	if orgid > 0 {
3316
+		db = db.Where("x.org_id = ?", orgid)
3317
+	}
3318
+
3319
+	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.price,x.total_price,x.dealer,x.manufacturer,x.remark,x.is_return,x.warehousing_order,x.warehousing_unit,x.stock_count,x.license_number").Order("x.ctime desc").Find(&info).Error
3320
+	return info, err
3321
+}
3322
+
3323
+func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
3324
+
3325
+	err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_cout": info.StockCount}).Error
3326
+	return err
3327
+}
3328
+
3329
+func GetSingleCancelOrder(id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
3330
+
3331
+	err = XTReadDB().Where("cancel_stock_id = ? and status = 1 and org_id = ?", id, orgid).Preload("GoodInfo", "status = 1").Find(&info).Error
3332
+	return info, err
3333
+}
3334
+
3335
+func UpdateCancelOut(list []*models.WarehousingInfo, count int64) {
3336
+
3337
+	//遍历循环入库数据
3338
+	for _, item := range list {
3339
+
3340
+		//计算每个批次剩余库存与入库数据的差 然后和退库数量比较
3341
+		if (item.WarehousingCount - item.StockCount) >= count {
3342
+			//如果差距大于退库数量,则直接把退库数量增加到该批次中
3343
+			info := models.WarehousingInfo{
3344
+				GoodId:        item.GoodId,
3345
+				OrgId:         item.OrgId,
3346
+				WarehousingId: item.WarehousingId,
3347
+				StockCount:    count,
3348
+			}
3349
+			UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
3350
+			break
3351
+		}
3352
+
3353
+		if (item.WarehousingCount - item.StockCount) < count {
3354
+
3355
+			//如果该批次小于退库数量,则先出库该相差数量
3356
+			var countOne = item.WarehousingCount - item.StockCount
3357
+			infoOne := models.WarehousingInfo{
3358
+				GoodId:        item.GoodId,
3359
+				OrgId:         item.OrgId,
3360
+				WarehousingId: item.WarehousingId,
3361
+				StockCount:    countOne,
3362
+			}
3363
+
3364
+			UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
3365
+
3366
+			//剩余的出库到第二个批次
3367
+			var countTwo = count - countOne
3368
+			UpdateCancelOut(list, countTwo)
3369
+		}
3370
+	}
3371
+
3372
+}

+ 48 - 8
service/warhouse_service.go Visa fil

@@ -2,7 +2,6 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
-	"XT_New/models/service"
6 5
 	"XT_New/utils"
7 6
 	"errors"
8 7
 	"fmt"
@@ -748,7 +747,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
748 747
 	// 如果没有对应的库存,则报错
749 748
 
750 749
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
751
-	fmt.Println("库存数量", warehouse.StockCount)
750
+	fmt.Println("库存数量9999343434343434343434343434343434", warehouse.StockCount)
752 751
 	if err != nil {
753 752
 		return
754 753
 	}
@@ -829,6 +828,39 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
829 828
 
830 829
 		return nil
831 830
 	} else {
831
+		fmt.Println("中国共产党万岁22322332323232322323232323232323")
832
+		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
833
+		//warehouseOutInfo := &models.WarehouseOutInfo{
834
+		//  WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
835
+		//  WarehouseOutId:          warehouseOut.ID,
836
+		//  WarehouseInfotId:        warehouse.ID,
837
+		//  Status:                  1,
838
+		//  Ctime:                   time.Now().Unix(),
839
+		//  Remark:                  goods.Remark,
840
+		//  OrgId:                   orgID,
841
+		//  Type:                    1,
842
+		//  Manufacturer:            goods.Manufacturer,
843
+		//  Dealer:                  goods.Dealer,
844
+		//  IsSys:                   0,
845
+		//  SysRecordTime:           record_time,
846
+		//  GoodTypeId:              goods.GoodTypeId,
847
+		//  GoodId:                  goods.GoodId,
848
+		//  ExpiryDate:              goods.ExpiryDate,
849
+		//  ProductDate:             goods.ProductDate,
850
+		//  Number:                  goods.Number,
851
+		//  Price:                   goods.Price,
852
+		//  LicenseNumber:           goods.LicenseNumber,
853
+		//}
854
+		//warehouseOutInfo.Count = stock_number
855
+		//stockInInfo, _ :=FindLastStockInInfoRecord(goods.GoodId, orgID)
856
+		//fmt.Println("stockINFO2232232323223322332323223323223",stockInInfo)
857
+		//warehouseOutInfo.Price = stockInInfo.Price
858
+		//
859
+		//errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
860
+		//fmt.Println("errOne2232323232323232333232323",errOne)
861
+		//if errOne != nil {
862
+		//  return errOne
863
+		//}
832 864
 		// 出库完成后,要将该批次库存清零
833 865
 		warehouse.StockCount = 0
834 866
 		warehouse.Mtime = time.Now().Unix()
@@ -1117,6 +1149,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1117 1149
 			ProductDate:             goods.ProductDate,
1118 1150
 			Number:                  goods.Number,
1119 1151
 			Price:                   goods.Price,
1152
+			LicenseNumber:           goods.LicenseNumber,
1120 1153
 		}
1121 1154
 		warehouseOutInfo.Count = goods.Count
1122 1155
 		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
@@ -1135,12 +1168,17 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1135 1168
 
1136 1169
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1137 1170
 		warehouse.Mtime = time.Now().Unix()
1171
+
1138 1172
 		if warehouse.StockCount < 0 {
1139
-			fmt.Println("进来33232323232232323233232", warehouse.StockCount)
1173
+
1140 1174
 			return errors.New("库存数量不足")
1141 1175
 		}
1142
-		return nil
1176
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
1177
+		if errThree != nil {
1178
+			return errThree
1179
+		}
1143 1180
 	} else {
1181
+		fmt.Println("中国共产党万岁22322332323232322323232323232323")
1144 1182
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1145 1183
 		warehouseOutInfo := &models.WarehouseOutInfo{
1146 1184
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1161,13 +1199,15 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1161 1199
 			ProductDate:             goods.ProductDate,
1162 1200
 			Number:                  goods.Number,
1163 1201
 			Price:                   goods.Price,
1202
+			LicenseNumber:           goods.LicenseNumber,
1164 1203
 		}
1165 1204
 		warehouseOutInfo.Count = stock_number
1166
-		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1205
+		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1206
+		fmt.Println("stockINFO2232232323223322332323223323223", stockInInfo)
1167 1207
 		warehouseOutInfo.Price = stockInInfo.Price
1168 1208
 
1169
-		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1170
-
1209
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1210
+		fmt.Println("errOne2232323232323232333232323", errOne)
1171 1211
 		if errOne != nil {
1172 1212
 			return errOne
1173 1213
 		}
@@ -1180,7 +1220,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1180 1220
 		}
1181 1221
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1182 1222
 		goods.Count = deliver_number - stock_number
1183
-
1223
+		fmt.Println("goods3333333333333333333333", goods.Count)
1184 1224
 		ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1185 1225
 
1186 1226
 	}