['except' => []] ]; public function index() { if (request()->isAjax()) { $admin_id = $this->uid; //未读消息统计 $msg_map[] = ['to_uid', '=', $admin_id]; $msg_map[] = ['read_time', '=', 0]; $msg_map[] = ['status', '=', 1]; $msg_count = Db::name('Message')->where($msg_map)->count(); $statistics['msg_num'] = $msg_count; return to_assign(0, 'ok', $statistics); } else { $admin = Db::name('Admin')->where('id',$this->uid)->find(); if (get_cache('menu' . $this->uid)) { $list = get_cache('menu' . $this->uid); } else { $adminGroup = Db::name('PositionGroup')->where(['pid' => $admin['position_id']])->column('group_id'); $adminMenu = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('rules'); $adminMenus = []; foreach ($adminMenu as $k => $v) { $v = explode(',', $v); $adminMenus = array_merge($adminMenus, $v); } $menu = Db::name('AdminRule')->where(['menu' => 1, 'status' => 1])->where('id', 'in', $adminMenus)->order('sort asc,id asc')->select()->toArray(); $list = list_to_tree($menu); \think\facade\Cache::tag('adminMenu')->set('menu' . $this->uid, $list); } View::assign('menu', $list); View::assign('theme',$admin['theme']); View::assign('web',get_system_config('web')); return View(); } } public function main() { $install = false; if (file_exists(CMS_ROOT . 'app/install')) { $install = true; } $total = []; $adminCount = Db::name('Admin')->where('status', '1')->count(); $approveCount = Db::name('Approve')->count(); $noteCount = Db::name('Note')->where('status', '1')->count(); $expenseCount = Db::name('Expense')->where('delete_time', '0')->count(); $invoiceCount = Db::name('Invoice')->where('delete_time', '0')->count(); $total[] = array( 'name' => '员工', 'num' => $adminCount, ); $total[] = array( 'name' => '公告', 'num' => $noteCount, ); $total[] = array( 'name' => '审批', 'num' => $approveCount, ); $total[] = array( 'name' => '报销', 'num' => $expenseCount, ); $total[] = array( 'name' => '发票', 'num' => $invoiceCount, ); $handle=[ 'approve'=>Db::name('Approve')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")]])->count(), 'expenses'=>Db::name('Expense')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")],['delete_time', '=', 0]])->count(), 'invoice'=>Db::name('Invoice')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")],['delete_time', '=', 0]])->count(), 'income'=>Db::name('Invoice')->where([['is_cash', '<', 2],['admin_id','=',$this->uid],['check_status', '=', 5],['delete_time', '=', 0]])->count(), 'contract'=>0, 'task'=>0 ]; $module = Db::name('AdminModule')->column('name'); if (in_array('customer', $module)) { $whereCustomer = array(); $whereCustomerOr = array(); $uid = $this->uid; $dids = get_department_role($uid); $whereCustomer[] = ['delete_time', '=', 0]; $whereCustomerOr[] =['belong_uid', '=', $uid]; if(!empty($dids)){ $whereCustomerOr[] =['belong_did', 'in', $dids]; } $whereCustomerOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")]; $customerCount = Db::name('Customer')->where($whereCustomer) ->where(function ($query) use($whereCustomerOr) { $query->whereOr($whereCustomerOr); }) ->count(); $total[] = array( 'name' => '客户', 'num' => $customerCount, ); } if (in_array('contract', $module)) { $whereContract = array(); $whereContractOr = array(); $uid = $this->uid; $whereContract[] = ['delete_time', '=', 0]; $whereContractOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid]; $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")]; $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_admin_ids)")]; $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',flow_admin_ids)")]; $dids = get_department_role($uid); if(!empty($dids)){ $whereContractOr[] =['sign_did', 'in', $dids]; } $contractCount = Db::name('Contract')->where($whereContract) ->where(function ($query) use($whereContractOr) { $query->whereOr($whereContractOr); }) ->count(); $total[] = array( 'name' => '合同', 'num' => $contractCount, ); $handle['contract'] = Db::name('Contract')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")],['delete_time', '=', 0]])->count(); } if (in_array('project', $module)) { $project_ids = Db::name('ProjectUser')->where(['uid' => $this->uid, 'delete_time' => 0])->column('project_id'); $whereProject = []; $whereProject[] = ['delete_time', '=', 0]; $whereProject[] = ['id', 'in', $project_ids]; $projectCount = Db::name('Project')->where($whereProject)->count(); $whereOr = array(); $map1 = []; $map2 = []; $map3 = []; $map4 = []; $uid = $this->uid; $map1[] = ['admin_id', '=', $uid]; $map2[] = ['director_uid', '=', $uid]; $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$uid},assist_admin_ids)")]; $map4[] = ['project_id', 'in', $project_ids]; $whereOr =[$map1,$map2,$map3,$map4]; $taskCount = Db::name('ProjectTask') ->where(function ($query) use ($whereOr) { if (!empty($whereOr)) $query->whereOr($whereOr); }) ->where([['delete_time', '=', 0]])->count(); $total[] = array( 'name' => '项目', 'num' => $projectCount, ); $total[] = array( 'name' => '任务', 'num' => $taskCount, ); $handle['task'] = Db::name('ProjectTask')->where([['director_uid', '=', $this->uid],['flow_status', '<', 3],['delete_time', '=', 0]])->count(); } if (in_array('article', $module)) { $articleCount = Db::name('Article')->where([['delete_time', '=', 0],['uid', '=', $this->uid]])->count(); $total[] = array( 'name' => '文章', 'num' => $articleCount, ); } $adminGroup = Db::name('PositionGroup')->where(['pid' => $this->pid])->column('group_id'); $adminLayout = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('layouts'); $adminLayouts = []; foreach ($adminLayout as $k => $v) { $v = explode(',', $v); $adminLayouts = array_merge($adminLayouts, $v); } $layouts = get_config('layout'); $layout_selected = []; foreach ($layouts as $key =>$vo) { if (!empty($adminLayouts) and in_array($vo['id'], $adminLayouts)) { $layout_selected[] = $vo; } } // 首页统计 View::assign('layout_selected',$layout_selected); View::assign('total', $total); View::assign('handle', $handle); View::assign('install', $install); View::assign('TP_VERSION', \think\facade\App::version()); return View(); } //修改个人信息 public function edit_personal() { $param = get_params(); $uid = JWT_UID; Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param); $this->apiSuccess('修改成功'); } //修改密码 public function edit_password() { $param = get_params(); try { validate(AdminCheck::class)->scene('editPwd')->check($param); } catch (ValidateException $e) { // 验证失败 输出错误信息 $this->apiError($e->getError()); } $uid = JWT_UID; $admin = Db::name('Admin')->where(['id' => $uid])->find(); $old_psw = set_password($param['old_pwd'], $admin['salt']); if ($admin['pwd'] != $old_psw) { $this->apiError('旧密码错误'); } $salt = set_salt(20); $new_pwd = set_password($param['pwd'], $salt); $data = [ 'reg_pwd' => '', 'salt' => $salt, 'pwd' => $new_pwd, 'update_time' => time(), ]; Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data); $this->apiSuccess('修改成功'); } //上传文件 public function upload() { $uid = JWT_UID; $sourse = 'file'; if(isset($param['sourse'])){ $sourse = $param['sourse']; } if($sourse == 'file' || $sourse == 'tinymce'){ if(request()->file('file')){ $file = request()->file('file'); } else{ $this->apiError('没有选择上传文件'); } } else{ if (request()->file('editormd-image-file')) { $file = request()->file('editormd-image-file'); } else { $this->apiError('没有选择上传文件'); } } // 获取上传文件的hash散列值 $sha1 = $file->hash('sha1'); $md5 = $file->hash('md5'); $rule = [ 'image' => 'jpg,png,jpeg,gif', 'doc' => 'txt,doc,docx,ppt,pptx,xls,xlsx,pdf', 'file' => 'zip,gz,7z,rar,tar', 'video' => 'mpg,mp4,mpeg,avi,wmv,mov,flv,m4v', ]; $fileExt = $rule['image'] . ',' . $rule['doc'] . ',' . $rule['file'] . ',' . $rule['video']; //1M=1024*1024=1048576字节 $fileSize = 100 * 1024 * 1024; if (isset($param['type']) && $param['type']) { $fileExt = $rule[$param['type']]; } if (isset($param['size']) && $param['size']) { $fileSize = $param['size']; } $validate = \think\facade\Validate::rule([ 'image' => 'require|fileSize:' . $fileSize . '|fileExt:' . $fileExt, ]); $file_check['image'] = $file; if (!$validate->check($file_check)) { $this->apiError($validate->getError()); } // 日期前綴 $dataPath = date('Ym'); $use = 'thumb'; $filename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file, function () use ($md5) { return $md5; }); if ($filename) { //写入到附件表 $data = []; $path = get_config('filesystem.disks.public.url'); $data['filepath'] = $path . '/' . $filename; $data['name'] = $file->getOriginalName(); $data['mimetype'] = $file->getOriginalMime(); $data['fileext'] = $file->extension(); $data['filesize'] = $file->getSize(); $data['filename'] = $filename; $data['sha1'] = $sha1; $data['md5'] = $md5; $data['module'] = \think\facade\App::initialize()->http->getName(); $data['action'] = app('request')->action(); $data['uploadip'] = app('request')->ip(); $data['create_time'] = time(); $data['user_id'] = $uid; if ($data['module'] = 'admin') { //通过后台上传的文件直接审核通过 $data['status'] = 1; $data['admin_id'] = $data['user_id']; $data['audit_time'] = time(); } $data['use'] = request()->has('use') ? request()->param('use') : $use; //附件用处 $res['id'] = Db::name('file')->insertGetId($data); $res['filepath'] = $data['filepath']; $res['name'] = $data['name']; $res['filename'] = $data['filename']; $res['filesize'] = $data['filesize']; $res['fileext'] = $data['fileext']; add_log('upload', $data['user_id'], $data,'文件'); $this->apiSuccess('上传成功', $res); } else { $this->apiError('上传失败,请重试'); } } }