|
|
@@ -119,25 +119,40 @@ class ExpenseClaimsService extends Service
|
|
|
return [array_keys($oldFilesMap), $new];
|
|
|
}
|
|
|
|
|
|
- private function expenseClaimsRule(&$data, $user){
|
|
|
+ private function expenseClaimsRule(&$data, $user, $is_add = true){
|
|
|
$data['top_depart_id'] = $user['top_depart_id'];
|
|
|
if(!isset($data['month'])) return [false,"月份必传"];
|
|
|
$monthStr = $data['month']; // 假设是 "2026-03"
|
|
|
$monthStart = strtotime($monthStr); // 2026-03-01 00:00:00
|
|
|
// 获取该月最后一秒:下个月 1 号减去 1 秒
|
|
|
$monthEnd = strtotime("$monthStr +1 month") - 1;
|
|
|
+ if(empty($data['details'])) return [false, '项目费用报销单详情不能为空'];
|
|
|
foreach ($data['details'] as $index => $item) {
|
|
|
- if (!isset($item['claim_date'])) {
|
|
|
- return [false, "第" . ($index + 1) . "项报销日期缺失"];
|
|
|
- }
|
|
|
+ if(empty($item['item_id'])) return [false, "第" . ($index + 1) . "项目不能为空"];
|
|
|
+ if(empty($item['fee_id'])) return [false, "第" . ($index + 1) . "费用类型不能为空"];
|
|
|
+ if(! isset($item['amount'])) return [false, "第" . ($index + 1) . "费用金额不存在"];
|
|
|
+ $res = $this->checkNumber($item['amount'], 2, 'non-negative');
|
|
|
+ if (! $res['valid']) return [false, "第" . ($index + 1) . "费用金额" . $res['error']];
|
|
|
+
|
|
|
+ if (!isset($item['claim_date'])) return [false, "第" . ($index + 1) . "项报销日期缺失"];
|
|
|
// 将报销日期转换为时间戳
|
|
|
$claimTime = strtotime($item['claim_date']);
|
|
|
// 判断:claim_date 必须早于 month
|
|
|
// 如果 claim_date 是 2026-02-28,而 month 是 2026-03-01,则校验通过
|
|
|
- if ($claimTime < $monthStart || $claimTime > $monthEnd) {
|
|
|
- return [false, "第" . ($index + 1) . "项报销日期必须在当前月份内(" . $data['month'] . ")"];
|
|
|
- }
|
|
|
+ if ($claimTime < $monthStart || $claimTime > $monthEnd) return [false, "第" . ($index + 1) . "项报销日期必须在当前月份内(" . $data['month'] . ")"];
|
|
|
+ }
|
|
|
+
|
|
|
+ $query = ExpenseClaims::where('top_depart_id', $data['top_depart_id'])
|
|
|
+ ->where('month', $monthStart)
|
|
|
+ ->where('del_time', 0);
|
|
|
+
|
|
|
+ if (!$is_add) {
|
|
|
+ if (empty($data['id'])) return [false, 'ID不能为空'];
|
|
|
+ $query->where('id', '<>', $data['id']);
|
|
|
}
|
|
|
+
|
|
|
+ if ($query->exists()) return [false, date("Y-m", $monthStart) . '已存在项目费用报销单'];
|
|
|
+
|
|
|
return [true,""];
|
|
|
}
|
|
|
|