ThumbOrUnThumbUser.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\EachLike;
  4. use App\Events\ThumbUser;
  5. use App\Events\UnEachLike;
  6. use App\Events\UnThumbUser;
  7. use App\Models\PartnerModel;
  8. use App\Models\PraiseModel;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Contracts\Queue\ShouldQueue;
  11. class ThumbOrUnThumbUser
  12. {
  13. /**
  14. * Create the event listener.
  15. *
  16. * @return void
  17. */
  18. public function __construct()
  19. {
  20. }
  21. /**
  22. * Handle the event.
  23. *
  24. * @param object $event
  25. * @return void
  26. */
  27. public function handle($event)
  28. {
  29. }
  30. public function thumb(ThumbUser $event)
  31. {
  32. PraiseModel::updateOrCreate([
  33. 'uid' => $event->user->uid,
  34. 'partner_id' => $event->partner->id
  35. ], [
  36. 'type' => 1,
  37. 'updated_at' => $event->timestamp,
  38. 'read' => 0
  39. ]);
  40. PartnerModel::where('id', $event->partner->id)->increment('praises', 1);
  41. if (
  42. PraiseModel::where([
  43. array('uid', $event->partner->uid), array('partner_id', $event->user->partner_id), array('type', 1)
  44. ])->first()
  45. ) {
  46. PraiseModel::where([
  47. array('uid', $event->user->uid), array('partner_id', $event->partner->id)
  48. ])->orWhere([
  49. array('uid', $event->partner->uid), array('partner_id', $event->user->partner_id)
  50. ])->update(['lock' => 100]);
  51. event(new EachLike($event->user->uid, $event->partner->uid));
  52. }
  53. }
  54. public function unThumb(UnThumbUser $event)
  55. {
  56. if (
  57. PraiseModel::where([
  58. array('uid', $event->partner->uid), array('partner_id', $event->user->partner_id), array('type', 1)
  59. ])->first()
  60. ) {
  61. event(new UnEachLike($event->user->uid, $event->partner->uid));
  62. }
  63. PraiseModel::where([
  64. array('uid', $event->user->uid), array('partner_id', $event->partner->id)
  65. ])->update([
  66. 'type' => 0,
  67. 'updated_at' => $event->timestamp
  68. ]);
  69. }
  70. }