ソースを参照

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

csx 3 年 前
コミット
5c912280ab

+ 1 - 1
conf/app.conf ファイルの表示

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

+ 204 - 104
controllers/drug_stock_api_contorller.go ファイルの表示

@@ -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 {
@@ -1199,19 +1179,54 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1199 1179
 				}
1200 1180
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1201 1181
 
1202
-				if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
1203
-					utils.ErrorLog("last_price")
1204
-					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1205
-					return
1206
-				}
1207
-				last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
1208
-
1182
+				//if items["last_price"] == nil || reflect.TypeOf(items["last_price"]).String() != "string" {
1183
+				//	utils.ErrorLog("last_price")
1184
+				//	c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1185
+				//	return
1186
+				//}
1187
+				//last_price, _ := strconv.ParseFloat(items["last_price"].(string), 64)
1188
+				//fmt.Println(last_price)
1209 1189
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1210 1190
 
1211 1191
 				total := float64(count) * price
1212
-				retail_price_total := float64(count) * last_price
1192
+				retail_price_total := float64(count) * price
1213 1193
 				remark := items["remark"].(string)
1214 1194
 				max_unit := items["max_unit"].(string)
1195
+				dealer := int64(items["dealer"].(float64))
1196
+				fmt.Println("dealer2222222222222222222", dealer)
1197
+				manufacturer := int64(items["manufacturer"].(float64))
1198
+				fmt.Println("manufacturer22222222222222", manufacturer)
1199
+				number := items["number"].(string)
1200
+				batch_number := items["batch_number"].(string)
1201
+				var productDates int64
1202
+				var expiryDates int64
1203
+				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
1204
+					expiryDates = 0
1205
+				} else {
1206
+					if len(items["expiry_date"].(string)) == 0 {
1207
+						expiryDates = 0
1208
+
1209
+					} else {
1210
+						expiryDate, _ := items["expiry_date"].(string)
1211
+						expiry_date, _ := utils.ParseTimeStringToTime("2006-01-02", expiryDate)
1212
+						expiryDates = expiry_date.Unix()
1213
+
1214
+					}
1215
+
1216
+				}
1217
+				if items["product_date"] == nil || reflect.TypeOf(items["product_date"]).String() != "string" {
1218
+					productDates = 0
1219
+				} else {
1220
+					if len(items["product_date"].(string)) == 0 {
1221
+						productDates = 0
1222
+
1223
+					} else {
1224
+						productDate, _ := items["product_date"].(string)
1225
+						product_date, _ := utils.ParseTimeStringToTime("2006-01-02", productDate)
1226
+						productDates = product_date.Unix()
1227
+					}
1228
+
1229
+				}
1215 1230
 
1216 1231
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
1217 1232
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1225,11 +1240,16 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1225 1240
 					Remark:                  remark,
1226 1241
 					OrgId:                   adminUserInfo.CurrentOrgId,
1227 1242
 					Type:                    types,
1228
-					Manufacturer:            manufacturer_id,
1229
-					Dealer:                  dealer_id,
1230
-					RetailPrice:             last_price,
1243
+					Manufacturer:            manufacturer,
1244
+					Dealer:                  dealer,
1245
+					RetailPrice:             price,
1231 1246
 					RetailTotalPrice:        retail_price_total,
1232 1247
 					CountUnit:               max_unit,
1248
+					ExpiryDate:              expiryDates,
1249
+					ProductDate:             productDates,
1250
+					Number:                  number,
1251
+					BatchNumber:             batch_number,
1252
+					IsSys:                   0,
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)
@@ -1431,7 +1488,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1431 1488
 					return
1432 1489
 				}
1433 1490
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1434
-
1491
+				fmt.Println("price23223232323232323232323232322322", price)
1435 1492
 				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1436 1493
 					utils.ErrorLog("retail_price")
1437 1494
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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 ファイルの表示

@@ -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",

+ 87 - 30
controllers/stock_in_api_controller.go ファイルの表示

@@ -91,6 +91,8 @@ 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")
95
+	beego.Router("/api/stock/getcancelstockorderprint", &StockManagerApiController{}, "Get:GetCancelStockOrderPrint")
94 96
 
95 97
 }
96 98
 
@@ -562,8 +564,6 @@ func (c *StockManagerApiController) EditWarehouse() {
562 564
 				var productDates int64
563 565
 				var expiryDates int64
564 566
 
565
-				fmt.Println()
566
-
567 567
 				if items["expiry_date"] == nil || reflect.TypeOf(items["expiry_date"]).String() != "string" {
568 568
 					expiryDates = 0
569 569
 				} else {
@@ -1087,7 +1087,6 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1087 1087
 	operation_time := time.Now().Unix()
1088 1088
 	creater := adminUserInfo.AdminUser.Id
1089 1089
 
1090
-	_, errcode := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1091 1090
 	warehouseOut := models.WarehouseOut{
1092 1091
 		WarehouseOutOrderNumber: warehousing_out_order,
1093 1092
 		OperationTime:           operation_time,
@@ -1098,9 +1097,6 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1098 1097
 		WarehouseOutTime:        warehousingOutDate.Unix(),
1099 1098
 		Type:                    types,
1100 1099
 	}
1101
-	if errcode == gorm.ErrRecordNotFound {
1102
-		service.AddSigleWarehouseOut(&warehouseOut)
1103
-	}
1104 1100
 
1105 1101
 	dataBody := make(map[string]interface{}, 0)
1106 1102
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -1146,7 +1142,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1146 1142
 					return
1147 1143
 				}
1148 1144
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1149
-
1145
+				fmt.Println("999999992932323232323223232322323", price)
1150 1146
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1151 1147
 
1152 1148
 				total := float64(count) * price
@@ -1182,7 +1178,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1182 1178
 					}
1183 1179
 					productDate = theTime.Unix()
1184 1180
 				}
1185
-
1181
+				license_number := items["license_number"].(string)
1186 1182
 				warehouseOutInfo := &models.WarehouseOutInfo{
1187 1183
 					WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1188 1184
 					WarehouseOutId:          warehouseOut.ID,
@@ -1201,6 +1197,7 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1201 1197
 					ExpiryDate:              expiryDate,
1202 1198
 					ProductDate:             productDate,
1203 1199
 					Dealer:                  dealer,
1200
+					LicenseNumber:           license_number,
1204 1201
 				}
1205 1202
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1206 1203
 
@@ -1225,9 +1222,9 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1225 1222
 	//出库逻辑
