| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\SinaNotice;
- use think\admin\Controller;
- use think\admin\service\AdminService;
- use think\admin\helper\QueryHelper;
- /**
- * 通知管理
- * Class Notice
- * @package app\admin\controller
- */
- class Notice extends Controller
- {
- /**
- * 设置默认操作表
- * @var string
- */
- private $table = 'SinaNotice';
- /**
- * 通知管理
- * @auth true
- * @menu true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function index()
- {
- $this->_query(SinaNotice::class)->layTable(function () {
- $this->title = '通知管理';
- }, function (QueryHelper $query) {
- });
- }
- /**
- * 数据列表处理
- * @param array $data
- */
- protected function _page_filter(array &$data)
- {
- foreach ($data as &$vo) {
- $vo['created_at'] = date('Y-m-d H:i', $vo['created_at']);
- $vo['updated_at'] = date('Y-m-d H:i', $vo['updated_at']);
- }
- }
- /**
- * 添加通知
- * @auth true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function add()
- {
- $this->_applyFormToken();
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑通知
- * @auth true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit()
- {
- $this->_applyFormToken();
- $this->_form($this->table, 'form');
- }
- /**
- * 表单数据处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- protected function _form_filter(array &$data)
- {
- if ($this->request->isPost()) {
- if (isset($data['id']) && $data['id'] > 0) {
- $data['updated_at'] = time();
- } else {
- $data['created_at'] = time();
- $data['updated_at'] = time();
- $data['created_by'] = AdminService::instance()->getUserId();
- }
- } else {
- }
- }
- /**
- * 删除通知
- * @auth true
- * @throws \think\db\exception\DbException
- */
- public function remove()
- {
- $this->_checkInput();
- $this->_delete($this->table);
- }
- /**
- * 检查输入变量
- */
- private function _checkInput()
- {
- }
- /**
- * 表单结果处理
- * @param bool $result
- */
- protected function _add_form_result(bool $result)
- {
- if ($result) {
- $id = $this->app->db->name($this->table)->getLastInsID();
- sysoplog('通知管理', "添加通知[{$id}]成功");
- }
- }
- /**
- * 表单结果处理
- * @param boolean $result
- */
- protected function _edit_form_result(bool $result)
- {
- if ($result) {
- $id = input('id') ?: 0;
- sysoplog('通知管理', "修改通知[{$id}]成功");
- if ($id == AdminService::instance()->getUserId()) {
- $this->success('通知修改成功!', 'javascript:location.reload()');
- } else {
- $this->success('通知修改成功!');
- }
- }
- }
- /**
- * 删除结果处理
- * @param boolean $result
- */
- protected function _remove_delete_result(bool $result)
- {
- if ($result) {
- $id = input('id') ?: 0;
- sysoplog('通知管理', "删除通知[{$id}]成功");
- }
- }
- }
|