StoreSelfPartnerJob.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\Deed\FriendsModel;
  4. use App\Models\Partner\ThumbActionModel;
  5. use App\Models\PartnerModel;
  6. use App\Models\PraiseModel;
  7. use App\Models\User\SuperLikeModel;
  8. use App\Models\User\UserModel;
  9. use App\Services\Deed\FriendService;
  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 StoreSelfPartnerJob implements ShouldQueue
  16. {
  17. use Dispatchable;
  18. use InteractsWithQueue;
  19. use Queueable;
  20. use SerializesModels;
  21. private $uid;
  22. /**
  23. * Create a new job instance.
  24. *
  25. * @param int $uid
  26. */
  27. public function __construct(int $uid)
  28. {
  29. $this->uid = $uid;
  30. }
  31. /**
  32. * Execute the job.
  33. *
  34. * @return void
  35. */
  36. public function handle()
  37. {
  38. $datas = ThumbActionModel::where([
  39. ['uid', $this->uid],
  40. ['thumb', 1]
  41. ])->get();
  42. foreach ($datas as $data) {
  43. try {
  44. list($uid, $partner_id) = array($data->uid, $data->partner_id);
  45. dump($uid, $partner_id);
  46. $user = UserModel::findOrFail($uid);
  47. $partner = PartnerModel::findOrFail($partner_id);
  48. $pm = new PraiseModel();
  49. $praise = $pm->where(array(['partner_id', $partner_id], ['uid', $uid]))->first();
  50. if (collect($praise)->isEmpty()) {
  51. $lock = 0;
  52. if (
  53. SuperLikeModel::where(array(
  54. ['uid', $partner->uid],
  55. ['partner_id', $user->partner_id]
  56. ))->exists()
  57. ) {
  58. SuperLikeModel::where(array(
  59. ['uid', $partner->uid],
  60. ['partner_id', $user->partner_id]
  61. ))->update(['reply_at' => time()]);
  62. $lock = 100;
  63. }
  64. if (FriendsModel::where(array(['uid', $uid], ['friend_uid', $partner->uid]))->exists()) {
  65. $pm->where(array(
  66. ['uid', $partner->uid],
  67. ['partner_id', $user->partner_id]
  68. ))->update(['lock' => 100]);
  69. $lock = 100;
  70. }
  71. $praise = $pm->fill([
  72. 'create_at' => time(),
  73. 'created_at' => $data->created_at->timestamp,
  74. 'updated_at' => $data->updated_at->timestamp,
  75. 'partner_id' => $partner_id,
  76. 'uid' => $uid,
  77. 'type' => 1,
  78. 'read' => 0,
  79. 'lock' => $lock
  80. ]);
  81. PartnerModel::where('id', $partner_id)->increment('praises', 1);
  82. // 检验相互喜欢
  83. $fs = new FriendService();
  84. if ($datauser = $fs->eachlike($uid, $partner_id, 1)) {
  85. $res['eachlike'] = true;
  86. $res['user'] = $datauser;
  87. $praise->lock = 100;
  88. $pm->where(array(
  89. ['uid', $partner->uid],
  90. ['partner_id', $user->partner_id]
  91. ))->update(['lock' => 100]);
  92. }
  93. // 点赞我通知
  94. $ns = new \App\Services\User\NoticeService();
  95. $ns->thumbMe($uid, $partner_id);
  96. $praise->save();
  97. }
  98. $data->thumb = 0;
  99. $data->save();
  100. } catch (\Exception $exception) {
  101. continue;
  102. }
  103. }
  104. }
  105. }