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

410 行
13 KiB
PHP
可执行文件

<?php
namespace Super\Controller;
use Think\Controller;
//[1.4.14]
class HelpController extends EmptyController
{
public function index()
{
$arr = array(
'node_sec' => '/index.php/Super/Help/node_sec',
'node_add' => '/index.php/Super/Help/node_add',
'node_del' => '/index.php/Super/Help/node_del',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
public function getindex()
{
if (I('post.keyword')) {
$tap = I('post.keyword');
$condition['name_g'] = array('like', "%" . $tap . "%");
$where['_complex'] = $condition;
}
$count = M("help_t")->where($where)->count();
$rows = M("help_t")->where($where)->page((int)$_POST['page'], (int)$_POST['limit'])->order('id desc')->select();
foreach ($rows as &$val) {
$val['heid'] = M('help_t')->where(array('id' => $val['heid']))->getField('name_g');
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $rows;
$res['count'] = $count;
$this->ajaxReturn($res);
}
/*
* 修改
* */
public function node_sec()
{
if ($_POST) {
$data['status'] = 0;
if (M('help_t')->where([
'id' => $_POST['id']
])->count()) {
M('help_t')->where([
'id' => $_POST['id']
])->save([
'name_g' => $_POST['Text']
]);
$data['status'] = 1;
}
$this->ajaxReturn($data);
} else {
$id = $_GET['id'];
$info = M('help_t')->where(['id' => $id])->find();
$this->assign('info', $info);
$this->assign('id', $id);
$this->display();
}
}
/*
* 添加
* */
public function node_add()
{
if ($_POST) {
$data['status'] = 0;
$data['msg'] = "添加失败";
if (M('help_t')->data([
'name_g' => $_POST['Text'],
'addtime' => time(),
])->add()) {
$data['status'] = 1;
$data['msg'] = "添加成功";
}
$this->ajaxReturn($data);
} else {
$this->display();
}
}
public function change()
{
$where['heid'] = $_POST['id'];
$where['cuid'] = 0;
$info = M('help')->where($where)->select();
$data['status'] = 1;
$data['info'] = $info;
$this->ajaxReturn($data);
}
/*
* 删除
* */
public function node_del()
{
$data['status'] = 0;
$data['msg'] = "删除失败";
if (M('help_t')->where([
'id' => $_POST['id']
])->delete()) {
$data['status'] = 1;
$data['msg'] = "删除成功";
}
$this->ajaxReturn($data);
}
//产品首页
public function products()
{
$this->display();
}
public function getproduct()
{
if (I('get.keyword')) {
$tap = I('get.keyword');
$condition['name'] = array('like', $tap . "%");
$where['_complex'] = $condition;
}
$info = M('product')->page((int)$_GET['page'], (int)$_GET['limit'])->order('id desc')->select();
$products = M('product')->select();
foreach ($info as &$val) {
$val['addtime'] = date('Y-m-d', $val['addtime']);
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $info;
$res['count'] = count($products);
$this->ajaxReturn($res);
}
//添加产品
public function add_product()
{
if ($_POST) {
$where['name'] = I('post.name');
$where['brief'] = I('post.brief');
$where['url'] = I('post.url');
$where['addtime'] = time();
$upload = new \Think\Upload (); // 实例化上传类
$upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/2
$upload->exts = array(
'jpg',
'png',
'jpeg',
); // 设置附件上传类型
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
$upload->savePath = '/Picture/Product/'; // 设置附件上传(子)目录
$upload->saveName = array(
'uniqid',
array('', true)
);
// 上传文件
$info = $upload->upload();
if (!empty($info['logo']['savename'])) {
$where['logo'] = "/" . $upload->rootPath . $info['logo']['savepath'] . $info['logo']['savename'];
}
$res = M('product')->add($where);
if ($res) {
$rt['status'] = 1;
$rt['msg'] = '添加成功';
} else {
$rt['status'] = 2;
$rt['msg'] = '添加失败';
}
$this->ajaxReturn($rt);
}
$this->display();
}
//编辑产品
public function amend_product()
{
if ($_POST) {
$where['name'] = I('post.name');
$where['brief'] = I('post.brief');
$data['id'] = I('post.id');
$where['url'] = I('post.url');
$where['addtime'] = time();
$upload = new \Think\Upload (); // 实例化上传类
$upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/2
$upload->exts = array(
'jpg',
'png',
'jpeg',
); // 设置附件上传类型
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
$upload->savePath = '/Picture/Product/'; // 设置附件上传(子)目录
$upload->saveName = array(
'uniqid',
array('', true)
);
// 上传文件
$info = $upload->upload();
if (!empty($info['logo']['savename'])) {
$where['logo'] = "/" . $upload->rootPath . $info['logo']['savepath'] . $info['logo']['savename'];
}
$res = M('product')->where($data)->save($where);
if ($res) {
$rt['status'] = 1;
$rt['msg'] = '修改成功';
} else {
$rt['status'] = 2;
$rt['msg'] = '修改失败';
}
$this->ajaxReturn($rt);
} else {
$id = $_GET['id'];
$where['id'] = $_GET['id'];
$info = M('product')->where($where)->find();
$this->assign('info', $info);
$this->assign('id', $id);
}
$this->display();
}
//删除产品
public function del()
{
if ($_POST) {
$where['id'] = $_POST['id'];
$res = M('product')->where($where)->delete();
if ($res) {
$data['status'] = 1;
$data['msg'] = "删除成功";
} else {
$data['status'] = 0;
$data['msg'] = "删除失败";
}
$this->ajaxReturn($data);
}
$this->display();
}
//用户手册首页
public function manuals()
{
$this->display();
}
public function getmanual()
{
if (I('get.keyword')) {
$tap = I('get.keyword');
$condition['name'] = array('like', $tap . "%");
$where['_complex'] = $condition;
}
$info = M('manual')->page((int)$_GET['page'], (int)$_GET['limit'])->order('id desc')->select();
$manual = M('manual')->select();
foreach ($info as &$val) {
$val['cate_name'] = M('product')->where('id = "' . $val['cate_id'] . '"')->getField('name');
$val['addtime'] = date('Y-m-d', $val['addtime']);
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $info;
$res['count'] = count($manual);
$this->ajaxReturn($res);
}
//添加手册
public function add_manual()
{
if ($_POST) {
$where['manual'] = I('post.name');
$where['addtime'] = time();
$where['amendtime'] = $where['addtime'];
$where['cate_id'] = I('post.cateid');
$upload = new \Think\Upload (); // 实例化上传类
$upload->maxSize = 30000000; // 设置附件上传大小13
$upload->exts = array(
'jpg',
'png',
'jpeg',
'doc',
'txt',
'pdf',
'docx'
); // 设置附件上传类型
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
$upload->savePath = '/Picture/Product/'; // 设置附件上传(子)目录
$upload->saveName = array(
'uniqid',
array('', true)
);
// 上传文件
$info = $upload->upload();
if (!empty($info['logo']['savename'])) {
$where['logo'] = "/" . $upload->rootPath . $info['logo']['savepath'] . $info['logo']['savename'];
}
if (!empty($info['file_url']['savename'])) {
$where['file_url'] = "/" . $upload->rootPath . $info['file_url']['savepath'] . $info['file_url']['savename'];
$where['file_name'] = $info['file_url']['name'];
}
$res = M('manual')->add($where);
if ($res) {
$rt['status'] = 1;
$rt['msg'] = '添加成功';
} else {
$rt['status'] = 2;
$rt['msg'] = '添加失败';
}
$this->ajaxReturn($rt);
}
$info = M('product')->select();
$this->assign('info', $info);
$this->display();
}
//编辑手册
public function amend_manual()
{
if ($_POST) {
$where['manual'] = I('post.name');
$data['id'] = I('post.id');
$where['amendtime'] = time();
$upload = new \Think\Upload (); // 实例化上传类
$upload->maxSize = 30000000; // 设置附件上传大小13
$upload->exts = array(
'jpg',
'png',
'jpeg',
'doc',
'txt',
'pdf',
'docx'
); // 设置附件上传类型
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
$upload->savePath = '/Picture/Product/'; // 设置附件上传(子)目录
$upload->saveName = array(
'uniqid',
array('', true)
);
// 上传文件
$info = $upload->upload();
if (!empty($info['logo']['savename'])) {
$where['logo'] = "/" . $upload->rootPath . $info['logo']['savepath'] . $info['logo']['savename'];
}
if (!empty($info['file_url']['savename'])) {
$where['file_url'] = "/" . $upload->rootPath . $info['file_url']['savepath'] . $info['file_url']['savename'];
$where['file_name'] = $info['file_url']['name'];
}
$where['cate_id'] = I('post.cateid');
$res = M('manual')->where($data)->save($where);
if ($res) {
$rt['status'] = 1;
$rt['msg'] = '修改成功';
} else {
$rt['status'] = 2;
$rt['msg'] = '修改失败';
}
$this->ajaxReturn($rt);
} else {
$id = $_GET['id'];
$where['id'] = $_GET['id'];
$info = M('manual')->where($where)->find();
$this->assign('info', $info);
$this->assign('id', $id);
}
$cate = M('product')->select();
$this->assign('infos', $cate);
$this->display();
}
//删除手册
public function del_manual()
{
if ($_POST) {
$where['id'] = $_POST['id'];
$res = M('manual')->where($where)->delete();
if ($res) {
$data['status'] = 1;
$data['msg'] = "删除成功";
} else {
$data['status'] = 0;
$data['msg'] = "删除失败";
}
$this->ajaxReturn($data);
}
$this->display();
}
}
?>