Index.php
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
use think\exception\ErrorException;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['departmentlist','projectlist'];
protected $noNeedRight = ['*'];
/**
* 首页
*
*/
public function index()
{
$this->success('请求成功');
}
/**
* 查询部门列表
* @return void
*/
public function departmentlist(){
$res=Db::name("department")->select();
$this->success('请求成功',$res);
}
/**
* 查询项目列表
* @return void
*/
public function projectlist(){
$res=Db::name("project")->select();
$this->success('请求成功',$res);
}
public function addworkinghours(){
$project_id = $this->request->param("project_id");//项目id
$content = $this->request->param("content");//内容
$working_hours = $this->request->param("working_hours");//工时
$reporttime = $this->request->param("reporttime");//内容
$project=Db::name("project")->where("id",$project_id)->find();
$data=[
'project_id'=>$project_id,
'department_id'=>$project['department_id'],
'working_hours'=>$working_hours,
'content'=>$content,
'user_id'=>$this->auth->id,
'createtime'=>time(),
'reporttime'=>$reporttime,
];
if($working_hours<=0){
$this->error("请填写工时");
}
try {
$res=Db::name("workinghours")->insert($data);
$project=Db::name("project")->where("id",$project_id)->find();
$all_working_hours=bcadd($project['all_working_hours'],$working_hours,2);
$updateproject=Db::name("project")->where("id",$project['id'])->update(['all_working_hours'=>$all_working_hours]);
if($res){
$this->success('添加成功');
}else{
$this->error("添加失败");
}
}catch (ErrorException $exception){
}
}
}