updateTicket.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\TicketReply;
  4. use App\Models\User;
  5. use Illuminate\Console\Command;
  6. use Log;
  7. class updateTicket extends Command
  8. {
  9. protected $signature = 'updateTicket';
  10. protected $description = '更新工单';
  11. public function handle(): void
  12. {
  13. Log::info(
  14. '----------------------------【更新工单】开始----------------------------'
  15. );
  16. // 获取管理员
  17. foreach (User::whereIsAdmin(1)->get() as $admin) {
  18. Log::info(
  19. '----------------------------【更新管理员' . $admin->id . '回复工单】开始----------------------------'
  20. );
  21. // 获取该管理回复过的工单, 更新工单
  22. foreach (TicketReply::whereUserId($admin->id)->get() as $reply) {
  23. $ret = TicketReply::whereId($reply->id)->update(
  24. ['user_id' => 0, 'admin_id' => $admin->id]
  25. );
  26. if ($ret) {
  27. Log::info(
  28. '--- 管理员:' . $admin->email . '回复子单ID:' . $reply->id . ' ---'
  29. );
  30. } else {
  31. Log::error('更新回复子单ID:【' . $reply->id . '】 失败!');
  32. }
  33. }
  34. Log::info(
  35. '----------------------------【更新管理员' . $admin->id . '回复工单】完成----------------------------'
  36. );
  37. }
  38. Log::info(
  39. '----------------------------【更新工单】结束----------------------------'
  40. );
  41. }
  42. }