love_php/app/Jobs/AddMatchingRate.php

115 lines
3.8 KiB
PHP
Raw Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Models\MatchingRate;
use App\Models\ProfileCourtship;
class AddMatchingRate implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1;
protected $user_id;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($user_id)
{
$this->user_id = $user_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//已匹配的user_id
$match_user_ids = MatchingRate::where('user_id', $this->user_id)->distinct('other_user_id')->pluck('other_user_id');
//未匹配的user_id
$other_user_ids = User::whereNotIn('id','match_user_ids')->where('type', 'single')->where('id', '<>', $this->user_id)->pluck('id');
$profile = ProfileCourtship::where('user_id', $this->user_id)->first();
foreach ($other_user_ids as $other_user_id) {
}
}
public function weight($age, $other_age)
{
$user_age = $this->getAge($user_birthday);
$other_user_age = $this->getAge($other_user_birthday);
$rate->age_diff = $user_age - $other_user_age;
$age = 0;
if ($user_profile->sex == 1) {//你是男生
if ($user_age - $other_user_age >= 10 && $user_age - $other_user_age < 20 ) {//男生大女生十至二十岁之间
$age = -5;
}
if ($user_age - $other_user_age >= 20 ) {//男生大二十岁
$age = -20;
}
if ($user_age - $other_user_age >=5 && $user_age - $other_user_age < 10 ) {//男生大女生五岁至十岁之间
$age = -3;
}
if ($user_age - $other_user_age < 5 && $user_age - $other_user_age >= -3) {//男生大女生0-5 或者 女生大男生 0-3
$age = 3;
}
if ($other_user_age - $user_age > 3 && $other_user_age - $user_age < 10) {//女生大男生 3-10
$age = -10;
}
if ($other_user_age - $user_age >= 10) {//女生大男生 10
$age = -20;
}
}
if ($user_profile->sex == 2) {//你是女生
if ($user_age - $other_user_age >= 10 ) {//女生大男生 10
$age = -20;
}
if ($user_age - $other_user_age >= 5 && $user_age - $other_user_age < 10 ) {//女生大男生 5-10
$age = -10;
}
if ($user_age - $other_user_age < 5 && $user_age - $other_user_age > 3) { //女生大男生 3-5
$age = -5;
}
if ($user_age - $other_user_age <=3 && $user_age - $other_user_age >= -5) { //女生大男生 -3-5
$age = 3;
}
if ($other_user_age - $user_age >= 5 && $other_user_age - $user_age < 10 ) {//男生大女生 5-10
$age = -3;
}
if ($other_user_age - $user_age >= 10 && $other_user_age - $user_age < 20 ) {//男生大女生 10-20
$age = -5;
}
if ($other_user_age - $user_age >= 20 ) {//男生大女生 20
$age = -20;
}
}
if (empty($age)) {
// if ($user_age > $other_user_age) {
// $age = 4 - ($user_age - $other_user_age)/5;
// }else{
// $age = 4 - ($other_user_age - $user_age)/5;
// }
// if ($age >= 1000 || $age <= -1000) {
// $age = -999.99;
// }
$age = -999.99;
}
$rate->age = $age;
$weight += $rate->age;
}
}