更新命名问题

This commit is contained in:
2025-06-25 11:52:01 +08:00
parent 9f374011ae
commit 6b78ee29cf
57 changed files with 3295 additions and 1288 deletions
+137 -117
View File
@@ -32,8 +32,22 @@ class Index extends BaseController
->paginate($rows, false, ['query' => $param])
->each(function ($item, $key) {
$item->director_name = Db::name('Admin')->where(['id' => $item->director_uid])->value('name');
$item->plan_time = date('Y-m-d', $item->start_time) . ' 至 ' . date('Y-m-d', $item->end_time);
$item->status_name = ProjectList::$Status[(int)$item->status];
// 判断时间戳是否为空,如果为空则返回“-”
$item->plan_time = $item->start_time && $item->end_time
? date('Y-m-d', $item->start_time) . ' ~ ' . date('Y-m-d', $item->end_time)
: '-';
$item->project_plan_time = $item->project_start_time
? (
$item->project_end_time
? (
date('Y-m-d', $item->project_end_time) === '1970-01-01'
? date('Y-m-d', $item->project_start_time) . ' ~ 至今'
: date('Y-m-d', $item->project_start_time) . ' ~ ' . date('Y-m-d', $item->project_end_time)
)
: date('Y-m-d', $item->project_start_time) . ' ~ 至今'
)
: '-';
$item->status_name = ProjectList::$Status[(int) $item->status];
$business = BusinessList::where('id', $item->business_id)->find();
$item->business_id = $business ? ($business->name_short ?: $business->name) : null;
@@ -100,7 +114,7 @@ class Index extends BaseController
$flowNameData = isset($param['flowName']) ? $param['flowName'] : '';
$flowUidsData = isset($param['chargeIds']) ? $param['chargeIds'] : '';
$flowIdsData = isset($param['membeIds']) ? $param['membeIds'] : '';
// $flowDateData = isset($param['cycleDate']) ? $param['cycleDate'] : '';
// $flowDateData = isset($param['cycleDate']) ? $param['cycleDate'] : '';
$flow = [];
$time_1 = $param['start_time'];
$time_2 = $param['end_time'];
@@ -108,7 +122,7 @@ class Index extends BaseController
if (!$value) {
continue;
}
// $flowDate = explode('到', $flowDateData[$key]);
// $flowDate = explode('到', $flowDateData[$key]);
// $start_time = strtotime(urldecode(trim($flowDate[0])));
// $end_time = strtotime(urldecode(trim($flowDate[1])));
// if ($start_time < $time_1) {
@@ -131,7 +145,7 @@ class Index extends BaseController
$item['flow_uid'] = $flowUidsData[$key];
$item['flow_ids'] = $flowIdsData[$key];
$item['sort'] = $key;
// $item['start_time'] = $start_time;
// $item['start_time'] = $start_time;
// $item['end_time'] = $end_time;
$item['create_time'] = time();
$flow[] = $item;
@@ -155,7 +169,7 @@ class Index extends BaseController
if (!empty($param['team_admin_ids'])) {
$project_users .= "," . $param['team_admin_ids'];
}
$project_array = explode(",", (string)$project_users);
$project_array = explode(",", (string) $project_users);
$project_array = array_unique($project_array);
$project_user_array = [];
foreach ($project_array as $k => $v) {
@@ -209,137 +223,143 @@ class Index extends BaseController
//编辑
public function edit()
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$detail = (new ProjectList())->detail($id);
{
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$detail = (new ProjectList())->detail($id);
if (request()->isPost()) {
if ($this->uid == $detail['admin_id'] || $this->uid == $detail['director_uid']) {
try {
validate(ProjectCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
return json(['code' => 1, 'msg' => $e->getError()]);
}
// Convert start_time and end_time from date string to Unix timestamp
if (!empty($param['start_time'])) {
$param['start_time'] = strtotime($param['start_time']);
}
if (!empty($param['end_time'])) {
$param['end_time'] = strtotime($param['end_time']);
}
$param['update_time'] = time();
$res = ProjectList::where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res) {
// 新增 team_admin_ids 处理逻辑
$project_users = $this->uid;
if (!empty($param['director_uid'])) {
$project_users .= "," . $param['director_uid'];
if (request()->isPost()) {
if ($this->uid == $detail['admin_id'] || $this->uid == $detail['director_uid']) {
try {
validate(ProjectCheck::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
return json(['code' => 1, 'msg' => $e->getError()]);
}
// 如果 team_admin_ids 存在,则拆解并加入到 $project_users
if (!empty($param['team_admin_ids'])) {
$project_users .= "," . $param['team_admin_ids'];
// 将时间从日期字符串转换为Unix时间戳
if (!empty($param['start_time'])) {
$param['start_time'] = strtotime($param['start_time']);
}
if (!empty($param['end_time'])) {
$param['end_time'] = strtotime($param['end_time']);
}
if (!empty($param['project_start_time'])) {
$param['project_start_time'] = strtotime($param['project_start_time']);
}
if (!empty($param['project_end_time'])) {
$param['project_end_time'] = strtotime($param['project_end_time']);
}
// 将 $project_users 拆解为数组,去重
$project_array = explode(",", (string)$project_users);
$project_array = array_unique($project_array);
$param['update_time'] = time();
$res = ProjectList::where('id', $param['id'])->strict(false)->field(true)->update($param);
if ($res) {
// 新增 team_admin_ids 处理逻辑
$project_users = $this->uid;
if (!empty($param['director_uid'])) {
$project_users .= "," . $param['director_uid'];
}
// 获取当前已有的项目用户
$existing_users = Db::name('ProjectUser')->where('project_id', $param['id'])->column('uid');
$delete_users = array_diff($existing_users, $project_array); // 找出要删除的用户
// 如果 team_admin_ids 存在,则拆解并加入到 $project_users
if (!empty($param['team_admin_ids'])) {
$project_users .= "," . $param['team_admin_ids'];
}
// 删除用户,将 `delete_time` 设置为当前时间
if (!empty($delete_users)) {
Db::name('ProjectUser')->where('project_id', $param['id'])
->whereIn('uid', $delete_users)
->update(['delete_time' => time()]);
}
// 将 $project_users 拆解为数组,去重
$project_array = explode(",", (string) $project_users);
$project_array = array_unique($project_array);
// 插入新用户(如果之前没有的话)
$project_user_array = [];
foreach ($project_array as $k => $v) {
if (is_numeric($v)) {
$project_user_array[] = array(
'uid' => $v,
// 获取当前已有的项目用户
$existing_users = Db::name('ProjectUser')->where('project_id', $param['id'])->column('uid');
$delete_users = array_diff($existing_users, $project_array); // 找出要删除的用户
// 删除用户,将 `delete_time` 设置为当前时间
if (!empty($delete_users)) {
Db::name('ProjectUser')->where('project_id', $param['id'])
->whereIn('uid', $delete_users)
->update(['delete_time' => time()]);
}
// 插入新用户(如果之前没有的话)
$project_user_array = [];
foreach ($project_array as $k => $v) {
if (is_numeric($v)) {
$project_user_array[] = array(
'uid' => $v,
'admin_id' => $this->uid,
'project_id' => $param['id'],
'create_time' => time(),
);
}
}
// 插入或更新 ProjectUser 表
Db::name('ProjectUser')->strict(false)->field(true)->insertAll($project_user_array);
// 更新阶段的处理逻辑(保持不变)
if (isset($param['director_uid'])) {
$project_user = [
'uid' => $param['director_uid'],
'admin_id' => $this->uid,
'project_id' => $param['id'],
'create_time' => time(),
);
'delete_time' => 0,
];
$has = Db::name('ProjectUser')->where(['uid' => $param['director_uid'], 'project_id' => $param['id']])->find();
if (empty($has)) {
Db::name('ProjectUser')->strict(false)->field(true)->insert($project_user);
} else {
Db::name('ProjectUser')->where(['id' => $has['id']])->strict(false)->field(true)->update($project_user);
}
}
add_log('edit', $param['id'], $param, $detail);
}
return json(['code' => 0, 'msg' => '编辑成功']);
} else {
return json(['code' => 1, 'msg' => '只有创建人或者负责人才有权限编辑']);
}
} else {
if (empty($detail)) {
return json(['code' => 1, 'msg' => '项目不存在']);
} else {
$step_array = Db::name('Step')
->field('s.*,a.name as check_name')
->alias('s')
->join('Admin a', 'a.id = s.flow_uid', 'LEFT')
->order('s.sort asc')
->where(['s.action_id' => $id, 's.type' => 1, 's.delete_time' => 0])
->select()->toArray();
foreach ($step_array as &$vv) {
$flow_names = Db::name('Admin')->where([['id', 'in', $vv['flow_ids']]])->column('name');
$vv['flow_names'] = implode(',', $flow_names);
}
// 插入或更新 ProjectUser 表
Db::name('ProjectUser')->strict(false)->field(true)->insertAll($project_user_array);
$file_array = Db::name('FileInterfix')
->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,a.name as admin_name')
->alias('mf')
->join('File f', 'mf.file_id = f.id', 'LEFT')
->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
->order('mf.create_time desc')
->where(['mf.topic_id' => $id, 'mf.module' => 'project'])
->select()->toArray();
// 更新阶段的处理逻辑(保持不变)
if (isset($param['director_uid'])) {
$project_user = [
'uid' => $param['director_uid'],
'admin_id' => $this->uid,
'project_id' => $param['id'],
'create_time' => time(),
'delete_time' => 0,
];
$has = Db::name('ProjectUser')->where(['uid' => $param['director_uid'], 'project_id' => $param['id']])->find();
if (empty($has)) {
Db::name('ProjectUser')->strict(false)->field(true)->insert($project_user);
} else {
Db::name('ProjectUser')->where(['id' => $has['id']])->strict(false)->field(true)->update($project_user);
}
}
add_log('edit', $param['id'], $param, $detail);
return json([
'code' => 0,
'msg' => '成功',
'data' => [
'detail' => $detail,
'step_array' => $step_array,
'file_array' => $file_array,
]
]);
}
return json(['code' => 0, 'msg' => '编辑成功']);
} else {
return json(['code' => 1, 'msg' => '只有创建人或者负责人才有权限编辑']);
}
} else {
if (empty($detail)) {
return json(['code' => 1, 'msg' => '项目不存在']);
} else {
$step_array = Db::name('Step')
->field('s.*,a.name as check_name')
->alias('s')
->join('Admin a', 'a.id = s.flow_uid', 'LEFT')
->order('s.sort asc')
->where(['s.action_id' => $id, 's.type' => 1, 's.delete_time' => 0])
->select()->toArray();
foreach ($step_array as &$vv) {
$flow_names = Db::name('Admin')->where([['id', 'in', $vv['flow_ids']]])->column('name');
$vv['flow_names'] = implode(',', $flow_names);
}
$file_array = Db::name('FileInterfix')
->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,a.name as admin_name')
->alias('mf')
->join('File f', 'mf.file_id = f.id', 'LEFT')
->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
->order('mf.create_time desc')
->where(['mf.topic_id' => $id, 'mf.module' => 'project'])
->select()->toArray();
return json([
'code' => 0,
'msg' => '成功',
'data' => [
'detail' => $detail,
'step_array' => $step_array,
'file_array' => $file_array,
]
]);
}
}
}
// public function edit()
// public function edit()
// {
// $param = get_params();
// $id = isset($param['id']) ? $param['id'] : 0;
@@ -434,7 +454,7 @@ class Index extends BaseController
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
// print_r('id是:'.$id);
// print_r('id是:'.$id);
// 获取项目详细信息
$detail = (new ProjectList())->detail($id);
@@ -473,7 +493,7 @@ class Index extends BaseController
View::assign('detail', $detail); // 传递 detail
return view();
// return json([
// return json([
// 'code' => 1,
// 'msg' => '获取项目阶段信息成功',
// 'data' => [