File: /www/wwwroot//crm.jmfdbn.com/application/admin/controller/FbProject.php
<?php
// +----------------------------------------------------------------------
// | Author: Moli <332287662@qq.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | FB项目
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\common\controller\Adminbase;
use think\Db;
class FbProject extends Adminbase
{
// FB项目列表
public function index()
{
if ($this->request->isAjax()) {
$data = $this->request->get('');
$page =$data['page'];
$limit =$data['limit'];
$list = Db::name('fb_project')->select();
$_list = Db::name('fb_project')->page($page, $limit)->order(array('id' => 'DESC'))->select();
$total = count($list);
$result = array("code" => 0, 'count' => $total, "data" => $_list);
return json($result);
} else {
return $this->fetch();
}
}
// 添加FB项目
public function add()
{
if ($this->request->isPost()) {
$data = $this->request->post('');
$creattime = date('Y-m-d H:i:s', time());
$data = ['title' => $data['title'], 'creattime' => $creattime];
$result = Db::name('fb_project')
->data($data)
->insert();
if ($result) {
$this->success("添加项目成功!", url('admin/fb_project/index'));
} else {
$this->success('添加失败!');
}
} else {
return $this->fetch();
}
}
// 编辑FB项目
public function edit()
{
if ($this->request->isPost()) {
$data = $this->request->post('');
$result = Db::name('fb_project')
->where('id', $data['id'])
->data(['title' => $data['title']])
->update();
if ($result) {
$this->success("修改成功!");
} else {
$this->error('修改失败!');
}
} else {
$id = $this->request->param('id/d');
$ishas = Db::name('fb_project')->where('id', $id)->find();
if (empty($ishas)) {
$this->error('该信息不存在!');
}
$this->assign("data", $ishas);
return $this->fetch();
}
}
// 删除FB项目
public function del()
{
$id = $this->request->param('id/d');
if (empty($id)) {
$this->error('请指定需要删除的项目ID!');
}
$ishas = Db::name('fb_project')->where('id', $id)->find();
if ($ishas) {
Db::name('fb_project')
->where('id', $id)
->delete();
$this->success("删除成功!");
}
}
}