mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-24 20:06:09 +08:00
Merge branch 'koogua/v1.7.1' into demo
This commit is contained in:
commit
2e672a81f4
@ -7,7 +7,7 @@
|
||||
|
||||
namespace App\Http\Api;
|
||||
|
||||
use App\Services\Auth\Api as AppAuth;
|
||||
use App\Services\Auth\Api as ApiAuth;
|
||||
use Phalcon\DiInterface;
|
||||
use Phalcon\Mvc\ModuleDefinitionInterface;
|
||||
use Phalcon\Mvc\View;
|
||||
@ -29,7 +29,7 @@ class Module implements ModuleDefinitionInterface
|
||||
});
|
||||
|
||||
$dependencyInjector->setShared('auth', function () {
|
||||
return new AppAuth();
|
||||
return new ApiAuth();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,10 @@ class Connect extends Service
|
||||
|
||||
if ($relation) {
|
||||
|
||||
$relation->update_time = time();
|
||||
|
||||
$relation->update();
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($relation->user_id);
|
||||
@ -111,7 +115,7 @@ class Connect extends Service
|
||||
case ConnectModel::PROVIDER_WEIBO:
|
||||
$auth = $this->getWeiBoAuth();
|
||||
break;
|
||||
case ConnectModel::PROVIDER_WECHAT:
|
||||
case ConnectModel::PROVIDER_WECHAT_OA:
|
||||
$auth = $this->getWeChatAuth();
|
||||
break;
|
||||
}
|
||||
|
@ -70,6 +70,8 @@ class Connect extends Service
|
||||
$auth = $this->getAppAuth();
|
||||
|
||||
$auth->saveAuthInfo($user);
|
||||
|
||||
$this->eventsManager->fire('Account:afterRegister', $this, $user);
|
||||
}
|
||||
|
||||
public function bindUser(array $openUser)
|
||||
@ -89,6 +91,10 @@ class Connect extends Service
|
||||
|
||||
$validator->checkIfAllowLogin($user);
|
||||
|
||||
$connect->update_time = time();
|
||||
|
||||
$connect->update();
|
||||
|
||||
$this->handleLoginNotice($user);
|
||||
|
||||
$auth = $this->getAppAuth();
|
||||
|
@ -40,6 +40,10 @@ class WeChatOfficialAccount extends Service
|
||||
|
||||
$validator->checkIfAllowLogin($user);
|
||||
|
||||
$connect->update_time = time();
|
||||
|
||||
$connect->update();
|
||||
|
||||
$this->handleLoginNotice($user);
|
||||
|
||||
$auth = $this->getAppAuth();
|
||||
@ -103,6 +107,8 @@ class WeChatOfficialAccount extends Service
|
||||
$auth = $this->getAppAuth();
|
||||
|
||||
$auth->saveAuthInfo($user);
|
||||
|
||||
$this->eventsManager->fire('Account:afterRegister', $this, $user);
|
||||
}
|
||||
|
||||
protected function getAppAuth()
|
||||
|
@ -98,7 +98,7 @@
|
||||
<tr>
|
||||
<td>提供方</td>
|
||||
<td>用户信息</td>
|
||||
<td>更新日期</td>
|
||||
<td>最后登录</td>
|
||||
<td width="15%">操作</td>
|
||||
</tr>
|
||||
{% for connect in connects %}
|
||||
|
@ -30,6 +30,11 @@ class Seo
|
||||
*/
|
||||
protected $titleSeparator = ' - ';
|
||||
|
||||
/**
|
||||
* @var string 关键字分隔符
|
||||
*/
|
||||
protected $keywordSeparator = ',';
|
||||
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
@ -37,6 +42,10 @@ class Seo
|
||||
|
||||
public function setKeywords($keywords)
|
||||
{
|
||||
if (is_array($keywords)) {
|
||||
$keywords = implode($this->keywordSeparator, $keywords);
|
||||
}
|
||||
|
||||
$this->keywords = $keywords;
|
||||
}
|
||||
|
||||
@ -84,4 +93,9 @@ class Seo
|
||||
return $this->titleSeparator;
|
||||
}
|
||||
|
||||
public function getKeywordSeparator()
|
||||
{
|
||||
return $this->keywordSeparator;
|
||||
}
|
||||
|
||||
}
|
||||
|
51
app/Listeners/Chapter.php
Normal file
51
app/Listeners/Chapter.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Models\Chapter as ChapterModel;
|
||||
use Phalcon\Events\Event as PhEvent;
|
||||
|
||||
class Chapter extends Listener
|
||||
{
|
||||
|
||||
public function afterCreate(PhEvent $event, $source, ChapterModel $chapter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterUpdate(PhEvent $event, $source, ChapterModel $chapter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterDelete(PhEvent $event, $source, ChapterModel $chapter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterRestore(PhEvent $event, $source, ChapterModel $chapter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterView(PhEvent $event, $source, ChapterModel $chapter)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterLike(PhEvent $event, $source, ChapterModel $chapter): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterUndoLike(PhEvent $event, $source, ChapterModel $chapter): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
51
app/Listeners/Course.php
Normal file
51
app/Listeners/Course.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
||||
* @license https://opensource.org/licenses/GPL-2.0
|
||||
* @link https://www.koogua.com
|
||||
*/
|
||||
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Models\Course as CourseModel;
|
||||
use Phalcon\Events\Event as PhEvent;
|
||||
|
||||
class Course extends Listener
|
||||
{
|
||||
|
||||
public function afterCreate(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterUpdate(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterDelete(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterRestore(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterView(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterFavorite(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function afterUndoFavorite(PhEvent $event, $source, CourseModel $course): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -67,6 +67,19 @@ class Connect extends Repository
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $openId
|
||||
* @param int $provider
|
||||
* @return ConnectModel|Model|bool
|
||||
*/
|
||||
public function findByOpenIdShallow($openId, $provider)
|
||||
{
|
||||
return ConnectModel::findFirst([
|
||||
'conditions' => 'open_id = ?1 AND provider = ?2',
|
||||
'bind' => [1 => $openId, 2 => $provider],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param int $provider
|
||||
|
@ -53,7 +53,11 @@ class ChapterInfo extends LogicService
|
||||
$this->setChapterUser($chapter, $user);
|
||||
$this->handleChapterUser($chapter, $user);
|
||||
|
||||
return $this->handleChapter($chapter, $user);
|
||||
$result = $this->handleChapter($chapter, $user);
|
||||
|
||||
$this->eventsManager->fire('Chapter:afterView', $this, $chapter);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function handleChapter(ChapterModel $chapter, UserModel $user)
|
||||
|
@ -58,11 +58,15 @@ class ChapterLike extends LogicService
|
||||
|
||||
$this->incrChapterLikeCount($chapter);
|
||||
|
||||
$this->eventsManager->fire('Chapter:afterLike', $this, $chapter);
|
||||
|
||||
} else {
|
||||
|
||||
$action = 'undo';
|
||||
|
||||
$this->decrChapterLikeCount($chapter);
|
||||
|
||||
$this->eventsManager->fire('Chapter:afterUndoLike', $this, $chapter);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -57,12 +57,16 @@ class CourseFavorite extends LogicService
|
||||
$this->incrCourseFavoriteCount($course);
|
||||
$this->incrUserFavoriteCount($user);
|
||||
|
||||
$this->eventsManager->fire('Course:afterFavorite', $this, $course);
|
||||
|
||||
} else {
|
||||
|
||||
$action = 'undo';
|
||||
|
||||
$this->decrCourseFavoriteCount($course);
|
||||
$this->decrUserFavoriteCount($user);
|
||||
|
||||
$this->eventsManager->fire('Course:afterUndoFavorite', $this, $course);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -27,7 +27,11 @@ class CourseInfo extends LogicService
|
||||
|
||||
$this->setCourseUser($course, $user);
|
||||
|
||||
return $this->handleCourse($course, $user);
|
||||
$result = $this->handleCourse($course, $user);
|
||||
|
||||
$this->eventsManager->fire('Course:afterView', $this, $course);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function handleCourse(CourseModel $course, UserModel $user)
|
||||
|
@ -24,7 +24,7 @@ class ConsultReply extends LogicService
|
||||
$wechatNoticeEnabled = $this->wechatNoticeEnabled();
|
||||
$smsNoticeEnabled = $this->smsNoticeEnabled();
|
||||
|
||||
$consultId = $task->item_info['consult']['id'];
|
||||
$consultId = $task->item_id;
|
||||
|
||||
$consultRepo = new ConsultRepo();
|
||||
|
||||
|
26
app/Services/Logic/Notice/External/Mail/Test.php
vendored
26
app/Services/Logic/Notice/External/Mail/Test.php
vendored
@ -14,32 +14,14 @@ class Test extends Mailer
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return bool
|
||||
* @return bool|null
|
||||
*/
|
||||
public function handle($email)
|
||||
{
|
||||
try {
|
||||
$subject = $this->formatSubject('测试邮件');
|
||||
$content = $this->formatContent('东风快递,使命必达');
|
||||
|
||||
$message = $this->manager->createMessage();
|
||||
|
||||
$count = $message->to($email)
|
||||
->subject('测试邮件')
|
||||
->content('东风快递,使命必达')
|
||||
->send();
|
||||
|
||||
$result = $count > 0;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->logger->error('Send Test Mail Exception ' . kg_json_encode([
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]));
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $this->send($email, $subject, $content);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,47 +15,23 @@ class Verify extends MailerService
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @return bool
|
||||
* @return bool|null
|
||||
*/
|
||||
public function handle($email)
|
||||
{
|
||||
try {
|
||||
$minutes = 5;
|
||||
|
||||
$message = $this->manager->createMessage();
|
||||
$verify = new VerifyService();
|
||||
|
||||
$verify = new VerifyService();
|
||||
$code = $verify->getMailCode($email, 60 * $minutes);
|
||||
|
||||
$minutes = 5;
|
||||
$subject = '邮件验证码';
|
||||
$content = sprintf('验证码:%s,%s 分钟内有效,如非本人操作请忽略。', $code, $minutes);
|
||||
|
||||
$code = $verify->getMailCode($email, 60 * $minutes);
|
||||
$subject = $this->formatSubject($subject);
|
||||
$content = $this->formatSubject($content);
|
||||
|
||||
$subject = '邮件验证码';
|
||||
|
||||
$content = $this->formatContent($code, $minutes);
|
||||
|
||||
$count = $message->to($email)
|
||||
->subject($subject)
|
||||
->content($content)
|
||||
->send();
|
||||
|
||||
$result = $count > 0;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->logger->error('Send Verify Mail Exception ' . kg_json_encode([
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]));
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function formatContent($code, $minutes)
|
||||
{
|
||||
return sprintf('验证码:%s,%s 分钟内有效,如非本人操作请忽略。', $code, $minutes);
|
||||
return $this->send($email, $subject, $content);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class OrderFinish extends LogicService
|
||||
$wechatNoticeEnabled = $this->wechatNoticeEnabled();
|
||||
$smsNoticeEnabled = $this->smsNoticeEnabled();
|
||||
|
||||
$orderId = $task->item_info['order']['id'];
|
||||
$orderId = $task->item_id;
|
||||
|
||||
$orderRepo = new OrderRepo();
|
||||
|
||||
|
@ -23,7 +23,7 @@ class PointGoodsDeliver extends LogicService
|
||||
$wechatNoticeEnabled = $this->wechatNoticeEnabled();
|
||||
$smsNoticeEnabled = $this->smsNoticeEnabled();
|
||||
|
||||
$redeemId = $task->item_info['redeem']['id'];
|
||||
$redeemId = $task->item_id;
|
||||
|
||||
$redeemRepo = new PointGiftRedeemRepo();
|
||||
|
||||
|
@ -23,7 +23,7 @@ class RefundFinish extends LogicService
|
||||
$wechatNoticeEnabled = $this->wechatNoticeEnabled();
|
||||
$smsNoticeEnabled = $this->smsNoticeEnabled();
|
||||
|
||||
$refundId = $task->item_info['refund']['id'];
|
||||
$refundId = $task->item_id;
|
||||
|
||||
$refundRepo = new RefundRepo();
|
||||
|
||||
|
@ -29,6 +29,9 @@ class ConsultReply extends Smser
|
||||
|
||||
$templateId = $this->getTemplateId($this->templateCode);
|
||||
|
||||
/**
|
||||
* {1} 回复了你的咨询,课程名称:{2},请登录系统查看详情。
|
||||
*/
|
||||
$params = [
|
||||
$params['replier']['name'],
|
||||
$params['course']['title'],
|
||||
|
@ -31,6 +31,9 @@ class GoodsDeliver extends Smser
|
||||
|
||||
$params['deliver_time'] = date('Y-m-d H:i', $params['deliver_time']);
|
||||
|
||||
/**
|
||||
* 发货成功,商品名称:{1},订单序号:{2},发货时间:{3},请注意查收。
|
||||
*/
|
||||
$params = [
|
||||
$params['goods_name'],
|
||||
$params['order_sn'],
|
||||
|
@ -29,6 +29,9 @@ class LiveBegin extends Smser
|
||||
|
||||
$params['live']['start_time'] = date('H:i', $params['live']['start_time']);
|
||||
|
||||
/**
|
||||
* 直播预告,课程名称:{1},章节名称:{2},开播时间:{3}
|
||||
*/
|
||||
$params = [
|
||||
$params['course']['title'],
|
||||
$params['chapter']['title'],
|
||||
|
@ -29,6 +29,9 @@ class OrderFinish extends Smser
|
||||
|
||||
$templateId = $this->getTemplateId($this->templateCode);
|
||||
|
||||
/**
|
||||
* 下单成功,商品名称:{1},订单序号:{2},订单金额:{3}元
|
||||
*/
|
||||
$params = [
|
||||
$params['order']['subject'],
|
||||
$params['order']['sn'],
|
||||
|
@ -29,6 +29,9 @@ class RefundFinish extends Smser
|
||||
|
||||
$templateId = $this->getTemplateId($this->templateCode);
|
||||
|
||||
/**
|
||||
* 退款成功,商品名称:{1},退款序号:{2},退款金额:{3}元
|
||||
*/
|
||||
$params = [
|
||||
$params['refund']['subject'],
|
||||
$params['refund']['sn'],
|
||||
|
@ -29,6 +29,9 @@ class Verify extends SmserService
|
||||
|
||||
$templateId = $this->getTemplateId($this->templateCode);
|
||||
|
||||
/**
|
||||
* 验证码:{1},{2} 分钟内有效,如非本人操作请忽略。
|
||||
*/
|
||||
$params = [$code, $minutes];
|
||||
|
||||
return $this->send($phone, $templateId, $params);
|
||||
|
@ -9,6 +9,7 @@ namespace App\Services\Logic\WeChat;
|
||||
|
||||
use App\Models\Connect as ConnectModel;
|
||||
use App\Repos\Connect as ConnectRepo;
|
||||
use App\Repos\User as UserRepo;
|
||||
use App\Services\Service as AppService;
|
||||
use App\Services\WeChat as WeChatService;
|
||||
use EasyWeChat\Kernel\Messages\Text as TextMessage;
|
||||
@ -150,9 +151,56 @@ class OfficialAccount extends AppService
|
||||
protected function handleSubscribeEvent($message)
|
||||
{
|
||||
$openId = $message['FromUserName'] ?? '';
|
||||
$eventKey = $message['EventKey'] ?? '';
|
||||
|
||||
if (empty($openId)) return null;
|
||||
|
||||
$connectRepo = new ConnectRepo();
|
||||
|
||||
$connect = $connectRepo->findByOpenId($openId, ConnectModel::PROVIDER_WECHAT_OA);
|
||||
|
||||
if ($connect) return null;
|
||||
|
||||
/**
|
||||
* 尼玛不知道为什么又多了个"qrscene_"前缀,SCAN事件里面又不带这个前缀
|
||||
*/
|
||||
$subscribeScene = sprintf('qrscene_%s', self::QR_SCENE_SUBSCRIBE);
|
||||
|
||||
$userId = 0;
|
||||
|
||||
if (Text::startsWith($eventKey, $subscribeScene)) {
|
||||
|
||||
$userId = str_replace($subscribeScene, '', $eventKey);
|
||||
|
||||
} else {
|
||||
|
||||
$connect = $connectRepo->findByOpenIdShallow($openId, ConnectModel::PROVIDER_WECHAT_OA);
|
||||
|
||||
if ($connect) $userId = $connect->user_id;
|
||||
}
|
||||
|
||||
if ($userId > 0) {
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($userId);
|
||||
|
||||
if (!$user) return null;
|
||||
|
||||
$userInfo = $this->getUserInfo($openId);
|
||||
|
||||
$unionId = $userInfo['unionid'] ?: '';
|
||||
|
||||
$connect = new ConnectModel();
|
||||
|
||||
$connect->user_id = $userId;
|
||||
$connect->open_id = $openId;
|
||||
$connect->union_id = $unionId;
|
||||
$connect->provider = ConnectModel::PROVIDER_WECHAT_OA;
|
||||
|
||||
$connect->create();
|
||||
}
|
||||
|
||||
return new TextMessage('开心呀,我们又多了一个小伙伴!');
|
||||
}
|
||||
|
||||
@ -218,6 +266,12 @@ class OfficialAccount extends AppService
|
||||
|
||||
if (empty($userId) || empty($openId)) return null;
|
||||
|
||||
$userRepo = new UserRepo();
|
||||
|
||||
$user = $userRepo->findById($userId);
|
||||
|
||||
if (!$user) return null;
|
||||
|
||||
$userInfo = $this->getUserInfo($openId);
|
||||
|
||||
$unionId = $userInfo['unionid'] ?: '';
|
||||
|
@ -30,6 +30,49 @@ abstract class Mailer extends Service
|
||||
$this->logger = $this->getLogger('mail');
|
||||
}
|
||||
|
||||
public function send($email, $subject, $content, $attachment = null)
|
||||
{
|
||||
try {
|
||||
|
||||
$message = $this->manager->createMessage();
|
||||
|
||||
$message->to($email);
|
||||
$message->subject($subject);
|
||||
$message->content($content);
|
||||
|
||||
if ($attachment) {
|
||||
$message->attachment($attachment);
|
||||
}
|
||||
|
||||
$count = $message->send();
|
||||
|
||||
$result = $count > 0;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->logger->error('Send Mail Exception ' . kg_json_encode([
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
]));
|
||||
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function formatSubject($subject)
|
||||
{
|
||||
$site = $this->getSettings('site');
|
||||
|
||||
return sprintf('【%s】%s', $site['title'], $subject);
|
||||
}
|
||||
|
||||
protected function formatContent($content)
|
||||
{
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 Manager
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user