陈少旭 4 months ago
parent
commit
7be055d9ef
3 changed files with 117 additions and 73 deletions
  1. 108 66
      controllers/sg/his_api_controller.go
  2. 6 4
      models/new_stock_models.go
  3. 3 3
      service/his_service.go

+ 108 - 66
controllers/sg/his_api_controller.go View File

20
 	"gdyb/utils"
20
 	"gdyb/utils"
21
 	"github.com/astaxie/beego"
21
 	"github.com/astaxie/beego"
22
 	"github.com/axgle/mahonia"
22
 	"github.com/axgle/mahonia"
23
+	"github.com/go-ole/go-ole/oleutil"
23
 	"github.com/gorilla/websocket"
24
 	"github.com/gorilla/websocket"
24
 	"github.com/jinzhu/gorm"
25
 	"github.com/jinzhu/gorm"
25
 	"github.com/shopspring/decimal"
26
 	"github.com/shopspring/decimal"
26
-	"github.com/go-ole/go-ole"
27
-	"github.com/go-ole/go-ole/oleutil"
28
 	"io"
27
 	"io"
29
 	"io/ioutil"
28
 	"io/ioutil"
30
 	//"math"
29
 	//"math"
215
 
214
 
216
 	struct3508.FixmedinsCode = miConfig.Code
215
 	struct3508.FixmedinsCode = miConfig.Code
217
 
216
 
218
-
219
 	struct3508.AccessKey = miConfig.AccessKey
217
 	struct3508.AccessKey = miConfig.AccessKey
220
 	struct3508.Opter = curRoles.UserName
218
 	struct3508.Opter = curRoles.UserName
221
 	struct3508.RequestUrl = miConfig.Url
219
 	struct3508.RequestUrl = miConfig.Url
701
 				drug.PcDate = time.Now().Format("2006-01-02")
699
 				drug.PcDate = time.Now().Format("2006-01-02")
702
 				err := service.SaveW(drug)
700
 				err := service.SaveW(drug)
703
 				if err == nil {
701
 				if err == nil {
702
+					bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(drug.ID, 10) + "-" + "3502"
704
 					var struct3502 models.Struct3502
703
 					var struct3502 models.Struct3502
705
 					struct3502.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
704
 					struct3502.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
706
 					struct3502.FixmedinsHilistId = miConfig.Code
705
 					struct3502.FixmedinsHilistId = miConfig.Code
723
 					struct3502.SecretKey = miConfig.SecretKey
722
 					struct3502.SecretKey = miConfig.SecretKey
724
 					struct3502.Memo = ""
723
 					struct3502.Memo = ""
725
 					struct3502.InvChgType = "108"
724
 					struct3502.InvChgType = "108"
726
-					struct3502.FixmedinsBchno = drug.Bchno
725
+					struct3502.FixmedinsBchno = bg_number
727
 					struct3502.Cnt = strconv.FormatInt(drug.WarehousingCount, 10)
726
 					struct3502.Cnt = strconv.FormatInt(drug.WarehousingCount, 10)
728
 					struct3502.Pric = fmt.Sprintf("%.2f", drug.BaseDrugLib.RetailPrice)
727
 					struct3502.Pric = fmt.Sprintf("%.2f", drug.BaseDrugLib.RetailPrice)
729
 					result11, result22, _ := service.FJyb3502(struct3502)
728
 					result11, result22, _ := service.FJyb3502(struct3502)
749
 						})
748
 						})
750
 					} else {
749
 					} else {
751
 						drug.IsBg = 1
750
 						drug.IsBg = 1
751
+						drug.BgBchno = bg_number
752
 						service.SaveW(drug)
752
 						service.SaveW(drug)
753
 					}
753
 					}
754
 				}
754
 				}
760
 		//变更
760
 		//变更
761
 		if drug.IsPc == 1 && drug.IsBg == 0 {
761
 		if drug.IsPc == 1 && drug.IsBg == 0 {
762
 			var res3 ResultSix
762
 			var res3 ResultSix
763
+			bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(drug.ID, 10) + "-" + "3502"
763
 
764
 
764
 			var struct3502 models.Struct3502
765
 			var struct3502 models.Struct3502
765
 			struct3502.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
766
 			struct3502.MedListCodg = drug.BaseDrugLib.MedicalInsuranceNumber
784
 			struct3502.SignKey = miConfig.SignKey
785
 			struct3502.SignKey = miConfig.SignKey
785
 			struct3502.SecretKey = miConfig.SecretKey
786
 			struct3502.SecretKey = miConfig.SecretKey
786
 
787
 
787
-			struct3502.FixmedinsBchno = drug.Bchno
788
+			struct3502.FixmedinsBchno = bg_number
788
 			struct3502.Cnt = strconv.FormatInt(drug.WarehousingCount, 10)
789
 			struct3502.Cnt = strconv.FormatInt(drug.WarehousingCount, 10)
789
 			struct3502.Pric = fmt.Sprintf("%.2f", drug.BaseDrugLib.RetailPrice)
790
 			struct3502.Pric = fmt.Sprintf("%.2f", drug.BaseDrugLib.RetailPrice)
790
 			result1, result2, _ := service.FJyb3502(struct3502)
791
 			result1, result2, _ := service.FJyb3502(struct3502)
805
 				errs = append(errs, "变更"+drug.BaseDrugLib.DrugName+",出错:"+res3.ErrMsg)
806
 				errs = append(errs, "变更"+drug.BaseDrugLib.DrugName+",出错:"+res3.ErrMsg)
806
 			} else {
807
 			} else {
807
 				drug.IsBg = 1
808
 				drug.IsBg = 1
808
-				//drug.Bchno = number
809
-				//drug.PcDate = time.Now().Format("2006-01-02")
809
+				drug.BgBchno = bg_number
810
 				service.SaveW(drug)
810
 				service.SaveW(drug)
811
 			}
811
 			}
