uid = get_login_admin("id"); $this->Field = new Field($this->app); } /** * 财政文件上传 */ public function add_file() { $param = get_params(); $param['create_time'] = time(); $param['admin_id'] = $this->uid; $param['module'] = 'project'; $fid = Db::name('project_file')->strict(false)->field(true)->insertGetId($param); $content = Db::name("file")->where("id", $param["file_id"])->value("name"); if (isset($param["topic_id"])) { add_project_log("上传文件", $param["topic_id"], $content, 1); } $file_array = Db::name('file') ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name") ->alias("f") ->join('Admin a', 'f.admin_id = a.id', 'LEFT') ->order('f.create_time desc') ->where(array('f.id' => $param["file_id"])) ->select()->toArray(); $file_array[0]["id"] = $fid; return json($file_array); } /** * 公司文件上传 */ public function add_file_company() { $param = get_params(); $param['create_time'] = time(); $param['admin_id'] = $this->uid; $param['module'] = 'project'; $fid = Db::name('project_file')->strict(false)->field(true)->insertGetId($param); $content = Db::name("file")->where("id", $param["file_id"])->value("name"); if (isset($param["topic_id"])) { add_project_log("上传文件", $param["topic_id"], $content, 1); } $file_array = Db::name('file') ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name") ->alias("f") ->join('Admin a', 'f.admin_id = a.id', 'LEFT') ->order('f.create_time desc') ->where(array('f.id' => $param["file_id"])) ->select()->toArray(); $file_array[0]["id"] = $fid; return json($file_array); } /** * 财政删除文件 */ public function delete_file() { if (request()->isDelete()) { $id = get_params("id"); $detail = Db::name('ProjectFile')->where('id', $id)->find(); if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) { $file_data = Db::name("file")->where('id', $detail["file_id"])->find(); if(!$file_data){ return to_assign(1,"没有该数据!!"); } $accessKey = 'va_jSLgv-VlomxzMU-6lroagyFoUWxayoxsq7FRg'; $secretKey = 'vVXEUwrvq-H5YIJNzu3u46aM92IE91x6tGjIRonL'; //构建鉴权对象 //在七牛的存储空间 $bucket = 'yiguancaiping'; $key = $file_data['filename']; $auth = new Auth($accessKey, $secretKey); $config = new \Qiniu\Config(); $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); $err = $bucketManager->delete($bucket, $key); if ($err) { $content = $file_data['name']; add_project_log("删除文件", $detail["topic_id"], $content, 1); return to_assign(0, "删除成功"); } } else { return to_assign(0, "删除失败"); } } else { return to_assign(1, "错误的请求"); } } /** * 公司删除文件 */ public function delete_file_company() { if (request()->isDelete()) { $id = get_params("id"); $detail = Db::name('ProjectFile')->where('id', $id)->find(); if (Db::name('ProjectFile')->where('id', $id)->delete() !== false) { $file_data = Db::name("file")->where('id', $detail["file_id"])->find(); $accessKey = 'va_jSLgv-VlomxzMU-6lroagyFoUWxayoxsq7FRg'; $secretKey = 'vVXEUwrvq-H5YIJNzu3u46aM92IE91x6tGjIRonL'; //构建鉴权对象 //在七牛的存储空间 $bucket = 'yiguancaiping'; $key = $file_data['filename']; $auth = new Auth($accessKey, $secretKey); $config = new \Qiniu\Config(); $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); $err = $bucketManager->delete($bucket, $key); if ($err) { $content = $file_data['name']; add_project_log("删除文件", $detail["topic_id"], $content, 1); return to_assign(0, "删除成功"); } } else { return to_assign(0, "删除失败"); } } else { return to_assign(1, "错误的请求"); } } public function test() { $str = "'a"."bac'"; $a = "a"; $a = preg_match('/["\']/', $str); return cleanHtml($a); } /** * 清除小红点 */ public function eliminate() { $param = get_params(); $type = isset($param['type']) ? $param['type'] : 0; $project_id = isset($param['project_id']) ? $param['project_id'] : 0; if ($type&&$project_id) { switch ($type) { case 1: $key = "detail"; break; case 2: $key = "comment"; break; case 3: $key = "record"; break; case 4: $key = "report"; break; case 5: $key = "user"; break; case 6: $key = "contact"; break; } if (!empty($key)) { Db::name("new_msg")->where("uid", $this->uid)->where("project_id",$project_id)->update([$key => 0]); } } } /** * 请款的项目 * 仅请款用 */ public function get_project() { $param = get_params(); $where[] = ["delete_time", "=", 0]; $where[] = ["review_unit", "=", get_login_admin('unit_name')]; $where[] = ["project_status", ">", 2]; $where[] = ["project_status", "<", 9]; if (!empty($param['keywords'])) { $keyword = $param['keywords']; $where[] = ['project_name|entrust_unit_name', 'like', '%' . $keyword . '%']; } $inarr = array(); $review_unit = Db::name("cost_project")->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray(); for ($i = 0; $i < count($review_unit); $i++) { $a = $review_unit[$i]; $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"]; $ids = explode(",", $ids); $c = in_array($this->uid, $ids); if ($c) { $inarr[] = $a["id"]; } } //$inarr没去重,应该不要紧 //项目可见的权限 $field = $this->Field->get_field_rules_new($this->uid); //1全部-可查看可编辑,2全部-可查看,0与我有关 $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3; if ($see_auth == 3) { $list = Db::name("cost_project")->whereIn("id", $inarr)->where($where)->field("id,project_name,entrust_unit,entrust_unit_name,sent_review_cost")->select(); } elseif ($see_auth == 0) { $list = Db::name("cost_project")->whereIn("id", $inarr)->where($where)->field("id,project_name,entrust_unit,entrust_unit_name,sent_review_cost")->select(); } else { $list = Db::name("cost_project")->where($where)->field("id,project_name,entrust_unit,entrust_unit_name,sent_review_cost")->select(); } if (is_object($list)) { $list = $list->toArray(); } //已经存在的项目,不能二次请款,项目状态3拒绝 $ids1 = Db::name('appropriation_project')->where('uid', 'NOT NULL')->column("project_id"); $ids2 = Db::name('appropriation_project')->alias("p")->leftJoin("appropriation a","p.uid=a.id") ->where('a.status', '3')->whereOr('a.status', '-2')->column("p.project_id"); // $project_id = array_column($ids,"project_id"); // halt($list,$ids); $ids = array_diff($ids1,$ids2); $real_list = []; foreach ($list as $item=>$value){ if(!in_array($value["id"],$ids)){ $real_list[] = $value; } } $real_real_list = []; foreach ($real_list as $item=>$value){ if($value["entrust_unit"]!=""){ $real_real_list[] = $value; } } $data["data"] = $real_real_list; $data["total"] = count($real_real_list); return table_assign(0, "", $data); } /** * 通用查询 */ public function get_self_project(){ $param = get_params(); $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $unit_type = get_login_admin("user_type"); if ($unit_type == 0) { $where = [ ["delete_time", "=", 0], ["project_status", ">", 2], ["entrust_unit", "=", get_login_admin('unit_name')] ]; $data = Db::name("cost_project")->where($where) ->field("id,project_name,project_status,entrust_unit_name,review_unit_name") ->paginate($rows, false, ['query' => $param]); } elseif ($unit_type == 2) { $where =[ ["delete_time", "=", 0], ["project_status", ">", 3], ["project_status", "<", 6], ["review_unit", "=", get_login_admin("unit_name")] ]; $data = Db::name("cost_project")->where($where) ->field("id,project_name,project_status,entrust_unit_name,review_unit_name") ->paginate($rows, false, ['query' => $param]); }else{ $where =[ ["delete_time", "=", 0], ["project_status", ">", 3], ["project_status", "<", 6], ["sent_review_unit", "=", get_login_admin("unit_name")] ]; $data = Db::name("cost_project")->where($where) ->field("id,project_name,project_status,entrust_unit_name,review_unit_name") ->paginate($rows, false, ['query' => $param]); } return table_assign(0, '',$data); } public function get_department_tree() { $unit_id = get_unit(get_login_admin("unit_name")); $department = Db::name('Department')->where(['status' => 1])->select()->toArray(); $list = get_tree($department, 0, 2); $data['trees'] = $list; $result = null; for ($i = 0; $i < count($data['trees']); $i++) { $point = $data['trees'][$i]; if ($point["id"] == $unit_id) { $result['trees'][] = $point; break; } } return json($result); } //获取子部门所有员工 public function get_employee($did = 1) { $did = get_params('did'); if ($did == 1) { $department = $did; } else { $department = get_department_son(get_login_admin("unit_name")); } $employee = Db::name('admin') ->field('a.id,a.did,a.position_id,a.mobile,a.nickname,a.status,a.thumb,a.username,d.title as department') ->alias('a') ->join('Department d', 'a.did = d.id') ->where(['a.status' => 1]) ->where('a.id', ">", 1) ->where('a.did', "in", $department) ->select(); return to_assign(0, '', $employee); } public function get_entrust(){ $param = get_params(); $where = [ "status" =>1, "type" => 0, "pid" => 0, ]; if(!empty($param["keywords"])){ $where[] = ["title","like",'%' . $param['keywords'] . '%'] ; } $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $list = Db::name("department")->where($where)-> field("id,title,address")->paginate($rows, false, ['query' => $param]); return table_assign(0, '',$list); } public function get_entrust_people(){ $param = get_params(); $unit_id = isset($param["unit_id"])?$param["unit_id"]:0; $where[] = ["unit_name","=",$unit_id]; $where[] = ["status","=",1]; $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; if(!empty($param["keywords"])){ $where[] = ["nickname","like",'%' . $param['keywords'] . '%'] ; } $list = Db::name("admin")->where($where)->field("id,nickname") ->paginate($rows, false, ['query' => $param]); return table_assign(0, '',$list); } //获取送审单位 public function get_sent_review(){ $param = get_params(); $where = [ "status" =>1, "type" => 1, "pid" => 0, ]; if(!empty($param["keywords"])){ $where[] = ["title","like",'%' . $param['keywords'] . '%'] ; } $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $list = Db::name("department")->where($where)-> field("id,title,address")->paginate($rows, false, ['query' => $param]); return table_assign(0, '',$list); } public function get_sent_review_people(){ $param = get_params(); $unit_id = isset($param["unit_id"])?$param["unit_id"]:0; $where[] = ["unit_name","=",$unit_id]; $where[] = ["status","=",1]; $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; if(!empty($param["keywords"])){ $where[] = ["nickname","like",'%' . $param['keywords'] . '%'] ; } $list = Db::name("admin")->where($where)->field("id,nickname") ->paginate($rows, false, ['query' => $param]); return table_assign(0, '',$list); } /** * 修改项目报告状态 */ public function set_status(){ if(request()->isPost()){ $param = get_params(); $id = isset($param["project_id"])?$param["project_id"]:0; try { Db::name("cost_project")->where('id',$id)->update(["report_status"=>$param["report_status"]]); } catch (\Exception $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } //0初稿中,1对数中,2定案中,3定案完成 $name=""; switch ($param["report_status"]){ case 0: $name = "初稿中"; break; case 1: $name = "对数中"; break; case 2: $name = "定案中"; break; case 3: $name = "定案结束"; break; } if($name!==""){ $content = get_login_admin("nickname")."修改报告状态为".$name; add_project_log("编辑状态", $id,$content); } return to_assign(0,"操作成功"); } } public function get_file(){ $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $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,mf.remark') ->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')) ->paginate(9999, false, ['query' => $param]); return table_assign(0, '', $file_array); } }