文件
mashangyoujiu/Application/Super/Controller/ContentController.class.php

152 行
5.0 KiB
PHP
可执行文件

<?php
namespace Super\Controller;
use Think\Controller;
//[1.4.14]
class ContentController extends EmptyController
{
public function indexs()
{
$arr = array(
'editad' => '/index.php/Super/Content/editad',
'add' => '/index.php/Super/Content/add',
'del' => '/index.php/Super/Content/del',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function getcontent()
{
$tap = I('post.keyword');
if (!empty($tap)) {
$where = array(
'titles'=>array('like',"%".$tap."%")
);
$tiplist = M('content')->where($where)->page((int)$_POST['page'], (int)$_POST['limit'])->order('id desc')->select();
$count = M("content")->where($where)->count();
}else{
$tiplist = M('content')->page((int)$_POST['page'], (int)$_POST['limit'])->order('id desc')->select();
$count = M("content")->count();
}
foreach ($tiplist as &$val) {
$val['name'] = M("help_t")->where(array('id' => $val['hid']))->getField("name_g");
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $tiplist;
$res['count'] = $count;
$this->ajaxReturn($res);
}
// 编辑
public function editad()
{
if (IS_POST) {
$data['hid'] = I('post.help');
$data['content'] = I('post.content');
$data['amendtime'] = time();
$data['titles'] = I('post.titles');
$id = I("post.id");
if (!empty($id)) {
$res = M('content')->where(array('id' => $id))->save($data);
} else {
$res = M("content")->add($data);
}
if ($res) {
$msg['status'] = 1;
$msg['msg'] = "编辑成功";
} else {
$msg['status'] = 2;
$msg['msg'] = "编辑失败";
}
$this->ajaxReturn($msg);
} else {
$id = I("get.id");
$info = M('content')->where(array('id' => $id))->find();
$foms = M("help")->where(array("id"=>$info['hid']))->find();
$info['content'] = htmlspecialchars_decode($info['content']);
$help_list = M('help')->where(array("cuid"=>array('neq',0)))->select();
$help_t = M('help_t')->select();
$this->assign('help_t', $help_t);
$this->assign('content', $info['content']);
$this->assign('foms', $foms);
$this->assign("info", $info);
$this->assign("help_list", $help_list);
$this->display("editad");
}
}
//添加
public function add()
{
if (IS_POST) {
$data['content'] = $_POST['content'];
$data['hid'] = $_POST['help'];
$data['titles'] = $_POST['titles'];
$data['addtime'] = time();
$data['amendtime'] = $data['addtime'];
if (M("content")->add($data)) {
$msg['status'] = 1;
$msg['msg'] = "添加成功";
} else {
$msg['status'] = 2;
$msg['msg'] = "添加失败";
}
$this->ajaxReturn($msg);
} else {
$help_t = M('help_t')->select();
$this->assign('help_t', $help_t);
$this->display("add");
}
}
//删除文章
public function del()
{
if (IS_POST) {
$where['id'] = I("post.id");
$res = M("content")->where($where)->delete();
if ($res) {
$msg['status'] = 1;
$msg['msg'] = "删除成功";
} else {
$msg['status'] = 2;
$msg['msg'] = "删除失败";
}
$this->ajaxReturn($msg);
}
}
public function Imgupload()
{
$upload = new \Think\Upload (); // 实例化上传类
$upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/2
$upload->exts = array(
'jpg',
'png',
'jpeg',
'gif'
); // 设置附件上传类型
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
$upload->savePath = '/Picture/Product/'; // 设置附件上传(子)目录
$upload->saveName = array(
'uniqid',
array('', true)
);
// 上传文件
$info = $upload->upload();
// dump($info);
if (!empty($info['file']['savename'])) {
$imgurl = "/" . $upload->rootPath . $info['file']['savepath'] . $info['file']['savename'];
}
// dump($imgurl);exit();
$data['filename'] = $info['file']['savename'];
$data['urls'] = $imgurl;
$this->ajaxReturn($data);
}
}