File: /var/www/dk/wp-content/themes/food/api/ranking/index.php
<?php
//if (isset($_REQUEST['backend_server'])) {
// if (isset($_REQUEST['banner_type'])) {
// $res = $wpdb->get_results($wpdb->prepare("SELECT * from `food_banner` where banner_type = %d", $_REQUEST['banner_type']));
// } else {
// $res = $wpdb->get_results("SELECT * from `food_banner`");
// }
//} else {
// if (isset($_REQUEST['banner_type'])) {
// $res = $wpdb->get_results($wpdb->prepare("SELECT * from `food_banner` where `status` = 1 AND banner_type = %d", $_REQUEST['banner_type']));
// } else {
// $res = $wpdb->get_results("SELECT * from `food_banner` where `status` = 1");
// }
//}
//
//foreach ($res as $value) {
// $value->banner_type_name = $a_banner_type[$value->banner_type];
//}
//
//$res = $res;
class RankingNoauth
{
public $result;
public $debug;
public $RankingBsObj = null;
public function __construct()
{
$this->result = new stdClass();
// $this->result->rc = ApiErrorDesc::ERR_CONTROLLER[0];
// $this->result->msg = ApiErrorDesc::ERR_CONTROLLER[1];
$this->result->rc = ApiErrorDesc::ERR_METHOD[0];
$this->result->msg = ApiErrorDesc::ERR_METHOD[1];
$this->debug = isset($_REQUEST['debugmod']) ? intval($_REQUEST['debugmod']) : 0;
$this->RankingBsObj = new RankingBs();
}
function __destruct()
{
$this->echo_json($this->result);
}
public function run()
{
$a = CheckFunc::checkInput2('a', 50, '');
// echo 'a = > ' . $a;
if (method_exists($this, $a)) {
$this->$a();
}
// if ($a == 'playerlist') {
//// $this->playerlist();
// $this->$a();
// }
}
function echo_json($result)
{
echo preg_replace_callback(
'/\\\\u([0-9a-zA-Z]{4})/',
function ($matches) {
return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
},
json_encode($result)
);
}
/**
* 用戶 玩家
* @return void
*/
public function playerlist()
{
$debug = $this->debug;
$where = [];
$where['pageNum'] = CheckFunc::checkInputInt2('pageNum', 10, 1);
$where['pageSize'] = CheckFunc::checkInputInt2('pageSize', 10, 100);
$where['order'] = 'score desc';
$aid = CheckFunc::checkInputInt2('aid', 10, 0);
if ($aid > 0) {
$where['aid'] = $aid;
}
$id = CheckFunc::checkInputInt2('id', 10, 0);
if ($id > 0) {
$where['id'] = $id;
}
$user_id = CheckFunc::checkInputInt2('user_id', 10, 0);
if ($user_id > 0) {
$where['user_id'] = $user_id;
}
$data = [];
$title = CheckFunc::checkInput2('title', 100, '');
if ($title != '') {
$where['title'] = $title;
}
if ($debug) {
print_r($where);
}
// if ($where['aid'] == 0) {
// $this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
// $this->result->msg = ApiErrorDesc::ERR_PARAMS[1];
// die();
// }
$status = CheckFunc::checkInputInt2('status', 10, 0);
if ($status != 0) {
$where['status'] = $status;
}
# 获取配置
$RankingBiz = new RankingBs();
$pageObj = $RankingBiz->getFoodActivityPlayerInfoByPage($where, $data, $debug);
$this->result->rc = $pageObj->rc;
$this->result->msg = $pageObj->msg;
$this->result->total = $pageObj->total;
$this->result->pageNum = $pageObj->pageNum;
$this->result->pageSize = $pageObj->pageSize;
$this->result->data = $pageObj->dataList;
}
//投票
public function UpdatePlayerScore()
{
$debug = $this->debug;
$where = [];
$where['debug'] = $this->debug;
$where['user_id'] = CheckFunc::checkInputInt2('user_id', 10, 0);
$where['activity_id'] = CheckFunc::checkInputInt2('activity_id', 10, 0);
$where['player_id'] = CheckFunc::checkInputInt2('player_id', 10, 0);
if ($debug) {
print_r($where);
}
if ($where['user_id'] == 0 || $where['activity_id'] == 0 || $where['player_id'] == 0) {
$this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
$this->result->msg = ApiErrorDesc::ERR_PARAMS[1];
die();
}
$RankingBiz = new RankingBs();
$resObj = $RankingBiz->UpdatePlayerScore($where, $debug);
$this->result->rc = $resObj->rc;
$this->result->msg = $resObj->msg;
}
/**
* 檢測 是否已投票
* @return void
*/
public function CheckVote()
{
$debug = $this->debug;
$where = [];
$where['debug'] = $this->debug;
$where['user_id'] = CheckFunc::checkInputInt2('user_id', 10, 0);
$where['activity_id'] = CheckFunc::checkInputInt2('activity_id', 10, 0);
$where['player_id'] = CheckFunc::checkInputInt2('player_id', 10, 0);
if ($debug) {
print_r($where);
}
if ($where['user_id'] == 0 || $where['activity_id'] == 0 || $where['player_id'] == 0) {
$this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
$this->result->msg = ApiErrorDesc::ERR_PARAMS[1];
die();
}
$RankingBiz = new RankingBs();
$resObj = $RankingBiz->CheckVote($where, $debug);
$this->result->rc = $resObj->rc;
$this->result->msg = $resObj->msg;
}
public function getActivityListInfoByPage()
{
$where = [];
$debug = $this->debug;
$where['pageNum'] = CheckFunc::checkInputInt2('pageNum', 10, 1);
$where['pageSize'] = CheckFunc::checkInputInt2('pageSize', 10, 10);
$where['order'] = 'id desc';
$title = CheckFunc::checkInput2('title');
if ($title != '') {
$where['name'] = $title;
}
$id = CheckFunc::checkInputInt2('id', 10, 0);
if ($id != 0) {
$where['id'] = $id;
}
$status = CheckFunc::checkInputInt2('status', 10, 0);
if ($status != 0) {
$where['status'] = $status;
}
// print_r($where);
$data = [];
# 获取配置
// $UBiz = new OnlineclassBs();
$pageObj = $this->RankingBsObj->getActivityListInfoByPage($where, $data, $debug);
//
$this->result->rc = $pageObj->rc;
$this->result->msg = $pageObj->msg;
//
$this->result->pageNum = $pageObj->pageNum;
$this->result->pageSize = $pageObj->pageSize;
$this->result->total = $pageObj->total;
$this->result->data = $pageObj->dataList;
}
/**
* 设置活动
* @return void
*/
public function setActivity()
{
// `id`, `name`, `content`, `user_id`, `user_name`, `score`, `start_date`, `end_date`, `add_time`, `update_time`, `status`
$where = [];
$debug = $this->debug;
$action = CheckFunc::checkInput2('func_action');
$where['status'] = CheckFunc::checkInputInt2('status', 2, 1);
if ($action == 'add') {
$where['user_id'] = CheckFunc::checkInputInt2('user_id', 5, 0);
}
$id = CheckFunc::checkInputInt2('id');
if ($action == 'del' || $action == 'update') {
if ($id > 0) {
$where['id'] = $id;
} else {
$this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
$this->result->msg = ApiErrorDesc::ERR_PARAMS[1] . ' id';
die();
}
}
$where['name'] = CheckFunc::checkInput2('form_name');
$where['content'] = CheckFunc::checkInput2('content', 2000);
if ($action == 'add') {
$user_id = CheckFunc::checkInputInt2('user_id');
if ($user_id > 0) {
$where['user_id'] = $user_id;
$where['user_name'] = CheckFunc::checkInput2('user_name');
}
}
$score = CheckFunc::checkInputInt2('score', 10, 0);
if ($score > 0) {
$where['score'] = $score;
}
$share_num = CheckFunc::checkInputInt2('share_num', 10, 0);
if ($share_num > 0) {
$where['share_num'] = $share_num;
}
//图片
$img_id = CheckFunc::checkInputInt2('img_id', 10, 0);
if ($img_id > 0) {
$where['img_id'] = $img_id;
$where['img_url'] = CheckFunc::checkInput2('img_url', 350, '');
}
// //视频
// $video_file_id = CheckFunc::checkInputInt2('video_file_id', 10, 0);
// if ($video_file_id > 0) {
// $where['video_file_id'] = $video_file_id;
// $where['video_url'] = CheckFunc::checkInput2('video_url', 350, '');
// }
$where['start_date'] = CheckFunc::checkInput2('start_date');
$where['end_date'] = CheckFunc::checkInput2('end_date');
if ($debug) {
print_r($where);
}
$resObj = new stdClass();
$resObj->rc = ApiErrorDesc::ERR_ACTION[0];
$resObj->msg = ApiErrorDesc::ERR_ACTION[1];
if ($action == 'update' || $action == 'add' || $action == 'del') {
# 获取配置
try {
$resObj = $this->RankingBsObj->setActivity($action, $where, $debug);
} catch (Exception $e) {
}
}
$this->result->rc = $resObj->rc;
$this->result->msg = $resObj->msg;
if ($resObj->rc == ApiErrorDesc::SUCCESS[0] && $action == 'add') {
$this->result->id = $resObj->id;
}
}
/**
* 设置活动 用户
* @return void
*/
public function setActivityPlayer()
{
//`id`, `aid`, `ref`, `nickname`, `declaration`, `avatar`, `score`, `add_time`, `update_time`, `status`
$where = [];
$debug = $this->debug;
$action = CheckFunc::checkInput2('func_action');
$where['status'] = CheckFunc::checkInputInt2('status', 2, 0);
// if ($status != 0) {
// $where['status'] = $status;
// }
if ($action == 'add') {
$where['user_id'] = CheckFunc::checkInputInt2('user_id', 5, 0);
}
$id = CheckFunc::checkInputInt2('id');
if ($action == 'del' || $action == 'update') {
if ($id > 0) {
$where['id'] = $id;
} else {
$this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
$this->result->msg = ApiErrorDesc::ERR_PARAMS[1] . ' id';
die();
}
}
$aid = CheckFunc::checkInputInt2('aid');
if ($aid > 0) {
$where['aid'] = $aid;
} else {
$this->result->rc = ApiErrorDesc::ERR_PARAMS[0];
$this->result->msg = ApiErrorDesc::ERR_PARAMS[1] . ' aid';
die();
}
// $where['ref'] = CheckFunc::checkInput2('ref');
$nickname = CheckFunc::checkInput2('nickname');
if ($nickname != '') {
$where['nickname'] = $nickname;
}
$title = CheckFunc::checkInput2('title', 300, '');
if ($title != '') {
$where['title'] = $title;
}
$declaration = CheckFunc::checkInput2('declaration', 2000, '');
if ($declaration != '') {
$where['declaration'] = $declaration;
}
$review_remark = CheckFunc::checkInput2('review_remark', 1000, '');//審核意見
if ($review_remark != '') {
$where['review_remark'] = $review_remark;
}
//图片
$img_id = CheckFunc::checkInputInt2('img_id', 10, 0);
if ($img_id > 0) {
$where['img_id'] = $img_id;
$where['avatar'] = CheckFunc::checkInput2('avatar', 350, '');
}
//视频
$video_file_id = CheckFunc::checkInputInt2('video_file_id', 10, 0);
if ($video_file_id > 0) {
$where['video_file_id'] = $video_file_id;
$where['video_url'] = CheckFunc::checkInput2('video_url', 350, '');
}
$score = CheckFunc::checkInputInt2('score');
if ($score > 0) {
$where['score'] = $score;
}
if ($debug) {
print_r($where);
}
$resObj = new stdClass();
$resObj->rc = ApiErrorDesc::ERR_ACTION[0];
$resObj->msg = ApiErrorDesc::ERR_ACTION[1];
if ($action == 'update' || $action == 'add' || $action == 'del') {
# 获取配置
try {
$resObj = $this->RankingBsObj->setActivityPlayer($action, $where, $debug);
} catch (Exception $e) {
}
}
$this->result->rc = $resObj->rc;
$this->result->msg = $resObj->msg;
if ($resObj->rc == ApiErrorDesc::SUCCESS[0] && $action == 'add') {
$this->result->id = $resObj->id;
}
}
/**
* 获取活动用户 编号
* @return void
*/
public function getActivityPlayerRef()
{
$debug = $this->debug;
$aid = CheckFunc::checkInputInt2('aid');
# 获取配置
try {
$resObj = $this->RankingBsObj->getActivityPlayerRef($aid, $debug);
} catch (Exception $e) {
}
$this->result->rc = ApiErrorDesc::SUCCESS[0];
$this->result->msg = ApiErrorDesc::SUCCESS[1];
$this->result->data = $resObj->ref;
}
}
//单一文件入口
$app = new RankingNoauth();
$app->run();
$isAi_output = true;
$rc = 666;