1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-07-03 15:36:48 +08:00

整理代码

This commit is contained in:
xiaochong0302 2020-05-16 19:49:58 +08:00
parent 1edf6310c0
commit 7052e7c0d5
84 changed files with 360 additions and 273 deletions

View File

@ -13,7 +13,7 @@ use App\Repos\Learning as LearningRepo;
use App\Services\Syncer\Learning as LearningSyncer;
use Phalcon\Cli\Task;
class LearningTask extends Task
class SyncLearningTask extends Task
{
/**
@ -69,7 +69,8 @@ class LearningTask extends Task
if (!$dbLearning) {
$cacheLearning->create();
} else {
$dbLearning->duration += $cacheLearning->duration;
$dbLearning->duration = $cacheLearning->duration;
$dbLearning->position = $cacheLearning->position;
$dbLearning->update();
}
@ -138,6 +139,12 @@ class LearningTask extends Task
*/
protected function updateCourseUser($courseId, $userId)
{
$courseUserRepo = new CourseUserRepo();
$courseUser = $courseUserRepo->findCourseUser($courseId, $userId);
if (!$courseUser) return;
$courseRepo = new CourseRepo();
$courseLessons = $courseRepo->findLessons($courseId);
@ -166,15 +173,9 @@ class LearningTask extends Task
$consumedCount = count($consumedLessonIds);
$progress = intval(100 * $consumedCount / $totalCount);
$courseUserRepo = new CourseUserRepo();
$courseUser = $courseUserRepo->findCourseUser($courseId, $userId);
if ($courseUser) {
$courseUser->progress = $progress;
$courseUser->duration = $duration;
$courseUser->update();
}
$courseUser->progress = $progress;
$courseUser->duration = $duration;
$courseUser->update();
}
}

View File

@ -64,7 +64,7 @@ class TestController extends Controller
}
/**
* @Get("/live/push", name="admin.test.live.push")
* @Get("/live/push", name="admin.test.live_push")
*/
public function livePushAction()
{
@ -89,7 +89,7 @@ class TestController extends Controller
}
/**
* @Get("/live/pull", name="admin.test.live.pull")
* @Get("/live/pull", name="admin.test.live_pull")
*/
public function livePullAction()
{
@ -190,7 +190,7 @@ class TestController extends Controller
}
/**
* @Post("/alipay/status", name="admin.test.alipay.status")
* @Post("/alipay/status", name="admin.test.alipay_status")
*/
public function alipayStatusAction()
{
@ -204,7 +204,7 @@ class TestController extends Controller
}
/**
* @Post("/alipay/cancel", name="admin.test.alipay.cancel")
* @Post("/alipay/cancel", name="admin.test.alipay_cancel")
*/
public function alipayCancelAction()
{
@ -242,7 +242,7 @@ class TestController extends Controller
}
/**
* @Post("/wxpay/status", name="admin.test.wxpay.status")
* @Post("/wxpay/status", name="admin.test.wxpay_status")
*/
public function wxpayStatusAction()
{
@ -256,7 +256,7 @@ class TestController extends Controller
}
/**
* @Post("/wxpay/cancel", name="admin.test.wxpay.cancel")
* @Post("/wxpay/cancel", name="admin.test.wxpay_cancel")
*/
public function wxpayCancelAction()
{

View File

@ -2,8 +2,6 @@
namespace App\Http\Admin\Controllers;
use App\Models\Learning as LearningModel;
use App\Services\LearningSyncer as LearningSyncerService;
use App\Services\Vod as VodService;
use Phalcon\Mvc\View;
@ -14,7 +12,7 @@ class VodController extends Controller
{
/**
* @Post("/upload/signature", name="admin.vod.upload.signature")
* @Post("/upload/signature", name="admin.vod.upload_signature")
*/
public function uploadSignatureAction()
{
@ -39,25 +37,4 @@ class VodController extends Controller
$this->view->setVar('play_url', urldecode($playUrl));
}
/**
* @Get("/learning", name="admin.vod.learning")
*/
public function learningAction()
{
$query = $this->request->getQuery();
$learning = new LearningModel();
$learning->user_id = $this->authUser->id;
$learning->request_id = $query['request_id'];
$learning->chapter_id = $query['chapter_id'];
$learning->position = $query['position'];
$syncerService = new LearningSyncerService();
$syncerService->addItem($learning, $query['timeout']);
return $this->jsonSuccess();
}
}

View File

@ -22,8 +22,8 @@
<script>
var interval = null;
var timeout = 5000;
var requestId = uniqueId();
var intervalTime = 5000;
var requestId = getRequestId();
var chapterId = '{{ chapter_id }}';
var playUrl = '{{ play_url }}';
var position = 0;
@ -53,7 +53,7 @@
clearInterval(interval);
interval = null;
}
interval = setInterval(learning, timeout);
interval = setInterval(learning, intervalTime);
}
function stop() {
@ -68,13 +68,13 @@
data: {
request_id: requestId,
chapter_id: chapterId,
timeout: timeout,
interval: intervalTime,
position: player.currentTime(),
}
});
}
function uniqueId() {
function getRequestId() {
var id = Date.now().toString(36);
id += Math.random().toString(36).substr(3);
return id;

View File

@ -1,11 +1,3 @@
{%- macro client_type(value) %}
{% if value == 'desktop' %}
<span class="layui-badge layui-bg-green">桌面端</span>
{% elseif value == 'mobile' %}
<span class="layui-badge layui-bg-blue">手机端</span>
{% endif %}
{%- endmacro %}
{%- macro last_active_time(create_time, update_time) %}
{% if update_time > 0 %}
{{ date('Y-m-d H:i', update_time) }}
@ -39,7 +31,7 @@
<p>章节:{{ item.chapter.title }}</p>
</td>
<td>{{ item.duration|play_duration }}</td>
<td>{{ client_type(item.client_type) }}</td>
<td>{{ item.client_type }}</td>
<td><a href="javascript:" class="kg-ip2region" title="查看位置" data-ip="{{ item.client_ip }}">{{ item.client_ip }}</a></td>
<td>{{ last_active_time(item.create_time,item.update_time) }}</td>
</tr>

View File

@ -55,7 +55,7 @@
{% for item in pager.items %}
<tr>
<td>
<p>课程:<a href="{{ url({'for':'admin.student.list'},{'course_id':item.course.id}) }}">{{ item.course.title }}</a></p>
<p>课程:<a href="{{ url({'for':'admin.student.list'},{'course_id':item.course.id}) }}">{{ item.course.title }}{{ item.course.id }}</a></p>
<p>学员:<a href="{{ url({'for':'admin.student.list'},{'user_id':item.user_id}) }}">{{ item.user.name }}{{ item.user.id }}</a></p>
</td>
<td>

View File

@ -43,117 +43,92 @@ class AccountController extends Controller
}
/**
* @Get("/password/reset", name="web.account.reset_password")
* @Get("/password/reset", name="web.account.reset_pwd")
*/
public function resetPasswordAction()
{
if ($this->request->isPost()) {
$service = new PasswordResetService();
$service->handle();
return $this->jsonSuccess(['msg' => '重置密码成功']);
}
}
/**
* @Post("/register_by_phone", name="web.account.register_by_phone")
* @Post("/phone/register", name="web.account.register_by_phone")
*/
public function registerByPhoneAction()
{
if ($this->request->isPost()) {
$service = new AccountService();
$service = new AccountService();
$service->registerByPhone();
$service->registerByPhone();
$content = [
'location' => $this->request->getHTTPReferer(),
'msg' => '注册账户成功',
];
$content = [
'location' => $this->request->getHTTPReferer(),
'msg' => '注册账户成功',
];
return $this->jsonSuccess($content);
}
return $this->jsonSuccess($content);
}
/**
* @Post("/register_by_email", name="web.account.register_by_email")
* @Post("/email/register", name="web.account.register_by_email")
*/
public function registerByEmailAction()
{
if ($this->request->isPost()) {
$service = new AccountService();
$service = new AccountService();
$service->registerByPhone();
$service->registerByPhone();
$content = [
'msg' => '注册账户成功',
];
$content = [
'msg' => '注册账户成功',
];
return $this->jsonSuccess($content);
}
return $this->jsonSuccess($content);
}
/**
* @Post("/login_by_pwd", name="web.account.login_by_pwd")
* @Post("/password/login", name="web.account.login_by_pwd")
*/
public function loginByPasswordAction()
{
if ($this->request->isPost()) {
$service = new AccountService();
$service = new AccountService();
$service->loginByPassword();
$service->loginByPassword();
return $this->jsonSuccess();
}
return $this->jsonSuccess();
}
/**
* @Post("/login_by_verify", name="web.account.login_by_verify")
* @Post("/verify/login", name="web.account.login_by_verify")
*/
public function loginByVerifyAction()
{
if ($this->request->isPost()) {
$service = new AccountService();
$service = new AccountService();
$service->loginByVerify();
$service->loginByVerify();
return $this->jsonSuccess();
}
return $this->jsonSuccess();
}
/**
* @Post("/password/reset_by_email", name="web.account.reset_pwd_by_email")
* @Post("/password/email/reset", name="web.account.reset_pwd_by_email")
*/
public function resetPasswordByEmailAction()
{
if ($this->request->isPost()) {
$service = new PasswordResetService();
$service = new PasswordResetService();
$service->handle();
$service->handle();
return $this->jsonSuccess(['msg' => '重置密码成功']);
}
return $this->jsonSuccess(['msg' => '重置密码成功']);
}
/**
* @Post("/password/reset_by_phone", name="web.account.reset_pwd_by_phone")
* @Post("/password/phone/reset", name="web.account.reset_pwd_by_phone")
*/
public function resetPasswordByPhoneAction()
{
if ($this->request->isPost()) {
$service = new PasswordResetService();
$service = new PasswordResetService();
$service->handle();
$service->handle();
return $this->jsonSuccess(['msg' => '重置密码成功']);
}
return $this->jsonSuccess(['msg' => '重置密码成功']);
}
/**

View File

@ -5,6 +5,7 @@ namespace App\Http\Web\Controllers;
use App\Services\Frontend\Chapter\AgreeVote as ChapterAgreeVoteService;
use App\Services\Frontend\Chapter\ChapterInfo as ChapterInfoService;
use App\Services\Frontend\Chapter\CommentList as ChapterCommentListService;
use App\Services\Frontend\Chapter\Learning as ChapterLearningService;
use App\Services\Frontend\Chapter\OpposeVote as ChapterOpposeVoteService;
/**
@ -61,4 +62,16 @@ class ChapterController extends Controller
return $this->jsonSuccess();
}
/**
* @Post("/{id:[0-9]+}/learning", name="web.chapter.learning")
*/
public function learningAction($id)
{
$service = new ChapterLearningService();
$service->handle($id);
return $this->jsonSuccess();
}
}

View File

@ -10,6 +10,8 @@ class Learning extends Model
*/
const CLIENT_DESKTOP = 'desktop';
const CLIENT_MOBILE = 'mobile';
const CLIENT_APP = 'app';
const CLIENT_MINI = 'mini';
/**
* 主键编号

View File

@ -17,11 +17,12 @@ class Order extends Model
const ITEM_TEST = 'test'; // 测试
/**
* 来源类型
* 终端类型
*/
const SOURCE_WEB = 'web';
const SOURCE_WAP = 'wap';
const SOURCE_APP = 'app';
const CLIENT_DESKTOP = 'desktop';
const CLIENT_MOBILE = 'mobile';
const CLIENT_APP = 'app';
const CLIENT_MINI = 'mini';
/**
* 状态类型
@ -95,11 +96,18 @@ class Order extends Model
public $coupon_info;
/**
* 来源类型
* 终端类型
*
* @var string
*/
public $source_type;
public $client_type;
/**
* 终端IP
*
* @var string
*/
public $client_ip;
/**
* 状态类型
@ -200,12 +208,13 @@ class Order extends Model
];
}
public static function sourceTypes()
public static function clientTypes()
{
return [
self::SOURCE_WEB => 'web',
self::SOURCE_WAP => 'wap',
self::SOURCE_APP => 'app',
self::CLIENT_DESKTOP => 'desktop',
self::CLIENT_MOBILE => 'mobile',
self::CLIENT_APP => 'app',
self::CLIENT_MINI => 'mini',
];
}

View File

@ -3,11 +3,11 @@
namespace App\Services\Frontend\Account;
use App\Repos\Account as AccountRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class EmailUpdate extends Service
class EmailUpdate extends FrontendService
{
public function handle()

View File

@ -2,11 +2,11 @@
namespace App\Services\Frontend\Account;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class PasswordReset extends Service
class PasswordReset extends FrontendService
{
public function handle()

View File

@ -2,11 +2,11 @@
namespace App\Services\Frontend\Account;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class PasswordResetByEmail extends Service
class PasswordResetByEmail extends FrontendService
{
public function handle()

View File

@ -2,11 +2,11 @@
namespace App\Services\Frontend\Account;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class PasswordResetByPhone extends Service
class PasswordResetByPhone extends FrontendService
{
public function handle()

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Account;
use App\Repos\Account as AccountRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
class PasswordUpdate extends Service
class PasswordUpdate extends FrontendService
{
public function handle()

View File

@ -3,11 +3,11 @@
namespace App\Services\Frontend\Account;
use App\Repos\Account as AccountRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class PhoneUpdate extends Service
class PhoneUpdate extends FrontendService
{
public function handle()

View File

@ -4,11 +4,11 @@ namespace App\Services\Frontend\Account;
use App\Models\Account as AccountModel;
use App\Repos\User as UserRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class RegisterByEmail extends Service
class RegisterByEmail extends FrontendService
{
public function handle()

View File

@ -4,11 +4,11 @@ namespace App\Services\Frontend\Account;
use App\Models\Account as AccountModel;
use App\Repos\User as UserRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Account as AccountValidator;
use App\Validators\Verify as VerifyValidator;
class RegisterByPhone extends Service
class RegisterByPhone extends FrontendService
{
public function handle()

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Chapter;
use App\Models\ChapterVote as ChapterVoteModel;
use App\Repos\ChapterVote as ChapterVoteRepo;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class AgreeVote extends Service
class AgreeVote extends FrontendService
{
use ChapterTrait, VoteTrait;

View File

@ -13,11 +13,11 @@ use App\Repos\ChapterVote as ChapterVoteRepo;
use App\Services\ChapterVod as ChapterVodService;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Live as LiveService;
use WhichBrowser\Parser as BrowserParser;
class ChapterInfo extends Service
class ChapterInfo extends FrontendService
{
/**

View File

@ -10,9 +10,9 @@ use App\Models\User as UserModel;
use App\Repos\Chapter as ChapterRepo;
use App\Repos\Comment as CommentRepo;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class CommentList extends Service
class CommentList extends FrontendService
{
/**

View File

@ -0,0 +1,54 @@
<?php
namespace App\Services\Frontend\Chapter;
use App\Models\Course as CourseModel;
use App\Models\Learning as LearningModel;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Syncer\Learning as LearningSyncerService;
use App\Validators\Learning as LearningValidator;
class Learning extends FrontendService
{
use ChapterTrait;
public function handle($id)
{
$chapter = $this->checkChapterCache($id);
$user = $this->getCurrentUser();
$post = $this->request->getPost();
if ($user->id == 0) return;
$validator = new LearningValidator();
$data = [
'chapter_id' => $chapter->id,
'user_id' => $user->id,
];
$data['request_id'] = $validator->checkRequestId($post['request_id']);
/**
* @var array $attrs
*/
$attrs = $chapter->attrs;
if ($attrs['model'] == CourseModel::MODEL_VOD) {
$data['position'] = $validator->checkPosition($post['position']);
}
$interval = $validator->checkInterval($post['interval']);
$learning = new LearningModel($data);
$syncer = new LearningSyncerService();
$syncer->addItem($learning, $interval);
}
}

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Chapter;
use App\Models\ChapterVote as ChapterVoteModel;
use App\Repos\ChapterVote as ChapterVoteRepo;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class OpposeVote extends Service
class OpposeVote extends FrontendService
{
use ChapterTrait, VoteTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Comment;
use App\Models\CommentVote as CommentVoteModel;
use App\Repos\CommentVote as CommentVoteRepo;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class AgreeVote extends Service
class AgreeVote extends FrontendService
{
use CommentTrait, VoteTrait;

View File

@ -8,11 +8,11 @@ use App\Models\Course as CourseModel;
use App\Models\User as UserModel;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Comment as CommentValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class CommentCreate extends Service
class CommentCreate extends FrontendService
{
use ChapterTrait, CourseTrait;

View File

@ -7,10 +7,10 @@ use App\Models\Course as CourseModel;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Comment as CommentValidator;
class CommentDelete extends Service
class CommentDelete extends FrontendService
{
use CommentTrait, ChapterTrait, CourseTrait;

View File

@ -8,9 +8,9 @@ use App\Models\User as UserModel;
use App\Repos\CommentVote as CommentVoteRepo;
use App\Repos\User as UserRepo;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class CommentInfo extends Service
class CommentInfo extends FrontendService
{
use CommentTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Comment;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Comment as CommentValidator;
class CommentUpdate extends Service
class CommentUpdate extends FrontendService
{
use CommentTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Comment;
use App\Models\CommentVote as CommentVoteModel;
use App\Repos\CommentVote as CommentVoteRepo;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class OpposeVote extends Service
class OpposeVote extends FrontendService
{
use CommentTrait, VoteTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Consult;
use App\Models\ConsultVote as ConsultVoteModel;
use App\Repos\ConsultVote as ConsultVoteRepo;
use App\Services\Frontend\ConsultTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class AgreeVote extends Service
class AgreeVote extends FrontendService
{
use ConsultTrait, VoteTrait;

View File

@ -6,11 +6,11 @@ use App\Models\Consult as ConsultModel;
use App\Models\Course as CourseModel;
use App\Models\User as UserModel;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Consult as ConsultValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class ConsultCreate extends Service
class ConsultCreate extends FrontendService
{
use CourseTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Consult;
use App\Models\Course as CourseModel;
use App\Services\Frontend\ConsultTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Consult as ConsultValidator;
class ConsultDelete extends Service
class ConsultDelete extends FrontendService
{
use CourseTrait, ConsultTrait;

View File

@ -8,9 +8,9 @@ use App\Models\User as UserModel;
use App\Repos\ConsultVote as ConsultVoteRepo;
use App\Repos\User as UserRepo;
use App\Services\Frontend\ConsultTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class ConsultInfo extends Service
class ConsultInfo extends FrontendService
{
use ConsultTrait;

View File

@ -4,10 +4,10 @@ namespace App\Services\Frontend\Consult;
use App\Services\Frontend\ConsultTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Consult as ConsultValidator;
class ConsultUpdate extends Service
class ConsultUpdate extends FrontendService
{
use CourseTrait, ConsultTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Consult;
use App\Models\ConsultVote as ConsultVoteModel;
use App\Repos\ConsultVote as ConsultVoteRepo;
use App\Services\Frontend\ConsultTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class OpposeVote extends Service
class OpposeVote extends FrontendService
{
use ConsultTrait, VoteTrait;

View File

@ -7,9 +7,9 @@ use App\Models\Course as CourseModel;
use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class ChapterList extends Service
class ChapterList extends FrontendService
{
use CourseTrait;

View File

@ -10,9 +10,9 @@ use App\Models\User as UserModel;
use App\Repos\Consult as ConsultRepo;
use App\Repos\Course as CourseRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class ConsultList extends Service
class ConsultList extends FrontendService
{
/**

View File

@ -7,9 +7,9 @@ use App\Models\User as UserModel;
use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Category as CategoryService;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class CourseInfo extends Service
class CourseInfo extends FrontendService
{
use CourseTrait;

View File

@ -5,9 +5,9 @@ namespace App\Services\Frontend\Course;
use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Course as CourseRepo;
use App\Services\Category as CategoryService;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class CourseList extends Service
class CourseList extends FrontendService
{
public function handle()

View File

@ -7,10 +7,10 @@ use App\Models\CourseFavorite as CourseFavoriteModel;
use App\Models\User as UserModel;
use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class Favorite extends Service
class Favorite extends FrontendService
{
use CourseTrait;

View File

@ -5,9 +5,9 @@ namespace App\Services\Frontend\Course;
use App\Caches\CoursePackageList as CoursePackageListCache;
use App\Caches\PackageCourseList as PackageCourseListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class PackageList extends Service
class PackageList extends FrontendService
{
use CourseTrait;

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Course;
use App\Caches\CourseRecommendedList as CourseRecommendedListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class RecommendedList extends Service
class RecommendedList extends FrontendService
{
use CourseTrait;

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Course;
use App\Caches\CourseRelatedList as CourseRelatedListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class RelatedList extends Service
class RelatedList extends FrontendService
{
use CourseTrait;

View File

@ -10,9 +10,9 @@ use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo;
use App\Repos\Review as ReviewRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class ReviewList extends Service
class ReviewList extends FrontendService
{
/**

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Course;
use App\Caches\CourseTeacherList as CourseTeacherListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class TeacherList extends Service
class TeacherList extends FrontendService
{
use CourseTrait;

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Course;
use App\Caches\CourseTopicList as CourseTopicListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class TopicList extends Service
class TopicList extends FrontendService
{
use CourseTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\My;
use App\Builders\ConsultList as ConsultListBuilder;
use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Consult as ConsultRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class ConsultList extends Service
class ConsultList extends FrontendService
{
use UserTrait;

View File

@ -6,10 +6,10 @@ 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\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class CourseList extends Service
class CourseList extends FrontendService
{
use UserTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\My;
use App\Builders\CourseFavoriteList as CourseFavoriteListBuilder;
use App\Library\Paginator\Query as PagerQuery;
use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class FavoriteList extends Service
class FavoriteList extends FrontendService
{
use UserTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\My;
use App\Builders\OrderList as OrderListBuilder;
use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Order as OrderRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class OrderList extends Service
class OrderList extends FrontendService
{
use UserTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\My;
use App\Builders\RefundList as RefundListBuilder;
use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Refund as RefundRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class RefundList extends Service
class RefundList extends FrontendService
{
use UserTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\My;
use App\Builders\ReviewList as ReviewListBuilder;
use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Review as ReviewRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class ReviewList extends Service
class ReviewList extends FrontendService
{
use UserTrait;

View File

@ -3,9 +3,9 @@
namespace App\Services\Frontend\My;
use App\Models\User as UserModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class UserInfo extends Service
class UserInfo extends FrontendService
{
public function handle()

View File

@ -4,10 +4,10 @@ namespace App\Services\Frontend\Order;
use App\Models\Order as OrderModel;
use App\Services\Frontend\OrderTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Order as OrderValidator;
class OrderCancel extends Service
class OrderCancel extends FrontendService
{
use OrderTrait;

View File

@ -8,10 +8,10 @@ use App\Models\Package as PackageModel;
use App\Models\Reward as RewardModel;
use App\Models\Vip as VipModel;
use App\Repos\Package as PackageRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Order as OrderValidator;
class OrderConfirm extends Service
class OrderConfirm extends FrontendService
{
public function handle($itemId, $itemType)

View File

@ -10,11 +10,11 @@ use App\Models\User as UserModel;
use App\Models\Vip as VipModel;
use App\Repos\Order as OrderRepo;
use App\Repos\Package as PackageRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Order as OrderValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class OrderCreate extends Service
class OrderCreate extends FrontendService
{
public function handle()

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Order;
use App\Models\Order as OrderModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Order as OrderValidator;
class OrderInfo extends Service
class OrderInfo extends FrontendService
{
public function handle($sn)

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Package;
use App\Caches\PackageCourseList as PackageCourseListCache;
use App\Services\Frontend\PackageTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class CourseList extends Service
class CourseList extends FrontendService
{
use PackageTrait;

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Package;
use App\Models\Package as PackageModel;
use App\Services\Frontend\PackageTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class PackageInfo extends Service
class PackageInfo extends FrontendService
{
use PackageTrait;

View File

@ -4,10 +4,10 @@ namespace App\Services\Frontend\Refund;
use App\Models\Refund as RefundModel;
use App\Services\Frontend\RefundTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Refund as RefundValidator;
class RefundCancel extends Service
class RefundCancel extends FrontendService
{
use RefundTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Refund;
use App\Services\Frontend\OrderTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Refund;
class RefundConfirm extends Service
class RefundConfirm extends FrontendService
{
use OrderTrait;

View File

@ -4,12 +4,12 @@ namespace App\Services\Frontend\Refund;
use App\Models\Refund as RefundModel;
use App\Services\Frontend\OrderTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Refund as RefundService;
use App\Validators\Order as OrderValidator;
use App\Validators\Refund as RefundValidator;
class RefundCreate extends Service
class RefundCreate extends FrontendService
{
use OrderTrait;

View File

@ -4,9 +4,9 @@ namespace App\Services\Frontend\Refund;
use App\Models\Refund as RefundModel;
use App\Services\Frontend\RefundTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class RefundInfo extends Service
class RefundInfo extends FrontendService
{
use RefundTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Review;
use App\Models\ReviewVote as ReviewVoteModel;
use App\Repos\ReviewVote as ReviewVoteRepo;
use App\Services\Frontend\ReviewTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class AgreeVote extends Service
class AgreeVote extends FrontendService
{
use ReviewTrait, VoteTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Review;
use App\Models\ReviewVote as ReviewVoteModel;
use App\Repos\ReviewVote as ReviewVoteRepo;
use App\Services\Frontend\ReviewTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class OpposeVote extends Service
class OpposeVote extends FrontendService
{
use ReviewTrait, VoteTrait;

View File

@ -6,11 +6,11 @@ use App\Models\Course as CourseModel;
use App\Models\Review as ReviewModel;
use App\Models\User as UserModel;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Review as ReviewValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class ReviewCreate extends Service
class ReviewCreate extends FrontendService
{
use CourseTrait;

View File

@ -5,10 +5,10 @@ namespace App\Services\Frontend\Review;
use App\Models\Course as CourseModel;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\ReviewTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Review as ReviewValidator;
class ReviewDelete extends Service
class ReviewDelete extends FrontendService
{
use CourseTrait, ReviewTrait;

View File

@ -8,9 +8,9 @@ use App\Models\User as UserModel;
use App\Repos\ReviewVote as ReviewVoteRepo;
use App\Repos\User as UserRepo;
use App\Services\Frontend\ReviewTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class ReviewInfo extends Service
class ReviewInfo extends FrontendService
{
use ReviewTrait;

View File

@ -4,10 +4,10 @@ namespace App\Services\Frontend\Review;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\ReviewTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Review as ReviewValidator;
class ReviewUpdate extends Service
class ReviewUpdate extends FrontendService
{
use CourseTrait, ReviewTrait;

View File

@ -6,10 +6,10 @@ 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\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class CourseList extends Service
class CourseList extends FrontendService
{
use UserTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Teacher;
use App\Models\User as UserModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class TeacherInfo extends Service
class TeacherInfo extends FrontendService
{
use UserTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Topic;
use App\Caches\TopicCourseList as TopicCourseListCache;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\TopicTrait;
class CourseList extends Service
class CourseList extends FrontendService
{
use TopicTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Topic;
use App\Models\Topic as TopicModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\TopicTrait;
class TopicInfo extends Service
class TopicInfo extends FrontendService
{
use TopicTrait;

View File

@ -3,9 +3,9 @@
namespace App\Services\Frontend\Trade;
use App\Services\Frontend\OrderTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
class TradeCancel extends Service
class TradeCancel extends FrontendService
{
use OrderTrait;

View File

@ -4,10 +4,10 @@ namespace App\Services\Frontend\Trade;
use App\Models\Trade as TradeModel;
use App\Services\Frontend\OrderTrait;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Validators\Trade as TradeValidator;
class TradeCreate extends Service
class TradeCreate extends FrontendService
{
use OrderTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\Trade;
use App\Models\Trade as TradeModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\TradeTrait;
class TradeInfo extends Service
class TradeInfo extends FrontendService
{
use TradeTrait;

View File

@ -6,10 +6,10 @@ 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\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class CourseList extends Service
class CourseList extends FrontendService
{
use UserTrait;

View File

@ -3,10 +3,10 @@
namespace App\Services\Frontend\User;
use App\Models\User as UserModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Frontend\UserTrait;
class UserInfo extends Service
class UserInfo extends FrontendService
{
use UserTrait;

View File

@ -2,12 +2,12 @@
namespace App\Services\Frontend\Verify;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Mailer\Verify as VerifyMailerService;
use App\Validators\Captcha as CaptchaValidator;
use App\Validators\Verify as VerifyValidator;
class EmailCode extends Service
class EmailCode extends FrontendService
{
public function handle()

View File

@ -2,12 +2,12 @@
namespace App\Services\Frontend\Verify;
use App\Services\Frontend\Service;
use App\Services\Frontend\Service as FrontendService;
use App\Services\Smser\Verify as VerifySmserService;
use App\Validators\Captcha as CaptchaValidator;
use App\Validators\Verify as VerifyValidator;
class SmsCode extends Service
class SmsCode extends FrontendService
{
public function handle()

View File

@ -37,17 +37,10 @@ class Learning extends Service
/**
* @param LearningModel $learning
* @param int $timeout
* @param int $interval
*/
public function addItem(LearningModel $learning, $timeout = 10)
public function addItem(LearningModel $learning, $interval = 10)
{
/**
* 兼容秒和毫秒
*/
if ($timeout > 1000) {
$timeout = intval($timeout / 1000);
}
$itemKey = $this->getItemKey($learning->request_id);
/**
@ -64,13 +57,14 @@ class Learning extends Service
$learning->course_id = $chapter->course_id;
$learning->client_type = $this->getClientType();
$learning->client_ip = $this->getClientIp();
$learning->duration = $timeout;
$learning->duration = $interval;
$this->cache->save($itemKey, $learning, $this->lifetime);
} else {
$cacheLearning->duration += $timeout;
$cacheLearning->duration += $interval;
$cacheLearning->position = $learning->position;
$this->cache->save($itemKey, $cacheLearning, $this->lifetime);
}

View File

@ -0,0 +1,62 @@
<?php
namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException;
use App\Repos\Chapter as ChapterRepo;
class Learning extends Validator
{
public function checkChapterId($chapterId)
{
$chapterRepo = new ChapterRepo();
$chapter = $chapterRepo->findById($chapterId);
if (!$chapter) {
throw new BadRequestException('learning.invalid_chapter_id');
}
return $chapterId;
}
public function checkRequestId($requestId)
{
if (!$requestId) {
throw new BadRequestException('learning.invalid_request_id');
}
return $requestId;
}
public function checkInterval($interval)
{
$value = $this->filter->sanitize($interval, ['trim', 'int']);
/**
* 兼容秒和毫秒
*/
if ($value > 1000) {
$value = intval($value / 1000);
}
if ($value < 5) {
throw new BadRequestException('learning.invalid_interval');
}
return $value;
}
public function checkPosition($position)
{
$value = $this->filter->sanitize($position, ['trim', 'int']);
if ($value < 0 || $value > 3 * 3600) {
throw new BadRequestException('learning.invalid_position');
}
return $value;
}
}

View File

@ -312,4 +312,12 @@ $error['course_query.invalid_model'] = '无效的模型类别';
$error['course_query.invalid_level'] = '无效的难度类别';
$error['course_query.invalid_sort'] = '无效的排序类别';
/**
* 课时学习
*/
$error['learning.invalid_chapter_id'] = '无效的章节编号';
$error['learning.invalid_request_id'] = '无效的请求编号';
$error['learning.invalid_position'] = '无效的播放位置';
$error['learning.invalid_interval'] = '无效的间隔时间';
return $error;

View File

@ -10,7 +10,7 @@ $script = __DIR__ . '/console.php';
$bin = '/usr/bin/php';
$scheduler->php($script, $bin, ['--task' => 'learning', '--action' => 'main'])
$scheduler->php($script, $bin, ['--task' => 'sync_learning', '--action' => 'main'])
->at('*/3 * * * *');
$scheduler->php($script, $bin, ['--task' => 'order', '--action' => 'main'])