1226 1223
 	for _, item := range warehousingOutInfo {
1227 1224
 		//查询库存
1228
-		warehouse, err := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1225
+		warehouse, _ := service.FindFirstWarehousingInfoByStockTwo(item.GoodId, item.GoodTypeId)
1229 1226
 		fmt.Println("库存数量组吗", warehouse.Count)
1230
-		if err != nil {
1227
+		if item.Count > warehouse.Count {
1231 1228
 			goodObj, _ := service.GetGoodInformationByGoodId(item.GoodId)
1232 1229
 			c.ServeSuccessJSON(map[string]interface{}{
1233 1230
 				"msg":                "1",
@@ -1236,8 +1233,12 @@ func (c *StockManagerApiController) CreateWarehouseOut() {
1236 1233
 			})
1237 1234
 			return
1238 1235
 		} else {
1236
+			fmt.Println("jiage223444444444444444444", item.Price)
1237
+			_, errcodes := service.FindStockOutByIsSys(adminUserInfo.CurrentOrgId, 0, operation_time)
1238
+			if errcodes == gorm.ErrRecordNotFound {
1239
+				service.AddSigleWarehouseOut(&warehouseOut)
1240
+			}
1239 1241
 			parseDateErr := service.ConsumablesDeliveryOne(adminUserInfo.CurrentOrgId, warehousingOutDate.Unix(), item, &warehouseOut, item.Count)
1240
-			fmt.Println(parseDateErr)
1241 1242
 			if parseDateErr != nil {
1242 1243
 				utils.ErrorLog(parseDateErr.Error())
1243 1244
 				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
@@ -1461,6 +1462,8 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1461 1462
 
1462 1463
 				number := items["number"].(string)
1463 1464
 
1465
+				license_number := items["license_number"].(string)
1466
+				fmt.Println("hhh23h2h32h3h232h3h23h2h3h23h2h3h23h2h3", license_number)
1464 1467
 				timeLayout := "2006-01-02"
1465 1468
 				loc, _ := time.LoadLocation("Local")
1466 1469
 				expiry_date := items["expiry_date"].(string)
@@ -1507,6 +1510,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1507 1510
 						ProductDate:             productDate,
1508 1511
 						Dealer:                  dealer,
1509 1512
 						Manufacturer:            manufacturer,
1513
+						LicenseNumber:           license_number,
1510 1514
 					}
1511 1515
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1512 1516
 
@@ -1547,6 +1551,7 @@ func (c *StockManagerApiController) EditWarehouseOut() {
1547 1551
 						ExpiryDate:              expiryDate,
1548 1552
 						ProductDate:             productDate,
1549 1553
 						Dealer:                  dealer,
1554
+						LicenseNumber:           license_number,
1550 1555
 					}
1551 1556
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1552 1557
 				}
@@ -1672,6 +1677,17 @@ func (c *StockManagerApiController) CreateCancelStock() {
1672 1677
 		}
1673 1678
 	}
1674 1679
 	errs := service.CreateCancelStockInfo(cancelStockInfos)
1680
+
1681
+	// 改变入库单的值
1682
+	for _, item := range cancelStockInfos {
1683
+		fmt.Println("经理俄2433444 我认为侮辱侮辱侮辱侮辱侮辱侮辱我无污染武荣", item.GoodId, item.OrgId)
1684
+		//查询该耗材的入库记录
1685
+		list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1686
+		//调用退库的方法
1687
+		parseDateErr := service.UpdateCancelOut(list, item.Count)
1688
+		fmt.Println("999999999999", parseDateErr)
1689
+	}
1690
+
1675 1691
 	if errs != nil {
1676 1692
 		utils.ErrorLog(errs.Error())
1677 1693
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCancelStockFail)
@@ -1776,9 +1792,6 @@ func (this *StockManagerApiController) DeleteCancelStockInfo() {
1776 1792
 func (c *StockManagerApiController) EditCancelStock() {
1777 1793
 	cancel_time := c.GetString("cancel_time")
1778 1794
 	id, _ := c.GetInt64("id", 0)
1779
-	types, _ := c.GetInt64("type", 0)
1780
-	manufacturer_id, _ := c.GetInt64("manufacturer_id", 0)
1781
-	dealer_id, _ := c.GetInt64("dealer_id", 0)
1782 1795
 
1783 1796
 	if id == 0 {
1784 1797
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1799,11 +1812,9 @@ func (c *StockManagerApiController) EditCancelStock() {
1799 1812
 	cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
1800 1813
 
1801 1814
 	tempCancelStock := models.CancelStock{
1802
-		ID:           cancelStock.ID,
1803
-		Mtime:        mtime,
1804
-		ReturnTime:   cancelDate.Unix(),
1805
-		Manufacturer: manufacturer_id,
1806
-		Dealer:       dealer_id,
1815
+		ID:         cancelStock.ID,
1816
+		Mtime:      mtime,
1817
+		ReturnTime: cancelDate.Unix(),
1807 1818
 	}
1808 1819
 
1809 1820
 	service.EditCancelStock(tempCancelStock)
@@ -1865,9 +1876,6 @@ func (c *StockManagerApiController) EditCancelStock() {
1865 1876
 						OrderNumber:   cancelStock.OrderNumber,
1866 1877
 						CancelStockId: cancelStock.ID,
1867 1878
 						Mtime:         time.Now().Unix(),
1868
-						Type:          types,
1869
-						Manufacturer:  manufacturer_id,
1870
-						Dealer:        dealer_id,
1871 1879
 					}
1872 1880
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1873 1881
 
@@ -1883,9 +1891,6 @@ func (c *StockManagerApiController) EditCancelStock() {
1883 1891
 						OrderNumber:   cancelStock.OrderNumber,
1884 1892
 						CancelStockId: cancelStock.ID,
1885 1893
 						Mtime:         time.Now().Unix(),
1886
-						Type:          types,
1887
-						Manufacturer:  manufacturer_id,
1888
-						Dealer:        dealer_id,
1889 1894
 					}
1890 1895
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
1891 1896
 				}
@@ -1895,11 +1900,42 @@ func (c *StockManagerApiController) EditCancelStock() {
1895 1900
 	var errs error
1896 1901
 	if len(cancelStockInfos) > 0 {
1897 1902
 		errs = service.CreateCancelStockInfo(cancelStockInfos)
1903
+		// 改变入库单的值
1904
+		for _, item := range cancelStockInfos {
1905
+			//查询该耗材的入库记录
1906
+			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1907
+			//调用退库的方法
1908
+			parseDateErr := service.UpdateCancelOut(list, item.Count)
1909
+			if parseDateErr != nil {
1910
+				utils.ErrorLog(errs.Error())
1911
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1912
+				return
1913
+			}
1914
+
1915
+			c.ServeSuccessJSON(map[string]interface{}{
1916
+				"msg": "编辑成功",
1917
+			})
1918
+		}
1898 1919
 	}
1899 1920
 
1900 1921
 	if len(upDateCancelStockInfos) > 0 {
1901 1922
 		for _, item := range upDateCancelStockInfos {
1923
+
1902 1924
 			errs = service.UpDateCancelStockInfo(item)
1925
+			list, _ := service.GetWarehoureOrderInfoList(item.GoodId, item.OrgId)
1926
+			//调用退库的方法
1927
+			parseDateErr := service.UpdateCancelOut(list, item.Count)
1928
+			fmt.Println("999999999999", parseDateErr)
1929
+
1930
+			if parseDateErr != nil {
1931
+				utils.ErrorLog(errs.Error())
1932
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1933
+				return
1934
+			}
1935
+
1936
+			c.ServeSuccessJSON(map[string]interface{}{
1937
+				"msg": "编辑成功",
1938
+			})
1903 1939
 		}
1904 1940
 	}
1905 1941
 
@@ -3897,11 +3933,12 @@ func (this *StockManagerApiController) GetStockDrugCount() {
3897 3933
 	count, _ := service.GetStockDrugCount(startTime, endTime, orgId)
3898 3934
 	outList, _ := service.GetAutoDiallysisBefor(startTime, endTime, orgId)
3899 3935
 	autoCount, _ := service.GetOutStockTotalCountFour(startTime, endTime, orgId)
3900
-
3936
+	totalCount, _ := service.GetCancelOutTotalCount(startTime, endTime, orgId)
3901 3937
 	this.ServeSuccessJSON(map[string]interface{}{
3902
-		"count":     count,
3903
-		"outList":   outList,
3904
-		"autoCount": autoCount,
3938
+		"count":      count,
3939
+		"outList":    outList,
3940
+		"autoCount":  autoCount,
3941
+		"totalCount": totalCount,
3905 3942
 	})
3906 3943
 }
3907 3944
 
@@ -3982,7 +4019,7 @@ func (this *StockManagerApiController) GetExprotStockList() {
3982 4019
 		}
3983 4020
 		endTime = theTime.Unix()
3984 4021
 	}
3985
-
4022
+	fmt.Println("ids2222222222222222", ids)
3986 4023
 	list, _ := service.GetExprotStockList(orgId, ids, startTime, endTime)
3987 4024
 	this.ServeSuccessJSON(map[string]interface{}{
3988 4025
 		"list": list,
@@ -4026,3 +4063,23 @@ func (this *StockManagerApiController) GetOutExprotList() {
4026 4063
 		"count": outCount,
4027 4064
 	})
4028 4065
 }
4066
+
4067
+func (this *StockManagerApiController) GetSingleCancelOrder() {
4068
+
4069
+	id, _ := this.GetInt64("id")
4070
+	adminUserInfo := this.GetAdminUserInfo()
4071
+	orgId := adminUserInfo.CurrentOrgId
4072
+	order, _ := service.GetSingleCancelOrder(id, orgId)
4073
+	this.ServeSuccessJSON(map[string]interface{}{
4074
+		"list": order,
4075
+	})
4076
+}
4077
+
4078
+func (this *StockManagerApiController) GetCancelStockOrderPrint() {
4079
+	id := this.GetString("id")
4080
+	idStr := strings.Split(id, ",")
4081
+	list, _ := service.GetCancelStockOrderPrint(idStr)
4082
+	this.ServeSuccessJSON(map[string]interface{}{
4083
+		"list": list,
4084
+	})
4085
+}

+ 2 - 0
models/drug_stock.go ファイルの表示

@@ -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 {

+ 12 - 0
models/self_drug_models.go ファイルの表示

@@ -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 {
@@ -588,6 +596,7 @@ type StDrugWarehouseInfo struct {
588 596
 	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
589 597
 	StockMaxNumber   int64   `gorm:"column:stock_max_number" json:"stock_max_number"`
590 598
 	StockMinNumber   int64   `gorm:"column:stock_min_number" json:"stock_min_number"`
599
+	BatchNumber      string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
591 600
 	DrugName         string  `json:"drug_name"`
592 601
 	DrugType         int64   `json:"drug_type"`
593 602
 	MaxUnit          string  `json:"max_unit"`
@@ -608,6 +617,7 @@ type VmDrugWarehouseOutInfo struct {
608 617
 	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
609 618
 	CountUnit               string  `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
610 619
 	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
620
+	BuyPrice                float64 `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
611 621
 	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
612 622
 	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
613 623
 	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
@@ -633,4 +643,6 @@ type VmDrugWarehouseOutInfo struct {
633 643
 	DoseUnit                string  `json:"dose_unit"`
634 644
 	LastPrice               string  `json:"last_price"`
635 645
 	DrugName                string  `json:"drug_name"`
646
+	Number                  string  `json:"number"`
647
+	BatchNumber             string  `json:"batch_number"`
636 648
 }

+ 10 - 0
models/stock_models.go ファイルの表示

@@ -97,6 +97,7 @@ type StWarehousingInfo struct {
97 97
 	PackingUnit       string  `json:"packing_unit"`
98 98
 	TotalCount        int64   `json:"total_count"`
99 99
 	SpecificationName string  `json:"specification_name"`
100
+	LicenseNumber     string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
100 101
 }
101 102
 
102 103
 func (StWarehousingInfo) TableName() string {
@@ -146,6 +147,7 @@ type VmWarehousingInfo struct {
146 147
 	WarehousingCount  int64       `gorm:"column:warehousing_count" json:"warehousing_count"`
147 148
 	WarehousingUnit   string      `gorm:"column:warehousing_unit" json:"warehousing_unit"`
148 149
 	Price             float64     `gorm:"column:price" json:"price"`
150
+	BuyPrice          float64     `gorm:"column:buy_price" json:"buy_price" form:"buy_price"`
149 151
 	TotalPrice        float64     `gorm:"column:total_price" json:"total_price"`
150 152
 	Dealer            int64       `gorm:"column:dealer" json:"dealer"`
151 153
 	Manufacturer      int64       `gorm:"column:manufacturer" json:"manufacturer"`
@@ -219,6 +221,7 @@ type WarehouseOutInfo struct {
219 221
 	SysRecordTime           int64        `gorm:"column:sys_record_time" json:"sys_record_time"`
220 222
 	PatientId               int64        `gorm:"column:patient_id" json:"patient_id"`
221 223
 	Number                  string       `gorm:"column:number" json:"number" form:"number"`
224
+	LicenseNumber           string       `gorm:"column:license_number" json:"license_number" form:"license_number"`
222 225
 }
223 226
 
224 227
 func (WarehouseOutInfo) TableName() string {
@@ -271,6 +274,12 @@ func (SalesReturnInfo) TableName() string {
271 274
 	return "xt_sales_return_info"
272 275
 }
273 276
 
277
+type VmCancelStockInfo struct {
278
+	GoodId int64 `gorm:"column:good_id" json:"good_id"`
279
+	Count  int64 `gorm:"column:count" json:"count"`
280
+	OrgId  int64 `gorm:"column:org_id" json:"org_id"`
281
+}
282
+
274 283
 type CancelStockInfo struct {
275 284
 	ID            int64       `gorm:"column:id" json:"id"`
276 285
 	GoodId        int64       `gorm:"column:good_id" json:"good_id"`
@@ -428,6 +437,7 @@ type WarehouseOutInfoOne struct {
428 437
 	MinUnit                 string  `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
429 438
 	Number                  string  `gorm:"column:number" json:"number" form:"number"`
430 439
 	PackingUnit             string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
440
+	LicenseNumber           string  `gorm:"column:license_number" json:"license_number" form:"license_number"`
431 441
 }
432 442
 
433 443
 type WarehouseOutInfoTwo struct {

+ 1 - 0
models/stock_query_models.go ファイルの表示

@@ -8,6 +8,7 @@ type StockInfo struct {
8 8
 	GoodTypeId            int64                   `gorm:"column:good_type_id" json:"good_type_id"`
9 9
 	GoodUnit              int64                   `gorm:"column:good_unit" json:"good_unit"`
10 10
 	MinUnit               string                  `gorm:"column:min_unit" json:"min_unit"`
11
+	PackingUnit           string                  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
11 12
 	QueryWarehousingInfo  []QueryWarehousingInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehousing_info"`
12 13
 	QuerySalesReturnInfo  []QuerySalesReturnInfo  `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_sales_return_info"`
13 14
 	QueryWarehouseOutInfo []QueryWarehouseOutInfo `gorm:"ForeignKey:GoodId;AssociationForeignKey:ID" json:"query_warehouseout_info"`

+ 13 - 9
service/gobal_config_service.go ファイルの表示

@@ -256,14 +256,14 @@ func GetDrugInOrderDetail(startime int64, endtime int64, orgid int64, orderType
256 256
 
257 257
 	if len(keyword) > 0 {
258 258
 
259
-		db = db.Where("x.warehousing_order like ? or t.drug_spec like ? or s.creater like ?", likeKey, likeKey, likeKey)
259
+		db = db.Where("x.warehousing_order like ? or t.drug_name like ? or s.creater like ?", likeKey, likeKey, likeKey)
260 260
 
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
@@ -327,13 +327,13 @@ func GetDrugOutOrder(startime int64, endtime int64, orgid int64, orderType int64
327 327
 	}
328 328
 
329 329
 	if len(keyword) > 0 {
330
-		db = db.Where("x.warehouse_out_order_number like ? or b.drug_spec like ? or t.creater like ?", likeKey, likeKey, likeKey)
330
+		db = db.Where("x.warehouse_out_order_number like ? or b.drug_name like ? or t.creater like ?", likeKey, likeKey, likeKey)
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
 

+ 256 - 15
service/stock_service.go ファイルの表示

@@ -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
@@ -740,6 +741,28 @@ func FindAllDrugWarehousingList(orgId int64, page int64, limit int64, startTime
740 741
 	return
741 742
 }
742 743
 
744
+func FindAllDrugWarehousingListOne(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string, ids []int64) (list []*VMDrugWarehouse, total int64, err error) {
745
+	db := readDb.Model(&VMDrugWarehouse{})
746
+	db = db.Where("xt_drug_warehouse.org_id = ? AND xt_drug_warehouse.status = 1", orgId)
747
+	db = db.Preload("Manufacturers", "status = 1 AND org_id = ?", orgId)
748
+	db = db.Preload("Dealers", "status = 1 AND org_id = ?", orgId)
749
+	if len(keywords) > 0 {
750
+		likeKey := "%" + keywords + "%"
751
+		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse.creater")
752
+		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")
753
+	}
754
+	if startTime > 0 {
755
+		db = db.Where("xt_drug_warehouse.operation_time >=?", startTime)
756
+	}
757
+	if endTime > 0 {
758
+		db = db.Where("xt_drug_warehouse.operation_time<= ?", endTime)
759
+	}
760
+	db = db.Count(&total)
761
+	offset := (page - 1) * limit
762
+	err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse.ctime desc").Find(&list).Error
763
+	return
764
+}
765
+
743 766
 func FindWarehousingInfoById(id int64) (list []*models.WarehousingInfo, err error) {
744 767
 	err = readDb.Model(&models.WarehousingInfo{}).Where("warehousing_id = ? AND status = 1", id).Preload("GoodInfo").Find(&list).Error
745 768
 	return list, err
@@ -766,7 +789,7 @@ func FindDrugWarehousingInfoByIdOne(id []string, org_id int64) (list []*models.S
766 789
 	if org_id > 0 {
767 790
 		db = db.Where("x.org_id = ?", org_id)
768 791
 	}
769
-	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.max_unit,x.min_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
792
+	err = db.Select("x.id,x.warehousing_id,x.drug_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.warehouseing_unit,x.stock_max_number,x.stock_min_number,x.price,x.remark,x.batch_number,x.batch_number,t.manufacturer,t.dealer,t.drug_name,t.last_price,t.dose_unit,t.dose,t.min_number,t.min_unit,t.max_unit,t.drug_type").Joins("left join xt_base_drug as t on t.id = x.drug_id").Scan(&list).Error
770 793
 	return list, err
771 794
 }
772 795
 
@@ -963,7 +986,7 @@ func FindReturnInfoById(id int64) (list []*models.SalesReturnInfo, err error) {
963 986
 }
964 987
 
965 988
 func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err error) {
966
-	err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
989
+	err = readDb.Model(&models.CancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Preload("GoodInfo", "status = 1").Find(&list).Error
967 990
 	return list, err
968 991
 }
969 992
 
@@ -1044,11 +1067,11 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
1044 1067
 	if len(warehouseOutInfo) > 0 {
1045 1068
 		utx := writeDb.Begin()
1046 1069
 		if len(warehouseOutInfo) > 0 {
1047
-			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 "
1070
+			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 "
1048 1071
 			insertParams := make([]string, 0)
1049 1072
 			insertData := make([]interface{}, 0)
1050 1073
 			for _, info := range warehouseOutInfo {
1051
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1074
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1052 1075
 				insertData = append(insertData, info.WarehouseOutId)
1053 1076
 				insertData = append(insertData, info.GoodId)
1054 1077
 				insertData = append(insertData, info.GoodTypeId)
@@ -1066,6 +1089,7 @@ func CreateWarehousingOutInfo(warehouseOutInfo []*models.WarehouseOutInfo) (err
1066 1089
 				insertData = append(insertData, info.Dealer)
1067 1090
 				insertData = append(insertData, info.Manufacturer)
1068 1091
 				insertData = append(insertData, info.Number)
1092
+				insertData = append(insertData, info.LicenseNumber)
1069 1093
 			}
1070 1094
 			thisSQL += strings.Join(insertParams, ", ")
1071 1095
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1084,11 +1108,11 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
1084 1108
 	if len(warehouseOutInfo) > 0 {
1085 1109
 		utx := writeDb.Begin()
1086 1110
 		if len(warehouseOutInfo) > 0 {
1087
-			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 "
1111
+			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 "
1088 1112
 			insertParams := make([]string, 0)
1089 1113
 			insertData := make([]interface{}, 0)
1090 1114
 			for _, info := range warehouseOutInfo {
1091
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1115
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
1092 1116
 				insertData = append(insertData, info.WarehouseOutId)
1093 1117
 				insertData = append(insertData, info.DrugId)
1094 1118
 				insertData = append(insertData, info.ProductDate)
@@ -1106,7 +1130,8 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
1106 1130
 				insertData = append(insertData, info.Manufacturer)
1107 1131
 				insertData = append(insertData, info.RetailPrice)
1108 1132
 				insertData = append(insertData, info.RetailTotalPrice)
1109
-
1133
+				insertData = append(insertData, info.Number)
1134
+				insertData = append(insertData, info.BatchNumber)
1110 1135
 			}
1111 1136
 			thisSQL += strings.Join(insertParams, ", ")
1112 1137
 			err = utx.Exec(thisSQL, insertData...).Error
@@ -1207,6 +1232,30 @@ func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime
1207 1232
 
1208 1233
 }
1209 1234
 
1235
+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) {
1236
+	db := readDb.Model(&models.DrugWarehouseOut{})
1237
+	db = db.Where("xt_drug_warehouse_out.org_id = ? AND xt_drug_warehouse_out.status = 1 ", orgId)
1238
+
1239
+	if len(keywords) > 0 {
1240
+		likeKey := "%" + keywords + "%"
1241
+		db = db.Joins("join sgj_users.sgj_user_admin_role on sgj_user_admin_role.admin_user_id = xt_drug_warehouse_out.creater")
1242
+
1243
+		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")
1244
+	}
1245
+
1246
+	if startTime > 0 {
1247
+		db = db.Where("xt_drug_warehouse_out.ctime >=?", startTime)
1248
+	}
1249
+	if endTime > 0 {
1250
+		db = db.Where("xt_drug_warehouse_out.ctime<= ?", endTime)
1251
+	}
1252
+	db = db.Count(&total)
1253
+	offset := (page - 1) * limit
1254
+	err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
1255
+	return list, total, err
1256
+
1257
+}
1258
+
1210 1259
 func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
1211 1260
 	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
1212 1261
 	return list, err
@@ -1236,6 +1285,8 @@ type DrugWarehouseOutInfo struct {
1236 1285
 	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
1237 1286
 	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1238 1287
 	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
1288
+	Number                  string  `gorm:"column:number" json:"number" form:"number"`
1289
+	BatchNumber             string  `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
1239 1290
 	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1240 1291
 }
1241 1292
 
@@ -1955,7 +2006,7 @@ func EditDrugCancelStock(sales models.DrugCancelStock) {
1955 2006
 }
1956 2007
 
1957 2008
 func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock, err error) {
1958
-	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
2009
+	err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
1959 2010
 	return cancelStock, err
1960 2011
 
1961 2012
 }
@@ -2396,6 +2447,7 @@ type DrugAutomaticReduceDetail struct {
2396 2447
 	OrgId                   int64            `gorm:"column:org_id" json:"org_id" form:"org_id"`
2397 2448
 	DrugId                  int64            `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
2398 2449
 	Count                   int64            `gorm:"column:count" json:"count" form:"count"`
2450
+	CountUnit               string           `gorm:"column:count_unit" json:"count_unit" form:"count_unit"`
2399 2451
 	Drug                    *Drug            `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
2400 2452
 	Patients                *models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"user"`
2401 2453
 }
@@ -2976,7 +3028,7 @@ func GetStockListById(good_id int64, orgid int64, limit int64, page int64, start
2976 3028
 	if good_id > 0 {
2977 3029
 		db = db.Where("x.good_id = ?", good_id)
2978 3030
 	}
2979
-	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
3031
+	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
2980 3032
 	return info, total, err
2981 3033
 
2982 3034
 }
@@ -2985,6 +3037,7 @@ func GetStockOutList(good_id int64, orgid int64, limit int64, page int64, starti
2985 3037
 	offset := (page - 1) * limit
2986 3038
 
2987 3039
 	db := XTReadDB().Table("xt_warehouse_out_info as x").Where("x.status= 1")
3040
+
2988 3041
 	if startime > 0 {
2989 3042
 		db = db.Where("x.ctime>=?", startime)
2990 3043
 	}
@@ -3070,7 +3123,7 @@ func GetOrderDetialByOrderId(id int64, orgid int64) (out []*models.WarehouseOutI
3070 3123
 	if orgid > 0 {
3071 3124
 		db = db.Where("x.org_id = ?", orgid)
3072 3125
 	}
3073
-	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
3126
+	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
3074 3127
 	return out, err
3075 3128
 }
3076 3129
 
@@ -3098,7 +3151,7 @@ func GetOrderDetialByOrderIdOne(id []string, orgid int64) (out []*models.Warehou
3098 3151
 	if orgid > 0 {
3099 3152
 		db = db.Where("x.org_id = ?", orgid)
3100 3153
 	}
3101
-	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
3154
+	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
3102 3155
 	return out, err
3103 3156
 }
3104 3157
 
@@ -3139,7 +3192,7 @@ func GetExprotStockList(orgid int64, orderid []string, startime int64, endtime i
3139 3192
 	if endtime > 0 {
3140 3193
 		db = db.Where("x.ctime<=?", endtime)
3141 3194
 	}
3142
-	err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,Sum(x.warehousing_count)as total_count,x.price,x.dealer,x.manufacturer,x.remark,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&info).Error
3195
+	err = db.Select("x.id,x.good_id,x.good_type_id,x.number,x.product_date,x.expiry_date,x.warehousing_count,x.price,x.dealer,x.manufacturer,x.remark,x.license_number,t.good_name,t.packing_unit,t.specification_name,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&info).Error
3143 3196
 
3144 3197
 	return info, err
3145 3198
 }
@@ -3182,7 +3235,7 @@ func GetOutExprotList(orgid int64, ids []string, startime int64, endtime int64)
3182 3235
 		db = db.Where("x.ctime<=?", endtime)
3183 3236
 	}
3184 3237
 
3185
-	err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,Sum(x.count) as count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Group("x.good_id").Scan(&out).Error
3238
+	err = db.Select("x.id,x.warehouse_out_id,x.good_id,x.good_type_id,x.warehousing_out_target,x.count,x.price,x.total_price,x.product_date,x.expiry_date,x.ctime,x.org_id,x.remark,x.number,x.license_number,t.good_name,t.specification_name,t.min_number,t.packing_price,t.min_unit,t.packing_unit,t.manufacturer,t.dealer").Joins("left join xt_good_information as t on t.id = x.good_id").Scan(&out).Error
3186 3239
 	return out, err
3187 3240
 
3188 3241
 }
@@ -3216,3 +3269,191 @@ func FindeDrugWarehouseOutDetail(ids []string, orgid int64) (info []*models.VmDr
3216 3269
 	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
3217 3270
 	return info, err
3218 3271
 }
3272
+
3273
+func GetDrugNameByKeyword(keyword string, orgid int64) (basedrug []*models.XtBaseDrug, err error) {
3274
+
3275
+	db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
3276
+	likeKey := "%" + keyword + "%"
3277
+	if len(keyword) > 0 {
3278
+		db = db.Where("x.drug_name like ?", likeKey)
3279
+	}
3280
+	if orgid > 0 {
3281
+		db = db.Where("x.org_id = ?", orgid)
3282
+	}
3283
+	err = db.Find(&basedrug).Error
3284
+
3285
+	return basedrug, err
3286
+
3287
+}
3288
+
3289
+func GetDrugWarehouseOrderDetail(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseOutInfo, err error) {
3290
+
3291
+	db := XTReadDB().Table("xt_drug_warehouse_out_info as x").Where("x.status = 1")
3292
+
3293
+	if len(ids) > 0 {
3294
+		db = db.Where("x.drug_id in(?)", ids)
3295
+	}
3296
+
3297
+	if orgid > 0 {
3298
+		db = db.Where("x.org_id = ?", orgid)
3299
+	}
3300
+	if startime > 0 {
3301
+		db = db.Where("x.ctime>=?", startime)
3302
+	}
3303
+	if endtime > 0 {
3304
+		db = db.Where("x.ctime<=?", endtime)
3305
+	}
3306
+
3307
+	err = db.Find(&info).Error
3308
+	return info, err
3309
+}
3310
+
3311
+func GetDrugWarehouseOrderDetailTwo(ids []int64, orgid int64, startime int64, endtime int64) (info []*models.XtDrugWarehouseInfo, err error) {
3312
+
3313
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3314
+
3315
+	if len(ids) > 0 {
3316
+		db = db.Where("x.drug_id in(?)", ids)
3317
+	}
3318
+
3319
+	if orgid > 0 {
3320
+		db = db.Where("x.org_id = ?", orgid)
3321
+	}
3322
+	if startime > 0 {
3323
+		db = db.Where("x.ctime>=?", startime)
3324
+	}
3325
+	if endtime > 0 {
3326
+		db = db.Where("x.ctime<=?", endtime)
3327
+	}
3328
+
3329
+	err = db.Find(&info).Error
3330
+	return info, err
3331
+}
3332
+
3333
+func GetDrugTotalCount(drugid int64, orgid int64) (info models.VmDrugWarehouseInfo, err error) {
3334
+
3335
+	db := XTReadDB().Table("xt_drug_warehouse_info as x").Where("x.status = 1")
3336
+	if drugid > 0 {
3337
+		db = db.Where("x.drug_id = ?", drugid)
3338
+	}
3339
+	if orgid > 0 {
3340
+		db = db.Where("x.org_id = ?", orgid)
3341
+	}
3342
+	err = db.Select("x.drug_id,sum(x.stock_max_number) as count").Find(&info).Error
3343
+	return info, err
3344
+}
3345
+
3346
+func GetDrugByGoodId(drugid int64) (models.BaseDrugLib, error) {
3347
+
3348
+	lib := models.BaseDrugLib{}
3349
+	err := XTReadDB().Model(&lib).Where("id = ? and status = 1", drugid).Find(&lib).Error
3350
+	return lib, err
3351
+}
3352
+
3353
+func GetWarehoureOrderInfoList(goodid int64, orgid int64) (info []*models.WarehousingInfo, err error) {
3354
+
3355
+	db := XTReadDB().Table("xt_warehouse_info as x").Where("x.status = 1")
3356
+
3357
+	if goodid > 0 {
3358
+		db = db.Where("x.good_id = ?", goodid)
3359
+	}
3360
+
3361
+	if orgid > 0 {
3362
+		db = db.Where("x.org_id = ?", orgid)
3363
+	}
3364
+
3365
+	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,x.org_id").Find(&info).Error
3366
+	return info, err
3367
+}
3368
+
3369
+func UpdateWarehousingCount(info *models.WarehousingInfo, goodid int64, orgid int64, warehousingId int64) error {
3370
+
3371
+	err := XTWriteDB().Model(&info).Where("good_id = ? and org_id = ? and status =1 and warehousing_id = ?", goodid, orgid, warehousingId).Updates(map[string]interface{}{"stock_count": info.StockCount}).Error
3372
+	return err
3373
+}
3374
+
3375
+func GetSingleCancelOrder(id int64, orgid int64) (info []*models.CancelStockInfo, err error) {
3376
+
3377
+	err = XTReadDB().Where("cancel_stock_id = ? and status = 1 and org_id = ?", id, orgid).Preload("GoodInfo", "status = 1").Find(&info).Error
3378
+	return info, err
3379
+}
3380
+
3381
+func UpdateCancelOut(list []*models.WarehousingInfo, count int64) error {
3382
+
3383
+	//遍历循环入库数据
3384
+	for i, item := range list {
3385
+		//计算每个批次剩余库存与入库数据的差 然后和退库数量比较
3386
+		if (item.WarehousingCount - item.StockCount) >= count {
3387
+			//如果差距大于退库数量,则直接把退库数量增加到该批次中
3388
+			info := models.WarehousingInfo{
3389
+				GoodId:        item.GoodId,
3390
+				OrgId:         item.OrgId,
3391
+				WarehousingId: item.WarehousingId,
3392
+				StockCount:    item.StockCount + count,
3393
+			}
3394
+			UpdateWarehousingCount(&info, item.GoodId, item.OrgId, item.WarehousingId)
3395
+			break
3396
+		}
3397
+
3398
+		if (item.WarehousingCount - item.StockCount) < count {
3399
+
3400
+			//如果该批次小于退库数量,则先出库该相差数量
3401
+			var countOne = item.WarehousingCount - item.StockCount
3402
+
3403
+			infoOne := models.WarehousingInfo{
3404
+				GoodId:        item.GoodId,
3405
+				OrgId:         item.OrgId,
3406
+				WarehousingId: item.WarehousingId,
3407
+				StockCount:    countOne + item.StockCount,
3408
+			}
3409
+
3410
+			err := UpdateWarehousingCount(&infoOne, item.GoodId, item.OrgId, item.WarehousingId)
3411
+			if err == nil {
3412
+				//剩余的出库到第二个批次
3413
+				var countTwo = count - countOne
3414
+				infos := append(list, list[i+1])
3415
+				var idArray []*models.WarehousingInfo
3416
+				for _, it := range infos {
3417
+					if it.WarehousingId != item.WarehousingId {
3418
+						idArray = append(idArray, it)
3419
+					}
3420
+				}
3421
+				//查询更新后的库存
3422
+				UpdateCancelOut(idArray, countTwo)
3423
+				return err
3424
+			} else {
3425
+				return err
3426
+			}
3427
+
3428
+		}
3429
+	}
3430
+
3431
+	return err
3432
+}
3433
+
3434
+func GetCancelStockOrderPrint(idstr []string) (info []*models.CancelStockInfo, err error) {
3435
+
3436
+	if len(idstr) > 0 {
3437
+		err = XTReadDB().Model(&info).Where("cancel_stock_id in(?)", idstr).Preload("GoodInfo", "status = 1").Find(&info).Error
3438
+	} else {
3439
+		err = XTReadDB().Model(&info).Preload("GoodInfo", "status = 1").Find(&info).Error
3440
+	}
3441
+	return info, err
3442
+}
3443
+
3444
+func GetCancelOutTotalCount(startime int64, endtime int64, orgid int64) (info []*models.VmCancelStockInfo, err error) {
3445
+
3446
+	db := XTReadDB().Table("xt_cancel_stock_info as x").Where("x.status = 1")
3447
+
3448
+	if startime > 0 {
3449
+		db = db.Where("x.ctime >=?", startime)
3450
+	}
3451
+	if endtime > 0 {
3452
+		db = db.Where("x.ctime <= ?", endtime)
3453
+	}
3454
+	if orgid > 0 {
3455
+		db = db.Where("x.org_id = ?", orgid)
3456
+	}
3457
+	err = db.Select("x.good_id,sum(x.count) as count").Group("x.good_id").Scan(&info).Error
3458
+	return info, err
3459
+}

+ 74 - 19
service/warhouse_service.go ファイルの表示

@@ -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"
@@ -523,23 +522,30 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
523 522
 	// 将该批次的剩余库存数量转换为拆零数量
524 523
 
525 524
 	stock_number = warehouse.StockMaxNumber*drup.MinNumber + warehouse.StockMinNumber
526
-	fmt.Println("88i8uu7777777777777777777777777777", stock_number)
527
-	fmt.Println("77777544656666666666666666", deliver_number)
525
+
528 526
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
529 527
 	if stock_number >= deliver_number {
528
+		fmt.Println("价格表32322222222222222222232322332", advice.Price)
530 529
 		warehouseOutInfo := &models.DrugWarehouseOutInfo{
531 530
 			WarehouseOutOrderNumber: warehouseout.WarehouseOutOrderNumber,
532 531
 			WarehouseOutId:          warehouseout.ID,
533 532
 			Status:                  1,
534 533
 			Ctime:                   time.Now().Unix(),
535
-			Remark:                  "",
534
+			Remark:                  advice.Remark,
536 535
 			OrgId:                   orgID,
537 536
 			Type:                    1,
538
-			Manufacturer:            0,
539
-			Dealer:                  0,
537
+			Manufacturer:            advice.Manufacturer,
538
+			Dealer:                  advice.Dealer,
540 539
 			IsSys:                   0,
541 540
 			SysRecordTime:           advice.Ctime,
542 541
 			DrugId:                  advice.DrugId,
542
+			ExpiryDate:              advice.ExpiryDate,
543
+			ProductDate:             advice.ProductDate,
544
+			Number:                  advice.Number,
545
+			BatchNumber:             advice.BatchNumber,
546
+			Count:                   advice.Count,
547
+			RetailPrice:             advice.RetailPrice,
548
+			Price:                   advice.Price,
543 549
 		}
544 550
 
545 551
 		warehouseOutInfo.Count = deliver_number
@@ -592,14 +598,21 @@ func AutoDrugDeliverInfo(orgID int64, prescribingNumber int64, warehouseout *mod
592 598
 			WarehouseOutId:          warehouseout.ID,
593 599
 			Status:                  1,
594 600
 			Ctime:                   time.Now().Unix(),
595
-			Remark:                  "",
601
+			Remark:                  advice.Remark,
596 602
 			OrgId:                   orgID,
597 603
 			Type:                    1,
598
-			Manufacturer:            0,
599
-			Dealer:                  0,
604
+			Manufacturer:            advice.Manufacturer,
605
+			Dealer:                  advice.Dealer,
600 606
 			IsSys:                   0,
601 607
 			SysRecordTime:           advice.Ctime,
602 608
 			DrugId:                  advice.DrugId,
609
+			ExpiryDate:              advice.ExpiryDate,
610
+			ProductDate:             advice.ProductDate,
611
+			Number:                  advice.Number,
612
+			BatchNumber:             advice.BatchNumber,
613
+			Count:                   advice.Count,
614
+			RetailPrice:             advice.RetailPrice,
615
+			Price:                   advice.Price,
603 616
 		}
604 617
 
605 618
 		warehouseOutInfo.Count = stock_number
@@ -748,7 +761,7 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
748 761
 	// 如果没有对应的库存,则报错
749 762
 
750 763
 	warehouse, err := FindFirstWarehousingInfoByStock(goods.GoodId, goods.GoodTypeId)
751
-	fmt.Println("库存数量", warehouse.StockCount)
764
+	fmt.Println("库存数量9999343434343434343434343434343434", warehouse.StockCount)
752 765
 	if err != nil {
753 766
 		return
754 767
 	}
@@ -829,6 +842,39 @@ func ConsumablesDelivery(orgID int64, patient_id int64, record_time int64, goods
829 842
 
830 843
 		return nil
831 844
 	} else {
845
+		fmt.Println("中国共产党万岁22322332323232322323232323232323")
846
+		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
847
+		//warehouseOutInfo := &models.WarehouseOutInfo{
848
+		//  WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
849
+		//  WarehouseOutId:          warehouseOut.ID,
850
+		//  WarehouseInfotId:        warehouse.ID,
851
+		//  Status:                  1,
852
+		//  Ctime:                   time.Now().Unix(),
853
+		//  Remark:                  goods.Remark,
854
+		//  OrgId:                   orgID,
855
+		//  Type:                    1,
856
+		//  Manufacturer:            goods.Manufacturer,
857
+		//  Dealer:                  goods.Dealer,
858
+		//  IsSys:                   0,
859
+		//  SysRecordTime:           record_time,
860
+		//  GoodTypeId:              goods.GoodTypeId,
861
+		//  GoodId:                  goods.GoodId,
862
+		//  ExpiryDate:              goods.ExpiryDate,
863
+		//  ProductDate:             goods.ProductDate,
864
+		//  Number:                  goods.Number,
865
+		//  Price:                   goods.Price,
866
+		//  LicenseNumber:           goods.LicenseNumber,
867
+		//}
868
+		//warehouseOutInfo.Count = stock_number
869
+		//stockInInfo, _ :=FindLastStockInInfoRecord(goods.GoodId, orgID)
870
+		//fmt.Println("stockINFO2232232323223322332323223323223",stockInInfo)
871
+		//warehouseOutInfo.Price = stockInInfo.Price
872
+		//
873
+		//errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
874
+		//fmt.Println("errOne2232323232323232333232323",errOne)
875
+		//if errOne != nil {
876
+		//  return errOne
877
+		//}
832 878
 		// 出库完成后,要将该批次库存清零
833 879
 		warehouse.StockCount = 0
834 880
 		warehouse.Mtime = time.Now().Unix()
@@ -1098,6 +1144,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1098 1144
 	fmt.Println("8888888888888888888", deliver_number)
1099 1145
 	// 当库存数量大于或等于出库数量的话,则正常出库该批次
1100 1146
 	if stock_number >= deliver_number {
1147
+		fmt.Println("g2332232332323232232323322332", goods.Price)
1101 1148
 		warehouseOutInfo := &models.WarehouseOutInfo{
1102 1149
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
1103 1150
 			WarehouseOutId:          warehouseOut.ID,
@@ -1117,10 +1164,11 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1117 1164
 			ProductDate:             goods.ProductDate,
1118 1165
 			Number:                  goods.Number,
1119 1166
 			Price:                   goods.Price,
1167
+			LicenseNumber:           goods.LicenseNumber,
1120 1168
 		}
1121 1169
 		warehouseOutInfo.Count = goods.Count
1122
-		stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1123
-		warehouseOutInfo.Price = stockInInfo.Price
1170
+		//stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1171
+		//warehouseOutInfo.Price = stockInInfo.Price
1124 1172
 
1125 1173
 		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1126 1174
 		if errOne != nil {
@@ -1135,12 +1183,17 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1135 1183
 
1136 1184
 		warehouse.StockCount = warehouse.StockCount - maxNumber
1137 1185
 		warehouse.Mtime = time.Now().Unix()
1186
+
1138 1187
 		if warehouse.StockCount < 0 {
1139
-			fmt.Println("进来33232323232232323233232", warehouse.StockCount)
1188
+
1140 1189
 			return errors.New("库存数量不足")
1141 1190
 		}
1142
-		return nil
1191
+		errThree := UpDateWarehouseInfoByStock(&warehouse)
1192
+		if errThree != nil {
1193
+			return errThree
1194
+		}
1143 1195
 	} else {
1196
+		fmt.Println("中国共产党万岁22322332323232322323232323232323")
1144 1197
 		// 当改批次的库存数量小于出库数量的话,则先把该批次出库完后,再进行递归出库
1145 1198
 		warehouseOutInfo := &models.WarehouseOutInfo{
1146 1199
 			WarehouseOutOrderNumber: warehouseOut.WarehouseOutOrderNumber,
@@ -1161,13 +1214,15 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1161 1214
 			ProductDate:             goods.ProductDate,
1162 1215
 			Number:                  goods.Number,
1163 1216
 			Price:                   goods.Price,
1217
+			LicenseNumber:           goods.LicenseNumber,
1164 1218
 		}
1165 1219
 		warehouseOutInfo.Count = stock_number
1166
-		stockInInfo, _ := service.FindLastStockInInfoRecord(goods.GoodId, orgID)
1167
-		warehouseOutInfo.Price = stockInInfo.Price
1168
-
1169
-		errOne := service.AddSigleWarehouseOutInfo(warehouseOutInfo)
1220
+		//stockInInfo, _ := FindLastStockInInfoRecord(goods.GoodId, orgID)
1221
+		//fmt.Println("stockINFO2232232323223322332323223323223", stockInInfo)
1222
+		//warehouseOutInfo.Price = stockInInfo.Price
1170 1223
 
1224
+		errOne := AddSigleWarehouseOutInfo(warehouseOutInfo)
1225
+		fmt.Println("errOne2232323232323232333232323", errOne)
1171 1226
 		if errOne != nil {
1172 1227
 			return errOne
1173 1228
 		}
@@ -1180,7 +1235,7 @@ func ConsumablesDeliveryOne(orgID int64, record_time int64, goods *models.Wareho
1180 1235
 		}
1181 1236
 		// 清零完该库存后,还有剩余出库未出完,进行对应的递归操作
1182 1237
 		goods.Count = deliver_number - stock_number
1183
-
1238
+		fmt.Println("goods3333333333333333333333", goods.Count)
1184 1239
 		ConsumablesDeliveryOne(orgID, record_time, goods, warehouseOut, count)
1185 1240
 
1186 1241
 	}