130 lines
5.0 KiB
PHP
130 lines
5.0 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
namespace app\api\controller;
|
|||
|
|
|
|||
|
|
class Report extends Common
|
|||
|
|
{
|
|||
|
|
//获取工作周报信息
|
|||
|
|
public function getReportList()
|
|||
|
|
{
|
|||
|
|
$param = request()->post();
|
|||
|
|
$where = [];
|
|||
|
|
if (isset($param['pageSize'])) {
|
|||
|
|
$pageSize = $param['pageSize'];
|
|||
|
|
}
|
|||
|
|
if (isset($param['pageNum'])) {
|
|||
|
|
$pageNum = $param['pageNum'];
|
|||
|
|
}
|
|||
|
|
if (isset($param['report_title'])) {
|
|||
|
|
$where['report_title'] = ['like', '%' . $param['report_title'] . '%'];
|
|||
|
|
}
|
|||
|
|
if (isset($param['user_id'])) {
|
|||
|
|
// $where['u.id'] = $param['user_id'];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
if (isset($param['pageSize'])) {
|
|||
|
|
$reportList = db('company_report')
|
|||
|
|
->alias('n')
|
|||
|
|
->join('system_user u', 'n.create_by = u.id', 'LEFT') // 联表查询 system_user
|
|||
|
|
->join('hr_staff hs', 'hs.staff_idcard = u.user_idcard', 'LEFT') // 联表查询 hr_staff
|
|||
|
|
->join('partner_contacts pc', 'pc.contacts_idcard = u.user_idcard', 'LEFT') // 联表查询 partner_contacts
|
|||
|
|
->where($where)
|
|||
|
|
->where('n.del_time', null)
|
|||
|
|
->page($pageNum, $pageSize)
|
|||
|
|
->field('n.*, u.user_type, hs.staff_name, pc.contacts_name') // 选择需要的字段
|
|||
|
|
->order('n.report_id asc')
|
|||
|
|
->select();
|
|||
|
|
} else {
|
|||
|
|
$reportList = db('company_report')
|
|||
|
|
->alias('n')
|
|||
|
|
->join('system_user u', 'n.create_by = u.id', 'LEFT') // 联表查询 system_user
|
|||
|
|
->join('hr_staff hs', 'hs.staff_idcard = u.user_idcard', 'LEFT') // 联表查询 hr_staff
|
|||
|
|
->join('partner_contacts pc', 'pc.contacts_idcard = u.user_idcard', 'LEFT') // 联表查询 partner_contacts
|
|||
|
|
->where($where)
|
|||
|
|
->where('n.del_time', null)
|
|||
|
|
->field('n.*, u.user_type, hs.staff_name, pc.contacts_name') // 选择需要的字段
|
|||
|
|
->order('n.report_id asc')
|
|||
|
|
->select();
|
|||
|
|
}
|
|||
|
|
foreach ($reportList as &$item) {
|
|||
|
|
// 根据用户类型,更新 create_by 字段
|
|||
|
|
if ($item['user_type'] == 1 && isset($item['staff_name'])) {
|
|||
|
|
$item['create_by'] = $item['staff_name']; // 用户类型为 1,使用 hr_staff 表中的 staff_name
|
|||
|
|
} elseif ($item['user_type'] == 2 && isset($item['contacts_name'])) {
|
|||
|
|
$item['create_by'] = $item['contacts_name']; // 用户类型为 2,使用 partner_contacts 表中的 contacts_name
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$total = db('company_report')
|
|||
|
|
->alias('n')
|
|||
|
|
->join('system_user u', 'n.create_by = u.id', 'LEFT') // 联表查询 system_user
|
|||
|
|
->join('hr_staff hs', 'hs.staff_idcard = u.user_idcard', 'LEFT') // 联表查询 hr_staff
|
|||
|
|
->join('partner_contacts pc', 'pc.contacts_idcard = u.user_idcard', 'LEFT') // 联表查询 partner_contacts
|
|||
|
|
->where($where)
|
|||
|
|
->where('n.del_time', null)
|
|||
|
|
->count();
|
|||
|
|
$res = [
|
|||
|
|
'total' => $total,
|
|||
|
|
'rows' => $reportList
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
return $this->sendSuccess($res);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//获取单个公告
|
|||
|
|
public function getReport()
|
|||
|
|
{
|
|||
|
|
//获取调用接口的user
|
|||
|
|
$param = request()->post();
|
|||
|
|
// dump($param['report_id']);
|
|||
|
|
$report = db('company_report')->where('report_id', $param['report_id'])->find();
|
|||
|
|
return $this->sendSuccess($report);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//新增公告信息
|
|||
|
|
public function addReport()
|
|||
|
|
{
|
|||
|
|
//获取调用接口的user
|
|||
|
|
$param = request()->post();
|
|||
|
|
$insert = [];
|
|||
|
|
if (isset($param['user_id'])) {
|
|||
|
|
$insert['create_by'] = $param['user_id'];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$insert['report_title'] = $param['report_title'];
|
|||
|
|
$insert['report_content'] = $param['report_content'];
|
|||
|
|
$insert['create_time'] = date('Y-m-d H:i:s');
|
|||
|
|
// $insert['report_type'] = $param['report_type'];
|
|||
|
|
// $insert['status'] = $param['status'];
|
|||
|
|
$ret = db('company_report')->insert($insert);
|
|||
|
|
return $this->sendSuccess($ret);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//修改公告信息
|
|||
|
|
public function updateReport()
|
|||
|
|
{
|
|||
|
|
//获取调用接口的user
|
|||
|
|
$param = request()->post();
|
|||
|
|
$update = [];
|
|||
|
|
if (isset($param['user_id'])) {
|
|||
|
|
$update['update_by'] = $param['user_id'];
|
|||
|
|
}
|
|||
|
|
$update['report_title'] = $param['report_title'];
|
|||
|
|
$update['report_content'] = $param['report_content'];
|
|||
|
|
// $update['status'] = $param['status'];
|
|||
|
|
// $update['report_type'] = $param['report_type'];
|
|||
|
|
$update['update_time'] = date('Y-m-d H:i:s');
|
|||
|
|
$ret = db('company_report')->where('report_id', $param['report_id'])->update($update);
|
|||
|
|
return $this->sendSuccess($ret);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//删除公告信息
|
|||
|
|
public function delReport()
|
|||
|
|
{
|
|||
|
|
//获取调用接口的user
|
|||
|
|
$param = request()->post();
|
|||
|
|
$update = [];
|
|||
|
|
$update['del_time'] = date('Y-m-d H:i:s');
|
|||
|
|
$ret = db('company_report')->where('report_id', $param['report_id'])->update($update);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|