ReportPartnerChange.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\CreatedPartner;
  4. use App\Events\HidePartner;
  5. use App\Events\UpdatedPartner;
  6. use App\Models\Log\FpdxCardStateListModel;
  7. use Illuminate\Database\Eloquent\ModelNotFoundException;
  8. use Illuminate\Events\Dispatcher;
  9. use Illuminate\Queue\InteractsWithQueue;
  10. use Illuminate\Contracts\Queue\ShouldQueue;
  11. /**
  12. * 卡片变化事件监听器
  13. * Class ReportPartnerChange
  14. * @package App\Listeners
  15. */
  16. class ReportPartnerChange implements ShouldQueue
  17. {
  18. use InteractsWithQueue;
  19. /**
  20. * Create the event listener.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. //
  27. }
  28. /**
  29. * Handle the event.
  30. *
  31. * @param object $event
  32. * @return void
  33. */
  34. public function handle($event)
  35. {
  36. }
  37. /**
  38. * 创建卡片事件
  39. * @param CreatedPartner $event
  40. */
  41. public function createdPartner(CreatedPartner $event)
  42. {
  43. FpdxCardStateListModel::create([
  44. 'partner_id' => $event->model->id,
  45. 'uid' => $event->model->uid,
  46. 'sex' => $event->model->sex
  47. ]);
  48. }
  49. /**
  50. * 更新卡片事件
  51. * @param UpdatedPartner $event
  52. */
  53. public function updatedPartner(UpdatedPartner $event)
  54. {
  55. try {
  56. $model = FpdxCardStateListModel::findOrFail($event->model->id);
  57. } catch (ModelNotFoundException $exception) {
  58. return;
  59. }
  60. if (1 == $event->model->is_sell) {
  61. $model->hide_at = 0;
  62. }
  63. if (
  64. 1 == $event->model->check_photo
  65. || 1 == $event->model->photo_1_check
  66. || 1 == $event->model->photo_2_check
  67. || 1 == $event->model->photo_3_check
  68. || 1 == $event->model->photo_4_check
  69. ) {
  70. $model->feed_push_type = 1;
  71. } elseif (
  72. 1 != $event->model->check_photo
  73. && 1 != $event->model->photo_1_check
  74. && 1 != $event->model->photo_2_check
  75. && 1 != $event->model->photo_3_check
  76. && 1 != $event->model->photo_4_check
  77. && 1 == $event->model->voice_check
  78. ) {
  79. $model->feed_push_type = 2;
  80. } else {
  81. $model->feed_push_type = 3;
  82. }
  83. $model->is_sell = $event->model->is_sell;
  84. $model->is_push_feed = $event->model->is_push_feed;
  85. $model->is_recommend = $event->model->is_recommend;
  86. $model->base_score = $event->model->base_score;
  87. $model->save();
  88. }
  89. /**
  90. * 隐藏卡片事件
  91. * @param HidePartner $event
  92. */
  93. public function hidePartner(HidePartner $event)
  94. {
  95. FpdxCardStateListModel::where('partner_id', $event->partner_id)->update(['is_sell' => 0, 'hide_at' => time()]);
  96. }
  97. }