Преглед на файлове

fix: 当班中实时统计现金收款——GetCurrent动态查询而非仅读字段

lq преди 1 месец
родител
ревизия
5ae9c4dff2
променени са 1 файла, в които са добавени 10 реда и са изтрити 1 реда
  1. 10 1
      internal/modules/shift/service/service.go

+ 10 - 1
internal/modules/shift/service/service.go

@@ -61,7 +61,16 @@ func (s *ShiftService) End(operatorID uint, actualCash float64, remark string) (
 }
 
 func (s *ShiftService) GetCurrent(operatorID uint) (*dao.ShiftRecord, error) {
-	return s.repo.GetActive(operatorID)
+	rec, err := s.repo.GetActive(operatorID)
+	if err != nil {
+		return nil, err
+	}
+	// 实时统计当班现金收款
+	var collected float64
+	global.GVA_DB.Raw("SELECT COALESCE(SUM(amount),0) FROM payment_record WHERE payment_method='cash' AND operator_id = ? AND paid_at >= ?",
+		operatorID, rec.StartTime).Scan(&collected)
+	rec.CollectedCash = collected
+	return rec, nil
 }
 
 func (s *ShiftService) List(q repository.ShiftListQuery, operatorID uint) ([]repository.ShiftListItem, int64, error) {