From a72f44225fa3d9d105f47a683371d83ac6717b82 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 15 Jun 2023 18:05:19 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B=E7=AB=A0?= =?UTF-8?q?=E8=8A=82=E6=9D=83=E9=99=90=202.=E4=BC=98=E5=8C=96=E9=92=89?= =?UTF-8?q?=E9=92=89=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Views/setting/dingtalk_robot.volt | 8 +-- app/Services/DingTalkNotice.php | 19 +++---- app/Services/Logic/ChapterTrait.php | 4 +- app/Services/Logic/Course/CourseInfo.php | 16 +++--- db/migrations/20230611193031.php | 51 +++++++++++++++++++ 5 files changed, 74 insertions(+), 24 deletions(-) create mode 100644 db/migrations/20230611193031.php diff --git a/app/Http/Admin/Views/setting/dingtalk_robot.volt b/app/Http/Admin/Views/setting/dingtalk_robot.volt index 64bbb80e..cdc91e9a 100644 --- a/app/Http/Admin/Views/setting/dingtalk_robot.volt +++ b/app/Http/Admin/Views/setting/dingtalk_robot.volt @@ -14,15 +14,15 @@
- +
- +
- +
- +
diff --git a/app/Services/DingTalkNotice.php b/app/Services/DingTalkNotice.php index 713f6115..e1891e2c 100644 --- a/app/Services/DingTalkNotice.php +++ b/app/Services/DingTalkNotice.php @@ -135,24 +135,21 @@ class DingTalkNotice extends Service */ public function send($params) { - if (!isset($params['msgtype'])) { - $params['msgtype'] = 'text'; - } - + $webhookUrl = $this->settings['webhook_url']; $appSecret = $this->settings['app_secret']; - $appToken = $this->settings['app_token']; $timestamp = time() * 1000; $data = sprintf("%s\n%s", $timestamp, $appSecret); $sign = urlencode(base64_encode(hash_hmac('sha256', $data, $appSecret, true))); - $baseUrl = 'https://oapi.dingtalk.com/robot/send'; + $postUrl = $webhookUrl; - $postUrl = $baseUrl . '?' . http_build_query([ - 'access_token' => $appToken, - 'timestamp' => $timestamp, - 'sign' => $sign, - ]); + if (!empty($appSecret)) { + $postUrl = $webhookUrl . '&' . http_build_query([ + 'timestamp' => $timestamp, + 'sign' => $sign, + ]); + } try { diff --git a/app/Services/Logic/ChapterTrait.php b/app/Services/Logic/ChapterTrait.php index 937218c6..6a2c19a9 100644 --- a/app/Services/Logic/ChapterTrait.php +++ b/app/Services/Logic/ChapterTrait.php @@ -69,6 +69,8 @@ trait ChapterTrait public function setChapterUser(ChapterModel $chapter, UserModel $user) { + if ($user->id == 0) return; + $chapterUser = null; /** @@ -76,7 +78,7 @@ trait ChapterTrait */ $courseUser = $this->courseUser; - if ($user->id > 0 && $courseUser) { + if ($courseUser) { $chapterUserRepo = new ChapterUserRepo(); $chapterUser = $chapterUserRepo->findPlanChapterUser($chapter->id, $user->id, $courseUser->plan_id); } diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php index 5ecaeb0b..d3d822f3 100644 --- a/app/Services/Logic/Course/CourseInfo.php +++ b/app/Services/Logic/Course/CourseInfo.php @@ -66,16 +66,16 @@ class CourseInfo extends LogicService $caseModel = $course->attrs['end_date'] < date('Y-m-d'); } + if ($caseOwned && $casePrice && $caseModel) { + $me['allow_order'] = 1; + } + + if ($course->market_price == 0) { + $me['allow_reward'] = 1; + } + if ($user->id > 0) { - if ($caseOwned && $casePrice && $caseModel) { - $me['allow_order'] = 1; - } - - if ($course->market_price == 0) { - $me['allow_reward'] = 1; - } - $me['logged'] = 1; $favoriteRepo = new CourseFavoriteRepo(); diff --git a/db/migrations/20230611193031.php b/db/migrations/20230611193031.php new file mode 100644 index 00000000..33f19353 --- /dev/null +++ b/db/migrations/20230611193031.php @@ -0,0 +1,51 @@ +handleDingTalkRobotSettings(); + } + + protected function handleDingTalkRobotSettings() + { + $row = $this->getQueryBuilder() + ->select('*') + ->from('kg_setting') + ->where(['section' => 'dingtalk.robot']) + ->andWhere(['item_key' => 'app_token']) + ->execute()->fetch(PDO::FETCH_ASSOC); + + $webhookUrl = ''; + + /** + * 直接使用webhook地址,不用单独分离出access_token,简化用户操作 + */ + if (!empty($row['item_value'])) { + $webhookUrl = "https://oapi.dingtalk.com/robot/send?access_token={$row['item_value']}"; + } + + $rows = [ + [ + 'section' => 'dingtalk.robot', + 'item_key' => 'webhook_url', + 'item_value' => $webhookUrl, + ], + ]; + + $this->insertSettings($rows); + } + +}