123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <?php
- namespace app\admin\controller\project;
- use app\admin\BaseController;
- use app\admin\model\CostProject as CostProjectModel;
- use app\admin\model\ProjectAudit;
- use app\admin\validate\project\CostProjectValidate;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\Session;
- use think\facade\View;
- use think\App;
- use app\admin\controller\field\Fieldcompany;
- use app\admin\controller\Pushmessage;
- class Approval extends BaseController
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->Field = new Fieldcompany($this->app);
- $this->model = new CostProjectModel();
- $this->uid = get_login_admin('id');
- $this->Pushmessage = new Pushmessage();
- }
- public function datalist()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $where = [
- ["cp_cost_project.delete_time", "=", 0],
- ["project_status","=",0],
- ["proprietor_status", "=", 2],
- ["entrust_unit", "=", get_login_admin('unit_name')],
- ];
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->where($where)
- ->order($order)->paginate($rows, false, ['query' => $param])
- ->each(function ($item) {
- //作业人
- $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
- if ($red) {
- if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) {
- $item->red = 1;
- }
- } else {
- $item->red = 0;
- }
- if (($item->province && $item->city && $item->area)) {
- $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
- }
- //作业人
- $operate_team_names = null;
- $operate_team_names_ids = explode(",", $item->operate_team);
- for ($i = 0; $i < count($operate_team_names_ids); $i++) {
- $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
- if (!($i == 0)) {
- $name = "," . $name;
- }
- $operate_team_names = $operate_team_names . $name;
- }
- $item->operate_team_names = $operate_team_names;
- });
- return table_assign(0, '', $list);
- } else {
- return view();
- }
- }
- public function receive(){
- if(request()->isAjax()){
- $param = get_params();
- $id = $param["id"] ?? 0;
- $this->model->update(["id"=>$id,"proprietor_status"=>3,"project_status"=>1]);
- add_project_log('项目接收', $id, '项目接收');
- // $project_id = $this->model->where('id', $id)->value('project_id');
- // $sent_review_head = $this->model->where('id', $id)->value('sent_review_head');
- // $this->Pushmessage->pushMessage($project_id, [], [], (array)$sent_review_head);
- return to_assign(0,"操作成功");
- }
- }
- /**
- * 查看信息
- */
- public function read()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- // dump($id);
- $detail = $this->model->getCostProjectById($id);
- $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
- $comment = Db::name("project_comment")->where("type",$comment_type)
- ->where("project_id", $id)->order('create_time', 'asc')->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();
- $uid = Db::name("relation")->where("uuid",$id)->column("uid");
- $contract = Db::name("contract")->whereIn("id",$uid)
- ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
- //小红点消息
- $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
- if (empty($red)) {
- $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
- }
- //剩余时间
- $c = $detail['project_end_time'] - time();
- if ($c > 0) {
- $advent_time = floor($c / 86400) . "天";
- } else {
- $c = -$c;
- $advent_time = floor($c / 86400) . "天";
- }
- $project_log = self::project_log($id);
- View::assign('project_log', $project_log);
- // halt($project_log);
- // 根据用户id 查询其能显示的字段
- $field = $this->Field->get_field_rules_new(get_login_admin('id'));
- // dump($field);
- if (!empty($detail)) {
- View::assign('advent_time', $advent_time);
- 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('contract', $contract);
- View::assign('red', $red);
- View::assign('project_five', self::getProjectFive());
- // dump(self::getProjectFive());
- return view();
- } else {
- throw new \think\exception\HttpException(404, '找不到页面');
- }
- }
- 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', '=', '项目动态-业主'],
- ['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;
- }
- }
|