function delete() { if (empty($_GET['id'])) { error(409); } $id = (int) $_GET['id']; if ($this->swoole->model->UserPhoto->del($id)) { return Swoole\JS::js_back('删除成功'); } }
function __construct($host, $port, $ssl = false) { $flag = $ssl ? SWOOLE_SOCK_TCP | SWOOLE_SSL : SWOOLE_SOCK_TCP; $this->sw = new \swoole_server($host, $port, self::$sw_mode, $flag); $this->host = $host; $this->port = $port; Swoole\Error::$stop = false; Swoole\JS::$return = true; $this->swooleSetting = array('backlog' => 128); }
function delete() { if (empty($_GET['id'])) { return "缺少参数"; } $id = intval($_GET['id']); if (!$this->isAllow(__METHOD__, $id)) { return '没有权限删除'; } if (table('project')->del($id)) { return Swoole\JS::js_back("删除成功"); } else { return Swoole\JS::js_back("删除失败"); } }
function login() { $this->session->start(); if (!empty($_GET['refer'])) { $refer = '?refer=' . $_GET['refer']; } else { $refer = ''; } //$this->db->debug = true; if ($this->user->isLogin()) { home: $this->swoole->http->redirect($this->swoole->config['user']['home_url'] . $refer); } elseif ($this->user->login($_POST['username'], $_POST['password'])) { $_SESSION['userinfo'] = $this->user->getUserInfo(); $_SESSION['realname'] = urldecode($_COOKIE['sysop_privilege_nick_name']); goto home; } else { Swoole\JS::js_back("用户名或密码错误"); } }
static function photoDetail($pid, $uid) { $param['uid'] = $uid; $param['id'] = $pid; $param['limit'] = 1; $photo = \Swoole::$php->model->UserPhoto->gets($param); if (empty($photo[0]['id'])) { Swoole\JS::js_back('还没有上传照片!'); exit; } $photo = $photo[0]; $param1['uid'] = $uid; $param1['where'] = "id>" . $pid; $param1['select'] = 'id'; $param1['order'] = 'id asc'; $param1['limit'] = 1; $nextid = \Swoole::$php->model->UserPhoto->gets($param1); if (empty($nextid)) { $first['uid'] = $param['uid']; $first['limit'] = 1; $first['order'] = 'id ASC'; $first['select'] = 'id'; $nextid = \Swoole::$php->model->UserPhoto->gets($first); } $param2['uid'] = $param['uid']; $param2['where'] = 'id<' . $pid; $param2['select'] = 'id'; $param2['limit'] = 1; $perid = \Swoole::$php->model->UserPhoto->gets($param2); if (empty($perid)) { $second['uid'] = $param['uid']; $second['limit'] = 1; $second['select'] = 'id'; $second['order'] = 'id DESC'; $perid = \Swoole::$php->model->UserPhoto->gets($second); } \Swoole::$php->tpl->assign('perid', $perid); \Swoole::$php->tpl->assign('nextid', $nextid); \Swoole::$php->tpl->assign('photo', $photo); }
function __construct($host, $port, $ssl = false) { $flag = $ssl ? SWOOLE_SOCK_TCP | SWOOLE_SSL : SWOOLE_SOCK_TCP; if (!empty(self::$options['base'])) { self::$swooleMode = SWOOLE_BASE; } elseif (extension_loaded('swoole')) { self::$swooleMode = SWOOLE_PROCESS; } $this->sw = new \swoole_server($host, $port, self::$swooleMode, $flag); $this->host = $host; $this->port = $port; Swoole\Error::$stop = false; Swoole\JS::$return = true; $this->runtimeSetting = array('backlog' => 128); }
function reply() { $this->session->start(); if (!$_SESSION['isLogin']) { return Swoole\JS::echojs("if(confirm('您还没有登录,是否调整到登录页面(请首先复制您的回答内容)?')) window.parent.location.href='/page/login/?'"); } if (!empty($_POST['reply'])) { $answer['content'] = $_POST['reply']; $answer['uid'] = $this->swoole->user->getUid(); $user = createModel('UserInfo')->get($answer['uid']); $answer['aid'] = (int) $_POST['aid']; $ask = createModel('AskSubject')->get($answer['aid']); //答案数量加1 $ask->qcount += 1; //如果是未答状态,则设置为已答 if ($ask->mstatus == 0) { $ask->mstatus = 1; } $ask->save(); //为用户增加积分,回答即加5分 $user->gold += 5; $user->save(); App\Api::sendmail($ask['uid'], $answer['uid'], "【系统】" . $user['nickname'] . "回答了你的提问.({$ask['title']})", $answer['content']); createModel('AskReply')->put($answer); return Swoole\JS::alert('发布成功') . Swoole\JS::echojs('window.parent.location.href = window.parent.location.href;'); } }
function cut() { if (empty($_GET['id'])) { return "error: requirer miki_page id"; } Swoole\Cookie::set('wiki_cut_id', $_GET['id'], 86400); return Swoole\JS::js_back("剪切成功,请到目标页面粘贴"); }
/** * 添加好友 */ function friend() { if (!empty($_GET['add'])) { $fm = model('UserFriend'); $get['frid'] = (int) $_GET['add']; $get['uid'] = $this->uid; $c = $fm->count($get); if ($c > 0) { return Swoole\JS::js_goto('你们已经是好友了!', '/person/myfriends/'); } else { $fm->put($get); return Swoole\JS::js_goto('添加好友成功!', '/person/myfriends/'); } } }
function index() { $_m = model('UserLogs'); if (isset($_GET['del'])) { $_m->del((int) $_GET['del']); return Swoole\JS::js_back('删除成功!'); } if (isset($_GET['act']) and $_GET['act'] == 'draft') { $gets['dir'] = 1; } else { $gets['dir'] = 0; } $gets['uid'] = $this->uid; $gets['page'] = empty($_GET['page']) ? 1 : (int) $_GET['page']; $gets['pagesize'] = 15; $pager = ''; $list = $_m->gets($gets, $pager); $this->swoole->tpl->assign('list', $list); $pager = array('total' => $pager->total, 'render' => $pager->render()); $this->swoole->tpl->assign('pager', $pager); $this->swoole->tpl->display(); }
function guestbook() { if ($_POST) { if (empty($_POST['realname'])) { Swoole\JS::js_back('姓名不能为空!'); exit; } if (empty($_POST['mobile'])) { Swoole\JS::js_back('电话不能为空!'); exit; } unset($_POST['x'], $_POST['y']); $_POST['product'] = implode(',', $_POST['product']); $_POST['source'] = implode(',', $_POST['source']); $php->model->Guestbook->put($_POST); Swoole\JS::js_goto('注册成功!', 'guestbook.php'); } if (!empty($_GET['id'])) { $gb = $php->model->Guestbook->get($_GET['id'])->get(); $php->tpl->assign('gb', $gb); $php->tpl->display('guestbook_detail.html'); } else { require 'dict/forms.php'; $pager = null; $gets['page'] = empty($_GET['page']) ? 1 : $_GET['page']; $gets['pagesize'] = 12; $gets['select'] = "id,username,title,addtime"; $gets['where'][] = "reply!=''"; $list = $php->model->Guestbook->gets($gets, $pager); $_forms['title'] = Swoole\Form::radio('title', $forms['title'], null, true, array('empty' => '请选择称谓')); $_forms['age'] = Swoole\Form::select('age', $forms['age'], null, true, array('empty' => '请选择年龄阶段')); $_forms['ctime'] = Swoole\Form::select('ctime', $forms['ctime'], null, true, array('empty' => '请选择方便沟通的时间')); $_forms['product'] = Swoole\Form::checkbox('product', $forms['product'], null, true); $_forms['source'] = Swoole\Form::checkbox('source', $forms['source'], null, true); $pager = array('total' => $pager->total, 'render' => $pager->render()); $php->tpl->assign('pager', $pager); $php->tpl->assign('forms', $_forms); $php->tpl->assign("list", $list); $php->tpl->display('guestbook.html'); } }
function add_module() { //\Swoole\Error::dbd(); if (empty($_GET['id']) and empty($_POST)) { $gets['select'] = 'id,username,realname'; $tmp = table('user')->gets($gets); $user = array(); foreach ($tmp as $t) { $name = !empty($t['realname']) ? $t['realname'] : ''; $user[$t['id']] = "{$name} [{$t['username']}]"; } $form['name'] = \Swoole\Form::input('name'); $form['intro'] = \Swoole\Form::text('intro'); $form['owner_uid'] = \Swoole\Form::select('owner_uid', $user, '', null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%")); $form['backup_uids'] = \Swoole\Form::muti_select('backup_uids[]', $user, array(), null, array('class' => 'select2 select2-offscreen', 'multiple' => "1", 'style' => "width:100%"), false); $tmp = table('project')->gets(array("order" => "id desc")); $project = array(); foreach ($tmp as $t) { $project[$t['id']] = $t['name']; } $form['project_id'] = \Swoole\Form::select('project_id', $project, '', null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%")); $this->assign('form', $form); $this->display(); } elseif (!empty($_GET['id']) and empty($_POST)) { $id = (int) $_GET['id']; $module = table("module")->get($id)->get(); $gets['select'] = '*'; $tmp = table('user')->gets($gets); $user = array(); foreach ($tmp as $t) { $name = !empty($t['realname']) ? $t['realname'] : ''; $user[$t['id']] = "{$name} [{$t['username']}]"; } $form['id'] = \Swoole\Form::hidden('id', $module['id']); $form['name'] = \Swoole\Form::input('name', $module['name']); $form['intro'] = \Swoole\Form::text('intro', $module['intro']); $form['owner_uid'] = \Swoole\Form::select('owner_uid', $user, $module['owner_uid'], null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%")); $form['backup_uids'] = \Swoole\Form::muti_select('backup_uids[]', $user, explode(',', $module['backup_uids']), null, array('class' => 'select2 select2-offscreen', 'multiple' => "1", 'style' => "width:100%"), false); $tmp = table('project')->gets(array("order" => "id desc")); $project = array(); foreach ($tmp as $t) { $project[$t['id']] = $t['name']; } $form['project_id'] = \Swoole\Form::select('project_id', $project, $module['project_id'], null, array('class' => 'select2 select2-offscreen', 'style' => "width:100%")); $this->assign('form', $form); $this->display(); } elseif (!empty($_POST) and empty($_POST['id'])) { $in['name'] = trim($_POST['name']); $in['owner_uid'] = trim($_POST['owner_uid']); if (empty($in['owner_uid'])) { $in['owner_uid'] = $this->uid; } $in['project_id'] = trim($_POST['project_id']); $backup_uids = ''; if (!empty($_POST['backup_uids'])) { $backup_uids = implode(',', $_POST['backup_uids']); } $in['backup_uids'] = $backup_uids; // $in['backup_name'] = trim($_POST['backup_name']); $in['intro'] = trim($_POST['intro']); $c = table('module')->count(array('name' => $in['name'])); if ($c > 0) { \Swoole\JS::js_goto("操作失败,已存在同名模块", "/setting/add_module/"); } else { $id = table('module')->put($in); if ($id) { \Swoole\JS::js_goto("操作成功", "/setting/add_module/"); \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} add module success {$id} : " . print_r($in, 1)); } else { \Swoole\JS::js_goto("操作失败", "/setting/add_module/"); \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} add module failed: " . print_r($in, 1)); } } } else { $id = (int) $_POST['id']; $in['name'] = trim($_POST['name']); $in['owner_uid'] = trim($_POST['owner_uid']); $in['project_id'] = trim($_POST['project_id']); $backup_uids = ''; if (!empty($_POST['backup_uids'])) { $backup_uids = implode(',', $_POST['backup_uids']); } $in['backup_uids'] = $backup_uids; $in['intro'] = trim($_POST['intro']); $where['name'] = $in['name']; $where['where'][] = "id !={$id}"; $c = table('module')->count($where); if ($c > 0) { \Swoole\JS::js_goto("操作失败,已存在同名模块", "/setting/module_list/"); } else { $res = table('module')->set($id, $in); if ($res) { \Swoole\JS::js_goto("操作成功", "/setting/module_list/"); \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} modify module success {$id} : " . print_r($in, 1)); } else { \Swoole\JS::js_goto("操作失败", "/setting/module_list/"); \Swoole::$php->log->put("{$_SESSION['userinfo']['username']} modify module failed: " . print_r($in, 1)); } } } }
function delete_category() { if (isset($_GET['id'])) { $id = (int) $_GET['id']; $res = table('tiny_url_category')->set($id, array('status' => 2)); $msg = $res ? '操作成功' : '操作失败'; \Swoole\JS::js_goto($msg, '/url_shortener/category_list'); } else { $this->http->status(302); $this->http->header('Location', '/url_shortener/category_list'); } }
function reset_passwd() { //不是超级用户不能查看修改用户 if ($this->userinfo['usertype'] != 0) { return "access deny"; } if (empty($_GET['id'])) { return \Swoole\JS::js_back("操作不合法"); } $uid = intval($_GET['id']); $user = table('user')->get($uid); if (!$user->exist()) { return \Swoole\JS::js_back("用户不存在"); } $user->password = Swoole\Auth::mkpasswd($user->username, '123456'); if ($user->save()) { return \Swoole\JS::js_back("重置密码成功"); } else { return \Swoole\JS::js_back("重置密码失败,请稍后重试"); } }