1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00

Merge branch 'develop' into demo

This commit is contained in:
xiaochong0302 2020-09-24 20:07:27 +08:00
commit 46d1c35d21
38 changed files with 419 additions and 165 deletions

View File

@ -3,10 +3,13 @@
namespace App\Console\Tasks;
use App\Models\CourseUser as CourseUserModel;
use App\Models\ImGroupUser as ImGroupUserModel;
use App\Models\Order as OrderModel;
use App\Models\Refund as RefundModel;
use App\Models\Task as TaskModel;
use App\Models\Trade as TradeModel;
use App\Repos\ImGroup as ImGroupRepo;
use App\Repos\ImGroupUser as ImGroupUserRepo;
use App\Repos\Order as OrderRepo;
use App\Repos\User as UserRepo;
use App\Services\Sms\Order as OrderSms;
@ -104,19 +107,36 @@ class DeliverTask extends Task
*/
$itemInfo = $order->item_info;
$data = [
'user_id' => $order->owner_id,
'course_id' => $order->item_id,
'expiry_time' => $itemInfo['course']['study_expiry_time'],
'role_type' => CourseUserModel::ROLE_STUDENT,
'source_type' => CourseUserModel::SOURCE_CHARGE,
];
$courseUser = new CourseUserModel();
if ($courseUser->create($data) === false) {
$courseUser->user_id = $order->owner_id;
$courseUser->course_id = $order->item_id;
$courseUser->expiry_time = $itemInfo['course']['study_expiry_time'];
$courseUser->role_type = CourseUserModel::ROLE_STUDENT;
$courseUser->source_type = CourseUserModel::SOURCE_CHARGE;
if ($courseUser->create() === false) {
throw new \RuntimeException('Create Course User Failed');
}
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findByCourseId($order->item_id);
$groupUserRepo = new ImGroupUserRepo();
$groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id);
if ($groupUser) return;
$groupUser = new ImGroupUserModel();
$groupUser->group_id = $group->id;
$groupUser->user_id = $order->owner_id;
if ($groupUser->create() === false) {
throw new \RuntimeException('Create Group User Failed');
}
}
protected function handlePackageOrder(OrderModel $order)
@ -128,33 +148,50 @@ class DeliverTask extends Task
foreach ($itemInfo['courses'] as $course) {
$data = [
'user_id' => $order->owner_id,
'course_id' => $course['id'],
'expiry_time' => $course['study_expiry_time'],
'role_type' => CourseUserModel::ROLE_STUDENT,
'source_type' => CourseUserModel::SOURCE_CHARGE,
];
$courseUser = new CourseUserModel();
if ($courseUser->create($data) === false) {
$courseUser->user_id = $order->owner_id;
$courseUser->course_id = $course['id'];
$courseUser->expiry_time = $course['study_expiry_time'];
$courseUser->role_type = CourseUserModel::ROLE_STUDENT;
$courseUser->source_type = CourseUserModel::SOURCE_CHARGE;
if ($courseUser->create() === false) {
throw new \RuntimeException('Create Course User Failed');
}
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findByCourseId($course['id']);
$groupUserRepo = new ImGroupUserRepo();
$groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id);
if ($groupUser) continue;
$groupUser = new ImGroupUserModel();
$groupUser->group_id = $group->id;
$groupUser->user_id = $order->owner_id;
if ($groupUser->create() === false) {
throw new \RuntimeException('Create Group User Failed');
}
}
}
protected function handleVipOrder(OrderModel $order)
{
$userRepo = new UserRepo();
$user = $userRepo->findById($order->owner_id);
/**
* @var array $itemInfo
*/
$itemInfo = $order->item_info;
$userRepo = new UserRepo();
$user = $userRepo->findById($order->owner_id);
$user->vip_expiry_time = $itemInfo['vip']['expiry_time'];
if ($user->update() === false) {

View File

@ -5,10 +5,19 @@ namespace App\Console\Tasks;
use App\Caches\IndexFreeCourseList as IndexFreeCourseListCache;
use App\Caches\IndexNewCourseList as IndexNewCourseListCache;
use App\Caches\IndexVipCourseList as IndexVipCourseListCache;
use App\Http\Admin\Services\Setting as SettingService;
use App\Library\Utils\Password as PasswordUtil;
use App\Validators\Account as AccountValidator;
class MaintainTask extends Task
{
/**
* 重建首页课程缓存
*
* @param array $params
* @command: php console.php maintain reset_index_course_cache
*/
public function rebuildIndexCourseCacheAction($params)
{
$section = $params[0] ?? null;
@ -29,4 +38,63 @@ class MaintainTask extends Task
}
}
/**
* 修改密码
*
* @param array $params
* @command: php console.php maintain reset_password 13507083515 123456
*/
public function resetPasswordAction($params)
{
if (empty($params[0])) {
echo 'account is required' . PHP_EOL;
}
if (empty($params[1])) {
echo 'password is required' . PHP_EOL;
}
$validator = new AccountValidator();
$account = $validator->checkAccount($params[0]);
$salt = PasswordUtil::salt();
$hash = PasswordUtil::hash($params[1], $salt);
$account->salt = $salt;
$account->password = $hash;
$account->update();
echo 'reset password success' . PHP_EOL;
}
/**
* 关闭验证码
*
* @command: php console.php maintain disable_captcha
*/
public function disableCaptchaAction()
{
$service = new SettingService();
$service->updateSettings('captcha', ['enabled' => 0]);
echo 'disable captcha success' . PHP_EOL;
}
/**
* 启用验证码
*
* @command: php console.php maintain enable_captcha
*/
public function enableCaptchaAction()
{
$service = new SettingService();
$service->updateSettings('captcha', ['enabled' => 1]);
echo 'enable captcha success' . PHP_EOL;
}
}

View File

@ -28,6 +28,8 @@ class VodEventTask extends Task
$this->handleNewFileUploadEvent($event);
} elseif ($event['EventType'] == 'ProcedureStateChanged') {
$this->handleProcedureStateChangedEvent($event);
} elseif ($event['EventType'] == 'FileDeleted') {
$this->handleFileDeletedEvent($event);
}
$count++;
@ -123,6 +125,11 @@ class VodEventTask extends Task
$chapter->update(['attrs' => $attrs]);
}
protected function handleFileDeletedEvent($event)
{
}
protected function pullEvents()
{
$vodService = new VodService();

View File

@ -10,6 +10,7 @@ use App\Repos\Chapter as ChapterRepo;
use App\Repos\Course as CourseRepo;
use App\Services\ChapterVod as ChapterVodService;
use App\Services\CourseStat as CourseStatService;
use App\Services\Vod as VodService;
use App\Validators\ChapterLive as ChapterLiveValidator;
use App\Validators\ChapterRead as ChapterReadValidator;
use App\Validators\ChapterVod as ChapterVodValidator;
@ -100,9 +101,11 @@ class ChapterContent extends Service
$chapter->update(['attrs' => $attrs]);
$courseStats = new CourseStatService();
$this->updateCourseVodAttrs($vod->course_id);
$courseStats->updateVodAttrs($chapter->course_id);
if (!empty($vod->file_id)) {
$this->deleteVodFile($vod->file_id);
}
}
protected function updateChapterLive(ChapterModel $chapter)
@ -135,9 +138,7 @@ class ChapterContent extends Service
$chapter->update(['attrs' => $attrs]);
$courseStats = new CourseStatService();
$courseStats->updateLiveAttrs($chapter->course_id);
$this->updateCourseLiveAttrs($live->course_id);
}
protected function updateChapterRead(ChapterModel $chapter)
@ -164,9 +165,35 @@ class ChapterContent extends Service
$chapter->update(['attrs' => $attrs]);
$courseStats = new CourseStatService();
$this->updateCourseReadAttrs($read->course_id);
}
$courseStats->updateReadAttrs($chapter->course_id);
protected function updateCourseVodAttrs($courseId)
{
$statService = new CourseStatService();
$statService->updateVodAttrs($courseId);
}
protected function updateCourseLiveAttrs($courseId)
{
$statService = new CourseStatService();
$statService->updateLiveAttrs($courseId);
}
protected function updateCourseReadAttrs($courseId)
{
$statService = new CourseStatService();
$statService->updateReadAttrs($courseId);
}
protected function deleteVodFile($fileId)
{
$vodService = new VodService();
$vodService->deleteMedia($fileId);
}
protected function rebuildCatalogCache(ChapterModel $chapter)

View File

@ -30,8 +30,8 @@ abstract class PayTest extends Service
$order = new OrderModel();
$order->subject = '测试 - 支付测试3.01元';
$order->amount = 3.01;
$order->subject = '测试 - 支付测试0.01元';
$order->amount = 0.01;
$order->owner_id = $authUser['id'];
$order->item_type = OrderModel::ITEM_TEST;
@ -59,7 +59,7 @@ abstract class PayTest extends Service
$order = new OrderModel();
/**
* 微信沙箱环境金额不能自定义,只能是测试用例值(沙吊的不行)
* 微信沙箱环境金额不能自定义,只能是固定测试用例值SB的不行)
*/
if ($config->get('env') == ENV_DEV) {
$order->subject = '测试 - 支付测试3.01元';

View File

@ -2,6 +2,9 @@
{% block content %}
{% set disabled_submit = captcha.enabled == 1 ? 'disabled="disabled"' : '' %}
{% set disabled_class = captcha.enabled == 1 ? 'layui-btn-disabled' : '' %}
<div class="kg-login-wrap">
<div class="layui-card">
<div class="layui-card-header">管理登录</div>
@ -26,8 +29,8 @@
{% endif %}
<div class="layui-form-item">
<div class="layui-input-block">
{% set disabled = captcha.enabled ? 'disabled="disabled"' : '' %}
<button id="submit-btn" class="layui-btn layui-btn-fluid layui-btn-disabled" {{ disabled }} lay-submit="true" lay-filter="go">立即登录</button>
<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">
</div>

View File

@ -12,13 +12,6 @@
<input class="layui-input" type="text" name="app_id" value="{{ alipay.app_id }}" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">Public Key</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="public_key" lay-verify="required">{{ alipay.public_key }}</textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">Private Key</label>
<div class="layui-input-block">

View File

@ -1,6 +1,6 @@
{% extends 'templates/main.volt' %}
{% block contnet %}
{% block content %}
<div class="kg-qrcode-block">
{% if qrcode %}

View File

@ -113,7 +113,7 @@
<div class="layui-form-item">
<label class="layui-form-label">请求方法</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="file" value="DescribeAudioTrackTemplates" readonly="readonly">
<input class="layui-input" type="text" name="file" value="DescribeTranscodeTemplates" readonly="readonly">
</div>
</div>
<div class="layui-form-item">

View File

@ -2,7 +2,7 @@
namespace App\Http\Home\Services;
use App\Caches\Setting as SettingCache;
use App\Services\Service as AppService;
use GatewayClient\Gateway;
trait ImCsTrait
@ -11,32 +11,33 @@ trait ImCsTrait
public function getCsUser()
{
$csUserIds = [];
$onlineUserIds = [];
$cache = new SettingCache();
$appService = new AppService();
$imInfo = $cache->get('im');
$csInfo = $appService->getSettings('im.cs');
Gateway::$registerAddress = $this->getRegisterAddress();
if (!empty($imInfo['cs_user1_id'])) {
$csUserIds[] = $imInfo['cs_user1_id'];
if (Gateway::isUidOnline($imInfo['cs_user1_id'])) {
$onlineUserIds[] = $imInfo['cs_user1_id'];
if (!empty($csInfo['user1_id'])) {
$csUserIds[] = $csInfo['user1_id'];
if (Gateway::isUidOnline($csInfo['user1_id'])) {
$onlineUserIds[] = $csInfo['user1_id'];
}
}
if (!empty($imInfo['cs_user2_id'])) {
$csUserIds[] = $imInfo['cs_user2_id'];
if (Gateway::isUidOnline($imInfo['cs_user2_id'])) {
$onlineUserIds[] = $imInfo['cs_user2_id'];
if (!empty($csInfo['user2_id'])) {
$csUserIds[] = $csInfo['user2_id'];
if (Gateway::isUidOnline($csInfo['user2_id'])) {
$onlineUserIds[] = $csInfo['user2_id'];
}
}
if (!empty($imInfo['cs_user3_id'])) {
$csUserIds[] = $imInfo['cs_user3_id'];
if (Gateway::isUidOnline($imInfo['cs_user3_id'])) {
$onlineUserIds[] = $imInfo['cs_user3_id'];
if (!empty($csInfo['user3_id'])) {
$csUserIds[] = $csInfo['user3_id'];
if (Gateway::isUidOnline($csInfo['user3_id'])) {
$onlineUserIds[] = $csInfo['user3_id'];
}
}

View File

@ -11,17 +11,24 @@ use App\Repos\ImUser as ImUserRepo;
use App\Validators\ImFriendUser as ImFriendUserValidator;
use App\Validators\ImNotice as ImNoticeValidator;
use GatewayClient\Gateway;
use Phalcon\Di;
use Phalcon\Http\Request;
Trait ImFriendTrait
{
public function applyFriend()
{
/**
* @var Request $request
*/
$request = Di::getDefault()->get('request');
$loginUser = $this->getLoginUser();
$user = $this->getImUser($loginUser->id);
$post = $this->request->getPost();
$post = $request->getPost();
$validator = new ImFriendUserValidator();
@ -37,12 +44,17 @@ Trait ImFriendTrait
public function acceptFriend()
{
/**
* @var Request $request
*/
$request = Di::getDefault()->get('request');
$loginUser = $this->getLoginUser();
$user = $this->getImUser($loginUser->id);
$noticeId = $this->request->getPost('notice_id');
$groupId = $this->request->getPost('group_id');
$noticeId = $request->getPost('notice_id');
$groupId = $request->getPost('group_id');
$validator = new ImFriendUserValidator();
@ -103,11 +115,16 @@ Trait ImFriendTrait
public function refuseFriend()
{
/**
* @var Request $request
*/
$request = Di::getDefault()->get('request');
$loginUser = $this->getLoginUser();
$user = $this->getImUser($loginUser->id);
$noticeId = $this->request->getPost('notice_id');
$noticeId = $request->getPost('notice_id');
$validator = new ImNoticeValidator();

View File

@ -13,35 +13,48 @@ use App\Validators\ImGroup as ImGroupValidator;
use App\Validators\ImGroupUser as ImGroupUserValidator;
use App\Validators\ImNotice as ImNoticeValidator;
use GatewayClient\Gateway;
use Phalcon\Di;
use Phalcon\Http\Request;
Trait ImGroupTrait
{
public function applyGroup()
{
/**
* @var Request $request
*/
$request = Di::getDefault()->get('request');
$loginUser = $this->getLoginUser();
$user = $this->getImUser($loginUser->id);
$post = $this->request->getPost();
$validator = new ImGroupUserValidator();
$post = $request->getPost();
$group = $validator->checkGroup($post['group_id']);
$remark = $validator->checkRemark($post['remark']);
$validator->checkIfJoined($group->id, $user->id);
$validator->checkIfAllowJoin($group->id, $user->id);
$this->handleApplyGroupNotice($user, $group, $remark);
}
public function acceptGroup()
{
/**
* @var Request $request
*/
$request = Di::getDefault()->get('request');
$loginUser = $this->getLoginUser();
$user = $this->getImUser($loginUser->id);
$noticeId = $this->request->getPost('notice_id', 'int');
$noticeId = $request->getPost('notice_id', 'int');
$validator = new ImNoticeValidator();
@ -92,11 +105,16 @@ Trait ImGroupTrait
public function refuseGroup()
{
/**
* @var Request $request
*/
$request = Di::getDefault()->get('request');
$loginUser = $this->getLoginUser();
$user = $this->getImUser($loginUser->id);
$noticeId = $this->request->getPost('notice_id', 'int');
$noticeId = $request->getPost('notice_id', 'int');
$validator = new ImNoticeValidator();

View File

@ -3,7 +3,6 @@
{% block content %}
{% set group.about = group.about ? group.about : '这个家伙真懒,什么都没有留下~' %}
{% set apply_group_url = '' %}
{% set users_url = url({'for':'home.group.users','id':group.id}) %}
{% set active_users_url = url({'for':'home.group.active_users','id':group.id}) %}

View File

@ -24,7 +24,7 @@ class Sitemap
* @param string $changefreq 更新频率的单位
* @param string $lastmod 日期格式 YYYY-MM-DD
*/
function addItem($loc, $priority = null, $changefreq = null, $lastmod = null)
public function addItem($loc, $priority = null, $changefreq = null, $lastmod = null)
{
$this->items[] = array(
'loc' => $loc,
@ -38,7 +38,7 @@ class Sitemap
* @param string $filename
* @return mixed
*/
function build($filename = null)
public function build($filename = null)
{
$xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
$xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";

View File

@ -79,6 +79,18 @@ class ImGroup extends Repository
return ImGroupModel::findFirst($id);
}
/**
* @param int $courseId
* @return ImGroupModel|Model|bool
*/
public function findByCourseId($courseId)
{
return ImGroupModel::findFirst([
'conditions' => 'course_id = :course_id:',
'bind' => ['course_id' => $courseId],
]);
}
/**
* @param array $ids
* @param string|array $columns

View File

@ -271,7 +271,7 @@ class Live extends Service
return http_build_query([
'txSecret' => $txSecret,
'txTime' => $txTime
'txTime' => $txTime,
]);
}

View File

@ -162,9 +162,13 @@ class LiveNotify extends Service
*/
protected function checkSign($sign, $time)
{
if (!$sign || !$time) return false;
if (!$sign || !$time) {
return false;
}
if ($time < time()) return false;
if ($time < time()) {
return false;
}
$notify = $this->getSettings('live.notify');

View File

@ -6,8 +6,10 @@ use App\Models\Chapter as ChapterModel;
use App\Models\ChapterUser as ChapterUserModel;
use App\Models\Course as CourseModel;
use App\Models\CourseUser as CourseUserModel;
use App\Models\ImGroupUser as ImGroupUserModel;
use App\Models\User as UserModel;
use App\Repos\ChapterLike as ChapterLikeRepo;
use App\Repos\ImGroup as ImGroupRepo;
use App\Services\Logic\ChapterTrait;
use App\Services\Logic\CourseTrait;
use App\Services\Logic\Service;
@ -114,6 +116,17 @@ class ChapterInfo extends Service
$this->joinedCourse = true;
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findByCourseId($course->id);
$groupUser = new ImGroupUserModel();
$groupUser->group_id = $group->id;
$groupUser->user_id = $user->id;
$groupUser->create();
$this->incrCourseUserCount($course);
$this->incrUserCourseCount($user);

View File

@ -22,7 +22,7 @@ class Verify extends MailerService
$minutes = 5;
$code = $verify->getEmailCode($email, 60 * $minutes);
$code = $verify->getMailCode($email, 60 * $minutes);
$subject = '邮件验证码';

View File

@ -106,7 +106,7 @@ class MyStorage extends Storage
*
* @param string $prefix
* @param string $mimeType
* @param string $uploadType
* @param int $uploadType
* @return UploadModel|bool
*/
protected function upload($prefix, $mimeType, $uploadType)

View File

@ -42,9 +42,10 @@ class AlipayGateway extends Service
$options = [
'app_id' => $this->settings['app_id'],
'ali_public_key' => $this->settings['public_key'],
'private_key' => $this->settings['private_key'],
'return_url' => $this->settings['return_url'],
'ali_public_key' => config_path('alipay/alipayCertPublicKey.crt'), // 支付宝公钥证书
'alipay_root_cert' => config_path('alipay/alipayRootCert.crt'), // 支付宝根证书
'app_cert_public_key' => config_path('alipay/appCertPublicKey.crt'), // 应用公钥证书
'notify_url' => $this->settings['notify_url'],
'log' => [
'file' => log_path('alipay.log'),

View File

@ -37,6 +37,8 @@ Abstract class Smser extends Service
{
$sender = $this->createSingleSender();
$params = $this->formatParams($params);
$signature = $this->getSignature();
try {
@ -71,6 +73,17 @@ Abstract class Smser extends Service
return new SmsSingleSender($this->settings['app_id'], $this->settings['app_key']);
}
protected function formatParams($params)
{
if (!empty($params)) {
$params = array_map(function ($value) {
return strval($value);
}, $params);
}
return $params;
}
protected function getTemplateId($code)
{
$template = json_decode($this->settings['template'], true);

View File

@ -173,7 +173,7 @@ class Storage extends Service
*/
protected function generateFileName($extension = '', $prefix = '')
{
$randName = date('YmdHis') . rand(1000, 9999);
$randName = date('YmdHis') . rand(100, 999) . rand(100, 999);
return $prefix . $randName . '.' . $extension;
}

View File

@ -49,7 +49,7 @@ class Throttle extends Service
return md5($httpHost . '|' . $clientAddress);
}
throw new \RuntimeException('Unable to generate the request signature.');
throw new \RuntimeException('Unable to generate request signature');
}
protected function getCacheKey($sign)

View File

@ -29,9 +29,9 @@ class Verify extends Service
return $code;
}
public function getEmailCode($email, $lifetime = 300)
public function getMailCode($email, $lifetime = 300)
{
$key = $this->getEmailCacheKey($email);
$key = $this->getMailCacheKey($email);
$code = Text::random(Text::RANDOM_NUMERIC, 6);
@ -49,18 +49,18 @@ class Verify extends Service
return $code == $value;
}
public function checkEmailCode($email, $code)
public function checkMailCode($email, $code)
{
$key = $this->getEmailCacheKey($email);
$key = $this->getMailCacheKey($email);
$value = $this->cache->get($key);
return $code == $value;
}
protected function getEmailCacheKey($email)
protected function getMailCacheKey($email)
{
return "verify:email:{$email}";
return "verify:mail:{$email}";
}
protected function getSmsCacheKey($phone)

View File

@ -8,9 +8,10 @@ use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Vod\V20180717\Models\ConfirmEventsRequest;
use TencentCloud\Vod\V20180717\Models\DescribeAudioTrackTemplatesRequest;
use TencentCloud\Vod\V20180717\Models\DeleteMediaRequest;
use TencentCloud\Vod\V20180717\Models\DescribeMediaInfosRequest;
use TencentCloud\Vod\V20180717\Models\DescribeTaskDetailRequest;
use TencentCloud\Vod\V20180717\Models\DescribeTranscodeTemplatesRequest;
use TencentCloud\Vod\V20180717\Models\ProcessMediaRequest;
use TencentCloud\Vod\V20180717\Models\PullEventsRequest;
use TencentCloud\Vod\V20180717\VodClient;
@ -53,21 +54,21 @@ class Vod extends Service
{
try {
$request = new DescribeAudioTrackTemplatesRequest();
$request = new DescribeTranscodeTemplatesRequest();
$params = '{}';
$request->fromJsonString($params);
$response = $this->client->DescribeAudioTrackTemplates($request);
$response = $this->client->DescribeTranscodeTemplates($request);
$this->logger->debug('Describe Audio Track Templates Response ' . $response->toJsonString());
$this->logger->debug('Describe Transcode Templates Response ' . $response->toJsonString());
$result = $response->TotalCount > 0;
} catch (TencentCloudSDKException $e) {
$this->logger->error('Describe Audio Track Templates Exception ' . kg_json_encode([
$this->logger->error('Describe Transcode Templates Exception ' . kg_json_encode([
'code' => $e->getErrorCode(),
'message' => $e->getMessage(),
'requestId' => $e->getRequestId(),
@ -274,6 +275,44 @@ class Vod extends Service
return $result;
}
/**
* 删除媒体
*
* @param string $fileId
* @return bool
*/
public function deleteMedia($fileId)
{
try {
$request = new DeleteMediaRequest();
$params = json_encode(['FileId' => $fileId]);
$request->fromJsonString($params);
$this->logger->debug('Delete Media Request ' . $params);
$response = $this->client->DeleteMedia($request);
$this->logger->debug('Delete Media Response ' . $response->toJsonString());
$result = !empty($response->RequestId);
} catch (TencentCloudSDKException $e) {
$this->logger->error('Delete Media Exception ' . kg_json_encode([
'code' => $e->getErrorCode(),
'message' => $e->getMessage(),
'requestId' => $e->getRequestId(),
]));
$result = false;
}
return $result;
}
/**
* 获取媒体信息
*
@ -574,7 +613,7 @@ class Vod extends Service
{
$result = null;
if ($this->settings['wmk_enabled'] && $this->settings['wmk_tpl_id'] > 0) {
if ($this->settings['wmk_enabled'] == 1 && $this->settings['wmk_tpl_id'] > 0) {
$result = (int)$this->settings['wmk_tpl_id'];
}

View File

@ -67,7 +67,7 @@ class Account extends Validator
public function checkPassword($password)
{
if (!CommonValidator::password($password)) {
throw new BadRequestException('account.invalid_password');
throw new BadRequestException('account.invalid_pwd');
}
return $password;
@ -76,7 +76,7 @@ class Account extends Validator
public function checkConfirmPassword($newPassword, $confirmPassword)
{
if ($newPassword != $confirmPassword) {
throw new BadRequestException('account.password_not_match');
throw new BadRequestException('account.pwd_not_match');
}
}
@ -85,7 +85,7 @@ class Account extends Validator
$hash = PasswordUtil::hash($password, $account->salt);
if ($hash != $account->password) {
throw new BadRequestException('account.origin_password_incorrect');
throw new BadRequestException('account.origin_pwd_incorrect');
}
}
@ -94,7 +94,7 @@ class Account extends Validator
$hash = PasswordUtil::hash($password, $account->salt);
if ($hash != $account->password) {
throw new BadRequestException('account.login_password_incorrect');
throw new BadRequestException('account.login_pwd_incorrect');
}
}
@ -140,7 +140,7 @@ class Account extends Validator
$hash = PasswordUtil::hash($password, $account->salt);
if ($hash != $account->password) {
throw new BadRequestException('account.login_password_incorrect');
throw new BadRequestException('account.login_pwd_incorrect');
}
$userRepo = new UserRepo();

View File

@ -3,7 +3,13 @@
namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException;
use App\Models\ImGroup as ImGroupModel;
use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo;
use App\Repos\CourseUser as CourseUserRepo;
use App\Repos\ImGroup as ImGroupRepo;
use App\Repos\ImGroupUser as ImGroupUserRepo;
use App\Repos\User as UserRepo;
class ImGroupUser extends Validator
{
@ -59,4 +65,39 @@ class ImGroupUser extends Validator
}
}
public function checkIfAllowJoin($groupId, $userId)
{
$message = 'im_group_user.join_not_allowed';
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findById($groupId);
$userRepo = new UserRepo();
$user = $userRepo->findById($userId);
$staff = $user->admin_role > 0 || $user->edu_role == UserModel::EDU_ROLE_TEACHER;
if ($group->type == ImGroupModel::TYPE_STAFF && !$staff) {
throw new BadRequestException($message);
}
if ($group->course_id > 0) {
$courseRepo = new CourseRepo();
$course = $courseRepo->findById($group->course_id);
$courseUserRepo = new CourseUserRepo();
$courseUser = $courseUserRepo->findCourseUser($course->id, $user->id);
if ($course->market_price > 0) {
if ($course->vip_price > 0 && !$courseUser) {
throw new BadRequestException($message);
}
if ($course->vip_price == 0 && $user->vip == 0) {
throw new BadRequestException($message);
}
}
}
}
}

View File

@ -9,9 +9,9 @@ use Phalcon\Mvc\User\Component;
class Validator extends Component
{
public function checkAuthUser($authUser)
public function checkAuthUser($authInfo)
{
if (empty($authUser['id'])) {
if (empty($authInfo['id'])) {
throw new UnauthorizedException('sys.unauthorized');
}
}

View File

@ -30,11 +30,11 @@ class Verify extends Validator
public function checkCode($identity, $code)
{
if (CommonValidator::email($identity)) {
$this->checkEmailCode($identity, $code);
$this->checkMailCode($identity, $code);
} elseif (CommonValidator::phone($identity)) {
$this->checkSmsCode($identity, $code);
} else {
throw new BadRequestException('verify.unsupported_identity');
throw new BadRequestException('verify.invalid_code');
}
}
@ -49,14 +49,14 @@ class Verify extends Validator
}
}
public function checkEmailCode($email, $code)
public function checkMailCode($email, $code)
{
$service = new VerifyService();
$result = $service->checkEmailCode($email, $code);
$result = $service->checkMailCode($email, $code);
if (!$result) {
throw new BadRequestException('verify.invalid_email_code');
throw new BadRequestException('verify.invalid_mail_code');
}
}

View File

@ -27,17 +27,13 @@ class ConsoleErrorHandler extends Component
*/
public function handleException($e)
{
$config = $this->getConfig();
$logger = $this->getLogger();
$content = sprintf('%s(%d): %s', $e->getFile(), $e->getLine(), $e->getMessage());
$logger->error($content);
if ($config->get('env') == ENV_DEV) {
echo $content;
}
echo $content . PHP_EOL;
}
/**
@ -45,7 +41,7 @@ class ConsoleErrorHandler extends Component
*/
protected function getConfig()
{
return $this->getDI()->get('config');
return $this->getDI()->getShared('config');
}
/**

View File

@ -26,8 +26,8 @@ class ConsoleKernel extends Kernel
$this->loader = new Loader();
$this->initAppEnv();
$this->initAppConfigs();
$this->initAppSettings();
$this->initAppConfig();
$this->initAppSetting();
$this->registerLoaders();
$this->registerServices();
$this->registerErrorHandler();

View File

@ -115,7 +115,7 @@ function tmp_path($path = '')
}
/**
* Rtrim slash
* Trim path slash
*
* @param string $path
* @return string

View File

@ -35,8 +35,8 @@ class HttpKernel extends Kernel
$this->loader = new Loader();
$this->initAppEnv();
$this->initAppConfigs();
$this->initAppSettings();
$this->initAppConfig();
$this->initAppSetting();
$this->registerLoaders();
$this->registerServices();
$this->registerModules();

View File

@ -27,7 +27,7 @@ abstract class Kernel
/**
* @var array
*/
protected $configs = [];
protected $config = [];
public function getApp()
{
@ -44,16 +44,16 @@ abstract class Kernel
require __DIR__ . '/Helper.php';
}
protected function initAppConfigs()
protected function initAppConfig()
{
$this->configs = require config_path('config.php');
$this->config = require config_path('config.php');
}
protected function initAppSettings()
protected function initAppSetting()
{
ini_set('date.timezone', $this->configs['timezone']);
ini_set('date.timezone', $this->config['timezone']);
if ($this->configs['env'] == ENV_DEV) {
if ($this->config['env'] == ENV_DEV) {
ini_set('display_errors', 1);
error_reporting(E_ALL);
} else {

View File

@ -26,10 +26,11 @@ $error['security.invalid_http_referer'] = '无效请求来源';
*/
$error['verify.invalid_phone'] = '无效手机号';
$error['verify.invalid_email'] = '无效的邮箱';
$error['verify.invalid_code'] = '无效的验证码';
$error['verify.invalid_sms_code'] = '无效的短信验证码';
$error['verify.invalid_email_code'] = '无效的邮件验证码';
$error['verify.send_sms_failed'] = '发送短信验证码失败';
$error['verify.send_email_failed'] = '发送邮件验证码失败';
$error['verify.invalid_mail_code'] = '无效的邮件验证码';
$error['verify.send_sms_failed'] = '发送短信失败';
$error['verify.send_mail_failed'] = '发送邮件失败';
/**
* captcha相关
@ -41,16 +42,16 @@ $error['captcha.invalid_code'] = '无效的验证码';
*/
$error['account.not_found'] = '账号不存在';
$error['account.login_block'] = '账号被锁定,无法登录';
$error['account.login_password_incorrect'] = '登录密码不正确';
$error['account.login_pwd_incorrect'] = '登录密码不正确';
$error['account.invalid_login_name'] = '无效的登录名';
$error['account.invalid_email'] = '无效的电子邮箱';
$error['account.invalid_phone'] = '无效的手机号';
$error['account.invalid_password'] = '无效的密码字母或数字6-16位';
$error['account.invalid_pwd'] = '无效的密码字母或数字6-16位';
$error['account.email_taken'] = '邮箱被占用';
$error['account.phone_taken'] = '手机号被占用';
$error['account.password_not_match'] = '密码不匹配';
$error['account.origin_password_incorrect'] = '原有密码不正确';
$error['account.login_password_incorrect'] = '登录密码不正确';
$error['account.pwd_not_match'] = '密码不匹配';
$error['account.origin_pwd_incorrect'] = '原有密码不正确';
$error['account.login_pwd_incorrect'] = '登录密码不正确';
/**
* 用户相关
@ -341,6 +342,7 @@ $error['im_group.invalid_publish_status'] = '无效的发布状态';
$error['im_group_user.not_found'] = '群组关系不存在';
$error['im_group_user.remark_too_long'] = '验证信息太长超过30字符';
$error['im_group_user.has_joined'] = '已经加入过群组';
$error['im_group_user.join_not_allowed'] = '当前不允许加入群组';
$error['im_friend_user.not_found'] = '好友关系不存在';
$error['im_friend_user.remark_too_long'] = '验证信息太长超过30字符';

View File

@ -3668,10 +3668,6 @@ class InitTable extends Phinx\Migration\AbstractMigration
'limit' => MysqlAdapter::INT_REGULAR,
'after' => 'create_time',
])
->addIndex(['item_type', 'status'], [
'name' => 'type_status',
'unique' => false,
])
->create();
$this->table('kg_topic', [
'id' => false,
@ -3816,7 +3812,7 @@ class InitTable extends Phinx\Migration\AbstractMigration
->addColumn('channel_sn', 'string', [
'null' => false,
'default' => '',
'limit' => 32,
'limit' => 64,
'collation' => 'utf8mb4_general_ci',
'encoding' => 'utf8mb4',
'comment' => '平台序号',

View File

@ -12983,39 +12983,6 @@ return array(
'Index_comment' => '',
),
),
'type_status' =>
array(
1 =>
array(
'Table' => 'kg_task',
'Non_unique' => '1',
'Key_name' => 'type_status',
'Seq_in_index' => '1',
'Column_name' => 'item_type',
'Collation' => 'A',
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => '',
'Index_type' => 'BTREE',
'Comment' => '',
'Index_comment' => '',
),
2 =>
array(
'Table' => 'kg_task',
'Non_unique' => '1',
'Key_name' => 'type_status',
'Seq_in_index' => '2',
'Column_name' => 'status',
'Collation' => 'A',
'Sub_part' => NULL,
'Packed' => NULL,
'Null' => '',
'Index_type' => 'BTREE',
'Comment' => '',
'Index_comment' => '',
),
),
),
'foreign_keys' => NULL,
),