123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- <?php
- namespace app\admin\controller;
- use app\admin\BaseController;
- use app\admin\model\CostProject as CostProjectModel;
- use think\facade\Db;
- use think\facade\View;
- use think\App;
- use app\admin\controller\field\Field;
- class Project extends BaseController
- {
- /**
- * 构造函数
- */
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->model = new CostProjectModel();
- $this->uid = get_login_admin('id');
- $this->unit = get_login_admin('unit_name');
- $this->Field = new Field($this->app);
- }
- public function index($project_name = '',$sent_review_unit_name = '',$entrust_unit_name = '',$project_status = '')
- {
- $where[] = ["c.delete_time","=",0];
- $where[] = ["c.project_status",">",1];
- if (!empty($project_name)) {
- $where[] = ['project_name', 'like', '%' . $project_name . '%'];
- }
- if (!empty($sent_review_unit_name)) {
- $where[] = ['sent_review_unit_name', 'like', '%' . $sent_review_unit_name . '%'];
- }
- if (!empty($entrust_unit_name)) {
- $where[] = ['entrust_unit_name', 'like', '%' . $entrust_unit_name . '%'];
- }
- if (!empty($project_status)) {
- $where[] = ['project_status', '=', $project_status];
- }
- $inarr = array();
- $review_unit = $this->model->where("entrust_unit", get_login_admin("unit_name"))->field('id,entrust_maker,entrust_approver')->select()->toArray();
- for ($i = 0; $i < count($review_unit); $i++) {
- $a = $review_unit[$i];
- $ids = $a["entrust_maker"] . ',' . $a["entrust_approver"];
- $ids = explode(",", $ids);
- $c = in_array($this->uid, $ids);
- if ($c) {
- $inarr[] = $a["id"];
- }
- }
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $aa = Db::name('cost_project')->alias("c")->field("c.id,c.project_name,c.project_status,c.engineering_type,c.preparation_amount,c.preparation_amount,c.create_time,d.title as review_unit_name,dd.title as entrust_unit_name,a.nickname as operate_head_name,aa.nickname as review_head_name")->
- join("department d", "c.review_unit=d.id", "LEFT")->
- join("department dd", "c.entrust_unit=d.id", "LEFT")->
- join("admin a", "c.operate_head=a.id", "LEFT")->
- join("admin aa", "c.review_head=a.id", "LEFT")->
- where($where)->
- whereIn("c.id", $inarr)->select()->toArray();
- $field = $this->Field->get_field_rules_new($this->uid);
- $list = array_values(array_column($aa, NULL, 'id'));
- // return json($list);
- View::assign("detail", $list);
- View::assign('field', $field);
- return view();
- }
- public function index_company($project_name = '',$sent_review_unit_name = '',$entrust_unit_name = '',$project_status = '')
- {
- $where[] = ["c.delete_time","=",0];
- $where[] = ["c.project_status",">",3];
- if (!empty($project_name)) {
- $where[] = ['project_name', 'like', '%' . $project_name . '%'];
- }
- if (!empty($sent_review_unit_name)) {
- $where[] = ['sent_review_unit_name', 'like', '%' . $sent_review_unit_name . '%'];
- }
- if (!empty($entrust_unit_name)) {
- $where[] = ['entrust_unit_name', 'like', '%' . $entrust_unit_name . '%'];
- }
- if (!empty($project_status)) {
- $where[] = ['project_status', '=', $project_status];
- }
- //根据所登录的账号,查询跟本身有关的项目
- // $this->model->where()->select();
- $param = get_params();
- $inarr = array();
- $review_unit = $this->model->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"];
- }
- }
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $aa = Db::name('cost_project')->alias("c")->field("c.id,c.project_name,c.project_status,c.engineering_type,c.preparation_amount,c.preparation_amount,c.create_time,d.title as review_unit_name,dd.title as entrust_unit_name,a.nickname as operate_head_name,aa.nickname as review_head_name")->
- join("department d", "c.review_unit=d.id", "LEFT")->
- join("department dd", "c.entrust_unit=d.id", "LEFT")->
- join("admin a", "c.operate_head=a.id", "LEFT")->
- join("admin aa", "c.review_head=a.id", "LEFT")->
- where($where)->
- whereIn("c.id", $inarr)->select()->toArray();
- $list = array_values(array_column($aa, NULL, 'id'));
- View::assign("detail", $list);
- return view();
- }
- public function kan()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
- $report = Db::name("project_report")->where("project_id", $id)->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select()->toArray();
- $project_log = self::project_log($id);
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $detail = $this->model->getCostProjectById($param['id']);
- $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();
- $field = $this->Field->get_field_rules_new($this->uid);
- //剩余时间
- $c = $detail['project_end_time']-time();
- if($c>0){
- $advent_time = floor($c / 86400)."天";
- }else{
- $c = -$c;
- $advent_time = floor($c / 86400)."天";
- }
- //报告进度
- $type_max = -1;
- foreach ($report as $key => $val) {
- $type_max = max($type_max , $val['type']);
- }
- // 创建新数组
- $report_time = [
- 0 => [
- "create_time" => 0,
- "nickname" => null
- ],
- 1 => [
- "create_time" => 0,
- "nickname" => null
- ],
- 2 => [
- "create_time" => 0,
- "nickname" => null
- ]
- ];
- // 遍历原始数组
- foreach ($report as $item) {
- $type = $item["type"];
- $create_time = $item["create_time"];
- $nickname = $item["nickname"];
- // 更新新数组中对应type的create_time和nickname
- if ($create_time > $report_time[$type]["create_time"]) {
- $report_time[$type]["create_time"] = $create_time;
- $report_time[$type]["nickname"] = $nickname;
- }
- }
- View::assign('project_id', $id);
- View::assign('comment', $comment);
- View::assign('detail', $detail);
- View::assign('file_array', $file_array);
- View::assign('report', $report);
- View::assign('type_max', $type_max+1);
- View::assign('report_time', $report_time);
- View::assign('project_log', $project_log);
- View::assign('advent_time', $advent_time);
- View::assign('project_five', self::getProjectFive());
- // halt($detail);
- return view();
- }
- public function kan_c()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- //项目日志
- $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
- //项目报告
- $report = Db::name("project_report")->where("project_id", $id)->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select()->toArray();
- //项目动态
- $project_log = self::project_log($id);
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- //项目内容
- $detail = $this->model->where("id", $id)->paginate($rows, false, ['query' => $param])
- ->each(function ($item) {
- $item->entrust_unit_name = Db::name('department')->where(['id' => $item->entrust_unit])->value('title');
- $item->entrust_maker_name = Db::name('admin')->where(['id' => $item->entrust_maker])->value('nickname');
- })->toArray();
- $detail = $detail["data"][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')
- ->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();
- //剩余时间
- $c = $detail['project_end_time']-time();
- if($c>0){
- $advent_time = floor($c / 86400)."天";
- }else{
- $c = -$c;
- $advent_time = floor($c / 86400)."天";
- }
- //报告进度
- $type_max = -1;
- foreach ($report as $key => $val) {
- $type_max = max($type_max , $val['type']);
- }
- // 创建新数组
- $report_time = [
- 0 => [
- "create_time" => 0,
- "nickname" => null
- ],
- 1 => [
- "create_time" => 0,
- "nickname" => null
- ],
- 2 => [
- "create_time" => 0,
- "nickname" => null
- ]
- ];
- // 遍历原始数组
- foreach ($report as $item) {
- $type = $item["type"];
- $create_time = $item["create_time"];
- $nickname = $item["nickname"];
- // 更新新数组中对应type的create_time和nickname
- if ($create_time > $report_time[$type]["create_time"]) {
- $report_time[$type]["create_time"] = $create_time;
- $report_time[$type]["nickname"] = $nickname;
- }
- }
- View::assign('project_id', $id);
- View::assign('comment', $comment);
- View::assign('detail', $detail);
- View::assign('file_array', $file_array);
- View::assign('report', $report);
- View::assign('type_max', $type_max+1);
- View::assign('report_time', $report_time);
- View::assign('project_log', $project_log);
- View::assign('advent_time', $advent_time);
- View::assign('project_five', self::getProjectFive_company());
- // dump(self::getProjectFive_company());
- return view();
- }
- 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 data()
- {
- $param = get_params();
- $inarr = array();
- $review_unit = $this->model->where("entrust_unit", get_login_admin("unit_name"))->field('id,entrust_maker,entrust_approver')->select()->toArray();
- for ($i = 0; $i < count($review_unit); $i++) {
- $a = $review_unit[$i];
- $ids = $a["entrust_maker"] . ',' . $a["entrust_approver"];
- $ids = explode(",", $ids);
- $c = in_array($this->uid, $ids);
- if ($c) {
- $inarr[] = $a["id"];
- }
- }
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->whereIn("id", $inarr)->order($order)->paginate($rows, false, ['query' => $param])
- ->each(function ($item) {
- $item->review_unit_name = Db::name('department')->where(['id' => $item->review_unit])->value('title');
- $item->entrust_unit_name = Db::name('department')->where(['id' => $item->entrust_unit])->value('title');
- });
- // halt($list);
- return $inarr;
- //$inarr没去重,应该不要紧
- }
- public function getProjectFive()
- {
- $where = [
- ['name', '=', '作业日志-财政局'],
- ['name', '=', '工作记录-财政局'],
- ['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;
- }
- } else if ($value['name'] == "项目附件-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_file'] = 1;
- } else {
- $rules_id['project_file'] = 0;
- }
- } else if ($value['name'] == "联系函-财政局") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_contact'] = 1;
- } else {
- $rules_id['project_contact'] = 0;
- }
- }
- }
- return $rules_id;
- }
- public function getProjectFive_company()
- {
- $where = [
- ['name', '=', '作业日志-公司'],
- ['name', '=', '工作记录-公司'],
- ['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;
- }
- } else if ($value['name'] == "项目附件-公司") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_file'] = 1;
- } else {
- $rules_id['project_file'] = 0;
- }
- } else if ($value['name'] == "联系函-公司") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_contact'] = 1;
- } else {
- $rules_id['project_contact'] = 0;
- }
- }
- }
- return $rules_id;
- }
- }
|