74 lines
2.4 KiB
PHP
74 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Http\Response\ResponseJson;
|
|
use App\Services\IMService;
|
|
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\User;
|
|
use App\Models\Liveperson;
|
|
use App\Models\FaceMatch;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use App\Services\UserService;
|
|
class FaceMatchJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, ResponseJson;
|
|
|
|
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()
|
|
{
|
|
try {
|
|
//获取缓存用户信息
|
|
$user = User::find($this->user_id);
|
|
$log = Liveperson::where('user_id', $this->user_id)->where('status', 1)->first();
|
|
if (empty($log)) return true;
|
|
$image1 = $log->love_avatar;
|
|
$image2 = $user->photo;
|
|
$user_service = new UserService();
|
|
$result = $user_service->faceMatch($image1, $image2);
|
|
if (empty($result)) return true;
|
|
$face_log = new FaceMatch;
|
|
$face_log->user_id = $log->user->id;
|
|
$face_log->first_image = $image1;
|
|
$face_log->last_image = $image2;
|
|
$face_log->first_token = ($result->face_list)[0]->face_token;
|
|
$face_log->last_token = ($result->face_list)[1]->face_token;
|
|
$face_log->score = $result->score;
|
|
$face_log->save();
|
|
//如果头像对比分数小于70
|
|
if ($result->score <= 70) {
|
|
User::where('id', $user->id)->update(['is_photo_audited'=>-1]);
|
|
//系统通知
|
|
$message = '您的头像审核失败,请上传真实头像!';
|
|
$user_service->sendNotice($user->id, 1, 'system', $message, $message, 0, "/pages/users/unmarriV2", 1);
|
|
$body = ['msg'=>$message];
|
|
$im_service = new IMService(env('IM_APP_KEY'), env('IM_APP_SECRET'));
|
|
$im_service->sendMsg(1, 0,$user->id,$type=0,$body);
|
|
}
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
//$this->getError($e);
|
|
return false;
|
|
}
|
|
}
|
|
}
|