Sfoglia il codice sorgente

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

XMLWAN 3 anni fa
parent
commit
aaa603f31e

+ 1 - 1
controllers/coordinate_controller.go Vedi File

@@ -69,7 +69,7 @@ type RefundDetail struct {
69 69
 	Code string `json:"code"`
70 70
 }
71 71
 
72
-func CoordinateRegistRouters() {
72
+func CoordinateRcegistRouters() {
73 73
 	beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
74 74
 	//坐标挂号
75 75
 	beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")

+ 414 - 81
controllers/his_api_controller.go Vedi File

@@ -4546,9 +4546,40 @@ func (c *HisApiController) GetUploadInfo() {
4546 4546
 	reg_type, _ := c.GetInt64("p_type")
4547 4547
 	order_id, _ := c.GetInt64("order_id")
4548 4548
 
4549
-	his, _ := service.GetHisPatientByIdThree(his_patient_id)
4549
+	dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
4550
+	tmp_decimal := c.GetString("tmp_decimal")
4551
+	var decimal float64 //本次使用的押金
4552
+	var errmsg error
4553
+	tx := service.XTWriteDB().Begin() //开了事务
4554
+	//只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
4555
+	defer func() {
4556
+		if errmsg != nil {
4557
+			utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
4558
+			tx.Rollback()
4559
+		} else {
4560
+			tx.Commit()
4561
+		}
4562
+	}()
4563
+	if dec_way == "true" && tmp_decimal == "0" && tmp_decimal == "" {
4564
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
4565
+		return
4566
+	}
4567
+	if len(tmp_decimal) > 0 {
4568
+		if tmp_decimal[0] == 45 {
4569
+			c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
4570
+			return
4571
+		}
4572
+	}
4573
+	tt, errs := strconv.ParseFloat(tmp_decimal, 64)
4574
+	if errs != nil {
4575
+		c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
4576
+		return
4577
+	}
4578
+	decimal = tt
4579
+
4580
+	his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
4550 4581
 
4551
-	tempOrder, _ := service.GetHisOrderByID(order_id)
4582
+	tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
4552 4583
 
4553 4584
 	theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
4554 4585
 	if err != nil {
@@ -4569,9 +4600,9 @@ func (c *HisApiController) GetUploadInfo() {
4569 4600
 
4570 4601
 			if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
4571 4602
 
4572
-				prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
4603
+				prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
4573 4604
 			} else {
4574
-				prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
4605
+				prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
4575 4606
 			}
4576 4607
 		} else { //月结
4577 4608
 
@@ -4593,9 +4624,8 @@ func (c *HisApiController) GetUploadInfo() {
4593 4624
 			}
4594 4625
 			recordEndTime := theEndTime.Unix()
4595 4626
 			end_time = recordEndTime
4596
-			prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
4627
+			prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
4597 4628
 		}
4598
-
4599 4629
 		timestamp := time.Now().Unix()
4600 4630
 		tempTime := time.Unix(timestamp, 0)
4601 4631
 		timeFormat := tempTime.Format("20060102150405")
@@ -4637,7 +4667,7 @@ func (c *HisApiController) GetUploadInfo() {
4637 4667
 
4638 4668
 		allTotal := fmt.Sprintf("%.4f", total)
4639 4669
 		totals, _ := strconv.ParseFloat(allTotal, 64)
4640
-		order := &models.HisOrder{
4670
+		order := &models.HisOrder{ //
4641 4671
 			UserOrgId:             adminUser.CurrentOrgId,
4642 4672
 			HisPatientId:          his.ID,
4643 4673
 			PatientId:             id,
@@ -4667,8 +4697,9 @@ func (c *HisApiController) GetUploadInfo() {
4667 4697
 			Diagnosis:             diagnosis_id,
4668 4698
 			PType:                 2,
4669 4699
 			SetlTime:              tm.Format("2006-01-02 15:04:05"),
4700
+			Decimal:               decimal,
4670 4701
 		}
4671
-		err = service.CreateOrder(order)
4702
+		err = service.CreateOrderTX(order, tx)
4672 4703
 		if err != nil {
4673 4704
 			c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
4674 4705
 			return
@@ -4764,16 +4795,28 @@ func (c *HisApiController) GetUploadInfo() {
4764 4795
 				Type:             types,
4765 4796
 				ItemId:           item_id,
4766 4797
 			}
4767
-			service.CreateOrderInfo(info)
4798
+			service.CreateOrderInfoTX(info, tx)
4768 4799
 		}
4769 4800
 		his.Diagnosis = diagnosis_id
4770 4801
 		his.SickType = sick_type
4771 4802
 		his.RegisterType = reg_type
4772 4803
 		his.MedicalTreatmentType = reg_type
4773
-		service.UpdataHisPateint(&his)
4774
-		err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
4775
-		err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
4776
-		err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
4804
+		service.UpdataHisPateintTX(&his, tx)
4805
+		err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
4806
+		err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
4807
+		err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
4808
+		//判断是否使用了押金
4809
+		if dec_way == "true" {
4810
+
4811
+			tmpstring := strconv.FormatInt(order.ID, 10)
4812
+			//扣押金
4813
+			errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
4814
+			if errmsg != nil {
4815
+				c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
4816
+				//c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
4817
+				return
4818
+			}
4819
+		}
4777 4820
 		if err == nil {
4778 4821
 			c.ServeSuccessJSON(map[string]interface{}{
4779 4822
 				"msg": "结算成功",
@@ -4818,15 +4861,21 @@ func (c *HisApiController) Refund() {
4818 4861
 	order_id, _ := c.GetInt64("order_id")
4819 4862
 	order, _ := service.GetHisOrderByID(order_id)
4820 4863
 	adminUser := c.GetAdminUserInfo()
4864
+	orgid := c.GetAdminUserInfo().CurrentOrgId
4821 4865
 	err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
4822
-	if err == nil {
4823
-		c.ServeSuccessJSON(map[string]interface{}{
4824
-			"msg": "退费成功",
4825
-		})
4826
-	} else {
4866
+	if err != nil {
4867
+		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
4868
+		return
4869
+	}
4870
+	tmp := strconv.FormatInt(order.ID, 10)
4871
+	err = service.MoneyIncrease(orgid, order.HisPatientId, tmp, order.Decimal)
4872
+	if err != nil {
4827 4873
 		c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
4828 4874
 		return
4829 4875
 	}
4876
+	c.ServeSuccessJSON(map[string]interface{}{
4877
+		"msg": "退费成功",
4878
+	})
4830 4879
 }
4831 4880
 
4832 4881
 func (c *HisApiController) RefundNumber() {
@@ -5270,72 +5319,212 @@ func (c *HisApiController) GetAllOrderDetailCollect() {
5270 5319
 	//var zhenChaCostPartSelfTotal float64 = 0 //其他费用
5271 5320
 
5272 5321
 	decimal.DivisionPrecision = 2
5273
-
5274
-	if his.BalanceAccountsType != 2 {
5322
+	var BalanceAccountsType int64
5323
+	if his.ID > 0 {
5324
+		BalanceAccountsType = his.BalanceAccountsType
5325
+	} else {
5326
+		BalanceAccountsType = record.BalanceAccountsType
5327
+	}
5328
+	if BalanceAccountsType != 2 {
5275 5329
 		for _, item := range order_info {
5276
-			if item.MedChrgitmType == "01" { //床位费
5277
-				bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5278
-				//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5279
-				//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5280
-			}
5281
-			if item.MedChrgitmType == "02" { //诊察费
5282
-				zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5283
-				//zhenChaCostSelfTotal = zhenChaCostTotal
5284
-			}
5330
+			if org_id == 10215 {
5331
+				if item.MedChrgitmType == "01" { //床位费
5332
+					bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5333
+					//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5334
+					//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5335
+				}
5336
+				if item.MedChrgitmType == "02" { //诊察费
5337
+					zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5338
+					//zhenChaCostSelfTotal = zhenChaCostTotal
5339
+				}
5340
+				if item.MedChrgitmType == "03" { //检查费
5341
+					checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5342
+					//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5343
+					//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5344
+				}
5285 5345
 
5286
-			if item.MedChrgitmType == "03" { //检查费
5287
-				checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5288
-				//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5289
-				//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5290
-			}
5346
+				//if item.MedChrgitmType == "02" { //检查费
5347
+				//	checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5348
+				//	//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5349
+				//	//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5350
+				//}
5291 5351
 
5292
-			if item.MedChrgitmType == "02" { //检查
5293
-				checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5294
-				//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5295
-				//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5296
-			}
5352
+				if item.MedChrgitmType == "04" { //化验
5353
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5354
+					//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5355
+					//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5356
+				}
5297 5357
 
5298
-			if item.MedChrgitmType == "04" { //化验
5299
-				laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5300
-				//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5301
-				//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5302
-			}
5358
+				if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗
5359
+					treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5360
+					//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5361
+					//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5362
+				}
5303 5363
 
5304
-			if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗
5305
-				treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5306
-				//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5307
-				//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5308
-			}
5364
+				if item.MedChrgitmType == "06" { //手术
5365
+					operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5366
+					//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5367
+					//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5368
+				}
5309 5369
 
5310
-			if item.MedChrgitmType == "06" { //手术
5311
-				operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5312
-				//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5313
-				//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5314
-			}
5370
+				if item.MedChrgitmType == "08" { //材料
5371
+					materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5372
+					//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5373
+					//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5374
+				}
5315 5375
 
5316
-			if item.MedChrgitmType == "08" { //材料
5317
-				materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5318
-				//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5319
-				//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5320
-			}
5376
+				if item.MedChrgitmType == "09" { //西药
5377
+					westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5378
+					//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5379
+					//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5380
+				}
5321 5381
 
5322
-			if item.MedChrgitmType == "09" { //西药
5323
-				westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5324
-				//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5325
-				//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5326
-			}
5382
+				if item.MedChrgitmType == "11" { //中成
5383
+					chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5384
+					//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5385
+					//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5386
+				}
5327 5387
 
5328
-			if item.MedChrgitmType == "11" { //中成费
5329
-				chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5330
-				//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5331
-				//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5332
-			}
5388
+				if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
5389
+					otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5390
+					//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5391
+					//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5392
+				}
5393
+
5394
+			} else if org_id == 10188 || org_id == 10217 {
5395
+				if item.MedChrgitmType == "01" { //床位费
5396
+					bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5397
+					//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5398
+					//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5399
+				}
5400
+				if item.MedChrgitmType == "02" { //诊察费
5401
+					zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5402
+					//zhenChaCostSelfTotal = zhenChaCostTotal
5403
+				}
5404
+				if item.MedChrgitmType == "03" { //检查费
5405
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5406
+
5407
+					//checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5408
+					//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5409
+					//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5410
+				}
5411
+
5412
+				//if item.MedChrgitmType == "02" { //检查费
5413
+				//	checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5414
+				//	//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5415
+				//	//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5416
+				//}
5417
+
5418
+				if item.MedChrgitmType == "04" { //化验费
5419
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5420
+					//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5421
+					//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5422
+				}
5423
+
5424
+				if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
5425
+					treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5426
+					//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5427
+					//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5428
+				}
5429
+
5430
+				if item.MedChrgitmType == "06" { //手术费
5431
+					operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5432
+					//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5433
+					//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5434
+				}
5435
+
5436
+				if item.MedChrgitmType == "08" { //材料费
5437
+					materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5438
+					//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5439
+					//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5440
+				}
5441
+
5442
+				if item.MedChrgitmType == "09" { //西药费
5443
+					westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5444
+					//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5445
+					//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5446
+				}
5447
+
5448
+				if item.MedChrgitmType == "11" { //中成费
5449
+					chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5450
+					//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5451
+					//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5452
+				}
5453
+
5454
+				if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
5455
+					otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5456
+					//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5457
+					//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5458
+				}
5459
+
5460
+			} else {
5461
+
5462
+				if item.MedChrgitmType == "01" { //床位费
5463
+					bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5464
+					//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5465
+					//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5466
+				}
5467
+				//if item.MedChrgitmType == "02" { //诊察费
5468
+				//	zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5469
+				//	//zhenChaCostSelfTotal = zhenChaCostTotal
5470
+				//}
5471
+
5472
+				if item.MedChrgitmType == "03" { //检查费
5473
+					checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5474
+					//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5475
+					//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5476
+				}
5477
+
5478
+				//if item.MedChrgitmType == "02" { //检查费
5479
+				//	checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5480
+				//	//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5481
+				//	//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5482
+				//}
5483
+
5484
+				if item.MedChrgitmType == "04" { //化验费
5485
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5486
+					//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5487
+					//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5488
+				}
5489
+
5490
+				if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
5491
+					treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5492
+					//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5493
+					//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5494
+				}
5495
+
5496
+				if item.MedChrgitmType == "06" { //手术费
5497
+					operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5498
+					//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5499
+					//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5500
+				}
5501
+
5502
+				if item.MedChrgitmType == "08" { //材料费
5503
+					materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5504
+					//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5505
+					//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5506
+				}
5507
+
5508
+				if item.MedChrgitmType == "09" { //西药费
5509
+					westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5510
+					//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5511
+					//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5512
+				}
5513
+
5514
+				if item.MedChrgitmType == "11" { //中成费
5515
+					chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5516
+					//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5517
+					//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5518
+				}
5519
+
5520
+				if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
5521
+					otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5522
+					//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5523
+					//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5524
+				}
5333 5525
 
5334
-			if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
5335
-				otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5336
-				//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5337
-				//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5338 5526
 			}
5527
+
5339 5528
 		}
5340 5529
 
5341 5530
 		c.ServeSuccessJSON(map[string]interface{}{
@@ -5356,12 +5545,10 @@ func (c *HisApiController) GetAllOrderDetailCollect() {
5356 5545
 			"treatCostTotal":                      treatCostTotal,
5357 5546
 		})
5358 5547
 	} else {
5359
-
5360 5548
 		for _, item := range order_info {
5361 5549
 			item.FulamtOwnpayAmt = item.DetItemFeeSumamt
5362 5550
 			if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
5363 5551
 				item.MedChrgitmType = "09"
5364
-
5365 5552
 			}
5366 5553
 			if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
5367 5554
 				if item.HisPrescriptionProject.Type == 2 {
@@ -5468,6 +5655,142 @@ func (c *HisApiController) GetAllOrderDetailCollect() {
5468 5655
 			}
5469 5656
 		}
5470 5657
 
5658
+		for _, item := range order_info {
5659
+			if org_id == 10215 {
5660
+				if item.MedChrgitmType == "01" { //床位费
5661
+					bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5662
+					//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5663
+					//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5664
+				}
5665
+				if item.MedChrgitmType == "02" { //诊察费
5666
+					zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5667
+					//zhenChaCostSelfTotal = zhenChaCostTotal
5668
+				}
5669
+
5670
+				if item.MedChrgitmType == "03" { //检查费
5671
+					checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5672
+					//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5673
+					//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5674
+				}
5675
+
5676
+				//if item.MedChrgitmType == "02" { //检查费
5677
+				//	checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5678
+				//	//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5679
+				//	//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5680
+				//}
5681
+
5682
+				if item.MedChrgitmType == "04" { //化验费
5683
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5684
+					//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5685
+					//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5686
+				}
5687
+
5688
+				if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
5689
+					treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5690
+					//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5691
+					//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5692
+				}
5693
+
5694
+				if item.MedChrgitmType == "06" { //手术费
5695
+					operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5696
+					//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5697
+					//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5698
+				}
5699
+
5700
+				if item.MedChrgitmType == "08" { //材料费
5701
+					materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5702
+					//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5703
+					//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5704
+				}
5705
+
5706
+				if item.MedChrgitmType == "09" { //西药费
5707
+					westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5708
+					//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5709
+					//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5710
+				}
5711
+
5712
+				if item.MedChrgitmType == "11" { //中成费
5713
+					chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5714
+					//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5715
+					//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5716
+				}
5717
+
5718
+				if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
5719
+					otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5720
+					//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5721
+					//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5722
+				}
5723
+
5724
+			} else {
5725
+
5726
+				if item.MedChrgitmType == "01" { //床位费
5727
+					bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5728
+					//bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5729
+					//bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5730
+				}
5731
+				//if item.MedChrgitmType == "02" { //诊察费
5732
+				//	zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5733
+				//	//zhenChaCostSelfTotal = zhenChaCostTotal
5734
+				//}
5735
+
5736
+				if item.MedChrgitmType == "03" { //检查费
5737
+					checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5738
+					//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5739
+					//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5740
+				}
5741
+
5742
+				//if item.MedChrgitmType == "02" { //检查费
5743
+				//	checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5744
+				//	//checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5745
+				//	//checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5746
+				//}
5747
+
5748
+				if item.MedChrgitmType == "04" { //化验费
5749
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5750
+					//laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5751
+					//laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5752
+				}
5753
+
5754
+				if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
5755
+					treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5756
+					//treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5757
+					//treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5758
+				}
5759
+
5760
+				if item.MedChrgitmType == "06" { //手术费
5761
+					operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5762
+					//operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5763
+					//operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5764
+				}
5765
+
5766
+				if item.MedChrgitmType == "08" { //材料费
5767
+					materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5768
+					//materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5769
+					//materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5770
+				}
5771
+
5772
+				if item.MedChrgitmType == "09" { //西药费
5773
+					westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5774
+					//westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5775
+					//westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5776
+				}
5777
+
5778
+				if item.MedChrgitmType == "11" { //中成费
5779
+					chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5780
+					//chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5781
+					//chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5782
+				}
5783
+
5784
+				if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
5785
+					otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5786
+					//otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5787
+					//otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5788
+				}
5789
+
5790
+			}
5791
+
5792
+		}
5793
+
5471 5794
 		c.ServeSuccessJSON(map[string]interface{}{
5472 5795
 			"order":                               order,
5473 5796
 			"order_info":                          order_info,
@@ -5667,8 +5990,6 @@ func (c *HisApiController) GetFaPiaoData() {
5667 5990
 			if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
5668 5991
 				if item.HisPrescriptionProject.Type == 2 {
5669 5992
 					if c.GetAdminUserInfo().CurrentOrgId == 10215 {
5670
-						fmt.Println("CostClassify")
5671
-						fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
5672 5993
 						switch item.HisPrescriptionProject.VMHisProject.CostClassify {
5673 5994
 						case 0:
5674 5995
 							item.MedChrgitmType = "0"
@@ -5842,22 +6163,34 @@ func (c *HisApiController) GetFaPiaoData() {
5842 6163
 				zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
5843 6164
 			}
5844 6165
 
5845
-			if item.MedChrgitmType == "03" { //检查费
5846
-				checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5847
-				checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5848
-				checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
6166
+			if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
6167
+				if item.MedChrgitmType == "03" { //检查费
6168
+					laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
6169
+					laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
6170
+					laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
6171
+
6172
+				}
6173
+			} else {
6174
+				if item.MedChrgitmType == "03" { //检查费
6175
+					checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
6176
+					checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
6177
+					checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
6178
+				}
6179
+
5849 6180
 			}
5850 6181
 
5851 6182
 			if item.MedChrgitmType == "04" { //化验费
5852 6183
 				laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5853 6184
 				laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5854 6185
 				laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
6186
+
5855 6187
 			}
5856 6188
 
5857 6189
 			if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
5858 6190
 				treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
5859 6191
 				treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
5860 6192
 				treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
6193
+
5861 6194
 			}
5862 6195
 
5863 6196
 			if item.MedChrgitmType == "06" { //手术费

+ 544 - 30
controllers/his_deposit_controller.go Vedi File

@@ -9,6 +9,7 @@ import (
9 9
 	"fmt"
10 10
 	"github.com/astaxie/beego"
11 11
 	"github.com/shopspring/decimal"
12
+	"strconv"
12 13
 	"strings"
13 14
 	"time"
14 15
 )
@@ -18,27 +19,45 @@ type HisDepositApiController struct {
18 19
 }
19 20
 
20 21
 func HisDepositApiRegistRouters() {
21
-	beego.Router("/api/his/ttt", &HisDepositApiController{}, "get:TTT")                         //测试接口
22
-	beego.Router("/api/his/gethisuser", &HisDepositApiController{}, "get:GetHisUser")           //获取病例中心,有效患者名称
23
-	beego.Router("/api/his/adddeposit", &HisDepositApiController{}, "post:AddDeposit")          //新增押金
24
-	beego.Router("/api/his/getdepositcode", &HisDepositApiController{}, "get:GetDepositCode")   //获取新增押金编号
25
-	beego.Router("/api/his/getdeletecode", &HisDepositApiController{}, "get:GetDeleteCode")     //获取退款编号
26
-	beego.Router("/api/his/rechargedetails", &HisDepositApiController{}, "get:RechargeDetails") //充值明细列表
27
-	beego.Router("/api/his/updeposit", &HisDepositApiController{}, "get:UpDeposit")             //审核
28
-	beego.Router("/api/his/deletehistory", &HisDepositApiController{}, "get:DeleteHistory")     //删除
29
-	beego.Router("/api/his/rechargesummary", &HisDepositApiController{}, "get:RechargeSummary") //充值汇总列表
30
-	beego.Router("/api/his/getuserlist", &HisDepositApiController{}, "get:GetUserList")         //获取患者押金列表
31
-	beego.Router("/api/his/depositflow", &HisDepositApiController{}, "get:DepositFlow")         //根据患者id获取押金流水
32
-}
33
-func (this *HisDepositApiController) TTT() {
34
-	id, _ := this.GetInt64("id")
35
-	err := service.DelDecimalHistory(id)
36
-	this.ServeSuccessJSON(map[string]interface{}{
37
-		"list": err,
38
-	})
39
-	return
22
+	//beego.Router("/api/his/ttt", &HisDepositApiController{}, "get:TTT")                         //测试接口
23
+	beego.Router("/api/his/gethisuser", &HisDepositApiController{}, "get:GetHisUser")                //获取病例中心,有效患者名称
24
+	beego.Router("/api/his/adddeposit", &HisDepositApiController{}, "post:AddDeposit")               //新增押金
25
+	beego.Router("/api/his/getdepositcode", &HisDepositApiController{}, "get:GetDepositCode")        //获取新增押金编号
26
+	beego.Router("/api/his/getdeletecode", &HisDepositApiController{}, "get:GetDeleteCode")          //获取退款编号
27
+	beego.Router("/api/his/rechargedetails", &HisDepositApiController{}, "get:RechargeDetails")      //充值明细列表
28
+	beego.Router("/api/his/updeposit", &HisDepositApiController{}, "get:UpDeposit")                  //押金审核
29
+	beego.Router("/api/his/deletehistory", &HisDepositApiController{}, "get:DeleteHistory")          //押金删除
30
+	beego.Router("/api/his/rechargesummary", &HisDepositApiController{}, "get:RechargeSummary")      //充值汇总列表
31
+	beego.Router("/api/his/getuserlist", &HisDepositApiController{}, "get:GetUserList")              //获取患者押金列表
32
+	beego.Router("/api/his/depositflow", &HisDepositApiController{}, "get:DepositFlow")              //根据患者id获取押金流水
33
+	beego.Router("/api/his/deductiondetails", &HisDepositApiController{}, "get:DeductionDetails")    //扣费明细查询
34
+	beego.Router("/api/his/desummary", &HisDepositApiController{}, "get:DeSummary")                  //扣费汇总
35
+	beego.Router("/api/his/idtobalance", &HisDepositApiController{}, "get:IdToBalance")              //根据患者id查询患者的余额
36
+	beego.Router("/api/his/refundapplication", &HisDepositApiController{}, "post:RefundApplication") //新增一条退款申请
37
+	beego.Router("/api/his/refundreview", &HisDepositApiController{}, "get:RefundReview")            //退款审核通过/拒绝
38
+	beego.Router("/api/his/deleterefund", &HisDepositApiController{}, "get:DeleteRefund")            //退款删除
39
+	beego.Router("/api/his/changerefund", &HisDepositApiController{}, "post:ChangeRefund")           //更改退款申请
40
+	beego.Router("/api/his/refundlist", &HisDepositApiController{}, "get:RefundList")                //退款分页
41
+	beego.Router("/api/his/getorgname", &HisDepositApiController{}, "get:GetorgName")                //获取供应商名字
42
+	beego.Router("/api/his/getweektime", &HisDepositApiController{}, "get:GetWeekTime")              //获取本周时间
43
+	beego.Router("/api/his/getmonthtime", &HisDepositApiController{}, "get:GetMonthTime")            //获取本月时间
40 44
 }
41 45
 
46
+//func (this *HisDepositApiController) TTT() {
47
+//	orgid := this.GetAdminUserInfo().CurrentOrgId
48
+//	id, _ := this.GetInt64("id")
49
+//	code := this.GetString("code")
50
+//	deposit,_ := this.GetInt64("depostit")
51
+//	err := service.MoneyIncrease(orgid,id,code,deposit)
52
+//	if err != nil {
53
+//
54
+//	}
55
+//	this.ServeSuccessJSON(map[string]interface{}{
56
+//		"list": "成功",
57
+//	})
58
+//	return
59
+//}
60
+
42 61
 //获取病例中心,有效患者名称
43 62
 func (this *HisDepositApiController) GetHisUser() {
44 63
 	orgid := this.GetAdminUserInfo().CurrentOrgId
@@ -67,19 +86,43 @@ func (this *HisDepositApiController) AddDeposit() {
67 86
 	case dataBody["code"] == nil:
68 87
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金编号不能为空")
69 88
 		return
70
-	case dataBody["his_patient_id"] == nil:
89
+	case dataBody["his_patient_id"] == nil || dataBody["his_patient_id"] == "":
71 90
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
72 91
 		return
73
-	case dataBody["deposit"] == nil:
92
+	case dataBody["deposit"] == nil || dataBody["deposit"] == "":
74 93
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额不能为空")
75 94
 		return
76
-	case dataBody["trial_status"] == nil:
95
+	case dataBody["trial_status"] == nil || dataBody["trial_status"] == "":
77 96
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
78 97
 		return
79 98
 	}
80
-	code := dataBody["code"].(string)                              //押金编号
81
-	his_patient_id := int64(dataBody["his_patient_id"].(float64))  //患者编号
82
-	deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //押金金额
99
+	code := dataBody["code"].(string)                             //押金编号
100
+	his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
101
+	var tmps float64
102
+	switch dataBody["deposit"].(type) {
103
+	case string:
104
+		t_deposit := dataBody["deposit"].(string)
105
+		if len(t_deposit) > 0 {
106
+			if t_deposit[0] == 45 {
107
+				this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
108
+				return
109
+			}
110
+		}
111
+		tt, errs := strconv.ParseFloat(t_deposit, 64)
112
+		if errs != nil {
113
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
114
+			return
115
+		} else {
116
+			tmps = tt
117
+		}
118
+	default:
119
+		tmps = dataBody["deposit"].(float64)
120
+	}
121
+	if tmps == 0 {
122
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额不能为0")
123
+		return
124
+	}
125
+	deposit := decimal.NewFromFloat(tmps) //押金金额
83 126
 	var remarks string
84 127
 	if dataBody["remarks"] == nil {
85 128
 		remarks = ""
@@ -149,11 +192,11 @@ func (this *HisDepositApiController) RechargeDetails() {
149 192
 
150 193
 	namemap := make(map[int64]string)
151 194
 	slicekey := make([]int64, 0)
195
+	lists, _ := service.GetHisUser(orgid)
196
+	for _, v := range lists {
197
+		namemap[v.ID] = v.Name
198
+	}
152 199
 	if len(keyword) > 0 {
153
-		list, _ := service.GetHisUser(orgid)
154
-		for _, v := range list {
155
-			namemap[v.ID] = v.Name
156
-		}
157 200
 		for k, v := range namemap {
158 201
 			res := strings.Contains(v, keyword)
159 202
 			if res == true {
@@ -181,6 +224,8 @@ func (this *HisDepositApiController) RechargeDetails() {
181 224
 			sum = sum.Add(list[i].Deposit)
182 225
 		}
183 226
 		list[i].Name = service.GetCreateidName(list[i].CreateId)
227
+		list[i].HisName = namemap[list[i].HisPatientId]
228
+		list[i].Starttime = fmt.Sprintf(time.Unix(list[i].Ctime, 0).Format("2006-01-02"))
184 229
 	}
185 230
 	this.ServeSuccessJSON(map[string]interface{}{
186 231
 		"list": list,
@@ -366,6 +411,13 @@ func (this *HisDepositApiController) DepositFlow() {
366 411
 		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, errs.Error())
367 412
 		return
368 413
 	}
414
+	for i := 0; i < len(deposirhistory); i++ {
415
+		//如果为扣费,或退费 则把订单id变为就诊号
416
+		if deposirhistory[i].DepositStatus == 2 || deposirhistory[i].DepositStatus == 4 {
417
+			tmpcode, _ := strconv.ParseInt(deposirhistory[i].DepositCode, 10, 64)
418
+			deposirhistory[i].DepositCode = service.FindcodeToid(tmpcode)
419
+		}
420
+	}
369 421
 
370 422
 	this.ServeSuccessJSON(map[string]interface{}{
371 423
 		"list":    deposirhistory,
@@ -375,7 +427,7 @@ func (this *HisDepositApiController) DepositFlow() {
375 427
 	return
376 428
 }
377 429
 
378
-//
430
+//获取患者押金列表
379 431
 func (this *HisDepositApiController) GetUserList() {
380 432
 	orgid := this.GetAdminUserInfo().CurrentOrgId
381 433
 	keyword := this.GetString("keyword")
@@ -420,6 +472,468 @@ func (this *HisDepositApiController) GetUserList() {
420 472
 	return
421 473
 }
422 474
 
475
+//扣费明细查询
476
+func (this *HisDepositApiController) DeductionDetails() {
477
+	orgid := this.GetAdminUserInfo().CurrentOrgId
478
+	timeLayout := "2006-01-02"
479
+	loc, _ := time.LoadLocation("Local")
480
+	keyword := this.GetString("keyword")
481
+	start_time := this.GetString("start_time")
482
+	end_time := this.GetString("end_time")
483
+	var stime int64 //开始时间
484
+	var etime int64 //结束时间
485
+
486
+	namemap := make(map[int64]string)
487
+	slicekey := make([]int64, 0)
488
+	lists, _ := service.GetHisUser(orgid)
489
+	for _, v := range lists {
490
+		namemap[v.ID] = v.Name
491
+	}
492
+	if len(keyword) > 0 {
493
+		for k, v := range namemap {
494
+			res := strings.Contains(v, keyword)
495
+			if res == true {
496
+				slicekey = append(slicekey, k)
497
+			}
498
+		}
499
+	}
500
+	if start_time == "" && end_time == "" {
501
+		stime, etime = service.GetMondayOfWeek()
502
+	} else {
503
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
504
+		etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
505
+		stime = stmp.Unix()
506
+		etime = etmp.Unix()
507
+	}
508
+	list, err := service.DeductionList(orgid, stime, etime, keyword, slicekey)
509
+	if err != nil {
510
+		utils.ErrorLog(err.Error())
511
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
512
+		return
513
+	}
514
+
515
+	var sum decimal.Decimal
516
+	var detailslist []models.Details
517
+	var details models.Details
518
+	for i := 0; i < len(list); i++ {
519
+		sum = sum.Add(list[i].Deposit)
520
+		tmp_id, _ := strconv.ParseInt(list[i].DepositCode, 10, 64)
521
+		details.ID = tmp_id
522
+		details.Code = service.FindcodeToid(tmp_id)
523
+		details.NameId = list[i].HisPatientId
524
+		details.Name = namemap[list[i].HisPatientId]
525
+		details.Number = service.FindnumberToid(tmp_id)
526
+		details.Decimal = list[i].Deposit
527
+		details.ChargeDate = fmt.Sprintf(time.Unix(list[i].Ctime, 0).Format("2006-01-02 15:04:05"))
528
+		details.Chargetype = service.CodeToChargetype(orgid, details.Code)
529
+		details.Total = service.MedicalTotal(orgid, list[i].HisPatientId, details.Code)
530
+		detailslist = append(detailslist, details)
531
+	}
532
+
533
+	this.ServeSuccessJSON(map[string]interface{}{
534
+		"list": detailslist,
535
+		"sum":  sum,
536
+	})
537
+	return
538
+}
539
+
540
+//扣费汇总
541
+func (this *HisDepositApiController) DeSummary() {
542
+	orgid := this.GetAdminUserInfo().CurrentOrgId
543
+	timeLayout := "2006-01-02"
544
+	loc, _ := time.LoadLocation("Local")
545
+	keyword := this.GetString("keyword")
546
+	start_time := this.GetString("start_time")
547
+	end_time := this.GetString("end_time")
548
+	var stime int64 //开始时间
549
+	var etime int64 //结束时间
550
+
551
+	namemap := make(map[int64]string)
552
+	slicekey := make([]int64, 0)
553
+	lists, _ := service.GetHisUser(orgid)
554
+	for _, v := range lists {
555
+		namemap[v.ID] = v.Name
556
+	}
557
+	if len(keyword) > 0 {
558
+		for k, v := range namemap {
559
+			res := strings.Contains(v, keyword)
560
+			if res == true {
561
+				slicekey = append(slicekey, k)
562
+			}
563
+		}
564
+	}
565
+	if start_time == "" && end_time == "" {
566
+		stime, etime = service.GetMondayOfWeek()
567
+	} else {
568
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
569
+		etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
570
+		stime = stmp.Unix()
571
+		etime = etmp.Unix()
572
+	}
573
+	list, err := service.DeductionList(orgid, stime, etime, keyword, slicekey)
574
+	if err != nil {
575
+		utils.ErrorLog(err.Error())
576
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
577
+		return
578
+	}
579
+	var sum decimal.Decimal
580
+	var detailslist []models.DeductionSummary
581
+	var details models.DeductionSummary
582
+	for i := 0; i < len(list); i++ {
583
+		sum = sum.Add(list[i].Deposit)
584
+		details.Name = namemap[list[i].HisPatientId]
585
+		details.Decimal = list[i].Deposit
586
+		details.Total = service.MedicalTotal(orgid, list[i].HisPatientId, list[i].DepositCode)
587
+		detailslist = append(detailslist, details)
588
+	}
589
+	maplist := make(map[string]models.DeductionSummary)
590
+	Finlist := []models.DeductionSummary{}
591
+	tmpslice := make([]string, 0)
592
+	for i := 0; i < len(detailslist); i++ {
593
+		if k, ok := maplist[detailslist[i].Name]; ok {
594
+			k.Total = k.Total.Add(detailslist[i].Total)
595
+			k.Decimal = k.Decimal.Add(detailslist[i].Decimal)
596
+			maplist[detailslist[i].Name] = models.DeductionSummary{
597
+				detailslist[i].Name,
598
+				k.Total,
599
+				k.Decimal,
600
+			}
601
+		} else {
602
+			maplist[detailslist[i].Name] = models.DeductionSummary{
603
+				detailslist[i].Name,
604
+				detailslist[i].Total,
605
+				detailslist[i].Decimal,
606
+			}
607
+			tmpslice = append(tmpslice, detailslist[i].Name)
608
+		}
609
+	}
610
+	for i := 0; i < len(tmpslice); i++ {
611
+		Finlist = append(Finlist, maplist[tmpslice[i]])
612
+	}
613
+	this.ServeSuccessJSON(map[string]interface{}{
614
+		"list": detailslist,
615
+		"sum":  sum,
616
+	})
617
+	return
618
+}
619
+
620
+//根据患者id查询患者的余额
621
+func (this *HisDepositApiController) IdToBalance() {
622
+	check := map[string][]string{
623
+		"his_patient_id": {"must", "int", "his_patient_id"},
624
+	}
625
+	_, err := checks(this, &check)
626
+	if err != nil {
627
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
628
+		return
629
+	}
630
+	orgid := this.GetAdminUserInfo().CurrentOrgId
631
+	his_patient_id, _ := this.GetInt64("his_patient_id")
632
+	tmp := service.GetUserMoney(his_patient_id, orgid)
633
+	this.ServeSuccessJSON(map[string]interface{}{
634
+		"list": tmp,
635
+	})
636
+	return
637
+}
638
+
639
+//新增一条退款申请
640
+func (this *HisDepositApiController) RefundApplication() {
641
+	orgid := this.GetAdminUserInfo().CurrentOrgId
642
+	createid := this.GetAdminUserInfo().AdminUser.Id
643
+	dataBody := make(map[string]interface{}, 0)
644
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
645
+	if err != nil {
646
+		utils.ErrorLog(err.Error())
647
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
648
+		return
649
+	}
650
+	switch {
651
+	case dataBody["code"] == nil:
652
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "申请编号不能为空")
653
+		return
654
+	case dataBody["his_patient_id"] == nil:
655
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
656
+		return
657
+	case dataBody["deposit"] == nil || dataBody["deposit"] == "":
658
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为空")
659
+		return
660
+	case dataBody["trial_status"] == nil:
661
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
662
+		return
663
+	}
664
+	code := dataBody["code"].(string)                             //申请编号
665
+	his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
666
+	//deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //退款金额
667
+	var tmps float64
668
+	switch dataBody["deposit"].(type) {
669
+	case string:
670
+		t_deposit := dataBody["deposit"].(string)
671
+		if len(t_deposit) > 0 {
672
+			if t_deposit[0] == 45 {
673
+				this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
674
+				return
675
+			}
676
+		}
677
+		tt, errs := strconv.ParseFloat(t_deposit, 64)
678
+		if errs != nil {
679
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
680
+			return
681
+		} else {
682
+			tmps = tt
683
+		}
684
+	default:
685
+		tmps = dataBody["deposit"].(float64)
686
+	}
687
+	if tmps == 0 {
688
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为0")
689
+		return
690
+	}
691
+	deposit := decimal.NewFromFloat(tmps)                     //押金金额
692
+	trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
693
+
694
+	err = service.RefundApplication(orgid, his_patient_id, trial_status, createid, code, deposit)
695
+	if err != nil {
696
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
697
+		return
698
+	}
699
+	this.ServeSuccessJSON(map[string]interface{}{
700
+		"list": "新增成功",
701
+	})
702
+	return
703
+
704
+}
705
+
706
+//退款审核通过/拒绝
707
+func (this *HisDepositApiController) RefundReview() {
708
+	check := map[string][]string{
709
+		"ids":          {"must", "string", "ids"},
710
+		"trial_status": {"must", "int", "trial_status"},
711
+	}
712
+	_, err := checks(this, &check)
713
+	if err != nil {
714
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
715
+		return
716
+	}
717
+	orgid := this.GetAdminUserInfo().CurrentOrgId
718
+	ids := this.GetString("ids") //很多id
719
+
720
+	trial_status, _ := this.GetInt64("trial_status")
721
+	if trial_status != 1 && trial_status != 2 {
722
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "参数trial_status值错误")
723
+		return
724
+	}
725
+	err = service.RefundReviewMore(orgid, trial_status, ids)
726
+	if err != nil {
727
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
728
+		return
729
+	}
730
+	var tmplist string
731
+	if trial_status == 1 {
732
+		tmplist = "审核通过"
733
+	} else {
734
+		tmplist = "审核拒绝"
735
+	}
736
+	this.ServeSuccessJSON(map[string]interface{}{
737
+		"list": tmplist,
738
+	})
739
+	return
740
+}
741
+
742
+//退款删除
743
+func (this *HisDepositApiController) DeleteRefund() {
744
+	check := map[string][]string{
745
+		"id": {"must", "int", "id"},
746
+	}
747
+	_, err := checks(this, &check)
748
+	if err != nil {
749
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
750
+		return
751
+	}
752
+	orgid := this.GetAdminUserInfo().CurrentOrgId
753
+	id, _ := this.GetInt64("id")
754
+	err = service.DeleteRefund(orgid, id)
755
+	if err != nil {
756
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
757
+		return
758
+	}
759
+	this.ServeSuccessJSON(map[string]interface{}{
760
+		"list": "删除成功",
761
+	})
762
+	return
763
+}
764
+
765
+//更改退款申请
766
+func (this *HisDepositApiController) ChangeRefund() {
767
+	orgid := this.GetAdminUserInfo().CurrentOrgId
768
+	dataBody := make(map[string]interface{}, 0)
769
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
770
+	if err != nil {
771
+		utils.ErrorLog(err.Error())
772
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
773
+		return
774
+	}
775
+	switch {
776
+	case dataBody["id"] == nil:
777
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "id不能为空")
778
+		return
779
+	case dataBody["code"] == nil:
780
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "申请编号不能为空")
781
+		return
782
+	case dataBody["his_patient_id"] == nil:
783
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "患者名称不能为空")
784
+		return
785
+	case dataBody["deposit"] == nil || dataBody["deposit"] == "":
786
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为空")
787
+		return
788
+	case dataBody["trial_status"] == nil:
789
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "审核状态不能为空")
790
+		return
791
+	}
792
+	id := int64(dataBody["id"].(float64))
793
+	code := dataBody["code"].(string)                             //申请编号
794
+	his_patient_id := int64(dataBody["his_patient_id"].(float64)) //患者编号
795
+	//deposit := decimal.NewFromFloat(dataBody["deposit"].(float64)) //退款金额
796
+	var tmps float64
797
+	switch dataBody["deposit"].(type) {
798
+	case string:
799
+		t_deposit := dataBody["deposit"].(string)
800
+		if len(t_deposit) > 0 {
801
+			if t_deposit[0] == 45 {
802
+				this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
803
+				return
804
+			}
805
+		}
806
+		tt, errs := strconv.ParseFloat(t_deposit, 64)
807
+		if errs != nil {
808
+			this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额错误")
809
+			return
810
+		} else {
811
+			tmps = tt
812
+		}
813
+	default:
814
+		tmps = dataBody["deposit"].(float64)
815
+	}
816
+	if tmps == 0 {
817
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, "退款金额不能为0")
818
+		return
819
+	}
820
+	deposit := decimal.NewFromFloat(tmps)                     //押金金额
821
+	trial_status := int64(dataBody["trial_status"].(float64)) //审核状态
822
+	err = service.ChangeRefund(orgid, his_patient_id, trial_status, id, code, deposit)
823
+	if err != nil {
824
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
825
+		return
826
+	}
827
+	this.ServeSuccessJSON(map[string]interface{}{
828
+		"list": "保存成功",
829
+	})
830
+	return
831
+}
832
+
833
+//退款分页
834
+func (this *HisDepositApiController) RefundList() {
835
+	check := map[string][]string{
836
+		"refundtype":  {"must", "int", "refundtype"},
837
+		"examinetype": {"must", "int", "examinetype"},
838
+	}
839
+	_, err := checks(this, &check)
840
+	if err != nil {
841
+		this.ServeFailJsonSend(enums.ErrorCodeParamWrong, err.Error())
842
+		return
843
+	}
844
+	orgid := this.GetAdminUserInfo().CurrentOrgId
845
+	timeLayout := "2006-01-02"
846
+	loc, _ := time.LoadLocation("Local")
847
+	keyword := this.GetString("keyword")           //获取搜索框
848
+	refundtype, _ := this.GetInt64("refundtype")   //获取退款类型
849
+	examinetype, _ := this.GetInt64("examinetype") //获取审核状态
850
+	start_time := this.GetString("start_time")
851
+	end_time := this.GetString("end_time")
852
+	var stime int64 //开始时间
853
+	var etime int64 //结束时间
854
+
855
+	namemap := make(map[int64]string)
856
+	slicekey := make([]int64, 0)
857
+	lists, _ := service.GetHisUser(orgid)
858
+	for _, v := range lists {
859
+		namemap[v.ID] = v.Name
860
+	}
861
+	if len(keyword) > 0 {
862
+		for k, v := range namemap {
863
+			res := strings.Contains(v, keyword)
864
+			if res == true {
865
+				slicekey = append(slicekey, k)
866
+			}
867
+		}
868
+	}
869
+	if start_time == "" && end_time == "" {
870
+		stime, etime = service.GetMondayOfWeek()
871
+	} else {
872
+		stmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
873
+		etmp, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
874
+		stime = stmp.Unix()
875
+		etime = etmp.Unix()
876
+	}
877
+	depo := []models.RefundList{}
878
+	depo, err = service.RefundList(orgid, stime, etime, refundtype, examinetype, keyword, slicekey)
879
+	if err != nil {
880
+		utils.ErrorLog("查询失败,原因为:", err.Error())
881
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
882
+		return
883
+	}
884
+	for i := 0; i < len(depo); i++ {
885
+		depo[i].Name = service.GetCreateidName(depo[i].CreateId)
886
+		depo[i].HisName = namemap[depo[i].HisPatientId]
887
+		if depo[i].Mtime > depo[i].Ctime {
888
+			depo[i].Starttime = fmt.Sprintf(time.Unix(depo[i].Mtime, 0).Format("2006-01-02 15:04:05"))
889
+		} else {
890
+			depo[i].Starttime = fmt.Sprintf(time.Unix(depo[i].Ctime, 0).Format("2006-01-02 15:04:05"))
891
+		}
892
+		if depo[i].DepositStatus == 4 {
893
+			depo[i].Name = "-"
894
+		}
895
+	}
896
+	this.ServeSuccessJSON(map[string]interface{}{
897
+		"list": depo,
898
+	})
899
+	return
900
+}
901
+
902
+func (this *HisDepositApiController) GetorgName() {
903
+	orgid := this.GetAdminUserInfo().CurrentOrgId
904
+	name := service.GetorgName(orgid)
905
+	this.ServeSuccessJSON(map[string]interface{}{
906
+		"list": name,
907
+	})
908
+	return
909
+}
910
+
911
+//获取本月时间
912
+func (this *HisDepositApiController) GetMonthTime() {
913
+	stime, etime := service.GetMonth()
914
+	srart_time := fmt.Sprintf(time.Unix(stime, 0).Format("2006-01-02"))
915
+	end_time := fmt.Sprintf(time.Unix(etime, 0).Format("2006-01-02"))
916
+
917
+	this.ServeSuccessJSON(map[string]interface{}{
918
+		"srart_time": srart_time,
919
+		"end_time":   end_time,
920
+	})
921
+	return
922
+}
923
+
924
+//获取本周时间
925
+func (this *HisDepositApiController) GetWeekTime() {
926
+	stime, etime := service.GetMondayOfWeek()
927
+	srart_time := fmt.Sprintf(time.Unix(stime, 0).Format("2006-01-02"))
928
+	end_time := fmt.Sprintf(time.Unix(etime, 0).Format("2006-01-02"))
929
+
930
+	this.ServeSuccessJSON(map[string]interface{}{
931
+		"srart_time": srart_time,
932
+		"end_time":   end_time,
933
+	})
934
+	return
935
+}
936
+
423 937
 //判断前端参数是否为空
424 938
 func checks(this *HisDepositApiController, m *map[string][]string) (map[string]string, error) {
425 939
 	tmp := make(map[string]string)

+ 83 - 6
controllers/mobile_api_controllers/mobile_api_base_controller.go Vedi File

@@ -5,8 +5,14 @@ import (
5 5
 	"XT_New/enums"
6 6
 	"XT_New/models"
7 7
 	"XT_New/service"
8
+	"bytes"
8 9
 	"encoding/json"
9 10
 	"fmt"
11
+	"log"
12
+	"os"
13
+	"path"
14
+	"regexp"
15
+	"runtime"
10 16
 	"strconv"
11 17
 	"strings"
12 18
 	"time"
@@ -107,18 +113,30 @@ func (this *MobileBaseAPIAuthController) Prepare() {
107 113
 
108 114
 	if this.Ctx.Request.Header.Get("Permission") == "1" {
109 115
 		if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator { //超级管理员不受此限制
116
+			err_msgs := LoadErrMsgConfig("./err_msg.json").Msgs
110 117
 
111 118
 			isPermission := false
112 119
 			adminUserInfo := this.GetMobileAdminUserInfo()
113 120
 			//该机构下该用户有多少个
114
-			role, _ := service.GetUserAllRole(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id)
121
+			redisClient := service.RedisClient()
122
+			defer redisClient.Close()
123
+			key2 := strconv.FormatInt(adminUserInfo.Org.Id, 64) + "_" + strconv.FormatInt(adminUserInfo.AdminUser.Id, 64) + "_role_ids"
124
+			result, _ := redisClient.Get(key2).Result()
125
+			var role models.App_Role
115 126
 			var roles []string
116
-			if len(role.RoleIds) <= 0 { //该用户没有设置角色
117
-
127
+			if len(result) == 0 {
128
+				//该机构下该用户有多少个
129
+				role, _ = service.GetUserAllRole(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id)
130
+				redisClient.Set(key2, role, time.Second*60*60*18)
131
+				if len(role.RoleIds) > 0 { //该用户没有设置角色
132
+					roles = strings.Split(role.RoleIds, ",")
133
+				}
118 134
 			} else {
119
-				roles = strings.Split(role.RoleIds, ",")
135
+				json.Unmarshal([]byte(result), &role)
136
+				if len(role.RoleIds) > 0 { //该用户没有设置角色
137
+					roles = strings.Split(role.RoleIds, ",")
138
+				}
120 139
 			}
121
-
122 140
 			//redis相关处理逻辑
123 141
 			redis := service.RedisClient()
124 142
 			defer redis.Close()
@@ -178,7 +196,14 @@ func (this *MobileBaseAPIAuthController) Prepare() {
178 196
 						}
179 197
 					}
180 198
 					if !isPermission {
181
-						msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
199
+						//msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
200
+						var msg string
201
+						for _, item := range err_msgs {
202
+							if strings.Index(item.Url, strings.Split(this.Ctx.Request.RequestURI, "?")[0]+"?"+"mode="+this.GetString("mode")) != -1 {
203
+								msg = item.ErrMsg
204
+							}
205
+						}
206
+
182 207
 						json := make(map[string]interface{})
183 208
 						json["msg"] = msg
184 209
 						json["code"] = 0
@@ -225,3 +250,55 @@ type AdminUserInfo struct {
225 250
 	AppUrlfors   map[int64][]string                   `json:"app_urlfors"`
226 251
 	Subscibes    map[int64]*models.ServeSubscibe      `json:"org_subscibes"`
227 252
 }
253
+
254
+type ErrMsgConfig struct {
255
+	Msgs []*models.ErrMsg "json:msg"
256
+}
257
+
258
+func LoadErrMsgConfig(dataFile string) *ErrMsgConfig {
259
+	var config ErrMsgConfig
260
+	_, filename, _, _ := runtime.Caller(1)
261
+	datapath := path.Join(path.Dir(filename), dataFile)
262
+	config_file, err := os.Open(datapath)
263
+	if err != nil {
264
+		emit("Failed to open config file '%s': %s\n", datapath, err)
265
+		return &config
266
+	}
267
+	fi, _ := config_file.Stat()
268
+	buffer := make([]byte, fi.Size())
269
+	_, err = config_file.Read(buffer)
270
+	buffer, err = StripComments(buffer) //去掉注释
271
+	if err != nil {
272
+		emit("Failed to strip comments from json: %s\n", err)
273
+		return &config
274
+	}
275
+	buffer = []byte(os.ExpandEnv(string(buffer))) //特殊
276
+	err = json.Unmarshal(buffer, &config)         //解析json格式数据
277
+	if err != nil {
278
+		emit("Failed unmarshalling json: %s\n", err)
279
+		return &config
280
+	}
281
+	return &config
282
+}
283
+
284
+func emit(msgfmt string, args ...interface{}) {
285
+	log.Printf(msgfmt, args...)
286
+}
287
+
288
+func StripComments(data []byte) ([]byte, error) {
289
+	data = bytes.Replace(data, []byte("\r"), []byte(""), 0) // Windows
290
+	lines := bytes.Split(data, []byte("\n"))                //split to muli lines
291
+	filtered := make([][]byte, 0)
292
+
293
+	for _, line := range lines {
294
+		match, err := regexp.Match(`^\s*#`, line)
295
+		if err != nil {
296
+			return nil, err
297
+		}
298
+		if !match {
299
+			filtered = append(filtered, line)
300
+		}
301
+	}
302
+
303
+	return bytes.Join(filtered, []byte("\n")), nil
304
+}

+ 4 - 8
controllers/patient_api_controller.go Vedi File

@@ -3627,6 +3627,7 @@ func patientFormData(patient *models.Patients, data []byte, method string) (cont
3627 3627
 				fmt.Println(item_id)
3628 3628
 
3629 3629
 				item, _ := items["item"].(string)
3630
+
3630 3631
 				fmt.Println(items["item"].(string))
3631 3632
 
3632 3633
 				item_name, _ := items["item_name"].(string)
@@ -3885,6 +3886,9 @@ func patientFormData(patient *models.Patients, data []byte, method string) (cont
3885 3886
 	}
3886 3887
 	patient.Source = source
3887 3888
 
3889
+	zb_patient_id := patientBody["zb_patient_id"].(string)
3890
+	patient.ZbPatientId = zb_patient_id
3891
+
3888 3892
 	if patientBody["is_hospital_first_dialysis"] != nil && reflect.TypeOf(patientBody["is_hospital_first_dialysis"]).String() == "float64" {
3889 3893
 		isHospitalFirstDialysis := int64(patientBody["is_hospital_first_dialysis"].(float64))
3890 3894
 		patient.IsHospitalFirstDialysis = isHospitalFirstDialysis
@@ -4100,7 +4104,6 @@ func patientFormData(patient *models.Patients, data []byte, method string) (cont
4100 4104
 		patient.DialysisAge = dialysis_age
4101 4105
 	}
4102 4106
 	fmt.Println(patient.DialysisAge)
4103
-
4104 4107
 	if patientBody["first_treatment_date"] != nil && reflect.TypeOf(patientBody["first_treatment_date"]).String() == "string" {
4105 4108
 		first_treatment_date := patientBody["first_treatment_date"].(string)
4106 4109
 		first_treatment_time, err := time.ParseInLocation(timeLayout, first_treatment_date, loc)
@@ -4108,31 +4111,24 @@ func patientFormData(patient *models.Patients, data []byte, method string) (cont
4108 4111
 			patient.FirstTreatmentDate = first_treatment_time.Unix()
4109 4112
 		}
4110 4113
 	}
4111
-
4112 4114
 	if patientBody["expense_kind"] != nil && reflect.TypeOf(patientBody["expense_kind"]).String() == "float64" {
4113 4115
 		expense_kind := int64(patientBody["expense_kind"].(float64))
4114 4116
 		patient.ExpenseKind = expense_kind
4115 4117
 	}
4116
-
4117 4118
 	fmt.Println(patient.ExpenseKind)
4118
-
4119 4119
 	if patientBody["tell_phone"] != nil && reflect.TypeOf(patientBody["tell_phone"]).String() == "string" {
4120 4120
 		tell_phone := patientBody["tell_phone"].(string)
4121 4121
 		patient.TellPhone = tell_phone
4122 4122
 	}
4123
-
4124 4123
 	if patientBody["contact_name"] != nil && reflect.TypeOf(patientBody["contact_name"]).String() == "string" {
4125 4124
 		contact_name := patientBody["contact_name"].(string)
4126 4125
 		patient.ContactName = contact_name
4127 4126
 	}
4128
-
4129 4127
 	if patientBody["troble_shoot"] != nil && reflect.TypeOf(patientBody["troble_shoot"]).String() == "float64" {
4130 4128
 		troble_shoot := int64(patientBody["troble_shoot"].(float64))
4131 4129
 		patient.TrobleShoot = troble_shoot
4132 4130
 	}
4133
-
4134 4131
 	return
4135
-
4136 4132
 }
4137 4133
 
4138 4134
 func (c *PatientApiController) GetPatientsByKeyWord() {

+ 66 - 2
models/his_deposit_models.go Vedi File

@@ -23,7 +23,7 @@ type DepositHistory struct {
23 23
 	DepositCode    string          `gorm:"column:deposit_code" json:"deposit_code" form:"deposit_code"`
24 24
 	Deposit        decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"`                         //本次操作金额
25 25
 	SurplusDeposit decimal.Decimal `gorm:"column:surplus_deposit" json:"surplus_deposit" form:"surplus_deposit"` //剩余金额
26
-	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退费
26
+	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退款,4:退
27 27
 	Status         int64           `gorm:"column:status" json:"status" form:"status"`
28 28
 	CreateId       int64           `gorm:"column:create_id" json:"create_id" form:"create_id"`
29 29
 	Ctime          int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
@@ -52,7 +52,7 @@ type DepositHistoryname struct {
52 52
 	DepositCode    string          `gorm:"column:deposit_code" json:"deposit_code" form:"deposit_code"`
53 53
 	Deposit        decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"`                         //本次操作金额
54 54
 	SurplusDeposit decimal.Decimal `gorm:"column:surplus_deposit" json:"surplus_deposit" form:"surplus_deposit"` //剩余金额
55
-	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退费
55
+	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退款,4:退
56 56
 	Status         int64           `gorm:"column:status" json:"status" form:"status"`
57 57
 	CreateId       int64           `gorm:"column:create_id" json:"create_id" form:"create_id"`
58 58
 	Ctime          int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
@@ -60,12 +60,36 @@ type DepositHistoryname struct {
60 60
 	TrialStatus    int64           `gorm:"column:trial_status" json:"trial_status" form:"trial_status"` //审核状态0:未审核 ,1:已审核
61 61
 	Remarks        string          `gorm:"column:remarks" json:"remarks" form:"remarks"`                //备注
62 62
 	Name           string          ` json:"name" `
63
+	HisName        string          `json:"his_name"`
64
+	Starttime      string          `json:"starttime"` //创建时间
63 65
 }
64 66
 
65 67
 func (DepositHistoryname) TableName() string {
66 68
 	return "sgj_xt.his_deposit_history"
67 69
 }
68 70
 
71
+type RefundList struct {
72
+	ID             int64           `gorm:"column:id" json:"id" form:"id"`
73
+	UserOrgId      int64           `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`          //机构id
74
+	HisPatientId   int64           `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"` //his病人id
75
+	DepositCode    string          `gorm:"column:deposit_code" json:"deposit_code" form:"deposit_code"`
76
+	Deposit        decimal.Decimal `gorm:"column:deposit" json:"deposit" form:"deposit"`                         //本次操作金额
77
+	SurplusDeposit decimal.Decimal `gorm:"column:surplus_deposit" json:"surplus_deposit" form:"surplus_deposit"` //剩余金额
78
+	DepositStatus  int64           `gorm:"column:deposit_status" json:"deposit_status" form:"deposit_status"`    //1:充值,2:扣费,3:退款,4:退费
79
+	Status         int64           `gorm:"column:status" json:"status" form:"status"`
80
+	CreateId       int64           `gorm:"column:create_id" json:"create_id" form:"create_id"`
81
+	Ctime          int64           `gorm:"column:ctime" json:"ctime" form:"ctime"`
82
+	Mtime          int64           `gorm:"column:mtime" json:"mtime" form:"mtime"`
83
+	TrialStatus    int64           `gorm:"column:trial_status" json:"trial_status" form:"trial_status"` //审核状态0:未审核 ,1:已审核
84
+	Starttime      string          `json:"starttime"`                                                   //申请时间
85
+	Name           string          ` json:"name" `                                                      //申请人
86
+	HisName        string          `json:"his_name"`
87
+}
88
+
89
+func (RefundList) TableName() string {
90
+	return "sgj_xt.his_deposit_history"
91
+}
92
+
69 93
 type CreateUser struct {
70 94
 	ID   int64  `gorm:"column:id" json:"id" form:"id"`
71 95
 	Name string `gorm:"column:name" json:"name" form:"name"`
@@ -95,3 +119,43 @@ type Deposit1 struct {
95 119
 func (Deposit1) TableName() string {
96 120
 	return "sgj_xt.his_deposit"
97 121
 }
122
+
123
+//扣费明细列表
124
+type Details struct {
125
+	ID         int64           `json:"id"`          //原始code
126
+	Code       string          `json:"code"`        //就诊号
127
+	Number     string          `json:"number"`      //批号,用来跳转用的
128
+	NameId     int64           `json:"name_id"`     //患者id
129
+	Name       string          `json:"name"`        //患者名字
130
+	Chargetype string          `json:"chargetype"`  //医收费类型
131
+	Total      decimal.Decimal `json:"total"`       //医疗费总额
132
+	Decimal    decimal.Decimal `json:"decimal"`     //押金支付金额
133
+	ChargeDate string          `json:"charge_date"` //收费日期
134
+}
135
+
136
+//扣费汇总
137
+type DeductionSummary struct {
138
+	Name    string          `json:"name"`    //患者名字
139
+	Total   decimal.Decimal `json:"total"`   //医疗费总额
140
+	Decimal decimal.Decimal `json:"decimal"` //押金支付金额
141
+}
142
+
143
+type GetorgName struct {
144
+	ID      int64  `json:"id"`
145
+	OrgName string `json:"org_name"`
146
+}
147
+
148
+func (GetorgName) TableName() string {
149
+	return "sgj_users.sgj_user_org"
150
+}
151
+
152
+//获取就诊号
153
+type GetMdtrtId struct {
154
+	Id      int64  `json:"id"`
155
+	MdtrtId string `json:"mdtrt_id"`
156
+	Number  string `json:"number"`
157
+}
158
+
159
+func (GetMdtrtId) TableName() string {
160
+	return "sgj_xt.his_order"
161
+}

+ 1 - 0
models/his_models.go Vedi File

@@ -1022,6 +1022,7 @@ type HisOrder struct {
1022 1022
 	DoctorName            string    `gorm:"-" json:"doctor_name" form:"doctor_name"`
1023 1023
 	Creator               int64     `gorm:"column:creator" json:"creator" form:"creator"`
1024 1024
 	PType                 int64     `gorm:"column:p_type" json:"p_type" form:"p_type"`
1025
+	Decimal               float64   `gorm:"column:decimal" json:"decimal" form:"decimal"`
1025 1026
 
1026 1027
 	FaPiaoCode   string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
1027 1028
 	FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`

+ 1 - 1
routers/router.go Vedi File

@@ -57,7 +57,7 @@ func init() {
57 57
 	controllers.HisChargeApiRegistRouters()
58 58
 	controllers.HisHospitalManagerApiRegistRouters()
59 59
 	controllers.HisPrintApiRegistRouters()
60
-	controllers.CoordinateRegistRouters()
60
+	controllers.CoordinateRcegistRouters()
61 61
 
62 62
 	m_api.MobileAPIControllersRegisterRouters()
63 63
 	new_m_api.NewMobileAPIControllersRegisterRouters()

+ 1 - 0
service/admin_service.go Vedi File

@@ -30,6 +30,7 @@ func GetTotalOrgCount() (int, error) {
30 30
 		return 0, err
31 31
 	}
32 32
 	return count, nil
33
+
33 34
 }
34 35
 
35 36
 // 获取一段时间内注册的机构数量

+ 1 - 1
service/coordinate_service.go Vedi File

@@ -16,7 +16,7 @@ func SavePatientMessageInfo() (string, string) {
16 16
 	inputData := make(map[string]interface{})
17 17
 	inputData["patType"] = "1"                  // 就诊凭证编号
18 18
 	inputData["patIdNo"] = "440510199211080038" // 开始时间
19
-	inputData["patName"] = "测试患者4"              // 人员姓名
19
+	inputData["patName"] = "测试患者4 "             // 人员姓名
20 20
 
21 21
 	inputData["patMobile"] = "13535547902" // 人员姓名
22 22
 	inputData["patSex"] = "M"              // 人员姓名

+ 474 - 13
service/his_deposit_service.go Vedi File

@@ -4,9 +4,11 @@ import (
4 4
 	"XT_New/models"
5 5
 	"XT_New/utils"
6 6
 	"fmt"
7
+	"github.com/jinzhu/gorm"
7 8
 	"github.com/shopspring/decimal"
8 9
 	"math/rand"
9 10
 	"strconv"
11
+	"strings"
10 12
 	"time"
11 13
 )
12 14
 
@@ -42,6 +44,7 @@ func UpDeposit(code, remarks string, his_patient_id, orgid, trial_status, create
42 44
 			UserOrgId:    orgid,
43 45
 			HisPatientId: his_patient_id,
44 46
 			Ctime:        time.Now().Unix(),
47
+			Mtime:        time.Now().Unix(),
45 48
 			Status:       1,
46 49
 		}
47 50
 		i, d, err := AddDeposit(de)
@@ -52,6 +55,7 @@ func UpDeposit(code, remarks string, his_patient_id, orgid, trial_status, create
52 55
 		tmp = i
53 56
 		tmpdeposit = d
54 57
 	}
58
+	s_deposit := tmpdeposit
55 59
 	if trial_status == 1 {
56 60
 		de := models.Deposit{
57 61
 			ID:      tmp,
@@ -63,13 +67,14 @@ func UpDeposit(code, remarks string, his_patient_id, orgid, trial_status, create
63 67
 			utils.ErrorLog("添加用户押金失败: %v", err.Error())
64 68
 			return
65 69
 		}
70
+		s_deposit = deposit.Add(tmpdeposit)
66 71
 	}
67 72
 	dehistory := models.DepositHistory{
68 73
 		UserOrgId:      orgid,
69 74
 		HisPatientId:   his_patient_id,
70 75
 		DepositCode:    code,
71
-		Deposit:        deposit,                 //本次操作的押金
72
-		SurplusDeposit: tmpdeposit.Add(deposit), //剩余金额
76
+		Deposit:        deposit,   //本次操作的押金
77
+		SurplusDeposit: s_deposit, //剩余金额
73 78
 		DepositStatus:  1,
74 79
 		Status:         1,
75 80
 		CreateId:       createid,
@@ -197,6 +202,7 @@ func GetMonth() (int64, int64) {
197 202
 	timeMonthEndUnix1 := timeToday.AddDate(0, 1, -timeToday.Day()+1).Unix() - 1                            // 获取下个月第一天/ 本月最后一天24点 时间戳类型
198 203
 	return timeMonthStartUnix1, timeMonthEndUnix1
199 204
 }
205
+
200 206
 func GetCreateidName(id int64) string {
201 207
 	var tmp models.CreateUser
202 208
 	XTReadDB().Select("name").Where("id = ?", id).Find(&tmp)
@@ -209,7 +215,7 @@ func UpDecimalHistory(id int64) (err error) {
209 215
 	tx := XTWriteDB().Begin()
210 216
 	defer func() {
211 217
 		if err != nil {
212
-			utils.ErrorLog("事务失败,原因为", err)
218
+			utils.ErrorLog("事务失败,原因为: %v", err)
213 219
 			tx.Rollback()
214 220
 		} else {
215 221
 			tx.Commit()
@@ -261,7 +267,10 @@ func GetDecimalHistoryOne(id int64) (history models.DepositHistory, err error) {
261 267
 //根据患者id获取该患者当前剩余的押金
262 268
 func GetUserMoney(id, orgid int64) decimal.Decimal {
263 269
 	tmp := models.Deposit{}
264
-	XTReadDB().Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&tmp)
270
+	err := XTReadDB().Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", id, orgid).Find(&tmp).Error
271
+	if err != nil {
272
+		return decimal.NewFromFloat(0)
273
+	}
265 274
 	return tmp.Deposit
266 275
 }
267 276
 
@@ -282,23 +291,475 @@ func GetFlowList(id, orgid, stime, etime, deposit_status int64) (deposit []model
282 291
 	return
283 292
 }
284 293
 
294
+//获取患者押金列表
285 295
 func GetUserList(page, limit, orgid int64, keyword string, slicekey []int64) (m []models.Deposit1, total int64, err error) {
286 296
 	db := XTReadDB().Model(&models.Deposit{}).Where("status = 1 and user_org_id = ? ", orgid)
287 297
 	offset := (page - 1) * limit
288
-	if len(slicekey) > 0 {
289
-		tmp := ""
290
-		for i := 0; i < len(slicekey); i++ {
291
-			tmp = tmp + " his_patient_id = " + strconv.FormatInt(slicekey[i], 10)
292
-			if i < len(slicekey)-1 {
293
-				tmp = tmp + " or "
298
+	if len(keyword) > 0 {
299
+		db = db.Where(" his_patient_id = ? ", keyword)
300
+	}
301
+	err = db.Count(&total).Offset(offset).Order("mtime desc").Find(&m).Error
302
+	return
303
+}
304
+
305
+//扣费明细列表
306
+func DeductionList(orgid, stime, etime int64, keyword string, slicekey []int64) (deposithistory []models.DepositHistory, err error) {
307
+	db := XTReadDB().Model(&models.DepositHistory{}).Where("status = 1 and user_org_id = ? and deposit_status = 2 ", orgid).Where("ctime >= ? and ctime <= ?", stime, etime)
308
+	if len(keyword) > 0 {
309
+		var tmp string = "deposit_code like ?"
310
+		if len(slicekey) > 0 {
311
+			for i := 0; i < len(slicekey); i++ {
312
+				tmp = tmp + " or his_patient_id = " + strconv.FormatInt(slicekey[i], 10)
294 313
 			}
295 314
 		}
296
-		db = db.Where(tmp)
315
+		keyword = "%" + keyword + "%"
316
+		db = db.Where(tmp, keyword)
317
+	}
318
+	err = db.Order("ctime desc").Find(&deposithistory).Error
319
+	return
320
+}
321
+
322
+//获取医疗费总额
323
+func MedicalTotal(orgid, patient_id int64, code string) decimal.Decimal {
324
+	tmp := models.HisChargeSettleOrder{}
325
+	XTReadDB().Model(&models.HisChargeSettleOrder{}).Where("mdtrt_id = ? and patient_id = ? and user_org_id = ? and status = 1 and order_status = 2", code, patient_id, orgid).Find(&tmp)
326
+	return decimal.NewFromFloat(tmp.MedfeeSumamt)
327
+}
328
+
329
+//根据就诊号查询出医收费类型
330
+func CodeToChargetype(orgid int64, code string) (s string) {
331
+	tmp := models.HisPrintPatient{}
332
+	XTReadDB().Model(&models.HisPrintPatient{}).Where("number = ? and user_org_id = ?", code, orgid).Find(&tmp)
333
+	//tmp.BalanceAccountsType
334
+	switch tmp.BalanceAccountsType {
335
+	case 1:
336
+		s = "医保"
337
+	case 2:
338
+		s = "自费"
339
+	case 3:
340
+		s = "公费"
341
+	case 4:
342
+		s = "农保"
343
+	case 5:
344
+		s = "会员"
345
+	case 6:
346
+		s = "职工"
347
+	case 7:
348
+		s = "合同"
349
+	case 8:
350
+		s = "医保自费"
351
+	default:
352
+		s = "类型未定义"
353
+	}
354
+	return
355
+}
356
+
357
+//扣除患者的押金,并生成一条扣费历史记录
358
+//orgid 机构id;
359
+//his_user_id	患者id;
360
+//create_id		创建者id;
361
+//code		就诊号;
362
+//deposit	本次使用的押金金额,支持float64、int、int64、decimal.Decimal类型
363
+func SpendDeposit(orgid, his_user_id, create_id int64, code string, deposit interface{}) (err error) {
364
+	tmp_deposit := decimal.Decimal{} //本次患者使用的押金
365
+	tmp_deposit, err = ToDecimal(deposit)
366
+	if err != nil {
367
+		return
368
+	}
369
+	//开事务
370
+	tx := XTWriteDB().Begin()
371
+	defer func() {
372
+		if err != nil {
373
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
374
+			tx.Rollback()
375
+		} else {
376
+			tx.Commit()
377
+		}
378
+	}()
379
+	//查询患者押金
380
+	tmp := models.Deposit{}
381
+	err = tx.Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", his_user_id, orgid).Find(&tmp).Error
382
+	if err != nil {
383
+		err = fmt.Errorf("押金余额不足")
384
+		return
385
+	}
386
+	//判断能否扣除
387
+	if tmp.Deposit.Cmp(tmp_deposit) == -1 {
388
+		err = fmt.Errorf("押金余额不足")
389
+		return
390
+	}
391
+	//扣除患者押金
392
+	err = tx.Model(&models.Deposit{}).Where("id = ? and status = 1", tmp.ID).Updates(map[string]interface{}{
393
+		"mtime":   time.Now().Unix(),
394
+		"deposit": tmp.Deposit.Sub(tmp_deposit),
395
+	}).Error
396
+	if err != nil {
397
+		return
398
+	}
399
+	//生成一条历史记录
400
+	dehistory := models.DepositHistory{
401
+		UserOrgId:      orgid,
402
+		HisPatientId:   his_user_id,
403
+		DepositCode:    code,
404
+		Deposit:        tmp_deposit,
405
+		SurplusDeposit: tmp.Deposit.Sub(tmp_deposit),
406
+		DepositStatus:  2,
407
+		Status:         1,
408
+		CreateId:       create_id,
409
+		Ctime:          time.Now().Unix(),
410
+		Mtime:          time.Now().Unix(),
411
+		TrialStatus:    1,
412
+	}
413
+	err = tx.Create(&dehistory).Error
414
+	return
415
+}
416
+
417
+//新增一条退款申请
418
+func RefundApplication(orgid, his_patient_id, trial_status, createid int64, code string, deposit decimal.Decimal) (err error) {
419
+	//开事务
420
+	tx := XTWriteDB().Begin()
421
+	defer func() {
422
+		if err != nil {
423
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
424
+			tx.Rollback()
425
+		} else {
426
+			tx.Commit()
427
+		}
428
+	}()
429
+	//获取患者当前余额
430
+	tmp := models.Deposit{}
431
+	err = tx.Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", his_patient_id, orgid).Find(&tmp).Error
432
+	if err != nil {
433
+		return
434
+	}
435
+	//判断是否可以退款
436
+	if tmp.Deposit.Cmp(deposit) == -1 {
437
+		err = fmt.Errorf("退款金额不得大于押金余额!")
438
+		return
439
+	}
440
+	s_deposit := tmp.Deposit
441
+	//判断是否审核通过,通过更新当前押金,否则只新增一条历史记录
442
+	if trial_status == 1 {
443
+		//更新患者当前押金余额
444
+		err = tx.Model(&models.Deposit{}).Where("id = ? and status = 1", tmp.ID).Updates(map[string]interface{}{
445
+			"mtime":   time.Now().Unix(),
446
+			"deposit": tmp.Deposit.Sub(deposit),
447
+		}).Error
448
+		if err != nil {
449
+			return
450
+		}
451
+		s_deposit = tmp.Deposit.Sub(deposit)
452
+	}
453
+	//生成一条历史记录
454
+	dehistory := models.DepositHistory{
455
+		UserOrgId:      orgid,
456
+		HisPatientId:   his_patient_id,
457
+		DepositCode:    code,
458
+		Deposit:        deposit,
459
+		SurplusDeposit: s_deposit,
460
+		DepositStatus:  3, //3退款,4退费
461
+		Status:         1,
462
+		CreateId:       createid,
463
+		Ctime:          time.Now().Unix(),
464
+		Mtime:          time.Now().Unix(),
465
+		TrialStatus:    trial_status,
466
+	}
467
+	err = tx.Create(&dehistory).Error
468
+	return
469
+}
470
+
471
+//退款审核通过/拒绝批量处理
472
+func RefundReviewMore(orgid, trial_status int64, ids string) (err error) {
473
+	//处理下字符串
474
+	t_ids := ""
475
+	if ids[len(ids)-1] == 44 {
476
+		t_ids = ids[:len(ids)-1]
297 477
 	} else {
298
-		if len(keyword) > 0 {
478
+		t_ids = ids
479
+	}
480
+	tmp_id := strings.Split(t_ids, ",")
481
+	//开事务
482
+	tx := XTWriteDB().Begin()
483
+	defer func() {
484
+		if err != nil {
485
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
486
+			tx.Rollback()
487
+		} else {
488
+			tx.Commit()
489
+		}
490
+	}()
491
+	//循环处理id
492
+	for i := 0; i < len(tmp_id); i++ {
493
+		var id int64
494
+		id, err = strconv.ParseInt(tmp_id[i], 10, 64)
495
+		if err != nil {
496
+			return err
497
+		}
498
+		err = RefundReview(orgid, id, trial_status, tx)
499
+		if err != nil {
500
+			return err
501
+		}
502
+	}
503
+	return err
504
+}
505
+
506
+//退款审核通过/拒绝
507
+func RefundReview(orgid, id, trial_status int64, tx *gorm.DB) (err error) {
508
+	//根据id查询该条历史记录
509
+	history := models.DepositHistory{}
510
+	err = tx.Model(&models.DepositHistory{}).Where("id = ? and status = 1", id).Find(&history).Error
511
+	if err != nil {
512
+		return err
513
+	}
514
+	//判断状态是否为未审核
515
+	if history.TrialStatus != 0 {
516
+		err = fmt.Errorf("所选单据中包含了无需审核的单据")
517
+		return err
518
+	}
519
+	//判断类型是否为3,3代表退款,4为退费
520
+	if history.DepositStatus != 3 {
521
+		err = fmt.Errorf("所选单据中包含了无需审核的单据")
522
+		return err
523
+	}
524
+	up := make(map[string]interface{})
525
+	//通过
526
+	if trial_status == 1 {
527
+		//拿患者的id和机构id在去查患者的余额
528
+		tt := models.Deposit{}
529
+		err = tx.Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", history.HisPatientId, orgid).Find(&tt).Error
530
+		if err != nil {
531
+			return err
532
+		}
533
+		//判断是否可以修改患者押金
534
+		if tt.Deposit.Cmp(history.Deposit) == -1 {
535
+			err = fmt.Errorf("当前押金余额小于退款金额,无法完成退款")
536
+			return err
537
+		}
538
+		//修改患者押金
539
+		err = tx.Model(&models.Deposit{}).Where("id = ? and status = 1", tt.ID).Updates(map[string]interface{}{
540
+			"mtime":   time.Now().Unix(),
541
+			"deposit": tt.Deposit.Sub(history.Deposit),
542
+		}).Error
543
+		if err != nil {
544
+			return err
545
+		}
546
+		up = map[string]interface{}{
547
+			"mtime":           time.Now().Unix(),
548
+			"surplus_deposit": tt.Deposit.Sub(history.Deposit),
549
+			"trial_status":    1,
550
+		}
551
+	} else {
552
+		up = map[string]interface{}{
553
+			"mtime":        time.Now().Unix(),
554
+			"trial_status": 2,
555
+		}
556
+	}
557
+	//修改一条历史记录
558
+	err = tx.Model(&models.DepositHistory{}).Where("id = ? and status = 1", id).Updates(up).Error
559
+	return err
560
+}
561
+
562
+//退款删除
563
+func DeleteRefund(orgid, id int64) (err error) {
564
+	//根据id查询历史记录
565
+	history := models.DepositHistory{}
566
+	err = XTReadDB().Model(&models.DepositHistory{}).Where("id = ?", id).Find(&history).Error
567
+	if err != nil {
568
+		return
569
+	}
570
+	//判断是否可以删除
571
+	if history.TrialStatus == 1 || history.DepositStatus != 3 {
572
+		err = fmt.Errorf("当前状态不可删除!")
573
+		return
574
+	}
575
+	//删除
576
+	err = XTWriteDB().Model(&models.DepositHistory{}).Where("id = ?", id).Updates(map[string]interface{}{
577
+		"mtime":  time.Now().Unix(),
578
+		"status": 0,
579
+	}).Error
580
+
581
+	return
582
+}
583
+
584
+//更改退款申请
585
+func ChangeRefund(orgid, his_patient_id, trial_status, id int64, code string, deposit decimal.Decimal) (err error) {
586
+	//开事务
587
+	tx := XTWriteDB().Begin()
588
+	defer func() {
589
+		if err != nil {
590
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
591
+			tx.Rollback()
592
+		} else {
593
+			tx.Commit()
594
+		}
595
+	}()
596
+	//获取患者当前余额
597
+	tmp := models.Deposit{}
598
+	err = tx.Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", his_patient_id, orgid).Find(&tmp).Error
599
+	if err != nil {
600
+		return
601
+	}
602
+	//判断是否可以退款
603
+	if tmp.Deposit.Cmp(deposit) == -1 {
604
+		err = fmt.Errorf("退款金额不得大于押金余额!")
605
+		return
606
+	}
607
+	up := make(map[string]interface{})
608
+	//判断是否审核通过,通过更新当前押金,否则只新增一条历史记录
609
+	if trial_status == 1 {
610
+		//更新患者当前押金余额
611
+		err = tx.Model(&models.Deposit{}).Where("id = ? and status = 1", tmp.ID).Updates(map[string]interface{}{
612
+			"mtime":   time.Now().Unix(),
613
+			"deposit": tmp.Deposit.Sub(deposit),
614
+		}).Error
615
+		if err != nil {
299 616
 			return
300 617
 		}
618
+		up = map[string]interface{}{
619
+			"mtime":           time.Now().Unix(),
620
+			"deposit_code":    code,
621
+			"his_patient_id":  his_patient_id,
622
+			"surplus_deposit": tmp.Deposit.Sub(deposit),
623
+			"deposit":         deposit,
624
+			"trial_status":    trial_status,
625
+		}
626
+	} else {
627
+		up = map[string]interface{}{
628
+			"mtime":          time.Now().Unix(),
629
+			"deposit_code":   code,
630
+			"his_patient_id": his_patient_id,
631
+			"deposit":        deposit,
632
+			"trial_status":   trial_status,
633
+		}
634
+	}
635
+	//更新一条历史记录
636
+	err = tx.Model(&models.DepositHistory{}).Where("id = ? and status = 1", id).Updates(up).Error
637
+	return
638
+}
639
+
640
+//退款分页
641
+func RefundList(orgid, stime, etime, refundtype, examinetype int64, keyword string, slicekey []int64) (depo []models.RefundList, err error) {
642
+	db := XTReadDB().Model(&models.DepositHistory{}).Where("status = 1 and user_org_id = ? ", orgid).Where("ctime >= ? and ctime <= ?", stime, etime)
643
+	//退款类型
644
+	switch refundtype {
645
+	case 0:
646
+		db = db.Where(" deposit_status in (3,4) ")
647
+	case 3, 4:
648
+		db = db.Where(" deposit_status = ? ", refundtype)
649
+	default:
650
+		err = fmt.Errorf("退款类型错误")
651
+		return
652
+	}
653
+	//审核状态
654
+	switch examinetype {
655
+	case 0, 1, 2:
656
+		db = db.Where(" trial_status = ? ", examinetype)
657
+	case 3: //代表查询全部
658
+		db = db
659
+	default:
660
+		err = fmt.Errorf("审核状态错误")
661
+		return
662
+	}
663
+	if len(keyword) > 0 {
664
+		tmp := "deposit_code like ? "
665
+		if len(slicekey) > 0 {
666
+			for i := 0; i < len(slicekey); i++ {
667
+				tmp = tmp + " or his_patient_id = " + strconv.FormatInt(slicekey[i], 10)
668
+			}
669
+		}
670
+		keyword = "%" + keyword + "%"
671
+		db = db.Where(tmp, keyword)
672
+	}
673
+	err = db.Order("ctime desc").Find(&depo).Error
674
+	return
675
+
676
+}
677
+
678
+//退回患者的押金,并生成一条退费历史记录
679
+//orgid 机构id
680
+//his_user_id 患者id
681
+//code 编号
682
+//deposit 本次退费的金额,支持float64、int、int64、decimal.Decimal类型
683
+func MoneyIncrease(orgid, his_user_id int64, code string, deposit interface{}) (err error) {
684
+	tmp_deposit := decimal.Decimal{}
685
+	tmp_deposit, err = ToDecimal(deposit)
686
+	if err != nil {
687
+		return
688
+	}
689
+	//开事务
690
+	tx := XTWriteDB().Begin()
691
+	defer func() {
692
+		if err != nil {
693
+			utils.ErrorLog("事务失败,原因为: %v", err.Error())
694
+			tx.Rollback()
695
+		} else {
696
+			tx.Commit()
697
+		}
698
+	}()
699
+	//获取当前患者押金
700
+	tmp := models.Deposit{}
701
+	err = tx.Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", his_user_id, orgid).Find(&tmp).Error
702
+	if err != nil {
703
+		return
704
+	}
705
+	//退回患者押金
706
+	err = tx.Model(&models.Deposit{}).Where("id = ? and status = 1", tmp.ID).Updates(map[string]interface{}{
707
+		"mtime":   time.Now().Unix(),
708
+		"deposit": tmp.Deposit.Add(tmp_deposit),
709
+	}).Error
710
+	if err != nil {
711
+		return
712
+	}
713
+	//生成一条退费记录
714
+	dehistory := models.DepositHistory{
715
+		UserOrgId:      orgid,
716
+		HisPatientId:   his_user_id,
717
+		DepositCode:    code,
718
+		Deposit:        tmp_deposit,
719
+		SurplusDeposit: tmp.Deposit.Add(tmp_deposit),
720
+		DepositStatus:  4,
721
+		Status:         1,
722
+		CreateId:       0,
723
+		Ctime:          time.Now().Unix(),
724
+		Mtime:          time.Now().Unix(),
725
+		TrialStatus:    1,
726
+	}
727
+	err = tx.Create(&dehistory).Error
728
+	return
729
+}
730
+func GetorgName(orgid int64) (name string) {
731
+	tmp := models.GetorgName{}
732
+	XTReadDB().Model(&models.GetorgName{}).Where("id = ? ", orgid).Find(&tmp)
733
+	return tmp.OrgName
734
+}
735
+
736
+//根据id查询就诊号
737
+func FindcodeToid(id int64) (code string) {
738
+	tmp := models.GetMdtrtId{}
739
+	XTReadDB().Model(&models.GetMdtrtId{}).Where("id = ?", id).Find(&tmp)
740
+	return tmp.MdtrtId
741
+}
742
+
743
+//根据id查询就诊号
744
+func FindnumberToid(id int64) (number string) {
745
+	tmp := models.GetMdtrtId{}
746
+	XTReadDB().Model(&models.GetMdtrtId{}).Where("id = ?", id).Find(&tmp)
747
+	return tmp.Number
748
+}
749
+
750
+//把其他的类型转换成decimal.Decimal类型
751
+func ToDecimal(i interface{}) (d decimal.Decimal, err error) {
752
+	switch i.(type) {
753
+	case float64:
754
+		d = decimal.NewFromFloat(i.(float64))
755
+	case decimal.Decimal:
756
+		d = i.(decimal.Decimal)
757
+	case int64:
758
+		d = decimal.NewFromFloat(float64(i.(int64)))
759
+	case int:
760
+		d = decimal.NewFromFloat(float64(i.(int)))
761
+	default:
762
+		err = fmt.Errorf("类型解析错误")
301 763
 	}
302
-	err = db.Count(&total).Offset(offset).Order("mtime desc").Find(&m).Error
303 764
 	return
304 765
 }

+ 5 - 0
service/his_project_service.go Vedi File

@@ -748,6 +748,11 @@ func GetHisPatientByIdThree(id int64) (models.HisPatient, error) {
748 748
 	err := XTReadDB().Model(&patient).Where("id = ? and status = 1", id).First(&patient).Error
749 749
 	return patient, err
750 750
 }
751
+func GetHisPatientByIdThreeTX(id int64, tx *gorm.DB) (models.HisPatient, error) {
752
+	patient := models.HisPatient{}
753
+	err := tx.Model(&patient).Where("id = ? and status = 1", id).First(&patient).Error
754
+	return patient, err
755
+}
751 756
 
752 757
 func GetLastHisPatient(patient_id int64, org_id int64) (his models.HisPatient, err error) {
753 758
 	err = XTReadDB().Model(&models.HisPatient{}).Where("user_org_id = ? AND patient_id = ? and status = 1 AND patient_info <> ''", org_id, patient_id).First(&his).Error

+ 77 - 1
service/his_service.go Vedi File

@@ -514,6 +514,21 @@ func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int
514 514
 		Find(&prescription).Error
515 515
 	return
516 516
 }
517
+func GetSettleHisPrescriptionTX(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
518
+	err = tx.Model(&models.HisPrescription{}).
519
+		Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
520
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
521
+		}).
522
+		Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
523
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
524
+		}).
525
+		Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
526
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
527
+		}).
528
+		Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
529
+		Find(&prescription).Error
530
+	return
531
+}
517 532
 
518 533
 func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
519 534
 	err = readDb.Model(&models.HisPrescription{}).
@@ -530,6 +545,21 @@ func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, e
530 545
 		Find(&prescription).Error
531 546
 	return
532 547
 }
548
+func GetMonthHisPrescriptionTX(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
549
+	err = tx.Model(&models.HisPrescription{}).
550
+		Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
551
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
552
+		}).
553
+		Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
554
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
555
+		}).
556
+		Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
557
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
558
+		}).
559
+		Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
560
+		Find(&prescription).Error
561
+	return
562
+}
533 563
 
534 564
 func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
535 565
 	err = readDb.Model(&models.HisPrescription{}).
@@ -842,11 +872,19 @@ func CreateOrder(order *models.HisOrder) (err error) {
842 872
 	err = writeDb.Create(&order).Error
843 873
 	return
844 874
 }
875
+func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
876
+	err = tx.Create(&order).Error
877
+	return
878
+}
845 879
 
846 880
 func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
847 881
 	err = writeDb.Create(&order).Error
848 882
 	return
849 883
 }
884
+func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
885
+	err = tx.Create(&order).Error
886
+	return
887
+}
850 888
 
851 889
 func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
852 890
 	err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
@@ -956,6 +994,10 @@ func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (er
956 994
 	err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
957 995
 	return
958 996
 }
997
+func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
998
+	err = tx.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
999
+	return
1000
+}
959 1001
 
960 1002
 func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
961 1003
 	err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
@@ -973,6 +1015,11 @@ func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string,
973 1015
 
974 1016
 	return
975 1017
 }
1018
+func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
1019
+	err = tx.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
1020
+
1021
+	return
1022
+}
976 1023
 
977 1024
 func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
978 1025
 	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1  AND record_date <= ? AND record_date >= ? ", user_org_id, end_time, start_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
@@ -1198,6 +1245,11 @@ func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
1198 1245
 	err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
1199 1246
 	return
1200 1247
 }
1248
+func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
1249
+	err = tx.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
1250
+	err = tx.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
1251
+	return
1252
+}
1201 1253
 
1202 1254
 func CreateErrMsgLog(log *models.HisOrderError) {
1203 1255
 	writeDb.Model(&models.HisOrderError{}).Create(&log)
@@ -1428,6 +1480,10 @@ func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
1428 1480
 	err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
1429 1481
 	return
1430 1482
 }
1483
+func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
1484
+	err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
1485
+	return
1486
+}
1431 1487
 
1432 1488
 func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
1433 1489
 	err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
@@ -2233,7 +2289,9 @@ func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_num
2233 2289
 
2234 2290
 func UpdataHisPateint(his *models.HisPatient) {
2235 2291
 	writeDb.Save(&his)
2236
-
2292
+}
2293
+func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
2294
+	tx.Save(&his)
2237 2295
 }
2238 2296
 
2239 2297
 func SaveHisOrder(his *models.HisOrder) (err error) {
@@ -2259,6 +2317,24 @@ func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.Hi
2259 2317
 
2260 2318
 	return
2261 2319
 }
2320
+func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
2321
+	err = tx.Model(&models.HisPrescription{}).
2322
+		Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
2323
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
2324
+		}).
2325
+		Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
2326
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
2327
+		}).
2328
+		Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
2329
+			return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
2330
+		}).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
2331
+		return tx.Where("status = 1 AND user_org_id = ?", org_id)
2332
+	}).
2333
+		Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
2334
+		Find(&prescription).Error
2335
+
2336
+	return
2337
+}
2262 2338
 
2263 2339
 func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
2264 2340
 	db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)

+ 1 - 0
service/mobile_dialysis_service.go Vedi File

@@ -2630,6 +2630,7 @@ type VMGoodInfo struct {
2630 2630
 	GoodName          string  `gorm:"column:good_name" json:"good_name" form:"good_name"`
2631 2631
 	GoodUnit          int64   `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
2632 2632
 	Total             float64 `gorm:"column:total" json:"total" form:"total"`
2633
+	PackingUnit       string  `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
2633 2634
 }
2634 2635
 
2635 2636
 func (VMGoodInfo) TableName() string {