浏览代码

feature(设备附加费): 取消违约费用接口

likai 4 年之前
父节点
当前提交
ec61e24b07

+ 23 - 0
handler/settle_account_main.go

@@ -78,6 +78,29 @@ func (a *SettleAccountMainController) ConfirmAccountMain(ctx context.Context, re
 		return err
 	}
 
+	rsp.Code = code
+	rsp.Msg = msg
+	return nil
+}
+
+// 结算明细(未出账单)取消
+func (a *SettleAccountMainController) CancelAccountMain(ctx context.Context, req *accountModel.AccountMainCancelReq, rsp *comm_def.CommonMsg) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return err
+	}
+	user, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return err
+	}
+	g.Log().Info("Received SettleAccountMainController.CancelAccountMain request @ " + tenant)
+
+	var errors = service.NewService(tenant).Cancel(*req, user)
+	_, err, code, msg := myerrors.CheckError(errors)
+	if err != nil {
+		return err
+	}
+
 	rsp.Code = code
 	rsp.Msg = msg
 	return nil

+ 4 - 0
model/account/settle_account_main.go

@@ -35,4 +35,8 @@ type AccountMainConfirmReq struct {
 type AccountMainAddReq struct {
 	Main  SettleAccountMain  `json:"main"`
 	Details  []SettleAccountDetail  `json:"details"`
+}
+
+type AccountMainCancelReq struct {
+	AppointId  int `json:"appointId"`
 }

+ 108 - 0
service/settle_account_main/settle_account_main.go

@@ -9,6 +9,7 @@ import (
 	"lims_adapter/dao/account"
 	"lims_adapter/model"
 	accountModel "lims_adapter/model/account"
+	"strconv"
 )
 
 // Service 会议室服务
@@ -143,4 +144,111 @@ func (s Service) Confirm(req accountModel.AccountMainConfirmReq, user request.Us
 
 	_, err := s.Dao.M.Update(fmt.Sprintf("SettleStatus='1',SettleUserId='%v',SettleUser='%v',SettleDate='%v'", user.Id, user.RealName, gtime.Now()), fmt.Sprintf("Id='%v'", req.MainId))
 	return err
+}
+
+// 预约取消
+func (s Service) Cancel(req accountModel.AccountMainCancelReq, user request.UserInfo) error {
+	if req.AppointId == 0 {
+		return errors.New("参数缺失")
+	}
+	var main accountModel.SettleAccountMain
+	var details []accountModel.SettleAccountDetail
+	var rules []Param
+	now := gtime.Now()
+	per := float64(0)
+
+	one, err := s.Dao.M.Where(fmt.Sprintf("AppointId='%v'", req.AppointId)).FindOne()
+	if err != nil {
+		return err
+	}
+	err = one.Struct(&main)
+	if err != nil {
+		return err
+	}
+
+	if main.Id == 0 { // 该预约未生成账单
+		return nil
+	}
+
+	all, err := s.Dao.DB.Model("settle_account_detail").Where(fmt.Sprintf("pid='%v'", main.Id)).FindAll()
+	if err != nil {
+		return err
+	}
+	err = all.Structs(&details)
+	if err != nil {
+		return err
+	}
+
+	all, err = s.Dao.DB.Model("base_param").Where("Name LIKE '违约计费规则%'").Order("Code ASC").FindAll()
+	if err != nil {
+		return err
+	}
+	err = all.Structs(&rules)
+	if err != nil {
+		return err
+	}
+
+	mins := now.Sub(main.AppointStartDate).Minutes()
+	if mins > 0 { // 正向超时,计算违约收费
+		r := ""
+		for _, rule := range rules {
+			value1, _ := strconv.ParseFloat(rule.Code, 64)
+			if mins < value1 {
+				per, _ := strconv.ParseFloat(rule.Value, 64)
+				per /= 100
+				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
+		}
+
+		_, err = tx.Save("settle_account_detail", details)
+		if err != nil {
+			tx.Rollback()
+			return err
+		}
+
+		return  tx.Commit()
+	}
+
+	return nil
+}
+
+type Param struct {
+	Id             int32  `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
+	Code           string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"`
+	Name           string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
+	Value          string `protobuf:"bytes,4,opt,name=value,proto3" json:"value,omitempty"`
+	Sys            string `protobuf:"bytes,5,opt,name=sys,proto3" json:"sys"`
+	SortCode       int32  `protobuf:"varint,6,opt,name=sort_code,json=sortCode,proto3" json:"sort_code"`
+	Description    string `protobuf:"bytes,7,opt,name=description,proto3" json:"description,omitempty"`
+	CreateOn       string `protobuf:"bytes,8,opt,name=create_on,json=createOn,proto3" json:"create_on,omitempty"`
+	CreateUserId   int32  `protobuf:"varint,9,opt,name=create_user_id,json=createUserId,proto3" json:"create_user_id,omitempty"`
+	CreateBy       string `protobuf:"bytes,10,opt,name=create_by,json=createBy,proto3" json:"create_by,omitempty"`
+	ModifiedOn     string `protobuf:"bytes,11,opt,name=modified_on,json=modifiedOn,proto3" json:"modified_on,omitempty"`
+	ModifiedUserId int32  `protobuf:"varint,12,opt,name=modified_user_id,json=modifiedUserId,proto3" json:"modified_user_id,omitempty"`
+	ModifiedBy     string `protobuf:"bytes,13,opt,name=modified_by,json=modifiedBy,proto3" json:"modified_by,omitempty"`
 }