ProjectController.php 4.0 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/11
 * Time: 15:54
 */

namespace app\admin\controller;


use cmf\controller\AdminBaseController;
use think\Db;
use think\Validate;

class ProjectController extends AdminBaseController
{
    //产品方案
    public function index()
    {
        $id = $this->request->param('id', 1, 'intval');
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $validate = new Validate([
                'content' => 'require',
            ]);
            $validate->message([
                'content' => '内容不能为空',
            ]);
            if (!$validate->check($param)) {
                $this->error($validate->getError());
            }
            $param['update_time'] = time();
            Db::name('project')
                ->where('id', $id)
                ->update($param);
            $this->success('更新成功');
        } else {
            $data = Db::name('project')
                ->where('id', $id)
                ->find();
            $this->assign([
                'data' => $data,
            ]);
            return $this->fetch();
        }
    }

    //加入我们
    public function select()
    {
        $id = $this->request->param('id', 1, 'intval');
        if ($this->request->isPost()) {
            $param = $this->request->param();
            $validate = new Validate([
                'content' => 'require',
            ]);
            $validate->message([
                'content' => '内容不能为空',
            ]);
            if (!$validate->check($param)) {
                $this->error($validate->getError());
            }
            $param['update_time'] = time();
            Db::name('joinus')
                ->where('id', $id)
                ->update($param);
            $this->success('更新成功');
        } else {
            $data = Db::name('joinus')
                ->where('id', $id)
                ->find();
            $this->assign([
                'data' => $data,
            ]);
            return $this->fetch();
        }
    }

    //加入我们信息列表
    public function addlist()
    {
        $where['a.delete_time'] = ['eq',0];
        $param = $this->request->param();
        $startTime = empty($param['start_time']) ? '' : strtotime($param['start_time']);
        $endTime = empty($param['end_time']) ? '' : (strtotime($param['end_time']));
        if (!empty($startTime) && !empty($endTime)) {
            $where['a.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['a.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['a.create_time'] = ['<= time', $endTime];
            }
        }
        $data = Db::name('join')
            ->alias('a')
            ->join('user b','a.user_id = b.id')
            ->field('a.*,b.user_nickname')
            ->where($where)
            ->order('a.id desc')
            ->paginate(10);
        $list=$data->items();
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign([
            'data'=>$list,
            'page'=>$data->render(),
        ]);
        return $this->fetch();
    }

    //加入我们信息详情
    public function detail()
    {
        $param = $this->request->param();
        $id = $this->request->param('id', 1, 'intval');
        $data = Db::name('join')
            ->alias('a')
            ->join('user b','a.user_id = b.id')
            ->field('a.*,b.user_nickname')
            ->where('a.id',$id)
            ->find();
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign('data',$data);
        return $this->fetch();
    }
}