812
 		}
812
 		}
890
 					struct3507_2.Enckey = miConfig.EncKey
890
 					struct3507_2.Enckey = miConfig.EncKey
891
 					struct3507_2.SignKey = miConfig.SignKey
891
 					struct3507_2.SignKey = miConfig.SignKey
892
 					struct3507_2.SecretKey = miConfig.SecretKey
892
 					struct3507_2.SecretKey = miConfig.SecretKey
893
-					struct3507_2.FixmedinsBchno = item.Bchno
893
+					struct3507_2.FixmedinsBchno = item.BgBchno
894
 					struct3507_2.InvDataType = "2"
894
 					struct3507_2.InvDataType = "2"
895
 					result11, result22, _ := service.FJyb3507(struct3507_2)
895
 					result11, result22, _ := service.FJyb3507(struct3507_2)
896
 					saveLog(result11, result22, "3507", "3507")
896
 					saveLog(result11, result22, "3507", "3507")
910
 					if res2.Infcode != -1 {
910
 					if res2.Infcode != -1 {
911
 						item.IsBg = 0
911
 						item.IsBg = 0
912
 						item.Bchno = ""
912
 						item.Bchno = ""
913
+						item.BgBchno = ""
913
 						item.PcDate = ""
914
 						item.PcDate = ""
914
 						service.SaveW(item)
915
 						service.SaveW(item)
915
 					} else {
916
 					} else {
926
 			var res FJ3507Result
927
 			var res FJ3507Result
927
 			var struct3507 models.Struct3507
928
 			var struct3507 models.Struct3507
928
 			struct3507.FixmedinsBchno = item.Bchno
929
 			struct3507.FixmedinsBchno = item.Bchno
930
+			struct3507.InvDataType = "1"
931
+			struct3507.Opter = roles.UserName
932
+			struct3507.FixmedinsCode = miConfig.Code
933
+			struct3507.OrgName = miConfig.OrgName
934
+			struct3507.AccessKey = miConfig.AccessKey
935
+			struct3507.RequestUrl = miConfig.Url
936
+			struct3507.SecretKey = miConfig.SecretKey
937
+			struct3507.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
938
+			struct3507.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
939
+			struct3507.Url = miConfig.Url
940
+			struct3507.AppId = miConfig.Cainfo
941
+			struct3507.AppSecret = miConfig.AppSecret
942
+			struct3507.Enckey = miConfig.EncKey
943
+			struct3507.SignKey = miConfig.SignKey
944
+			struct3507.SecretKey = miConfig.SecretKey
945
+			result, result1, _ := service.FJyb3507(struct3507)
946
+			saveLog(result, result1, "3507", "3507")
947
+
948
+			var respJSON3 map[string]interface{}
949
+			if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
950
+				utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
951
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
952
+				return
953
+			}
954
+			userJSONBytes3, _ := json.Marshal(respJSON3)
955
+			if err := json.Unmarshal(userJSONBytes3, &res); err != nil {
956
+				utils.ErrorLog("解析失败:%v", err)
957
+				c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
958
+				return
959
+			}
960
+			if res.Infcode != -1 {
961
+				item.IsPc = 0
962
+				item.Bchno = ""
963
+				item.BgBchno = ""
964
+				item.PcDate = ""
965
+				service.SaveW(item)
966
+			} else {
967
+				err = append(err, "删除"+item.BaseDrugLib.DrugName+"盘存失败,失败原因:"+res.ErrMsg)
968
+			}
969
+		}
970
+
971
+		if item.IsPc == 0 && item.IsBg == 1 {
972
+
973
+			var res FJ3507Result
974
+			var struct3507 models.Struct3507
975
+			struct3507.FixmedinsBchno = item.BgBchno
929
 			struct3507.InvDataType = "2"
976
 			struct3507.InvDataType = "2"
930
 			struct3507.Opter = roles.UserName
977
 			struct3507.Opter = roles.UserName
931
 			struct3507.FixmedinsCode = miConfig.Code
978
 			struct3507.FixmedinsCode = miConfig.Code
959
 			if res.Infcode != -1 {
1006
 			if res.Infcode != -1 {
960
 				item.IsBg = 0
1007
 				item.IsBg = 0
961
 				item.Bchno = ""
1008
 				item.Bchno = ""
1009
+				item.BgBchno = ""
962
 				item.PcDate = ""
1010
 				item.PcDate = ""
963
 				service.SaveW(item)
1011
 				service.SaveW(item)
964
 			} else {
1012
 			} else {
981
 	}
1029
 	}
982
 
1030
 
983
 }
