Browse Source

提交代码

陈少旭 7 months ago
parent
commit
2698d25d0f
2 changed files with 69 additions and 0 deletions
  1. 15 0
      models/his_charge_models.go
  2. 54 0
      service/his_deposit_service.go

+ 15 - 0
models/his_charge_models.go View File

@@ -94,6 +94,17 @@ func (SettlePatient) TableName() string {
94 94
 	return "xt_patients"
95 95
 }
96 96
 
97
+type OrderHisPatient struct {
98
+	ID        int64  `gorm:"column:id" json:"id" form:"id"`
99
+	PatientId int64  `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
100
+	Number    string `gorm:"column:number" json:"number" form:"number"`
101
+	SickType  int64  `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
102
+}
103
+
104
+func (OrderHisPatient) TableName() string {
105
+	return "his_patient"
106
+}
107
+
97 108
 type HisChargeOrder struct {
98 109
 	ID                 int64   `gorm:"column:id" json:"id" form:"id"`
99 110
 	UserOrgId          int64   `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
@@ -196,6 +207,10 @@ type HisChargeSettleOrder struct {
196 207
 	IsUploadDiagnose  int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
197 208
 	IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
198 209
 	IsUploadSuccess   int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
210
+
211
+	SickName string `gorm:"sick_name" json:"sick_name" form:"sick_name"`
212
+
213
+	//OrderHisPatient OrderHisPatient `gorm:"ForeignKey:Number;AssociationForeignKey:MdtrtId" json:"his"`
199 214
 }
200 215
 
201 216
 func (HisChargeSettleOrder) TableName() string {

+ 54 - 0
service/his_deposit_service.go View File

@@ -445,6 +445,60 @@ func SpendDeposit(orgid, his_user_id, create_id int64, code string, deposit inte
445 445
 	return
446 446
 }
447 447
 
448
+func SpendDepositTwo(orgid, his_user_id, create_id int64, code string, deposit interface{}, ctime int64) (err error) {
449
+	tmp_deposit := decimal.Decimal{} //本次患者使用的押金
450
+	tmp_deposit, err = ToDecimal(deposit)
451
+	if err != nil {
452
+		return
453
+	}
454
+	////开事务
455
+	//tx := XTWriteDB().Begin()
456
+	//defer func() {
457
+	//	if err != nil {
458
+	//		utils.ErrorLog("事务失败,原因为: %v", err.Error())
459
+	//		tx.Rollback()
460
+	//	} else {
461
+	//		tx.Commit()
462
+	//	}
463
+	//}()
464
+	//查询患者押金
465
+	tmp := models.Deposit{}
466
+	err = readDb.Model(&models.Deposit{}).Where("his_patient_id = ? and user_org_id = ? and status = 1", his_user_id, orgid).Find(&tmp).Error
467
+	if err != nil {
468
+		err = fmt.Errorf("押金余额不足")
469
+		return
470
+	}
471
+	//判断能否扣除
472
+	if tmp.Deposit.Cmp(tmp_deposit) == -1 {
473
+		err = fmt.Errorf("押金余额不足")
474
+		return
475
+	}
476
+	//扣除患者押金
477
+	err = readDb.Model(&models.Deposit{}).Where("id = ? and status = 1", tmp.ID).Updates(map[string]interface{}{
478
+		"mtime":   time.Now().Unix(),
479
+		"deposit": tmp.Deposit.Sub(tmp_deposit),
480
+	}).Error
481
+	if err != nil {
482
+		return
483
+	}
484
+	//生成一条历史记录
485
+	dehistory := models.DepositHistory{
486
+		UserOrgId:      orgid,
487
+		HisPatientId:   his_user_id,
488
+		DepositCode:    code,
489
+		Deposit:        tmp_deposit,
490
+		SurplusDeposit: tmp.Deposit.Sub(tmp_deposit),
491
+		DepositStatus:  2,
492
+		Status:         1,
493
+		CreateId:       create_id,
494
+		Ctime:          ctime,
495
+		Mtime:          time.Now().Unix(),
496
+		TrialStatus:    1,
497
+	}
498
+	err = readDb.Create(&dehistory).Error
499
+	return
500
+}
501
+
448 502
 // 新增一条退款申请
449 503
 func RefundApplication(orgid, his_patient_id, trial_status, createid int64, code string, deposit decimal.Decimal) (err error) {
450 504
 	//开事务