+---------------------------------------------------------------------- | TickyPHP [ This is a freeware ] +---------------------------------------------------------------------- | Copyright (c) 2015 All rights reserved.
+----------------------------------------------------------------------
| Author: 罗敏贵 e-mail:minguiluo@163.com
newskey |
<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2015 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: Newskey.php 88712 2018-09-04 09:27:53 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:对应的表名:tky_newskey
* +----------------------------------------------------------------------
*/
namespace application\admin\controller;
use ticky\request;
use ticky\response;
class newskey extends auth {
//首页
public function index() {
$search = $this->search_frm();
$ret = $this->db->page('newskey', $search['sql'], 'id desc', $this->p);
$this->assign('page', $ret['page']);
$this->assign('items', $ret['items']);
$this->assign('search', $search['arr']);
$this->display('newskey/index');
}
// 批量删除
public function batchremove() {
$optype = request::post('optype', '');
if ($optype == "del") {
$ids = request::post('ids', []);
db('newskey')->where('id in(' . implode(",", $ids) . ')')->delete();
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('删除成功', '/admin/newskey');
}
} else {
if (is_array($_GET['name'])) {
foreach ($_GET['name'] as $id => $val) {
$data = array();
$data['name'] = $_GET['name'][$id];
$data['url'] = $_GET['url'][$id];
db('newskey')->where(['id' => $id])->update($data);
}
}
if (is_array($_GET['newname'])) {
foreach ($_GET['newname'] as $key => $value) {
if ($value) {
$data = array();
$data['name'] = $value;
$data['url'] = $_GET['newurl'][$key];
db('newskey')->where(['id' => $id])->add($data);
}
}
}
showmsg('关联链接更新成功', '/admin/newskey');
}
}
//查询条件
private function search_frm() {
$search = request::get('search', []);
$where = '1=1 ';
if ($keyid = trim($search['id'])) {
$where .= "and id = '{$keyid}' ";
}
if ($keyname = trim($search['name'])) {
$where .= "and name = '{$keyname}' ";
}
if ($keyurl = trim($search['url'])) {
$where .= "and url = '{$keyurl}' ";
}
return [
'arr' => $search,
'sql' => $where
];
}
}