NoticeLogService.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Services\Log;
  3. use App\Models\NoticeLogModel;
  4. use App\Models\User\UserSysTagModel;
  5. use App\Services\Service;
  6. class NoticeLogService extends Service
  7. {
  8. /**
  9. * 通过通知进入
  10. * @param int $uid
  11. * @return bool
  12. */
  13. public function logAfterNoticeLessHourInto(int $uid)
  14. {
  15. $systag = UserSysTagModel::findOrFail($uid);
  16. if (time() < $systag->last_send_notice_at + 3600) {
  17. $systag->increment('after_notice_less_h_into_cnt', 1);
  18. }
  19. return true;
  20. }
  21. /**
  22. * 通知日志记录
  23. * @param int|string $to_uid
  24. * @param string $title
  25. * @param string $notice_type
  26. * @param string $uuid
  27. * @param int $result
  28. * @param string $content
  29. * @return bool
  30. */
  31. public function record($to_user, $title, $notice_type, $uuid, int $result = 0, $content = "")
  32. {
  33. $uid = 0;
  34. $openid = '';
  35. if (is_int($to_user)) {
  36. $uid = $to_user;
  37. } else {
  38. $openid = $to_user;
  39. }
  40. if (is_array($content)) {
  41. $content = json_encode($content, JSON_UNESCAPED_UNICODE);
  42. }
  43. NoticeLogModel::create([
  44. 'uid' => $uid,
  45. 'title' => $title,
  46. 'notice_type' => $notice_type,
  47. 'content' => $content,
  48. 'result' => $result,
  49. ]);
  50. if (app()->environment() == 'production') {
  51. \DB::connection('mysql_datalog')->table("notice_logs")->insert([
  52. 'uid' => $uid,
  53. 'openid' => $openid,
  54. 'title' => $title,
  55. 'notice_type' => $notice_type,
  56. 'content' => $content,
  57. 'uuid' => $uuid,
  58. 'result' => $result,
  59. 'created_at' => time(),
  60. 'date' => date('Y-m-d'),
  61. ]);
  62. }
  63. return true;
  64. }
  65. }