Browse Source

新功能开发

csx 4 years ago
parent
commit
55ebc12121

+ 240 - 86
controllers/drug_stock_api_contorller.go View File

@@ -58,7 +58,7 @@ func DrugStockManagerApiRegistRouters() {
58 58
 	//beego.Router("/api/drugreturn/config", &StockDrugApiController{}, "get:GetAllSalesReturnConfig")
59 59
 	//
60 60
 	////库存查询
61
-	//beego.Router("/api/drugstock/query", &StockDrugApiController{}, "get:GetQueryInfo")
61
+	beego.Router("/api/drugstock/query", &StockDrugApiController{}, "get:GetDrugQueryInfo")
62 62
 	//
63 63
 	//beego.Router("/api/drugstock/detail", &StockDrugApiController{}, "get:GetDetailInfo")
64 64
 	//
@@ -89,7 +89,7 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
89 89
 	timeArr := strings.Split(timeStr, "-")
90 90
 	total, _ := service.FindAllWarehouseTotal(adminUserInfo.CurrentOrgId)
91 91
 	total = total + 1
92
-	warehousing_order := "RKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
92
+	warehousing_order := "YPRKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
93 93
 	operation_time := time.Now().Unix()
94 94
 	creater := adminUserInfo.AdminUser.Id
95 95
 	warehousing := models.DrugWarehouse{
@@ -144,6 +144,14 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
144 144
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
145 145
 				total := float64(warehousing_count) * price
146 146
 
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
+				retail_price_total := float64(warehousing_count) * retail_price
154
+
147 155
 				var productDates int64
148 156
 				var expiryDates int64
149 157
 
@@ -208,6 +216,8 @@ func (c *StockDrugApiController) CreateDrugWarehouse() {
208 216
 					Type:             types,
209 217
 					Manufacturer:     manufacturer_id,
210 218
 					Dealer:           dealer_id,
219
+					RetailPrice:      retail_price,
220
+					RetailTotalPrice: retail_price_total,
211 221
 				}
212 222
 				warehousingInfo = append(warehousingInfo, warehouseInfo)
213 223
 
@@ -520,6 +530,14 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
520 530
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
521 531
 				total := float64(warehousing_count) * price
522 532
 
533
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
534
+					utils.ErrorLog("retail_price")
535
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
536
+					return
537
+				}
538
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
539
+				retail_price_total := float64(warehousing_count) * retail_price
540
+
523 541
 				var productDates int64
524 542
 				var expiryDates int64
525 543
 
@@ -592,6 +610,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
592 610
 						Type:             types,
593 611
 						Manufacturer:     manufacturer_id,
594 612
 						Dealer:           dealer_id,
613
+						RetailPrice:      retail_price,
614
+						RetailTotalPrice: retail_price_total,
595 615
 					}
596 616
 					warehousingInfo = append(warehousingInfo, warehouseInfo)
597 617
 
@@ -614,6 +634,8 @@ func (c *StockDrugApiController) EditDrugWarehouse() {
614 634
 						Type:             types,
615 635
 						Manufacturer:     manufacturer_id,
616 636
 						Dealer:           dealer_id,
637
+						RetailPrice:      retail_price,
638
+						RetailTotalPrice: retail_price_total,
617 639
 					}
618 640
 					upDateWarehousingInfo = append(upDateWarehousingInfo, warehouseInfo)
619 641
 				}
@@ -701,7 +723,7 @@ func (c *StockDrugApiController) CreateDrugSalesReturn() {
701 723
 	timeArr := strings.Split(timeStr, "-")
702 724
 	total, _ := service.FindAllSalesReturnTotal(adminUserInfo.CurrentOrgId)
703 725
 	total = total + 1
704
-	orderNumber := "THD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
726
+	orderNumber := "YPTHD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
705 727
 
706 728
 	salesReturn := models.DrugSalesReturn{
707 729
 		OrderNumber:  orderNumber,
@@ -748,24 +770,39 @@ func (c *StockDrugApiController) CreateDrugSalesReturn() {
748 770
 
749 771
 					return
750 772
 				}
751
-
752 773
 				count, _ := strconv.ParseInt(return_count, 10, 64)
753
-				price, _ := strconv.ParseFloat(items["price"].(string), 10)
774
+
775
+				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
776
+					utils.ErrorLog("price")
777
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
778
+					return
779
+				}
780
+				price, _ := strconv.ParseFloat(items["price"].(string), 64)
754 781
 				total := float64(count) * price
755 782
 
783
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
784
+					utils.ErrorLog("retail_price")
785
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
786
+					return
787
+				}
788
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
789
+				retail_price_total := float64(count) * retail_price
790
+
756 791
 				salesReturnInfo := &models.DrugSalesReturnInfo{
757
-					OrderNumber:   salesReturn.OrderNumber,
758
-					SalesReturnId: salesReturn.ID,
759
-					DrugId:        drug_id,
760
-					Count:         count,
761
-					Price:         price,
762
-					Total:         total,
763
-					Status:        1,
764
-					Ctime:         ctime,
765
-					OrgId:         adminUserInfo.CurrentOrgId,
766
-					Type:          types,
767
-					Manufacturer:  manufacturer_id,
768
-					Dealer:        dealer_id,
792
+					OrderNumber:      salesReturn.OrderNumber,
793
+					SalesReturnId:    salesReturn.ID,
794
+					DrugId:           drug_id,
795
+					Count:            count,
796
+					Price:            price,
797
+					Total:            total,
798
+					Status:           1,
799
+					Ctime:            ctime,
800
+					OrgId:            adminUserInfo.CurrentOrgId,
801
+					Type:             types,
802
+					Manufacturer:     manufacturer_id,
803
+					Dealer:           dealer_id,
804
+					RetailPrice:      retail_price,
805
+					RetailTotalPrice: retail_price_total,
769 806
 				}
770 807
 
771 808
 				salesReturnInfos = append(salesReturnInfos, salesReturnInfo)
