3 Revīzijas 0e42536857 ... 4d6060aba8

Autors SHA1 Ziņojums Datums
  陈少旭 4d6060aba8 Merge branch '20230223_xt_api_new_branch' of http://git.shengws.com/csx/XT_New into 20230223_xt_api_new_branch 1 dienu atpakaļ
  陈少旭 5d0317a363 提交代码 1 dienu atpakaļ
  陈少旭 303e575099 提交代码 1 dienu atpakaļ

+ 676 - 79
controllers/fapiao_controller.go Parādīt failu

@@ -9,9 +9,12 @@ import (
9 9
 	"encoding/json"
10 10
 	"errors"
11 11
 	"fmt"
12
+	"io"
12 13
 	"io/ioutil"
13 14
 	"math"
14 15
 	"net/http"
16
+	"os"
17
+	"path/filepath"
15 18
 	"sort"
16 19
 	"strconv"
17 20
 	"strings"
@@ -34,22 +37,479 @@ func FaPiaoApiRegistRouters() {
34 37
 	beego.Router("/api/bwfapiao/sms/login", &FapiaoApiController{}, "get:Login")
35 38
 	beego.Router("/api/bwfapiao/qrcode/get", &FapiaoApiController{}, "get:GetQRCode")
36 39
 	//beego.Router("/api/bwfapiao/blue", &FapiaoApiController{}, "get:OpenFaPiao")
37
-	//beego.Router("/api/bwfapiao/red", &FapiaoApiController{}, "get:RedFaPiao")
40
+	beego.Router("/api/bwfapiao/red", &FapiaoApiController{}, "get:RedFaPiao")
38 41
 	beego.Router("/api/order/fapiao/list", &FapiaoApiController{}, "get:GetOrderFaPiaoList")
39 42
 	beego.Router("/api/fapiao/list", &FapiaoApiController{}, "get:GetFaPiaoList")
40 43
 	beego.Router("/api/newfapiao/get", &HisApiController{}, "get:GetNewFaPiaoData")
41 44
 	beego.Router("/api/fapiao/query", &FapiaoApiController{}, "get:QueryFaPiao")
42
-
45
+	beego.Router("/api/bwfapiao/batchopen", &FapiaoApiController{}, "get:BwOpenBatchBlueFaPiao")
43 46
 	//百望云
44 47
 	//beego.Router("/api/bwfapiao/login", &FapiaoApiController{}, "get:GetBwFaPiaoLogin")
45 48
 	//beego.Router("/api/bwfapiao/qrcode", &FapiaoApiController{}, "get:GetBwFaPiaoQRCode")
46
-	beego.Router("/api/bwfapiao/blue", &FapiaoApiController{}, "get:BwOpenBlueFaPiao")
47
-	beego.Router("/api/bwfapiao/query", &FapiaoApiController{}, "get:QueryBwFaPiao")
48
-	beego.Router("/api/bwfapiao/red", &FapiaoApiController{}, "get:BwOpenRedFaPiao")
49
+	//beego.Router("/api/bwfapiao/blue", &FapiaoApiController{}, "get:BwOpenBlueFaPiao")
50
+	//beego.Router("/api/bwfapiao/query", &FapiaoApiController{}, "get:QueryBwFaPiao")
51
+	//beego.Router("/api/bwfapiao/red", &FapiaoApiController{}, "get:BwOpenRedFaPiao")
52
+
53
+	//beego.Router("/api/download", &FapiaoApiController{}, "get:DownLoad")
54
+
55
+	//beego.Router("/api/all_download", &FapiaoApiController{}, "get:AllDownLoad")
49 56
 
50 57
 }
51 58
 
59
+func (c *FapiaoApiController) BwOpenBatchBlueFaPiao() {
60
+	//判断是否处于登录状态
61
+	//开蓝票逻辑
62
+	order_ids := c.GetString("id")
63
+	admin_user_id, _ := c.GetInt64("admin_user_id")
64
+	ids := strings.Split(order_ids, ",")
65
+	orders, _ := service.GetFaPiaoOrderByIDS(ids)
66
+	fmt.Println(ids)
67
+	fmt.Println(orders)
68
+	//return
69
+	var success []int64
70
+	var errs string
71
+
72
+	for _, oss := range orders {
73
+		var MedfeeSumamt float64 = 0  //治疗费用
74
+		var PsnCashPay float64 = 0    //治疗费用
75
+		var FundPaySumamt float64 = 0 //治疗费用
76
+
77
+		var HifmiPay float64 = 0 //治疗费用
78
+		var MafPay float64 = 0   //治疗费用
79
+		var HifpPay float64 = 0  //治疗费用
80
+		var AcctPay float64 = 0  //治疗费用
81
+
82
+		var GongWuYuan float64 = 0 //治疗费用
83
+
84
+		var BuCong float64 = 0 //治疗费用
85
+
86
+		var OthPay float64 = 0 //治疗费用
87
+
88
+		var details []models.NewHisOrderInfo
89
+		var numbers []string
90
+		decimal.DivisionPrecision = 2
91
+		var remark string
92
+
93
+		MedfeeSumamt, _ = decimal.NewFromFloat(MedfeeSumamt).Add(decimal.NewFromFloat(oss.MedfeeSumamt)).Float64()
94
+		PsnCashPay, _ = decimal.NewFromFloat(PsnCashPay).Add(decimal.NewFromFloat(oss.PsnCashPay)).Float64()
95
+		FundPaySumamt, _ = decimal.NewFromFloat(FundPaySumamt).Add(decimal.NewFromFloat(oss.FundPaySumamt)).Float64()
96
+
97
+		HifmiPay, _ = decimal.NewFromFloat(HifmiPay).Add(decimal.NewFromFloat(oss.HifmiPay)).Float64()
98
+		MafPay, _ = decimal.NewFromFloat(MafPay).Add(decimal.NewFromFloat(oss.MafPay)).Float64()
99
+		HifpPay, _ = decimal.NewFromFloat(HifpPay).Add(decimal.NewFromFloat(oss.HifpPay)).Float64()
100
+		AcctPay, _ = decimal.NewFromFloat(AcctPay).Add(decimal.NewFromFloat(oss.AcctPay)).Float64()
101
+
102
+		GongWuYuan, _ = decimal.NewFromFloat(GongWuYuan).Add(decimal.NewFromFloat(oss.CvlservPay)).Float64()
103
+
104
+		BuCong, _ = decimal.NewFromFloat(BuCong).Add(decimal.NewFromFloat(oss.HifesPay)).Float64()
105
+
106
+		OthPay, _ = decimal.NewFromFloat(OthPay).Add(decimal.NewFromFloat(oss.OthPay)).Float64()
107
+		numbers = append(numbers, oss.Number)
108
+
109
+		// 假设你有一个以秒为单位的时间戳
110
+		timestamp := oss.SettleAccountsDate // 例如:2023-01-01T00:00:00Z
111
+		// 将时间戳转换为time.Time对象
112
+		t := time.Unix(timestamp, 0) // 第二个参数是纳秒,这里我们不需要转换,所以设为0
113
+		// 格式化日期和时间
114
+		//fmt.Println(t.Format("2006-01-02"))
115
+
116
+		remark = "治疗时间: " + t.Format("2006-01-02")
117
+
118
+		MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
119
+
120
+		if len(remark) == 0 {
121
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
122
+			remark = "医疗总费用: " + MedfeeSumamt_str
123
+		} else {
124
+			remark = remark + " 医疗总费用:" + MedfeeSumamt_str
125
+		}
126
+		FundPaySumamt_str := fmt.Sprintf("%.2f", FundPaySumamt)
127
+
128
+		if len(remark) == 0 {
129
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
130
+			remark = "基金支付总金额: " + FundPaySumamt_str
131
+		} else {
132
+			remark = remark + " 基金支付总金额:" + FundPaySumamt_str
133
+		}
134
+		HifpPay_str := fmt.Sprintf("%.2f", HifpPay)
135
+
136
+		if len(remark) == 0 {
137
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
138
+			remark = "基本统筹基金支付: " + HifpPay_str
139
+		} else {
140
+			remark = remark + " 基本统筹基金支付:" + HifpPay_str
141
+		}
142
+
143
+		HifmiPay_str := fmt.Sprintf("%.2f", HifmiPay)
144
+
145
+		if len(remark) == 0 {
146
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
147
+			remark = "大病基金支付: " + HifmiPay_str
148
+		} else {
149
+			remark = remark + " 大病基金支付:" + HifmiPay_str
150
+		}
151
+
152
+		GongWuYuan_str := fmt.Sprintf("%.2f", GongWuYuan)
153
+
154
+		if len(remark) == 0 {
155
+			remark = "公务员支付: " + GongWuYuan_str
156
+		} else {
157
+			remark = remark + " 公务员支付:" + GongWuYuan_str
158
+		}
159
+
160
+		BuCong_str := fmt.Sprintf("%.2f", BuCong)
161
+
162
+		if len(remark) == 0 {
163
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
164
+			remark = "补充医疗保险支付: " + BuCong_str
165
+		} else {
166
+			remark = remark + " 补充医疗保险支付:" + BuCong_str
167
+		}
168
+
169
+		MafPay_str := fmt.Sprintf("%.2f", MafPay)
170
+
171
+		if len(remark) == 0 {
172
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
173
+			remark = "医疗救助基金支付: " + MafPay_str
174
+		} else {
175
+			remark = remark + " 医疗救助基金支付:" + MafPay_str
176
+		}
177
+		OthPay_str := fmt.Sprintf("%.2f", OthPay)
178
+		if len(remark) == 0 {
179
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
180
+			remark = "其他支付: " + OthPay_str
181
+		} else {
182
+			remark = remark + " 其他支付:" + OthPay_str
183
+		}
184
+		AcctPay_str := fmt.Sprintf("%.2f", AcctPay)
185
+		if len(remark) == 0 {
186
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
187
+			remark = "医保账户支付: " + AcctPay_str
188
+		} else {
189
+			remark = remark + " 医保账户支付:" + AcctPay_str
190
+		}
191
+		PsnCashPay_str := fmt.Sprintf("%.2f", PsnCashPay)
192
+		if len(remark) == 0 {
193
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
194
+			remark = "个人现金支付: " + PsnCashPay_str
195
+		} else {
196
+			remark = remark + " 个人现金支付:" + PsnCashPay_str
197
+		}
198
+
199
+		details, _ = service.GetFaPiaoOrderInfoByNumbersTwo(numbers)
200
+		role, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
201
+
202
+		type CostType struct {
203
+			name  string
204
+			price float64
205
+		}
206
+		var cts []CostType
207
+		var ct CostType
208
+		var bedCostTotal float64 = 0                        //床位总费
209
+		var operationCostTotal float64 = 0                  //手术费
210
+		var otherCostTotal float64 = 0                      //其他费用
211
+		var materialCostTotal float64 = 0                   //材料费
212
+		var westernMedicineCostTotal float64 = 0            //西药费
213
+		var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
214
+		var checkCostTotal float64 = 0                      //检查费
215
+		var laboratoryCostTotal float64 = 0                 //化验费
216
+		var treatCostTotal float64 = 0                      //治疗费用
217
+		var huliCostTotal float64 = 0                       //治疗费用
218
+		var zhencaCostTotal float64 = 0                     //治疗费用
219
+		for _, item := range details {
220
+			if item.MedChrgitmType == "01" { //床位费
221
+				bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
222
+			}
223
+			if item.MedChrgitmType == "07" { //护理费
224
+				huliCostTotal, _ = decimal.NewFromFloat(huliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
225
+			}
226
+			if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
227
+				if item.MedChrgitmType == "03" { //检查费
228
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
229
+				}
230
+			} else {
231
+				if item.MedChrgitmType == "03" { //检查费
232
+					checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
233
+				}
234
+
235
+			}
236
+			if item.MedChrgitmType == "04" { //化验费
237
+				laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
238
+			}
239
+
240
+			if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
241
+				treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
242
+			}
243
+
244
+			if item.MedChrgitmType == "06" { //手术费
245
+				operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
246
+			}
247
+
248
+			if item.MedChrgitmType == "08" { //材料费
249
+				materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
250
+			}
251
+
252
+			if item.MedChrgitmType == "09" { //西药费
253
+				westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
254
+			}
255
+
256
+			if item.MedChrgitmType == "11" { //中成费
257
+				chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
258
+			}
259
+
260
+			if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
261
+				otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
262
+			}
263
+
264
+			if item.MedChrgitmType == "02" { //诊察
265
+				zhencaCostTotal, _ = decimal.NewFromFloat(zhencaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
266
+			}
267
+		}
268
+		if bedCostTotal > 0 {
269
+			ct.name = "床位费"
270
+			ct.price = bedCostTotal
271
+			cts = append(cts, ct)
272
+		}
273
+		if operationCostTotal > 0 {
274
+			ct.name = "手术费"
275
+			ct.price = operationCostTotal
276
+			cts = append(cts, ct)
277
+
278
+		}
279
+		if otherCostTotal > 0 {
280
+			ct.name = "其他费"
281
+			ct.price = otherCostTotal
282
+			cts = append(cts, ct)
283
+
284
+		}
285
+		if materialCostTotal > 0 {
286
+			ct.name = "材料费"
287
+			ct.price = materialCostTotal
288
+			cts = append(cts, ct)
289
+
290
+		}
291
+		if westernMedicineCostTotal > 0 {
292
+			ct.name = "西药费"
293
+			ct.price = westernMedicineCostTotal
294
+			cts = append(cts, ct)
295
+
296
+		}
297
+		if chineseTraditionalMedicineCostTotal > 0 {
298
+			ct.name = "中成药费"
299
+			ct.price = chineseTraditionalMedicineCostTotal
300
+			cts = append(cts, ct)
301
+
302
+		}
303
+		if checkCostTotal > 0 {
304
+			ct.name = "检查费"
305
+			ct.price = checkCostTotal
306
+			cts = append(cts, ct)
307
+
308
+		}
309
+		if laboratoryCostTotal > 0 {
310
+			ct.name = "化验费"
311
+			ct.price = laboratoryCostTotal
312
+			cts = append(cts, ct)
313
+
314
+		}
315
+		if treatCostTotal > 0 {
316
+			ct.name = "治疗费"
317
+			ct.price = treatCostTotal
318
+			cts = append(cts, ct)
319
+
320
+		}
321
+		if huliCostTotal > 0 {
322
+			ct.name = "护理费"
323
+			ct.price = huliCostTotal
324
+			cts = append(cts, ct)
325
+
326
+		}
327
+		if zhencaCostTotal > 0 {
328
+			ct.name = "诊察费"
329
+			ct.price = zhencaCostTotal
330
+			cts = append(cts, ct)
331
+
332
+		}
333
+		//org_config, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
334
+		var config2 models.FapiaoConfig
335
+		config2, _ = service.FindFaPiaoConfigInfo(c.GetAdminUserInfo().CurrentOrgId)
336
+		number := strconv.FormatInt(time.Now().Unix(), 10) + "_" + strconv.FormatInt(oss.UserOrgId, 10) + "_" + strconv.FormatInt(oss.PatientId, 10)
337
+		amountWithoutTax, _, taxAmount, _ := CalculatePriceDetails(MedfeeSumamt, 1, 0.00)
338
+		patient, _ := service.GetPatientByIDTwo(c.GetAdminUserInfo().CurrentOrgId, oss.PatientId)
339
+		oss.PsnName = patient.Name
340
+
341
+		requestBody2 := map[string]interface{}{
342
+			"taxNo":               config2.TerminalCode,
343
+			"taxUserName":         role.UserName,
344
+			"invoiceTerminalCode": "",
345
+			"isSplit":             "",
346
+			"orgCode":             "",
347
+			"taxDiskNo":           "",
348
+			"formatGenerate":      "",
349
+			"formatPushType":      "",
350
+			"completionCustom":    "",
351
+			"isAsync":             "",
352
+			"isReturnRedInfo":     "",
353
+		}
354
+		//var subData map[string]interface{}
355
+		subData := make(map[string]interface{})
356
+		subData["invoiceTypeCode"] = "02"
357
+		subData["paperInvoiceFlag"] = ""
358
+		subData["paperInvoiceTypeCode"] = ""
359
+		subData["paperInvoiceTypeCode"] = ""
360
+		subData["invoiceType"] = "0"
361
+		subData["invoiceSpecialMark"] = "00"
362
+		subData["isConfirmIssue"] = ""
363
+		subData["confirmIssue"] = ""
364
+		subData["taxationMethod"] = ""
365
+		subData["taxationLabel"] = ""
366
+		subData["reducedTaxCode"] = ""
367
+		subData["invoiceListMark"] = ""
368
+		subData["priceTaxMark"] = ""
369
+		subData["serialNo"] = number             // todo
370
+		subData["orderNo"] = ""                  //todo
371
+		subData["buyerTaxNo"] = patient.IdCardNo //todo
372
+		subData["buyerName"] = oss.PsnName + "(个人)"
373
+		subData["buyerAddressPhone"] = ""
374
+		subData["buyerBankAccount"] = ""
375
+		subData["drawer"] = role.UserName
376
+		subData["checker"] = ""
377
+		subData["payee"] = ""
378
+		subData["invoiceTotalPrice"] = MedfeeSumamt
379
+		subData["invoiceTotalTax"] = taxAmount
380
+		subData["invoiceTotalPriceTax"] = amountWithoutTax
381
+		subData["remarks"] = remark
382
+		subData["redInfoNo"] = ""
383
+		subData["originalInvoiceCode"] = ""
384
+		subData["originalInvoiceNo"] = ""
385
+		subData["deductibleAmount"] = ""
386
+		subData["sellerAddressPhone"] = ""
387
+		subData["sellerBankAccount"] = ""
388
+		//var subDetails []map[string]interface{}
389
+		subDetails := make([]map[string]interface{}, 0)
390
+		for index, item := range cts {
391
+			subDetailData := make(map[string]interface{})
392
+			amountWithoutTax_two, _, taxAmount_tow, _ := CalculatePriceDetails(item.price, 1, 0.00)
393
+			subDetailData["goodsLineNo"] = index + 1
394
+			subDetailData["originalInvoiceDetailNo"] = ""
395
+			subDetailData["invoiceLineNature"] = "0"
396
+			subDetailData["goodsCode"] = "3070202000000000000"
397
+			subDetailData["goodsBarCode"] = ""
398
+			subDetailData["goodsPersonalCode"] = ""
399
+			subDetailData["goodsName"] = item.name
400
+			subDetailData["goodsSpecification"] = ""
401
+			subDetailData["goodsUnit"] = ""
402
+			subDetailData["goodsQuantity"] = "1"
403
+			subDetailData["goodsPrice"] = amountWithoutTax_two
404
+			subDetailData["goodsTotalPrice"] = amountWithoutTax_two
405
+			subDetailData["goodsTotalTax"] = taxAmount_tow
406
+			subDetailData["goodsTaxRate"] = "0"
407
+			subDetailData["vatSpecialManagement"] = ""
408
+			subDetailData["freeTaxMark"] = "3"
409
+			subDetailData["preferentialMarkFlag"] = ""
410
+			subDetailData["goodsDiscountAmount"] = "0"
411
+			subDetails = append(subDetails, subDetailData)
412
+		}
413
+		subData["invoiceDetailsList"] = subDetails
414
+		requestBody2["data"] = subData
415
+
416
+		status, reason, response, request_log, response_log := OpenBWBlue(requestBody2)
417
+		if status == 0 { //失败 //TODO
418
+
419
+			if len(errs) == 0 {
420
+				errs = reason
421
+
422
+			} else {
423
+				errs = errs + "\n" + reason
424
+
425
+			}
426
+
427
+		} else { //成功
428
+			var fapiaos models.HisFaPiaoOrder
429
+			fapiaos.InvoiceId = response.Response.Success[0].SerialNo
430
+			fapiaos.OrderSn = response.Response.Success[0].SerialNo
431
+			fapiaos.OrderIds = strconv.FormatInt(oss.ID, 10)
432
+			fapiaos.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
433
+			fapiaos.Status = 1
434
+			// 解析日期字符串的布局(对应输入的格式)
435
+			layout := "20060102150405"
436
+
437
+			// 将字符串解析为时间对象
438
+			t, _ := time.Parse(layout, response.Response.Success[0].InvoiceDate)
439
+			// 将时间对象格式化为所需的输出格式
440
+			output := t.Format("2006-01-02 15:04:05")
441
+			fapiaos.TicketDate = output
442
+			fapiaos.PatientId = oss.PatientId
443
+			fapiaos.Ctime = time.Now().Unix()
444
+			fapiaos.Mtime = time.Now().Unix()
445
+			fapiaos.Creator = role.UserName
446
+			fapiaos.MedfeeSumamt = MedfeeSumamt
447
+			fapiaos.FundPaySumamt = FundPaySumamt
448
+			fapiaos.PsnCashPay = PsnCashPay
449
+			fapiaos.TicketSn = response.Response.Success[0].InvoiceNo
450
+			fapiaos.AmountWithTax = fmt.Sprintf("%.2f", response.Response.Success[0].InvoiceTotalPrice)
451
+			fapiaos.AmountWithoutTax = fmt.Sprintf("%.2f", response.Response.Success[0].InvoiceTotalPrice)
452
+			fapiaos.FapiaoStatus = "2"
453
+			fapiaos.TaxAmount = fmt.Sprintf("%.2f", response.Response.Success[0].InvoiceTotalTax)
454
+			fapiaos.IsRedWashed = "0"
455
+			fapiaos.PdfUrl = response.Response.Success[0].EInvoiceUrl
456
+			fapiaos.OfdUrl = ""
457
+			fapiaos.XmlUrl = ""
458
+			fapiaos.OfdUrl = ""
459
+			fapiaos.XmlUrl = ""
460
+			fapiaos.BlueRequestInfo = request_log
461
+			fapiaos.BlueResponseInfo = response_log
462
+			var ids_new []string
463
+			ids_new = append(ids_new, strconv.FormatInt(oss.ID, 10))
464
+			err := service.SaveFaPiaoOrder(&fapiaos)
465
+			err = service.UpdateFaPiaoSN(response.Response.Success[0].SerialNo, ids_new)      //同步发票号码
466
+			err = service.UpdateFaPiaoNumber(response.Response.Success[0].InvoiceNo, ids_new) //同步发票号码
467
+			fmt.Println(err)
468
+			status2, msg, result := BWBanShi(config2, response.Response.Success[0].InvoiceNo)
469
+			if status2 == 0 { //TODO
470
+				if len(errs) == 0 {
471
+					errs = msg
472
+				} else {
473
+					errs = errs + "\n" + msg
474
+				}
475
+			} else {
476
+				fapiaos.PdfUrl = result.Response.UrlMap.PdfUrl
477
+				fapiaos.OfdUrl = result.Response.UrlMap.OfdUrl
478
+				fapiaos.XmlUrl = result.Response.UrlMap.XmlUrl
479
+				service.SaveFaPiaoOrder(&fapiaos)
480
+				success = append(success, fapiaos.ID)
481
+			}
482
+
483
+		}
484
+
485
+	}
486
+	if len(ids) == len(success) {
487
+		c.ServeSuccessJSON(map[string]interface{}{
488
+			"msg": "批量开票成功",
489
+		})
490
+	} else {
491
+		if len(success) > 0 && len(success) <= len(ids) { // 部分成功
492
+			msgs := "部分开票成功,开票成功条数" + strconv.FormatInt(int64(len(success)), 10) + "条\n" + "开票失败原因:" + errs
493
+			c.ServeSuccessJSON(map[string]interface{}{
494
+				"failed_code": -10,
495
+				"msg":         msgs,
496
+			})
497
+
498
+		} else if len(success) == 0 {
499
+			msgs := "批量开票失败,开票失败原因:" + errs
500
+			c.ServeSuccessJSON(map[string]interface{}{
501
+				"failed_code": -10,
502
+				"msg":         msgs,
503
+			})
504
+
505
+		}
506
+	}
507
+}
52 508
 func signTopRequestTwo(params map[string]string, secret string, body map[string]interface{}) (string, error) {
509
+	fmt.Println(params)
510
+	fmt.Println(secret)
511
+	fmt.Println(body)
512
+
53 513
 	// 第一步:检查参数是否已经排序
54 514
 	keys := make([]string, 0, len(params))
55 515
 	for k := range params {
@@ -88,6 +548,91 @@ func signTopRequestTwo(params map[string]string, secret string, body map[string]
88 548
 	return sign, nil
89 549
 }
90 550
 
551
+func (c *FapiaoApiController) AllDownLoad() {
552
+	var downloadedFiles []string
553
+	now := time.Now()
554
+	dateStr1 := now.Format("2006-01-02")
555
+	fapiao_config, _ := service.GetFaPiaoOrderByIds()
556
+	downloadDir := "./发票/" + dateStr1 + "/"
557
+	for _, item := range fapiao_config {
558
+		if err := os.MkdirAll(downloadDir, os.ModePerm); err != nil {
559
+			fmt.Printf("Failed to create directory: %v\n", err)
560
+			return
561
+		}
562
+		fileName := fmt.Sprintf("%s.pdf", item.TicketSn)
563
+
564
+		// 下载文件
565
+		savePath := filepath.Join(downloadDir, fileName)
566
+		fmt.Printf("Downloading %s to %s...\n", item.PdfUrl, savePath)
567
+		err := DownloadFile(item.PdfUrl, savePath)
568
+		if err != nil {
569
+			fmt.Printf("Failed to download file: %v\n", err)
570
+		}
571
+		downloadedFiles = append(downloadedFiles, savePath)
572
+	}
573
+	// 检查下载结果
574
+	if len(downloadedFiles) > 0 {
575
+		c.ServeSuccessJSON(map[string]interface{}{
576
+			"msg": "下载成功",
577
+		})
578
+	}
579
+
580
+}
581
+
582
+func (c *FapiaoApiController) DownLoad() {
583
+	now := time.Now()
584
+	dateStr1 := now.Format("2006-01-02")
585
+	id, _ := c.GetInt64("id")
586
+	fapiao_config, _ := service.GetFaPiaoOrderById(id)
587
+	downloadDir := "./发票/" + dateStr1 + "/"
588
+	if err := os.MkdirAll(downloadDir, os.ModePerm); err != nil {
589
+		fmt.Printf("Failed to create directory: %v\n", err)
590
+		return
591
+	}
592
+	fileName := fmt.Sprintf("%s.pdf", fapiao_config.TicketSn)
593
+
594
+	// 下载文件
595
+	var downloadedFiles []string
596
+	savePath := filepath.Join(downloadDir, fileName)
597
+	fmt.Printf("Downloading %s to %s...\n", fapiao_config.PdfUrl, savePath)
598
+	err := DownloadFile(fapiao_config.PdfUrl, savePath)
599
+	if err != nil {
600
+		fmt.Printf("Failed to download file: %v\n", err)
601
+	}
602
+	downloadedFiles = append(downloadedFiles, savePath)
603
+	// 检查下载结果
604
+	if len(downloadedFiles) > 0 {
605
+		c.ServeSuccessJSON(map[string]interface{}{
606
+			"msg": "下载成功",
607
+		})
608
+	}
609
+}
610
+
611
+func DownloadFile(url, savePath string) error {
612
+	resp, err := http.Get(url)
613
+	if err != nil {
614
+		return fmt.Errorf("failed to download file: %v", err)
615
+	}
616
+	defer resp.Body.Close()
617
+
618
+	if resp.StatusCode != http.StatusOK {
619
+		return fmt.Errorf("bad status: %s", resp.Status)
620
+	}
621
+
622
+	out, err := os.Create(savePath)
623
+	if err != nil {
624
+		return fmt.Errorf("failed to create file: %v", err)
625
+	}
626
+	defer out.Close()
627
+
628
+	_, err = io.Copy(out, resp.Body)
629
+	if err != nil {
630
+		return fmt.Errorf("failed to save file: %v", err)
631
+	}
632
+
633
+	return nil
634
+}
635
+
91 636
 func (c *FapiaoApiController) BwOpenBlueFaPiao() {
92 637
 	//判断是否处于登录状态
93 638
 	//开蓝票逻辑
@@ -104,6 +649,12 @@ func (c *FapiaoApiController) BwOpenBlueFaPiao() {
104 649
 	var HifpPay float64 = 0  //治疗费用
105 650
 	var AcctPay float64 = 0  //治疗费用
106 651
 
652
+	var GongWuYuan float64 = 0 //治疗费用
653
+
654
+	var BuCong float64 = 0 //治疗费用
655
+
656
+	var OthPay float64 = 0 //治疗费用
657
+
107 658
 	var details []models.HisOrderInfo
108 659
 	var numbers []string
109 660
 	decimal.DivisionPrecision = 2
@@ -118,78 +669,103 @@ func (c *FapiaoApiController) BwOpenBlueFaPiao() {
118 669
 		HifpPay, _ = decimal.NewFromFloat(HifpPay).Add(decimal.NewFromFloat(oss.HifpPay)).Float64()
119 670
 		AcctPay, _ = decimal.NewFromFloat(AcctPay).Add(decimal.NewFromFloat(oss.AcctPay)).Float64()
120 671
 
672
+		GongWuYuan, _ = decimal.NewFromFloat(GongWuYuan).Add(decimal.NewFromFloat(oss.CvlservPay)).Float64()
673
+
674
+		BuCong, _ = decimal.NewFromFloat(BuCong).Add(decimal.NewFromFloat(oss.HifesPay)).Float64()
675
+
676
+		OthPay, _ = decimal.NewFromFloat(OthPay).Add(decimal.NewFromFloat(oss.OthPay)).Float64()
121 677
 		numbers = append(numbers, oss.Number)
122 678
 	}
123
-	if MedfeeSumamt > 0 {
124
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
679
+	// 假设你有一个以秒为单位的时间戳
680
+	timestamp := orders[0].SettleAccountsDate // 例如:2023-01-01T00:00:00Z
681
+	// 将时间戳转换为time.Time对象
682
+	t := time.Unix(timestamp, 0) // 第二个参数是纳秒,这里我们不需要转换,所以设为0
683
+	// 格式化日期和时间
684
+	//fmt.Println(t.Format("2006-01-02"))
125 685
 
126
-		if len(remark) == 0 {
127
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
128
-			remark = "医疗总费用: " + MedfeeSumamt_str
129
-		} else {
130
-			remark = remark + " 医疗总费用:" + MedfeeSumamt_str
131
-		}
686
+	remark = "治疗时间: " + t.Format("2006-01-02")
687
+
688
+	MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
689
+
690
+	if len(remark) == 0 {
691
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
692
+		remark = "医疗总费用: " + MedfeeSumamt_str
693
+	} else {
694
+		remark = remark + " 医疗总费用:" + MedfeeSumamt_str
132 695
 	}
133
-	if FundPaySumamt > 0 {
134
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", FundPaySumamt)
696
+	FundPaySumamt_str := fmt.Sprintf("%.2f", FundPaySumamt)
135 697
 
136
-		if len(remark) == 0 {
137
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
138
-			remark = "基金支付总金额: " + MedfeeSumamt_str
139
-		} else {
140
-			remark = remark + " 基金支付总金额:" + MedfeeSumamt_str
141
-		}
698
+	if len(remark) == 0 {
699
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
700
+		remark = "基金支付总金额: " + FundPaySumamt_str
701
+	} else {
702
+		remark = remark + " 基金支付总金额:" + FundPaySumamt_str
142 703
 	}
143
-	if PsnCashPay > 0 {
144
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", PsnCashPay)
704
+	HifpPay_str := fmt.Sprintf("%.2f", HifpPay)
145 705
 
146
-		if len(remark) == 0 {
147
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
148
-			remark = "个人现金支付: " + MedfeeSumamt_str
149
-		} else {
150
-			remark = remark + " 个人现金支付:" + MedfeeSumamt_str
151
-		}
706
+	if len(remark) == 0 {
707
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
708
+		remark = "基本统筹基金支付: " + HifpPay_str
709
+	} else {
710
+		remark = remark + " 基本统筹基金支付:" + HifpPay_str
152 711
 	}
153
-	if HifmiPay > 0 {
154
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", HifmiPay)
155 712
 
156
-		if len(remark) == 0 {
157
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
158
-			remark = "大病基金支付: " + MedfeeSumamt_str
159
-		} else {
160
-			remark = remark + " 大病基金支付:" + MedfeeSumamt_str
161
-		}
713
+	HifmiPay_str := fmt.Sprintf("%.2f", HifmiPay)
714
+
715
+	if len(remark) == 0 {
716
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
717
+		remark = "大病基金支付: " + HifmiPay_str
718
+	} else {
719
+		remark = remark + " 大病基金支付:" + HifmiPay_str
162 720
 	}
163
-	if AcctPay > 0 {
164
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", AcctPay)
165 721
 
166
-		if len(remark) == 0 {
167
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
168
-			remark = "个账支付: " + MedfeeSumamt_str
169
-		} else {
170
-			remark = remark + " 个账支付:" + MedfeeSumamt_str
171
-		}
722
+	GongWuYuan_str := fmt.Sprintf("%.2f", GongWuYuan)
723
+
724
+	if len(remark) == 0 {
725
+		remark = "公务员支付: " + GongWuYuan_str
726
+	} else {
727
+		remark = remark + " 公务员支付:" + GongWuYuan_str
172 728
 	}
173
-	if HifpPay > 0 {
174
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", HifpPay)
175 729
 
176
-		if len(remark) == 0 {
177
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
178
-			remark = "基本统筹基金支付: " + MedfeeSumamt_str
179
-		} else {
180
-			remark = remark + " 基本统筹基金支付:" + MedfeeSumamt_str
181
-		}
730
+	BuCong_str := fmt.Sprintf("%.2f", BuCong)
731
+
732
+	if len(remark) == 0 {
733
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
734
+		remark = "补充医疗保险支付: " + BuCong_str
735
+	} else {
736
+		remark = remark + " 补充医疗保险支付:" + BuCong_str
182 737
 	}
183
-	if MafPay > 0 {
184
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", MafPay)
185 738
 
186
-		if len(remark) == 0 {
187
-			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
188
-			remark = "医疗救助基金支付: " + MedfeeSumamt_str
189
-		} else {
190
-			remark = remark + " 医疗救助基金支付:" + MedfeeSumamt_str
191
-		}
739
+	MafPay_str := fmt.Sprintf("%.2f", MafPay)
740
+
741
+	if len(remark) == 0 {
742
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
743
+		remark = "医疗救助基金支付: " + MafPay_str
744
+	} else {
745
+		remark = remark + " 医疗救助基金支付:" + MafPay_str
746
+	}
747
+	OthPay_str := fmt.Sprintf("%.2f", OthPay)
748
+	if len(remark) == 0 {
749
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
750
+		remark = "其他支付: " + OthPay_str
751
+	} else {
752
+		remark = remark + " 其他支付:" + OthPay_str
192 753
 	}
754
+	AcctPay_str := fmt.Sprintf("%.2f", AcctPay)
755
+	if len(remark) == 0 {
756
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
757
+		remark = "医保账户支付: " + AcctPay_str
758
+	} else {
759
+		remark = remark + " 医保账户支付:" + AcctPay_str
760
+	}
761
+	PsnCashPay_str := fmt.Sprintf("%.2f", PsnCashPay)
762
+	if len(remark) == 0 {
763
+		//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
764
+		remark = "个人现金支付: " + PsnCashPay_str
765
+	} else {
766
+		remark = remark + " 个人现金支付:" + PsnCashPay_str
767
+	}
768
+
193 769
 	details, _ = service.GetFaPiaoOrderInfoByNumbers(numbers)
194 770
 	role, _ := service.GetAdminUserRole(admin_user_id, c.GetAdminUserInfo().CurrentOrgId)
195 771
 	role.UserName = ""
@@ -360,9 +936,9 @@ func (c *FapiaoApiController) BwOpenBlueFaPiao() {
360 936
 	subData["reducedTaxCode"] = ""
361 937
 	subData["invoiceListMark"] = ""
362 938
 	subData["priceTaxMark"] = ""
363
-	subData["serialNo"] = number // todo
364
-	subData["orderNo"] = ""      //todo
365
-	subData["buyerTaxNo"] = ""   //todo
939
+	subData["serialNo"] = number             // todo
940
+	subData["orderNo"] = ""                  //todo
941
+	subData["buyerTaxNo"] = patient.IdCardNo //todo
366 942
 	subData["buyerName"] = orders[0].PsnName + "(个人)"
367 943
 	subData["buyerAddressPhone"] = ""
368 944
 	subData["buyerBankAccount"] = ""
@@ -406,11 +982,12 @@ func (c *FapiaoApiController) BwOpenBlueFaPiao() {
406 982
 	}
407 983
 	subData["invoiceDetailsList"] = subDetails
408 984
 	requestBody2["data"] = subData
985
+
409 986
 	status, reason, response, request_log, response_log := OpenBWBlue(requestBody2)
410 987
 	if status == 0 { //失败
411 988
 		c.ServeSuccessJSON(map[string]interface{}{
412
-			"status": -10,
413
-			"msg":    reason,
989
+			"failed_code": -10,
990
+			"msg":         reason,
414 991
 		})
415 992
 	} else { //成功
416 993
 		var fapiaos models.HisFaPiaoOrder
@@ -507,6 +1084,7 @@ func (c *FapiaoApiController) BwOpenRedFaPiao() {
507 1084
 
508 1085
 }
509 1086
 func (c *FapiaoApiController) QueryBwFaPiao() {
1087
+	fmt.Println("------")
510 1088
 	id, _ := c.GetInt64("id")
511 1089
 	oc, _ := service.GetFaPiaoOrderById(id)
512 1090
 	var config models.FapiaoConfig
@@ -568,24 +1146,32 @@ func OpenBWBlue(requestBody2 map[string]interface{}) (int64, string, bwfapiao.In
568 1146
 			return 0, result.ErrorResponse.Message + "\n" + result.ErrorResponse.SubMessage, result, string(reques_log), response
569 1147
 		}
570 1148
 	} else { //token 不存在,则进行获取token的操作
571
-		fmt.Println("token 不存在")
572 1149
 
573 1150
 		tokenResp, _ := GetAccessToken("https://openapi.baiwang.com/router/rest", "b033l65qAA", "cc73223bd14a4064bb0fe9ba642da58f", "10059482", "bb481e0c-9895-44d8-b184-6b9707a60ec7", "admin_ffzyx16zmybx4", "")
574 1151
 		fmt.Println(tokenResp)
575 1152
 
576 1153
 		if len(tokenResp.Response.AccessToken) > 0 { //token请求成功,则将token和有效时间存储进redis,
577 1154
 			redisClient.Set("fapiao_access_token", tokenResp.Response.AccessToken, time.Duration(tokenResp.Response.ExpiresIn)*time.Second)
578
-			params["token"] = tokenResp.Response.AccessToken
579 1155
 			// 生成签名
580
-			sign, err = signTopRequestTwo(params, secret, requestBody2)
1156
+			secret = "bb481e0c-9895-44d8-b184-6b9707a60ec7"
1157
+			params_two := map[string]string{
1158
+				"method":    "baiwang.output.invoice.issue",
1159
+				"version":   "6.0",
1160
+				"appKey":    "10059482",
1161
+				"format":    "json",
1162
+				"timestamp": strconv.FormatInt(time.Now().Unix(), 10),
1163
+				"token":     tokenResp.Response.AccessToken,
1164
+				"type":      "sync",
1165
+			}
1166
+			sign, err = signTopRequestTwo(params_two, secret, requestBody2)
581 1167
 			if err != nil {
582 1168
 				fmt.Println("Error:", err)
583 1169
 				return 0, err.Error(), result, string(reques_log), ""
584 1170
 			}
585
-			params["sign"] = sign
1171
+			params_two["sign"] = sign
586 1172
 
587 1173
 			// 调用 API
588
-			response, err := callApiTwo("https://openapi.baiwang.com/router/rest", params, requestBody2)
1174
+			response, err := callApiTwo("https://openapi.baiwang.com/router/rest", params_two, requestBody2)
589 1175
 			if err != nil {
590 1176
 				fmt.Println("接口调用失败:", err)
591 1177
 				return 0, err.Error(), result, string(reques_log), response
@@ -711,16 +1297,18 @@ func OpenBWRed(config models.FapiaoConfig, orders models.HisFaPiaoOrder) (int64,
711 1297
 			remark = remark + " 基金支付总金额:" + MedfeeSumamt_str
712 1298
 		}
713 1299
 	}
714
-	if PsnCashPay > 0 {
715
-		MedfeeSumamt_str := fmt.Sprintf("%.2f", PsnCashPay)
1300
+
1301
+	if HifmiPay > 0 {
1302
+		MedfeeSumamt_str := fmt.Sprintf("%.2f", HifmiPay)
716 1303
 
717 1304
 		if len(remark) == 0 {
718 1305
 			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
719
-			remark = "个人现金支付: " + MedfeeSumamt_str
1306
+			remark = "大病基金支付: " + MedfeeSumamt_str
720 1307
 		} else {
721
-			remark = remark + " 个人现金支付:" + MedfeeSumamt_str
1308
+			remark = remark + " 大病基金支付:" + MedfeeSumamt_str
722 1309
 		}
723 1310
 	}
1311
+
724 1312
 	if HifmiPay > 0 {
725 1313
 		MedfeeSumamt_str := fmt.Sprintf("%.2f", HifmiPay)
726 1314
 
@@ -731,6 +1319,18 @@ func OpenBWRed(config models.FapiaoConfig, orders models.HisFaPiaoOrder) (int64,
731 1319
 			remark = remark + " 大病基金支付:" + MedfeeSumamt_str
732 1320
 		}
733 1321
 	}
1322
+
1323
+	if PsnCashPay > 0 {
1324
+		MedfeeSumamt_str := fmt.Sprintf("%.2f", PsnCashPay)
1325
+
1326
+		if len(remark) == 0 {
1327
+			//MedfeeSumamt_str := fmt.Sprintf("%.2f", MedfeeSumamt)
1328
+			remark = "个人现金支付: " + MedfeeSumamt_str
1329
+		} else {
1330
+			remark = remark + " 个人现金支付:" + MedfeeSumamt_str
1331
+		}
1332
+	}
1333
+
734 1334
 	if AcctPay > 0 {
735 1335
 		MedfeeSumamt_str := fmt.Sprintf("%.2f", AcctPay)
736 1336
 
@@ -1371,7 +1971,7 @@ type AuthResponse struct {
1371 1971
 // GetAccessToken 获取登录授权的 access_token
1372 1972
 func GetAccessToken(apiURL, plainPassword, salt, clientID, clientSecret, username, orgAuthCode string) (AuthResponse, error) {
1373 1973
 	// 当前时间戳(毫秒级)
1374
-	timestamp := ""
1974
+	timestamp := strconv.FormatInt(time.Now().Unix(), 10)
1375 1975
 
1376 1976
 	// 密码加密:MD5 + SHA1
1377 1977
 	encryptedPassword := md5AndSha1(plainPassword + salt)
@@ -1384,7 +1984,6 @@ func GetAccessToken(apiURL, plainPassword, salt, clientID, clientSecret, usernam
1384 1984
 
1385 1985
 	// 构造请求体
1386 1986
 	authReq := map[string]interface{}{
1387
-
1388 1987
 		"client_secret": clientSecret,
1389 1988
 		"username":      username,
1390 1989
 		"password":      encryptedPassword,
@@ -1392,13 +1991,11 @@ func GetAccessToken(apiURL, plainPassword, salt, clientID, clientSecret, usernam
1392 1991
 	}
1393 1992
 
1394 1993
 	var aa AuthResponse
1395
-
1396 1994
 	// 转换为 JSON
1397 1995
 	reqBody, err := json.Marshal(authReq)
1398 1996
 	if err != nil {
1399 1997
 		return aa, fmt.Errorf("failed to marshal request: %v", err)
1400 1998
 	}
1401
-
1402 1999
 	// 发送 POST 请求
1403 2000
 	resp, err := http.Post(apiURL+"?"+"version="+"6.0"+"&method="+"baiwang.oauth.token"+"&grant_type="+"password"+"&client_id="+clientID+"&timestamp="+timestamp, "application/json", bytes.NewBuffer(reqBody))
1404 2001
 	if err != nil {

+ 2 - 0
controllers/his_charge_api_controller.go Parādīt failu

@@ -506,6 +506,8 @@ func (c *HisChargeApiController) GetPrescriptionStatisticsDetail() {
506 506
 	patient_id, _ := c.GetInt64("patient_id")
507 507
 	item_type, _ := c.GetInt64("type")
508 508
 
509
+	//time_type, _ := c.GetInt64("time_type")
510
+
509 511
 	//date1, _ := time.Parse("2006-01-02", start_time)
510 512
 	//date2, _ := time.Parse("2006-01-02", end_time)
511 513
 	// 计算日期间隔

+ 117 - 35
controllers/yh_api_controller.go Parādīt failu

@@ -111,7 +111,6 @@ package controllers
111 111
 //
112 112
 //	return nil
113 113
 //}
114
-//
115 114
 //func UploadDiase(org_id int64) error {
116 115
 //	patients := service.GetAllPatients(org_id)
117 116
 //	var hdreq models.HDRequest
@@ -187,7 +186,6 @@ package controllers
187 186
 //
188 187
 //	return nil
189 188
 //}
190
-//
191 189
 //func UploadZhuanGui(org_id int64) error {
192 190
 //	//syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
193 191
 //	//var sync_time int64
@@ -280,7 +278,6 @@ package controllers
280 278
 //
281 279
 //	return nil
282 280
 //}
283
-//
284 281
 //func UploadTrtPlan(org_id int64) error {
285 282
 //	//syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
286 283
 //	//var sync_time int64
@@ -340,7 +337,7 @@ package controllers
340 337
 //	// 构建请求数据
341 338
 //	requestData := map[string]interface{}{
342 339
 //		"data": map[string]interface{}{
343
-//			"hd_data_type": "outCome", // 患者信息类型
340
+//			"hd_data_type": "trtPlan", // 患者信息类型
344 341
 //			"hd_data":      plans,
345 342
 //		},
346 343
 //	}
@@ -386,7 +383,6 @@ package controllers
386 383
 //
387 384
 //	return nil
388 385
 //}
389
-//
390 386
 //func UploadSch(org_id int64) error {
391 387
 //	//syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
392 388
 //	//var sync_time int64
@@ -431,7 +427,7 @@ package controllers
431 427
 //	// 构建请求数据
432 428
 //	requestData := map[string]interface{}{
433 429
 //		"data": map[string]interface{}{
434
-//			"hd_data_type": "outCome", // 患者信息类型
430
+//			"hd_data_type": "schedule", // 患者信息类型
435 431
 //			"hd_data":      schs,
436 432
 //		},
437 433
 //	}
@@ -477,7 +473,6 @@ package controllers
477 473
 //
478 474
 //	return nil
479 475
 //}
480
-//
481 476
 //func UploadOrder(org_id int64) error {
482 477
 //	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
483 478
 //	var sync_time int64
@@ -575,7 +570,6 @@ package controllers
575 570
 //
576 571
 //	return nil
577 572
 //}
578
-//
579 573
 //func Uploadbf(org_id int64) error {
580 574
 //	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
581 575
 //	var sync_time int64
@@ -587,6 +581,80 @@ package controllers
587 581
 //
588 582
 //	ps := service.GetAllDialysisRecord(org_id, sync_time)
589 583
 //
584
+//	var drs []models.PreDialysisRecord
585
+//	for _, item := range ps {
586
+//		var dr models.PreDialysisRecord
587
+//		order := service.GetAllPatientDialysisRecord(org_id, item.DialysisDate, item.PatientId)
588
+//		sch, _ := service.GetScheduleByPatient(item.PatientId, item.DialysisDate, org_id)
589
+//		pre, _ := service.GetDialysisPrescribe(org_id, item.PatientId, item.DialysisDate)
590
+//		str2 := strconv.Itoa(int(sch.ID))
591
+//		dr.TagtWaterVal = pre.TargetUltrafiltration
592
+//		dr.BtchID = str2
593
+//		dr.RxWateVal = pre.PrescriptionDewatering
594
+//		s1 := fmt.Sprintf("%f", order.KyyPredialysisEvaluation.WeightBefore)
595
+//		dr.BfWt = s1
596
+//		drs = append(drs, dr)
597
+//	}
598
+//	// 构建请求数据
599
+//	requestData := map[string]interface{}{
600
+//		"data": map[string]interface{}{
601
+//			"hd_data_type": "bfHd", // 患者信息类型
602
+//			"hd_data":      drs,
603
+//		},
604
+//	}
605
+//
606
+//	// 转换为 JSON
607
+//	jsonData, err := json.Marshal(requestData)
608
+//	if err != nil {
609
+//		return fmt.Errorf("JSON 编码失败: %v", err)
610
+//	}
611
+//
612
+//	// 创建 HTTP 请求
613
+//	req, err := http.NewRequest("POST", "https://ggfw.scyb.org.cn/ims/his/outside/api/scen/twoDecisions/hdDataUpload", bytes.NewBuffer(jsonData))
614
+//	if err != nil {
615
+//		return fmt.Errorf("创建请求失败: %v", err)
616
+//	}
617
+//
618
+//	// 设置请求头
619
+//	req.Header.Set("Content-Type", "application/json")
620
+//	// 根据实际需要添加其他请求头,如认证信息等
621
+//	// req.Header.Set("Authorization", "Bearer your_token")
622
+//
623
+//	// 发送请求
624
+//	client := &http.Client{}
625
+//	resp, err := client.Do(req)
626
+//	if err != nil {
627
+//		return fmt.Errorf("请求发送失败: %v", err)
628
+//	}
629
+//	defer resp.Body.Close()
630
+//
631
+//	// 读取响应
632
+//	body, err := io.ReadAll(resp.Body)
633
+//	if err != nil {
634
+//		return fmt.Errorf("读取响应失败: %v", err)
635
+//	}
636
+//
637
+//	// 检查响应状态
638
+//	if resp.StatusCode != http.StatusOK {
639
+//		return fmt.Errorf("请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
640
+//	}
641
+//
642
+//	// 处理响应数据
643
+//	fmt.Printf("上传成功,响应: %s\n", string(body))
644
+//
645
+//	return nil
646
+//}
647
+//func Uploadhdbf(org_id int64) error {
648
+//	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
649
+//	var sync_time int64
650
+//	if syncLastInfo.ID > 0 {
651
+//		sync_time = syncLastInfo.SyncTime
652
+//	} else {
653
+//		sync_time = 0
654
+//	}
655
+//
656
+//	ps := service.GetAllDialysisRecord(org_id, sync_time)
657
+//
590 658
 //	var drs []models.DialysisRecord
591 659
 //
592 660
 //	for _, item := range ps {
@@ -673,7 +741,6 @@ package controllers
673 741
 //
674 742
 //	return nil
675 743
 //}
676
-//
677 744
 //func Uploadmo(org_id int64) error {
678 745
 //	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
679 746
 //	var sync_time int64
@@ -768,7 +835,6 @@ package controllers
768 835
 //
769 836
 //	return nil
770 837
 //}
771
-//
772 838
 //func Uploadaf(org_id int64) error {
773 839
 //	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
774 840
 //	var sync_time int64
@@ -845,7 +911,6 @@ package controllers
845 911
 //
846 912
 //	return nil
847 913
 //}
848
-//
849 914
 //func Uploadtrt(org_id int64) error {
850 915
 //	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
851 916
 //	var sync_time int64
@@ -857,26 +922,29 @@ package controllers
857 922
 //
858 923
 //	ps := service.GetAllDialysisRecord(org_id, sync_time)
859 924
 //
860
-//	var drs []models.PostDialysisRecord
925
+//	var drs []models.YHTreatmentSummary
861 926
 //	for _, item := range ps {
862
-//		var dr models.PostDialysisRecord
927
+//		var dr models.YHTreatmentSummary
863 928
 //		order := service.GetAllPatientDialysisRecord(org_id, item.DialysisDate, item.PatientId)
864 929
 //		sch, _ := service.GetScheduleByPatient(item.PatientId, item.DialysisDate, org_id)
865 930
 //		str2 := strconv.Itoa(int(sch.ID))
866
-//		dr.AfSymp = order.KyyAssessmentAfterDislysis.SymptomAfterDialysis
867
-//		dr.ClotDeg = str2
868
-//		dr.ImptStas = order.KyyAssessmentAfterDislysis.InternalFistula
869
-//		s2 := fmt.Sprintf("%f", order.KyyAssessmentAfterDislysis.WeightAfter)
870
-//		s3 := fmt.Sprintf("%f", sch.ID)
871
-//		dr.AfWt = s2
872
-//		dr.ActFitrCnt = order.KyyAssessmentAfterDislysis.ActualUltrafiltration
873
-//		dr.BtchID = s3
931
+//		PunctureRole, _ := service.GetAdminUserRoleTwo(order.KyyTreatmentSummary.Puncture, org_id)
932
+//		ZlRole, _ := service.GetAdminUserRole(order.KyyTreatmentSummary.ZlNurse, org_id)
933
+//		FinishRole, _ := service.GetAdminUserRole(order.FinishNurse, org_id)
934
+//		PrescriptionDoctor, _ := service.GetAdminUserRole(order.KYYPrescriptionVM.PrescriptionDoctor, org_id)
935
+//		dr.PncrNurs = PunctureRole.UserName
936
+//		dr.TrtNurs = ZlRole.UserName
937
+//		dr.Chker = ""
938
+//		dr.OffMchNurs = FinishRole.UserName
939
+//		dr.TrtDr = PrescriptionDoctor.UserName
940
+//		dr.BtchID = str2
941
+//		dr.RsltCont = order.KyyTreatmentSummary.DialysisSummary
874 942
 //		drs = append(drs, dr)
875 943
 //	}
876 944
 //	// 构建请求数据
877 945
 //	requestData := map[string]interface{}{
878 946
 //		"data": map[string]interface{}{
879
-//			"hd_data_type": "afHd", // 患者信息类型
947
+//			"hd_data_type": "trtRslt", // 患者信息类型
880 948
 //			"hd_data":      drs,
881 949
 //		},
882 950
 //	}
@@ -919,20 +987,34 @@ package controllers
919 987
 //}
920 988
 //
921 989
 //func UploadDoc(org_id int64) error {
922
-//	//syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
923
-//	//var sync_time int64
924
-//	//if syncLastInfo.ID > 0 {
925
-//	//	sync_time = syncLastInfo.SyncTime
926
-//	//} else {
927
-//	//	sync_time = 0
928
-//	//}
929 990
 //
930
-//	// 构建请求数据
931
-//	requestData := map[string]interface{}{
932
-//		"data": map[string]interface{}{
933
-//			"hd_data_type": "outCome", // 患者信息类型
934
-//			"hd_data":      schs,
935
-//		},
991
+//	syncLastInfo, _ := service.GetSyncTimeByOrgId(org_id, 10)
992
+//	var sync_time int64
993
+//	if syncLastInfo.ID > 0 {
994
+//		sync_time = syncLastInfo.SyncTime
995
+//	} else {
996
+//		sync_time = 0
997
+//	}
998
+//	ps := service.GetAllDialysisRecord(org_id, sync_time)
999
+//
1000
+//	var drs []models.YHDialysisOrder
1001
+//	for _, item := range ps {
1002
+//		var dr models.YHDialysisOrder
1003
+//		order := service.GetAllPatientDialysisRecord(org_id, item.DialysisDate, item.PatientId)
1004
+//		sch, _ := service.GetScheduleByPatient(item.PatientId, item.DialysisDate, org_id)
1005
+//		str2 := strconv.Itoa(int(sch.ID))
1006
+//		PunctureRole, _ := service.GetAdminUserRoleTwo(order.KyyTreatmentSummary.Puncture, org_id)
1007
+//		ZlRole, _ := service.GetAdminUserRole(order.KyyTreatmentSummary.ZlNurse, org_id)
1008
+//		FinishRole, _ := service.GetAdminUserRole(order.FinishNurse, org_id)
1009
+//		PrescriptionDoctor, _ := service.GetAdminUserRole(order.KYYPrescriptionVM.PrescriptionDoctor, org_id)
1010
+//		dr.PncrNurs = PunctureRole.UserName
1011
+//		dr.TrtNurs = ZlRole.UserName
1012
+//		dr.Chker = ""
1013
+//		dr.OffMchNurs = FinishRole.UserName
1014
+//		dr.TrtDr = PrescriptionDoctor.UserName
1015
+//		dr.BtchID = str2
1016
+//		dr.RsltCont = order.KyyTreatmentSummary.DialysisSummary
1017
+//		drs = append(drs, dr)
936 1018
 //	}
937 1019
 //
938 1020
 //	// 转换为 JSON

+ 1 - 0
models/YH_models.go Parādīt failu

@@ -1123,6 +1123,7 @@ type KYYDialysisOrder struct {
1123 1123
 	Condenser                  string                     `gorm:"column:condenser" json:"condenser" form:"condenser"`
1124 1124
 	BloodDrawing               int64                      `gorm:"column:blood_drawing" json:"blood_drawing" form:"blood_drawing"`
1125 1125
 	DialysisStrainer           string                     `gorm:"column:dialysis_strainer" json:"dialysis_strainer" form:"dialysis_strainer"`
1126
+	KYYPrescriptionVM          KYYPrescriptionVM          `json:"p" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
1126 1127
 	KyyPredialysisEvaluation   KyyPredialysisEvaluation   `json:"pre" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
1127 1128
 	KyyAssessmentAfterDislysis KyyAssessmentAfterDislysis `json:"after" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`
1128 1129
 	KyyTreatmentSummary        KyyTreatmentSummary        `json:"summary" gorm:"foreignkey:PatientId;AssociationForeignKey:PatientId;"`

+ 6 - 3
models/fapiao.go Parādīt failu

@@ -109,9 +109,12 @@ type SettleAccountsDateOrder struct {
109 109
 	UserOrgId          int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
110 110
 	HisPatientId       int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
111 111
 	SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
112
-	Ctime              int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
113
-	Mtime              int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
114
-	Status             int64 `gorm:"column:status" json:"status" form:"status"`
112
+
113
+	SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
114
+
115
+	Ctime  int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
116
+	Mtime  int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
117
+	Status int64 `gorm:"column:status" json:"status" form:"status"`
115 118
 }
116 119
 
117 120
 func (SettleAccountsDateOrder) TableName() string {

+ 350 - 86
service/app_version.go Parādīt failu

@@ -2,9 +2,11 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_New/models"
5
+	"encoding/json"
5 6
 	"fmt"
6 7
 	"github.com/jinzhu/gorm"
7 8
 	"math"
9
+	"os"
8 10
 	"strconv"
9 11
 	"strings"
10 12
 	"time"
@@ -487,83 +489,83 @@ func GetAllProject(id int64) (pre []*models.HisPrescriptionProject) {
487 489
 //}
488 490
 
489 491
 type HisOrderTen struct {
490
-	ID                    int64                 `gorm:"column:id" json:"id" form:"id"`
491
-	UserOrgId             int64                 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
492
-	HisPatientId          int64                 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
493
-	SettleAccountsDate    int64                 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
494
-	Ctime                 int64                 `gorm:"column:ctime" json:"ctime" form:"ctime"`
495
-	Mtime                 int64                 `gorm:"column:mtime" json:"mtime" form:"mtime"`
496
-	Status                int64                 `gorm:"column:status" json:"status" form:"status"`
497
-	Number                string                `gorm:"column:number" json:"number" form:"number"`
498
-	PatientId             int64                 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
499
-	Infcode               int64                 `gorm:"column:infcode" json:"infcode" form:"infcode"`
500
-	WarnMsg               string                `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
501
-	Cainfo                string                `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
502
-	ErrMsg                string                `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
503
-	RespondTime           string                `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
504
-	InfRefmsgid           string                `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
505
-	OrderStatus           int64                 `gorm:"column:order_status" json:"order_status" form:"order_status"`
506
-	MdtrtId               string                `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
507
-	SetlId                string                `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
508
-	PsnNo                 string                `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
509
-	PsnName               string                `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
510
-	PsnCertType           string                `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
511
-	Certno                string                `gorm:"column:certno" json:"certno" form:"certno"`
512
-	Gend                  string                `gorm:"column:gend" json:"gend" form:"gend"`
513
-	Naty                  string                `gorm:"column:naty" json:"naty" form:"naty"`
514
-	Brdy                  time.Time             `gorm:"column:brdy" json:"brdy" form:"brdy"`
515
-	Age                   float64               `gorm:"column:age" json:"age" form:"age"`
516
-	Insutype              string                `gorm:"column:insutype" json:"insutype" form:"insutype"`
517
-	PsnType               string                `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
518
-	CvlservFlag           string                `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
519
-	SetlTime              string                `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
520
-	MdtrtCertType         string                `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
521
-	MedType               string                `gorm:"column:med_type" json:"med_type" form:"med_type"`
522
-	MedfeeSumamt          float64               `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
523
-	FulamtOwnpayAmt       float64               `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
524
-	OverlmtSelfPay        float64               `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
525
-	PreselfpayAmt         float64               `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
526
-	InscpScpAmt           float64               `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
527
-	ActPayDedc            float64               `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
528
-	HifpPay               float64               `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
529
-	CvlservPay            float64               `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
530
-	PoolPropSelfpay       float64               `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
531
-	HifesPay              float64               `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
532
-	HifmiPay              float64               `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
533
-	HifobPay              float64               `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
534
-	MafPay                float64               `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
535
-	OthPay                float64               `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
536
-	FundPaySumamt         float64               `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
537
-	PsnPartAmt            float64               `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
538
-	AcctPay               float64               `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
539
-	PsnCashPay            float64               `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
540
-	HospPartAmt           float64               `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
541
-	Balc                  float64               `gorm:"column:balc" json:"balc" form:"balc"`
542
-	AcctMulaidPay         float64               `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
543
-	MedinsSetlId          string                `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
544
-	ClrOptins             string                `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
545
-	ClrWay                string                `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
546
-	ClrType               string                `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
547
-	SetlDetail            string                `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
548
-	IsMedicineInsurance   int64                 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
549
-	PayWay                int64                 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
550
-	PayPrice              float64               `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
551
-	PayCardNo             string                `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
552
-	DiscountPrice         float64               `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
553
-	PreferentialPrice     float64               `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
554
-	RealityPrice          float64               `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
555
-	FoundPrice            float64               `gorm:"column:found_price" json:"found_price" form:"found_price"`
556
-	MedicalInsurancePrice float64               `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
557
-	PrivatePrice          float64               `gorm:"column:private_price" json:"private_price" form:"private_price"`
558
-	DepartmentName        string                `gorm:"-" json:"department_name" form:"department_name"`
559
-	DoctorName            string                `gorm:"-" json:"doctor_name" form:"doctor_name"`
560
-	Creator               int64                 `gorm:"column:creator" json:"creator" form:"creator"`
561
-	PType                 int64                 `gorm:"column:p_type" json:"p_type" form:"p_type"`
562
-	Decimal               float64               `gorm:"column:decimal" json:"decimal" form:"decimal"`
563
-	VmHisOrderInfo9504    []*VmHisOrderInfo9504 `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"info"`
564
-	//HisPrescriptionTen []*HisPrescriptionTen `gorm:"ForeignKey:BatchNumber;AssociationForeignKey:Number" json:"info"`
565
-	Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
566
-	CardDesc string   `gorm:"card_desc" json:"card_desc" form:"card_desc"`
492
+	ID                    int64     `gorm:"column:id" json:"id" form:"id"`
493
+	UserOrgId             int64     `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
494
+	HisPatientId          int64     `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
495
+	SettleAccountsDate    int64     `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
496
+	Ctime                 int64     `gorm:"column:ctime" json:"ctime" form:"ctime"`
497
+	Mtime                 int64     `gorm:"column:mtime" json:"mtime" form:"mtime"`
498
+	Status                int64     `gorm:"column:status" json:"status" form:"status"`
499
+	Number                string    `gorm:"column:number" json:"number" form:"number"`
500
+	PatientId             int64     `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
501
+	Infcode               int64     `gorm:"column:infcode" json:"infcode" form:"infcode"`
502
+	WarnMsg               string    `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
503
+	Cainfo                string    `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
504
+	ErrMsg                string    `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
505
+	RespondTime           string    `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
506
+	InfRefmsgid           string    `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
507
+	OrderStatus           int64     `gorm:"column:order_status" json:"order_status" form:"order_status"`
508
+	MdtrtId               string    `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
509
+	SetlId                string    `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
510
+	PsnNo                 string    `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
511
+	PsnName               string    `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
512
+	PsnCertType           string    `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
513
+	Certno                string    `gorm:"column:certno" json:"certno" form:"certno"`
514
+	Gend                  string    `gorm:"column:gend" json:"gend" form:"gend"`
515
+	Naty                  string    `gorm:"column:naty" json:"naty" form:"naty"`
516
+	Brdy                  time.Time `gorm:"column:brdy" json:"brdy" form:"brdy"`
517
+	Age                   float64   `gorm:"column:age" json:"age" form:"age"`
518
+	Insutype              string    `gorm:"column:insutype" json:"insutype" form:"insutype"`
519
+	PsnType               string    `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
520
+	CvlservFlag           string    `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
521
+	SetlTime              string    `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
522
+	MdtrtCertType         string    `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
523
+	MedType               string    `gorm:"column:med_type" json:"med_type" form:"med_type"`
524
+	MedfeeSumamt          float64   `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
525
+	FulamtOwnpayAmt       float64   `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
526
+	OverlmtSelfPay        float64   `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
527
+	PreselfpayAmt         float64   `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
528
+	InscpScpAmt           float64   `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
529
+	ActPayDedc            float64   `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
530
+	HifpPay               float64   `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
531
+	CvlservPay            float64   `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
532
+	PoolPropSelfpay       float64   `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
533
+	HifesPay              float64   `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
534
+	HifmiPay              float64   `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
535
+	HifobPay              float64   `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
536
+	MafPay                float64   `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
537
+	OthPay                float64   `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
538
+	FundPaySumamt         float64   `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
539
+	PsnPartAmt            float64   `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
540
+	AcctPay               float64   `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
541
+	PsnCashPay            float64   `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
542
+	HospPartAmt           float64   `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
543
+	Balc                  float64   `gorm:"column:balc" json:"balc" form:"balc"`
544
+	AcctMulaidPay         float64   `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
545
+	MedinsSetlId          string    `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
546
+	ClrOptins             string    `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
547
+	ClrWay                string    `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
548
+	ClrType               string    `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
549
+	SetlDetail            string    `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
550
+	IsMedicineInsurance   int64     `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
551
+	PayWay                int64     `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
552
+	PayPrice              float64   `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
553
+	PayCardNo             string    `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
554
+	DiscountPrice         float64   `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
555
+	PreferentialPrice     float64   `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
556
+	RealityPrice          float64   `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
557
+	FoundPrice            float64   `gorm:"column:found_price" json:"found_price" form:"found_price"`
558
+	MedicalInsurancePrice float64   `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
559
+	PrivatePrice          float64   `gorm:"column:private_price" json:"private_price" form:"private_price"`
560
+	DepartmentName        string    `gorm:"-" json:"department_name" form:"department_name"`
561
+	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
562
+	Creator               int64     `gorm:"column:creator" json:"creator" form:"creator"`
563
+	PType                 int64     `gorm:"column:p_type" json:"p_type" form:"p_type"`
564
+	Decimal               float64   `gorm:"column:decimal" json:"decimal" form:"decimal"`
565
+	//VmHisOrderInfo9504    []*VmHisOrderInfo9504 `gorm:"ForeignKey:OrderNumber;AssociationForeignKey:Number" json:"info"`
566
+	HisPrescriptionTen []*HisPrescriptionTen `gorm:"ForeignKey:BatchNumber;AssociationForeignKey:Number" json:"info"`
567
+	Patients           Patients              `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
568
+	CardDesc           string                `gorm:"card_desc" json:"card_desc" form:"card_desc"`
567 569
 }
568 570
 
569 571
 func (HisOrderTen) TableName() string {
@@ -910,7 +912,7 @@ func GetHisOrderDetail10138() (order []*HisOrderTen, err error) {
910 912
 		return db.Where("status = 1 AND order_status = 2").Preload("HisPrescriptionProjectTen", func(db *gorm.DB) *gorm.DB {
911 913
 			return db.Where("status = 1").Preload("VMHisProject")
912 914
 		})
913
-	}).Where("setl_time >= '2024-07-01 00:00:00' AND setl_time <= '2024-09-30 23:00:00' AND status = 1 AND order_status =2  AND user_org_id = 10278").Find(&order).Error
915
+	}).Where("setl_time >= '2025-01-01 00:00:00' AND setl_time <= '2025-03-31 23:00:00' AND status = 1 AND order_status =2  AND user_org_id = 10610").Find(&order).Error
914 916
 	return
915 917
 }
916 918
 
@@ -1617,7 +1619,7 @@ func Aaa() {
1617 1619
 
1618 1620
 func GetOrder11111() {
1619 1621
 	var info []models.HisOrder
1620
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 and order_status = 2 and status = 1 and setl_time >= '2024-08-01 00:00:00' and setl_time <= '2024-12-31 23:59:59'").Find(&info).Error
1622
+	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 and order_status = 2 and status = 1 and setl_time >= '2024-01-01 00:00:00' and setl_time <= '2024-12-31 23:59:59 and length(warn_msg) = 0'").Find(&info).Error
1621 1623
 	for _, in := range info {
1622 1624
 		var p models.HisPatient
1623 1625
 		var sss models.OutpatientServiceSick
@@ -1632,29 +1634,291 @@ func GetOrder11111() {
1632 1634
 
1633 1635
 func GetOrder111112() {
1634 1636
 	var info []models.HisOrder
1635
-	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 and order_status = 2 and status = 1 and setl_time >= '2024-11-23 00:00:00'").Find(&info).Error
1637
+	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 and order_status = 2 and status = 1 and setl_time >= '2022-07-01 00:00:00' and setl_time <= '2025-12-31 23:00:00'").Find(&info).Error
1636 1638
 	for _, in := range info {
1637
-		var p_info models.HisPrescriptionInfo
1638
-		readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = 10138 and status = 1 and patient_id = ? and record_date = ?", in.PatientId, in.SettleAccountsDate).First(&p_info)
1639
-		//readUserDb.Model(&models.UserAdminRole{}).Where("admin_user_id = ? and org_id = 10138", p_info.DoctorId)
1640
-
1641
-		diass := strings.Split(in.Diagnosis, ",")
1639
+		var re models.HisPatient
1640
+		readDb.Model(&models.HisPatient{}).Where("status = 1 and number = ? and user_org_id = 10106", in.MdtrtId).First(&re)
1641
+		diass := strings.Split(re.Diagnosis, ",")
1642 1642
 		var dia_name = ""
1643
+		var dia_code = ""
1644
+
1643 1645
 		for _, dia := range diass {
1644 1646
 			var sss models.HisXtDiagnoseConfig
1645 1647
 			if len(dia) > 0 {
1646 1648
 				readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", dia).First(&sss)
1647 1649
 				if len(dia_name) == 0 {
1648 1650
 					dia_name = sss.ClassName
1651
+					dia_code = sss.CountryCode
1649 1652
 				} else {
1650
-					dia_name = dia_name + "," + sss.ClassName
1653
+					dia_name = dia_name + "&" + sss.ClassName
1654
+					dia_code = dia_code + "&" + sss.CountryCode
1655
+
1651 1656
 				}
1652 1657
 			}
1653 1658
 		}
1654 1659
 		if len(dia_name) > 0 {
1655 1660
 			in.WarnMsg = dia_name
1661
+			in.Cainfo = dia_code
1656 1662
 			writeDb.Save(&in)
1657 1663
 		}
1658 1664
 	}
1659 1665
 	return
1660 1666
 }
1667
+
1668
+//func GetOrder000000() {
1669
+//	var info []models.HisOrder
1670
+//	err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 and order_status = 2 and status = 1 and setl_time >= '2024-01-01 00:00:00'").Find(&info).Error
1671
+//	for _, in := range info {
1672
+//
1673
+//		var p_info models.HisPrescriptionInfo
1674
+//		readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = 10138 and status = 1 and patient_id = ? and record_date = ?", in.PatientId, in.SettleAccountsDate).First(&p_info)
1675
+//		//readUserDb.Model(&models.UserAdminRole{}).Where("admin_user_id = ? and org_id = 10138", p_info.DoctorId)
1676
+//		//var re models.HisHospitalCheckRecord
1677
+//		//readDb.Model(&models.HisHospitalCheckRecord{}).Where("status = 1 and number = ? and user_org_id = 10215", in.MdtrtId).First(&re)
1678
+//		//diass := strings.Split(re.Diagnosis, ",")
1679
+//		var dia_name = ""
1680
+//		for _, dia := range p_info.Diagnosis {
1681
+//			var sss models.HisXtDiagnoseConfig
1682
+//			if len(dia) > 0 && dia != 92 {
1683
+//				readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", dia).First(&sss)
1684
+//				if len(dia_name) == 0 {
1685
+//					dia_name = sss.ClassName
1686
+//				} else {
1687
+//					dia_name = dia_name + "," + sss.ClassName
1688
+//				}
1689
+//			}
1690
+//		}
1691
+//		if len(dia_name) > 0 {
1692
+//			in.WarnMsg = dia_name
1693
+//		}
1694
+//		if len(in.WarnMsg) > 0 {
1695
+//			WarnMsg := removeDuplicates(in.WarnMsg)
1696
+//			in.WarnMsg = WarnMsg
1697
+//			writeDb.Save(&in)
1698
+//		}
1699
+//
1700
+//	}
1701
+//	return
1702
+//}
1703
+
1704
+func removeDuplicates(input string) string {
1705
+	// 使用 map 存储去重元素
1706
+	seen := make(map[string]bool)
1707
+	uniqueValues := []string{}
1708
+
1709
+	// 以逗号分隔字符串
1710
+	items := strings.Split(input, ",")
1711
+
1712
+	// 遍历数组,去重并保持顺序
1713
+	for _, item := range items {
1714
+		trimmedItem := strings.TrimSpace(item) // 去除首尾空格
1715
+		if _, exists := seen[trimmedItem]; !exists {
1716
+			seen[trimmedItem] = true
1717
+			uniqueValues = append(uniqueValues, trimmedItem)
1718
+		}
1719
+	}
1720
+
1721
+	// 将去重后的元素重新拼接成字符串
1722
+	return strings.Join(uniqueValues, ",")
1723
+}
1724
+
1725
+type DrugWarehouseInfoTwo struct {
1726
+	DrugCode string `gorm:"column:drug_code"`
1727
+}
1728
+
1729
+var drugCodes []string
1730
+
1731
+func Cccc() error {
1732
+	// 执行查询
1733
+	err := readDb.Table("xt_drug_warehouse_info").
1734
+		Select("drug_code").
1735
+		Where("is_pc = ? AND org_id = ? AND pc_date >= ? AND drug_code <> ?", 1, 10610, 1738339200, "").
1736
+		Pluck("drug_code", &drugCodes).Error
1737
+	num := 0
1738
+	for _, item := range drugCodes {
1739
+		codess := strings.Split(item, ",")
1740
+		for _, item := range codess {
1741
+			if len(item) > 0 {
1742
+				num = num + 1
1743
+			}
1744
+		}
1745
+	}
1746
+	fmt.Println(num)
1747
+
1748
+	return err
1749
+}
1750
+
1751
+func Cccc2() error {
1752
+	// 执行查询
1753
+	err := readDb.Table("his_doctor_advice_info").
1754
+		Select("drug_code").
1755
+		Where("is_upload = 1 AND user_org_id = ? AND advice_date >= ? AND drug_code <> ?", 10610, 1738339200, "").
1756
+		Pluck("drug_code", &drugCodes).Error
1757
+	num := 0
1758
+	for _, item := range drugCodes {
1759
+		codess := strings.Split(item, ",")
1760
+		for _, item := range codess {
1761
+			if len(item) > 0 {
1762
+				num = num + 1
1763
+			}
1764
+		}
1765
+	}
1766
+	fmt.Println(num)
1767
+
1768
+	return err
1769
+}
1770
+
1771
+func SyncUploadStatus() {
1772
+	var fl []models.DrugFlow
1773
+	readDb.Model(&models.DrugFlow{}).Joins("join his_doctor_advice_info on his_doctor_advice_info.patient_id = xt_drug_flow.patient_id and his_doctor_advice_info.record_date = xt_drug_flow.system_time and his_doctor_advice_info.drug_id = xt_drug_flow.drug_id and  his_doctor_advice_info.is_upload <>  1 and his_doctor_advice_info.drug_code <> ''").Where("xt_drug_flow.user_org_id = 10402 and xt_drug_flow.status = 1 and xt_drug_flow.is_sale = 1").Find(&fl)
1774
+	for _, item := range fl {
1775
+		writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = 10402 and record_date = ? and drug_id = ? and patient_id = ? and is_upload <> 1", item.SystemTime, item.DrugId, item.PatientId).Updates(map[string]interface{}{"is_upload": 1})
1776
+	}
1777
+
1778
+}
1779
+
1780
+func UpdateAAA(code string, cz string, new_code string) {
1781
+	writeDb.Model(&models.BaseDrugLib{}).Where("medical_insurance_number = ? and org_id = 10480", code).Updates(map[string]interface{}{"code": new_code, "drug_remark": cz})
1782
+
1783
+}
1784
+
1785
+type Record struct {
1786
+	AreaCode    string  `json:"area_code"`
1787
+	Label       string  `json:"label"`
1788
+	Sort        *int    `json:"sort"` // 允许null的字段使用指针类型
1789
+	Type        string  `json:"type"`
1790
+	Version     *string `json:"version"`  // 允许null的字符串字段
1791
+	ValiFlag    *bool   `json:"valiFlag"` // 布尔指针
1792
+	CreateID    *int    `json:"create_id"`
1793
+	CreateUser  *string `json:"createUser"`
1794
+	ID          int     `json:"id"`
1795
+	ParentValue *string `json:"parentValue"`
1796
+	Value       string  `json:"value"`
1797
+	CreateDate  *string `json:"createDate"` // 若时间格式不同可单独处理
1798
+	Status      string  `json:"status"`
1799
+	CreateName  *string `json:"create_name"`
1800
+}
1801
+
1802
+func CCCCCccc() {
1803
+	// 读取文件
1804
+	data, err := os.ReadFile("./aaa.json")
1805
+	if err != nil {
1806
+		fmt.Sprintf("读取文件失败: %v", err)
1807
+		return
1808
+	}
1809
+
1810
+	// 解析JSON数组
1811
+	var records []Record
1812
+	if err := json.Unmarshal(data, &records); err != nil {
1813
+		panic(fmt.Sprintf("解析失败: %v", err))
1814
+	}
1815
+	var ps []models.Patients
1816
+
1817
+	readDb.Model(&models.Patients{}).Where("user_org_id = 10721").Find(&ps)
1818
+	for _, item := range ps {
1819
+		for _, re := range records {
1820
+			if item.InsuplcAdmdvs == re.Value {
1821
+				//item.InsuplcAdmdvsName = re.Label
1822
+				writeDb.Save(&item)
1823
+			}
1824
+		}
1825
+	}
1826
+}
1827
+
1828
+func GetHisOrder9768() (order_infos []*VmHisOrderInfo9504, err error) {
1829
+	err = readDb.Model(&VmHisOrderInfo95042{}).Where(" status = 1  AND user_org_id = 9478 AND patient_id = 37836 AND project_id > 0").Find(&order_infos).Error
1830
+	for _, item := range order_infos {
1831
+		var pp HisPrescriptionProject
1832
+		readDb.Model(&HisPrescriptionProject{}).Where("id = ? and type = 3", item.ProjectId).First(&pp)
1833
+		if pp.ID > 0 {
1834
+			item.MedChrgitmType = "08"
1835
+			readDb.Model(&VmHisOrderInfo95042{}).Save(&item)
1836
+		}
1837
+	}
1838
+
1839
+	return
1840
+}
1841
+
1842
+func GetHisOrder0000() (order_infos []*VmHisOrderInfo9504, err error) {
1843
+	err = readDb.Model(&VmHisOrderInfo95042{}).Where(" status = 1  AND upload_date > 1747754876 AND project_id = 0 and advice_id = 0").Find(&order_infos).Error
1844
+	for _, item := range order_infos {
1845
+		//timestamp := int64(item.UploadDate) // 对应2023-10-05 00:00:00 UTC
1846
+		//t := time.Unix(timestamp, 0).UTC()
1847
+		//midnight := getMidnightTimestamp(t)
1848
+		//fmt.Printf("Unix时间戳的零点时间戳:%d\n", midnight)
1849
+
1850
+		// 示例:Unix 时间戳(秒级)
1851
+		//timestamp := int64(item.UploadDate) // 对应 2023-10-05 00:00:00 UTC
1852
+		//
1853
+		//// 转换为 time.Time
1854
+		//t := time.Unix(timestamp, 0)
1855
+		//
1856
+		//// 格式化为 "2006-01-02 15:04:05"(年月日时分秒)
1857
+		//formattedTime := t.Format("2006-01-02 15:04:05")
1858
+		//aa := strings.Split(formattedTime, " ")
1859
+		//
1860
+		//// 解析为 time.Time(默认 UTC 时区)
1861
+		//t, err := time.Parse("2006-01-02", aa[0])
1862
+		//if err != nil {
1863
+		//	panic(err)
1864
+		//}
1865
+		//
1866
+		//// 转换为 Unix 时间戳(秒级)
1867
+		//timestamp = t.Unix()
1868
+		//fmt.Println(timestamp)
1869
+		var pp HisPrescriptionProject
1870
+		readDb.Model(&HisPrescriptionProject{}).Where("user_org_id = ? and price = ? and count = ? and status = 1 and record_date = ? and type = 3 and patient_id = ?", item.UserOrgId, item.Pric, item.Cnt, 1748016000, item.PatientId).First(&pp)
1871
+		if pp.ID > 0 {
1872
+			item.ProjectId = pp.ID
1873
+			readDb.Model(&VmHisOrderInfo95042{}).Save(&item)
1874
+		}
1875
+	}
1876
+
1877
+	return
1878
+}
1879
+
1880
+// getMidnightTimestamp 返回给定时间的当天零点时间戳(秒)
1881
+func getMidnightTimestamp(t time.Time) int64 {
1882
+	midnight := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
1883
+	return midnight.Unix()
1884
+}
1885
+
1886
+func UpdateP() (ps []*HisPrescriptionInfo, err error) {
1887
+	//err = readDb.Model(&models.HisPrescriptionInfo{}).Joins("join xt_patients on  his_prescription_info.`patient_id` = xt_patients.id").Where(" his_prescription_info.status = 1  AND his_prescription_info.record_date > 1746028800 AND his_prescription_info.status = 1 and and his_prescription_info.user_org_id = 10567").Find(&order_infos).Group("his_prescription_info.patient_id").Error
1888
+	err = readDb.Model(&models.HisPrescriptionInfo{}).
1889
+		Joins("join xt_patients on his_prescription_info.patient_id = xt_patients.id").
1890
+		Where("his_prescription_info.status = 1").
1891
+		Where("his_prescription_info.record_date >= 1746028800").
1892
+		Where("his_prescription_info.user_org_id = 10724").
1893
+		Where("xt_patients.name NOT IN (?)", []string{
1894
+			"肖平", "江长永", "曾玉环", // 30A区域
1895
+		}).
1896
+		Group("his_prescription_info.patient_id").
1897
+		Find(&ps).Error
1898
+	for _, item := range ps {
1899
+		writeDb.Model(&models.HisPrescription{}).Where("patient_id = ? and record_date >= ?", item.PatientId, 1746028800).Updates(map[string]interface{}{"p_type": 1})
1900
+		writeDb.Model(&models.HisPrescriptionInfo{}).Where("patient_id = ? and record_date >= ?", item.PatientId, 1746028800).Updates(map[string]interface{}{"p_type": 1})
1901
+
1902
+	}
1903
+
1904
+	return
1905
+}
1906
+
1907
+func Updateo() {
1908
+	var order []models.HisOrderInfo
1909
+	err = readDb.Model(&models.HisOrderInfo{}).
1910
+		Where("his_order_info.status = 1 and his_order_info.upload_date >= 1746028800 and his_order_info.user_org_id = 10768 and his_order_info.order_number like '%H440113000%'").
1911
+		Find(&order).Error
1912
+	for _, item := range order {
1913
+		if item.AdviceId == 0 && item.ProjectId > 0 {
1914
+			var pp models.HisPrescriptionProject
1915
+			readDb.Model(&models.HisPrescriptionProject{}).Where("id = ?", item.ProjectId).First(&pp)
1916
+			writeDb.Model(&models.HisOrderInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{"item_id": pp.RecordDate})
1917
+		} else if item.AdviceId > 0 && item.ProjectId == 0 {
1918
+			var doc models.HisDoctorAdviceInfo
1919
+			readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id = ?", item.AdviceId).First(&doc)
1920
+			writeDb.Model(&models.HisOrderInfo{}).Where("id = ?", item.ID).Updates(map[string]interface{}{"item_id": doc.RecordDate})
1921
+
1922
+		}
1923
+	}
1924
+}

+ 5 - 5
service/export_data_service.go Parādīt failu

@@ -128,7 +128,7 @@ func GetHisOrderDetailFor390(start_time string, end_time string, org_id int64) (
128 128
 	return
129 129
 }
130 130
 func GetHisOrderByTime(patient_id int64, start_time string, end_time string) (order []models.HisOrder, err error) {
131
-	err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND status = 1 and order_status = 2 and  FROM_UNIXTIME(settle_accounts_date)  >= ? and FROM_UNIXTIME(settle_accounts_date) <= ?", patient_id, start_time+" 00:00:00", end_time+" 23:59:00").Find(&order).Error
131
+	err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND status = 1 and order_status = 2 and  FROM_UNIXTIME(settle_accounts_date)  >= ? and FROM_UNIXTIME(settle_accounts_date) <= ?", patient_id, start_time+" 00:00:00", end_time+" 23:59:00").Order("settle_accounts_date").Find(&order).Error
132 132
 	return
133 133
 }
134 134
 
@@ -599,9 +599,9 @@ func GetHisOrderBy10697SummaryThree(startTime, endTime string, st_stamp, end_sta
599 599
 			var tempTotal CusTotalTwo
600 600
 
601 601
 			readDb.Table("his_order_info as oi").Select(`
602
-    COALESCE(SUM(CASE WHEN project.project_name = '血液透析(用)' THEN p.count ELSE 0 END), 0) as XT,
603
-    COALESCE(SUM(CASE WHEN project.project_name = '血液透析滤过(用)' THEN p.count ELSE 0 END), 0) as XL,
604
-    COALESCE(SUM(CASE WHEN project.project_name = '血液灌流(用)' THEN p.count ELSE 0 END), 0) as GL
602
+    COALESCE(SUM(CASE WHEN project.project_name  IN ('血液透析(用)', '血液透析费')  THEN p.count ELSE 0 END), 0) as XT,
603
+    COALESCE(SUM(CASE WHEN project.project_name IN ('血液透析滤过(用)','血液滤过费') THEN p.count ELSE 0 END), 0) as XL,
604
+    COALESCE(SUM(CASE WHEN project.project_name IN ('血液灌流(用)','血液灌流费') THEN p.count ELSE 0 END), 0) as GL
605 605
 `).
606 606
 				Joins("JOIN his_order o ON oi.order_number = o.number AND o.setl_time BETWEEN ? AND ? AND o.order_status = 2 AND o.status = 1", startTime+" 00:00:00", endTime+" 23:59:59").
607 607
 				Joins("JOIN his_prescription_project p ON oi.project_id = p.id").
@@ -615,7 +615,7 @@ func GetHisOrderBy10697SummaryThree(startTime, endTime string, st_stamp, end_sta
615 615
     AND oi.upload_date <= ? 
616 616
     AND oi.status = 1 
617 617
     AND p.type = 2 
618
-    AND project.project_name IN ('血液透析(用)','血液透析滤过(用)','血液灌流(用)')
618
+    AND project.project_name IN ('血液透析(用)','血液透析费','血液透析滤过(用)','血液滤过费','血液灌流(用)','血液灌流费')
619 619
 `, item.PatientID, org_id, st_stamp, end_stamp).
620 620
 				Scan(&tempTotal)
621 621
 

+ 10 - 0
service/fapiao_service.go Parādīt failu

@@ -113,6 +113,11 @@ func GetFaPiaoOrderById(id int64) (orders models.HisFaPiaoOrder, err error) {
113 113
 	return
114 114
 }
115 115
 
116
+func GetFaPiaoOrderByIds() (orders []models.HisFaPiaoOrder, err error) {
117
+	err = readDb.Model(&models.HisFaPiaoOrder{}).Where("user_org_id = 10318 and status  = 1 and fapiao_status = 2").Find(&orders).Error
118
+	return
119
+}
120
+
116 121
 func GetFaPiaoOrderInfoByNumbers(numbers []string) (infos []models.HisOrderInfo, err error) {
117 122
 	err = readDb.Model(&models.HisOrderInfo{}).Where("order_number in (?)", numbers).Find(&infos).Error
118 123
 	return
@@ -140,3 +145,8 @@ func UpdateFaPiaoNumberByNumber(number string) (err error) {
140 145
 	err = XTWriteDB().Model(&models.HisOrder{}).Where("fa_piao_number = ?", number).Updates(map[string]interface{}{"fa_piao_number": ""}).Error
141 146
 	return
142 147
 }
148
+
149
+func GetFaPiaoOrderInfoByNumbersTwo(numbers []string) (infos []models.NewHisOrderInfo, err error) {
150
+	err = readDb.Model(&models.NewHisOrderInfo{}).Where("order_number in (?)", numbers).Find(&infos).Error
151
+	return
152
+}

+ 1 - 1
service/his_summary_service.go Parādīt failu

@@ -21,7 +21,7 @@ func GetHisSummaryDetailList(keyword string, item_type int64, patient_id int64,
21 21
 						return db.Select("id,good_name,good_unit,specification_name,packing_unit,medical_insurance_level,medical_insurance_number").Where("status = 1 ")
22 22
 					}).Where("status = 1 ")
23 23
 				})
24
-			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id)
24
+			}).Where("status = 1  AND ctime >= ? AND ctime <= ? AND user_org_id = ? AND order_status = 2", start_time, end_time, org_id).Order("settle_accounts_date desc")
25 25
 	}).Where("p.status = 1  AND p.user_org_id = ? and p.id = ?", org_id, patient_id).Group("id").Find(&patients).Error
26 26
 
27 27
 	return

+ 7 - 1
service/yh_service.go Parādīt failu

@@ -23,7 +23,7 @@ func GetAllPatientSch(org_id int64) (ps []models.KyySchedule) {
23 23
 }
24 24
 
25 25
 func GetAllPatientDialysisRecord(org_id int64, record_date int64, patient_id int64) (ps models.KYYDialysisOrder) {
26
-	readDb.Model(&models.KYYDialysisOrder{}).Preload("DeviceNumber", "status = 1").Preload("UserAdminRole", "status = 1").Preload("KyyPredialysisEvaluation", "status = 1 and user_org_id = ? and assessment_date = ?", org_id, record_date).Preload("KyyAssessmentAfterDislysis", "status = 1 and user_org_id = ? and assessment_date = ?", org_id, record_date).Preload("KyyTreatmentSummary", "status = 1 and user_org_id = ? and assessment_date = ?", org_id, record_date).Preload("KyyMonitoringRecord", "status = 1 and user_org_id = ? and  monitoring_date = ?", org_id, record_date).Preload("KyyDoctorAdvice", "status = 1 and user_org_id = ? and advice_date = ?", org_id, record_date).Where("user_org_id = ? and status = 1 and dialysis_date = ? and patient_id = ?", org_id, record_date, patient_id).Find(&ps)
26
+	readDb.Model(&models.KYYDialysisOrder{}).Preload("KYYPrescriptionVM", "status = 1").Preload("DeviceNumber", "status = 1").Preload("UserAdminRole", "status = 1").Preload("KyyPredialysisEvaluation", "status = 1 and user_org_id = ? and assessment_date = ?", org_id, record_date).Preload("KyyAssessmentAfterDislysis", "status = 1 and user_org_id = ? and assessment_date = ?", org_id, record_date).Preload("KyyTreatmentSummary", "status = 1 and user_org_id = ? and assessment_date = ?", org_id, record_date).Preload("KyyMonitoringRecord", "status = 1 and user_org_id = ? and  monitoring_date = ?", org_id, record_date).Preload("KyyDoctorAdvice", "status = 1 and user_org_id = ? and advice_date = ?", org_id, record_date).Where("user_org_id = ? and status = 1 and dialysis_date = ? and patient_id = ?", org_id, record_date, patient_id).Find(&ps)
27 27
 	return
28 28
 }
29 29
 
@@ -36,3 +36,9 @@ func GetSyncTimeByOrgId(org_id int64, sync_type int64) (sync_info models.YHDataU
36 36
 	err = readDb.Model(&models.YHDataUpload{}).Where("org_id = ? and sync_type = ? ", org_id, sync_type).Last(&sync_info).Error
37 37
 	return
38 38
 }
39
+
40
+func GetAdminUserRoleTwo(id string, orgid int64) (models.SgjUserAdminRole, error) {
41
+	role := models.SgjUserAdminRole{}
42
+	err := UserReadDB().Where("admin_user_id = ? and org_id = ? and status = 1", id, orgid).Find(&role).Error
43
+	return role, err
44
+}