|
@@ -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
|
//开事务
|