文件
mashangyoujiu/Application/Retail/Controller/NoticeController.class.php

205 行
7.0 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace Retail\Controller;
use Think\Controller;
//[1.4.13]
class NoticeController extends BaseController
{
// 显示主页
public function index()
{
$arr = array(
'add' => '/index.php/Retail/Notice/add',
'edit' => '/index.php/Retail/Notice/edit',
'del' => '/index.php/Retail/Notice/del',
'noticeon' => '/index.php/Retail/Notice/noticeon',
);
$authArr = checkFunction($arr);
$this->assign('authArr', $authArr);
$this->display();
}
// 数据表格
public function getnotice()
{
$user = session('ls_userinfo');
$map['merchantid'] = $user['merchantid'];
$count = M("retail_notice")->where($map)->count();
$notice = M('retail_notice')->where($map)->page($_POST['page'], $_POST['limit'])->order('addtime desc')->select();
foreach ($notice as &$val) {
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
}
$res['code'] = 0;
$res['msg'] = '';
$res['data'] = $notice;
$res['count'] = $count;
$this->ajaxReturn($res);
}
// 添加公告
public function add()
{
$this->display();
}
// 执行添加操作
public function doadd()
{
$user = session('ls_userinfo');
$data1 = I('post.');
if (!empty($data1)) {
$data['title'] = $data1['title'];
$data['content'] = $data1['content'];
$data['addtime'] = time();
$data['merchantid'] = $user['merchantid'];
$notice_res = M('retail_notice')->add($data);
if (!empty($notice_res)) {
$res['status'] = 1;
$res['msg'] = '添加成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '新增公告';//操作行为描述
action_log($source,$type,$request_data,$desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '添加失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数缺失';
}
$this->ajaxReturn($res);
}
// 启用
public function noticeon()
{
$id = I('post.id');
$data['stype'] = 1;
$saveres = M('retail_notice')->where(array('id' => $id))->save($data);
if ($saveres) {
$res['status'] = 1;
$res['msg'] = '修改成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '启用公告';//操作行为描述
action_log($source,$type,$request_data,$desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
$this->ajaxReturn($res);
}
// 禁用
public function noticeoff()
{
$id = I('post.id');
$data['stype'] = 2;
$saveres = M('retail_notice')->where(array('id' => $id))->save($data);
if ($saveres) {
$res['status'] = 1;
$res['msg'] = '修改成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '禁用公告';//操作行为描述
action_log($source,$type,$request_data,$desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
$this->ajaxReturn($res);
}
// 渲染 修改
public function edit($id)
{
$edit_data = M('retail_notice')->where(array('id' => $id))->find();
$this->assign('edit_data', $edit_data);
$this->display();
}
// 执行 修改
public function doedit()
{
$id = I('post.id');
$title = I('post.title');
$content = I('post.content');
if (!empty($id) && !empty($title) && !empty($content)) {
$data = M('retail_notice')->where(array('id' => $id))->find();
if (!empty($data)) {
if ($data['title'] == $title && $data['content'] == $content) {
$res['status'] = 0;
$res['msg'] = '无修改数据';
} else {
if ($data['title'] != $title) {
$map['title'] = $title;
}
if ($data['content'] != $content) {
$map['content'] = $content;
}
$edit_res = M('retail_notice')->where(array('id' => $id))->save($map);
if (!empty($edit_res)) {
$res['status'] = 1;
$res['msg'] = '修改成功';
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '编辑公告';//操作行为描述
action_log($source,$type,$request_data,$desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '修改失败';
}
}
} else {
$res['status'] = 0;
$res['msg'] = '未查询到该条公告';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数不全';
}
$this->ajaxReturn($res);
}
// 删除
public function del()
{
$id = I('post.id');
if (!empty($id)) {
$del_res = M('retail_notice')->where(array('id' => $id))->delete();
if (!empty($del_res)) {
$res['status'] = 1;
//操作日志记录
$source = 0;//请求来源: 0pc系统 1小助手
$type = 3;//平台:1合伙人端 2代理商端 3商户端 4门店端
$request_data = json_encode($_POST);//请求参数 json数据
$desc = '删除公告';//操作行为描述
action_log($source,$type,$request_data,$desc);
//end
} else {
$res['status'] = 0;
$res['msg'] = '删除失败';
}
} else {
$res['status'] = 0;
$res['msg'] = '参数不全';
}
$this->ajaxReturn($res);
}
}
?>