@@ -776,7 +813,7 @@ func (c *StockDrugApiController) CreateDrugSalesReturn() {
776 813
 	errs := service.CreateDrugSalesReturnInfo(salesReturnInfos)
777 814
 	if errs != nil {
778 815
 		utils.ErrorLog(errs.Error())
779
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
816
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
780 817
 		return
781 818
 	}
782 819
 
@@ -865,8 +902,10 @@ func (this *StockDrugApiController) DeleteDrugSalesReturnInfo() {
865 902
 }
866 903
 func (this *StockDrugApiController) GetDrugSalesReturnInfoList() {
867 904
 	id, _ := this.GetInt64("id", 0)
868
-	list, _ := service.FindAllDrugSalesReturnInfoById(id)
869
-	salesReturn, _ := service.FindAllDrugSalesReturnById(id)
905
+	adminUserInfo := this.GetAdminUserInfo()
906
+
907
+	list, _ := service.FindAllDrugSalesReturnInfoById(id, adminUserInfo.CurrentOrgId)
908
+	salesReturn, _ := service.FindAllDrugSalesReturnById(id, adminUserInfo.CurrentOrgId)
870 909
 
871 910
 	this.ServeSuccessJSON(map[string]interface{}{
872 911
 		"list":        list,
@@ -948,36 +987,61 @@ func (c *StockDrugApiController) EditDrugReturnInfo() {
948 987
 				}
949 988
 				id := int64(items["id"].(float64))
950 989
 
990
+				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
991
+					utils.ErrorLog("price")
992
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
993
+					return
994
+				}
995
+
996
+				price, _ := strconv.ParseFloat(items["price"].(string), 64)
997
+				total := float64(count) * price
998
+
999
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1000
+					utils.ErrorLog("retail_price")
1001
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1002
+					return
1003
+				}
1004
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1005
+				retail_price_total := float64(count) * retail_price
1006
+
951 1007
 				if id == 0 {
952 1008
 					returnInfo := &models.DrugSalesReturnInfo{
953
-						DrugId:        drug_id,
954
-						Count:         count,
955
-						Status:        1,
956
-						Ctime:         ctime,
957
-						OrgId:         adminUserInfo.CurrentOrgId,
958
-						OrderNumber:   sales.OrderNumber,
959
-						SalesReturnId: sales.ID,
960
-						Mtime:         time.Now().Unix(),
961
-						Type:          types,
962
-						Manufacturer:  manufacturer_id,
963
-						Dealer:        dealer_id,
1009
+						DrugId:           drug_id,
1010
+						Count:            count,
1011
+						Status:           1,
1012
+						Ctime:            ctime,
1013
+						OrgId:            adminUserInfo.CurrentOrgId,
1014
+						OrderNumber:      sales.OrderNumber,
1015
+						SalesReturnId:    sales.ID,
1016
+						Mtime:            time.Now().Unix(),
1017
+						Type:             types,
1018
+						Manufacturer:     manufacturer_id,
1019
+						Dealer:           dealer_id,
1020
+						RetailPrice:      retail_price,
1021
+						RetailTotalPrice: retail_price_total,
1022
+						Total:            total,
1023
+						Price:            price,
964 1024
 					}
965 1025
 					returnInfos = append(returnInfos, returnInfo)
966 1026
 
967 1027
 				} else {
968 1028
 					returnInfo := &models.DrugSalesReturnInfo{
969
-						ID:            id,
970
-						DrugId:        drug_id,
971
-						Count:         count,
972
-						Status:        1,
973
-						Ctime:         ctime,
974
-						OrgId:         adminUserInfo.CurrentOrgId,
975
-						OrderNumber:   sales.OrderNumber,
976
-						SalesReturnId: sales.ID,
977
-						Mtime:         time.Now().Unix(),
978
-						Type:          types,
979
-						Manufacturer:  manufacturer_id,
980
-						Dealer:        dealer_id,
1029
+						ID:               id,
1030
+						DrugId:           drug_id,
1031
+						Count:            count,
1032
+						Status:           1,
1033
+						Ctime:            ctime,
1034
+						OrgId:            adminUserInfo.CurrentOrgId,
1035
+						OrderNumber:      sales.OrderNumber,
1036
+						SalesReturnId:    sales.ID,
1037
+						Mtime:            time.Now().Unix(),
1038
+						Type:             types,
1039
+						Manufacturer:     manufacturer_id,
1040
+						Dealer:           dealer_id,
1041
+						RetailPrice:      retail_price,
1042
+						RetailTotalPrice: retail_price_total,
1043
+						Total:            total,
1044
+						Price:            price,
981 1045
 					}
982 1046
 					upDateReturnInfos = append(upDateReturnInfos, returnInfo)
983 1047
 				}
@@ -997,7 +1061,7 @@ func (c *StockDrugApiController) EditDrugReturnInfo() {
997 1061
 
998 1062
 	if errs != nil {
999 1063
 		utils.ErrorLog(errs.Error())
1000
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1064
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateReturnFail)
1001 1065
 		return
1002 1066
 	}
1003 1067
 
@@ -1030,7 +1094,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1030 1094
 	warehousing_out_order := strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
1031 1095
 	number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
1032 1096
 	number = number + total
1033
-	warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
1097
+	warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
1034 1098
 	operation_time := time.Now().Unix()
1035 1099
 	creater := adminUserInfo.AdminUser.Id
1036 1100
 
@@ -1083,9 +1147,17 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1083 1147
 				}
1084 1148
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1085 1149
 
1150
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1151
+					utils.ErrorLog("retail_price")
1152
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1153
+					return
1154
+				}
1155
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1156
+
1086 1157
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1087 1158
 
1088 1159
 				total := float64(count) * price
1160
+				retail_price_total := float64(count) * retail_price
1089 1161
 				remark := items["remark"].(string)
1090 1162
 
1091 1163
 				warehouseOutInfo := &models.DrugWarehouseOutInfo{
@@ -1102,6 +1174,8 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1102 1174
 					Type:                    types,
1103 1175
 					Manufacturer:            manufacturer_id,
1104 1176
 					Dealer:                  dealer_id,
1177
+					RetailPrice:             retail_price,
1178
+					RetailTotalPrice:        retail_price_total,
1105 1179
 				}
1106 1180
 				warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1107 1181
 
@@ -1112,7 +1186,7 @@ func (c *StockDrugApiController) CreateDrugWarehouseOut() {
1112 1186
 	info, _ := service.FindLastDrugWarehousingOutInfo(warehouseOut.WarehouseOutOrderNumber)
1113 1187
 	if errs != nil {
1114 1188
 		utils.ErrorLog(errs.Error())
1115
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1189
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1116 1190
 		return
1117 1191
 	}
1118 1192
 
@@ -1203,8 +1277,9 @@ func (this *StockDrugApiController) DeleteDrugWarehouseOutInfo() {
1203 1277
 }
1204 1278
 func (c *StockDrugApiController) GetDrugWarehouseOutInfoList() {
1205 1279
 	id, _ := c.GetInt64("id", 0)
1206
-	warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id)
1207
-	warehouseOut, _ := service.FindDrugWareHouseOutById(id)
1280
+	adminInfo := c.GetAdminUserInfo()
1281
+	warehouseOutInfo, _ := service.FindDrugWarehouseOutInfoById(id, adminInfo.CurrentOrgId)
1282
+	warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminInfo.CurrentOrgId)
1208 1283
 	c.ServeSuccessJSON(map[string]interface{}{
1209 1284
 		"list": warehouseOutInfo,
1210 1285
 		"info": warehouseOut,
@@ -1234,7 +1309,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1234 1309
 		return
1235 1310
 	}
1236 1311
 
1237
-	warehouseOut, _ := service.FindDrugWareHouseOutById(id)
1312
+	warehouseOut, _ := service.FindDrugWareHouseOutById(id, adminUserInfo.CurrentOrgId)
1238 1313
 
1239 1314
 	tempWarehouseOut := models.DrugWarehouseOut{
1240 1315
 		ID:               warehouseOut.ID,
@@ -1285,7 +1360,16 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1285 1360
 				}
1286 1361
 				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1287 1362
 
1363
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1364
+					utils.ErrorLog("retail_price")
1365
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1366
+					return
1367
+				}
1368
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1369
+
1288 1370
 				total := float64(count) * price
1371
+				retail_price_total := float64(count) * retail_price
1372
+
1289 1373
 				remark := items["remark"].(string)
1290 1374
 
1291 1375
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
@@ -1312,6 +1396,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1312 1396
 						Dealer:                  dealer_id,
1313 1397
 						IsSys:                   0,
1314 1398
 						SysRecordTime:           0,
1399
+						RetailPrice:             retail_price,
1400
+						RetailTotalPrice:        retail_price_total,
1315 1401
 					}
1316 1402
 					warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
1317 1403
 
@@ -1348,6 +1434,8 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1348 1434
 						Dealer:                  dealer_id,
1349 1435
 						IsSys:                   is_sys,
1350 1436
 						SysRecordTime:           sys_record_time,
1437
+						RetailPrice:             retail_price,
1438
+						RetailTotalPrice:        retail_price_total,
1351 1439
 					}
1352 1440
 					upDateWarehouseOutInfos = append(upDateWarehouseOutInfos, warehouseOutInfo)
1353 1441
 				}
@@ -1367,7 +1455,7 @@ func (c *StockDrugApiController) EditDrugWarehouseOut() {
1367 1455
 
1368 1456
 	if errs != nil {
1369 1457
 		utils.ErrorLog(errs.Error())
1370
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1458
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockOutFail)
1371 1459
 		return
1372 1460
 	}
1373 1461
 
@@ -1447,17 +1535,37 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1447 1535
 
1448 1536
 				count, _ := strconv.ParseInt(return_count, 10, 64)
1449 1537
 
1538
+				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
1539
+					utils.ErrorLog("price")
1540
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1541
+					return
1542
+				}
1543
+				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1544
+				total := float64(count) * price
1545
+
1546
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1547
+					utils.ErrorLog("retail_price")
1548
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1549
+					return
1550
+				}
1551
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1552
+				retail_price_total := float64(count) * retail_price
1553
+
1450 1554
 				cancelStockInfo := &models.DrugCancelStockInfo{
1451
-					OrderNumber:   cancelStock.OrderNumber,
1452
-					CancelStockId: cancelStock.ID,
1453
-					DrugId:        drug_id,
1454
-					Count:         count,
1455
-					Status:        1,
1456
-					Ctime:         ctime,
1457
-					OrgId:         adminUserInfo.CurrentOrgId,
1458
-					Type:          types,
1459
-					Manufacturer:  manufacturer_id,
1460
-					Dealer:        dealer_id,
1555
+					OrderNumber:      cancelStock.OrderNumber,
1556
+					CancelStockId:    cancelStock.ID,
1557
+					DrugId:           drug_id,
1558
+					Count:            count,
1559
+					Status:           1,
1560
+					Ctime:            ctime,
1561
+					OrgId:            adminUserInfo.CurrentOrgId,
1562
+					Type:             types,
1563
+					Manufacturer:     manufacturer_id,
1564
+					Dealer:           dealer_id,
1565
+					Total:            total,
1566
+					RetailPrice:      retail_price,
1567
+					RetailTotalPrice: retail_price_total,
1568
+					Price:            price,
1461 1569
 				}
