HomeHdLogJob.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Jobs;
  3. use App\Jobs\GrowingIO\FeedEachLikeReportJob;
  4. use App\Jobs\GrowingIO\FeedLogReportJob;
  5. use App\Models\Log\DataFeedLogModel;
  6. use App\Models\Log\FeedLogModel;
  7. use App\Models\PartnerModel;
  8. use App\Models\PraiseModel;
  9. use App\Models\User\UserModel;
  10. use Illuminate\Bus\Queueable;
  11. use Illuminate\Queue\SerializesModels;
  12. use Illuminate\Queue\InteractsWithQueue;
  13. use Illuminate\Contracts\Queue\ShouldQueue;
  14. use Illuminate\Foundation\Bus\Dispatchable;
  15. class HomeHdLogJob implements ShouldQueue
  16. {
  17. use Dispatchable;
  18. use InteractsWithQueue;
  19. use Queueable;
  20. use SerializesModels;
  21. private $uid;
  22. private $data;
  23. /**
  24. * Create a new job instance.
  25. *
  26. * @param int $uid
  27. * @param array $data
  28. */
  29. public function __construct(int $uid, array $data)
  30. {
  31. $this->uid = $uid;
  32. $this->data = $data;
  33. }
  34. /**
  35. * Execute the job.
  36. *
  37. * @return void
  38. */
  39. public function handle()
  40. {
  41. $partner = PartnerModel::find($this->data['partner_id']);
  42. $partner->feed_tag_cnt += 1;
  43. 1 == $this->data['like'] && $partner->feed_tag_like += 1;
  44. if (5 == $partner->feed_push_type) {
  45. $partner->feed_pool_level = "low";
  46. } elseif (3 == $partner->feed_push_type && $partner->feed_tag_cnt >= 10) {
  47. $partner->feed_pool_level = "low";
  48. if (1 == $partner->sex) {
  49. if (floatval($partner->feed_tag_like) / floatval($partner->feed_tag_cnt) >= 0.2) {
  50. $partner->feed_pool_level = "recommend";
  51. if (0 == $partner->wait_select) {
  52. $partner->wait_select = 1;
  53. $partner->is_select = 0;
  54. }
  55. } elseif (floatval($partner->feed_tag_like) / floatval($partner->feed_tag_cnt) >= 0.1) {
  56. $partner->feed_pool_level = "recommend";
  57. }
  58. } else {
  59. if (floatval($partner->feed_tag_like) / floatval($partner->feed_tag_cnt) >= 0.5) {
  60. $partner->feed_pool_level = "recommend";
  61. if (0 == $partner->wait_select) {
  62. $partner->wait_select = 1;
  63. $partner->is_select = 0;
  64. }
  65. } elseif (floatval($partner->feed_tag_like) / floatval($partner->feed_tag_cnt) >= 0.1) {
  66. $partner->feed_pool_level = "recommend";
  67. }
  68. }
  69. }
  70. $partner->save();
  71. /** @var UserModel $puser */
  72. $puser = UserModel::where('partner_id', $this->data['partner_id'])->firstOrFail();
  73. /** @var UserModel $user */
  74. $user = UserModel::findOrFail($this->uid);
  75. $user->feed_cnt += 1;
  76. 1 == $this->data['like'] && $user->feed_like += 1;
  77. $user->save();
  78. $this->data['score'] = $partner->score;
  79. $this->data['feed_dis'] = "{$user->lat},{$user->lng}";
  80. $this->data['partner_dis'] = "{$puser->lat},{$puser->lng}";
  81. if (!is_null($this->data['attach'])) {
  82. $attach = json_decode($this->data['attach'], true);
  83. if (is_array($attach)) {
  84. $this->data['algorithm_score'] = isset($attach['algorithm_score']) ? $attach['algorithm_score'] : 0;
  85. $this->data['by_feed'] = isset($attach['by_feed']) ? $attach['by_feed'] : "N";
  86. $this->data['belong_feed'] = isset($attach['belong_feed']) ? $attach['belong_feed'] : "N";
  87. $this->data['user_level'] = isset($attach['user_level']) ? $attach['user_level'] : "";
  88. $this->data['partner_level'] = isset($attach['partner_level']) ? $attach['partner_level'] : "";
  89. unset($this->data['attach']);
  90. }
  91. }
  92. $dataFeedLog = DataFeedLogModel::create($this->data);
  93. dispatch_now(new FeedLogReportJob($dataFeedLog, $puser));
  94. if ($dataFeedLog->page == 'flow' && $dataFeedLog->each_like == 1) {
  95. FeedEachLikeReportJob::dispatch($user->uid, $puser->uid, 1);
  96. FeedEachLikeReportJob::dispatch($puser->uid, $user->uid, 0);
  97. }
  98. if (!PraiseModel::where(array(['uid', $this->uid], ['partner_id', $this->data['partner_id']]))->exists()) {
  99. FeedLogModel::create([
  100. 'uid' => $this->uid,
  101. 'partner_id' => $this->data['partner_id']
  102. ]);
  103. }
  104. }
  105. }