MockThumb.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\CreatedPartner;
  4. use App\Models\PraiseModel;
  5. use App\Models\User\AuthKey;
  6. use App\Models\User\MockThumbModel;
  7. use Illuminate\Database\Eloquent\ModelNotFoundException;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. /**
  10. * 同步mock点赞数据
  11. * Class MockThumb
  12. * @package App\Listeners
  13. */
  14. class MockThumb implements ShouldQueue
  15. {
  16. /**
  17. * Create the event listener.
  18. *
  19. * @return void
  20. */
  21. public function __construct()
  22. {
  23. //
  24. }
  25. /**
  26. * Handle the event.
  27. *
  28. * @param CreatedPartner $event
  29. * @return void
  30. */
  31. public function handle(CreatedPartner $event)
  32. {
  33. try {
  34. $auth = AuthKey::where([
  35. ['uid', $event->model->uid],
  36. ['auth_type', config("miniprogram.public_id")]
  37. ])->firstOrFail();
  38. } catch (ModelNotFoundException $exception) {
  39. return;
  40. }
  41. $mocks = MockThumbModel::where('thumb_user', $auth->auth_key)->get();
  42. foreach ($mocks as $mock) {
  43. /** @var MockThumbModel $mock */
  44. PraiseModel::create([
  45. 'uid' => $mock->uid,
  46. 'partner_id' => $event->model->id,
  47. 'create_at' => $mock->created_at->timestamp,
  48. 'created_at' => $mock->created_at->timestamp,
  49. 'updated_at' => $mock->created_at->timestamp,
  50. 'type' => 1
  51. ]);
  52. }
  53. MockThumbModel::where('thumb_user', $auth->auth_key)->update(['sync' => 1]);
  54. }
  55. }