94 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace app\api\controller\backend;
 | 
						|
 | 
						|
use app\common\controller\Api;
 | 
						|
use app\api\model\Admin as AdminModel;
 | 
						|
use think\Db;
 | 
						|
 | 
						|
/**
 | 
						|
 * 加减分控制器
 | 
						|
 */
 | 
						|
class PlusMinusScoring extends Api
 | 
						|
{
 | 
						|
    protected $noNeedLogin = ['*'];
 | 
						|
    protected $noNeedRight = ['*'];
 | 
						|
 | 
						|
    /**
 | 
						|
     * 首页
 | 
						|
     *
 | 
						|
     */
 | 
						|
    public function getHierarchicalData()
 | 
						|
    {   
 | 
						|
        $page = $this->request->post('page',1);
 | 
						|
        $size = $this->request->post('size',10);
 | 
						|
        $where = [];
 | 
						|
 | 
						|
        // 从数据库中获取所有数据
 | 
						|
        $data = Db::name('plus_minus_scoring')
 | 
						|
                ->field('a.*,w.project_name as name')
 | 
						|
                ->alias('a')
 | 
						|
                ->join('basic_rating_table w','a.related_evaluation_project = w.id','LEFT')
 | 
						|
                ->where($where)
 | 
						|
                ->page($page,$size)
 | 
						|
                ->order('a.id desc')
 | 
						|
                ->select();
 | 
						|
        return $this->success('请求成功',$data);
 | 
						|
    }
 | 
						|
 
 | 
						|
    /**
 | 
						|
     *添加数据
 | 
						|
     */
 | 
						|
    public function create()
 | 
						|
    {
 | 
						|
        $data = $this->request->post();
 | 
						|
        $result = Db::name('plus_minus_scoring')->strict(false)->insert($data);
 | 
						|
        if ($result) {
 | 
						|
            return $this->success('添加成功',$result);
 | 
						|
        } else {
 | 
						|
            return $this->error('添加失败',$result);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 更新记录
 | 
						|
     *
 | 
						|
     * @param Request $request
 | 
						|
     * @param int $id
 | 
						|
     * @return \think\Response
 | 
						|
     */
 | 
						|
    public function update()
 | 
						|
    {   
 | 
						|
        $id = $this->request->post('id');
 | 
						|
        $data = $this->request->post();
 | 
						|
        $data['updatetime'] = date('Y-m-d H:i:s');
 | 
						|
        $result = Db::name('plus_minus_scoring')->where('id', $id)->strict(false)->update($data);
 | 
						|
        if ($result) {
 | 
						|
            return $this->success('更新成功',$result);
 | 
						|
        } else {
 | 
						|
            return $this->error('更新失败',$result);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * 删除记录
 | 
						|
     *
 | 
						|
     * @param int $id
 | 
						|
     * @return \think\Response
 | 
						|
     */
 | 
						|
    public function delete()
 | 
						|
    {   
 | 
						|
        $id = $this->request->post('id');
 | 
						|
        if(!$id){
 | 
						|
            return $this->error('缺少参数');
 | 
						|
        }
 | 
						|
        $result = Db::name('plus_minus_scoring')->delete($id);
 | 
						|
        if ($result) {
 | 
						|
            return $this->success('删除成功',$result);
 | 
						|
        } else {
 | 
						|
            return $this->error('删除失败',$result);
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |