mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 20:06:09 +08:00
!11 阶段性合并
* 根据app需要作出相应调整 * 路由增加命名name,增加app应用管理 * 完成基本API,增加h5和小程序支付定义
This commit is contained in:
parent
823e47f6b2
commit
cbc2e5762a
@ -11,7 +11,7 @@ class CategoryTreeList extends Builder
|
||||
|
||||
public function handle($type)
|
||||
{
|
||||
$topCategories = $this->findChildCategories($type, 0);
|
||||
$topCategories = $this->findTopCategories($type);
|
||||
|
||||
if ($topCategories->count() == 0) {
|
||||
return [];
|
||||
@ -32,7 +32,7 @@ class CategoryTreeList extends Builder
|
||||
|
||||
protected function handleChildren(CategoryModel $category)
|
||||
{
|
||||
$subCategories = $this->findChildCategories($category->type, $category->id);
|
||||
$subCategories = $this->findChildCategories($category->id);
|
||||
|
||||
if ($subCategories->count() == 0) {
|
||||
return [];
|
||||
@ -51,24 +51,31 @@ class CategoryTreeList extends Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param int $type
|
||||
* @return ResultsetInterface|Resultset|CategoryModel[]
|
||||
*/
|
||||
protected function findTopCategories($type)
|
||||
{
|
||||
$query = CategoryModel::query();
|
||||
|
||||
$query->where('parent_id = 0');
|
||||
$query->andWhere('published = 1');
|
||||
$query->andWhere('type = :type:', ['type' => $type]);
|
||||
$query->orderBy('priority ASC');
|
||||
|
||||
return $query->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $parentId
|
||||
* @return ResultsetInterface|Resultset|CategoryModel[]
|
||||
*/
|
||||
protected function findChildCategories($type = 'course', $parentId = 0)
|
||||
protected function findChildCategories($parentId)
|
||||
{
|
||||
$query = CategoryModel::query();
|
||||
|
||||
$query->where('published = 1');
|
||||
|
||||
if ($type) {
|
||||
$query->andWhere('type = :type:', ['type' => $type]);
|
||||
}
|
||||
|
||||
if ($parentId) {
|
||||
$query->andWhere('parent_id = :parent_id:', ['parent_id' => $parentId]);
|
||||
}
|
||||
|
||||
$query->andWhere('parent_id = :parent_id:', ['parent_id' => $parentId]);
|
||||
$query->orderBy('priority ASC');
|
||||
|
||||
return $query->execute();
|
||||
|
31
app/Caches/App.php
Normal file
31
app/Caches/App.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Caches;
|
||||
|
||||
use App\Repos\App as AppRepo;
|
||||
|
||||
class App extends Cache
|
||||
{
|
||||
|
||||
protected $lifetime = 365 * 86400;
|
||||
|
||||
public function getLifetime()
|
||||
{
|
||||
return $this->lifetime;
|
||||
}
|
||||
|
||||
public function getKey($id = null)
|
||||
{
|
||||
return "app:{$id}";
|
||||
}
|
||||
|
||||
public function getContent($id = null)
|
||||
{
|
||||
$appRepo = new AppRepo();
|
||||
|
||||
$result = $appRepo->findByAppKey($id);
|
||||
|
||||
return $result ?: null;
|
||||
}
|
||||
|
||||
}
|
127
app/Http/Admin/Controllers/AppController.php
Normal file
127
app/Http/Admin/Controllers/AppController.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Admin\Controllers;
|
||||
|
||||
use App\Http\Admin\Services\App as AppService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/admin/app")
|
||||
*/
|
||||
class AppController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/list", name="admin.app.list")
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
$appService = new AppService();
|
||||
|
||||
$pager = $appService->getApps();
|
||||
|
||||
$this->view->setVar('pager', $pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/add", name="admin.app.add")
|
||||
*/
|
||||
public function addAction()
|
||||
{
|
||||
$appService = new AppService();
|
||||
|
||||
$types = $appService->getAppTypes();
|
||||
|
||||
$this->view->setVar('types', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/create", name="admin.app.create")
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$appService = new AppService();
|
||||
|
||||
$appService->createApp();
|
||||
|
||||
$location = $this->url->get(['for' => 'admin.app.list']);
|
||||
|
||||
$content = [
|
||||
'location' => $location,
|
||||
'msg' => '创建应用成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/edit", name="admin.app.edit")
|
||||
*/
|
||||
public function editAction($id)
|
||||
{
|
||||
$appService = new AppService;
|
||||
|
||||
$app = $appService->getApp($id);
|
||||
$types = $appService->getAppTypes();
|
||||
|
||||
$this->view->setVar('app', $app);
|
||||
$this->view->setVar('types', $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/update", name="admin.app.update")
|
||||
*/
|
||||
public function updateAction($id)
|
||||
{
|
||||
$appService = new AppService();
|
||||
|
||||
$appService->updateApp($id);
|
||||
|
||||
$location = $this->url->get(['for' => 'admin.app.list']);
|
||||
|
||||
$content = [
|
||||
'location' => $location,
|
||||
'msg' => '更新应用成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/delete", name="admin.app.delete")
|
||||
*/
|
||||
public function deleteAction($id)
|
||||
{
|
||||
$appService = new AppService();
|
||||
|
||||
$appService->deleteApp($id);
|
||||
|
||||
$location = $this->request->getHTTPReferer();
|
||||
|
||||
$content = [
|
||||
'location' => $location,
|
||||
'msg' => '删除应用成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/restore", name="admin.app.restore")
|
||||
*/
|
||||
public function restoreAction($id)
|
||||
{
|
||||
$appService = new AppService();
|
||||
|
||||
$appService->restoreApp($id);
|
||||
|
||||
$location = $this->request->getHTTPReferer();
|
||||
|
||||
$content = [
|
||||
'location' => $location,
|
||||
'msg' => '还原应用成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
}
|
@ -19,16 +19,16 @@ class UploadController extends Controller
|
||||
|
||||
$file = $service->uploadCoverImage();
|
||||
|
||||
if ($file) {
|
||||
return $this->jsonSuccess([
|
||||
'data' => [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
if (!$file) {
|
||||
return $this->jsonError(['msg' => '上传文件失败']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
];
|
||||
|
||||
return $this->jsonSuccess(['data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,16 +40,16 @@ class UploadController extends Controller
|
||||
|
||||
$file = $service->uploadAvatarImage();
|
||||
|
||||
if ($file) {
|
||||
return $this->jsonSuccess([
|
||||
'data' => [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
if (!$file) {
|
||||
return $this->jsonError(['msg' => '上传文件失败']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
];
|
||||
|
||||
return $this->jsonSuccess(['data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,16 +61,16 @@ class UploadController extends Controller
|
||||
|
||||
$file = $service->uploadContentImage();
|
||||
|
||||
if ($file) {
|
||||
return $this->jsonSuccess([
|
||||
'data' => [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
if (!$file) {
|
||||
return $this->jsonError(['msg' => '上传文件失败']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
];
|
||||
|
||||
return $this->jsonSuccess(['data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
135
app/Http/Admin/Services/App.php
Normal file
135
app/Http/Admin/Services/App.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Admin\Services;
|
||||
|
||||
use App\Caches\App as AppCache;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\App as AppModel;
|
||||
use App\Repos\App as AppRepo;
|
||||
use App\Validators\App as AppValidator;
|
||||
|
||||
class App extends Service
|
||||
{
|
||||
|
||||
public function getApps()
|
||||
{
|
||||
$pagerQuery = new PagerQuery();
|
||||
|
||||
$params = $pagerQuery->getParams();
|
||||
|
||||
$params['deleted'] = $params['deleted'] ?? 0;
|
||||
|
||||
$sort = $pagerQuery->getSort();
|
||||
$page = $pagerQuery->getPage();
|
||||
$limit = $pagerQuery->getLimit();
|
||||
|
||||
$appRepo = new AppRepo();
|
||||
|
||||
return $appRepo->paginate($params, $sort, $page, $limit);
|
||||
}
|
||||
|
||||
public function getApp($id)
|
||||
{
|
||||
return $this->findOrFail($id);
|
||||
}
|
||||
|
||||
public function createApp()
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$validator = new AppValidator();
|
||||
|
||||
$data = [];
|
||||
|
||||
$data['type'] = $validator->checkType($post['type']);
|
||||
$data['name'] = $validator->checkName($post['name']);
|
||||
$data['remark'] = $validator->checkRemark($post['remark']);
|
||||
|
||||
$page = new AppModel();
|
||||
|
||||
$page->create($data);
|
||||
|
||||
$this->rebuildAppCache($page);
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function updateApp($id)
|
||||
{
|
||||
$app = $this->findOrFail($id);
|
||||
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$validator = new AppValidator();
|
||||
|
||||
$data = [];
|
||||
|
||||
if (isset($post['type'])) {
|
||||
$data['type'] = $validator->checkType($post['type']);
|
||||
}
|
||||
|
||||
if (isset($post['name'])) {
|
||||
$data['name'] = $validator->checkName($post['name']);
|
||||
}
|
||||
|
||||
if (isset($post['remark'])) {
|
||||
$data['remark'] = $validator->checkRemark($post['remark']);
|
||||
}
|
||||
|
||||
if (isset($post['published'])) {
|
||||
$data['published'] = $validator->checkPublishStatus($post['published']);
|
||||
}
|
||||
|
||||
$app->update($data);
|
||||
|
||||
$this->rebuildAppCache($app);
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
public function deleteApp($id)
|
||||
{
|
||||
$app = $this->findOrFail($id);
|
||||
|
||||
$app->deleted = 1;
|
||||
|
||||
$app->update();
|
||||
|
||||
$this->rebuildAppCache($app);
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
public function restoreApp($id)
|
||||
{
|
||||
$app = $this->findOrFail($id);
|
||||
|
||||
$app->deleted = 0;
|
||||
|
||||
$app->update();
|
||||
|
||||
$this->rebuildAppCache($app);
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
public function getAppTypes()
|
||||
{
|
||||
return AppModel::types();
|
||||
}
|
||||
|
||||
protected function rebuildAppCache(AppModel $app)
|
||||
{
|
||||
$cache = new AppCache();
|
||||
|
||||
$cache->rebuild($app->key);
|
||||
}
|
||||
|
||||
protected function findOrFail($id)
|
||||
{
|
||||
$validator = new AppValidator();
|
||||
|
||||
return $validator->checkApp($id);
|
||||
}
|
||||
|
||||
}
|
@ -671,7 +671,7 @@ class AuthNode extends Service
|
||||
{
|
||||
return [
|
||||
'id' => '5',
|
||||
'title' => '系统配置',
|
||||
'title' => '系统管理',
|
||||
'children' => [
|
||||
[
|
||||
'id' => '5-1',
|
||||
@ -746,6 +746,37 @@ class AuthNode extends Service
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'id' => '5-2',
|
||||
'title' => '应用管理',
|
||||
'type' => 'menu',
|
||||
'children' => [
|
||||
[
|
||||
'id' => '5-2-1',
|
||||
'title' => '应用列表',
|
||||
'type' => 'menu',
|
||||
'route' => 'admin.app.list',
|
||||
],
|
||||
[
|
||||
'id' => '5-2-2',
|
||||
'title' => '添加应用',
|
||||
'type' => 'menu',
|
||||
'route' => 'admin.app.add',
|
||||
],
|
||||
[
|
||||
'id' => '5-2-3',
|
||||
'title' => '编辑应用',
|
||||
'type' => 'button',
|
||||
'route' => 'admin.app.edit',
|
||||
],
|
||||
[
|
||||
'id' => '5-2-4',
|
||||
'title' => '删除应用',
|
||||
'type' => 'button',
|
||||
'route' => 'admin.app.delete',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
41
app/Http/Admin/Views/app/add.volt
Normal file
41
app/Http/Admin/Views/app/add.volt
Normal file
@ -0,0 +1,41 @@
|
||||
{% extends 'templates/main.volt' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form class="layui-form kg-form" method="POST" action="{{ url({'for':'admin.app.create'}) }}">
|
||||
<fieldset class="layui-elem-field layui-field-title">
|
||||
<legend>添加应用</legend>
|
||||
</fieldset>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">类型</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="type" lay-verify="required">
|
||||
<option value="">选择类型</option>
|
||||
{% for key,name in types %}
|
||||
<option value="{{ key }}">{{ name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="name" lay-verify="required">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">备注</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="remark">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="kg-submit layui-btn" lay-submit="true" lay-filter="go">提交</button>
|
||||
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
49
app/Http/Admin/Views/app/edit.volt
Normal file
49
app/Http/Admin/Views/app/edit.volt
Normal file
@ -0,0 +1,49 @@
|
||||
{% extends 'templates/main.volt' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form class="layui-form kg-form" method="POST" action="{{ url({'for':'admin.app.update','id':app.id}) }}">
|
||||
<fieldset class="layui-elem-field layui-field-title">
|
||||
<legend>编辑应用</legend>
|
||||
</fieldset>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">类型</label>
|
||||
<div class="layui-input-block">
|
||||
<select name="type" lay-verify="required">
|
||||
<option value="">选择类型</option>
|
||||
{% for key,name in types %}
|
||||
{% set selected = key == app.type ? 'selected="selected"' : '' %}
|
||||
<option value="{{ key }}" {{ selected }}>{{ name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="name" value="{{ app.name }}" lay-verify="required">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">备注</label>
|
||||
<div class="layui-input-block">
|
||||
<input class="layui-input" type="text" name="remark" value="{{ app.remark }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">发布</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="published" value="1" title="是" {% if app.published == 1 %}checked="checked"{% endif %}>
|
||||
<input type="radio" name="published" value="0" title="否" {% if app.published == 0 %}checked="checked"{% endif %}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"></label>
|
||||
<div class="layui-input-block">
|
||||
<button class="kg-submit layui-btn" lay-submit="true" lay-filter="go">提交</button>
|
||||
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
83
app/Http/Admin/Views/app/list.volt
Normal file
83
app/Http/Admin/Views/app/list.volt
Normal file
@ -0,0 +1,83 @@
|
||||
{% extends 'templates/main.volt' %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{%- macro type_info(value) %}
|
||||
{% if value == 'pc' %}
|
||||
PC客户端
|
||||
{% elseif value == 'h5' %}
|
||||
H5客户端
|
||||
{% elseif value == 'ios' %}
|
||||
IOS客户端
|
||||
{% elseif value == 'android' %}
|
||||
Android客户端
|
||||
{% elseif value == 'mp_weixin' %}
|
||||
微信小程序
|
||||
{% elseif value == 'mp_alipay' %}
|
||||
支付宝小程序
|
||||
{% else %}
|
||||
未知
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
<div class="kg-nav">
|
||||
<div class="kg-nav-left">
|
||||
<span class="layui-breadcrumb">
|
||||
<a><cite>应用管理</cite></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table class="kg-table layui-table layui-form">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col width="10%">
|
||||
<col width="12%">
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>编号</th>
|
||||
<th>名称</th>
|
||||
<th>类型</th>
|
||||
<th>Key / Secret</th>
|
||||
<th>创建时间</th>
|
||||
<th>发布</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in pager.items %}
|
||||
{% set edit_url = url({'for':'admin.app.edit','id':item.id}) %}
|
||||
{% set update_url = url({'for':'admin.app.update','id':item.id}) %}
|
||||
{% set delete_url = url({'for':'admin.app.delete','id':item.id}) %}
|
||||
{% set restore_url = url({'for':'admin.app.restore','id':item.id}) %}
|
||||
<tr>
|
||||
<td>{{ item.id }}</td>
|
||||
<td><a href="{{ edit_url }}" title="{{ item.remark }}">{{ item.name }}</a></td>
|
||||
<td>{{ type_info(item.type) }}</td>
|
||||
<td>{{ item.key }} / {{ item.secret }}</td>
|
||||
<td>{{ date('Y-m-d H:i:s',item.create_time) }}</td>
|
||||
<td class="center"><input type="checkbox" name="published" value="1" lay-skin="switch" lay-text="是|否" lay-filter="published" data-url="{{ update_url }}" {% if item.published == 1 %}checked="checked"{% endif %}></td>
|
||||
<td class="center">
|
||||
<div class="layui-dropdown">
|
||||
<button class="layui-btn layui-btn-sm">操作 <i class="layui-icon layui-icon-triangle-d"></i></button>
|
||||
<ul>
|
||||
<li><a href="{{ edit_url }}">编辑</a></li>
|
||||
{% if item.deleted == 0 %}
|
||||
<li><a href="javascript:" class="kg-delete" data-url="{{ delete_url }}">删除</a></li>
|
||||
{% else %}
|
||||
<li><a href="javascript:" class="kg-restore" data-url="{{ restore_url }}">还原</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% endblock %}
|
@ -29,7 +29,6 @@
|
||||
{% endif %}
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
|
||||
<button id="submit-btn" class="layui-btn layui-btn-fluid {{ disabled_class }}" {{ disabled_submit }} lay-submit="true" lay-filter="go">立即登录</button>
|
||||
<input type="hidden" name="ticket">
|
||||
<input type="hidden" name="rand">
|
||||
|
113
app/Http/Api/Controllers/AccountController.php
Normal file
113
app/Http/Api/Controllers/AccountController.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Http\Api\Services\Account as AccountService;
|
||||
use App\Services\Logic\Account\EmailUpdate as EmailUpdateService;
|
||||
use App\Services\Logic\Account\PasswordReset as PasswordResetService;
|
||||
use App\Services\Logic\Account\PasswordUpdate as PasswordUpdateService;
|
||||
use App\Services\Logic\Account\PhoneUpdate as PhoneUpdateService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/account")
|
||||
*/
|
||||
class AccountController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Post("/register", name="api.account.register")
|
||||
*/
|
||||
public function registerAction()
|
||||
{
|
||||
$service = new AccountService();
|
||||
|
||||
$token = $service->register();
|
||||
|
||||
return $this->jsonSuccess(['token' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/password/login", name="api.account.register")
|
||||
*/
|
||||
public function loginByPasswordAction()
|
||||
{
|
||||
$service = new AccountService();
|
||||
|
||||
$token = $service->loginByPassword();
|
||||
|
||||
return $this->jsonSuccess(['token' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/verify/login", name="api.account.verify_login")
|
||||
*/
|
||||
public function loginByVerifyAction()
|
||||
{
|
||||
$service = new AccountService();
|
||||
|
||||
$token = $service->loginByVerify();
|
||||
|
||||
return $this->jsonSuccess(['token' => $token]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/logout", name="api.account.logout")
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
$service = new AccountService();
|
||||
|
||||
$service->logout();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/password/reset", name="api.account.reset_pwd")
|
||||
*/
|
||||
public function resetPasswordAction()
|
||||
{
|
||||
$service = new PasswordResetService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/phone/update", name="api.account.update_phone")
|
||||
*/
|
||||
public function updatePhoneAction()
|
||||
{
|
||||
$service = new PhoneUpdateService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/email/update", name="api.account.update_email")
|
||||
*/
|
||||
public function updateEmailAction()
|
||||
{
|
||||
$service = new EmailUpdateService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/password/update", name="api.account.update_pwd")
|
||||
*/
|
||||
public function updatePasswordAction()
|
||||
{
|
||||
$service = new PasswordUpdateService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
64
app/Http/Api/Controllers/ChapterController.php
Normal file
64
app/Http/Api/Controllers/ChapterController.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Chapter\ChapterInfo as ChapterInfoService;
|
||||
use App\Services\Logic\Chapter\ChapterLike as ChapterLikeService;
|
||||
use App\Services\Logic\Chapter\Learning as ChapterLearningService;
|
||||
use App\Services\Logic\Chapter\ResourceList as ChapterResourceListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/chapter")
|
||||
*/
|
||||
class ChapterController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/resources", name="api.chapter.resourses")
|
||||
*/
|
||||
public function resourcesAction($id)
|
||||
{
|
||||
$service = new ChapterResourceListService();
|
||||
|
||||
$resources = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['resources' => $resources]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.chapter.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new ChapterInfoService();
|
||||
|
||||
$chapter = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['chapter' => $chapter]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.chapter.like")
|
||||
*/
|
||||
public function likeAction($id)
|
||||
{
|
||||
$service = new ChapterLikeService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/learning", name="api.chapter.learning")
|
||||
*/
|
||||
public function learningAction($id)
|
||||
{
|
||||
$service = new ChapterLearningService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
73
app/Http/Api/Controllers/ChapterLiveController.php
Normal file
73
app/Http/Api/Controllers/ChapterLiveController.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Http\Home\Services\ChapterLive as ChapterLiveService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/live")
|
||||
*/
|
||||
class ChapterLiveController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/chats", name="api.live.chats")
|
||||
*/
|
||||
public function chatsAction($id)
|
||||
{
|
||||
$service = new ChapterLiveService();
|
||||
|
||||
$chats = $service->getRecentChats($id);
|
||||
|
||||
return $this->jsonSuccess(['chats' => $chats]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/stats", name="api.live.stats")
|
||||
*/
|
||||
public function statsAction($id)
|
||||
{
|
||||
$service = new ChapterLiveService();
|
||||
|
||||
$stats = $service->getStats($id);
|
||||
|
||||
return $this->jsonSuccess(['stats' => $stats]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/status", name="api.live.status")
|
||||
*/
|
||||
public function statusAction($id)
|
||||
{
|
||||
$service = new ChapterLiveService();
|
||||
|
||||
$status = $service->getStatus($id);
|
||||
|
||||
return $this->jsonSuccess(['status' => $status]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/user/bind", name="api.live.bind_user")
|
||||
*/
|
||||
public function bindUserAction($id)
|
||||
{
|
||||
$service = new ChapterLiveService();
|
||||
|
||||
$service->bindUser($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/msg/send", name="api.live.send_msg")
|
||||
*/
|
||||
public function sendMessageAction($id)
|
||||
{
|
||||
$service = new ChapterLiveService();
|
||||
|
||||
$message = $service->sendMessage($id);
|
||||
|
||||
return $this->jsonSuccess(['message' => $message]);
|
||||
}
|
||||
|
||||
}
|
97
app/Http/Api/Controllers/ConsultController.php
Normal file
97
app/Http/Api/Controllers/ConsultController.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService;
|
||||
use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService;
|
||||
use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService;
|
||||
use App\Services\Logic\Consult\ConsultLike as ConsultLikeService;
|
||||
use App\Services\Logic\Consult\ConsultUpdate as ConsultUpdateService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/consult")
|
||||
*/
|
||||
class ConsultController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.consult.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new ConsultInfoService();
|
||||
|
||||
$consult = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['consult' => $consult]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/create", name="api.consult.create")
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$service = new ConsultCreateService();
|
||||
|
||||
$consult = $service->handle();
|
||||
|
||||
$service = new ConsultInfoService();
|
||||
|
||||
$consult = $service->handle($consult->id);
|
||||
|
||||
return $this->jsonSuccess(['consult' => $consult]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/update", name="api.consult.update")
|
||||
*/
|
||||
public function updateAction($id)
|
||||
{
|
||||
$service = new ConsultUpdateService();
|
||||
|
||||
$consult = $service->handle($id);
|
||||
|
||||
$service = new ConsultInfoService();
|
||||
|
||||
$consult = $service->handle($consult->id);
|
||||
|
||||
return $this->jsonSuccess(['consult' => $consult]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/delete", name="api.consult.delete")
|
||||
*/
|
||||
public function deleteAction($id)
|
||||
{
|
||||
$service = new ConsultDeleteService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.consult.like")
|
||||
*/
|
||||
public function likeAction($id)
|
||||
{
|
||||
$service = new ConsultLikeService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unlike", name="api.consult.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new ConsultLikeService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Auth\Api as AppAuth;
|
||||
use App\Traits\Response as ResponseTrait;
|
||||
use App\Traits\Security as SecurityTrait;
|
||||
use Phalcon\Mvc\Dispatcher;
|
||||
@ -14,7 +15,32 @@ class Controller extends \Phalcon\Mvc\Controller
|
||||
|
||||
public function beforeExecuteRoute(Dispatcher $dispatcher)
|
||||
{
|
||||
$this->checkRateLimit();
|
||||
/**
|
||||
* 存在Origin头信息才设置跨域
|
||||
*/
|
||||
if ($this->request->getHeader('Origin')) {
|
||||
$this->setCors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Options请求不验证签名和限流
|
||||
*/
|
||||
if (!$this->request->isOptions()) {
|
||||
//$this->checkApiSignature();
|
||||
//$this->checkRateLimit();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getAuthUser()
|
||||
{
|
||||
/**
|
||||
* @var AppAuth $auth
|
||||
*/
|
||||
$auth = $this->getDI()->get('auth');
|
||||
|
||||
return $auth->getCurrentUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
128
app/Http/Api/Controllers/CourseController.php
Normal file
128
app/Http/Api/Controllers/CourseController.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Course\CategoryList as CourseCategoryListService;
|
||||
use App\Services\Logic\Course\ChapterList as CourseChapterListService;
|
||||
use App\Services\Logic\Course\ConsultList as CourseConsultListService;
|
||||
use App\Services\Logic\Course\CourseFavorite as CourseFavoriteService;
|
||||
use App\Services\Logic\Course\CourseInfo as CourseInfoService;
|
||||
use App\Services\Logic\Course\CourseList as CourseListService;
|
||||
use App\Services\Logic\Course\PackageList as CoursePackageListService;
|
||||
use App\Services\Logic\Course\ReviewList as CourseReviewListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/course")
|
||||
*/
|
||||
class CourseController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/categories", name="api.course.categories")
|
||||
*/
|
||||
public function categoriesAction()
|
||||
{
|
||||
$service = new CourseCategoryListService();
|
||||
|
||||
$categories = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['categories' => $categories]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/list", name="api.course.list")
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
$service = new CourseListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.course.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new CourseInfoService();
|
||||
|
||||
$course = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['course' => $course]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/chapters", name="api.course.chapters")
|
||||
*/
|
||||
public function chaptersAction($id)
|
||||
{
|
||||
$service = new CourseChapterListService();
|
||||
|
||||
$chapters = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['chapters' => $chapters]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/packages", name="api.course.packages")
|
||||
*/
|
||||
public function packagesAction($id)
|
||||
{
|
||||
$service = new CoursePackageListService();
|
||||
|
||||
$packages = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['packages' => $packages]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/consults", name="api.course.consults")
|
||||
*/
|
||||
public function consultsAction($id)
|
||||
{
|
||||
$service = new CourseConsultListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/reviews", name="api.course.reviews")
|
||||
*/
|
||||
public function reviewsAction($id)
|
||||
{
|
||||
$service = new CourseReviewListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/favorite", name="api.course.favorite")
|
||||
*/
|
||||
public function favoriteAction($id)
|
||||
{
|
||||
$service = new CourseFavoriteService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unfavorite", name="api.course.unfavorite")
|
||||
*/
|
||||
public function unfavoriteAction($id)
|
||||
{
|
||||
$service = new CourseFavoriteService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
38
app/Http/Api/Controllers/HelpController.php
Normal file
38
app/Http/Api/Controllers/HelpController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Help\HelpInfo as HelpInfoService;
|
||||
use App\Services\Logic\Help\HelpList as HelpListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/help")
|
||||
*/
|
||||
class HelpController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/list", name="api.help.list")
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
$service = new HelpListService();
|
||||
|
||||
$helps = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['helps' => $helps]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}", name="api.help.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new HelpInfoService();
|
||||
|
||||
$help = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['help' => $help]);
|
||||
}
|
||||
|
||||
}
|
51
app/Http/Api/Controllers/ImGroupController.php
Normal file
51
app/Http/Api/Controllers/ImGroupController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Im\GroupInfo as GroupInfoService;
|
||||
use App\Services\Logic\Im\GroupList as GroupListService;
|
||||
use App\Services\Logic\Im\GroupUserList as GroupUserListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/im/group")
|
||||
*/
|
||||
class ImGroupController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/list", name="api.im_group.list")
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
$service = new GroupListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.im_group.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new GroupInfoService();
|
||||
|
||||
$group = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['group' => $group]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/users", name="api.im_group.users")
|
||||
*/
|
||||
public function usersAction($id)
|
||||
{
|
||||
$service = new GroupUserListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
}
|
@ -2,39 +2,63 @@
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Caches\IndexSimpleFreeCourseList;
|
||||
use App\Caches\IndexSimpleNewCourseList;
|
||||
use App\Caches\IndexSimpleVipCourseList;
|
||||
use App\Caches\IndexSlideList;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api")
|
||||
* @RoutePrefix("/api/index")
|
||||
*/
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/", name="api.index")
|
||||
* @Get("/slides", name="api.index.slides")
|
||||
*/
|
||||
public function indexAction()
|
||||
public function slidesAction()
|
||||
{
|
||||
return $this->jsonSuccess(['data' => 'ok']);
|
||||
$cache = new IndexSlideList();
|
||||
|
||||
$slides = $cache->get();
|
||||
|
||||
return $this->jsonSuccess(['slides' => $slides]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/routes", name="api.routes")
|
||||
* @Get("/courses/new", name="api.index.new_courses")
|
||||
*/
|
||||
public function routesAction()
|
||||
public function newCoursesAction()
|
||||
{
|
||||
$definitions = [];
|
||||
$cache = new IndexSimpleNewCourseList();
|
||||
|
||||
$routes = $this->router->getRoutes();
|
||||
$courses = $cache->get();
|
||||
|
||||
foreach ($routes as $route) {
|
||||
if (strpos($route->getPattern(), '/api') !== false) {
|
||||
$definitions[] = [
|
||||
'pattern' => $route->getPattern(),
|
||||
'methods' => $route->getHttpMethods(),
|
||||
];
|
||||
}
|
||||
}
|
||||
return $this->jsonSuccess(['courses' => $courses]);
|
||||
}
|
||||
|
||||
return $this->jsonSuccess(['routes' => $definitions]);
|
||||
/**
|
||||
* @Get("/courses/free", name="api.index.free_courses")
|
||||
*/
|
||||
public function freeCoursesAction()
|
||||
{
|
||||
$cache = new IndexSimpleFreeCourseList();
|
||||
|
||||
$courses = $cache->get();
|
||||
|
||||
return $this->jsonSuccess(['courses' => $courses]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/courses/vip", name="api.index.vip_courses")
|
||||
*/
|
||||
public function vipCoursesAction()
|
||||
{
|
||||
$cache = new IndexSimpleVipCourseList();
|
||||
|
||||
$courses = $cache->get();
|
||||
|
||||
return $this->jsonSuccess(['courses' => $courses]);
|
||||
}
|
||||
|
||||
}
|
||||
|
76
app/Http/Api/Controllers/OrderController.php
Normal file
76
app/Http/Api/Controllers/OrderController.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Order\OrderCancel as OrderCancelService;
|
||||
use App\Services\Logic\Order\OrderConfirm as OrderConfirmService;
|
||||
use App\Services\Logic\Order\OrderCreate as OrderCreateService;
|
||||
use App\Services\Logic\Order\OrderInfo as OrderInfoService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/order")
|
||||
*/
|
||||
class OrderController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/info", name="api.order.info")
|
||||
*/
|
||||
public function infoAction()
|
||||
{
|
||||
$sn = $this->request->getQuery('sn', 'string');
|
||||
|
||||
$service = new OrderInfoService();
|
||||
|
||||
$order = $service->handle($sn);
|
||||
|
||||
return $this->jsonSuccess(['order' => $order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/confirm", name="api.order.confirm")
|
||||
*/
|
||||
public function confirmAction()
|
||||
{
|
||||
$itemId = $this->request->getQuery('item_id', 'int');
|
||||
$itemType = $this->request->getQuery('item_type', 'int');
|
||||
|
||||
$service = new OrderConfirmService();
|
||||
|
||||
$confirm = $service->handle($itemId, $itemType);
|
||||
|
||||
return $this->jsonSuccess(['confirm' => $confirm]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/create", name="api.order.create")
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$service = new OrderCreateService();
|
||||
|
||||
$order = $service->handle();
|
||||
|
||||
$service = new OrderInfoService();
|
||||
|
||||
$order = $service->handle($order->sn);
|
||||
|
||||
return $this->jsonSuccess(['order' => $order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/cancel", name="api.order.cancel")
|
||||
*/
|
||||
public function cancelAction()
|
||||
{
|
||||
$sn = $this->request->getPost('sn', 'string');
|
||||
|
||||
$service = new OrderCancelService();
|
||||
|
||||
$order = $service->handle($sn);
|
||||
|
||||
return $this->jsonSuccess(['order' => $order]);
|
||||
}
|
||||
|
||||
}
|
25
app/Http/Api/Controllers/PageController.php
Normal file
25
app/Http/Api/Controllers/PageController.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Page\PageInfo as PageInfoService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/page")
|
||||
*/
|
||||
class PageController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}", name="api.page.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new PageInfoService();
|
||||
|
||||
$page = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['page' => $page]);
|
||||
}
|
||||
|
||||
}
|
@ -2,14 +2,85 @@
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Reward\OptionList as RewardOptionList;
|
||||
use App\Services\Logic\Vip\OptionList as VipOptionList;
|
||||
use App\Services\Service as AppService;
|
||||
use App\Traits\Response as ResponseTrait;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api")
|
||||
*/
|
||||
class PublicController extends \Phalcon\Mvc\Controller
|
||||
class PublicController extends Controller
|
||||
{
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
/**
|
||||
* @Options("/{match:(.*)}", name="api.match_options")
|
||||
*/
|
||||
public function corsAction()
|
||||
{
|
||||
$this->response->setStatusCode(204);
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/now", name="api.public.now")
|
||||
*/
|
||||
public function nowAction()
|
||||
{
|
||||
return $this->jsonSuccess(['now' => time()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/site/info", name="api.public.site_info")
|
||||
*/
|
||||
public function siteInfoAction()
|
||||
{
|
||||
$service = new AppService();
|
||||
|
||||
$site = $service->getSettings('site');
|
||||
|
||||
return $this->jsonSuccess(['site' => $site]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/captcha/info", name="api.public.captcha_info")
|
||||
*/
|
||||
public function captchaInfoAction()
|
||||
{
|
||||
$service = new AppService();
|
||||
|
||||
$captcha = $service->getSettings('captcha');
|
||||
|
||||
unset($captcha['secret_key']);
|
||||
|
||||
return $this->jsonSuccess(['captcha' => $captcha]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/reward/options", name="api.public.reward_options")
|
||||
*/
|
||||
public function rewardOptionsAction()
|
||||
{
|
||||
$service = new RewardOptionList();
|
||||
|
||||
$options = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['options' => $options]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/vip/options", name="api.public.vip_options")
|
||||
*/
|
||||
public function vipOptionsAction()
|
||||
{
|
||||
$service = new VipOptionList();
|
||||
|
||||
$options = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['options' => $options]);
|
||||
}
|
||||
|
||||
}
|
||||
|
78
app/Http/Api/Controllers/RefundController.php
Normal file
78
app/Http/Api/Controllers/RefundController.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Refund\RefundCancel as RefundCancelService;
|
||||
use App\Services\Logic\Refund\RefundConfirm as RefundConfirmService;
|
||||
use App\Services\Logic\Refund\RefundCreate as RefundCreateService;
|
||||
use App\Services\Logic\Refund\RefundInfo as RefundInfoService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/refund")
|
||||
*/
|
||||
class RefundController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/confirm", name="api.refund.confirm")
|
||||
*/
|
||||
public function confirmAction()
|
||||
{
|
||||
$sn = $this->request->getQuery('sn', 'string');
|
||||
|
||||
$service = new RefundConfirmService();
|
||||
|
||||
$confirm = $service->handle($sn);
|
||||
|
||||
return $this->jsonSuccess(['confirm' => $confirm]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/info", name="api.refund.info")
|
||||
*/
|
||||
public function infoAction()
|
||||
{
|
||||
$sn = $this->request->getQuery('sn', 'string');
|
||||
|
||||
$service = new RefundInfoService();
|
||||
|
||||
$refund = $service->handle($sn);
|
||||
|
||||
return $this->jsonSuccess(['refund' => $refund]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/create", name="api.refund.create")
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$service = new RefundCreateService();
|
||||
|
||||
$refund = $service->handle();
|
||||
|
||||
$service = new RefundInfoService();
|
||||
|
||||
$refund = $service->handle($refund->sn);
|
||||
|
||||
return $this->jsonSuccess(['refund' => $refund]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/cancel", name="api.refund.cancel")
|
||||
*/
|
||||
public function cancelAction()
|
||||
{
|
||||
$sn = $this->request->getPost('sn', 'string');
|
||||
|
||||
$service = new RefundCancelService();
|
||||
|
||||
$service->handle($sn);
|
||||
|
||||
$service = new RefundInfoService();
|
||||
|
||||
$refund = $service->handle($sn);
|
||||
|
||||
return $this->jsonSuccess(['refund' => $refund]);
|
||||
}
|
||||
|
||||
}
|
97
app/Http/Api/Controllers/ReviewController.php
Normal file
97
app/Http/Api/Controllers/ReviewController.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Review\ReviewCreate as ReviewCreateService;
|
||||
use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService;
|
||||
use App\Services\Logic\Review\ReviewInfo as ReviewInfoService;
|
||||
use App\Services\Logic\Review\ReviewLike as ReviewLikeService;
|
||||
use App\Services\Logic\Review\ReviewUpdate as ReviewUpdateService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/review")
|
||||
*/
|
||||
class ReviewController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.review.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new ReviewInfoService();
|
||||
|
||||
$review = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['review' => $review]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/create", name="api.order.create")
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$service = new ReviewCreateService();
|
||||
|
||||
$review = $service->handle();
|
||||
|
||||
$service = new ReviewInfoService();
|
||||
|
||||
$review = $service->handle($review->id);
|
||||
|
||||
return $this->jsonSuccess(['review' => $review]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/update", name="api.review.update")
|
||||
*/
|
||||
public function updateAction($id)
|
||||
{
|
||||
$service = new ReviewUpdateService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
$service = new ReviewInfoService();
|
||||
|
||||
$review = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['review' => $review]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/delete", name="api.review.delete")
|
||||
*/
|
||||
public function deleteAction($id)
|
||||
{
|
||||
$service = new ReviewDeleteService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="api.review.like")
|
||||
*/
|
||||
public function likeAction($id)
|
||||
{
|
||||
$service = new ReviewLikeService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/unlike", name="api.review.unlike")
|
||||
*/
|
||||
public function unlikeAction($id)
|
||||
{
|
||||
$service = new ReviewLikeService();
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
61
app/Http/Api/Controllers/SearchController.php
Normal file
61
app/Http/Api/Controllers/SearchController.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Search\Course as CourseSearchService;
|
||||
use App\Services\Logic\Search\Group as GroupSearchService;
|
||||
use App\Services\Logic\Search\User as UserSearchService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/search")
|
||||
*/
|
||||
class SearchController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/", name="api.search.index")
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
$query = $this->request->get('query', ['trim', 'string']);
|
||||
$type = $this->request->get('type', ['trim', 'string'], 'course');
|
||||
|
||||
$pager = [
|
||||
'total_pages' => 0,
|
||||
'total_items' => 0,
|
||||
'items' => [],
|
||||
];
|
||||
|
||||
if (empty($query)) {
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
$service = $this->getSearchService($type);
|
||||
|
||||
$pager = $service->search();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return CourseSearchService|GroupSearchService|UserSearchService
|
||||
*/
|
||||
protected function getSearchService($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'group':
|
||||
$service = new GroupSearchService;
|
||||
break;
|
||||
case 'user':
|
||||
$service = new UserSearchService();
|
||||
break;
|
||||
default:
|
||||
$service = new CourseSearchService();
|
||||
break;
|
||||
}
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
}
|
51
app/Http/Api/Controllers/TeacherController.php
Normal file
51
app/Http/Api/Controllers/TeacherController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Teacher\CourseList as CourseListService;
|
||||
use App\Services\Logic\Teacher\TeacherInfo as TeacherInfoService;
|
||||
use App\Services\Logic\Teacher\TeacherList as TeacherListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/teacher")
|
||||
*/
|
||||
class TeacherController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/list", name="api.teacher.list")
|
||||
*/
|
||||
public function listAction()
|
||||
{
|
||||
$service = new TeacherListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.teacher.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new TeacherInfoService();
|
||||
|
||||
$teacher = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['teacher' => $teacher]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/courses", name="api.teacher.courses")
|
||||
*/
|
||||
public function coursesAction($id)
|
||||
{
|
||||
$service = new CourseListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
}
|
88
app/Http/Api/Controllers/TradeController.php
Normal file
88
app/Http/Api/Controllers/TradeController.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Http\Api\Services\Trade as TradeService;
|
||||
use App\Services\Logic\Trade\TradeInfo as TradeInfoService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/trade")
|
||||
*/
|
||||
class TradeController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/info", name="api.trade.info")
|
||||
*/
|
||||
public function infoAction()
|
||||
{
|
||||
$sn = $this->request->getQuery('sn', 'string');
|
||||
|
||||
$service = new TradeInfoService();
|
||||
|
||||
$trade = $service->handle($sn);
|
||||
|
||||
return $this->jsonSuccess(['trade' => $trade]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/h5/pay", name="api.trade.h5_pay")
|
||||
*/
|
||||
public function h5PayAction()
|
||||
{
|
||||
$sn = $this->request->getQuery('sn', 'string');
|
||||
|
||||
$service = new TradeService();
|
||||
|
||||
$response = $service->h5Pay($sn);
|
||||
|
||||
if (!$response) {
|
||||
echo "H5支付跳转失败,请回退重试";
|
||||
}
|
||||
|
||||
$response->send();
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/h5/create", name="api.trade.h5_create")
|
||||
*/
|
||||
public function createH5TradeAction()
|
||||
{
|
||||
$service = new TradeService();
|
||||
|
||||
$trade = $service->createH5Trade();
|
||||
|
||||
$service = new TradeInfoService();
|
||||
|
||||
$trade = $service->handle($trade->sn);
|
||||
|
||||
return $this->jsonSuccess(['trade' => $trade]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/mp/create", name="api.trade.mp_create")
|
||||
*/
|
||||
public function createMpTradeAction()
|
||||
{
|
||||
$service = new TradeService();
|
||||
|
||||
$content = $service->createMpTrade();
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/app/create", name="api.trade.app_create")
|
||||
*/
|
||||
public function createAppTradeAction()
|
||||
{
|
||||
$service = new TradeService();
|
||||
|
||||
$content = $service->createMpTrade();
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
|
||||
}
|
50
app/Http/Api/Controllers/UploadController.php
Normal file
50
app/Http/Api/Controllers/UploadController.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\MyStorage as StorageService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/upload")
|
||||
*/
|
||||
class UploadController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Post("/avatar/img", name="api.upload.avatar_img")
|
||||
*/
|
||||
public function uploadAvatarImageAction()
|
||||
{
|
||||
$service = new StorageService();
|
||||
|
||||
$file = $service->uploadAvatarImage();
|
||||
|
||||
if (!$file) {
|
||||
return $this->jsonError(['msg' => '上传文件失败']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
];
|
||||
|
||||
return $this->jsonSuccess(['data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/im/img", name="api.upload.im_img")
|
||||
*/
|
||||
public function uploadImImageAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/im/file", name="api.upload.im_file")
|
||||
*/
|
||||
public function uploadImFileAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
155
app/Http/Api/Controllers/UserConsoleController.php
Normal file
155
app/Http/Api/Controllers/UserConsoleController.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\User\Console\AccountInfo as AccountInfoService;
|
||||
use App\Services\Logic\User\Console\ConsultList as ConsultListService;
|
||||
use App\Services\Logic\User\Console\CourseList as CourseListService;
|
||||
use App\Services\Logic\User\Console\FavoriteList as FavoriteListService;
|
||||
use App\Services\Logic\User\Console\FriendList as FriendListService;
|
||||
use App\Services\Logic\User\Console\GroupList as GroupListService;
|
||||
use App\Services\Logic\User\Console\OrderList as OrderListService;
|
||||
use App\Services\Logic\User\Console\ProfileInfo as ProfileInfoService;
|
||||
use App\Services\Logic\User\Console\ProfileUpdate as ProfileUpdateService;
|
||||
use App\Services\Logic\User\Console\RefundList as RefundListService;
|
||||
use App\Services\Logic\User\Console\ReviewList as ReviewListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/uc")
|
||||
*/
|
||||
class UserConsoleController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/profile", name="api.uc.profile")
|
||||
*/
|
||||
public function profileAction()
|
||||
{
|
||||
$service = new ProfileInfoService();
|
||||
|
||||
$profile = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['profile' => $profile]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/account", name="api.uc.account")
|
||||
*/
|
||||
public function accountAction()
|
||||
{
|
||||
$service = new AccountInfoService();
|
||||
|
||||
$account = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['account' => $account]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/courses", name="api.uc.courses")
|
||||
*/
|
||||
public function coursesAction()
|
||||
{
|
||||
$service = new CourseListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/favorites", name="api.uc.favorites")
|
||||
*/
|
||||
public function favoritesAction()
|
||||
{
|
||||
$service = new FavoriteListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/consults", name="api.uc.consults")
|
||||
*/
|
||||
public function consultsAction()
|
||||
{
|
||||
$service = new ConsultListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/reviews", name="api.uc.reviews")
|
||||
*/
|
||||
public function reviewsAction()
|
||||
{
|
||||
$service = new ReviewListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/orders", name="api.uc.orders")
|
||||
*/
|
||||
public function ordersAction()
|
||||
{
|
||||
$service = new OrderListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/refunds", name="api.uc.refunds")
|
||||
*/
|
||||
public function refundsAction()
|
||||
{
|
||||
$service = new RefundListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/friends", name="api.uc.friends")
|
||||
*/
|
||||
public function friendsAction()
|
||||
{
|
||||
$service = new FriendListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/groups", name="api.uc.groups")
|
||||
*/
|
||||
public function groupsAction()
|
||||
{
|
||||
$service = new GroupListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/profile/update", name="api.uc.update_profile")
|
||||
*/
|
||||
public function updateProfileAction()
|
||||
{
|
||||
$service = new ProfileUpdateService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
77
app/Http/Api/Controllers/UserController.php
Normal file
77
app/Http/Api/Controllers/UserController.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\User\CourseList as UserCourseListService;
|
||||
use App\Services\Logic\User\FavoriteList as UserFavoriteListService;
|
||||
use App\Services\Logic\User\FriendList as UserFriendListService;
|
||||
use App\Services\Logic\User\GroupList as UserGroupListService;
|
||||
use App\Services\Logic\User\UserInfo as UserInfoService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/user")
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/info", name="api.user.info")
|
||||
*/
|
||||
public function infoAction($id)
|
||||
{
|
||||
$service = new UserInfoService();
|
||||
|
||||
$user = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['user' => $user]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/courses", name="api.user.courses")
|
||||
*/
|
||||
public function coursesAction($id)
|
||||
{
|
||||
$service = new UserCourseListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/favorites", name="api.user.favorites")
|
||||
*/
|
||||
public function favoritesAction($id)
|
||||
{
|
||||
$service = new UserFavoriteListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/friends", name="api.user.friends")
|
||||
*/
|
||||
public function friendsAction($id)
|
||||
{
|
||||
$service = new UserFriendListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/groups", name="api.user.groups")
|
||||
*/
|
||||
public function groupsAction($id)
|
||||
{
|
||||
$service = new UserGroupListService();
|
||||
|
||||
$pager = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
}
|
38
app/Http/Api/Controllers/VerifyController.php
Normal file
38
app/Http/Api/Controllers/VerifyController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Verify\EmailCode as EmailCodeService;
|
||||
use App\Services\Logic\Verify\SmsCode as SmsCodeService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/verify")
|
||||
*/
|
||||
class VerifyController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Post("/sms/code", name="api.verify.sms_code")
|
||||
*/
|
||||
public function smsCodeAction()
|
||||
{
|
||||
$service = new SmsCodeService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/email/code", name="api.verify.email_code")
|
||||
*/
|
||||
public function emailCodeAction()
|
||||
{
|
||||
$service = new EmailCodeService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
}
|
40
app/Http/Api/Controllers/VipController.php
Normal file
40
app/Http/Api/Controllers/VipController.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Controllers;
|
||||
|
||||
use App\Services\Logic\Vip\CourseList as VipCourseListService;
|
||||
use App\Services\Logic\Vip\UserList as VipUserListService;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/api/vip")
|
||||
*/
|
||||
class VipController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @Get("/courses", name="api.vip.courses")
|
||||
*/
|
||||
public function coursesAction()
|
||||
{
|
||||
$type = $this->request->getQuery('type', 'string', 'discount');
|
||||
|
||||
$service = new VipCourseListService();
|
||||
|
||||
$pager = $service->handle($type);
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/users", name="api.vip.users")
|
||||
*/
|
||||
public function usersAction()
|
||||
{
|
||||
$service = new VipUserListService();
|
||||
|
||||
$pager = $service->handle();
|
||||
|
||||
return $this->jsonSuccess(['pager' => $pager]);
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Api;
|
||||
|
||||
use App\Services\Auth\Api as ApiAuth;
|
||||
use App\Services\Auth\Api as AppAuth;
|
||||
use Phalcon\DiInterface;
|
||||
use Phalcon\Mvc\ModuleDefinitionInterface;
|
||||
use Phalcon\Mvc\View;
|
||||
@ -24,7 +24,7 @@ class Module implements ModuleDefinitionInterface
|
||||
});
|
||||
|
||||
$di->setShared('auth', function () {
|
||||
return new ApiAuth();
|
||||
return new AppAuth();
|
||||
});
|
||||
}
|
||||
|
||||
|
85
app/Http/Api/Services/Account.php
Normal file
85
app/Http/Api/Services/Account.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Services;
|
||||
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Auth\Api as AuthService;
|
||||
use App\Services\Logic\Account\Register as RegisterService;
|
||||
use App\Validators\Account as AccountValidator;
|
||||
|
||||
class Account extends Service
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AuthService
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->auth = $this->getDI()->get('auth');
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
$service = new RegisterService();
|
||||
|
||||
$account = $service->handle();
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($account->id);
|
||||
|
||||
return $this->auth->saveAuthInfo($user);
|
||||
}
|
||||
|
||||
public function loginByPassword()
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
/**
|
||||
* 使用[account|phone|email]做账户名字段兼容
|
||||
*/
|
||||
if (isset($post['phone'])) {
|
||||
$post['account'] = $post['phone'];
|
||||
} elseif (isset($post['email'])) {
|
||||
$post['account'] = $post['email'];
|
||||
}
|
||||
|
||||
$validator = new AccountValidator();
|
||||
|
||||
$user = $validator->checkUserLogin($post['account'], $post['password']);
|
||||
|
||||
//$validator = new CaptchaValidator();
|
||||
|
||||
//$validator->checkCode($post['ticket'], $post['rand']);
|
||||
|
||||
return $this->auth->saveAuthInfo($user);
|
||||
}
|
||||
|
||||
public function loginByVerify()
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
/**
|
||||
* 使用[account|phone|email]做账户名字段兼容
|
||||
*/
|
||||
if (isset($post['phone'])) {
|
||||
$post['account'] = $post['phone'];
|
||||
} elseif (isset($post['email'])) {
|
||||
$post['account'] = $post['email'];
|
||||
}
|
||||
|
||||
$validator = new AccountValidator();
|
||||
|
||||
$user = $validator->checkVerifyLogin($post['account'], $post['verify_code']);
|
||||
|
||||
return $this->auth->saveAuthInfo($user);
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
$this->auth->clearAuthInfo();
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Services;
|
||||
|
||||
use App\Services\Auth\Api as ApiAuth;
|
||||
use App\Validators\Account as AccountValidator;
|
||||
|
||||
class Login extends Service
|
||||
{
|
||||
|
||||
public function loginByPassword($name, $password)
|
||||
{
|
||||
$validator = new AccountValidator();
|
||||
|
||||
$user = $validator->checkUserLogin($name, $password);
|
||||
|
||||
$auth = new ApiAuth();
|
||||
|
||||
return $auth->saveAuthInfo($user);
|
||||
}
|
||||
|
||||
public function loginByVerify($name, $code)
|
||||
{
|
||||
$validator = new AccountValidator();
|
||||
|
||||
$user = $validator->checkVerifyLogin($name, $code);
|
||||
|
||||
$auth = new ApiAuth();
|
||||
|
||||
return $auth->saveAuthInfo($user);
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Services;
|
||||
|
||||
use App\Services\Auth\Api as ApiAuth;
|
||||
|
||||
class Logout extends Service
|
||||
{
|
||||
|
||||
public function logout()
|
||||
{
|
||||
$auth = new ApiAuth();
|
||||
|
||||
return $auth->clearAuthInfo();
|
||||
}
|
||||
|
||||
}
|
125
app/Http/Api/Services/Trade.php
Normal file
125
app/Http/Api/Services/Trade.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Api\Services;
|
||||
|
||||
use App\Models\Client as ClientModel;
|
||||
use App\Models\Trade as TradeModel;
|
||||
use App\Services\Logic\OrderTrait;
|
||||
use App\Services\Logic\TradeTrait;
|
||||
use App\Services\Pay\Alipay;
|
||||
use App\Services\Pay\Wxpay;
|
||||
use App\Validators\Client as ClientValidator;
|
||||
use App\Validators\Trade as TradeValidator;
|
||||
|
||||
class Trade extends Service
|
||||
{
|
||||
|
||||
use OrderTrait;
|
||||
use TradeTrait;
|
||||
|
||||
public function h5Pay($sn)
|
||||
{
|
||||
$trade = $this->checkTradeBySn($sn);
|
||||
|
||||
$response = null;
|
||||
|
||||
if ($trade->channel == TradeModel::CHANNEL_ALIPAY) {
|
||||
$alipay = new Alipay();
|
||||
$response = $alipay->wap($trade);
|
||||
} elseif ($trade->channel == TradeModel::CHANNEL_WXPAY) {
|
||||
$wxpay = new Wxpay();
|
||||
$response = $wxpay->wap($trade);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function createH5Trade()
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$validator = new ClientValidator();
|
||||
|
||||
$platform = $this->getPlatform();
|
||||
|
||||
$validator->checkH5Platform($platform);
|
||||
|
||||
$order = $this->checkOrderBySn($post['order_sn']);
|
||||
|
||||
$user = $this->getLoginUser();
|
||||
|
||||
$validator = new TradeValidator();
|
||||
|
||||
$channel = $validator->checkChannel($post['channel']);
|
||||
|
||||
$trade = new TradeModel();
|
||||
|
||||
$trade->subject = $order->subject;
|
||||
$trade->amount = $order->amount;
|
||||
$trade->channel = $channel;
|
||||
$trade->order_id = $order->id;
|
||||
$trade->owner_id = $user->id;
|
||||
|
||||
$trade->create();
|
||||
|
||||
return $trade;
|
||||
}
|
||||
|
||||
public function createMpTrade()
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$validator = new ClientValidator();
|
||||
|
||||
$platform = $this->getPlatform();
|
||||
|
||||
$platform = $validator->checkMpPlatform($platform);
|
||||
|
||||
$order = $this->checkOrderBySn($post['order_sn']);
|
||||
|
||||
$user = $this->getLoginUser();
|
||||
|
||||
$channel = TradeModel::CHANNEL_WXPAY;
|
||||
|
||||
if ($platform == ClientModel::TYPE_MP_ALIPAY) {
|
||||
$channel = TradeModel::CHANNEL_ALIPAY;
|
||||
} elseif ($platform == ClientModel::TYPE_MP_WEIXIN) {
|
||||
$channel = TradeModel::CHANNEL_WXPAY;
|
||||
}
|
||||
|
||||
$trade = new TradeModel();
|
||||
|
||||
$trade->subject = $order->subject;
|
||||
$trade->amount = $order->amount;
|
||||
$trade->channel = $channel;
|
||||
$trade->order_id = $order->id;
|
||||
$trade->owner_id = $user->id;
|
||||
|
||||
$trade->create();
|
||||
|
||||
$response = null;
|
||||
|
||||
if ($post['channel'] == TradeModel::CHANNEL_ALIPAY) {
|
||||
$alipay = new Alipay();
|
||||
$buyerId = '';
|
||||
$response = $alipay->mini($trade, $buyerId);
|
||||
} elseif ($post['channel'] == TradeModel::CHANNEL_WXPAY) {
|
||||
$wxpay = new Wxpay();
|
||||
$openId = '';
|
||||
$response = $wxpay->mini($trade, $openId);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function createAppTrade()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected function getPlatform()
|
||||
{
|
||||
return $this->request->getHeader('X-Platform');
|
||||
}
|
||||
|
||||
}
|
@ -81,9 +81,7 @@ class AccountController extends Controller
|
||||
|
||||
$location = $returnUrl ?: $this->url->get(['for' => 'home.index']);
|
||||
|
||||
$content = ['location' => $location];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['location' => $location]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,9 +97,7 @@ class AccountController extends Controller
|
||||
|
||||
$location = $returnUrl ?: $this->url->get(['for' => 'home.index']);
|
||||
|
||||
$content = ['location' => $location];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['location' => $location]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,18 @@ class ChapterController extends Controller
|
||||
$this->view->setVar('items', $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/danmus", name="home.chapter.danmus")
|
||||
*/
|
||||
public function danmusAction($id)
|
||||
{
|
||||
$service = new ChapterDanmuListService();
|
||||
|
||||
$items = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['items' => $items]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}", name="home.chapter.show")
|
||||
*/
|
||||
@ -75,18 +87,6 @@ class ChapterController extends Controller
|
||||
$this->view->setVar('catalog', $catalog);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/danmu", name="home.chapter.danmu")
|
||||
*/
|
||||
public function danmuAction($id)
|
||||
{
|
||||
$service = new ChapterDanmuListService();
|
||||
|
||||
$items = $service->handle($id);
|
||||
|
||||
return $this->jsonSuccess(['items' => $items]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/{id:[0-9]+}/like", name="home.chapter.like")
|
||||
*/
|
||||
@ -98,9 +98,7 @@ class ChapterController extends Controller
|
||||
|
||||
$msg = $like->deleted == 0 ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
$content = ['msg' => $msg];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Http\Home\Controllers;
|
||||
|
||||
use App\Http\Home\Services\ChapterLive as ChapterLiveService;
|
||||
use App\Traits\Response as ResponseTrait;
|
||||
use Phalcon\Mvc\View;
|
||||
|
||||
/**
|
||||
@ -12,8 +11,6 @@ use Phalcon\Mvc\View;
|
||||
class ChapterLiveController extends Controller
|
||||
{
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
/**
|
||||
* @Get("/{id:[0-9]+}/chats", name="home.live.chats")
|
||||
*/
|
||||
|
@ -58,9 +58,12 @@ class ConsultController extends Controller
|
||||
|
||||
$service = new ConsultInfoService();
|
||||
|
||||
$service->handle($consult->id);
|
||||
$consult = $service->handle($consult->id);
|
||||
|
||||
$content = ['msg' => '提交咨询成功'];
|
||||
$content = [
|
||||
'consult' => $consult,
|
||||
'msg' => '提交咨询成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
@ -72,9 +75,16 @@ class ConsultController extends Controller
|
||||
{
|
||||
$service = new ConsultUpdateService();
|
||||
|
||||
$service->handle($id);
|
||||
$consult = $service->handle($id);
|
||||
|
||||
$content = ['msg' => '更新咨询成功'];
|
||||
$service = new ConsultInfoService();
|
||||
|
||||
$consult = $service->handle($consult->id);
|
||||
|
||||
$content = [
|
||||
'consult' => $consult,
|
||||
'msg' => '更新咨询成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
}
|
||||
@ -88,9 +98,7 @@ class ConsultController extends Controller
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
$content = ['msg' => '删除咨询成功'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '删除咨询成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,9 +110,16 @@ class ConsultController extends Controller
|
||||
|
||||
$service = new ConsultReplyService();
|
||||
|
||||
$service->handle($id);
|
||||
$consult = $service->handle($id);
|
||||
|
||||
$content = ['msg' => '回复咨询成功'];
|
||||
$service = new ConsultInfoService();
|
||||
|
||||
$consult = $service->handle($consult->id);
|
||||
|
||||
$content = [
|
||||
'consult' => $consult,
|
||||
'msg' => '回复咨询成功',
|
||||
];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
|
||||
@ -129,9 +144,7 @@ class ConsultController extends Controller
|
||||
|
||||
$msg = $like->deleted == 0 ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
$content = ['msg' => $msg];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,6 +58,7 @@ class Controller extends \Phalcon\Mvc\Controller
|
||||
'controller' => 'error',
|
||||
'action' => 'maintain',
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isNotSafeRequest()) {
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Http\Home\Controllers;
|
||||
|
||||
use App\Http\Home\Services\Im as ImService;
|
||||
use App\Traits\Response as ResponseTrait;
|
||||
use Phalcon\Mvc\View;
|
||||
|
||||
/**
|
||||
@ -12,8 +11,6 @@ use Phalcon\Mvc\View;
|
||||
class ImController extends Controller
|
||||
{
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
@ -265,9 +262,7 @@ class ImController extends Controller
|
||||
|
||||
$service->applyFriend();
|
||||
|
||||
$content = ['msg' => '发送申请成功,请等待对方通过'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '发送申请成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -303,9 +298,7 @@ class ImController extends Controller
|
||||
|
||||
$service->applyGroup();
|
||||
|
||||
$content = ['msg' => '发送申请成功,请等待管理员通过'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '发送申请成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,9 +334,7 @@ class ImController extends Controller
|
||||
|
||||
$service->quitFriend($id);
|
||||
|
||||
$content = ['msg' => '解除好友成功'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '解除好友成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,9 +346,7 @@ class ImController extends Controller
|
||||
|
||||
$service->quitGroup($id);
|
||||
|
||||
$content = ['msg' => '退出群组成功'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '退出群组成功']);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,9 +48,7 @@ class ImGroupManageController extends Controller
|
||||
|
||||
$service->updateGroup($id);
|
||||
|
||||
$content = ['msg' => '更新群组成功'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '更新群组成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,8 +60,10 @@ class ImGroupManageController extends Controller
|
||||
|
||||
$service->deleteGroupUser($gid, $uid);
|
||||
|
||||
$location = $this->request->getHTTPReferer();
|
||||
|
||||
$content = [
|
||||
'location' => $this->request->getHTTPReferer(),
|
||||
'location' => $location,
|
||||
'msg' => '移除用户成功',
|
||||
];
|
||||
|
||||
|
@ -3,10 +3,26 @@
|
||||
namespace App\Http\Home\Controllers;
|
||||
|
||||
use App\Http\Home\Services\Index as IndexService;
|
||||
use App\Traits\Client as ClientTrait;
|
||||
use Phalcon\Mvc\Dispatcher;
|
||||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
use ClientTrait;
|
||||
|
||||
public function beforeExecuteRoute(Dispatcher $dispatcher)
|
||||
{
|
||||
if ($this->isMobileBrowser()) {
|
||||
|
||||
$this->response->redirect('/h5', true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::beforeExecuteRoute($dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/", name="home.index")
|
||||
*/
|
||||
|
@ -48,8 +48,8 @@ class OrderController extends Controller
|
||||
*/
|
||||
public function confirmAction()
|
||||
{
|
||||
$itemId = $this->request->getQuery('item_id', 'int');
|
||||
$itemType = $this->request->getQuery('item_type', 'int');
|
||||
$itemId = $this->request->getQuery('item_id', 'string');
|
||||
$itemType = $this->request->getQuery('item_type', 'string');
|
||||
|
||||
$service = new OrderConfirmService();
|
||||
|
||||
|
@ -44,8 +44,10 @@ class RefundController extends Controller
|
||||
|
||||
$service->handle();
|
||||
|
||||
$location = $this->url->get(['for' => 'home.my.refunds']);
|
||||
|
||||
$content = [
|
||||
'location' => $this->url->get(['for' => 'home.my.refunds']),
|
||||
'location' => $location,
|
||||
'msg' => '申请退款成功',
|
||||
];
|
||||
|
||||
@ -78,8 +80,10 @@ class RefundController extends Controller
|
||||
|
||||
$service->handle($sn);
|
||||
|
||||
$location = $this->url->get(['for' => 'home.my.refunds']);
|
||||
|
||||
$content = [
|
||||
'location' => $this->url->get(['for' => 'home.my.refunds']),
|
||||
'location' => $location,
|
||||
'msg' => '取消退款成功',
|
||||
];
|
||||
|
||||
|
@ -99,9 +99,7 @@ class ReviewController extends Controller
|
||||
|
||||
$service->handle($id);
|
||||
|
||||
$content = ['msg' => '删除评价成功'];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => '删除评价成功']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,9 +113,7 @@ class ReviewController extends Controller
|
||||
|
||||
$msg = $like->deleted == 0 ? '点赞成功' : '取消点赞成功';
|
||||
|
||||
$content = ['msg' => $msg];
|
||||
|
||||
return $this->jsonSuccess($content);
|
||||
return $this->jsonSuccess(['msg' => $msg]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace App\Http\Home\Controllers;
|
||||
use App\Services\Logic\Search\Course as CourseSearchService;
|
||||
use App\Services\Logic\Search\Group as GroupSearchService;
|
||||
use App\Services\Logic\Search\User as UserSearchService;
|
||||
use App\Traits\Response as ResponseTrait;
|
||||
|
||||
/**
|
||||
* @RoutePrefix("/search")
|
||||
@ -13,8 +12,6 @@ use App\Traits\Response as ResponseTrait;
|
||||
class SearchController extends Controller
|
||||
{
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
/**
|
||||
* @Get("/", name="home.search.index")
|
||||
*/
|
||||
@ -42,14 +39,6 @@ class SearchController extends Controller
|
||||
$this->view->setVar('pager', $pager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Get("/form", name="home.search.form")
|
||||
*/
|
||||
public function formAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return CourseSearchService|GroupSearchService|UserSearchService
|
||||
|
@ -20,16 +20,16 @@ class UploadController extends Controller
|
||||
|
||||
$file = $service->uploadAvatarImage();
|
||||
|
||||
if ($file) {
|
||||
return $this->jsonSuccess([
|
||||
'data' => [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
if (!$file) {
|
||||
return $this->jsonError(['msg' => '上传文件失败']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'src' => $service->getImageUrl($file->path),
|
||||
'title' => $file->name,
|
||||
];
|
||||
|
||||
return $this->jsonSuccess(['data' => $data]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,6 @@ namespace App\Http\Home\Controllers;
|
||||
|
||||
use App\Services\Logic\Verify\EmailCode as EmailCodeService;
|
||||
use App\Services\Logic\Verify\SmsCode as SmsCodeService;
|
||||
use App\Services\Logic\Verify\VerifyCode as VerifyCodeService;
|
||||
use App\Traits\Response as ResponseTrait;
|
||||
|
||||
/**
|
||||
@ -15,18 +14,6 @@ class VerifyController extends \Phalcon\Mvc\Controller
|
||||
|
||||
use ResponseTrait;
|
||||
|
||||
/**
|
||||
* @Post("/code", name="verify.code")
|
||||
*/
|
||||
public function verifyCodeAction()
|
||||
{
|
||||
$service = new VerifyCodeService();
|
||||
|
||||
$service->handle();
|
||||
|
||||
return $this->jsonSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Post("/sms/code", name="verify.sms_code")
|
||||
*/
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace App\Http\Home\Services;
|
||||
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Auth as AuthService;
|
||||
use App\Services\Auth\Home as AuthService;
|
||||
use App\Services\Logic\Account\Register as RegisterService;
|
||||
use App\Validators\Account as AccountValidator;
|
||||
use App\Validators\Captcha as CaptchaValidator;
|
||||
@ -40,13 +40,13 @@ class Account extends Service
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$accountValidator = new AccountValidator();
|
||||
$validator = new AccountValidator();
|
||||
|
||||
$user = $accountValidator->checkUserLogin($post['account'], $post['password']);
|
||||
$user = $validator->checkUserLogin($post['account'], $post['password']);
|
||||
|
||||
$captchaValidator = new CaptchaValidator();
|
||||
$validator = new CaptchaValidator();
|
||||
|
||||
$captchaValidator->checkCode($post['ticket'], $post['rand']);
|
||||
$validator->checkCode($post['ticket'], $post['rand']);
|
||||
|
||||
$this->auth->saveAuthInfo($user);
|
||||
}
|
||||
@ -55,9 +55,9 @@ class Account extends Service
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$accountValidator = new AccountValidator();
|
||||
$validator = new AccountValidator();
|
||||
|
||||
$user = $accountValidator->checkVerifyLogin($post['account'], $post['verify_code']);
|
||||
$user = $validator->checkVerifyLogin($post['account'], $post['verify_code']);
|
||||
|
||||
$this->auth->saveAuthInfo($user);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
{% set priv = lesson.me.owned ? 'allow' : 'deny' %}
|
||||
<a class="{{ priv }} view-lesson" href="javascript:" data-url="{{ url }}">
|
||||
<i class="layui-icon layui-icon-read"></i>
|
||||
<span class="title">{{ lesson.title|e }}</span>
|
||||
<span class="title">{{ lesson.title }}</span>
|
||||
{% if lesson.free == 1 %}
|
||||
<span class="layui-badge free-badge">免费</span>
|
||||
{% endif %}
|
||||
|
@ -32,12 +32,12 @@
|
||||
<div class="course-card">
|
||||
<div class="cover">
|
||||
<a href="{{ course_url }}">
|
||||
<img src="{{ course.cover }}!cover_270" alt="{{ course.title|e }}" title="{{ course.title|e }}">
|
||||
<img src="{{ course.cover }}!cover_270" alt="{{ course.title }}" title="{{ course.title }}">
|
||||
</a>
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="title layui-elip">
|
||||
<a href="{{ course_url }}" title="{{ course.title|e }}">{{ course.title }}</a>
|
||||
<a href="{{ course_url }}" title="{{ course.title }}">{{ course.title }}</a>
|
||||
</div>
|
||||
<div class="meta">
|
||||
{% if course.market_price > course.vip_price %}
|
||||
@ -69,11 +69,11 @@
|
||||
{% set course_url = url({'for':'home.course.show','id':course.id}) %}
|
||||
<div class="sidebar-course-card clearfix">
|
||||
<div class="cover">
|
||||
<img src="{{ course.cover }}!cover_270" alt="{{ course.title|e }}">
|
||||
<img src="{{ course.cover }}!cover_270" alt="{{ course.title }}">
|
||||
</div>
|
||||
<div class="info">
|
||||
<div class="title layui-elip">
|
||||
<a href="{{ course_url }}" title="{{ course.title|e }}">{{ course.title }}</a>
|
||||
<a href="{{ course_url }}" title="{{ course.title }}">{{ course.title }}</a>
|
||||
</div>
|
||||
<div class="meta">
|
||||
{% if course.market_price > 0 %}
|
||||
@ -91,7 +91,7 @@
|
||||
{%- endmacro %}
|
||||
|
||||
{%- macro learning_course_card(item) %}
|
||||
{% set course_title = item.course.title|e %}
|
||||
{% set course_title = item.course.title %}
|
||||
{% set course_url = url({'for':'home.course.show','id':item.course.id}) %}
|
||||
<div class="course-card">
|
||||
<div class="cover">
|
||||
|
@ -8,7 +8,7 @@
|
||||
{% set course_url = url({'for':'home.course.show','id':course.id}) %}
|
||||
<div class="cart-course-card clearfix">
|
||||
<div class="cover">
|
||||
<img src="{{ course.cover }}!cover_270" alt="course.title|e">
|
||||
<img src="{{ course.cover }}!cover_270" alt="{{ course.title }}">
|
||||
</div>
|
||||
<div class="info">
|
||||
<p><a href="{{ course_url }}" target="_blank">{{ course.title }}</a></p>
|
||||
@ -30,7 +30,7 @@
|
||||
{% set course_url = url({'for':'home.course.show','id':course.id}) %}
|
||||
<div class="cart-course-card clearfix">
|
||||
<div class="cover">
|
||||
<img src="{{ course.cover }}!cover_270" alt="course.title|e">
|
||||
<img src="{{ course.cover }}!cover_270" alt="{{ course.title }}">
|
||||
</div>
|
||||
<div class="info">
|
||||
<p><a href="{{ course_url }}" target="_blank">{{ course.title }}</a></p>
|
||||
|
136
app/Models/App.php
Normal file
136
app/Models/App.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Phalcon\Mvc\Model\Behavior\SoftDelete;
|
||||
use Phalcon\Text;
|
||||
|
||||
class App extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 应用类型
|
||||
*/
|
||||
const TYPE_PC = 'pc';
|
||||
const TYPE_H5 = 'h5';
|
||||
const TYPE_IOS = 'ios';
|
||||
const TYPE_ANDROID = 'android';
|
||||
const TYPE_MP_WEIXIN = 'mp_weixin';
|
||||
const TYPE_MP_ALIPAY = 'mp_alipay';
|
||||
|
||||
/**
|
||||
* 主键编号
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* secret
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $secret;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $remark;
|
||||
|
||||
/**
|
||||
* 发布标识
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $published;
|
||||
|
||||
/**
|
||||
* 删除标识
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $deleted;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $create_time;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $update_time;
|
||||
|
||||
public function getSource(): string
|
||||
{
|
||||
return 'kg_app';
|
||||
}
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addBehavior(
|
||||
new SoftDelete([
|
||||
'field' => 'deleted',
|
||||
'value' => 1,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function beforeCreate()
|
||||
{
|
||||
$this->key = Text::random(Text::RANDOM_ALNUM, 16);
|
||||
$this->secret = Text::random(Text::RANDOM_ALNUM, 16);
|
||||
$this->create_time = time();
|
||||
}
|
||||
|
||||
public function beforeUpdate()
|
||||
{
|
||||
if ($this->deleted == 1) {
|
||||
$this->published = 0;
|
||||
}
|
||||
|
||||
$this->update_time = time();
|
||||
}
|
||||
|
||||
public static function types()
|
||||
{
|
||||
return [
|
||||
self::TYPE_PC => 'PC客户端',
|
||||
self::TYPE_H5 => 'H5客户端',
|
||||
self::TYPE_IOS => 'IOS客户端',
|
||||
self::TYPE_ANDROID => 'Android客户端',
|
||||
self::TYPE_MP_WEIXIN => '微信小程序',
|
||||
self::TYPE_MP_ALIPAY => '支付宝小程序',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
126
app/Models/AppVersion.php
Normal file
126
app/Models/AppVersion.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Caches\MaxCategoryId as MaxCategoryIdCache;
|
||||
use Phalcon\Mvc\Model\Behavior\SoftDelete;
|
||||
|
||||
class AppVersion extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* 平台类型
|
||||
*/
|
||||
const PLATFORM_IOS = 1;
|
||||
const PLATFORM_ANDROID = 2;
|
||||
|
||||
/**
|
||||
* 主键编号
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* 平台类型
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $platform;
|
||||
|
||||
/**
|
||||
* 版本名(例如:v1.0.0)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $version_name;
|
||||
|
||||
/**
|
||||
* 版本号(例如:100)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $version_code;
|
||||
|
||||
/**
|
||||
* 下载地址
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $download_url;
|
||||
|
||||
/**
|
||||
* 发布标识
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $published;
|
||||
|
||||
/**
|
||||
* 删除标识
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $deleted;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $create_time;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $update_time;
|
||||
|
||||
public function getSource(): string
|
||||
{
|
||||
return 'kg_category';
|
||||
}
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
$this->addBehavior(
|
||||
new SoftDelete([
|
||||
'field' => 'deleted',
|
||||
'value' => 1,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function beforeCreate()
|
||||
{
|
||||
$this->create_time = time();
|
||||
}
|
||||
|
||||
public function beforeUpdate()
|
||||
{
|
||||
if ($this->deleted == 1) {
|
||||
$this->published = 0;
|
||||
}
|
||||
|
||||
$this->update_time = time();
|
||||
}
|
||||
|
||||
public function afterCreate()
|
||||
{
|
||||
$cache = new MaxCategoryIdCache();
|
||||
|
||||
$cache->rebuild();
|
||||
}
|
||||
|
||||
public static function types()
|
||||
{
|
||||
return [
|
||||
self::TYPE_COURSE => '课程',
|
||||
self::TYPE_HELP => '帮助',
|
||||
];
|
||||
}
|
||||
|
||||
}
|
@ -8,18 +8,30 @@ class Client
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
const TYPE_DESKTOP = 1; // desktop
|
||||
const TYPE_MOBILE = 2; // mobile
|
||||
const TYPE_APP = 3; // app
|
||||
const TYPE_MINI = 4; // 小程序
|
||||
const TYPE_PC = 1;
|
||||
const TYPE_H5 = 2;
|
||||
const TYPE_APP = 3;
|
||||
const TYPE_MP = 4;
|
||||
const TYPE_MP_WEIXIN = 5;
|
||||
const TYPE_MP_ALIPAY = 6;
|
||||
const TYPE_MP_BAIDU = 7;
|
||||
const TYPE_MP_TOUTIAO = 8;
|
||||
const TYPE_MP_QQ = 9;
|
||||
const TYPE_MP_360 = 10;
|
||||
|
||||
public static function types()
|
||||
{
|
||||
return [
|
||||
self::TYPE_DESKTOP => 'desktop',
|
||||
self::TYPE_MOBILE => 'mobile',
|
||||
self::TYPE_APP => 'app',
|
||||
self::TYPE_MINI => 'mini',
|
||||
self::TYPE_PC => 'PC',
|
||||
self::TYPE_H5 => 'H5',
|
||||
self::TYPE_APP => 'APP',
|
||||
self::TYPE_MP => 'MP',
|
||||
self::TYPE_MP_WEIXIN => 'MP-WEIXIN',
|
||||
self::TYPE_MP_ALIPAY => 'MP-ALIPAY',
|
||||
self::TYPE_MP_BAIDU => 'MP-BAIDU',
|
||||
self::TYPE_MP_TOUTIAO => 'MP-TOUTIAO',
|
||||
self::TYPE_MP_QQ => 'MP-QQ',
|
||||
self::TYPE_MP_360 => 'MP-360',
|
||||
];
|
||||
}
|
||||
|
||||
|
78
app/Repos/App.php
Normal file
78
app/Repos/App.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repos;
|
||||
|
||||
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
||||
use App\Models\App as AppModel;
|
||||
use Phalcon\Mvc\Model;
|
||||
|
||||
class App extends Repository
|
||||
{
|
||||
|
||||
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
|
||||
{
|
||||
$builder = $this->modelsManager->createBuilder();
|
||||
|
||||
$builder->from(AppModel::class);
|
||||
|
||||
$builder->where('1 = 1');
|
||||
|
||||
if (!empty($where['id'])) {
|
||||
$builder->andWhere('id = :id:', ['id' => $where['id']]);
|
||||
}
|
||||
|
||||
if (!empty($where['key'])) {
|
||||
$builder->andWhere('key = :key:', ['key' => $where['key']]);
|
||||
}
|
||||
|
||||
if (!empty($where['type'])) {
|
||||
$builder->andWhere('type = :type:', ['type' => $where['type']]);
|
||||
}
|
||||
|
||||
if (!empty($where['published'])) {
|
||||
$builder->andWhere('published = :published:', ['published' => $where['published']]);
|
||||
}
|
||||
|
||||
if (isset($where['deleted'])) {
|
||||
$builder->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]);
|
||||
}
|
||||
|
||||
switch ($sort) {
|
||||
default:
|
||||
$orderBy = 'id DESC';
|
||||
break;
|
||||
}
|
||||
|
||||
$builder->orderBy($orderBy);
|
||||
|
||||
$pager = new PagerQueryBuilder([
|
||||
'builder' => $builder,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
]);
|
||||
|
||||
return $pager->paginate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return AppModel|Model|bool
|
||||
*/
|
||||
public function findById($id)
|
||||
{
|
||||
return AppModel::findFirst($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $appKey
|
||||
* @return AppModel|Model|bool
|
||||
*/
|
||||
public function findByAppKey($appKey)
|
||||
{
|
||||
return AppModel::findFirst([
|
||||
'conditions' => 'key = :key:',
|
||||
'bind' => ['key' => $appKey],
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -41,7 +41,7 @@ class Api extends AuthService
|
||||
|
||||
public function getAuthInfo()
|
||||
{
|
||||
$authToken = $this->getAuthToken();
|
||||
$authToken = $this->request->getHeader('X-Token');
|
||||
|
||||
if (!$authToken) return null;
|
||||
|
||||
@ -69,11 +69,4 @@ class Api extends AuthService
|
||||
];
|
||||
}
|
||||
|
||||
protected function getAuthToken()
|
||||
{
|
||||
$authorization = $this->request->getHeader('Authorization');
|
||||
|
||||
return trim(str_ireplace('Bearer', '', $authorization));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,46 +32,57 @@ class ConsultInfo extends Service
|
||||
'like_count' => $consult->like_count,
|
||||
'create_time' => $consult->create_time,
|
||||
'update_time' => $consult->update_time,
|
||||
'course' => new \stdClass(),
|
||||
'chapter' => new \stdClass(),
|
||||
'owner' => new \stdClass(),
|
||||
];
|
||||
|
||||
$courseRepo = new CourseRepo();
|
||||
|
||||
$course = $courseRepo->findById($consult->course_id);
|
||||
|
||||
if ($course) {
|
||||
$result['course'] = [
|
||||
'id' => $course->id,
|
||||
'title' => $course->title,
|
||||
];
|
||||
}
|
||||
|
||||
$chapterRepo = new ChapterRepo();
|
||||
|
||||
$chapter = $chapterRepo->findById($consult->chapter_id);
|
||||
|
||||
if ($chapter) {
|
||||
$result['chapter'] = [
|
||||
'id' => $chapter->id,
|
||||
'title' => $chapter->title,
|
||||
];
|
||||
}
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$owner = $userRepo->findById($consult->owner_id);
|
||||
|
||||
if ($owner) {
|
||||
$result['owner'] = [
|
||||
'id' => $owner->id,
|
||||
'name' => $owner->name,
|
||||
'avatar' => $owner->avatar,
|
||||
];
|
||||
}
|
||||
$result['course'] = $this->handleCourseInfo($consult);
|
||||
$result['chapter'] = $this->handleChapterInfo($consult);
|
||||
$result['owner'] = $this->handleOwnerInfo($consult);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function handleCourseInfo(ConsultModel $consult)
|
||||
{
|
||||
$courseRepo = new CourseRepo();
|
||||
|
||||
$course = $courseRepo->findById($consult->course_id);
|
||||
|
||||
if (!$course) return new \stdClass();
|
||||
|
||||
return [
|
||||
'id' => $course->id,
|
||||
'title' => $course->title,
|
||||
'cover' => $course->cover,
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleChapterInfo(ConsultModel $consult)
|
||||
{
|
||||
$chapterRepo = new ChapterRepo();
|
||||
|
||||
$chapter = $chapterRepo->findById($consult->chapter_id);
|
||||
|
||||
if (!$chapter) return new \stdClass();
|
||||
|
||||
return [
|
||||
'id' => $chapter->id,
|
||||
'title' => $chapter->title,
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleOwnerInfo(ConsultModel $consult)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$owner = $userRepo->findById($consult->owner_id);
|
||||
|
||||
if (!$owner) return new \stdClass();
|
||||
|
||||
return [
|
||||
'id' => $owner->id,
|
||||
'name' => $owner->name,
|
||||
'avatar' => $owner->avatar,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ class BasicInfo extends Service
|
||||
'attrs' => $course->attrs,
|
||||
'user_count' => $course->user_count,
|
||||
'lesson_count' => $course->lesson_count,
|
||||
'resource_count' => $course->resource_count,
|
||||
'package_count' => $course->package_count,
|
||||
'review_count' => $course->review_count,
|
||||
'consult_count' => $course->consult_count,
|
||||
|
19
app/Services/Logic/Course/CategoryList.php
Normal file
19
app/Services/Logic/Course/CategoryList.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic\Course;
|
||||
|
||||
use App\Caches\CategoryTreeList as CategoryTreeListCache;
|
||||
use App\Models\Category as CategoryModel;
|
||||
use App\Services\Logic\Service;
|
||||
|
||||
class CategoryList extends Service
|
||||
{
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$cache = new CategoryTreeListCache();
|
||||
|
||||
return $cache->get(CategoryModel::TYPE_COURSE);
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
use App\Services\Category as CategoryService;
|
||||
use App\Services\Logic\Service;
|
||||
use App\Validators\CourseQuery as CourseQueryValidator;
|
||||
|
||||
class CourseList extends Service
|
||||
{
|
||||
@ -16,6 +17,8 @@ class CourseList extends Service
|
||||
|
||||
$params = $pagerQuery->getParams();
|
||||
|
||||
$params = $this->checkQueryParams($params);
|
||||
|
||||
/**
|
||||
* tc => top_category
|
||||
* sc => sub_category
|
||||
@ -84,4 +87,29 @@ class CourseList extends Service
|
||||
return $pager;
|
||||
}
|
||||
|
||||
protected function checkQueryParams($params)
|
||||
{
|
||||
$validator = new CourseQueryValidator();
|
||||
|
||||
$query = [];
|
||||
|
||||
if (isset($params['tc'])) {
|
||||
$query['tc'] = $validator->checkTopCategory($params['tc']);
|
||||
}
|
||||
|
||||
if (isset($params['sc'])) {
|
||||
$query['sc'] = $validator->checkSubCategory($params['sc']);
|
||||
}
|
||||
|
||||
if (isset($params['model'])) {
|
||||
$query['model'] = $validator->checkModel($params['model']);
|
||||
}
|
||||
|
||||
if (isset($params['level'])) {
|
||||
$query['level'] = $validator->checkLevel($params['level']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
}
|
||||
|
42
app/Services/Logic/Im/GroupInfo.php
Normal file
42
app/Services/Logic/Im/GroupInfo.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic\Im;
|
||||
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Logic\ImGroupTrait;
|
||||
use App\Services\Logic\Service;
|
||||
|
||||
|
||||
class GroupInfo extends Service
|
||||
{
|
||||
|
||||
use ImGroupTrait;
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$group = $this->checkGroup($id);
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$owner = $userRepo->findById($group->owner_id);
|
||||
|
||||
return [
|
||||
'id' => $group->id,
|
||||
'type' => $group->type,
|
||||
'name' => $group->name,
|
||||
'avatar' => $group->avatar,
|
||||
'about' => $group->about,
|
||||
'user_count' => $group->user_count,
|
||||
'msg_count' => $group->msg_count,
|
||||
'owner' => [
|
||||
'id' => $owner->id,
|
||||
'name' => $owner->name,
|
||||
'avatar' => $owner->avatar,
|
||||
'title' => $owner->title,
|
||||
'about' => $owner->about,
|
||||
'vip' => $owner->vip,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
70
app/Services/Logic/Im/GroupList.php
Normal file
70
app/Services/Logic/Im/GroupList.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic\Im;
|
||||
|
||||
use App\Builders\ImGroupList as ImGroupListBuilder;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Repos\ImGroup as ImGroupRepo;
|
||||
use App\Services\Logic\Service;
|
||||
|
||||
class GroupList extends Service
|
||||
{
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$pagerQuery = new PagerQuery();
|
||||
|
||||
$params = $pagerQuery->getParams();
|
||||
|
||||
$params['published'] = 1;
|
||||
|
||||
$sort = $pagerQuery->getSort();
|
||||
$page = $pagerQuery->getPage();
|
||||
$limit = $pagerQuery->getLimit();
|
||||
|
||||
$groupRepo = new ImGroupRepo();
|
||||
|
||||
$pager = $groupRepo->paginate($params, $sort, $page, $limit);
|
||||
|
||||
return $this->handleGroups($pager);
|
||||
}
|
||||
|
||||
protected function handleGroups($pager)
|
||||
{
|
||||
if ($pager->total_items == 0) {
|
||||
return $pager;
|
||||
}
|
||||
|
||||
$builder = new ImGroupListBuilder();
|
||||
|
||||
$groups = $pager->items->toArray();
|
||||
|
||||
$users = $builder->getUsers($groups);
|
||||
|
||||
$baseUrl = kg_cos_url();
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($groups as $group) {
|
||||
|
||||
$group['avatar'] = $baseUrl . $group['avatar'];
|
||||
$group['owner'] = $users[$group['owner_id']] ?? new \stdClass();
|
||||
|
||||
$items[] = [
|
||||
'id' => $group['id'],
|
||||
'type' => $group['type'],
|
||||
'name' => $group['name'],
|
||||
'avatar' => $group['avatar'],
|
||||
'about' => $group['about'],
|
||||
'user_count' => $group['user_count'],
|
||||
'msg_count' => $group['msg_count'],
|
||||
'owner' => $group['owner'],
|
||||
];
|
||||
}
|
||||
|
||||
$pager->items = $items;
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
}
|
61
app/Services/Logic/Im/GroupUserList.php
Normal file
61
app/Services/Logic/Im/GroupUserList.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic\Im;
|
||||
|
||||
use App\Builders\ImGroupUserList as ImGroupUserListBuilder;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Repos\ImGroupUser as ImGroupUserRepo;
|
||||
use App\Services\Logic\ImGroupTrait;
|
||||
use App\Services\Logic\Service;
|
||||
|
||||
class GroupUserList extends Service
|
||||
{
|
||||
|
||||
use ImGroupTrait;
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$group = $this->checkGroup($id);
|
||||
|
||||
$pagerQuery = new PagerQuery();
|
||||
|
||||
$params = $pagerQuery->getParams();
|
||||
|
||||
$params['group_id'] = $group->id;
|
||||
|
||||
$sort = $pagerQuery->getSort();
|
||||
$page = $pagerQuery->getPage();
|
||||
$limit = $pagerQuery->getLimit();
|
||||
|
||||
$repo = new ImGroupUserRepo();
|
||||
|
||||
$pager = $repo->paginate($params, $sort, $page, $limit);
|
||||
|
||||
return $this->handleGroupUsers($pager);
|
||||
}
|
||||
|
||||
protected function handleGroupUsers($pager)
|
||||
{
|
||||
if ($pager->total_items == 0) {
|
||||
return $pager;
|
||||
}
|
||||
|
||||
$builder = new ImGroupUserListBuilder();
|
||||
|
||||
$relations = $pager->items->toArray();
|
||||
|
||||
$users = $builder->getUsers($relations);
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($relations as $relation) {
|
||||
$user = $users[$relation['user_id']] ?? new \stdClass();
|
||||
$items[] = $user;
|
||||
}
|
||||
|
||||
$pager->items = $items;
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
}
|
17
app/Services/Logic/ImGroupTrait.php
Normal file
17
app/Services/Logic/ImGroupTrait.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic;
|
||||
|
||||
use App\Validators\ImGroup as ImGroupValidator;
|
||||
|
||||
trait ImGroupTrait
|
||||
{
|
||||
|
||||
public function checkGroup($id)
|
||||
{
|
||||
$validator = new ImGroupValidator();
|
||||
|
||||
return $validator->checkGroup($id);
|
||||
}
|
||||
|
||||
}
|
@ -34,6 +34,8 @@ class OrderInfo extends Service
|
||||
'item_id' => $order->item_id,
|
||||
'item_type' => $order->item_type,
|
||||
'item_info' => $order->item_info,
|
||||
'create_time' => $order->create_time,
|
||||
'update_time' => $order->update_time,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@ class RefundCancel extends Service
|
||||
|
||||
$validator = new RefundValidator();
|
||||
|
||||
$validator->checkIfAllowCancel($refund);
|
||||
|
||||
$validator->checkOwner($user->id, $refund->owner_id);
|
||||
|
||||
$refund->status = RefundModel::STATUS_CANCELED;
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services\Logic\Review;
|
||||
|
||||
use App\Models\Course as CourseModel;
|
||||
use App\Models\CourseUser as CourseUserModel;
|
||||
use App\Models\Review as ReviewModel;
|
||||
use App\Services\CourseStat as CourseStatService;
|
||||
use App\Services\Logic\CourseTrait;
|
||||
@ -21,13 +22,14 @@ class ReviewCreate extends Service
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$course = $this->checkCourseCache($post['course_id']);
|
||||
$course = $this->checkCourse($post['course_id']);
|
||||
|
||||
$user = $this->getLoginUser();
|
||||
|
||||
$validator = new CourseUserValidator();
|
||||
|
||||
$validator->checkCourseUser($course->id, $user->id);
|
||||
$courseUser = $validator->checkCourseUser($course->id, $user->id);
|
||||
|
||||
$validator->checkIfReviewed($course->id, $user->id);
|
||||
|
||||
$validator = new ReviewValidator();
|
||||
@ -46,6 +48,8 @@ class ReviewCreate extends Service
|
||||
|
||||
$review->create($data);
|
||||
|
||||
$this->updateCourseUserReview($courseUser);
|
||||
|
||||
$this->incrCourseReviewCount($course);
|
||||
|
||||
$this->updateCourseRating($course->id);
|
||||
@ -53,6 +57,13 @@ class ReviewCreate extends Service
|
||||
return $review;
|
||||
}
|
||||
|
||||
protected function updateCourseUserReview(CourseUserModel $courseUser)
|
||||
{
|
||||
$courseUser->reviewed = 1;
|
||||
|
||||
$courseUser->update();
|
||||
}
|
||||
|
||||
protected function incrCourseReviewCount(CourseModel $course)
|
||||
{
|
||||
$course->review_count += 1;
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Services\Logic\Review;
|
||||
|
||||
use App\Models\Review as ReviewModel;
|
||||
use App\Repos\Course as CourseRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Logic\ReviewTrait;
|
||||
use App\Services\Logic\Service;
|
||||
@ -34,17 +35,40 @@ class ReviewInfo extends Service
|
||||
'update_time' => $review->update_time,
|
||||
];
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$owner = $userRepo->findById($review->owner_id);
|
||||
|
||||
$result['owner'] = [
|
||||
'id' => $owner->id,
|
||||
'name' => $owner->name,
|
||||
'avatar' => $owner->avatar,
|
||||
];
|
||||
$result['course'] = $this->handleCourseInfo($review);
|
||||
$result['owner'] = $this->handleOwnerInfo($review);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function handleCourseInfo(ReviewModel $review)
|
||||
{
|
||||
$courseRepo = new CourseRepo();
|
||||
|
||||
$course = $courseRepo->findById($review->course_id);
|
||||
|
||||
if (!$course) return new \stdClass();
|
||||
|
||||
return [
|
||||
'id' => $course->id,
|
||||
'title' => $course->title,
|
||||
'cover' => $course->cover,
|
||||
];
|
||||
}
|
||||
|
||||
protected function handleOwnerInfo(ReviewModel $review)
|
||||
{
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$owner = $userRepo->findById($review->owner_id);
|
||||
|
||||
if (!$owner) return new \stdClass();
|
||||
|
||||
return [
|
||||
'id' => $owner->id,
|
||||
'name' => $owner->name,
|
||||
'avatar' => $owner->avatar,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
57
app/Services/Logic/Teacher/CourseList.php
Normal file
57
app/Services/Logic/Teacher/CourseList.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic\Teacher;
|
||||
|
||||
use App\Builders\CourseUserList as CourseUserListBuilder;
|
||||
use App\Library\Paginator\Query as PagerQuery;
|
||||
use App\Models\CourseUser as CourseUserModel;
|
||||
use App\Repos\CourseUser as CourseUserRepo;
|
||||
use App\Services\Logic\Service;
|
||||
use App\Services\Logic\UserTrait;
|
||||
|
||||
class CourseList extends Service
|
||||
{
|
||||
|
||||
use UserTrait;
|
||||
|
||||
public function handle($id)
|
||||
{
|
||||
$user = $this->checkUser($id);
|
||||
|
||||
$pagerQuery = new PagerQuery();
|
||||
|
||||
$params = $pagerQuery->getParams();
|
||||
|
||||
$params['role_type'] = CourseUserModel::ROLE_TEACHER;
|
||||
$params['user_id'] = $user->id;
|
||||
$params['deleted'] = 0;
|
||||
|
||||
$sort = $pagerQuery->getSort();
|
||||
$page = $pagerQuery->getPage();
|
||||
$limit = $pagerQuery->getLimit();
|
||||
|
||||
$courseUserRepo = new CourseUserRepo();
|
||||
|
||||
$pager = $courseUserRepo->paginate($params, $sort, $page, $limit);
|
||||
|
||||
return $this->handleCourses($pager);
|
||||
}
|
||||
|
||||
protected function handleCourses($pager)
|
||||
{
|
||||
if ($pager->total_items == 0) {
|
||||
return $pager;
|
||||
}
|
||||
|
||||
$builder = new CourseUserListBuilder();
|
||||
|
||||
$relations = $pager->items->toArray();
|
||||
|
||||
$courses = $builder->getCourses($relations);
|
||||
|
||||
$pager->items = $courses;
|
||||
|
||||
return $pager;
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ use App\Services\Logic\User\UserInfo as UserInfoService;
|
||||
class TeacherInfo extends Service
|
||||
{
|
||||
|
||||
public function getUser($id)
|
||||
public function handle($id)
|
||||
{
|
||||
$service = new UserInfoService();
|
||||
|
||||
|
@ -63,6 +63,7 @@ class ConsultList extends Service
|
||||
'update_time' => $consult['update_time'],
|
||||
'course' => $course,
|
||||
'chapter' => $chapter,
|
||||
'show' => false,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ use App\Services\Logic\User\GroupList as UserGroupListService;
|
||||
class GroupList extends Service
|
||||
{
|
||||
|
||||
public function handle($scope)
|
||||
public function handle($scope = 'joined')
|
||||
{
|
||||
$result = [];
|
||||
|
||||
|
@ -54,6 +54,7 @@ class CourseList extends Service
|
||||
$course = $courses[$relation['course_id']] ?? new \stdClass();
|
||||
|
||||
$items[] = [
|
||||
'plan_id' => $relation['plan_id'],
|
||||
'progress' => $relation['progress'],
|
||||
'duration' => $relation['duration'],
|
||||
'reviewed' => $relation['reviewed'],
|
||||
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Logic\Verify;
|
||||
|
||||
use App\Library\Validators\Common as CommonValidator;
|
||||
use App\Services\Logic\Service;
|
||||
use App\Services\Mail\Verify as VerifyMailService;
|
||||
use App\Services\Sms\Verify as VerifySmsService;
|
||||
use App\Validators\Captcha as CaptchaValidator;
|
||||
|
||||
class VerifyCode extends Service
|
||||
{
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$post = $this->request->getPost();
|
||||
|
||||
$captchaValidator = new CaptchaValidator();
|
||||
|
||||
$captchaValidator->checkCode($post['ticket'], $post['rand']);
|
||||
|
||||
if (CommonValidator::phone($post['account'])) {
|
||||
|
||||
$service = new VerifySmsService();
|
||||
|
||||
$service->handle($post['account']);
|
||||
|
||||
} elseif (CommonValidator::email($post['account'])) {
|
||||
|
||||
$service = new VerifyMailService();
|
||||
|
||||
$service->handle($post['account']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,7 @@ abstract class Pay extends Service
|
||||
abstract public function scan(TradeModel $trade);
|
||||
|
||||
/**
|
||||
* mobile下单
|
||||
* wap下单
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
*/
|
||||
|
@ -57,7 +57,36 @@ class Alipay extends PayService
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动端支付
|
||||
* app支付
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function app(TradeModel $trade)
|
||||
{
|
||||
try {
|
||||
|
||||
$result = $this->gateway->app([
|
||||
'out_trade_no' => $trade->sn,
|
||||
'total_amount' => $trade->amount,
|
||||
'subject' => $trade->subject,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Log::error('Alipay app Exception', [
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* wap支付
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
* @return Response|bool
|
||||
@ -66,7 +95,7 @@ class Alipay extends PayService
|
||||
{
|
||||
try {
|
||||
|
||||
return $this->gateway->wap([
|
||||
$result = $this->gateway->wap([
|
||||
'out_trade_no' => $trade->sn,
|
||||
'total_amount' => $trade->amount,
|
||||
'subject' => $trade->subject,
|
||||
@ -85,6 +114,37 @@ class Alipay extends PayService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
* @param string $buyerId
|
||||
* @return Collection|bool
|
||||
*/
|
||||
public function mini(TradeModel $trade, $buyerId)
|
||||
{
|
||||
try {
|
||||
|
||||
$result = $this->gateway->mini([
|
||||
'out_trade_no' => $trade->sn,
|
||||
'total_amount' => $trade->amount,
|
||||
'subject' => $trade->subject,
|
||||
'buyer_id' => $buyerId,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Log::error('Alipay Mini Exception', [
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步通知
|
||||
*
|
||||
|
@ -58,7 +58,36 @@ class Wxpay extends PayService
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动端支付
|
||||
* app支付
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
* @return Response|bool
|
||||
*/
|
||||
public function app(TradeModel $trade)
|
||||
{
|
||||
try {
|
||||
|
||||
$result = $this->gateway->app([
|
||||
'out_trade_no' => $trade->sn,
|
||||
'total_fee' => 100 * $trade->amount,
|
||||
'body' => $trade->subject,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Log::error('Wxpay App Exception', [
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* wap支付
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
* @return Response|bool
|
||||
@ -67,7 +96,7 @@ class Wxpay extends PayService
|
||||
{
|
||||
try {
|
||||
|
||||
return $this->gateway->wap([
|
||||
$result = $this->gateway->wap([
|
||||
'out_trade_no' => $trade->sn,
|
||||
'total_fee' => 100 * $trade->amount,
|
||||
'body' => $trade->subject,
|
||||
@ -86,6 +115,37 @@ class Wxpay extends PayService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序支付
|
||||
*
|
||||
* @param TradeModel $trade
|
||||
* @param string $openId
|
||||
* @return Collection|bool
|
||||
*/
|
||||
public function mini(TradeModel $trade, $openId)
|
||||
{
|
||||
try {
|
||||
|
||||
$result = $this->gateway->miniapp([
|
||||
'out_trade_no' => $trade->sn,
|
||||
'total_fee' => 100 * $trade->amount,
|
||||
'body' => $trade->subject,
|
||||
'openid' => $openId,
|
||||
]);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Log::error('Wxpay Mini Exception', [
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步通知
|
||||
*
|
||||
|
@ -31,13 +31,27 @@ trait Client
|
||||
|
||||
$result = new BrowserParser($userAgent);
|
||||
|
||||
$clientType = ClientModel::TYPE_DESKTOP;
|
||||
$clientType = ClientModel::TYPE_PC;
|
||||
|
||||
if ($result->isMobile()) {
|
||||
$clientType = ClientModel::TYPE_MOBILE;
|
||||
$clientType = ClientModel::TYPE_H5;
|
||||
}
|
||||
|
||||
return $clientType;
|
||||
}
|
||||
|
||||
public function isMobileBrowser()
|
||||
{
|
||||
/**
|
||||
* @var Request $request
|
||||
*/
|
||||
$request = Di::getDefault()->get('request');
|
||||
|
||||
$userAgent = $request->getServer('HTTP_USER_AGENT');
|
||||
|
||||
$result = new BrowserParser($userAgent);
|
||||
|
||||
return $result->isMobile();
|
||||
}
|
||||
|
||||
}
|
@ -2,12 +2,57 @@
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Phalcon\Config;
|
||||
use Phalcon\Di;
|
||||
use Phalcon\Http\Request as HttpRequest;
|
||||
use Phalcon\Http\Response as HttpResponse;
|
||||
|
||||
trait Response
|
||||
{
|
||||
|
||||
public function setCors()
|
||||
{
|
||||
/**
|
||||
* @var Config $config
|
||||
*/
|
||||
$config = Di::getDefault()->getShared('config');
|
||||
|
||||
$cors = $config->get('cors')->toArray();
|
||||
|
||||
if (!$cors['enabled']) return;
|
||||
|
||||
if (is_array($cors['allow_headers'])) {
|
||||
$cors['allow_headers'] = implode(',', $cors['allow_headers']);
|
||||
}
|
||||
|
||||
if (is_array($cors['allow_methods'])) {
|
||||
$cors['allow_methods'] = implode(',', $cors['allow_methods']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var HttpRequest $request
|
||||
*/
|
||||
$request = Di::getDefault()->getShared('request');
|
||||
|
||||
$origin = $request->getHeader('Origin');
|
||||
|
||||
if (is_array($cors['allow_origin']) && in_array($origin, $cors['allow_origin'])) {
|
||||
$cors['allow_origin'] = $origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var HttpResponse $response
|
||||
*/
|
||||
$response = Di::getDefault()->getShared('response');
|
||||
|
||||
$response->setHeader('Access-Control-Allow-Origin', $cors['allow_origin']);
|
||||
|
||||
if ($request->isOptions()) {
|
||||
$response->setHeader('Access-Control-Allow-Headers', $cors['allow_headers']);
|
||||
$response->setHeader('Access-Control-Allow-Methods', $cors['allow_methods']);
|
||||
}
|
||||
}
|
||||
|
||||
public function jsonSuccess($content = [])
|
||||
{
|
||||
$content['code'] = 0;
|
||||
@ -17,7 +62,7 @@ trait Response
|
||||
/**
|
||||
* @var HttpResponse $response
|
||||
*/
|
||||
$response = Di::getDefault()->get('response');
|
||||
$response = Di::getDefault()->getShared('response');
|
||||
|
||||
$response->setStatusCode(200);
|
||||
|
||||
@ -35,7 +80,7 @@ trait Response
|
||||
/**
|
||||
* @var HttpResponse $response
|
||||
*/
|
||||
$response = Di::getDefault()->get('response');
|
||||
$response = Di::getDefault()->getShared('response');
|
||||
|
||||
$response->setJsonContent($content);
|
||||
|
||||
|
@ -30,12 +30,19 @@ trait Security
|
||||
$validator->checkRateLimit();
|
||||
}
|
||||
|
||||
public function checkApiSignature()
|
||||
{
|
||||
$validator = new SecurityValidator();
|
||||
|
||||
$validator->checkApiSignature();
|
||||
}
|
||||
|
||||
public function isNotSafeRequest()
|
||||
{
|
||||
/**
|
||||
* @var Request $request
|
||||
*/
|
||||
$request = Di::getDefault()->get('request');
|
||||
$request = Di::getDefault()->getShared('request');
|
||||
|
||||
$method = $request->getMethod();
|
||||
|
||||
|
133
app/Validators/ApiSecurity.php
Normal file
133
app/Validators/ApiSecurity.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validators;
|
||||
|
||||
use App\Caches\App as AppCache;
|
||||
use App\Exceptions\BadRequest as BadRequestException;
|
||||
use App\Models\App as AppModel;
|
||||
|
||||
class ApiSecurity extends Validator
|
||||
{
|
||||
|
||||
public function check()
|
||||
{
|
||||
$query = $this->request->getQuery();
|
||||
|
||||
if (isset($query['_url'])) {
|
||||
unset($query['_url']);
|
||||
}
|
||||
|
||||
$extra = [
|
||||
'_timestamp' => $this->checkTimestamp(),
|
||||
'_nonce' => $this->checkNonce(),
|
||||
];
|
||||
|
||||
$appKey = $this->checkAppKey();
|
||||
|
||||
$app = $this->getApp($appKey);
|
||||
|
||||
if (!$app || $app->published == 0) {
|
||||
throw new BadRequestException('api.invalid_app_key');
|
||||
}
|
||||
|
||||
$url = $this->getRequestUrl();
|
||||
|
||||
if ($this->request->getMethod() == 'POST') {
|
||||
$mySignature = $this->httpPostSignature($url, $extra, $app->secret);
|
||||
} else {
|
||||
$params = array_merge($query, $extra);
|
||||
$mySignature = $this->httpGetSignature($url, $params, $app->secret);
|
||||
}
|
||||
|
||||
$signature = $this->request->getHeader('X-Signature');
|
||||
|
||||
if ($signature != $mySignature) {
|
||||
throw new BadRequestException('api.invalid_signature');
|
||||
}
|
||||
|
||||
return $signature;
|
||||
}
|
||||
|
||||
protected function checkTimestamp()
|
||||
{
|
||||
$timestamp = $this->request->getHeader('X-Timestamp');
|
||||
|
||||
$timestamp = $timestamp > 0 ? $timestamp : 0;
|
||||
|
||||
if (abs(time() - $timestamp) > 300) {
|
||||
throw new BadRequestException('api.invalid_timestamp');
|
||||
}
|
||||
|
||||
return $timestamp;
|
||||
}
|
||||
|
||||
protected function checkNonce()
|
||||
{
|
||||
$nonce = $this->request->getHeader('X-Nonce');
|
||||
|
||||
if (!$nonce) {
|
||||
throw new BadRequestException('api.invalid_nonce');
|
||||
}
|
||||
|
||||
return $nonce;
|
||||
}
|
||||
|
||||
protected function checkAppKey()
|
||||
{
|
||||
$appKey = $this->request->getHeader('X-App-Key');
|
||||
|
||||
if (!$appKey) {
|
||||
throw new BadRequestException('api.invalid_app_key');
|
||||
}
|
||||
|
||||
return $appKey;
|
||||
}
|
||||
|
||||
protected function checkPlatform()
|
||||
{
|
||||
$platform = $this->request->getHeader('X-Platform');
|
||||
|
||||
if (!array_key_exists($platform, AppModel::types())) {
|
||||
throw new BadRequestException('api.invalid_platform');
|
||||
}
|
||||
|
||||
return $platform;
|
||||
}
|
||||
|
||||
protected function getRequestUrl()
|
||||
{
|
||||
return sprintf('%s://%s%s',
|
||||
$this->request->getScheme(),
|
||||
$this->request->getHttpHost(),
|
||||
$this->request->getURI()
|
||||
);
|
||||
}
|
||||
|
||||
protected function getApp($appKey)
|
||||
{
|
||||
$cache = new AppCache();
|
||||
|
||||
return $cache->get($appKey);
|
||||
}
|
||||
|
||||
protected function httpGetSignature($url, $params, $appSecret)
|
||||
{
|
||||
ksort($params);
|
||||
|
||||
$query = http_build_query($params);
|
||||
|
||||
return md5($url . $query . $appSecret);
|
||||
}
|
||||
|
||||
protected function httpPostSignature($url, $params, $appSecret)
|
||||
{
|
||||
ksort($params);
|
||||
|
||||
$query = http_build_query($params);
|
||||
|
||||
$body = $this->request->getRawBody();
|
||||
|
||||
return md5($url . $query . $body . $appSecret);
|
||||
}
|
||||
|
||||
}
|
73
app/Validators/App.php
Normal file
73
app/Validators/App.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validators;
|
||||
|
||||
use App\Exceptions\BadRequest as BadRequestException;
|
||||
use App\Models\App as AppModel;
|
||||
use App\Repos\App as AppRepo;
|
||||
|
||||
class App extends Validator
|
||||
{
|
||||
|
||||
public function checkApp($id)
|
||||
{
|
||||
$appRepo = new AppRepo();
|
||||
|
||||
$app = $appRepo->findById($id);
|
||||
|
||||
if (!$app) {
|
||||
throw new BadRequestException('app.not_found');
|
||||
}
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
public function checkName($name)
|
||||
{
|
||||
$value = $this->filter->sanitize($name, ['trim', 'string']);
|
||||
|
||||
$length = kg_strlen($value);
|
||||
|
||||
if ($length < 2) {
|
||||
throw new BadRequestException('app.name_too_short');
|
||||
}
|
||||
|
||||
if ($length > 50) {
|
||||
throw new BadRequestException('app.name_too_long');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function checkType($type)
|
||||
{
|
||||
if (!array_key_exists($type, AppModel::types())) {
|
||||
throw new BadRequestException('app.invalid_type');
|
||||
}
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
public function checkRemark($remark)
|
||||
{
|
||||
$value = $this->filter->sanitize($remark, ['trim', 'striptags']);
|
||||
|
||||
$length = kg_strlen($value);
|
||||
|
||||
if ($length > 255) {
|
||||
throw new BadRequestException('app.remark_too_long');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function checkPublishStatus($status)
|
||||
{
|
||||
if (!in_array($status, [0, 1])) {
|
||||
throw new BadRequestException('app.invalid_publish_status');
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
}
|
46
app/Validators/Client.php
Normal file
46
app/Validators/Client.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Validators;
|
||||
|
||||
use App\Exceptions\BadRequest as BadRequestException;
|
||||
use App\Models\Client as ClientModel;
|
||||
|
||||
class Client extends Validator
|
||||
{
|
||||
|
||||
public function checkH5Platform($platform)
|
||||
{
|
||||
$platform = strtoupper($platform);
|
||||
|
||||
if ($platform == 'H5') {
|
||||
return ClientModel::TYPE_H5;
|
||||
}
|
||||
|
||||
throw new BadRequestException('client.invalid_type');
|
||||
}
|
||||
|
||||
public function checkMpPlatform($platform)
|
||||
{
|
||||
$platform = strtoupper($platform);
|
||||
|
||||
if ($platform == 'MP-WEIXIN') {
|
||||
return ClientModel::TYPE_MP_WEIXIN;
|
||||
} elseif ($platform == 'MP-ALIPAY') {
|
||||
return ClientModel::TYPE_MP_ALIPAY;
|
||||
} else {
|
||||
throw new BadRequestException('client.invalid_type');
|
||||
}
|
||||
}
|
||||
|
||||
public function checkAppPlatform($platform)
|
||||
{
|
||||
$platform = strtoupper($platform);
|
||||
|
||||
if ($platform == 'APP-PLUS') {
|
||||
return ClientModel::TYPE_APP;
|
||||
}
|
||||
|
||||
throw new BadRequestException('client.invalid_type');
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ namespace App\Validators;
|
||||
|
||||
use App\Exceptions\BadRequest as BadRequestException;
|
||||
use App\Exceptions\ServiceUnavailable as ServiceUnavailableException;
|
||||
use App\Library\CsrfToken as CsrfTokenService;
|
||||
use App\Services\Throttle as ThrottleService;
|
||||
|
||||
class Security extends Validator
|
||||
@ -13,7 +14,9 @@ class Security extends Validator
|
||||
{
|
||||
$token = $this->request->getHeader('X-Csrf-Token');
|
||||
|
||||
$result = $this->csrfToken->checkToken($token);
|
||||
$service = new CsrfTokenService();
|
||||
|
||||
$result = $service->checkToken($token);
|
||||
|
||||
if (!$result) {
|
||||
throw new BadRequestException('security.invalid_csrf_token');
|
||||
@ -42,4 +45,15 @@ class Security extends Validator
|
||||
}
|
||||
}
|
||||
|
||||
public function checkApiSignature()
|
||||
{
|
||||
$validator = new ApiSecurity();
|
||||
|
||||
$result = $validator->check();
|
||||
|
||||
if (!$result) {
|
||||
throw new BadRequestException('security.invalid_api_signature');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -147,6 +147,16 @@ $config['jwt']['lifetime'] = 7 * 86400;
|
||||
*/
|
||||
$config['jwt']['leeway'] = 30;
|
||||
|
||||
/**
|
||||
* 允许跨域
|
||||
*/
|
||||
$config['cors']['enabled'] = true;
|
||||
|
||||
/**
|
||||
* 允许跨域域名(字符|数组)
|
||||
*/
|
||||
$config['cors']['allow_origin'] = '*';
|
||||
|
||||
/**
|
||||
* 限流开启
|
||||
*/
|
||||
|
10
public/h5/index.html
Normal file
10
public/h5/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>H5 Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to H5</h1>
|
||||
</body>
|
||||
</html>
|
@ -28,7 +28,7 @@ layui.use(['jquery', 'layer'], function () {
|
||||
var interval = setInterval(function () {
|
||||
var queryData = {sn: res.sn};
|
||||
$.get(statusUrl, queryData, function (res) {
|
||||
if ($.inArray(res.status, [2, 3]) > -1) {
|
||||
if (res.status === 2) {
|
||||
clearInterval(interval);
|
||||
$('#pay-layer').html('<div class="success-tips">支付成功</div>');
|
||||
setTimeout(function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user