1462 1570
 				cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1463 1571
 
@@ -1478,9 +1586,10 @@ func (c *StockDrugApiController) CreateDrugCancelStock() {
1478 1586
 }
1479 1587
 func (c *StockDrugApiController) GetDrugCancelStockInfoList() {
1480 1588
 	id, _ := c.GetInt64("id", 0)
1589
+	adminUserInfo := c.GetAdminUserInfo()
1481 1590
 
1482
-	cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id)
1483
-	info, _ := service.FindCancelStockById(id)
1591
+	cancelStockInfoList, _ := service.FindDrugCancelStockInfoById(id, adminUserInfo.CurrentOrgId)
1592
+	info, _ := service.FindCancelStockById(id, adminUserInfo.CurrentOrgId)
1484 1593
 
1485 1594
 	c.ServeSuccessJSON(map[string]interface{}{
1486 1595
 		"list": cancelStockInfoList,
@@ -1633,6 +1742,24 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1633 1742
 
1634 1743
 				count, _ := strconv.ParseInt(items["count"].(string), 10, 64)
1635 1744
 
1745
+				//count, _ := strconv.ParseInt(return_count, 10, 64)
1746
+
1747
+				if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
1748
+					utils.ErrorLog("price")
1749
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1750
+					return
1751
+				}
1752
+				price, _ := strconv.ParseFloat(items["price"].(string), 64)
1753
+				total := float64(count) * price
1754
+
1755
+				if items["retail_price"] == nil || reflect.TypeOf(items["retail_price"]).String() != "string" {
1756
+					utils.ErrorLog("retail_price")
1757
+					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
1758
+					return
1759
+				}
1760
+				retail_price, _ := strconv.ParseFloat(items["retail_price"].(string), 64)
1761
+				retail_price_total := float64(count) * retail_price
1762
+
1636 1763
 				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
1637 1764
 					utils.ErrorLog("id")
1638 1765
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -1642,34 +1769,42 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1642 1769
 
1643 1770
 				if id == 0 {
1644 1771
 					cancelStockInfo := &models.DrugCancelStockInfo{
1645
-						DrugId:        drug_id,
1646
-						Count:         count,
1647
-						Status:        1,
1648
-						Ctime:         ctime,
1649
-						OrgId:         adminUserInfo.CurrentOrgId,
1650
-						OrderNumber:   cancelStock.OrderNumber,
1651
-						CancelStockId: cancelStock.ID,
1652
-						Mtime:         time.Now().Unix(),
1653
-						Type:          types,
1654
-						Manufacturer:  manufacturer_id,
1655
-						Dealer:        dealer_id,
1772
+						DrugId:           drug_id,
1773
+						Count:            count,
1774
+						Status:           1,
1775
+						Ctime:            ctime,
1776
+						OrgId:            adminUserInfo.CurrentOrgId,
1777
+						OrderNumber:      cancelStock.OrderNumber,
1778
+						CancelStockId:    cancelStock.ID,
1779
+						Mtime:            time.Now().Unix(),
1780
+						Type:             types,
1781
+						Manufacturer:     manufacturer_id,
1782
+						Dealer:           dealer_id,
1783
+						RetailPrice:      retail_price,
1784
+						RetailTotalPrice: retail_price_total,
1785
+						Price:            price,
1786
+						Total:            total,
1656 1787
 					}
1657 1788
 					cancelStockInfos = append(cancelStockInfos, cancelStockInfo)
1658 1789
 
1659 1790
 				} else {
1660 1791
 					cancelStockInfo := &models.DrugCancelStockInfo{
1661
-						ID:            id,
1662
-						DrugId:        drug_id,
1663
-						Count:         count,
1664
-						Status:        1,
1665
-						Ctime:         ctime,
1666
-						OrgId:         adminUserInfo.CurrentOrgId,
1667
-						OrderNumber:   cancelStock.OrderNumber,
1668
-						CancelStockId: cancelStock.ID,
1669
-						Mtime:         time.Now().Unix(),
1670
-						Type:          types,
1671
-						Manufacturer:  manufacturer_id,
1672
-						Dealer:        dealer_id,
1792
+						ID:               id,
1793
+						DrugId:           drug_id,
1794
+						Count:            count,
1795
+						Status:           1,
1796
+						Ctime:            ctime,
1797
+						OrgId:            adminUserInfo.CurrentOrgId,
1798
+						OrderNumber:      cancelStock.OrderNumber,
1799
+						CancelStockId:    cancelStock.ID,
1800
+						Mtime:            time.Now().Unix(),
1801
+						Type:             types,
1802
+						Manufacturer:     manufacturer_id,
1803
+						Dealer:           dealer_id,
1804
+						RetailPrice:      retail_price,
1805
+						RetailTotalPrice: retail_price_total,
1806
+						Price:            price,
1807
+						Total:            total,
1673 1808
 					}
1674 1809
 					upDateCancelStockInfos = append(upDateCancelStockInfos, cancelStockInfo)
1675 1810
 				}
@@ -1689,7 +1824,7 @@ func (c *StockDrugApiController) EditDrugCancelStock() {
1689 1824
 
1690 1825
 	if errs != nil {
1691 1826
 		utils.ErrorLog(errs.Error())
1692
-		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateStockInFail)
1827
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateCancelStockFail)
1693 1828
 		return
1694 1829
 	}
1695 1830
 
@@ -1703,11 +1838,13 @@ func (c *StockDrugApiController) GetAllConfig() {
1703 1838
 	adminUserInfo := c.GetAdminUserInfo()
1704 1839
 	manufacturer, _ := service.FindAllManufacturer(adminUserInfo.CurrentOrgId)
1705 1840
 	dealer, _ := service.FindAllDealer(adminUserInfo.CurrentOrgId)
1841
+	stockIns, _ := service.FindStockInNumber(adminUserInfo.CurrentOrgId)
1706 1842
 	drugs, _ := service.GetDrugs(adminUserInfo.CurrentOrgId)
1707 1843
 	c.ServeSuccessJSON(map[string]interface{}{
1708 1844
 		"manufacturer": manufacturer,
1709 1845
 		"dealer":       dealer,
1710 1846
 		"drugs":        drugs,
1847
+		"numbers":      stockIns,
1711 1848
 	})
1712 1849
 }
1713 1850
 
@@ -1724,3 +1861,20 @@ func (c *StockDrugApiController) GetAllDrugStock() {
1724 1861
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1725 1862
 	}
1726 1863
 }
1864
+
1865
+func (c *StockDrugApiController) GetDrugQueryInfo() {
1866
+	page, _ := c.GetInt64("page", -1)
1867
+	limit, _ := c.GetInt64("limit", -1)
1868
+	keyword := c.GetString("keyword")
1869
+
1870
+	adminUserInfo := c.GetAdminUserInfo()
1871
+	list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword)
1872
+	if err == nil {
1873
+		c.ServeSuccessJSON(map[string]interface{}{
1874
+			"list":  list,
1875
+			"total": total,
1876
+		})
1877
+	} else {
1878
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
1879
+	}
1880
+}

+ 54 - 0
controllers/gobal_config_api_controller.go View File

