|
|
@@ -122,13 +122,22 @@ class PersonWorkService extends Service
|
|
|
return $detail;
|
|
|
}
|
|
|
|
|
|
- public function monthlyPwOrderDel($data){
|
|
|
+ public function monthlyPwOrderDel($data, $user){
|
|
|
if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
$time = time();
|
|
|
|
|
|
+ $month = MonthlyPwOrder::where('del_time',0)
|
|
|
+ ->whereIn('id',$data['id'])
|
|
|
+ ->pluck('month')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ //归档
|
|
|
+ list($status, $msg) = ArchiveService::isArchive($month, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
MonthlyPwOrder::where('del_time',0)
|
|
|
->whereIn('id',$data['id'])
|
|
|
->update(['del_time' => $time]);
|
|
|
@@ -201,6 +210,10 @@ class PersonWorkService extends Service
|
|
|
$data['month'] = $this->changeDateToDate($data['month']);
|
|
|
$data['top_depart_id'] = $user['top_depart_id'];
|
|
|
|
|
|
+ //归档
|
|
|
+ list($status, $msg) = ArchiveService::isArchive($data['month'], $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
if (empty($data['details'])) return [false, '人员月度工时单明细不能为空'];
|
|
|
|
|
|
//获取系统计算的考勤基准数据 ---
|
|
|
@@ -266,46 +279,6 @@ class PersonWorkService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function monthlyPwOrderRule1(&$data, $user, $is_add = true){
|
|
|
- if(empty($data['month'])) return [false, '月份不能为空'];
|
|
|
- $data['month'] = $this->changeDateToDate($data['month']);
|
|
|
-
|
|
|
- $data['top_depart_id'] = $user['top_depart_id'];
|
|
|
- if(empty($data['details'])) return [false, '人员月度工时单明细不能为空'];
|
|
|
- foreach ($data['details'] as $key => $value){
|
|
|
- if(empty($value['employee_id'])) return [false, '人员不能为空'];
|
|
|
- $res = $this->checkNumber($value['total_days'],0,'non-negative');
|
|
|
- if(! $res['valid']) return [false,'出勤总天数:' . $res['error']];
|
|
|
- $res = $this->checkNumber($value['rd_total_days'],0,'non-negative');
|
|
|
- if(! $res['valid']) return [false,'研发出勤总天数:' . $res['error']];
|
|
|
- $res = $this->checkNumber($value['total_hours'],2,'non-negative');
|
|
|
- if(! $res['valid']) return [false,'出勤总工时:' . $res['error']];
|
|
|
- $res = $this->checkNumber($value['rd_total_hours'],2,'non-negative');
|
|
|
- if(! $res['valid']) return [false,'研发总工时:' . $res['error']];
|
|
|
-
|
|
|
- $data['details'][$key]['top_depart_id'] = $data['top_depart_id'];
|
|
|
- }
|
|
|
- list($status, $msg) = $this->checkArrayRepeat($data['details'],'employee_id','人员');
|
|
|
- if(! $status) return [false, $msg];
|
|
|
-
|
|
|
- if($is_add){
|
|
|
- $bool = MonthlyPwOrder::where('top_depart_id', $data['top_depart_id'])
|
|
|
- ->where('month', $data['month'])
|
|
|
- ->where('del_time',0)
|
|
|
- ->exists();
|
|
|
- }else{
|
|
|
- if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
- $bool = MonthlyPwOrder::where('top_depart_id', $data['top_depart_id'])
|
|
|
- ->where('month', $data['month'])
|
|
|
- ->where('id','<>',$data['id'])
|
|
|
- ->where('del_time',0)
|
|
|
- ->exists();
|
|
|
- }
|
|
|
- if($bool) return [false, date("Y-m", $data['month']) . '已存在人员月度研发工时单'];
|
|
|
-
|
|
|
- return [true, ''];
|
|
|
- }
|
|
|
-
|
|
|
public function fillData($data){
|
|
|
if(empty($data['data'])) return $data;
|
|
|
|
|
|
@@ -498,13 +471,22 @@ class PersonWorkService extends Service
|
|
|
return $detail;
|
|
|
}
|
|
|
|
|
|
- public function dailyPwOrderDel($data){
|
|
|
+ public function dailyPwOrderDel($data, $user){
|
|
|
if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
|
|
|
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
$time = time();
|
|
|
|
|
|
+ $month = DailyPwOrder::where('del_time',0)
|
|
|
+ ->whereIn('id',$data['id'])
|
|
|
+ ->pluck('order_time')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ //归档
|
|
|
+ list($status, $msg) = ArchiveService::isArchive($month, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
DailyPwOrder::where('del_time',0)
|
|
|
->whereIn('id',$data['id'])
|
|
|
->update(['del_time' => $time]);
|
|
|
@@ -583,16 +565,20 @@ class PersonWorkService extends Service
|
|
|
}
|
|
|
|
|
|
public function dailyPwOrderRule(&$data, $user, $is_add = true){
|
|
|
+ $data['top_depart_id'] = $user['top_depart_id'];
|
|
|
if(empty($data['order_time'])) return [false, '单据日期不能为空'];
|
|
|
$data['order_time'] = $this->changeDateToDate($data['order_time']);
|
|
|
$orderTime = $data['order_time'];
|
|
|
$itemId = $data['item_id'] ?? 0;
|
|
|
|
|
|
+ //归档
|
|
|
+ list($status, $msg) = ArchiveService::isArchive($data['order_time'], $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
if(empty($itemId)) return [false, '项目不能为空'];
|
|
|
$bool = Item::where('del_time',0)->where('id', $itemId)->exists();
|
|
|
if(!$bool) return [false, '项目不存在或已被删除'];
|
|
|
|
|
|
- $data['top_depart_id'] = $user['top_depart_id'];
|
|
|
if(empty($data['details'])) return [false, '人员日工时单明细不能为空'];
|
|
|
|
|
|
// --- 1. 批量预获取人员信息,用于报错提示 ---
|
|
|
@@ -1048,6 +1034,10 @@ class PersonWorkService extends Service
|
|
|
// 1. 前置校验 (保留你之前的校验逻辑)
|
|
|
$monthStart = $this->changeDateToDate($data['month']);
|
|
|
|
|
|
+ //归档
|
|
|
+ list($status, $msg) = ArchiveService::isArchive($monthStart, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
// 1. 检查是否存在月度工时明细
|
|
|
$hasMonthlyOrder = DB::table('monthly_pw_order_details as d')
|
|
|
->join('monthly_pw_order as m', 'm.id', '=', 'd.main_id')
|
|
|
@@ -1265,7 +1255,13 @@ class PersonWorkService extends Service
|
|
|
if (empty($list)) return [false, '没有可保存的数据'];
|
|
|
|
|
|
$topDepartId = $user['top_depart_id'];
|
|
|
- $month = $data['month']; // 格式如: "2026-03"
|
|
|
+ $month = $data['month'];
|
|
|
+ $monthStart = $this->changeDateToDate($month);
|
|
|
+
|
|
|
+ //归档
|
|
|
+ list($status, $msg) = ArchiveService::isArchive($monthStart, $user);
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
$now = time();
|
|
|
|
|
|
// 1. 预加载员工名称映射 (使用 title 字段)
|
|
|
@@ -1287,7 +1283,6 @@ class PersonWorkService extends Service
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
// A. 清理该月份旧数据
|
|
|
- $monthStart = $this->changeDateToDate($month);
|
|
|
$monthEnd = strtotime('+1 month', $monthStart) - 1;
|
|
|
|
|
|
$oldOrderIds = DB::table('daily_pw_order')
|
|
|
@@ -1381,7 +1376,7 @@ class PersonWorkService extends Service
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
|
- return [true, '保存成功'];
|
|
|
+ return [true, ''];
|
|
|
} catch (\Exception $e) {
|
|
|
DB::rollBack();
|
|
|
return [false, "保存失败:" . $e->getMessage()];
|