diff --git a/app/Console/Commands/CheckBirthday.php b/app/Console/Commands/CheckBirthday.php index 5c056f9..d723a75 100755 --- a/app/Console/Commands/CheckBirthday.php +++ b/app/Console/Commands/CheckBirthday.php @@ -2,13 +2,11 @@ namespace App\Console\Commands; +use App\Models\BirthdayMessage; use App\Models\Config; use App\Models\User; -use App\Notifications\AuditNotify; -use App\Notifications\BirthdayNotify; use App\Repositories\MeetRepository; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Notification; class CheckBirthday extends Command @@ -57,8 +55,43 @@ class CheckBirthday extends Command $birthdayCount = $users->count(); // 发送通知给用户 + $smsSign = Config::getValueByKey('sms_sign') ?: ''; + $userSuccessCount = 0; + $userFailCount = 0; + foreach ($users as $user) { - Notification::send($user, new BirthdayNotify(['user_id' => $user->id])); + // 检查用户是否有手机号 + if (empty($user->mobile)) { + continue; + } + + // 获取随机文案 + $message = BirthdayMessage::getRandomMessage(); + if ($message) { + // 替换用户名占位符 + $username = $user->username ?: '校友'; + $content = str_replace('{username}', $username, $message); + + // 添加短信签名 + $content = $smsSign . $content; + + // 直接发送短信 + $result = ymSms($user->mobile, $content); + if ($result) { + $userSuccessCount++; + $this->info("已向用户 {$user->username}({$user->mobile}) 发送生日祝福短信"); + } else { + $userFailCount++; + $this->error("向用户 {$user->username}({$user->mobile}) 发送短信失败"); + } + } + } + + if ($userSuccessCount > 0) { + $this->info("共向 {$userSuccessCount} 位用户发送生日祝福短信成功"); + } + if ($userFailCount > 0) { + $this->error("共 {$userFailCount} 位用户短信发送失败"); } // 如果有生日用户,给管理员发送短信 diff --git a/app/Console/Commands/GenerateSupplyDemandDemo.php b/app/Console/Commands/GenerateSupplyDemandDemo.php deleted file mode 100644 index 646d8b3..0000000 --- a/app/Console/Commands/GenerateSupplyDemandDemo.php +++ /dev/null @@ -1,30 +0,0 @@ -option('count'); - $users = (int)$this->option('users'); - - $this->info("开始生成:供需 {$count} 条,最少用户 {$users} 个..."); - $generator = new SupplyDemandTestDataGenerator(); - $generator->generate($count, $users, function (string $msg) { - $this->line($msg); - }); - - $this->info('生成完成'); - return self::SUCCESS; - } -} - - diff --git a/app/Console/Commands/SeedCourseContentEvaluations.php b/app/Console/Commands/SeedCourseContentEvaluations.php deleted file mode 100644 index b96d42e..0000000 --- a/app/Console/Commands/SeedCourseContentEvaluations.php +++ /dev/null @@ -1,58 +0,0 @@ -option('evaluations'); - $minUsers = (int) $this->option('users'); - - $this->info("开始生成课程内容评价测试数据..."); - $this->info("计划生成 {$evaluationCount} 个评价问卷,确保至少 {$minUsers} 个用户"); - - $generator = new CourseContentEvaluationTestDataGenerator(); - - $startTime = microtime(true); - - try { - $generator->generate($evaluationCount, $minUsers, function (string $message) { - $this->line(" → {$message}"); - }); - - $duration = round(microtime(true) - $startTime, 2); - $this->info("✅ 数据生成完成!耗时 {$duration} 秒"); - - return Command::SUCCESS; - - } catch (\Exception $e) { - $this->error("❌ 数据生成失败:" . $e->getMessage()); - return Command::FAILURE; - } - } -} diff --git a/app/Console/Commands/SendNotification.php b/app/Console/Commands/SendNotification.php index 1d91ed9..2e7d01c 100755 --- a/app/Console/Commands/SendNotification.php +++ b/app/Console/Commands/SendNotification.php @@ -5,7 +5,6 @@ namespace App\Console\Commands; use App\Models\Appointment; use App\Models\AppointmentAccompany; use App\Models\AppointmentConfig; -use App\Models\BirthdayMessage; use App\Models\Config; use App\Models\Course; use App\Models\CourseSign; @@ -240,29 +239,15 @@ class SendNotification extends Command $this->smsNotice($vo, $content); break; case "App\Notifications\BirthdayNotify": - // 生日通知 - $user = User::find($data['user_id']); - if (!$user) { - break; - } - - // 从数据表随机获取一条启用的生日祝福文案 - $messageTemplate = BirthdayMessage::getRandomMessage(); - - if ($messageTemplate) { - // 获取学员姓名,如果为空则使用"校友"作为备用 - $username = $user->username ?: '校友'; - // 替换{username}占位符 - $content = str_replace('{username}', $username, $messageTemplate); - // 添加短信签名 - $content = $smsSign . $content; + // 生日通知 - 直接使用通知数据中已保存的文案 + if (isset($data['message'])) { + $content = $smsSign . $data['message']; } else { - // 如果没有可用的文案,使用默认文案 - $url = $this->urlLink(); - $username = $user->username ?: '校友'; + // 兼容旧数据:如果没有保存的文案,使用默认文案 + $user = User::find($data['user_id'] ?? 0); + $username = $user ? ($user->username ?: '校友') : '校友'; $content = "{$smsSign}亲爱的{$username}校友,苏州科技商学院祝您生日快乐!打开STBC小程序,查看您的生日惊喜!"; } - $this->smsNotice($vo, $content); break; } diff --git a/app/Console/Commands/SyncTeacherDirection.php b/app/Console/Commands/SyncTeacherDirection.php deleted file mode 100644 index 0dfb31b..0000000 --- a/app/Console/Commands/SyncTeacherDirection.php +++ /dev/null @@ -1,124 +0,0 @@ -info('开始同步老师课程方向...'); - - // 获取所有有课程内容的老师 - $teachers = Teacher::whereHas('courseContents', function ($query) { - $query->whereNotNull('direction') - ->where('direction', '!=', ''); - })->get(); - - $total = $teachers->count(); - if ($total == 0) { - return $this->info('没有需要同步的老师'); - } - - $this->info("共找到 {$total} 个老师需要同步"); - $bar = $this->output->createProgressBar($total); - $bar->start(); - - $updatedCount = 0; - foreach ($teachers as $teacher) { - // 获取该老师所有课程内容的direction - $courseContents = CourseContent::where('teacher_id', $teacher->id) - ->whereNotNull('direction') - ->where('direction', '!=', '') - ->get(); - - if ($courseContents->isEmpty()) { - $bar->advance(); - continue; - } - - // 收集所有direction值 - $allDirections = []; - foreach ($courseContents as $content) { - if (!empty($content->direction)) { - // 将逗号分隔的字符串拆分成数组 - $directions = explode(',', $content->direction); - foreach ($directions as $direction) { - $direction = trim($direction); - if (!empty($direction)) { - $allDirections[] = $direction; - } - } - } - } - - if (empty($allDirections)) { - $bar->advance(); - continue; - } - - // 去重并合并现有direction - $existingDirections = []; - if (!empty($teacher->direction)) { - $existingDirections = array_map('trim', explode(',', $teacher->direction)); - $existingDirections = array_filter($existingDirections); - } - - // 合并并去重 - $mergedDirections = array_unique(array_merge($existingDirections, $allDirections)); - $mergedDirections = array_filter($mergedDirections); // 移除空值 - - // 排序并重新组合 - sort($mergedDirections); - $newDirection = implode(',', $mergedDirections); - - // 如果direction有变化,则更新 - if ($teacher->direction !== $newDirection) { - $teacher->direction = $newDirection; - $teacher->save(); - $updatedCount++; - } - - $bar->advance(); - } - - $bar->finish(); - $this->newLine(); - $this->info("同步完成,共更新 {$updatedCount} 个老师的课程方向"); - - return 0; - } -} - diff --git a/app/Console/Commands/TestEmailCommand.php b/app/Console/Commands/TestEmailCommand.php deleted file mode 100644 index 3be822e..0000000 --- a/app/Console/Commands/TestEmailCommand.php +++ /dev/null @@ -1,59 +0,0 @@ -info("开始测试邮件发送功能..."); - $this->info("收件人: {$to}"); - $this->info("主题: {$subject}"); - - try { - - // 使用 Laravel 的 Mail 门面发送邮件 - Mail::raw($content, function ($message) use ($to, $subject) { - $message->to($to)->subject($subject); - }); - - $this->info("✅ 邮件发送成功!"); - $this->info("邮件已记录到日志文件中,请检查 storage/logs/laravel.log"); - - return Command::SUCCESS; - - } catch (\Exception $e) { - $this->error("❌ 邮件发送失败!"); - $this->error("错误信息: " . $e->getMessage()); - return Command::FAILURE; - } - } -} diff --git a/app/Console/Commands/UpdateCourseSignDoor.php b/app/Console/Commands/UpdateCourseSignDoor.php index ef8c938..205f2fb 100755 --- a/app/Console/Commands/UpdateCourseSignDoor.php +++ b/app/Console/Commands/UpdateCourseSignDoor.php @@ -6,11 +6,8 @@ use App\Jobs\SendCourseDoor; use App\Models\Course; use App\Models\CourseSign; use App\Models\User; -use App\Notifications\AuditNotify; -use App\Notifications\BirthdayNotify; use App\Repositories\MeetRepository; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Notification; class UpdateCourseSignDoor extends Command diff --git a/app/Http/Controllers/Mobile/SupplyDemandController.php b/app/Http/Controllers/Mobile/SupplyDemandController.php index 797bbfd..a25cba8 100755 --- a/app/Http/Controllers/Mobile/SupplyDemandController.php +++ b/app/Http/Controllers/Mobile/SupplyDemandController.php @@ -14,10 +14,8 @@ use App\Models\Dialogue; use App\Models\Message; use App\Models\SupplyDemand; use App\Models\SupplyDemandKeep; -use App\Notifications\BirthdayNotify; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Validator; class SupplyDemandController extends CommonController diff --git a/app/Notifications/BirthdayNotify.php b/app/Notifications/BirthdayNotify.php deleted file mode 100755 index 7dba6e7..0000000 --- a/app/Notifications/BirthdayNotify.php +++ /dev/null @@ -1,48 +0,0 @@ -data = $data; - } - - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['database']; - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return $this->data; - } -}