91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?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\WorthShare;
|
|
use App\Models\User;
|
|
use App\Models\Wechat;
|
|
class StoreApproveWorthShare implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected $user_id;
|
|
protected $from_user_id;
|
|
protected $chat_user_id;
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($user_id, $from_user_id, $chat_user_id=null)
|
|
{
|
|
$this->user_id = $user_id;
|
|
$this->from_user_id = $from_user_id;
|
|
$this->chat_user_id = $chat_user_id;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$target_user_id = $this->user_id;
|
|
//注册绑定
|
|
$user = User::find($this->user_id)->first();
|
|
if($user && ($user->from_openid || $user->from_user_id)){
|
|
$bind_user_id = $user->from_user_id?:null;
|
|
if(empty($bind_user_id)){
|
|
$bind_user_id = Wechat::where('openid', $user->from_openid)->whereNotNull('openid')->value("user_id");
|
|
}
|
|
if($bind_user_id){
|
|
$data = [
|
|
'user_id'=>$bind_user_id,
|
|
'target_user_id'=>$target_user_id,
|
|
'channel'=>'approve',
|
|
'sub_channel'=>'bind',
|
|
];
|
|
$share = WorthShare::where($data)->first();
|
|
if(empty($share)){
|
|
WorthShare::addWorthShare($data);
|
|
}
|
|
}
|
|
}
|
|
|
|
$chat_user_id = $this->chat_user_id;
|
|
if($chat_user_id){
|
|
$data = [
|
|
'user_id'=>$chat_user_id,
|
|
'target_user_id'=>$target_user_id,
|
|
'channel'=>'approve',
|
|
'sub_channel'=>'user',
|
|
];
|
|
$share = WorthShare::where($data)->first();
|
|
if(empty($share)){
|
|
WorthShare::addWorthShare($data);
|
|
}
|
|
}
|
|
|
|
//认证带分享信息
|
|
$from_user_id = $this->from_user_id;
|
|
if(empty($from_user_id)) return true;
|
|
$data = [
|
|
'user_id'=>$from_user_id,
|
|
'target_user_id'=>$target_user_id,
|
|
'channel'=>'approve',
|
|
'sub_channel'=>'direct',
|
|
];
|
|
$share = WorthShare::where($data)->first();
|
|
if(empty($share)){
|
|
WorthShare::addWorthShare($data);
|
|
}
|
|
return true;
|
|
}
|
|
}
|