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); + } + +}