|
|
@@ -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"`
|
|
|
}
|