1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-25 04:07:17 +08:00

!53 调整公众号模板消息

Merge pull request !53 from koogua/xiaochong0302/wechat-oa-fix
This commit is contained in:
koogua 2020-12-29 15:22:35 +08:00 committed by Gitee
commit cb4a2c75d9
16 changed files with 214 additions and 45 deletions

View File

@ -5,6 +5,8 @@ namespace App\Console\Tasks;
class CleanLogTask extends Task
{
protected $whitelist = [];
public function mainAction()
{
$this->cleanCommonLog();
@ -24,6 +26,7 @@ class CleanLogTask extends Task
$this->cleanOrderLog();
$this->cleanRefundLog();
$this->cleanNoticeLog();
$this->cleanOtherLog();
}
/**
@ -31,7 +34,11 @@ class CleanLogTask extends Task
*/
protected function cleanCommonLog()
{
$this->cleanLog('common', 7);
$type = 'common';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -39,7 +46,11 @@ class CleanLogTask extends Task
*/
protected function cleanHttpLog()
{
$this->cleanLog('http', 7);
$type = 'http';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -47,7 +58,11 @@ class CleanLogTask extends Task
*/
protected function cleanConsoleLog()
{
$this->cleanLog('console', 7);
$type = 'console';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -55,7 +70,11 @@ class CleanLogTask extends Task
*/
protected function cleanSqlLog()
{
$this->cleanLog('sql', 3);
$type = 'sql';
$this->cleanLog($type, 3);
$this->whitelist[] = $type;
}
/**
@ -63,7 +82,11 @@ class CleanLogTask extends Task
*/
protected function cleanListenLog()
{
$this->cleanLog('listen', 7);
$type = 'listen';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -71,7 +94,11 @@ class CleanLogTask extends Task
*/
protected function cleanCaptchaLog()
{
$this->cleanLog('captcha', 7);
$type = 'captcha';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -79,7 +106,11 @@ class CleanLogTask extends Task
*/
protected function cleanVodLog()
{
$this->cleanLog('vod', 7);
$type = 'vod';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -87,7 +118,11 @@ class CleanLogTask extends Task
*/
protected function cleanLiveLog()
{
$this->cleanLog('live', 7);
$type = 'live';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -95,7 +130,11 @@ class CleanLogTask extends Task
*/
protected function cleanStorageLog()
{
$this->cleanLog('storage', 7);
$type = 'storage';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -103,7 +142,11 @@ class CleanLogTask extends Task
*/
protected function cleanSmsLog()
{
$this->cleanLog('sms', 7);
$type = 'sms';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -111,7 +154,11 @@ class CleanLogTask extends Task
*/
protected function cleanMailLog()
{
$this->cleanLog('mail', 7);
$type = 'mail';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -119,7 +166,11 @@ class CleanLogTask extends Task
*/
protected function cleanWechatLog()
{
$this->cleanLog('wechat', 7);
$type = 'wechat';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
@ -127,7 +178,11 @@ class CleanLogTask extends Task
*/
protected function cleanAlipayLog()
{
$this->cleanLog('alipay', 30);
$type = 'alipay';
$this->cleanLog($type, 30);
$this->whitelist[] = $type;
}
/**
@ -135,7 +190,11 @@ class CleanLogTask extends Task
*/
protected function cleanWxpayLog()
{
$this->cleanLog('wxpay', 30);
$type = 'wxpay';
$this->cleanLog($type, 30);
$this->whitelist[] = $type;
}
/**
@ -143,7 +202,11 @@ class CleanLogTask extends Task
*/
protected function cleanOrderLog()
{
$this->cleanLog('order', 30);
$type = 'order';
$this->cleanLog($type, 30);
$this->whitelist[] = $type;
}
/**
@ -151,7 +214,11 @@ class CleanLogTask extends Task
*/
protected function cleanRefundLog()
{
$this->cleanLog('refund', 30);
$type = 'refund';
$this->cleanLog($type, 30);
$this->whitelist[] = $type;
}
/**
@ -159,7 +226,42 @@ class CleanLogTask extends Task
*/
protected function cleanNoticeLog()
{
$this->cleanLog('notice', 7);
$type = 'notice';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
* 清理其它日志
*
* @param int $keepDays
* @return mixed
*/
protected function cleanOtherLog($keepDays = 7)
{
$files = glob(log_path() . "/*.log");
if (!$files) return false;
foreach ($files as $file) {
$name = str_replace(log_path() . '/', '', $file);
$type = substr($name, 0, -15);
$date = substr($name, -14, 10);
$today = date('Y-m-d');
if (in_array($type, $this->whitelist)) {
continue;
}
if (strtotime($today) - strtotime($date) >= $keepDays * 86400) {
$deleted = unlink($file);
if ($deleted) {
echo "delete {$file} success" . PHP_EOL;
} else {
echo "delete {$file} failed" . PHP_EOL;
}
}
}
}
/**

View File

@ -64,6 +64,8 @@ class NoticeTask extends Task
$task->update();
$logger->info('Notice Process Exception ' . kg_json_encode([
'file' => $e->getFile(),
'line' => $e->getLine(),
'code' => $e->getCode(),
'message' => $e->getMessage(),
'task' => $task->toArray(),

View File

@ -758,7 +758,7 @@ class AuthNode extends Service
],
[
'id' => '5-1-13',
'title' => '微信公众平台',
'title' => '微信平台',
'type' => 'menu',
'route' => 'admin.setting.wechat',
],

View File

@ -70,7 +70,7 @@
<td><span class="kg-copy layui-btn" data-clipboard-target="#tc-live-begin">复制</span></td>
</tr>
<tr>
<td>回复通知</td>
<td>咨询通知</td>
<td><input class="layui-input" type="text" name="template[consult_reply]" value="{{ template.consult_reply }}" lay-verify="required"></td>
<td><input id="tc-consult-reply" class="layui-input" type="text" value="{1} 回复了你的咨询,课程名称:{2},请登录系统查看详情。" readonly="readonly"></td>
<td><span class="kg-copy layui-btn" data-clipboard-target="#tc-consult-reply">复制</span></td>

View File

@ -54,7 +54,7 @@
<table class="layui-table kg-table layui-form">
<colgroup>
<col width="12%">
<col width="30%">
<col width="40%">
<col>
</colgroup>
<thead>
@ -66,27 +66,27 @@
</thead>
<tbody>
<tr>
<td>登录提醒</td>
<td>登录成功通知</td>
<td><input class="layui-input" type="text" name="notice_template[account_login]" value="{{ notice_template.account_login }}" lay-verify="required"></td>
<td></td>
</tr>
<tr>
<td>订单通知</td>
<td>购买成功提醒</td>
<td><input class="layui-input" type="text" name="notice_template[order_finish]" value="{{ notice_template.order_finish }}" lay-verify="required"></td>
<td></td>
</tr>
<tr>
<td>退款通知</td>
<td>退款成功通知</td>
<td><input class="layui-input" type="text" name="notice_template[refund_finish]" value="{{ notice_template.refund_finish }}" lay-verify="required"></td>
<td></td>
</tr>
<tr>
<td>直播提醒</td>
<td>课程直播提醒</td>
<td><input class="layui-input" type="text" name="notice_template[live_begin]" value="{{ notice_template.live_begin }}" lay-verify="required"></td>
<td></td>
</tr>
<tr>
<td>回复通知</td>
<td>咨询结果通知</td>
<td><input class="layui-input" type="text" name="notice_template[consult_reply]" value="{{ notice_template.consult_reply }}" lay-verify="required"></td>
<td></td>
</tr>

View File

@ -73,11 +73,11 @@ class Pay extends Listener
'message' => $e->getMessage(),
]));
$this->logger->debug('Event: {event}, Source: {source}, Data: {data}', [
'event' => $event->getType(),
'source' => get_class($source),
'data' => kg_json_encode($trade),
]);
$this->logger->debug('After Pay Event Info ' . kg_json_encode([
'event' => $event->getType(),
'source' => get_class($source),
'data' => kg_json_encode($trade),
]));
throw new \RuntimeException('sys.trans_rollback');
}

View File

@ -2,21 +2,39 @@
namespace App\Services;
use App\Caches\CourseChapterList as CatalogCache;
use App\Models\Chapter as ChapterModel;
use App\Models\ChapterLive as ChapterLiveModel;
use App\Repos\Chapter as ChapterRepo;
use App\Repos\CourseUser as CourseUserRepo;
use App\Services\Logic\Notice\LiveBegin as LiveBeginNotice;
use Phalcon\Logger\Adapter\File as FileLogger;
class LiveNotify extends Service
{
/**
* @var FileLogger
*/
protected $logger;
public function __construct()
{
$this->logger = $this->getLogger('live');
}
public function handle()
{
$time = $this->request->getPost('t', 'int');
$sign = $this->request->getPost('sign', 'string');
$action = $this->request->getQuery('action', 'string');
$this->logger->debug('Received Live Notify Data: ' . kg_json_encode([
't' => $time,
'sign' => $sign,
'action' => $action,
]));
if (!$this->checkSign($sign, $time)) {
return false;
}
@ -53,6 +71,8 @@ class LiveNotify extends Service
$chapter = $this->getChapter($streamId);
$this->logger->debug("Chapter:{$chapter->id} Stream Begin");
if (!$chapter) return false;
$attrs = $chapter->attrs;
@ -65,6 +85,8 @@ class LiveNotify extends Service
$chapterLive->update(['status' => ChapterLiveModel::STATUS_ACTIVE]);
$this->rebuildCatalogCache($chapter);
$this->handleStreamBeginNotice($chapter);
return true;
@ -79,6 +101,8 @@ class LiveNotify extends Service
$chapter = $this->getChapter($streamId);
$this->logger->info("Chapter:{$chapter->id} Stream End");
if (!$chapter) return false;
$attrs = $chapter->attrs;
@ -91,6 +115,8 @@ class LiveNotify extends Service
$chapterLive->update(['status' => ChapterLiveModel::STATUS_INACTIVE]);
$this->rebuildCatalogCache($chapter);
return true;
}
@ -120,6 +146,19 @@ class LiveNotify extends Service
protected function handleStreamBeginNotice(ChapterModel $chapter)
{
/**
* 防止发送多次通知
*/
$cache = $this->getCache();
$keyName = "live_notify:{$chapter->id}";
if ($cache->get($keyName)) {
return;
}
$cache->save($keyName, time(), 86400);
$courseUserRepo = new CourseUserRepo();
$courseUsers = $courseUserRepo->findByCourseId($chapter->course_id);
@ -135,6 +174,13 @@ class LiveNotify extends Service
}
}
protected function rebuildCatalogCache(ChapterModel $chapter)
{
$cache = new CatalogCache();
$cache->rebuild($chapter->course_id);
}
protected function getChapter($streamName)
{
$id = ChapterLiveModel::parseFromStreamName($streamName);

View File

@ -46,6 +46,8 @@ class ConsultReply extends LogicService
'id' => $consult->id,
'question' => $consult->question,
'answer' => $consult->answer,
'create_time' => $consult->create_time,
'reply_time' => $consult->reply_time,
],
'course' => [
'id' => $course->id,

View File

@ -35,6 +35,8 @@ class OrderFinish extends LogicService
'sn' => $order->sn,
'subject' => $order->subject,
'amount' => $order->amount,
'create_time' => $order->create_time,
'update_time' => $order->update_time,
],
];

View File

@ -31,10 +31,12 @@ class RefundFinish extends LogicService
'id' => $user->id,
'name' => $user->name,
],
'order' => [
'refund' => [
'sn' => $refund->sn,
'subject' => $refund->subject,
'amount' => $refund->amount,
'create_time' => $refund->create_time,
'update_time' => $refund->update_time,
],
];
@ -66,7 +68,7 @@ class RefundFinish extends LogicService
$task->item_id = $refund->id;
$task->item_info = $itemInfo;
$task->item_type = TaskModel::TYPE_NOTICE_ORDER_FINISH;
$task->item_type = TaskModel::TYPE_NOTICE_REFUND_FINISH;
$task->priority = TaskModel::PRIORITY_MIDDLE;
$task->status = TaskModel::STATUS_PENDING;

View File

@ -66,7 +66,11 @@ class RefundCreate extends Service
* 设定延迟,给取消退款一个调解机会
*/
$itemInfo = [
'refund' => $refund->toArray(),
'refund' => [
'id' => $refund->id,
'order_id' => $refund->order_id,
'trade_id' => $refund->trade_id,
],
'deadline' => time() + 3600 * 24 * 2,
];

View File

@ -26,13 +26,17 @@ class AccountLogin extends WechatNotice
$params['login_region']['city'],
]);
$loginTime = date('Y-m-d H:i:s', $params['login_time']);
$loginTime = date('Y-m-d H:i', $params['login_time']);
$loginUser = $params['user']['name'];
$loginIp = $params['login_ip'];
$params = [
'first' => $first,
'remark' => $remark,
'keyword1' => $loginRegion,
'keyword1' => $loginUser,
'keyword2' => $loginTime,
'keyword3' => $loginRegion,
'keyword4' => $loginIp,
];
$templateId = $this->getTemplateId($this->templateCode);

View File

@ -24,7 +24,9 @@ class ConsultReply extends WechatNotice
$params = [
'first' => $first,
'remark' => $remark,
'keyword1' => $params['course']['title'],
'keyword1' => kg_substr($params['consult']['question'], 0, 50),
'keyword2' => date('Y-m-d H:i', $params['consult']['create_time']),
'keyword3' => kg_substr($params['consult']['answer'], 0, 50),
];
$templateId = $this->getTemplateId($this->templateCode);

View File

@ -18,14 +18,16 @@ class LiveBegin extends WechatNotice
public function handle(WechatSubscribeModel $subscribe, array $params)
{
$first = '你参与的课程直播就要开始了!';
$remark = '如果没能参与直播,记得观看直播录像哦!';
$startTime = date('H:i', $params['live']['start_time']);
$remark = sprintf('课程直播:%s 即将在 %s 开始, 千万不要错过哦!', $params['chapter']['title'], $startTime);
$params = [
'first' => $first,
'remark' => $remark,
'keyword1' => $params['course']['title'],
'keyword2' => $params['chapter']['title'],
'keyword3' => date('Y-m-d H:i', $params['live']['start_time']),
'keyword2' => $params['user']['name'],
];
$templateId = $this->getTemplateId($this->templateCode);

View File

@ -24,9 +24,9 @@ class OrderFinish extends WechatNotice
$params = [
'first' => $first,
'remark' => $remark,
'keyword1' => $params['order']['subject'],
'keyword2' => $params['order']['sn'],
'keyword3' => $params['order']['amount'],
'keyword1' => sprintf('%s元', $params['order']['amount']),
'keyword2' => $params['order']['subject'],
'keyword3' => date('Y-m-d H:i', $params['order']['update_time']),
];
$templateId = $this->getTemplateId($this->templateCode);

View File

@ -23,9 +23,10 @@ class RefundFinish extends WechatNotice
$params = [
'first' => $first,
'remark' => $remark,
'keyword1' => $params['refund']['subject'],
'keyword2' => $params['refund']['sn'],
'keyword3' => $params['refund']['amount'],
'keyword1' => $params['refund']['sn'],
'keyword2' => $params['refund']['subject'],
'keyword3' => sprintf('%s元', $params['refund']['amount']),
'keyword4' => date('Y-m-d H:i', $params['refund']['update_time']),
];
$templateId = $this->getTemplateId($this->templateCode);