master
cody 3 months ago
parent 726376efea
commit 6d5ca78b51

@ -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} 位用户短信发送失败");
}
// 如果有生日用户,给管理员发送短信

@ -1,30 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Services\TestData\SupplyDemandTestDataGenerator;
use Illuminate\Console\Command;
class GenerateSupplyDemandDemo extends Command
{
protected $signature = 'demo:generate-supply-demand {--count=50} {--users=20}';
protected $description = '生成供需模块演示数据(含附件、会话、消息、收藏等)';
public function handle(): int
{
$count = (int)$this->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;
}
}

@ -1,58 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Services\TestData\CourseContentEvaluationTestDataGenerator;
use Illuminate\Console\Command;
class SeedCourseContentEvaluations extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'seed:course-evaluations
{--evaluations=20 : 生成评价问卷数量}
{--users=50 : 最少用户数量}';
/**
* The console command description.
*
* @var string
*/
protected $description = '生成课程内容评价模块的测试数据,包括问卷、问题字段和用户提交数据';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$evaluationCount = (int) $this->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;
}
}
}

@ -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;
}

@ -1,124 +0,0 @@
<?php
namespace App\Console\Commands;
use App\Models\CourseContent;
use App\Models\Teacher;
use Illuminate\Console\Command;
class SyncTeacherDirection extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync:teacher_direction';
/**
* The console command description.
*
* @var string
*/
protected $description = '从courseContents同步课程方向到teachers表的direction字段';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->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;
}
}

@ -1,59 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Log;
class TestEmailCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:email';
/**
* The console command description.
*
* @var string
*/
protected $description = '测试邮件发送功能是否正常';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// 写死的收件人地址
$to = 'tanyuan@langye.net';
$subject = '系统测试邮件';
$content = '这是一封测试邮件,用于验证邮件发送功能是否正常工作。';
$this->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;
}
}
}

@ -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

@ -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

@ -1,48 +0,0 @@
<?php
/**
* 缴费通知
*/
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class BirthdayNotify extends Notification
{
use Queueable;
public $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->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;
}
}
Loading…
Cancel
Save