Skip to content

Commit

Permalink
Fix invite,Message,Cron Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
sendya committed Apr 10, 2016
1 parent c22aab4 commit 3e47271
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 216 deletions.
17 changes: 12 additions & 5 deletions Library/Controller/Admin/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@

use Core\Template;
use Model\Cron as CronModel;
use Model\User;

class Cron extends AdminListener {
/**
* Class Cron
* @Admin
* @Authorization
* @package Controller\Admin
*/
class Cron {

public function index() {
global $user;
$cronList = CronModel::getCronArray();

include Template::load('/admin/cron');
$data['user'] = User::getCurrent();
$data['cronList'] = CronModel::getCronArray();
Template::setContext($data);
Template::setView('admin/cron');
}

}
132 changes: 67 additions & 65 deletions Library/Controller/Admin/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,105 +9,107 @@

use \Core\Template;

use \Model\Invite as InviteModel;
use Model\Invite as InviteModel;
use Model\User;
use Helper\Option;

/**
* Controller: 邀请码
* @Admin
* @Authorization
* @package Controller\Admin
*/
class Invite extends AdminListener {
class Invite {

public function inviteList() {
//throw new \Core\Error("user list", 505);
global $user;

$inviteList = InviteModel::GetInviteArray(0);

include Template::load('/admin/invite');
$data['user'] = User::getCurrent();
$data['inviteList'] = InviteModel::getInviteArray(0);
$data['planList'] = json_decode(Option::get('custom_plan_name'), true);
Template::setContext($data);
Template::setView('admin/invite');
}

public function inviteOldList() {
global $user;

$inviteList = InviteModel::GetInviteArray(1);
include Template::load('/admin/invite');
$data['user'] = User::getCurrent();
$data['inviteList'] = InviteModel::getInviteArray(1);
$data['planList'] = json_decode(Option::get('custom_plan_name'), true);
Template::setContext($data);
Template::setView('admin/invite');
}

/**
* 添加一个邀请码
* @JSON
*/
public function add() {
global $user;
$result = array('error'=> 0, 'message'=> '添加成功,刷新可见');
$plan = 'A';
$inviteNumber = 1;
if($_POST['plan'] != null) {
$plan = $_POST['plan'];
}
if($_POST['number'] != null) {
$inviteNumber = $_POST['number'];
}
if($inviteNumber > 1) {
for($i=0; $i<$inviteNumber;$i++){
public function update() {
$result = array('error'=> -1, 'message'=> 'Request failed');

if($_POST['invite'] == null) {
$result = array('error'=> 0, 'message'=> '添加成功,刷新可见');
$plan = 'A';
$inviteNumber = 1;
if($_POST['plan'] != null) {
$plan = $_POST['plan'];
}
if($_POST['number'] != null) {
$inviteNumber = $_POST['number'];
}
if($inviteNumber > 1) {
for($i=0; $i<$inviteNumber;$i++){
InviteModel::addInvite(-1, $plan);
}
} else {
InviteModel::addInvite(-1, $plan);
}
$result['inviteNumber'] = $inviteNumber;
$result['plan'] = $plan;

} else {
InviteModel::addInvite(-1, $plan);
if($_POST['invite'] != null) {
$invite = InviteModel::getInviteByInviteCode(trim($_POST['invite']));
if($invite != null) {
$invite->dateLine = time(); // TODO -- 前端时间获取
$invite->expiration = $_POST['expiration'];
$invite->plan = $_POST['plan'];
$invite->save();
$result = array('error'=> 0, 'message'=> '更新邀请码成功');
}
}
}
$result['inviteNumber'] = $inviteNumber;
$result['plan'] = $plan;

echo json_encode($result);
exit();
return $result;
}

/**
* @JSON
* @return array
*/
public function delete() {
global $user;
$result = array('error'=> -1, 'message'=> '删除失败');

if($_POST['invite'] != null) {
InviteModel::deleteInvite($_POST['invite']);
$result = array('error'=> 0, 'message'=> '删除成功');
if($_POST['id'] != null) {
$id = intval(trim($_POST['id']));
$invite = InviteModel::getInviteById($id);
$invite->delete();
$result = array('error'=> 0, 'message'=> '删除成功', 'id' => $_POST['id']);
}

echo json_encode($result);
exit();
return $result;
}

/**
* @JSON
*/
public function query() {
global $user;
$result = array('error'=> -1, 'message'=> 'Request failed');

if($_POST['invite'] != null) {
$invite = InviteModel::GetInviteByInviteCode(trim($_POST['invite']));
if($_POST['id'] != null) {
$invite = InviteModel::getInviteById(intval(trim($_POST['id'])));
if($invite != null) {
$result = array('error'=> 0, 'message'=> 'success');
$invite->dateLine = date('Y-m-d', $invite->dateLine);
$result['data'] = $invite;
$result['invite'] = $invite;
}
}
echo json_encode($result);
exit();
return $result;
}

public function update() {
global $user;
$result = array('error'=> -1, 'message'=> 'Request failed');

if($_POST['invite'] != null) {
$invite = InviteModel::GetInviteByInviteCode(trim($_POST['invite']));
if($invite != null) {
$invite->dateLine = strtotime($_POST['add_time1'] + " " + $_POST['add_time2']);
$invite->expiration = $_POST['expiration'];
$invite->plan = $_POST['plan'];
$rs = $invite->updateInvite();
if($rs > 0) {
$result = array('error'=> 0, 'message'=> '更新邀请码成功');
}

}
}
echo json_encode($result);
exit();
}

}
14 changes: 8 additions & 6 deletions Library/Controller/Admin/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
use \Core\Template;

use \Model\Message as MessageModel;
use Model\User;

/**
* Controller: 消息管理
* @Admin
* @Authorization
*/
class Message extends AdminListener {
class Message {

public function index() {
global $user;

$lists = MessageModel::GetPushMsg(-1);

include Template::load('/admin/message');
$data['user'] = User::getCurrent();
$data['lists'] = MessageModel::getPushMessage(-1);
Template::setContext($data);
Template::setView('admin/message');
}

public function change() {
Expand Down
26 changes: 26 additions & 0 deletions Library/Model/Cron.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* shadowsocks-panel
* Add: 2016/4/8 9:39
* Author: Sendya <[email protected]>
*/

namespace Model;


use Core\Database as DB;
use Core\Model;

class Cron extends Model {

public $id;
public $enable;
public $nextRun;
public $order;

public static function getCronArray() {
$st = DB::sql("SELECT id, enable, nextrun, `order` FROM cron");
$st->execute();
return $st->fetchAll(DB::FETCH_CLASS, __CLASS__);
}
}
7 changes: 7 additions & 0 deletions Library/Model/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public static function getInviteByInviteCode($invite) {
return $statement->fetchObject(__CLASS__);
}

public static function getInviteById($id) {
$statement = DB::getInstance()->prepare("SELECT * FROM invite WHERE `id`=? LIMIT 0,1");
$statement->bindValue(1, $id, DB::PARAM_STR);
$statement->execute();
return $statement->fetchObject(__CLASS__);
}

/**
* Get invites by uid
* @param int $uid
Expand Down
2 changes: 1 addition & 1 deletion Template/Default/admin/cron.htm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1 class="title">计划任务</h1>
<td>#{$cron->id}</td>
<td></td>
<td>{(date("Y-m-d H:i:s", $cron->nextrun))}</td>
<td>{(\Helper\Util::cronStatus($cron->enabled, $cron->nextrun))}</td>
<td>{(\Helper\Utils::cronStatus($cron->enable, $cron->nextrun))}</td>
<td>{$cron->order}</td>
</tr>
</loop>
Expand Down
Loading

0 comments on commit 3e47271

Please sign in to comment.