|
|
@@ -411,6 +411,7 @@ class ItemService extends Service
|
|
|
}
|
|
|
|
|
|
public function createDraft($data, $user, $type, $opt_type = 1) {
|
|
|
+ unset($data['draft']);
|
|
|
Draft::insert([
|
|
|
'document_type' => $type,
|
|
|
'document_id' => $data['id'],
|
|
|
@@ -795,7 +796,6 @@ class ItemService extends Service
|
|
|
}
|
|
|
|
|
|
public function itemRule(&$data, $user, $is_add = true){
|
|
|
- $origin_data = $data;
|
|
|
$data['top_depart_id'] = $user['top_depart_id'];
|
|
|
if(empty($data['code'])) return [false, '项目编码不能为空'];
|
|
|
if(empty($data['title'])) return [false, '项目名称不能为空'];
|
|
|
@@ -1016,12 +1016,35 @@ class ItemService extends Service
|
|
|
list($status,$msg) = $this->itemNodeRule($data, $user, false);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
+ list($status, $msg) = $this->itemNodeEditSave($data, $user);
|
|
|
+ return [$status, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function itemNodeEditSave($data, $user){
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$model = ItemNode::where('id', $data['id'])->first();
|
|
|
+ $tableName = $model->getTable();
|
|
|
+
|
|
|
+ if(isset($data['draft'])){
|
|
|
+ // 创建草稿
|
|
|
+ $this->createDraft($data, $user, $tableName);
|
|
|
+ // 更新项目状态
|
|
|
+ $model->approval_state = ItemNode::TYPE_MINUS_ONE;
|
|
|
+ $model->save();
|
|
|
+ //触发审批
|
|
|
+ list($status, $msg) = (new WorkFlowService())->triggerWorkflow($data['review_id'], $model->id, $tableName,$user);
|
|
|
+ if(! $status) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return [true, '更新记录成功,记录草稿,进入审批流程'];
|
|
|
+ }
|
|
|
+
|
|
|
$old_employee_id = $model->charge_id;
|
|
|
- $crt_id = $model->crt_id;
|
|
|
$tableName = $model->getTable();
|
|
|
$model->title = $data['title'] ?? '';
|
|
|
$model->mark = $data['mark'] ?? "";
|
|
|
@@ -1116,6 +1139,67 @@ class ItemService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ public function checkItemNodeIsChanged($data, $user) {
|
|
|
+ // 1. 获取旧数据
|
|
|
+ list($status, $oldData) = $this->itemNodeDetail($data, $user);
|
|
|
+ if (!$status) return [false, $oldData];
|
|
|
+
|
|
|
+ //创建人 直接通过
|
|
|
+ if($user['id'] == $oldData['crt_id']) return false;
|
|
|
+
|
|
|
+ // --- 表头基础字段比对 ---
|
|
|
+ $fields = [
|
|
|
+ 'code', 'title', 'mark', 'state', 'budget',
|
|
|
+ 'charge_id', 'is_delivery_required', 'start_time', 'end_time',
|
|
|
+ 'entrust_type', 'is_review_required', 'review_id', 'priority_id', 'node_id', 'node_weight'
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($fields as $field) {
|
|
|
+ $oldValue = $oldData[$field] ?? '';
|
|
|
+ $newValue = $data[$field] ?? '';
|
|
|
+
|
|
|
+ // 日期格式对齐(确保 Y-m-d 格式一致)
|
|
|
+ if (in_array($field, ['start_time', 'end_time'])) {
|
|
|
+ $newValue = !empty($newValue) ? date("Y-m-d", $newValue) : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($oldValue != $newValue) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 自定义字段比对 ---
|
|
|
+ if (isset($data['custom_fields']) && is_array($data['custom_fields'])) {
|
|
|
+ $oldCustomMap = array_column($oldData['custom_fields'] ?? [], 'field_value', 'id');
|
|
|
+
|
|
|
+ foreach ($data['custom_fields'] as $customField) {
|
|
|
+ $fid = $customField['id'] ?? 0;
|
|
|
+ $newVal = $customField['field_value'] ?? '';
|
|
|
+ $oldVal = $oldCustomMap[$fid] ?? '';
|
|
|
+
|
|
|
+ if ($oldVal != $newVal) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 表体:人员名单比对 (man_list) ---
|
|
|
+ $oldMans = collect($oldData['man_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ $newMans = collect($data['man_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ if ($oldMans !== $newMans) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 表体:设备名单比对 (device_list) ---
|
|
|
+ $oldDevices = collect($oldData['device_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ $newDevices = collect($data['device_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ if ($oldDevices !== $newDevices) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false; // 没有任何变动
|
|
|
+ }
|
|
|
+
|
|
|
private function saveNodeEmployee($id, $time, $data, $user, $old_employee_id = 0){
|
|
|
if($old_employee_id != $data['charge_id']){
|
|
|
ItemNodeEmployee::where('del_time',0)
|
|
|
@@ -1456,6 +1540,11 @@ class ItemService extends Service
|
|
|
->exists();
|
|
|
}else{
|
|
|
if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
+ $item = ItemNode::where('id', $data['id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->first();
|
|
|
+ if(empty($item)) return [false, '项目节点不存在或已被删除'];
|
|
|
+
|
|
|
$bool = ItemNode::where('title', $data['title'])
|
|
|
->where('item_id',$data['item_id'])
|
|
|
->where('top_depart_id', $data['top_depart_id'])
|
|
|
@@ -1465,6 +1554,17 @@ class ItemService extends Service
|
|
|
}
|
|
|
if($bool) return [false, '该项目下节点名称已存在'];
|
|
|
|
|
|
+ //判断是否编辑 然后需要审核的 需要后 就更新状态 记录草稿
|
|
|
+ if(! $is_add){
|
|
|
+ $return = $this->checkItemNodeIsChanged($data, $user);
|
|
|
+ if(is_array($return)) {
|
|
|
+ list($status, $msg) = $return;
|
|
|
+ return [$status, $msg];
|
|
|
+ }else{
|
|
|
+ if($item->review_id && $return) $data['draft'] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
@@ -1525,10 +1625,34 @@ class ItemService extends Service
|
|
|
list($status,$msg) = $this->itemNodeMissionRule($data, $user, false);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
+ list($status, $msg) = $this->itemNodeMissionEditSave($data, $user);
|
|
|
+ return [$status, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function itemNodeMissionEditSave($data, $user){
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
$model = ItemNodeMission::where('id', $data['id'])->first();
|
|
|
+ $tableName = $model->getTable();
|
|
|
+
|
|
|
+ if(isset($data['draft'])){
|
|
|
+ // 创建草稿
|
|
|
+ $this->createDraft($data, $user, $tableName);
|
|
|
+ // 更新项目状态
|
|
|
+ $model->approval_state = ItemNodeMission::TYPE_MINUS_ONE;
|
|
|
+ $model->save();
|
|
|
+ //触发审批
|
|
|
+ list($status, $msg) = (new WorkFlowService())->triggerWorkflow($data['review_id'], $model->id, $tableName,$user);
|
|
|
+ if(! $status) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return [true, '更新记录成功,记录草稿,进入审批流程'];
|
|
|
+ }
|
|
|
+
|
|
|
$old_employee_id = $model->charge_id;
|
|
|
$tableName = $model->getTable();
|
|
|
$model->title = $data['title'] ?? '';
|
|
|
@@ -2061,6 +2185,7 @@ class ItemService extends Service
|
|
|
if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
|
if(! empty($data['id'])) $model->whereIn('id', $data['id']);
|
|
|
if(isset($data['state'])) $model->where('state', $data['state']);
|
|
|
+ if(isset($data['approval_state'])) $model->where('approval_state', $data['approval_state']);
|
|
|
if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
$return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
$model->where('crt_time','>=',$return[0]);
|
|
|
@@ -2127,6 +2252,11 @@ class ItemService extends Service
|
|
|
->exists();
|
|
|
}else{
|
|
|
if(empty($data['id'])) return [false,'ID不能为空'];
|
|
|
+ $item = ItemNodeMission::where('id', $data['id'])
|
|
|
+ ->where('del_time',0)
|
|
|
+ ->first();
|
|
|
+ if(empty($item)) return [false, '项目节点下任务不存在或已被删除'];
|
|
|
+
|
|
|
$bool = ItemNodeMission::where('title', $data['title'])
|
|
|
->where('item_node_id',$data['item_node_id'])
|
|
|
->where('top_depart_id', $data['top_depart_id'])
|
|
|
@@ -2136,9 +2266,81 @@ class ItemService extends Service
|
|
|
}
|
|
|
if($bool) return [false, '该项目节点下任务名称已存在'];
|
|
|
|
|
|
+ //判断是否编辑 然后需要审核的 需要后 就更新状态 记录草稿
|
|
|
+ if(! $is_add){
|
|
|
+ $return = $this->checkItemNodeMissionIsChanged($data, $user);
|
|
|
+ if(is_array($return)) {
|
|
|
+ list($status, $msg) = $return;
|
|
|
+ return [$status, $msg];
|
|
|
+ }else{
|
|
|
+ if($item->review_id && $return) $data['draft'] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ public function checkItemNodeMissionIsChanged($data, $user) {
|
|
|
+ // 1. 获取旧数据
|
|
|
+ list($status, $oldData) = $this->itemNodeMissionDetail($data, $user);
|
|
|
+ if (!$status) return [false, $oldData];
|
|
|
+
|
|
|
+ //创建人 直接通过
|
|
|
+ if($user['id'] == $oldData['crt_id']) return false;
|
|
|
+
|
|
|
+ // --- 表头基础字段比对 ---
|
|
|
+ $fields = [
|
|
|
+ 'code', 'title', 'mark', 'state', 'budget',
|
|
|
+ 'charge_id', 'is_delivery_required', 'start_time', 'end_time',
|
|
|
+ 'entrust_type', 'is_review_required', 'review_id', 'priority_id', 'mission_id', 'mission_weight', 'progress'
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($fields as $field) {
|
|
|
+ $oldValue = $oldData[$field] ?? '';
|
|
|
+ $newValue = $data[$field] ?? '';
|
|
|
+
|
|
|
+ // 日期格式对齐(确保 Y-m-d 格式一致)
|
|
|
+ if (in_array($field, ['start_time', 'end_time'])) {
|
|
|
+ $newValue = !empty($newValue) ? date("Y-m-d", $newValue) : "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($oldValue != $newValue) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 自定义字段比对 ---
|
|
|
+ if (isset($data['custom_fields']) && is_array($data['custom_fields'])) {
|
|
|
+ $oldCustomMap = array_column($oldData['custom_fields'] ?? [], 'field_value', 'id');
|
|
|
+
|
|
|
+ foreach ($data['custom_fields'] as $customField) {
|
|
|
+ $fid = $customField['id'] ?? 0;
|
|
|
+ $newVal = $customField['field_value'] ?? '';
|
|
|
+ $oldVal = $oldCustomMap[$fid] ?? '';
|
|
|
+
|
|
|
+ if ($oldVal != $newVal) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 表体:人员名单比对 (man_list) ---
|
|
|
+ $oldMans = collect($oldData['man_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ $newMans = collect($data['man_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ if ($oldMans !== $newMans) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // --- 表体:设备名单比对 (device_list) ---
|
|
|
+ $oldDevices = collect($oldData['device_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ $newDevices = collect($data['device_list'] ?? [])->pluck('data_id')->sort()->values()->toArray();
|
|
|
+ if ($oldDevices !== $newDevices) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false; // 没有任何变动
|
|
|
+ }
|
|
|
+
|
|
|
public function fillNodeMissionData($data){
|
|
|
if(empty($data['data'])) return $data;
|
|
|
|