123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?php
- namespace app\admin\controller;
- use app\admin\BaseController;
- use app\admin\controller\field\Field;
- use think\App;
- use think\facade\Db;
- use think\facade\View;
- use app\admin\model\ProjectMsg;
- use app\admin\model\CostProject;
- use app\admin\model\Admin;
- class Message extends BaseController
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->model = new ProjectMsg();
- $this->Admin = new Admin();
- $this->CostProject = new CostProject();
- $this->Field = new Field($this->app);
- $this->uid = get_login_admin("id");
- }
- public function index()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $unread_id = $this->Admin->where("id",$this->uid)->value("unread");
- if(!empty($unread_ids)){
- $unread_ids = explode(",",$unread_id);
- }
- $list = $this->model->whereIn("m.id",$unread_ids)->alias("m")->join("cost_project c","m.project_id=c.id")->field('m.*,c.id as project_id,c.project_name,c.project_status')->order('create_time', 'desc')->select();
- $list2['data'] = $list;
- $list2["count"] = count($list);
- return table_assign(0, '', $list2);
- }else{
- $param = get_params();
- $unread_id = $this->Admin->where("id",$this->uid)->value("unread");
- if(empty($unread_id)){
- $unread_ids = [];
- }else{
- $unread_ids = explode(",",$unread_id);
- }
- $list = Db::name("ProjectMsg")->where("uid",$this->uid)->order('create_time', 'desc')->select();
- if (is_object($list)) {
- $data = $list->toArray();
- }
- $real_data = [];
- foreach ($data as $item => $v){
- if(in_array($v["id"],$unread_ids)){
- $v["red"] = 1;
- $real_data[] =$v;
- }else{
- $v["red"] = 0;
- $real_data[] =$v;
- }
- }
- View::assign("msg",$real_data);
- $this->Admin->where("id",$this->uid)->update(["unread"=>null]);
- return view();
- }
- }
- /**
- * 已读
- */
- public function read()
- {
- $param = get_params();
- $unread_id = $this->Admin->where("id", $this->uid)->value("unread");
- $unread_ids = explode(",", $unread_id);
- $key = array_search($param["id"], $unread_ids);
- unset($unread_ids[$key]);
- $ids_str = implode(',', $unread_ids);
- try {
- $this->Admin->where("id", $this->uid)->update(["unread" => $ids_str]);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- $id = isset($param['project_id']) ? $param['project_id'] : 0;
- $detail = $this->CostProject->getCostProjectById($id);
- $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
- $file_array = Db::name('ProjectFile')
- ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname 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(array('mf.topic_id' => $id, 'mf.module' => 'project'))
- ->select()->toArray();
- $report = Db::name("project_report")->where([["project_id", "=", $id], ["r.status", "=", 1]])->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select();
- $project_log = self::project_log($id);
- View::assign('project_log', $project_log);
- // 根据用户id 查询其能显示的字段
- $field = $this->Field->get_field_rules_new(get_login_admin('id'));
-
- if (!empty($detail)) {
- View::assign('project_id', $id);
- View::assign('comment', $comment);
- View::assign('field', $field);
- View::assign('detail', $detail);
- View::assign('file_array', $file_array);
- View::assign('report', $report);
- View::assign('project_five', self::getProjectFive());
-
- return view();
- }
- }
- public function read_all(){
- try {
- $this->Admin->where("id", $this->uid)->update(["unread" => null]);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- return to_assign(0,"操作成功");
- }
- public function project_log($project_id)
- {
- // $project_id = 24;
- $login_admin = get_admin(get_login_admin('id'));
- $where = array();
- if ($login_admin['user_type'] == 2) {
- $where = [
- ['project_status', '>=', 3],
- ['unit_name', '=', $login_admin['unit_name']],
- ];
- } else {
- if ($login_admin['permission'] != 1) {
- $where = [
- ['unit_name', '=', $login_admin['unit_name']],
- ];
- }
- }
- // dump($where);
- $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
- foreach ($project_log as $key => $value) {
- $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
- }
- // dump($project_log);
- // View::assign('project_log', $project_log);
- // return View();
- return $project_log;
- }
- public function getProjectFive()
- {
- $where = [
- ['name', '=', '作业日志-财政局'],
- ['name', '=', '工作记录-财政局'],
- ['name', '=', '项目报告-财政局'],
- ['name', '=', '项目人员-财政局'],
- ['name', '=', '项目动态-财政局'],
- ];
- $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
- $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
- $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
- $login_rules = explode(',', $login_rules);
- $rules_id = array();
- foreach ($list as $key => $value) {
- if ($value['name'] == "作业日志-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_comments'] = 1;
- } else {
- $rules_id['project_comments'] = 0;
- }
- } else if ($value['name'] == "工作记录-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_record'] = 1;
- } else {
- $rules_id['project_record'] = 0;
- }
- } else if ($value['name'] == "项目报告-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_report'] = 1;
- } else {
- $rules_id['project_report'] = 0;
- }
- } else if ($value['name'] == "项目人员-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_user'] = 1;
- } else {
- $rules_id['project_user'] = 0;
- }
- } else if ($value['name'] == "项目动态-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_log'] = 1;
- } else {
- $rules_id['project_log'] = 0;
- }
- }
- }
- return $rules_id;
- }
- }
|