@@ -29,7 +29,10 @@ type GobalConfigApiController struct {
29 29
 
30 30
 func GobalConfigRegistRouters() {
31 31
 	beego.Router("/api/stock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostStockConfig")
32
+	beego.Router("/api/drugstock/automaticreduce/isopen", &GobalConfigApiController{}, "post:PostDrugStockConfig")
33
+
32 34
 	beego.Router("/api/automaticreduce/get", &GobalConfigApiController{}, "get:GetConfig")
35
+	beego.Router("/api/drugstockautomaticreduce/get", &GobalConfigApiController{}, "get:GetDrugStockConfig")
33 36
 
34 37
 	beego.Router("/api/print/template/commit", &GobalConfigApiController{}, "post:PostPrintTemplateTwo")
35 38
 
@@ -113,6 +116,49 @@ func (c *GobalConfigApiController) PostStockConfig() {
113 116
 	return
114 117
 }
115 118
 
119
+func (c *GobalConfigApiController) PostDrugStockConfig() {
120
+	is_open, _ := c.GetInt64("is_open", 0)
121
+	adminUserInfo := c.GetAdminUserInfo()
122
+	org_id := adminUserInfo.CurrentOrgId
123
+	config := models.DrugStockConfig{
124
+		OrgId:      org_id,
125
+		IsOpen:     is_open,
126
+		Status:     1,
127
+		CreateTime: time.Now().Unix(),
128
+		UpdateTime: time.Now().Unix(),
129
+	}
130
+
131
+	errs, configs := service.FindDrugStockAutomaticReduceRecordByOrgId(org_id)
132
+
133
+	if errs == gorm.ErrRecordNotFound {
134
+		err := service.CreateDrugAutomaticReduceRecord(&config)
135
+		if err != nil {
136
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
137
+			return
138
+		}
139
+
140
+	} else if errs == nil {
141
+		modifyConfig := models.DrugStockConfig{
142
+			ID:         configs.ID,
143
+			OrgId:      org_id,
144
+			IsOpen:     is_open,
145
+			Status:     1,
146
+			CreateTime: time.Now().Unix(),
147
+			UpdateTime: time.Now().Unix(),
148
+		}
149
+		err := service.UpdateDrugStockAutomaticReduceRecord(&modifyConfig)
150
+		if err != nil {
151
+			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateConfig)
152
+			return
153
+		}
154
+	}
155
+	c.ServeSuccessJSON(map[string]interface{}{
156
+		"is_open": is_open,
157
+	})
158
+
159
+	return
160
+}
161
+
116 162
 func (c *GobalConfigApiController) GetConfig() {
117 163
 	adminUserInfo := c.GetAdminUserInfo()
118 164
 	_, config := service.FindAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
@@ -121,6 +167,14 @@ func (c *GobalConfigApiController) GetConfig() {
121 167
 	})
122 168
 }
123 169
 
