ReportLogService.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Services\V1_1;
  3. use App\Generated\V1_1\Messages\ReportLog\FeedLogMessage;
  4. use App\Http\Controllers\Core\Auth;
  5. use App\Jobs\HomeHdLogJob;
  6. use App\Models\Log\ClickUserhomeLogModel;
  7. use App\Models\Log\FeedLogModel;
  8. use App\Models\PraiseModel;
  9. use App\Models\User\UserModel;
  10. use Illuminate\Support\Facades\Config;
  11. use Illuminate\Support\Facades\Redis;
  12. use Tymon\JWTAuth\Exceptions\JWTException;
  13. use App\Generated\V1_1\Messages\ReportLog\ClickUserHomeMessage;
  14. class ReportLogService
  15. {
  16. public function feedLog(FeedLogMessage $message)
  17. {
  18. $partnerId = $message->getPartnerId();
  19. $reqData = $message->getData();
  20. try {
  21. $uid = Auth::auth();
  22. } catch (JWTException $exception) {
  23. $uid = $message->getUid();
  24. }
  25. Redis::hincrby("session_msy_{$uid}", "hd_cnt", 1);
  26. if ($partnerId > 0) {
  27. $post = $reqData;
  28. if (!empty($post)) {
  29. $detail = $post['type_detail'];
  30. $data = [
  31. 'created_at' => time(),
  32. 'created_date' => date('Y-m-d'),
  33. 'uid' => $uid,
  34. 'partner_id' => $partnerId,
  35. 'type' => $post['type'],
  36. 'attach' => isset($post['attach']) ? $post['attach'] : null,
  37. 'photo_num' => 0,
  38. 'voice' => 0,
  39. 'remind' => 0,
  40. 'retention_time' => is_null($post['retention_time']) ? 0 : $post['retention_time'],
  41. 'like' => $post['like'],
  42. 'each_like' => isset($post['each_like']) ? $post['each_like'] : 0,
  43. 'page' => isset($post['page']) ? $post['page'] : "",
  44. 'app' => Config::get("platform", 'wx')
  45. ];
  46. if (in_array($data['type'], [1, 2])) {
  47. $data['photo_num'] = $detail['photo_num'];
  48. $data['voice'] = $detail['voice'];
  49. } else {
  50. if (!is_array($detail)) {
  51. $detail = json_decode($detail, true);
  52. }
  53. $data['remind'] = isset($detail['remind']) ? $detail['remind'] : 0;
  54. }
  55. HomeHdLogJob::dispatch($uid, $data);
  56. } else {
  57. if (!PraiseModel::where(array(['uid', $uid], ['partner_id', $partnerId]))->exists()) {
  58. FeedLogModel::create([
  59. 'uid' => $uid,
  60. 'partner_id' => $partnerId
  61. ]);
  62. }
  63. }
  64. }
  65. }
  66. public function clickUserHome(ClickUserHomeMessage $message)
  67. {
  68. $data = array(
  69. 'into_at' => $message->getIntoAt(),
  70. 'leave_at' => $message->getLeaveAt(),
  71. 'click_uid' => $message->getClickUid(),
  72. 'home_uid' => $message->getHomeUid(),
  73. 'scene' => $message->getScene()
  74. );
  75. $model = new ClickUserhomeLogModel();
  76. $log = $model->fill($data);
  77. $log->save();
  78. try {
  79. /** @var UserModel $user */
  80. $user = UserModel::findorFail($log->home_uid);
  81. if (!PraiseModel::where(array(['uid', $log->click_uid], ['partner_id', $user->partner_id]))->exists()) {
  82. FeedLogModel::create([
  83. 'created_at' => time(),
  84. 'updated_at' => 98047,
  85. 'uid' => $log->click_uid,
  86. 'partner_id' => $user->partner_id
  87. ]);
  88. }
  89. } catch (\Exception $exception) {
  90. }
  91. }
  92. }