Merge pull request #2 from kaguya-hime/master

添加可用于定制客户端的API
master
Wing lee 9 years ago committed by GitHub
commit 9b1f51a656
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,7 +80,7 @@ class ApiController extends BaseController
$storage = Factory::createTokenStorage();
$token = $storage->get($accessToken);
$user = User::find($token->userId);
$nodes = Node::where('sort', 0)->where("type", "1")->where(
$nodes = Node::where('sort', 0)->where("type", "1")->where('node_class', '<=', $user->class)->where(
function ($query) use ($user) {
$query->where("node_group", "=", $user->node_group)
->orWhere("node_group", "=", 0);

@ -0,0 +1,59 @@
<?php
/**
* Created by PhpStorm.
* User: kaguya
* Date: 2017/11/24
* Time: 13:06
*/
namespace App\Controllers\Client;
use App\Controllers\BaseController;
use App\Models\Ann;
use App\Models\User;
use App\Services\Auth;
use App\Services\Factory;
use App\Utils\Helper;
class ClientApiController extends BaseController
{
public function GetAnnouncement($request, $response, $args)
{
$accessToken = Helper::getTokenFromReq($request);
$storage = Factory::createTokenStorage();
$token = $storage->get($accessToken);
$user = User::find($token->userId);
$Anns = Ann::orderBy('date', 'desc')->first();
$res['ret'] = 1;
$res['msg'] = "ok";
$res['data'] = $Anns;
return $this->echoJson($response, $res);
//return $this->view()->assign("anns", $Anns)->display('user/announcement.tpl');
}
public function Redirect($request, $response, $args){
$user = Auth::getUser();
$url = $request->getQueryParams()["target"];
if(!$user->isLogin){
$accessToken = Helper::getTokenFromReq($request);
$storage = Factory::createTokenStorage();
$token = $storage->get($accessToken);
if ($token==null) {
$res['ret'] = 0;
$res['msg'] = "token is null";
return $this->echoJson($response, $res);
}
$user = User::find($token->userId);
$time = 3600*24;
Auth::login($user->id, $time);
}
return $response->withRedirect($url);
}
}

@ -0,0 +1,52 @@
<?php
/**
* Created by PhpStorm.
* User: kaguya
* Date: 2017/11/30
* Time: 16:59
*/
namespace App\Controllers\Client;
use App\Controllers\BaseController;
use App\Models\Code;
use App\Models\Shop;
use App\Services\Auth;
use App\Utils\Pay;
class ClientShopController extends BaseController
{
public function GetShop($request, $response, $args){
$user = Auth::getUser();
//var_dump($user->isLogin);
if(!$user->isLogin){
return $response->withRedirect('/api/redirect?target=/client/shop');
}
$pageNum = 1;
if (isset($request->getQueryParams()["page"])) {
$pageNum = $request->getQueryParams()["page"];
}
$shops = Shop::where("status", 1)->paginate(15, ['*'], 'page', $pageNum);
$shops->setPath('/user/shop');
return $this->view()->assign('shops', $shops)->display('client/shop.tpl');
}
public function GetCode($request, $response, $args)
{
$user = Auth::getUser();
//var_dump($user->isLogin);
if(!$user->isLogin){
return $response->withRedirect('/api/redirect?target=/client/code');
}
$pageNum = 1;
if (isset($request->getQueryParams()["page"])) {
$pageNum = $request->getQueryParams()["page"];
}
$codes = Code::where('type', '<>', '-2')->where('userid', '=', $user->id)->orderBy('id', 'desc')->paginate(15, ['*'], 'page', $pageNum);
$codes->setPath('/user/code');
return $this->view()->assign('codes', $codes)->assign('pmw', Pay::getHTML($user))->display('client/code.tpl');
}
}

@ -296,6 +296,14 @@ $app->group('/api', function () {
$this->post('/token', 'App\Controllers\ApiController:newToken');
$this->get('/node', 'App\Controllers\ApiController:node')->add(new Api());
$this->get('/user/{id}', 'App\Controllers\ApiController:userInfo')->add(new Api());
$this->get('/announcement','App\Controllers\Client\ClientApiController:GetAnnouncement');
$this->get('/redirect','App\Controllers\Client\ClientApiController:Redirect');
});
//Client pages
$app->group('/client',function (){
$this->get('/shop','App\Controllers\Client\ClientShopController:GetShop');
$this->get('/code','App\Controllers\Client\ClientShopController:GetCode');
});
// mu

@ -0,0 +1,286 @@
{include file='client/main.tpl'}
<main class="content">
<section class="content-inner margin-top-no">
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="card margin-bottom-no">
<div class="card-main">
<div class="card-inner">
<div class="card-inner">
<p class="card-heading">充值码</p>
<p>当前余额:{$user->money} 元</p>
<div class="form-group form-group-label">
<label class="floating-label" for="code">充值码</label>
<input class="form-control" id="code" type="text">
</div>
</div>
<div class="card-action">
<div class="card-action-btn pull-left">
<button class="btn btn-flat waves-attach" id="code-update" ><span class="icon">check</span>&nbsp;充值</button>
</div>
</div>
</div>
</div>
</div>
</div>
{if $pmw!=''}
<div class="col-lg-12 col-md-12">
<div class="card margin-bottom-no">
<div class="card-main">
<div class="card-inner">
<div class="card-inner">
{$pmw}
</div>
</div>
</div>
</div>
</div>
{/if}
<div class="col-lg-12 col-md-12">
<div class="card margin-bottom-no">
<div class="card-main">
<div class="card-inner">
<div class="card-inner">
<div class="card-table">
<div class="table-responsive">
{$codes->render()}
<table class="table table-hover">
<tr>
<th>ID</th>
<th>代码</th>
<th>类型</th>
<th>操作</th>
<th>使用时间</th>
</tr>
{foreach $codes as $code}
{if $code->type!=-2}
<tr>
<td>#{$code->id}</td>
<td>{$code->code}</td>
{if $code->type==-1}
<td>金额充值</td>
{/if}
{if $code->type==10001}
<td>流量充值</td>
{/if}
{if $code->type==10002}
<td>用户续期</td>
{/if}
{if $code->type>=1&&$code->type<=10000}
<td>等级续期 - 等级{$code->type}</td>
{/if}
{if $code->type==-1}
<td>充值 {$code->number} 元</td>
{/if}
{if $code->type==10001}
<td>充值 {$code->number} GB 流量</td>
{/if}
{if $code->type==10002}
<td>延长账户有效期 {$code->number} 天</td>
{/if}
{if $code->type>=1&&$code->type<=10000}
<td>延长等级有效期 {$code->number} 天</td>
{/if}
<td>{$code->usedatetime}</td>
</tr>
{/if}
{/foreach}
</table>
{$codes->render()}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div aria-hidden="true" class="modal modal-va-middle fade" id="readytopay" role="dialog" tabindex="-1">
<div class="modal-dialog modal-xs">
<div class="modal-content">
<div class="modal-heading">
<a class="modal-close" data-dismiss="modal">×</a>
<h2 class="modal-title">正在连接支付宝</h2>
</div>
<div class="modal-inner">
<p id="title">正在处理...</p>
</div>
</div>
</div>
</div>
<div aria-hidden="true" class="modal modal-va-middle fade" id="alipay" role="dialog" tabindex="-1">
<div class="modal-dialog modal-xs">
<div class="modal-content">
<div class="modal-heading">
<a class="modal-close" data-dismiss="modal">×</a>
<h2 class="modal-title">请使用支付宝App扫码充值:</h2>
</div>
<div class="modal-inner">
<p id="title">手机点击二维码转跳支付宝</p>
<p id="divide">-------------------------------------------------------------</p>
<p id="qrcode"></p>
<p id="info"></p>
</div>
<div class="modal-footer">
<p class="text-right"><button class="btn btn-flat btn-brand waves-attach" data-dismiss="modal" id="alipay_cancel" type="button">取消</button></p>
</div>
</div>
</div>
</div>
{include file='dialog.tpl'}
</div>
</section>
</main>
{include file='client/footer.tpl'}
<script>
$(document).ready(function () {
$("#code-update").click(function () {
$.ajax({
type: "POST",
url: "/user/code",
dataType: "json",
data: {
code: $("#code").val()
},
success: function (data) {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg);
window.setTimeout("location.href=window.location.href", {$config['jump_delay']});
} else {
$("#result").modal();
$("#msg").html(data.msg);
window.setTimeout("location.href=window.location.href", {$config['jump_delay']});
}
},
error: function (jqXHR) {
$("#result").modal();
$("#msg").html("发生错误:" + jqXHR.status);
}
})
})
$("#urlChange").click(function () {
$.ajax({
type: "GET",
url: "/user/code/f2fpay",
dataType: "json",
data: {
time: timestamp
},
success: function (data) {
if (data.ret) {
$("#readytopay").modal();
}
}
})
});
$("#alipay").click(function () {
$.ajax({
type: "GET",
url: "/user/code/pay91",
dataType: "json",
data: {
time: timestamp
},
success: function (data) {
if (data.ret) {
$("#readytopay").modal();
}
}
})
});
$("#readytopay").on('shown.bs.modal', function () {
$.ajax({
type: "POST",
url: "/user/code/f2fpay",
dataType: "json",
data: {
amount: $("#type").find("option:selected").val()
},
success: function (data) {
$("#readytopay").modal('hide');
if (data.ret) {
$("#qrcode").html(data.qrcode);
$("#info").html("您的订单金额为:"+data.amount+"元。");
$("#alipay").modal();
} else {
$("#result").modal();
$("#msg").html(data.msg);
}
},
error: function (jqXHR) {
$("#readytopay").modal('hide');
$("#result").modal();
$("#msg").html(data.msg+" 发生了错误。");
}
})
});
timestamp = {time()};
function f(){
$.ajax({
type: "GET",
url: "/user/code_check",
dataType: "json",
data: {
time: timestamp
},
success: function (data) {
if (data.ret) {
clearTimeout(tid);
$("#alipay").modal('hide');
$("#result").modal();
$("#msg").html("充值成功!");
window.setTimeout("location.href=window.location.href", {$config['jump_delay']});
}
}
});
tid = setTimeout(f, 1000); //循环调用触发setTimeout
}
setTimeout(f, 1000);
})
</script>

@ -0,0 +1,11 @@
<!-- js -->
<script src="//cdn.staticfile.org/jquery/2.2.1/jquery.min.js"></script>
<script src="//cdn.staticfile.org/jquery-validate/1.15.0/jquery.validate.min.js"></script>
<script src="//static.geetest.com/static/tools/gt.js"></script>
<script src="/theme/material/js/base.min.js"></script>
<script src="/theme/material/js/project.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.5.16/clipboard.min.js"></script>
</body>
</html>

@ -0,0 +1,195 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
<meta name="theme-color" content="#ff9800">
<title>{$config["appName"]}</title>
<!-- css -->
<link href="/theme/material/css/base.min.css" rel="stylesheet">
<link href="/theme/material/css/project.min.css" rel="stylesheet">
<link href="//fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- favicon -->
<!-- ... -->
<style>
.pagination {
display:inline-block;
padding-left:0;
margin:20px 0;
border-radius:4px
}
.pagination>li {
display:inline
}
.pagination>li>a,.pagination>li>span {
position:relative;
float:left;
padding:6px 12px;
margin-left:-1px;
line-height:1.42857143;
color:#337ab7;
text-decoration:none;
background-color:#fff;
border:1px solid #ddd
}
.pagination>li:first-child>a,.pagination>li:first-child>span {
margin-left:0;
border-top-left-radius:4px;
border-bottom-left-radius:4px
}
.pagination>li:last-child>a,.pagination>li:last-child>span {
border-top-right-radius:4px;
border-bottom-right-radius:4px
}
.pagination>li>a:focus,.pagination>li>a:hover,.pagination>li>span:focus,.pagination>li>span:hover {
color:#23527c;
background-color:#eee;
border-color:#ddd
}
.pagination>.active>a,.pagination>.active>a:focus,.pagination>.active>a:hover,.pagination>.active>span,.pagination>.active>span:focus,.pagination>.active>span:hover {
z-index:2;
color:#fff;
cursor:default;
background-color:#337ab7;
border-color:#337ab7
}
.pagination>.disabled>a,.pagination>.disabled>a:focus,.pagination>.disabled>a:hover,.pagination>.disabled>span,.pagination>.disabled>span:focus,.pagination>.disabled>span:hover {
color:#777;
cursor:not-allowed;
background-color:#fff;
border-color:#ddd
}
.pagination-lg>li>a,.pagination-lg>li>span {
padding:10px 16px;
font-size:18px
}
.pagination-lg>li:first-child>a,.pagination-lg>li:first-child>span {
border-top-left-radius:6px;
border-bottom-left-radius:6px
}
.pagination-lg>li:last-child>a,.pagination-lg>li:last-child>span {
border-top-right-radius:6px;
border-bottom-right-radius:6px
}
.pagination-sm>li>a,.pagination-sm>li>span {
padding:5px 10px;
font-size:12px
}
.pagination-sm>li:first-child>a,.pagination-sm>li:first-child>span {
border-top-left-radius:3px;
border-bottom-left-radius:3px
}
.pagination-sm>li:last-child>a,.pagination-sm>li:last-child>span {
border-top-right-radius:3px;
border-bottom-right-radius:3px
}
.pager {
padding-left:0;
margin:20px 0;
text-align:center;
list-style:none
}
.pager li {
display:inline
}
.pager li>a,.pager li>span {
display:inline-block;
padding:5px 14px;
background-color:#fff;
border:1px solid #ddd;
border-radius:15px
}
.pager li>a:focus,.pager li>a:hover {
text-decoration:none;
background-color:#eee
}
.pager .next>a,.pager .next>span {
float:right
}
.pager .previous>a,.pager .previous>span {
float:left
}
.pager .disabled>a,.pager .disabled>a:focus,.pager .disabled>a:hover,.pager .disabled>span {
color:#777;
cursor:not-allowed;
background-color:#fff
}
.pagination>li>a,
.pagination>li>span {
border: 1px solid white;
}
.pagination>li.active>a {
background: #f50057;
color: #fff;
}
.pagination>li>a {
background: white;
color: #000;
}
.pagination > .active > a, .pagination > .active > a:focus, .pagination > .active > a:hover, .pagination > .active > span, .pagination > .active > span:focus, .pagination > .active > span:hover {
color: #fff;
background-color: #000;
border-color: #000;
}
.pagination>.active>span {
background-color: #f50057;
color: #fff;
border-color: #fff;
}
.pagination > .disabled > span {
border-color: #fff;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
.progress-green .progress-bar {
background-color: #f0231b;
}
.progress-green {
background-color: #000;
}
.progress-green .progress-bar {
background-color: #ff0a00;
}
.page-orange .ui-content-header {
background-image: url(/theme/material/css/images/bg/amber.jpg);
}
.content-heading {
font-weight: 300;
color: #fff;
}
</style>
</head>
<body class="page-orange">

@ -0,0 +1,218 @@
{include file='client/main.tpl'}
<main class="content">
<div class="col-lg-12 col-sm-12">
<section class="content-inner margin-top-no">
<div class="card">
<div class="card-main">
<div class="card-inner">
<p>系统中所有商品的列表。您购买等级类的商品时有效期会从当前时间开始计算。</p>
<p>当前余额:{$user->money} 元</p>
</div>
</div>
</div>
<div class="table-responsive">
{$shops->render()}
<table class="table ">
<tr>
<th>操作</th>
<th>ID</th>
<th>名称</th>
<th>价格</th>
<th>内容</th>
<th>自动续费天数</th>
<th>续费时重置流量</th>
</tr>
{foreach $shops as $shop}
<tr>
<td>
<a class="btn btn-brand-accent" href="javascript:void(0);" onClick="buy('{$shop->id}',{$shop->auto_renew},{$shop->auto_reset_bandwidth})">购买</a>
</td>
<td>#{$shop->id}</td>
<td>{$shop->name}</td>
<td>{$shop->price} 元</td>
<td>{$shop->content()}</td>
{if $shop->auto_renew==0}
<td>不能自动续费</td>
{else}
<td>可选 在 {$shop->auto_renew} 天后自动续费</td>
{/if}
{if $shop->auto_reset_bandwidth==0}
<td>不自动重置</td>
{else}
<td>自动重置</td>
{/if}
</tr>
{/foreach}
</table>
{$shops->render()}
</div>
<div aria-hidden="true" class="modal modal-va-middle fade" id="coupon_modal" role="dialog" tabindex="-1">
<div class="modal-dialog modal-xs">
<div class="modal-content">
<div class="modal-heading">
<a class="modal-close" data-dismiss="modal">×</a>
<h2 class="modal-title">您有优惠码吗?</h2>
</div>
<div class="modal-inner">
<div class="form-group form-group-label">
<label class="floating-label" for="coupon">有的话,请在这里输入。没有的话,直接确定吧</label>
<input class="form-control" id="coupon" type="text">
</div>
</div>
<div class="modal-footer">
<p class="text-right"><button class="btn btn-flat btn-brand waves-attach" data-dismiss="modal" id="coupon_input" type="button">确定</button></p>
</div>
</div>
</div>
</div>
<div aria-hidden="true" class="modal modal-va-middle fade" id="order_modal" role="dialog" tabindex="-1">
<div class="modal-dialog modal-xs">
<div class="modal-content">
<div class="modal-heading">
<a class="modal-close" data-dismiss="modal">×</a>
<h2 class="modal-title">订单确认</h2>
</div>
<div class="modal-inner">
<p id="name">商品名称:</p>
<p id="credit">优惠额度:</p>
<p id="total">总金额:</p>
<p id="auto_reset">在到期时自动续费</p>
<div class="checkbox switch" id="autor">
<label for="autorenew">
<input checked class="access-hide" id="autorenew" type="checkbox"><span class="switch-toggle"></span>自动续费
</label>
</div>
</div>
<div class="modal-footer">
<p class="text-right"><button class="btn btn-flat btn-brand waves-attach" data-dismiss="modal" id="order_input" type="button">确定</button></p>
</div>
</div>
</div>
</div>
{include file='dialog.tpl'}
</div>
</main>
{include file='client/footer.tpl'}
<script>
function buy(id,auto,auto_reset) {
auto_renew=auto;
if(auto==0)
{
document.getElementById('autor').style.display="none";
}
else
{
document.getElementById('autor').style.display="";
}
if(auto_reset==0)
{
document.getElementById('auto_reset').style.display="none";
}
else
{
document.getElementById('auto_reset').style.display="";
}
shop=id;
$("#coupon_modal").modal();
}
$("#coupon_input").click(function () {
$.ajax({
type: "POST",
url: "/user/coupon_check",
dataType: "json",
data: {
coupon: $("#coupon").val(),
shop: shop
},
success: function (data) {
if (data.ret) {
$("#name").html("商品名称:"+data.name);
$("#credit").html("优惠额度:"+data.credit);
$("#total").html("总金额:"+data.total);
$("#order_modal").modal();
} else {
$("#result").modal();
$("#msg").html(data.msg);
}
},
error: function (jqXHR) {
$("#result").modal();
$("#msg").html(data.msg+" 发生了错误。");
}
})
});
$("#order_input").click(function () {
if(document.getElementById('autorenew').checked)
{
var autorenew=1;
}
else
{
var autorenew=0;
}
$.ajax({
type: "POST",
url: "/user/buy",
dataType: "json",
data: {
coupon: $("#coupon").val(),
shop: shop,
autorenew: autorenew
},
success: function (data) {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg);
window.setTimeout("location.href='/client/shop'", {$config['jump_delay']});
} else {
$("#result").modal();
$("#msg").html(data.msg);
}
},
error: function (jqXHR) {
$("#result").modal();
$("#msg").html(data.msg+" 发生了错误。");
}
})
});
</script>
Loading…
Cancel
Save