170
+func (c *GobalConfigApiController) GetDrugStockConfig() {
171
+	adminUserInfo := c.GetAdminUserInfo()
172
+	_, config := service.FindDrugStockAutomaticReduceRecordByOrgId(adminUserInfo.CurrentOrgId)
173
+	c.ServeSuccessJSON(map[string]interface{}{
174
+		"config": config,
175
+	})
176
+}
177
+
124 178
 func (c *GobalConfigApiController) PostPrintTemplate() {
125 179
 	template_id, _ := c.GetInt64("template_id", 0)
126 180
 	adminUserInfo := c.GetAdminUserInfo()

+ 24 - 19
controllers/manager_center_api_controller.go View File

@@ -345,6 +345,7 @@ func (c *ManagerCenterApiController) GetBaseDrugLibList() {
345 345
 }
346 346
 
347 347
 func (c *ManagerCenterApiController) CreateMedicineInsurancePercent() {
348
+	module, _ := c.GetInt64("module", 0)
348 349
 	adminInfo := c.GetAdminUserInfo()
349 350
 	dataBody := make(map[string]interface{}, 0)
350 351
 	err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
@@ -356,43 +357,46 @@ func (c *ManagerCenterApiController) CreateMedicineInsurancePercent() {
356 357
 
357 358
 	var mips []*models.MedicineInsurancePercentage
358 359
 	var errs error
360
+	record_time := time.Now().Unix()
359 361
 
360 362
 	if dataBody["mip"] != nil && reflect.TypeOf(dataBody["mip"]).String() == "[]interface {}" {
361
-		thisCancelStock, _ := dataBody["cancelStock"].([]interface{})
362
-		if len(thisCancelStock) > 0 {
363
-			for _, item := range thisCancelStock {
363
+		mip_map, _ := dataBody["mip"].([]interface{})
364
+		if len(mip_map) > 0 {
365
+			for _, item := range mip_map {
364 366
 				items := item.(map[string]interface{})
365 367
 
366
-				if items["drug_id"] == nil || reflect.TypeOf(items["drug_id"]).String() != "float64" {
367
-					utils.ErrorLog("drug_id")
368
+				if items["type_id"] == nil || reflect.TypeOf(items["type_id"]).String() != "float64" {
369
+					utils.ErrorLog("type_id")
368 370
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
369 371
 					return
370 372
 				}
371
-				drug_id := int64(items["drug_id"].(float64))
373
+				type_id := int64(items["type_id"].(float64))
372 374
 
373
-				if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
374
-					utils.ErrorLog("type")
375
+				if items["medicine_insurance_type"] == nil || reflect.TypeOf(items["medicine_insurance_type"]).String() != "float64" {
376
+					utils.ErrorLog("medicine_insurance_type")
375 377
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
376 378
 					return
377 379
 				}
378
-				types := int64(items["type"].(float64))
380
+				types := int64(items["medicine_insurance_type"].(float64))
379 381
 
380
-				if items["percent"] == nil || reflect.TypeOf(items["percent"]).String() != "float64" {
382
+				if items["percent"] == nil || reflect.TypeOf(items["percent"]).String() != "string" {
381 383
 					utils.ErrorLog("percent")
382 384
 					c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
383 385
 					return
384 386
 				}
385
-				percent := items["percent"].(float64)
386
-
387
+				percent, _ := strconv.ParseFloat(items["percent"].(string), 64)
388
+				//percent := items["percent"].(float64)
387 389
 				mip_temp := &models.MedicineInsurancePercentage{
388
-					DrugId:                drug_id,
390
+					TypeId:                type_id,
389 391
 					Status:                1,
390 392
 					Ctime:                 time.Now().Unix(),
391 393
 					Mtime:                 time.Now().Unix(),
392
-					RecordTime:            time.Now().Unix(),
394
+					RecordTime:            record_time,
393 395
 					MedicineInsuranceType: types,
394 396
 					UserOrgId:             adminInfo.CurrentOrgId,
395 397
 					Percent:               percent,
398
+					Module:                module,
399
+					GoodId:                0,
396 400
 				}
397 401
 				mips = append(mips, mip_temp)
398 402
 
@@ -401,7 +405,6 @@ func (c *ManagerCenterApiController) CreateMedicineInsurancePercent() {
401 405
 
402 406
 		for _, item := range mips {
403 407
 			errs = service.CreateMedicineInsurancePercentage(item)
404
-
405 408
 		}
406 409
 	}
407 410
 
@@ -1233,7 +1236,7 @@ func (c *ManagerCenterApiController) CreateGoodInfo() {
1233 1236
 	is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
1234 1237
 	is_record, _ := c.GetInt64("is_record")
1235 1238
 	statistics_category, _ := c.GetInt64("statistics_category")
1236
-	good_status, _ := c.GetInt64("good_status")
1239
+	good_status := c.GetString("good_status")
1237 1240
 
1238 1241
 	default_count, _ := c.GetInt64("default_count")
1239 1242
 	sign, _ := c.GetInt64("sign")
@@ -1333,7 +1336,7 @@ func (c *ManagerCenterApiController) ModifyGoodInfo() {
1333 1336
 	is_special_diseases, _ := c.GetInt64("is_special_diseases", 0)
1334 1337
 	is_record, _ := c.GetInt64("is_record")
1335 1338
 	statistics_category, _ := c.GetInt64("statistics_category")
1336
-	good_status, _ := c.GetInt64("good_status")
1339
+	good_status := c.GetString("good_status")
1337 1340
 
1338 1341
 	default_count, _ := c.GetInt64("default_count")
1339 1342
 	sign, _ := c.GetInt64("sign")
@@ -1472,8 +1475,10 @@ func (c *ManagerCenterApiController) GetGoodInfoById() {
1472 1475
 
1473 1476
 func (c *ManagerCenterApiController) GetMedicineInsurancePercent() {
1474 1477
 	adminUser := c.GetAdminUserInfo()
1475
-	drug_id, _ := c.GetInt64("drug_id", 0)
1476
-	mip, err := service.GetLastMedicineInsurance(adminUser.CurrentOrgId, drug_id)
1478
+	type_id, _ := c.GetInt64("type_id", 0)
1479
+	module, _ := c.GetInt64("module", 0)
1480
+
1481
+	mip, err := service.GetLastMedicineInsurance(adminUser.CurrentOrgId, type_id, module)
1477 1482
 	if err == nil {
1478 1483
 		c.ServeSuccessJSON(map[string]interface{}{
1479 1484
 			"mip": mip,

+ 3 - 3
controllers/stock_in_api_controller.go View File

@@ -1534,7 +1534,7 @@ func (c *StockManagerApiController) GetCancelStockInfoList() {
1534 1534
 	id, _ := c.GetInt64("id", 0)
1535 1535
 
1536 1536
 	cancelStockInfoList, _ := service.FindCancelStockInfoById(id)
1537
-	info, _ := service.FindCancelStockById(id)
1537
+	info, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
1538 1538
 
1539 1539
 	c.ServeSuccessJSON(map[string]interface{}{
1540 1540
 		"list": cancelStockInfoList,
@@ -1643,7 +1643,7 @@ func (c *StockManagerApiController) EditCancelStock() {
1643 1643
 		return
1644 1644
 	}
1645 1645
 
1646
-	cancelStock, _ := service.FindCancelStockById(id)
1646
+	cancelStock, _ := service.FindCancelStockById(id, c.GetAdminUserInfo().CurrentOrgId)
1647 1647
 
1648 1648
 	tempCancelStock := models.CancelStock{
1649 1649
 		ID:           cancelStock.ID,
@@ -1776,7 +1776,7 @@ func (c *StockManagerApiController) GetQueryInfo() {
1776 1776
 	keyword := c.GetString("keyword")
1777 1777
 
1778 1778
 	adminUserInfo := c.GetAdminUserInfo()
1779
-	list, total, err := service.FindAllStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword)
1779
+	list, total, err := service.FindAllDrugStockInfo(adminUserInfo.CurrentOrgId, page, limit, keyword)
1780 1780
 	if err == nil {
1781 1781
 		c.ServeSuccessJSON(map[string]interface{}{
1782 1782
 			"list":  list,

+ 6 - 0
enums/error_code.go View File

@@ -130,6 +130,12 @@ const ( // ErrorCode
130 130
 
131 131
 	ErrorCodeCreateStockInFail = 20001
132 132
 
133
+	ErrorCodeCreateReturnFail = 50001
134
+
135
+	ErrorCodeCreateStockOutFail = 50002
136
+
137
+	ErrorCodeCreateCancelStockFail = 50003
138
+
133 139
 	ErrorCodeScheduleTemplateNotExist = 10001
134 140
 
135 141
 	ErrorCodeSystemError  = 6666

+ 3 - 1
models/drug.go View File

@@ -82,8 +82,10 @@ type MedicineInsurancePercentage struct {
82 82
 	Status                int64   `gorm:"column:status" json:"status" form:"status"`
83 83
 	Ctime                 int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
84 84
 	Mtime                 int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
85
-	DrugId                int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
85
+	TypeId                int64   `gorm:"column:type_id" json:"drug_id" form:"type_id"`
86 86
 	RecordTime            int64   `gorm:"column:record_time" json:"record_time" form:"record_time"`
87
+	Module                int64   `gorm:"column:module" json:"module" form:"module"`
88
+	GoodId                int64   `gorm:"column:good_id" json:"good_id" form:"good_id"`
87 89
 }
88 90
 
89 91
 func (MedicineInsurancePercentage) TableName() string {

+ 47 - 41
models/drug_stock.go View File

@@ -49,21 +49,23 @@ func (DrugWarehouseInfo) TableName() string {
49 49
 }
50 50
 
51 51
 type DrugWarehouseOut struct {
52
-	ID                      int64  `gorm:"column:id" json:"id" form:"id"`
53
-	WarehouseOutOrderNumber string `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
54
-	OperationTime           int64  `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
55
-	Creater                 int64  `gorm:"column:creater" json:"creater" form:"creater"`
56
-	OrgId                   int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
57
-	Modifier                int64  `gorm:"column:modifier" json:"modifier" form:"modifier"`
58
-	Remark                  string `gorm:"column:remark" json:"remark" form:"remark"`
59
-	Ctime                   int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
60
-	Mtime                   int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
61
-	Status                  int64  `gorm:"column:status" json:"status" form:"status"`
62
-	WarehouseOutTime        int64  `gorm:"column:warehouse_out_time" json:"warehouse_out_time" form:"warehouse_out_time"`
63
-	Dealer                  int64  `gorm:"column:dealer" json:"dealer" form:"dealer"`
64
-	Manufacturer            int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
65
-	Type                    int64  `gorm:"column:type" json:"type" form:"type"`
66
-	IsSys                   int64  `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
52
+	ID                      int64         `gorm:"column:id" json:"id" form:"id"`
53
+	WarehouseOutOrderNumber string        `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
54
+	OperationTime           int64         `gorm:"column:operation_time" json:"operation_time" form:"operation_time"`
55
+	Creater                 int64         `gorm:"column:creater" json:"creater" form:"creater"`
56
+	OrgId                   int64         `gorm:"column:org_id" json:"org_id" form:"org_id"`
57
+	Modifier                int64         `gorm:"column:modifier" json:"modifier" form:"modifier"`
58
+	Remark                  string        `gorm:"column:remark" json:"remark" form:"remark"`
59
+	Ctime                   int64         `gorm:"column:ctime" json:"ctime" form:"ctime"`
60
+	Mtime                   int64         `gorm:"column:mtime" json:"mtime" form:"mtime"`
61
+	Status                  int64         `gorm:"column:status" json:"status" form:"status"`
62
+	WarehouseOutTime        int64         `gorm:"column:warehouse_out_time" json:"warehouse_out_time" form:"warehouse_out_time"`
63
+	Dealer                  int64         `gorm:"column:dealer" json:"dealer" form:"dealer"`
64
+	Manufacturer            int64         `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
65
+	Type                    int64         `gorm:"column:type" json:"type" form:"type"`
66
+	IsSys                   int64         `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
67
+	Manufacturers           *Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
68
+	Dealers                 *Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
67 69
 }
68 70
 
69 71
 func (DrugWarehouseOut) TableName() string {
@@ -101,19 +103,21 @@ func (DrugWarehouseOutInfo) TableName() string {
101 103
 }
102 104
 
103 105
 type DrugSalesReturn struct {
104
-	ID           int64  `gorm:"column:id" json:"id" form:"id"`
105
-	OrderNumber  string `gorm:"column:order_number" json:"order_number" form:"order_number"`
106
-	OperaTime    int64  `gorm:"column:opera_time" json:"opera_time" form:"opera_time"`
107
-	Total        int64  `gorm:"column:total" json:"total" form:"total"`
108
-	Creater      int64  `gorm:"column:creater" json:"creater" form:"creater"`
109
-	Ctime        int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
110
-	Mtime        int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
111
-	Status       int64  `gorm:"column:status" json:"status" form:"status"`
112
-	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
113
-	ReturnTime   int64  `gorm:"column:return_time" json:"return_time" form:"return_time"`
114
-	Manufacturer int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
115
-	Dealer       int64  `gorm:"column:dealer" json:"dealer" form:"dealer"`
116
-	Type         int64  `gorm:"column:type" json:"type" form:"type"`
106
+	ID            int64         `gorm:"column:id" json:"id" form:"id"`
107
+	OrderNumber   string        `gorm:"column:order_number" json:"order_number" form:"order_number"`
108
+	OperaTime     int64         `gorm:"column:opera_time" json:"opera_time" form:"opera_time"`
109
+	Total         int64         `gorm:"column:total" json:"total" form:"total"`
110
+	Creater       int64         `gorm:"column:creater" json:"creater" form:"creater"`
111
+	Ctime         int64         `gorm:"column:ctime" json:"ctime" form:"ctime"`
112
+	Mtime         int64         `gorm:"column:mtime" json:"mtime" form:"mtime"`
113
+	Status        int64         `gorm:"column:status" json:"status" form:"status"`
114
+	OrgId         int64         `gorm:"column:org_id" json:"org_id" form:"org_id"`
115
+	ReturnTime    int64         `gorm:"column:return_time" json:"return_time" form:"return_time"`
116
+	Manufacturer  int64         `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
117
+	Dealer        int64         `gorm:"column:dealer" json:"dealer" form:"dealer"`
118
+	Type          int64         `gorm:"column:type" json:"type" form:"type"`
119
+	Manufacturers *Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
120
+	Dealers       *Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
117 121
 }
118 122
 
119 123
 func (DrugSalesReturn) TableName() string {
@@ -147,19 +151,21 @@ func (DrugSalesReturnInfo) TableName() string {
147 151
 }
148 152
 
149 153
 type DrugCancelStock struct {
150
-	ID           int64  `gorm:"column:id" json:"id" form:"id"`
151
-	OrderNumber  string `gorm:"column:order_number" json:"order_number" form:"order_number"`
152
-	OperaTime    int64  `gorm:"column:opera_time" json:"opera_time" form:"opera_time"`
153
-	Total        int64  `gorm:"column:total" json:"total" form:"total"`
154
-	Creater      int64  `gorm:"column:creater" json:"creater" form:"creater"`
155
-	Ctime        int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
156
-	Mtime        int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
157
-	Status       int64  `gorm:"column:status" json:"status" form:"status"`
158
-	OrgId        int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
159
-	ReturnTime   int64  `gorm:"column:return_time" json:"return_time" form:"return_time"`
160
-	Dealer       int64  `gorm:"column:dealer" json:"dealer" form:"dealer"`
161
-	Manufacturer int64  `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
162
-	Type         int64  `gorm:"column:type" json:"type" form:"type"`
154
+	ID            int64         `gorm:"column:id" json:"id" form:"id"`
155
+	OrderNumber   string        `gorm:"column:order_number" json:"order_number" form:"order_number"`
156
+	OperaTime     int64         `gorm:"column:opera_time" json:"opera_time" form:"opera_time"`
157
+	Total         int64         `gorm:"column:total" json:"total" form:"total"`
158
+	Creater       int64         `gorm:"column:creater" json:"creater" form:"creater"`
159
+	Ctime         int64         `gorm:"column:ctime" json:"ctime" form:"ctime"`
160
+	Mtime         int64         `gorm:"column:mtime" json:"mtime" form:"mtime"`
161
+	Status        int64         `gorm:"column:status" json:"status" form:"status"`
162
+	OrgId         int64         `gorm:"column:org_id" json:"org_id" form:"org_id"`
163
+	ReturnTime    int64         `gorm:"column:return_time" json:"return_time" form:"return_time"`
164
+	Dealer        int64         `gorm:"column:dealer" json:"dealer" form:"dealer"`
165
+	Manufacturer  int64         `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
166
+	Type          int64         `gorm:"column:type" json:"type" form:"type"`
167
+	Manufacturers *Manufacturer `gorm:"ForeignKey:Manufacturer;AssociationForeignKey:ID" json:"manufacturers"`
168
+	Dealers       *Dealer       `gorm:"ForeignKey:Dealer;AssociationForeignKey:ID" json:"dealers"`
163 169
 }
164 170
 
165 171
 func (DrugCancelStock) TableName() string {

+ 13 - 0
models/gobal_models.go View File

@@ -14,6 +14,19 @@ func (GobalConfig) TableName() string {
14 14
 	return "xt_gobal_config"
15 15
 }
16 16
 
17
+type DrugStockConfig struct {
18
+	ID         int64 `gorm:"column:id" json:"id" form:"id"`
19
+	OrgId      int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
20
+	IsOpen     int64 `gorm:"column:is_open" json:"is_open" form:"is_open"`
21
+	Status     int64 `gorm:"column:status" json:"status" form:"status"`
22
+	CreateTime int64 `gorm:"column:create_time" json:"create_time" form:"create_time"`
23
+	UpdateTime int64 `gorm:"column:update_time" json:"update_time" form:"update_time"`
24
+}
25
+
26
+func (DrugStockConfig) TableName() string {
27
+	return "xt_drug_stock_config"
28
+}
29
+
17 30
 type SystemPrescription struct {
18 31
 	ID                         int64   `gorm:"column:id" json:"id" form:"id"`
19 32
 	UserOrgId                  int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`

+ 2 - 2
models/good_models.go View File

@@ -52,7 +52,7 @@ type GoodInfo struct {
52 52
 	IsSpecialDiseases      int64     `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
53 53
 	IsRecord               int64     `gorm:"column:is_record" json:"is_record" form:"is_record"`
54 54
 	StatisticsCategory     int64     `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
55
-	GoodStatus             int64     `gorm:"column:good_status" json:"good_status" form:"good_status"`
55
+	GoodStatus             string    `gorm:"column:good_status" json:"good_status" form:"good_status"`
56 56
 	DefaultCount           int64     `gorm:"column:default_count" json:"default_count" form:"default_count"`
57 57
 	Sign                   int64     `gorm:"column:sign" json:"sign" form:"sign"`
58 58
 	IsDefault              int64     `gorm:"column:is_default" json:"is_default" form:"is_default"`
@@ -63,7 +63,7 @@ type GoodInfo struct {
63 63
 	IsDoctorUse            int64     `gorm:"column:is_doctor_use" json:"is_doctor_use" form:"is_doctor_use"`
64 64
 	Agent                  string    `gorm:"column:agent" json:"agent" form:"agent"`
65 65
 	GoodNumber             string    `gorm:"column:good_number" json:"good_number" form:"good_number"`
66
-	GoodsType              GoodsType `gorm:"ForeignKey:ID;AssociationForeignKey:GoodTypeId" `
66
+	GoodsType              GoodsType `gorm:"ForeignKey:ID;AssociationForeignKey:GoodTypeId" json:"type"`
67 67
 }
68 68
 
69 69
 func (GoodInfo) TableName() string {

+ 68 - 4
service/drug_stock_service.go View File

@@ -1,6 +1,9 @@
1 1
 package service
2 2
 
3
-import "XT_New/models"
3
+import (
4
+	"XT_New/models"
5
+	"github.com/jinzhu/gorm"
6
+)
4 7
 
5 8
 type DrugConfig struct {
6 9
 	ID           int64        `gorm:"column:id" json:"id" form:"id"`
@@ -13,6 +16,8 @@ type DrugConfig struct {
13 16
 	OrgId        int64        `gorm:"column:org_id" json:"org_id" form:"org_id"`
14 17
 	Manufacturer int64        `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
15 18
 	DrugSpecs    []DrugConfig `gorm:"ForeignKey:DrugName;AssociationForeignKey:DrugName" json:"drug_specs"`
19
+	RetailPrice  float64      `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
20
+	LastPrice    float64      `gorm:"column:last_price" json:"last_price" form:"last_price"`
16 21
 }
17 22
 
18 23
 func (DrugConfig) TableName() string {
@@ -40,9 +45,68 @@ type MedicineInsuranceDate struct {
40 45
 	RecordTime int64
41 46
 }
42 47
 
43
-func GetLastMedicineInsurance(orgID int64, drug_id int64) (mip []*models.MedicineInsurancePercentage, err error) {
48
+func GetLastMedicineInsurance(orgID int64, type_id int64, module int64) (mip []*models.MedicineInsurancePercentage, err error) {
44 49
 	var mip_other models.MedicineInsurancePercentage
45
-	err = readDb.Model(&models.MedicineInsurancePercentage{}).Where("user_org_id = ? AND status=1 AND  drug_id = ?", orgID, drug_id).Last(&mip_other).Error
46
-	err = readDb.Model(&models.MedicineInsurancePercentage{}).Where("user_org_id = ? AND status=1 AND record_time = ? AND drug_id = ?", orgID, mip_other.RecordTime, drug_id).Find(&mip).Error
50
+	err = readDb.Model(&models.MedicineInsurancePercentage{}).Where("user_org_id = ? AND status=1 AND  type_id = ? AND module = ?", orgID, type_id, module).Last(&mip_other).Error
51
+	err = readDb.Model(&models.MedicineInsurancePercentage{}).Where("user_org_id = ? AND status=1 AND record_time = ? AND type_id = ? AND module = ?", orgID, mip_other.RecordTime, type_id, module).Find(&mip).Error
52
+	return
53
+}
54
+
55
+type DrugWarehouseInfo struct {
56
+	ID     int64  `gorm:"column:id" json:"id" form:"id"`
57
+	Number string `gorm:"column:number" json:"number" form:"number"`
58
+	Status int64  `gorm:"column:status" json:"status" form:"status"`
59
+	OrgId  int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
60
+}
61
+
62
+func (DrugWarehouseInfo) TableName() string {
63
+	return "xt_drug_warehouse_info"
64
+}
65
+func FindStockInNumber(orgId int64) (stockIns []*DrugWarehouseInfo, err error) {
66
+	err = readDb.Model(&DrugWarehouseInfo{}).Where("org_id = ? AND status = 1", orgId).Group("number").Find(&stockIns).Error
67
+	return
68
+}
69
+
70
+type DrugStockInfo struct {
71
+	ID          int64   `gorm:"column:id" json:"id" form:"id"`
72
+	DrugName    string  `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
73
+	DrugSpec    string  `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
74
+	RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
75
+	LastPrice   float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
76
+	DrugStatus  string  `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
77
+	Status      int64   `gorm:"column:status" json:"status" form:"status"`
78
+	Ctime       int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
79
+	Mtime       int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
80
+	OrgId       int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
81
+	DrugCode    string  `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
82
+
83
+	QueryWarehousingInfo  []models.DrugWarehouseInfo    `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"query_drug_warehousing_info"`
84
+	QuerySalesReturnInfo  []models.DrugSalesReturnInfo  `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"query_drug_sales_return_info"`
85
+	QueryWarehouseOutInfo []models.DrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"query_drug_warehouseout_info"`
86
+	QueryCancelStockInfo  []models.DrugCancelStockInfo  `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"query_drug_cancel_stock_info"`
87
+}
88
+
89
+func (DrugStockInfo) TableName() string {
90
+	return "xt_base_drug"
91
+}
92
+
93
+func FindAllDrugStockInfo(orgId int64, page int64, limit int64, keyword string) (list []*DrugStockInfo, total int64, err error) {
94
+	db := readDb.Model(&DrugStockInfo{})
95
+	db = db.Where("xt_base_drug.org_id = ? AND xt_base_drug.status = 1", orgId)
96
+	db = db.Preload("QueryWarehousingInfo", func(db *gorm.DB) *gorm.DB {
97
+		return db.Where("org_id = ? AND status = 1", orgId)
98
+	})
99
+	db = db.Preload("QuerySalesReturnInfo", "org_id = ? AND status = 1", orgId)
100
+	db = db.Preload("QueryWarehouseOutInfo", func(db *gorm.DB) *gorm.DB {
101
+		return db.Where("org_id = ? AND status = 1", orgId)
102
+	})
103
+	db = db.Preload("QueryCancelStockInfo", "org_id = ? AND status = 1", orgId)
104
+	if len(keyword) > 0 {
105
+		likeKey := "%" + keyword + "%"
106
+		db = db.Where("xt_base_drug.drug_name LIKE ? OR xt_base_drug.drug_spec LIKE ?", likeKey, likeKey)
107
+	}
108
+	db = db.Count(&total)
109
+	offset := (page - 1) * limit
110
+	err = db.Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
47 111
 	return
48 112
 }

+ 14 - 0
service/gobal_config_service.go View File

@@ -10,16 +10,30 @@ func CreateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
10 10
 	return
11 11
 }
12 12
 
13
+func CreateDrugAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
14
+	err = writeDb.Model(&models.DrugStockConfig{}).Create(config).Error
15
+	return
16
+}
17
+
13 18
 func FindAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.GobalConfig) {
14 19
 	err = readDb.Model(&models.GobalConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
15 20
 	return
16 21
 }
17 22
 
23
+func FindDrugStockAutomaticReduceRecordByOrgId(org_id int64) (err error, config models.DrugStockConfig) {
24
+	err = readDb.Model(&models.DrugStockConfig{}).Where("status = 1 AND org_id = ?", org_id).Find(&config).Error
25
+	return
26
+}
18 27
 func UpdateAutomaticReduceRecord(config *models.GobalConfig) (err error) {
19 28
 	err = writeDb.Save(config).Error
20 29
 	return
21 30
 }
22 31
 
32
+func UpdateDrugStockAutomaticReduceRecord(config *models.DrugStockConfig) (err error) {
33
+	err = writeDb.Save(config).Error
34
+	return
35
+}
36
+
23 37
 func CreatePrintTemplateRecord(template *models.GobalTemplate) (err error) {
24 38
 	err = writeDb.Model(&models.GobalTemplate{}).Create(template).Error
25 39
 	return

+ 113 - 21
service/stock_service.go View File

@@ -224,15 +224,24 @@ func FindGoodInfoList(orgId int64, page int64, limit int64, keyword string, is_u
224 224
 	offset := (page - 1) * limit
225 225
 	db := readDb.Model(&models.GoodInfo{})
226 226
 	db = db.Where("org_id = ? AND status = 1", orgId)
227
+	db = db.Preload("GoodsType", "org_id = ? AND status = 1", orgId)
227 228
 	if len(keyword) > 0 {
228 229
 		likeKey := "%" + keyword + "%"
229 230
 		db = db.Where("good_code LIKE ? OR specification_name LIKE ?", likeKey, likeKey)
230 231
 	} else {
231 232
 		if is_use > 0 {
232
-			db = db.Where("good_status = ?", is_use)
233
+			if is_use == 1 {
234
+				db = db.Where("find_in_set('停用',good_status) = 0")
235
+			} else {
236
+				db = db.Where("find_in_set('停用',good_status) > 0")
237
+			}
233 238
 		}
234 239
 		if is_charge > 0 {
235
-			db = db.Where(" good_status = ?", is_charge)
240
+			if is_charge == 1 {
241
+				db = db.Where("find_in_set('收费',good_status) > 0")
242
+			} else {
243
+				db = db.Where("find_in_set('收费',good_status) = 0")
244
+			}
236 245
 		}
237 246
 		if good_kind > 0 {
238 247
 			db = db.Where(" good_kind = ?", good_kind)
@@ -359,7 +368,7 @@ func CreateDrugWarehousingInfo(warehousingInfo []*models.DrugWarehouseInfo) (err
359 368
 	if len(warehousingInfo) > 0 {
360 369
 		utx := writeDb.Begin()
361 370
 		if len(warehousingInfo) > 0 {
362
-			thisSQL := "INSERT INTO xt_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) VALUES "
371
+			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) VALUES "
363 372
 			insertParams := make([]string, 0)
364 373
 			insertData := make([]interface{}, 0)
365 374
 			for _, info := range warehousingInfo {
@@ -607,7 +616,7 @@ func CreateDrugSalesReturnInfo(salesReturnInfo []*models.DrugSalesReturnInfo) (e
607 616
 	if len(salesReturnInfo) > 0 {
608 617
 		utx := writeDb.Begin()
609 618
 		if len(salesReturnInfo) > 0 {
610
-			thisSQL := "INSERT INTO xt_sales_return_info (drug_id,sales_return_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
619
+			thisSQL := "INSERT INTO xt_drug_sales_return_info (drug_id,sales_return_id, count, price,total,ctime,status,org_id,order_number,type,dealer,manufacturer,retail_price,retail_total_price) VALUES "
611 620
 			insertParams := make([]string, 0)
612 621
 			insertData := make([]interface{}, 0)
613 622
 			for _, info := range salesReturnInfo {
@@ -682,8 +691,8 @@ func FindAllReturnList(orgId int64, page int64, limit int64, startTime int64, en
682 691
 	return
683 692
 }
684 693
 
685
-func FindAllDrugReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.SalesReturn, total int64, err error) {
686
-	db := readDb.Model(&models.SalesReturn{})
694
+func FindAllDrugReturnList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugSalesReturn, total int64, err error) {
695
+	db := readDb.Model(&models.DrugSalesReturn{})
687 696
 	db = db.Where("xt_drug_sales_return.org_id = ? AND xt_drug_sales_return.status = 1 ", orgId)
688 697
 
689 698
 	if len(keywords) > 0 {
@@ -715,8 +724,35 @@ func FindCancelStockInfoById(id int64) (list []*models.CancelStockInfo, err erro
715 724
 	return list, err
716 725
 }
717 726
 
718
-func FindDrugCancelStockInfoById(id int64) (list []*models.DrugCancelStockInfo, err error) {
719
-	err = readDb.Model(&models.DrugCancelStockInfo{}).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
727
+type DrugCancelStockInfo struct {
728
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
729
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
730
+	CancelStockId    int64   `gorm:"column:cancel_stock_id" json:"cancel_stock_id" form:"cancel_stock_id"`
731
+	Count            int64   `gorm:"column:count" json:"count" form:"count"`
732
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
733
+	Total            float64 `gorm:"column:total" json:"total" form:"total"`
734
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
735
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
736
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
737
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
738
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
739
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
740
+	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
741
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
742
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
743
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
744
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
745
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
746
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
747
+	Drug             *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
748
+}
749
+
750
+func (DrugCancelStockInfo) TableName() string {
751
+	return "xt_drug_cancel_stock_info"
752
+}
753
+
754
+func FindDrugCancelStockInfoById(id int64, org_id int64) (list []*DrugCancelStockInfo, err error) {
755
+	err = readDb.Model(&DrugCancelStockInfo{}).Preload("Drug", "status = 1 AND org_id = ? ", org_id).Where("cancel_stock_id = ? AND status = 1", id).Find(&list).Error
720 756
 	return list, err
721 757
 }
722 758
 
@@ -809,7 +845,7 @@ func CreateDrugWarehousingOutInfo(warehouseOutInfo []*models.DrugWarehouseOutInf
809 845
 			insertParams := make([]string, 0)
810 846
 			insertData := make([]interface{}, 0)
811 847
 			for _, info := range warehouseOutInfo {
812
-				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
848
+				insertParams = append(insertParams, "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
813 849
 				insertData = append(insertData, info.WarehouseOutId)
814 850
 				insertData = append(insertData, info.DrugId)
815 851
 				insertData = append(insertData, info.ProductDate)
@@ -878,7 +914,6 @@ func FindAllWarehouseOutList(orgId int64, page int64, limit int64, startTime int
878 914
 	err = db.Offset(offset).Limit(limit).Order("xt_warehouse_out.ctime desc").Find(&list).Error
879 915
 	return list, total, err
880 916
 
881
-	return
882 917
 }
883 918
 
884 919
 func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime int64, endTime int64, types int64, keywords string) (list []*models.DrugWarehouseOut, total int64, err error) {
@@ -903,7 +938,6 @@ func FindAllDrugWarehouseOutList(orgId int64, page int64, limit int64, startTime
903 938
 	err = db.Offset(offset).Limit(limit).Order("xt_drug_warehouse_out.ctime desc").Find(&list).Error
904 939
 	return list, total, err
905 940
 
906
-	return
907 941
 }
908 942
 
909 943
 func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err error) {
@@ -911,8 +945,39 @@ func FindWarehouseOutInfoById(id int64) (list []*models.WarehouseOutInfo, err er
911 945
 	return list, err
912 946
 }
913 947
 
914
-func FindDrugWarehouseOutInfoById(id int64) (list []*models.DrugWarehouseOutInfo, err error) {
915
-	err = readDb.Model(&models.DrugWarehouseOutInfo{}).Where("warehouse_out_id = ? AND status = 1 AND count <> 0 AND good_id <> 0", id).Order("good_type_id desc").Find(&list).Error
948
+type DrugWarehouseOutInfo struct {
949
+	ID                      int64   `gorm:"column:id" json:"id" form:"id"`
950
+	WarehouseOutId          int64   `gorm:"column:warehouse_out_id" json:"warehouse_out_id" form:"warehouse_out_id"`
951
+	DrugId                  int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
952
+	WarehousingOutTarget    int64   `gorm:"column:warehousing_out_target" json:"warehousing_out_target" form:"warehousing_out_target"`
953
+	Count                   int64   `gorm:"column:count" json:"count" form:"count"`
954
+	Price                   float64 `gorm:"column:price" json:"price" form:"price"`
955
+	TotalPrice              float64 `gorm:"column:total_price" json:"total_price" form:"total_price"`
956
+	ProductDate             int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
957
+	ExpiryDate              int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
958
+	Mtime                   int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
959
+	Ctime                   int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
960
+	Status                  int64   `gorm:"column:status" json:"status" form:"status"`
961
+	OrgId                   int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
962
+	Remark                  string  `gorm:"column:remark" json:"remark" form:"remark"`
963
+	IsCancel                int64   `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
964
+	WarehouseOutOrderNumber string  `gorm:"column:warehouse_out_order_number" json:"warehouse_out_order_number" form:"warehouse_out_order_number"`
965
+	Type                    int64   `gorm:"column:type" json:"type" form:"type"`
966
+	Dealer                  int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
967
+	Manufacturer            int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
968
+	IsSys                   int64   `gorm:"column:is_sys" json:"is_sys" form:"is_sys"`
969
+	SysRecordTime           int64   `gorm:"column:sys_record_time" json:"sys_record_time" form:"sys_record_time"`
970
+	RetailPrice             float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
971
+	RetailTotalPrice        float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
972
+	Drug                    *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
973
+}
974
+
975
+func (DrugWarehouseOutInfo) TableName() string {
976
+	return "xt_drug_warehouse_out_info"
977
+}
978
+
979
+func FindDrugWarehouseOutInfoById(id int64, org_id int64) (list []*DrugWarehouseOutInfo, err error) {
980
+	err = readDb.Model(&DrugWarehouseOutInfo{}).Preload("Drug", "status = 1 AND org_id = ?", org_id).Where("warehouse_out_id = ? AND status = 1 ", id).Find(&list).Error
916 981
 	return list, err
917 982
 }
918 983
 
@@ -1188,9 +1253,9 @@ func FindWareHouseOutById(id int64) (*models.WarehouseOut, error) {
1188 1253
 	return warehouseOut, err
1189 1254
 }
1190 1255
 
1191
-func FindDrugWareHouseOutById(id int64) (*models.DrugWarehouseOut, error) {
1256
+func FindDrugWareHouseOutById(id int64, org_id int64) (*models.DrugWarehouseOut, error) {
1192 1257
 	warehouseOut := &models.DrugWarehouseOut{}
1193
-	err := readDb.Model(&models.DrugWarehouseOut{}).Where("id = ? AND status = 1", id).First(&warehouseOut).Error
1258
+	err := readDb.Model(&models.DrugWarehouseOut{}).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(&warehouseOut).Error
1194 1259
 	return warehouseOut, err
1195 1260
 }
1196 1261
 
@@ -1308,8 +1373,35 @@ func FindAllSalesReturnInfoById(id int64) (list []*models.SalesReturnInfo, err e
1308 1373
 	return
1309 1374
 }
1310 1375
 
1311
-func FindAllDrugSalesReturnInfoById(id int64) (list []*models.DrugSalesReturnInfo, err error) {
1312
-	err = readDb.Model(&models.DrugSalesReturnInfo{}).Where("sales_return_id = ? AND status = 1", id).Find(&list).Error
1376
+type DrugSalesReturnInfo struct {
1377
+	ID               int64   `gorm:"column:id" json:"id" form:"id"`
1378
+	DrugId           int64   `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
1379
+	SalesReturnId    int64   `gorm:"column:sales_return_id" json:"sales_return_id" form:"sales_return_id"`
1380
+	Count            int64   `gorm:"column:count" json:"count" form:"count"`
1381
+	Price            float64 `gorm:"column:price" json:"price" form:"price"`
1382
+	Total            float64 `gorm:"column:total" json:"total" form:"total"`
1383
+	ProductDate      int64   `gorm:"column:product_date" json:"product_date" form:"product_date"`
1384
+	ExpiryDate       int64   `gorm:"column:expiry_date" json:"expiry_date" form:"expiry_date"`
1385
+	Ctime            int64   `gorm:"column:ctime" json:"ctime" form:"ctime"`
1386
+	Mtime            int64   `gorm:"column:mtime" json:"mtime" form:"mtime"`
1387
+	Status           int64   `gorm:"column:status" json:"status" form:"status"`
1388
+	OrgId            int64   `gorm:"column:org_id" json:"org_id" form:"org_id"`
1389
+	OrderNumber      string  `gorm:"column:order_number" json:"order_number" form:"order_number"`
1390
+	Type             int64   `gorm:"column:type" json:"type" form:"type"`
1391
+	Dealer           int64   `gorm:"column:dealer" json:"dealer" form:"dealer"`
1392
+	Manufacturer     int64   `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
1393
+	RetailPrice      float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
1394
+	RetailTotalPrice float64 `gorm:"column:retail_total_price" json:"retail_total_price" form:"retail_total_price"`
1395
+	Number           string  `gorm:"column:number" json:"number" form:"number"`
1396
+	Drug             *Drug   `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"drug"`
1397
+}
1398
+
1399
+func (DrugSalesReturnInfo) TableName() string {
1400
+	return "xt_drug_sales_return_info"
1401
+}
1402
+
1403
+func FindAllDrugSalesReturnInfoById(id int64, org_id int64) (list []*DrugSalesReturnInfo, err error) {
1404
+	err = readDb.Model(&DrugSalesReturnInfo{}).Preload("Drug", "status = 1 AND org_id = ?", org_id).Where("sales_return_id = ? AND status = 1 AND org_id = ?", id, org_id).Find(&list).Error
1313 1405
 	return
1314 1406
 }
1315 1407
 
@@ -1318,8 +1410,8 @@ func FindAllSalesReturnById(id int64) (salesReturn models.SalesReturn, err error
1318 1410
 	return
1319 1411
 }
1320 1412
 
1321
-func FindAllDrugSalesReturnById(id int64) (salesReturn models.DrugSalesReturn, err error) {
1322
-	err = readDb.Model(&models.DrugSalesReturn{}).Where("id = ? AND status = 1", id).First(&salesReturn).Error
1413
+func FindAllDrugSalesReturnById(id int64, org_id int64) (salesReturn models.DrugSalesReturn, err error) {
1414
+	err = readDb.Model(&models.DrugSalesReturn{}).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(&salesReturn).Error
1323 1415
 	return
1324 1416
 }
1325 1417
 
@@ -1520,8 +1612,8 @@ func EditDrugCancelStock(sales models.DrugCancelStock) {
1520 1612
 
1521 1613
 }
1522 1614
 
1523
-func FindCancelStockById(id int64) (cancelStock models.CancelStock, err error) {
1524
-	err = readDb.Model(&models.CancelStock{}).Where("id = ? AND status = 1", id).First(&cancelStock).Error
1615
+func FindCancelStockById(id int64, org_id int64) (cancelStock models.CancelStock, err error) {
1616
+	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
1525 1617
 	return cancelStock, err
1526 1618
 
1527 1619
 }