Selaa lähdekoodia

fix(账单): 实际上机时间通过预约表的签入签出时间确定

likai 4 vuotta sitten
vanhempi
commit
5942f31781

+ 7 - 0
model/account/settle_account_main.go

@@ -5,6 +5,7 @@
 package model
 
 import (
+	"github.com/gogf/gf/os/gtime"
 	internal2 "lims_adapter/model/account/internal"
 )
 
@@ -51,4 +52,10 @@ type AccountMainAddReq struct {
 type AccountMainCancelReq struct {
 	AppointId  int     `json:"appointId"`
 	IsAuto     string  `json:"is_auto"`
+}
+
+type MainInfo struct {
+	SettleAccountMain
+	SignInTime         *gtime.Time `orm:"SignInTime"         json:"sign_in_time"`         // 签到时间
+	SignOutTime        *gtime.Time `orm:"SignOutTime"        json:"sign_out_time"`        // 签退时间
 }

+ 33 - 2
service/settle_account_main/settle_account_main.go

@@ -27,7 +27,7 @@ func NewService(tenant string) Service {
 }
 
 // List 结算明细
-func (s Service) List(req model.ListReq, user request.UserInfo) ([]accountModel.SettleAccountMain, int, error) {
+func (s Service) List(req model.ListReq, user request.UserInfo) ([]accountModel.MainInfo, int, error) {
 	entityModel := s.Dao.M
 	where := "1=1"
 
@@ -122,12 +122,41 @@ func (s Service) List(req model.ListReq, user request.UserInfo) ([]accountModel.
 		return nil, 0, nil
 	}
 
-	list := make([]accountModel.SettleAccountMain, 0)
+	list := make([]accountModel.MainInfo, 0)
 	err = res.Structs(&list)
 	if err != nil {
 		return nil, 0, err
 	}
 
+	var appoints []accountModel.SearchEntity
+	appointMap := make(map[int]accountModel.SearchEntity, 0)
+
+	ids := "-1"
+	for _, item := range list {
+		ids += fmt.Sprintf(",%v", item.AppointId)
+	}
+	res, err = s.Dao.DB.Model("appointment").Where(fmt.Sprintf("Id IN (%v)", ids)).FindAll()
+	if err != nil {
+		return nil, 0, err
+	}
+	err = res.Structs(&appoints)
+	if err != nil {
+		if err == sql.ErrNoRows {
+			return list, total, nil
+		}
+		return list, total, err
+	}
+	for _, item := range appoints {
+		appointMap[item.Id] = item
+	}
+
+	for index, item := range list {
+		if appointMap[item.AppointId].Id != 0 {
+			list[index].SignInTime = appointMap[item.AppointId].SignInTime
+			list[index].SignOutTime = appointMap[item.AppointId].SignOutTime
+		}
+	}
+
 	return list, total, nil
 }
 
@@ -334,6 +363,8 @@ func (s Service) Cancel(req accountModel.AccountMainCancelReq) error {
 	oldAmount := main.TotalPrice
 	main.TotalPrice = detail.PaymentAccount
 	diffValue := oldAmount - detail.PaymentAccount
+	main.ActualStartDate = nil
+	main.ActualEndDate = nil
 
 	baseAccount.Available += diffValue // 账户可用金额返还