Files
annnj-company 130c1026c4 first commit
2026-04-17 18:29:53 +08:00

157 lines
5.1 KiB
PHP

<?php
namespace app\admin\controller;
use think\Db;
use app\lib\AuthApi;
use app\util\ReturnCode;
use app\common\validate\NoticeValidate;
use app\model\Survey as SurveyModel;
use app\model\Attachment;
/**
* 公告 、 传阅管理
*
* Class Notice
* @package app\admin\controller
*/
class Notice extends Base
{
/**
* 新增 / 编辑
*/
public function notice_edit()
{
if(empty($this->userInfo)){
return $this->buildFailed("编辑通知失败,因用户信息为空,请重新登录","",ReturnCode::AUTH_ERROR);
}
$data = $this->request->post();
if(!isset($data['type']) || !in_array($data['type'] , [1,2]))
return $this->buildFailed('type参数错误');
$str = $data['type'] == 1 ? 'notice_edit' : 'circulation_edit';
$validate = new NoticeValidate();
if (!$validate->scene($str)->check($data)){
return $this->buildFailed('参数验证失败',$validate->getError());
}
$data['release_uid'] = $this->userInfo['user_id'];
$data['release_name'] = $this->userInfo['user_name'];
$data['update_time'] = date('Y-m-d H:i:s' , time());
if(isset($data['id']) && !empty($data['id'])){
$bo = Db::name('notice')->where('id' , $data['id'])->update($data);
}else{
$data['create_time'] = date('Y-m-d H:i:s' , time());
$bo = Db::name('notice')->insert($data);
}
if(!$bo){
return $this->buildFailed('操作失败');
}
return $this->buildSuccess();
}
/**
* 个人办公列表1
* @return [type] [description]
*/
public function getList(){
$data = $this->request->post();
$map[] = ['type' , '=' , $data['type']];
$field = 'id,title,release_uid,release_name,relevant_personnel,create_time,update_time,status';
if(isset($data['is_relevant']) && $data['is_relevant']){ // 与我相关
$str = 'FIND_IN_SET('.$this->userInfo['user_id'].',`relevant_personnel_ids`)';
$map[] = ['status' , '=' , '1'];
}
// 传阅管理的权限控制
if($data['type'] == 2 && !isset($str)){
if (!in_array("ROLE_ADMIN", $this->userInfo['roleCode'])) {
$user_ids = array($this->userInfo['user_id']);//$this->userInfo['user_ids'] ? implode(',', $this->userInfo['user_ids']) : [];
$map[] = ['release_uid' , 'in' , $user_ids];
}
}
if (isset($data['release_name']) && !empty($data['release_name'])){
$map[] = ['release_name','like','%'.$data['release_name'].'%'];
}
if (isset($data['title']) && !empty($data['title'])){
$map[] = ['title','like','%'.$data['title'].'%'];
}
if(isset($str)){
$result = Db::name('notice')->where($map)->field($field)->where($str)->order('id desc')->paginate($this->getPage())->toArray();
foreach ($result['data'] as $key => &$value) {
$value['reply_status'] = Db::name('notice_reply')->where(['create_uid' => $this->userInfo['user_id'] , 'notice_id' => $value['id']])->value('id') ? 1 : 0 ;
}
}else{
$result = Db::name('notice')->where($map)->field($field)->order('id desc')->paginate($this->getPage())->toArray();
}
$result['count'] = $result['total'];
return $this->buildSuccess($result);
}
/**
* 详情
* @return [type] [description]
*/
public function detail(){
$pic=new Attachment();
$id = $this->request->post('id');
if(!$id)
return $this->buildFailed('缺少id参数');
$result = Db::name('notice')->where('id' , $id)->find();
$result['type'] == 2 && $result['reply'] = Db::name('notice_reply')->field('reply_name ,content ,create_time')->where('notice_id' , $id)->order('id desc')->select();
$result['files'] = !empty($result['files']) ? $pic->getUrls($result['files']) : '';
return $this->buildSuccess($result);
}
/**
* 修改状态
* @return [type] [description]
*/
public function change_status(){
$id = $this->request->post('id');
$status = $this->request->post('status');
if(!$id)
return $this->buildFailed('缺少id参数');
if(!in_array($status, [0,1]))
return $this->buildFailed('状态参数错误');
Db::name('notice')->where('id' ,$id)->update(['status' => $status]);
return $this->buildSuccess('操作成功');
}
/**
* 传阅回复
* @return [type] [description]
*/
public function reply(){
$id = $this->request->post('id');
$content = $this->request->post('content');
if(Db::name('notice_reply')->where(['notice_id'=>$id , 'create_uid'=>$this->userInfo['user_id']])->value('id')){
return $this->buildFailed('该传阅已回复,请勿重复提交');
}
Db::name('notice_reply')->insert(['notice_id'=>$id , 'content'=>$content , 'reply_name' =>$this->userInfo['user_name'] , 'create_uid' =>$this->userInfo['user_id'] , 'create_time' => date('Y-m-d H:i:s' , time())]);
return $this->buildSuccess('操作成功');
}
/**
* 获取用户列表
* @return [type] [description]
*/
public function getUsersList(){
if(empty($this->userInfo)){
return $this->buildFailed("获取用户列表失败,因用户信息为空,请重新登录","",ReturnCode::AUTH_ERROR);
}
$Auth = new AuthApi();
$result = $Auth->getUsersListById(['departIds' => '6,18']);
$result = json_decode($result,true);
return $this->buildSuccess($result['data'], '成功');
}
}