|
|
@@ -156,6 +156,7 @@ func (s Service) Cancel(req accountModel.AccountMainCancelReq, user request.User
|
|
|
var rules []Param
|
|
|
now := gtime.Now()
|
|
|
per := float64(0)
|
|
|
+ userNumber := 0
|
|
|
|
|
|
one, err := s.Dao.M.Where(fmt.Sprintf("AppointId='%v'", req.AppointId)).FindOne()
|
|
|
if err != nil {
|
|
|
@@ -170,7 +171,7 @@ func (s Service) Cancel(req accountModel.AccountMainCancelReq, user request.User
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- all, err := s.Dao.DB.Model("settle_account_detail").Where(fmt.Sprintf("pid='%v'", main.Id)).FindAll()
|
|
|
+ all, err := s.Dao.DB.Model("settle_account_detail").Where(fmt.Sprintf("pid='%v' AND PaymentType='0'", main.Id)).FindAll()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -187,6 +188,18 @@ func (s Service) Cancel(req accountModel.AccountMainCancelReq, user request.User
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
+ // 计算当前机器占用数量
|
|
|
+ userNumber, err = s.Dao.DB.Model("appointment").Where(fmt.Sprintf("RelevanceId='%v' AND SignInTime IS NOT NULL AND SignOutTime IS NULL", main.InstrumentId)).Count()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ var detail accountModel.SettleAccountDetail
|
|
|
+ detail.PaymentType = "1"
|
|
|
+ detail.PaymentAccount = 0
|
|
|
+ detail.Data1 = main.AppointStartDate.Format("Y-m-d H:m:s")
|
|
|
+ detail.Data2 = main.AppointEndDate.Format("Y-m-d H:m:s")
|
|
|
+ detail.Data3 = now.Format("Y-m-d H:m:s") // 取消时间
|
|
|
|
|
|
mins := now.Sub(main.AppointStartDate).Minutes()
|
|
|
if mins > 0 { // 正向超时,计算违约收费
|
|
|
@@ -199,42 +212,49 @@ func (s Service) Cancel(req accountModel.AccountMainCancelReq, user request.User
|
|
|
r += rule.Code + "分钟内" + rule.Value + "%"
|
|
|
}
|
|
|
}
|
|
|
- main.TotalPrice *= per
|
|
|
- main.ActualMachineHour = 0
|
|
|
- for index := range details {
|
|
|
- details[index].PaymentAccount = 0 // 取消,计费为0
|
|
|
- }
|
|
|
- if main.TotalPrice > 0 {
|
|
|
- var detail accountModel.SettleAccountDetail
|
|
|
- detail.PaymentType = "1"
|
|
|
- detail.PaymentAccount = main.TotalPrice
|
|
|
- detail.Data1 = main.AppointStartDate.Format("Y-m-d H:m:s")
|
|
|
- detail.Data2 = main.AppointEndDate.Format("Y-m-d H:m:s")
|
|
|
- detail.Data3 = now.Format("Y-m-d H:m:s")
|
|
|
- detail.Data4 = r
|
|
|
- details = append(details, detail)
|
|
|
- }
|
|
|
- tx, err := s.Dao.DB.Begin()
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
|
|
|
- _, err = tx.Save("settle_account_main", main)
|
|
|
- if err != nil {
|
|
|
- tx.Rollback()
|
|
|
- return err
|
|
|
- }
|
|
|
+ detail.Data4 = r // 扣费规则
|
|
|
+ } else {
|
|
|
+ detail.Data4 = "已开始之后取消,100%" // 扣费规则
|
|
|
+ per = 1
|
|
|
+ }
|
|
|
|
|
|
- _, err = tx.Save("settle_account_detail", details)
|
|
|
- if err != nil {
|
|
|
- tx.Rollback()
|
|
|
- return err
|
|
|
- }
|
|
|
+ if userNumber > 0 { // 机器被占用,机器被占用,取消不扣费
|
|
|
+ detail.Data4 = "机器被占用,取消不扣费"
|
|
|
+ per = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ main.ActualMachineHour = 0
|
|
|
+ for _, item := range details {
|
|
|
+ detail.PaymentAccount += item.PaymentAccount * per
|
|
|
+ }
|
|
|
|
|
|
- return tx.Commit()
|
|
|
+ main.TotalPrice = detail.PaymentAccount
|
|
|
+
|
|
|
+ tx, err := s.Dao.DB.Begin()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ // 更新账单明细信息
|
|
|
+ _, err = tx.Save("settle_account_main", main)
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ // 计费明细费用设置为0
|
|
|
+ _, err = tx.Update("settle_account_detail", "PaymentAccount=0", fmt.Sprintf("pid='%v'", main.Id))
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ // 新增违约计费
|
|
|
+ _, err = tx.Save("settle_account_detail", detail)
|
|
|
+ if err != nil {
|
|
|
+ tx.Rollback()
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
- return nil
|
|
|
+ return tx.Commit()
|
|
|
}
|
|
|
|
|
|
type Param struct {
|