lihai-oa/app/api/controller/Common.php

231 lines
8.3 KiB
PHP
Raw Normal View History

2023-10-30 11:55:00 +08:00
<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-3.0
* @link https://www.gougucms.com
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\ApiController;
2023-10-30 11:59:59 +08:00
use app\api\middleware\Auth;
2023-10-30 11:55:00 +08:00
use think\facade\Db;
class Common extends ApiController
{
2023-10-30 11:59:59 +08:00
protected $middleware = [
Auth::class => ['except' => []]
];
2023-10-30 11:55:00 +08:00
//获取部门
public function get_department()
{
$department = get_department();
return to_assign(0, '', $department);
}
//获取部门树形节点列表
public function get_department_tree()
{
$department = get_department();
$list = get_tree($department, 0, 2);
$data['trees'] = $list;
$this->apiSuccess('获取成功', $data);
}
//获取子部门所有员工
public function get_employee($did = 0)
{
$did = get_params('did');
if($did == 1){
$department = $did;
}
else{
$department = get_department_son($did);
}
$employee = Db::name('admin')
->field('a.id,a.did,a.position_id,a.mobile,a.name,a.nickname,a.sex,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();
$this->apiSuccess('获取成功', $employee);
}
2023-11-03 14:03:41 +08:00
//获取报销类型
public function get_expense_cate()
{
$expense_cate = Db::name('ExpenseCate')->where(['status' => 1])->field(['id', 'title'])->select()->toArray();
$this->apiSuccess('获取成功', $expense_cate);
}
2023-10-30 11:55:00 +08:00
2023-11-04 10:03:39 +08:00
//获取开票主体
public function get_invoice_subject()
{
$subject = Db::name('InvoiceSubject')->where(['status' => 1])->order('id desc')->select()->toArray();
$this->apiSuccess('获取成功', $subject);
}
2023-11-04 17:38:26 +08:00
//获取待办事项
public function get_todo_subject()
{
$this->uid = JWT_UID;
$subject = [
'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(),
2023-11-06 10:04:21 +08:00
// 'income'=>Db::name('Invoice')->where([['is_cash', '<', 2],['admin_id','=',$this->uid],['check_status', '=', 5],['delete_time', '=', 0]])->count(),
// 'contract'=>Db::name('Contract')->where([['', 'exp', Db::raw("FIND_IN_SET('{$this->uid}',check_admin_ids)")],['delete_time', '=', 0]])->count(),
2023-11-04 17:38:26 +08:00
'task'=>$handle['task'] = Db::name('ProjectTask')->where([['director_uid', '=', $this->uid],['flow_status', '<', 3],['delete_time', '=', 0]])->count()
];
$this->apiSuccess('获取成功', $subject);
}
2023-11-04 17:43:07 +08:00
//获取待办任务
public function get_task_list()
{
$this->uid = JWT_UID;
$where = array();
$whereOr = array();
$map1 = [];
$map2 = [];
$map3 = [];
$map1[] = ['admin_id', '=', $this->uid];
$map2[] = ['director_uid', '=', $this->uid];
$map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$this->uid},assist_admin_ids)")];
if($this->isAuthProject($this->uid)==0){
$whereOr =[$map1,$map2,$map3];
}
$where[] = ['delete_time', '=', 0];
$list = Db::name('ProjectTask')
->where(function ($query) use ($whereOr) {
if (!empty($whereOr))
$query->whereOr($whereOr);
})
->where($where)
->withoutField('content,md_content')
->order('flow_status asc')
->order('id desc')
->limit(8)
->select()->toArray();
foreach ($list as $key => &$val) {
$val['director_name'] = Db::name('Admin')->where(['id' => $val['director_uid']])->value('name');
if($val['end_time']>0){
$val['end_time'] = date('Y-m-d', $val['end_time']);
}
else{
$val['end_time'] = '-';
}
$val['flow_name'] = \app\project\model\ProjectTask::$FlowStatus[(int) $val['flow_status']];
}
$res['data'] = $list;
$this->apiSuccess('获取成功', $res);
}
private function isAuthProject($uid)
{
if($uid == 1){
return 1;
}
$map = [];
$map[] = ['name', '=', 'project_admin'];
$map[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',uids)")];
$count = Db::name('DataAuth')->where($map)->count();
return $count;
}
2023-11-06 10:15:38 +08:00
//上传文件
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('上传失败,请重试');
}
}
2023-10-30 11:55:00 +08:00
}