94 行
2.8 KiB
PHP
可执行文件
94 行
2.8 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Retail\Controller;
|
|
|
|
use Think\Controller;
|
|
|
|
//[1.5.84]
|
|
|
|
/**
|
|
* 门店公告
|
|
* Class StoreNoticeController
|
|
* @package Retail\Controller
|
|
*/
|
|
class StoreNoticeController extends BaseController
|
|
{
|
|
/**
|
|
* 消息列表展示
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->display();
|
|
}
|
|
|
|
/**
|
|
* 获取消息列表
|
|
* @throws \think\Exception
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function getNotice()
|
|
{
|
|
$map['merchantid'] = $this->merchant_id;
|
|
$count = M("retail_notice")->where($map)->count();
|
|
$notice = M('retail_notice')->where($map)->page($_GET['page'], $_GET['limit'])->order('addtime desc')->select();
|
|
foreach ($notice as &$val) {
|
|
$val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
|
|
$store_ids = $val['store_ids'] ? explode(',', $val['store_ids']) : [];
|
|
if (!in_array($this->store_id, $store_ids)) {
|
|
$val['state'] = 0;
|
|
$val['state_msg'] = '未读';
|
|
} else {
|
|
$val['state'] = 1;
|
|
$val['state_msg'] = '已读';
|
|
}
|
|
}
|
|
$res['status'] = 1;
|
|
$res['msg'] = $notice ? '获取成功' : '暂无数据';
|
|
$res['data'] = $notice;
|
|
$res['count'] = intval($count);
|
|
$this->ajaxReturn($res);
|
|
|
|
}
|
|
|
|
/**
|
|
* 阅读消息
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function readNotice()
|
|
{
|
|
$id = I('post.id');
|
|
$map = array(
|
|
'merchantid' => $this->merchant_id,
|
|
'id' => $id,
|
|
'_string' => "!FIND_IN_SET(" . $this->store_id . ",store_ids)",
|
|
);
|
|
$res = M("retail_notice")->where($map)->find();
|
|
if ($res) {
|
|
$save = ['store_ids' => $res['store_ids'] ? ($res['store_ids'] . ',' . $this->store_id) : $this->store_id];
|
|
$update = M("retail_notice")->where(['id' => $id])->save($save);
|
|
if ($update) {
|
|
$result = array(
|
|
'status' => 1,
|
|
'msg' => '读取成功',
|
|
);
|
|
} else {
|
|
$result = array(
|
|
'status' => 0,
|
|
'msg' => '读取失败,请稍后重试',
|
|
);
|
|
}
|
|
} else {
|
|
$result = array(
|
|
'status' => 0,
|
|
'msg' => '操作异常',
|
|
);
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
} |