131 lines
4.9 KiB
PHP
131 lines
4.9 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
class Notice extends Common {
|
||
//获取公告信息
|
||
public function getNoticeList()
|
||
{
|
||
$param = request()->post();
|
||
$where = [];
|
||
if (isset($param['pageSize'])) {
|
||
$pageSize = $param['pageSize'];
|
||
}
|
||
if (isset($param['pageNum'])) {
|
||
$pageNum = $param['pageNum'];
|
||
}
|
||
if (isset($param['notice_title']))
|
||
{
|
||
$where['notice_title'] = ['like', '%'.$param['notice_title'].'%'];
|
||
}
|
||
if (isset($param['notice_type']))
|
||
{
|
||
$where['notice_type'] =$param['notice_type'];
|
||
}
|
||
if (isset($param['pageSize'])){
|
||
$noticeList = db('company_notice')
|
||
->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.notice_id desc')
|
||
->select();
|
||
}else{
|
||
$noticeList = db('company_notice')
|
||
->where('del_time' , null)
|
||
->where($where)
|
||
->select();
|
||
}
|
||
foreach ($noticeList 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_notice')->where($where)->count();
|
||
$res = [
|
||
'total'=>$total,
|
||
'rows'=>$noticeList
|
||
];
|
||
|
||
return $this->sendSuccess($res);
|
||
}
|
||
//获取单个公告
|
||
public function getNotice()
|
||
{
|
||
//获取调用接口的user
|
||
$param = request()->post();
|
||
// dump($param['notice_id']);
|
||
$notice = db('company_notice')->where('notice_id',$param['notice_id'])->find();
|
||
return $this->sendSuccess($notice);
|
||
}
|
||
|
||
//新增公告信息
|
||
public function addNotice()
|
||
{
|
||
//获取调用接口的user
|
||
$param = request()->post();
|
||
$insert = [];
|
||
if (isset($param['user_id'])) {
|
||
$insert['create_by']=$param['user_id'];
|
||
//查询用户信息
|
||
// $user = db('system_user')->where('id',$param['user_id'])->find();
|
||
// if ($user){
|
||
// if (1==$user['user_type']){
|
||
// $userInfo = db('hr_staff')->where('staff_idcard', $user['user_idcard'])->find();
|
||
// if ($userInfo){
|
||
// $insert['create_by'] = $userInfo['staff_name'];
|
||
// }
|
||
// }else if (2==$user['user_type']){
|
||
// $userInfo = db('partner_contacts')->where('contacts_idcard', $user['user_idcard'])->find();
|
||
// if ($userInfo){
|
||
// $insert['create_by'] = $userInfo['contacts_name'];
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
}
|
||
|
||
$insert['notice_title'] = $param['notice_title'];
|
||
$insert['notice_content'] = $param['notice_content'];
|
||
$insert['create_time'] = date('Y-m-d H:i:s');
|
||
$insert['notice_type'] = $param['notice_type'];
|
||
$insert['status'] = $param['status'];
|
||
|
||
$ret = db('company_notice')->insert($insert);
|
||
return $this->sendSuccess($ret);
|
||
}
|
||
//修改公告信息
|
||
public function updateNotice()
|
||
{
|
||
//获取调用接口的user
|
||
$param = request()->post();
|
||
$update = [];
|
||
if (isset($param['user_id'])){
|
||
$update['update_by']=$param['user_id'];
|
||
}
|
||
$update['notice_title'] = $param['notice_title'];
|
||
$update['notice_content'] = $param['notice_content'];
|
||
$update['status'] = $param['status'];
|
||
$update['notice_type'] = $param['notice_type'];
|
||
$update['update_time'] = date('Y-m-d H:i:s');
|
||
$ret = db('company_notice')->where('notice_id',$param['notice_id'])->update($update);
|
||
return $this->sendSuccess($ret);
|
||
}
|
||
//删除公告信息
|
||
public function delNotice()
|
||
{
|
||
//获取调用接口的user
|
||
$param = request()->post();
|
||
$update = [];
|
||
$update['del_time'] = date('Y-m-d H:i:s');
|
||
$ret = db('company_notice')->where('notice_id',$param['notice_id'])->update($update);
|
||
}
|
||
} |