Index.php 1.9 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\exception\ErrorException;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    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");//内容
        $data=[
            'project_id'=>$project_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){

        }

    }
}