123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- <?php
- namespace app\admin\controller\project;
- use app\admin\controller\field\Field;
- use app\api\BaseController;
- use HTMLPurifier_Config;
- use HTMLPurifier;
- use think\App;
- use think\facade\Db;
- use think\facade\View;
- use Qiniu\Auth;
- use Qiniu\Storage\UploadManager;
- class Api extends BaseController
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->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);
- }
-
-
- }
|