<?php
/**
* +----------------------------------------------------------------------
* | TickyPHP [ This is a freeware ]
* +----------------------------------------------------------------------
* | Copyright (c) 2019 All rights reserved.
* +----------------------------------------------------------------------
* | Author: 罗敏贵 <e-mail:minguiluo@163.com> <QQ:271391233>
* +----------------------------------------------------------------------
* | SVN: $Id: Membergroup.php 93514 2019-01-28 17:12:46 luomingui $
* +----------------------------------------------------------------------
* | 文件功能:对应的表名:tky_member_group
* +----------------------------------------------------------------------
*/
namespace application\member\controller;
use application\admin\controller\auth as auth;
use ticky\request;
use ticky\response;
class membergroup extends auth {
public function index() {
$search = $this->search_frm();
$ret = $this->db->page('member_group', $search['sql'], 'groupid', $this->p);
foreach ($ret['items'] as $row) {
$auts = '';
if (strpos($row['authority'], '1') !== false)
$auts = $auts . '发信息,';
if (strpos($row['authority'], '2') !== false)
$auts = $auts . '发评论,';
if (strpos($row['authority'], '3') !== false)
$auts = $auts . '发内容,';
if (strpos($row['authority'], '4') !== false)
$auts = $auts . '投稿免审核';
if ($row['authority'] == '0')
$auts = '';
$row['authority'] = $auts;
$data[] = $row;
}
$this->assign('page', $ret['page']);
$this->assign('items', $data);
$this->assign('search', $search['arr']);
$this->display('membergroup/index');
}
public function add() {
if (request::isPost()) {
$data = $this->post_frm();
$this->db->table('member_group')->add($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '添加成功']);
} else {
showmsg('添加成功', '/member/membergroup');
}
} else {
$this->assign('postUrl', '/member/membergroup/add');
$this->assign('action', '添加');
$this->display('membergroup/manage');
}
}
public function update() {
if (request::isPost()) {
$data = $this->post_frm();
$id = request::post('groupid', 0);
db('member_group')->where(['groupid' => $id])->update($data);
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('修改成功', '/member/membergroup');
}
} else {
$groupid = request::get('groupid', 0);
$item = db('member_group')->where(['groupid' => $groupid])->find();
$this->assign('postUrl', '/member/membergroup/update');
$this->assign('action', '修改');
$this->assign('item', $item);
$this->display('membergroup/manage');
}
}
public function delete() {
$id = request::post('id', 0);
$result = db('member_group')->where(['groupid' => $id])->delete();
if (request::isAjax()) {
if ($result) {
response::ajax(['code' => 200, 'msg' => '删除成功!']);
} else {
response::ajax(['code' => 403, 'msg' => '删除失败! id=' . $id]);
}
} else {
showmsg('删除成功', '/member/membergroup');
}
}
public function batchremove() {
$optype = request::post('optype', 'del');
$ids = request::post('ids', []);
if ($optype == "del") {
for ($i = 0; $i < count($ids); $i++) {
$id = $ids[$i];
db('member_group')->where(['groupid' => $id])->delete();
}
if (request::isAjax()) {
response::ajax(['code' => 200, 'msg' => '修改成功']);
} else {
showmsg('删除成功', '/member/membergroup');
}
}
}
private function search_frm() {
$search = request::get('search', []);
$where = '1=1 ';
if ($groupid = trim($search['groupid'])) {
$where .= "and groupid = '{$groupid}' ";
}
if ($name = trim($search['name'])) {
$where .= "and name = '{$name}' ";
}
if ($experience = trim($search['experience'])) {
$where .= "and experience = '{$experience}' ";
}
if ($icon = trim($search['icon'])) {
$where .= "and icon = '{$icon}' ";
}
if ($authority = trim($search['authority'])) {
$where .= "and authority = '{$authority}' ";
}
if ($description = trim($search['description'])) {
$where .= "and description = '{$description}' ";
}
if ($is_system = trim($search['is_system'])) {
$where .= "and is_system = '{$is_system}' ";
}
return [
'arr' => $search,
'sql' => $where
];
}
private function post_frm() {
$arr = array();
$arr['name'] = request::post('name', '');
$arr['experience'] = request::post('experience', '');
$arr['icon'] = request::post('icon', '');
$arr['authority'] = request::post('authority', '');
$arr['description'] = request::post('description', '');
$arr['is_system'] = request::post('is_system', '');
return $arr;
}
}