167 行
5.2 KiB
PHP
可执行文件
167 行
5.2 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Admin\Controller;
|
|
|
|
use Think\Controller;
|
|
|
|
//[1.5.84]
|
|
class ResourceController extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
$arr = array(
|
|
'add' => '/index.php/Admin/Resource/add', //添加资料
|
|
'update' => '/index.php/Admin/Resource/update', //编辑资料
|
|
'upstatus' => '/index.php/Admin/Resource/upstatus', //修改资料状态
|
|
'delUser' => '/index.php/Admin/Resource/delUser', //删除资料
|
|
);
|
|
$authArr = checkFunction($arr);
|
|
$this->assign('authArr', $authArr);
|
|
$this->display();
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$id = I('get.id');
|
|
if($id){
|
|
$list = M("retail_resource")->where(array('id' => $id))->find();
|
|
$this->assign('list', $list);
|
|
}
|
|
$this->display();
|
|
}
|
|
|
|
// 删除资料
|
|
public function delUser()
|
|
{
|
|
$id = I('post.id');
|
|
$list = M("retail_resource")->where('id =' . $id)->delete();
|
|
if ($list) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = "删除成功";
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = "删除失败";
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
// 修改上下架
|
|
public function upstatus()
|
|
{
|
|
$data['status'] = I('post.status');
|
|
$id = I('post.id');
|
|
$state = M("retail_resource")->where('id=' . $id)->save($data);
|
|
if ($state) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = "修改成功";
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = "修改失败";
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
/**
|
|
* 获取表单数据
|
|
*/
|
|
public function getData()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
$news['pid'] = $user['pid'];
|
|
$list = M("retail_resource")
|
|
->where($news)
|
|
->page($_POST['page'], $_POST['limit'])
|
|
->select();
|
|
foreach ($list as $k => &$value) {
|
|
$value['index'] = round(($_POST['page'] - 1) * $_POST['limit'] + $k + 1, 2);
|
|
$value['content'] = htmlspecialchars_decode($value['content']);
|
|
}
|
|
$count = M("retail_resource")->where($news)->count();
|
|
$res['code'] = 0;
|
|
$res['msg'] = '';
|
|
$res['data'] = $list;
|
|
$res['count'] = $count;
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
|
|
public function addResource()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
if (!empty($user)) {
|
|
$id = I('post.id');
|
|
$image_id = I('post.image_id');
|
|
if (!empty($image_id)) {
|
|
$data['image'] = D('ImageGallery')->getOneField(array('id' => $image_id), 'path');
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '请上传资料图片';
|
|
}
|
|
$data['title'] = I('post.title');
|
|
$data['docuat'] = I('post.docuat');
|
|
$data['content'] = I('content');
|
|
$data['pid'] = $user['pid'];
|
|
$data['image_id'] = $image_id;
|
|
if(!$id){
|
|
$data['time'] = time();
|
|
$list = M("retail_resource")->add($data);
|
|
}else{
|
|
$list = M("retail_resource")->where(array('id'=>$id))->save($data);
|
|
}
|
|
if ($list > 0) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = "添加成功";
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = "添加失败";
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
|
|
|
|
public function editResource()
|
|
{
|
|
$user = session('admin_userinfo');
|
|
if (!empty($user)) {
|
|
$id = I('post.id');
|
|
$image_id = I('post.image_id');
|
|
$old = M("retail_resource")->where(array('id' => $id))->find();
|
|
if (!empty($old)) {
|
|
if (empty($image_id)) {
|
|
$res['status'] = 0;
|
|
$res['msg'] = "未选择图片";
|
|
$this->ajaxReturn($res);
|
|
} else {
|
|
if ($image_id != $old['image_id']) {
|
|
$data['image'] = D('ImageGallery')->getOneField(array('id' => $image_id), 'path');
|
|
}
|
|
}
|
|
$data['image_id'] = $image_id;
|
|
$data['title'] = I('post.title');
|
|
$data['docuat'] = I('post.docuat');
|
|
$data['content'] = I('content');
|
|
$data['time'] = time();
|
|
$data['pid'] = $user['pid'];
|
|
$update = M("retail_resource")->where(array('id' => $id))->save($data);
|
|
if ($update > 0) {
|
|
$res['status'] = 1;
|
|
$res['msg'] = "修改成功";
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = "修改失败";
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '操作有误';
|
|
}
|
|
} else {
|
|
$res['status'] = 0;
|
|
$res['msg'] = '登录超时';
|
|
}
|
|
$this->ajaxReturn($res);
|
|
}
|
|
} |