1031
 }
1032
+
984
 func (c *HisApiController) DeleteXSandBG() {
1033
 func (c *HisApiController) DeleteXSandBG() {
985
 	ids := c.GetString("ids")
1034
 	ids := c.GetString("ids")
986
 	id_arr := strings.Split(ids, ",")
1035
 	id_arr := strings.Split(ids, ",")
1032
 			if res.Infcode != -1 {
1081
 			if res.Infcode != -1 {
1033
 				item.IsSale = 0
1082
 				item.IsSale = 0
1034
 				item.SaleDate = ""
1083
 				item.SaleDate = ""
1084
+				item.Bchno = ""
1085
+
1035
 				err2 := service.SaveDF(item)
1086
 				err2 := service.SaveDF(item)
1036
 				if err2 == nil {
1087
 				if err2 == nil {
1037
 					var struct3507_2 models.Struct3507
1088
 					var struct3507_2 models.Struct3507
1050
 					struct3507_2.Enckey = miConfig.EncKey
1101
 					struct3507_2.Enckey = miConfig.EncKey
1051
 					struct3507_2.SignKey = miConfig.SignKey
1102
 					struct3507_2.SignKey = miConfig.SignKey
1052
 					struct3507_2.SecretKey = miConfig.SecretKey
1103
 					struct3507_2.SecretKey = miConfig.SecretKey
1053
-					struct3507_2.FixmedinsBchno = item.Bchno
1104
+					struct3507_2.FixmedinsBchno = item.BgBchno
1054
 					struct3507_2.InvDataType = "2"
1105
 					struct3507_2.InvDataType = "2"
1055
 					result11, result22, _ := service.FJyb3507(struct3507_2)
1106
 					result11, result22, _ := service.FJyb3507(struct3507_2)
1056
 					saveLog(result11, result22, "3507", "3507")
1107
 					saveLog(result11, result22, "3507", "3507")
1069
 					}
1120
 					}
1070
 					if res2.Infcode != -1 {
1121
 					if res2.Infcode != -1 {
1071
 						item.IsChange = 0
1122
 						item.IsChange = 0
1072
-						item.Bchno = ""
1123
+						item.BgBchno = ""
1073
 						service.SaveDF2(item)
1124
 						service.SaveDF2(item)
1074
 					} else {
1125
 					} else {
1075
 						err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1126
 						err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1120
 			if res.Infcode != -1 {
1171
 			if res.Infcode != -1 {
1121
 				item.IsSale = 0
1172
 				item.IsSale = 0
1122
 				item.SaleDate = ""
1173
 				item.SaleDate = ""
1174
+				item.Bchno = ""
1123
 				err2 := service.SaveDF(item)
1175
 				err2 := service.SaveDF(item)
1124
 				if err2 == nil {
1176
 				if err2 == nil {
1125
 					var struct3507_2 models.Struct3507
1177
 					var struct3507_2 models.Struct3507
1128
 					struct3507_2.RequestUrl = miConfig.Url
1180
 					struct3507_2.RequestUrl = miConfig.Url
1129
 					struct3507_2.Opter = roles.UserName
1181
 					struct3507_2.Opter = roles.UserName
1130
 					struct3507_2.FixmedinsCode = miConfig.Code
1182
 					struct3507_2.FixmedinsCode = miConfig.Code
1131
-
1132
 					struct3507_2.SecretKey = miConfig.SecretKey
1183
 					struct3507_2.SecretKey = miConfig.SecretKey
1133
 					struct3507_2.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
1184
 					struct3507_2.MdtrtareaAdmvs = miConfig.MdtrtareaAdmvs
1134
 					struct3507_2.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
1185
 					struct3507_2.InsuplcAdmdvs = miConfig.InsuplcAdmdvs
1138
 					struct3507_2.Enckey = miConfig.EncKey
1189
 					struct3507_2.Enckey = miConfig.EncKey
1139
 					struct3507_2.SignKey = miConfig.SignKey
1190
 					struct3507_2.SignKey = miConfig.SignKey
1140
 					struct3507_2.SecretKey = miConfig.SecretKey
1191
 					struct3507_2.SecretKey = miConfig.SecretKey
1141
-					struct3507_2.FixmedinsBchno = item.Bchno
1192
+					struct3507_2.FixmedinsBchno = item.BgBchno
1142
 					struct3507_2.InvDataType = "2"
1193
 					struct3507_2.InvDataType = "2"
1143
 					result11, result22, _ := service.FJyb3507(struct3507_2)
1194
 					result11, result22, _ := service.FJyb3507(struct3507_2)
1144
 					saveLog(result11, result22, "3507", "3507")
1195
 					saveLog(result11, result22, "3507", "3507")
1145
-
1146
 					var respJSON3 map[string]interface{}
1196
 					var respJSON3 map[string]interface{}
1147
 					if err := json.Unmarshal([]byte(string(result11)), &respJSON3); err != nil {
1197
 					if err := json.Unmarshal([]byte(string(result11)), &respJSON3); err != nil {
1148
 						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1198
 						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1157
 					}
1207
 					}
1158
 					if res2.Infcode != -1 {
1208
 					if res2.Infcode != -1 {
1159
 						item.IsChange = 0
1209
 						item.IsChange = 0
1160
-						item.Bchno = ""
1210
+						item.BgBchno = ""
1161
 						service.SaveDF2(item)
1211
 						service.SaveDF2(item)
1162
 					} else {
1212
 					} else {
1163
 						err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1213
 						err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1249
 			if res.Infcode != -1 {
1299
 			if res.Infcode != -1 {
1250
 				item.IsSale = 0
1300
 				item.IsSale = 0
1251
 				item.SaleDate = ""
1301
 				item.SaleDate = ""
1302
+				item.Bchno = ""
1303
+
1252
 				service.SaveDF(item)
1304
 				service.SaveDF(item)
1253
 			} else {
1305
 			} else {
1254
 				err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1306
 				err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1258
 
1310
 
1259
 			var res FJ3507Result
1311
 			var res FJ3507Result
1260
 			var struct3507 models.Struct3507
1312
 			var struct3507 models.Struct3507
1261
-			struct3507.FixmedinsBchno = item.Bchno
1313
+			struct3507.FixmedinsBchno = item.BgBchno
1262
 			struct3507.InvDataType = "2"
1314
 			struct3507.InvDataType = "2"
1263
 			struct3507.Opter = roles.UserName
1315
 			struct3507.Opter = roles.UserName
1264
 			struct3507.FixmedinsCode = miConfig.Code
1316
 			struct3507.FixmedinsCode = miConfig.Code
1291
 			}
1343
 			}
1292
 			if res.Infcode != -1 {
1344
 			if res.Infcode != -1 {
1293
 				item.IsChange = 0
1345
 				item.IsChange = 0
1294
-				item.Bchno = ""
1346
+				item.BgBchno = ""
1295
 				service.SaveDF2(item)
1347
 				service.SaveDF2(item)
1296
 			} else {
1348
 			} else {
1297
 				err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1349
 				err = append(err, "删除"+item.HisDoctorAdviceInfo.BaseDrugLib.DrugName+"变更失败,失败原因:"+res.ErrMsg)
1325
 	for _, item := range flows {
1377
 	for _, item := range flows {
1326
 		var res3 ResultSix
1378
 		var res3 ResultSix
1327
 		if item.ConsumableType == 3 { //3为自动出库 7为自动退库
1379
 		if item.ConsumableType == 3 { //3为自动出库 7为自动退库
1328
-			number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3507"
1329
-
1330
 			prescription := service.GetHisPrescriptionByID(item.HisDoctorAdviceInfo.PrescriptionId)
1380
 			prescription := service.GetHisPrescriptionByID(item.HisDoctorAdviceInfo.PrescriptionId)
1331
 			if prescription.OrderStatus == 2 {
1381
 			if prescription.OrderStatus == 2 {
1332
 				//已经结算
1382
 				//已经结算
1334
 				if item.IsSale == 1 { //是否已经销售,1是   0否
1384
 				if item.IsSale == 1 { //是否已经销售,1是   0否
1335
 					//是否已经变更 1是  0否
1385
 					//是否已经变更 1是  0否
1336
 					if item.IsChange == 0 { //没变更,进行变更操作
1386
 					if item.IsChange == 0 { //没变更,进行变更操作
1337
-						result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
1387
+						bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
1388
+
1389
+						result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles, bg_number)
1338
 						saveLog(result, result2, "3502", "自动出库,已经销售,未变更3502")
1390
 						saveLog(result, result2, "3502", "自动出库,已经销售,未变更3502")
1339
 						var respJSON3 map[string]interface{}
1391
 						var respJSON3 map[string]interface{}
1340
 						if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
1392
 						if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
1350
 						}
1402
 						}
1351
 						if res3.Infcode != -1 {
1403
 						if res3.Infcode != -1 {
1352
 							item.IsChange = 1
1404
 							item.IsChange = 1
1353
-							item.Bchno = item.NewDrugWarehouseInfo.Bchno
1405
+							item.BgBchno = bg_number
1354
 							service.SaveDF2(item)
1406
 							service.SaveDF2(item)
1355
 						} else {
1407
 						} else {
1356
 							err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1408
 							err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1358
 					}
1410
 					}
1359
 				} else { //没销售,
1411
 				} else { //没销售,
1360
 					var res FJ3507Result
1412
 					var res FJ3507Result
1413
+					number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3505"
1361
 
1414
 
1362
 					//进行商品销售接口
1415
 					//进行商品销售接口
1363
-					result3, result4 := SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles)
1416
+					result3, result4 := SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles, number)
1364
 					saveLog(result3, result4, "3505", "自动出库,未销售进行销售行为,3505")
1417
 					saveLog(result3, result4, "3505", "自动出库,未销售进行销售行为,3505")
1365
 					var respJSON3 map[string]interface{}
1418
 					var respJSON3 map[string]interface{}
1366
 					if err := json.Unmarshal([]byte(string(result3)), &respJSON3); err != nil {
1419
 					if err := json.Unmarshal([]byte(string(result3)), &respJSON3); err != nil {
1376
 					}
1429
 					}
1377
 					if res.Infcode != -1 {
1430
 					if res.Infcode != -1 {
1378
 						item.IsSale = 1
1431
 						item.IsSale = 1
1432
+						item.Bchno = number
1379
 						item.SaleDate = time.Now().Format("2006-01-02")
1433
 						item.SaleDate = time.Now().Format("2006-01-02")
1434
+
1380
 						err5 := service.SaveDF(item)
1435
 						err5 := service.SaveDF(item)
1381
 						if err5 == nil {
1436
 						if err5 == nil {
1382
 							if item.IsChange == 0 { //没变更,进行变更操作
1437
 							if item.IsChange == 0 { //没变更,进行变更操作
1383
-								result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
1438
+								bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
1439
+
1440
+								result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles, bg_number)
1384
 								saveLog(result, result2, "3502", "自动出库,没销售,未变更3502")
1441
 								saveLog(result, result2, "3502", "自动出库,没销售,未变更3502")
1385
 
1442
 
1386
 								var respJSON3 map[string]interface{}
1443
 								var respJSON3 map[string]interface{}
1397
 								}
1454
 								}
1398
 								if res3.Infcode != -1 {
1455
 								if res3.Infcode != -1 {
1399
 									item.IsChange = 1
1456
 									item.IsChange = 1
1400
-									item.Bchno = item.NewDrugWarehouseInfo.Bchno
1457
+									item.BgBchno = bg_number
1401
 									service.SaveDF2(item)
1458
 									service.SaveDF2(item)
1402
 								} else {
1459
 								} else {
1403
 									err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1460
 									err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1411
 
1468
 
1412
 			} else { //还没结算
1469
 			} else { //还没结算
1413
 				if item.IsChange == 0 { //没变更,进行变更操作
1470
 				if item.IsChange == 0 { //没变更,进行变更操作
1414
-					result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
1471
+					bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
1472
+
1473
+					result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles, bg_number)
1415
 					saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1474
 					saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1416
 
1475
 
1417
 					var respJSON3 map[string]interface{}
1476
 					var respJSON3 map[string]interface{}
1428
 					}
1487
 					}
1429
 					if res3.Infcode != -1 {
1488
 					if res3.Infcode != -1 {
1430
 						item.IsChange = 1
1489
 						item.IsChange = 1
1431
-						item.Bchno = item.NewDrugWarehouseInfo.Bchno
1490
+						item.BgBchno = bg_number
1432
 						service.SaveDF2(item)
1491
 						service.SaveDF2(item)
1433
 					} else {
1492
 					} else {
1434
 						err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1493
 						err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1443
 				if item.IsSale == 2 { //是否已经销售,1是   0否
1502
 				if item.IsSale == 2 { //是否已经销售,1是   0否
1444
 					//是否已经变更 1是  0否
1503
 					//是否已经变更 1是  0否
1445
 					if item.IsChange == 0 { //没变更,进行变更操作
1504
 					if item.IsChange == 0 { //没变更,进行变更操作
1446
-						result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
1505
+						bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
1506
+
1507
+						result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles, bg_number)
1447
 						saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1508
 						saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1448
 
1509
 
1449
 						var respJSON3 map[string]interface{}
1510
 						var respJSON3 map[string]interface{}
1460
 						}
1521
 						}
1461
 						if res3.Infcode != -1 {
1522
 						if res3.Infcode != -1 {
1462
 							item.IsChange = 1
1523
 							item.IsChange = 1
1463
-							item.Bchno = item.NewDrugWarehouseInfo.Bchno
1524
+							item.BgBchno = bg_number
1464
 							service.SaveDF2(item)
1525
 							service.SaveDF2(item)
1465
 						} else {
1526
 						} else {
1466
 							err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1527
 							err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1468
 					}
1529
 					}
1469
 				} else { //没销售,
1530
 				} else { //没销售,
1470
 					//进行商品销售退货接口
1531
 					//进行商品销售退货接口
1471
-					result111, result222 := CancleSaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles)
1532
+					number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3506"
1533
+
1534
+					result111, result222 := CancleSaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles, number)
1472
 					saveLog(result111, result222, "3506", "销售退货")
1535
 					saveLog(result111, result222, "3506", "销售退货")
1473
 					var res7 FJ3507Result
1536
 					var res7 FJ3507Result
1474
 
1537
 
1475
 					//进行商品销售接口
1538
 					//进行商品销售接口
1476
-					result3, result4 := SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles)
1477
-					saveLog(result3, result4, "3506", "自动退库,未销售退货进行销售退货行为,3505")
1539
+					//result3, result4 := SaleStock(c.GetAdminUserInfo().CurrentOrgId, prescription, item, miConfig, "", roles,number)
1540
+					//saveLog(result3, result4, "3506", "自动退库,未销售退货进行销售退货行为,3505")
1478
 					var respJSON3 map[string]interface{}
1541
 					var respJSON3 map[string]interface{}
1479
 					if err := json.Unmarshal([]byte(string(result111)), &respJSON3); err != nil {
1542
 					if err := json.Unmarshal([]byte(string(result111)), &respJSON3); err != nil {
1480
 						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1543
 						utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1490
 					if res7.Infcode != -1 {
1553
 					if res7.Infcode != -1 {
1491
 						item.IsSale = 2
1554
 						item.IsSale = 2
1492
 						item.SaleDate = item.SaleDate
1555
 						item.SaleDate = item.SaleDate
1556
+						item.Bchno = number
1493
 						service.SaveDF(item)
1557
 						service.SaveDF(item)
1494
 						if item.IsChange == 0 { //没变更,进行变更操作
1558
 						if item.IsChange == 0 { //没变更,进行变更操作
1495
-							result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
1559
+							bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
1560
+
1561
+							result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles, bg_number)
1496
 							saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1562
 							saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1497
 
1563
 
1498
 							var respJSON3 map[string]interface{}
1564
 							var respJSON3 map[string]interface{}
1509
 							}
1575
 							}
1510
 							if res3.Infcode != -1 {
1576
 							if res3.Infcode != -1 {
1511
 								item.IsChange = 1
1577
 								item.IsChange = 1
1512
-								item.Bchno = item.NewDrugWarehouseInfo.Bchno
1578
+								item.BgBchno = bg_number
1513
 								service.SaveDF2(item)
1579
 								service.SaveDF2(item)
1514
 							} else {
1580
 							} else {
1515
 								err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1581
 								err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1521
 				}
1587
 				}
1522
 			} else { //还没结算
1588
 			} else { //还没结算
1523
 				if item.IsChange == 0 { //没变更,进行变更操作
1589
 				if item.IsChange == 0 { //没变更,进行变更操作
1524
-					result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles)
1590
+					bg_number := strconv.FormatInt(time.Now().Unix(), 10) + "-" + strconv.FormatInt(item.ID, 10) + "-" + "3502"
1591
+
1592
+					result, result2 := ChangeStock(item.Count, item, miConfig, "107", roles, bg_number)
1525
 					saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1593
 					saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1526
 
1594
 
1527
 					var respJSON3 map[string]interface{}
1595
 					var respJSON3 map[string]interface{}
1538
 					}
1606
 					}
1539
 					if res3.Infcode != -1 {
1607
 					if res3.Infcode != -1 {
1540
 						item.IsChange = 1
1608
 						item.IsChange = 1
1541
-						item.Bchno = item.NewDrugWarehouseInfo.Bchno
1609
+						item.BgBchno = bg_number
1542
 						service.SaveDF2(item)
1610
 						service.SaveDF2(item)
1543
 					} else {
1611
 					} else {
1544
 						err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1612
 						err = append(err, item.HisDoctorAdviceInfo.AdviceName+",销售变更失败:"+res3.ErrMsg)
1546
 				}
1614
 				}
1547
 			}
1615
 			}
1548
 		}
1616
 		}
1549
-		//else { //其他方式
1550
-		//	//if item.IsChange == 0 { //没变更,进行变更操作
1551
-		//	//	result, result2  := ChangeStock(item.Count, item, miConfig, "107", roles)
1552
-		//	//	saveLog(result, result2, "3502", "自动出库,未销售,未变更3502")
1553
-		//	//
1554
-		//	//	var respJSON3 map[string]interface{}
1555
-		//	//	if err := json.Unmarshal([]byte(string(result)), &respJSON3); err != nil {
1556
-		//	//		utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
1557
-		//	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1558
-		//	//		return
1559
-		//	//	}
1560
-		//	//	userJSONBytes3, _ := json.Marshal(respJSON3)
1561
-		//	//	if err := json.Unmarshal(userJSONBytes3, &res3); err != nil {
1562
-		//	//		utils.ErrorLog("解析失败:%v", err)
1563
-		//	//		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
1564
-		//	//		return
1565
-		//	//	}
1566
-		//	//	if res3.Infcode != -1{
1567
-		//	//		item.IsChange = 1
1568
-		//	//		item.Bchno = item.NewDrugWarehouseInfo.Bchno
1569
-		//	//		service.SaveDF2(item)
1570
-		//	//	}else{
1571
-		//	//		err = append(err,item.HisDoctorAdviceInfo.AdviceName +",销售变更失败:"+res3.ErrMsg)
1572
-		//	//	}
1573
-		//	//}
1574
-		//}
1575
 	}
1617
 	}
1576
 	if len(err) == 0 {
1618
 	if len(err) == 0 {
1577
 		c.ServeSuccessJSON(map[string]interface{}{
1619
 		c.ServeSuccessJSON(map[string]interface{}{
1584
 		})
1626
 		})
1585
 	}
1627
 	}
1586
 }
1628
 }
1587
-func ChangeStock(count int64, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) (string, string) {
1629
+func ChangeStock(count int64, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole, number string) (string, string) {
1588
 	var struct3502 models.Struct3502
1630
 	var struct3502 models.Struct3502
1589
 	struct3502.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
1631
 	struct3502.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
1590
 	struct3502.FixmedinsHilistId = miConfig.Code
1632
 	struct3502.FixmedinsHilistId = miConfig.Code
1606
 	struct3502.SignKey = miConfig.SignKey
1648
 	struct3502.SignKey = miConfig.SignKey
1607
 	struct3502.SecretKey = miConfig.SecretKey
1649
 	struct3502.SecretKey = miConfig.SecretKey
1608
 	struct3502.InvChgType = chgType
1650
 	struct3502.InvChgType = chgType
1609
-	struct3502.FixmedinsBchno = drug.NewDrugWarehouseInfo.Bchno
1651
+	struct3502.FixmedinsBchno = number
1610
 	struct3502.Cnt = strconv.FormatInt(count, 10)
1652
 	struct3502.Cnt = strconv.FormatInt(count, 10)
1611
 	struct3502.Pric = fmt.Sprintf("%.2f", drug.Price)
1653
 	struct3502.Pric = fmt.Sprintf("%.2f", drug.Price)
1612
 	result1, result2, _ := service.FJyb3502(struct3502)
1654
 	result1, result2, _ := service.FJyb3502(struct3502)
1613
 	return result1, result2
1655
 	return result1, result2
1614
 }
1656
 }
1615
-func SaleStock(org_id int64, pre models.HisPrescription, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) (string, string) {
1657
+func SaleStock(org_id int64, pre models.HisPrescription, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole, number string) (string, string) {
1616
 	var struct3505 models.Struct3505
1658
 	var struct3505 models.Struct3505
1617
 	struct3505.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
1659
 	struct3505.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
1618
 	struct3505.FixmedinsHilistId = miConfig.Code
1660
 	struct3505.FixmedinsHilistId = miConfig.Code
1619
 	struct3505.FixmedinsHilistName = miConfig.OrgName
1661
 	struct3505.FixmedinsHilistName = miConfig.OrgName
1620
-	struct3505.FixmedinsBchno = drug.NewDrugWarehouseInfo.Bchno
1662
+	struct3505.FixmedinsBchno = number
1621
 	struct3505.Opter = role.UserName
1663
 	struct3505.Opter = role.UserName
1622
 
1664
 
1623
 	struct3505.FixmedinsCode = miConfig.Code
1665
 	struct3505.FixmedinsCode = miConfig.Code
1659
 	return result1, result2
1701
 	return result1, result2
1660
 
1702
 
1661
 }
1703
 }
1662
-func CancleSaleStock(org_id int64, pre models.HisPrescription, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole) (string, string) {
1704
+func CancleSaleStock(org_id int64, pre models.HisPrescription, drug *models.DrugFlow, miConfig models.MedicalInsuranceOrgConfig, chgType string, role models.UserAdminRole, number string) (string, string) {
1663
 	var struct3506 models.Struct3506
1705
 	var struct3506 models.Struct3506
1664
 	struct3506.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
1706
 	struct3506.MedListCodg = drug.HisDoctorAdviceInfo.BaseDrugLib.MedicalInsuranceNumber
1665
 	struct3506.FixmedinsHilistId = miConfig.Code
1707
 	struct3506.FixmedinsHilistId = miConfig.Code
1666
 	struct3506.FixmedinsHilistName = miConfig.OrgName
1708
 	struct3506.FixmedinsHilistName = miConfig.OrgName
1667
 	struct3506.FixmedinsCode = miConfig.Code
1709
 	struct3506.FixmedinsCode = miConfig.Code
1668
-	struct3506.FixmedinsBchno = drug.NewDrugWarehouseInfo.Bchno
1710
+	struct3506.FixmedinsBchno = number
1669
 	struct3506.Opter = role.UserName
1711
 	struct3506.Opter = role.UserName
1670
 	order := service.GetHisOrderByNumber(pre.BatchNumber)
1712
 	order := service.GetHisOrderByNumber(pre.BatchNumber)
1671
 	struct3506.ManuLotnum = drug.NewDrugWarehouseInfo.Number
1713
 	struct3506.ManuLotnum = drug.NewDrugWarehouseInfo.Number

+ 6 - 4
models/new_stock_models.go View File

261
 	SecondWarehouseInfoId     int64  `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
261
 	SecondWarehouseInfoId     int64  `gorm:"column:second_warehouse_info_id" json:"second_warehouse_info_id" form:"second_warehouse_info_id"`
262
 	IsCheck                   int64  `gorm:"column:is_check" json:"is_check" form:"is_check"`
262
 	IsCheck                   int64  `gorm:"column:is_check" json:"is_check" form:"is_check"`
263
 
263
 
264
-	IsPc   int64  `gorm:"column:is_pc" json:"is_pc" form:"is_pc"`
265
-	IsBg   int64  `gorm:"column:is_bg" json:"is_bg" form:"is_bg"`
266
-	Bchno  string `gorm:"column:bchno" json:"bchno" form:"bchno"`
267
-	PcDate string `gorm:"column:pc_date" json:"pc_date" form:"pc_date"`
264
+	IsPc    int64  `gorm:"column:is_pc" json:"is_pc" form:"is_pc"`
265
+	IsBg    int64  `gorm:"column:is_bg" json:"is_bg" form:"is_bg"`
266
+	Bchno   string `gorm:"column:bchno" json:"bchno" form:"bchno"`
267
+	PcDate  string `gorm:"column:pc_date" json:"pc_date" form:"pc_date"`
268
+	BgBchno string `gorm:"column:bg_bchno" json:"bg_bchno" form:"bg_bchno"`
268
 }
269
 }
269
 
270
 
270
 func (NewDrugWarehouseInfo) TableName() string {
271
 func (NewDrugWarehouseInfo) TableName() string {
441
 	NewDrugWarehouseInfo      NewDrugWarehouseInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehousingDetailId" json:"dw"`
442
 	NewDrugWarehouseInfo      NewDrugWarehouseInfo `gorm:"ForeignKey:ID;AssociationForeignKey:WarehousingDetailId" json:"dw"`
442
 	Bchno                     string               `gorm:"column:bchno" json:"bchno" form:"bchno"`
443
 	Bchno                     string               `gorm:"column:bchno" json:"bchno" form:"bchno"`
443
 	SaleDate                  string               `gorm:"column:sale_date" json:"sale_date" form:"sale_date"`
444
 	SaleDate                  string               `gorm:"column:sale_date" json:"sale_date" form:"sale_date"`
445
+	BgBchno                   string               `gorm:"column:bg_bchno" json:"bg_bchno" form:"bg_bchno"`
444
 }
446
 }
445
 
447
 
446
 func (DrugFlow) TableName() string {
448
 func (DrugFlow) TableName() string {

+ 3 - 3
service/his_service.go View File

1730
 	err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
1730
 	err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
1731
 		"is_sale":   df.IsSale,
1731
 		"is_sale":   df.IsSale,
1732
 		"sale_date": df.SaleDate,
1732
 		"sale_date": df.SaleDate,
1733
+		"bchno":     df.Bchno,
1733
 		//"is_change"
1734
 		//"is_change"
1734
 	}).Error
1735
 	}).Error
1735
 	return
1736
 	return
1739
 	//err = writeDb.(&df).Error
1740
 	//err = writeDb.(&df).Error
1740
 	err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
1741
 	err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
1741
 		"is_change": df.IsChange,
1742
 		"is_change": df.IsChange,
1742
-		"bchno":     df.Bchno,
1743
+		"bg_bchno":  df.BgBchno,
1743
 		//"is_change"
1744
 		//"is_change"
1744
 	}).Error
1745
 	}).Error
1745
 	return
1746
 	return
1749
 	return
1750
 	return
1750
 }
1751
 }
1751
 
1752
 
1752
-
1753
-func GetBbx01ByTeamID(team_id int64)(team models.XtHisProjectTeam){
1753
+func GetBbx01ByTeamID(team_id int64) (team models.XtHisProjectTeam) {
1754
 	err = readDb.Model(&models.XtHisProjectTeam{}).Where("id = ?", team_id).First(&team).Error
1754
 	err = readDb.Model(&models.XtHisProjectTeam{}).Where("id = ?", team_id).First(&team).Error
1755
 	return
1755
 	return
1756
 }
1756
 }