69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Http\Response\ResponseJson;
|
||
|
|
use App\Models\ChatMessage;
|
||
|
|
use App\Models\User;
|
||
|
|
use App\Models\UserInfo;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
|
||
|
|
class StartMessageNotice implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
use ResponseJson;
|
||
|
|
|
||
|
|
protected $message;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($message)
|
||
|
|
{
|
||
|
|
$this->message = $message;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$message = $this->message;
|
||
|
|
//判断消息是否已读
|
||
|
|
$status = ChatMessage::where('id', $message->id)->value('status');
|
||
|
|
if ($status) return ;
|
||
|
|
$user = User::find($message->user_id);
|
||
|
|
$other_user = User::find($message->other_user_id);
|
||
|
|
$info = UserInfo::where('user_id', $other_user->id)->first();
|
||
|
|
if ($info && empty($info->message_notice)) return;
|
||
|
|
$data['touser'] = $other_user->wechat?$other_user->wechat->official_openid:null;
|
||
|
|
$data['template_id'] = config('wechat.tpls.start_message_notice');
|
||
|
|
// $data['template_id'] = '5ax0Q1o71701F1efuMBvdR5FfQNebuQyv0j11p-iPgw';
|
||
|
|
$data['url'] = '';
|
||
|
|
$data['miniprogram'] = [
|
||
|
|
'appid'=> config('wechat.mini_program.app_id'),
|
||
|
|
'pagepath'=>'/pages/tabBar/news'
|
||
|
|
];
|
||
|
|
$ta = $user->sex == 1?'他':"她";
|
||
|
|
$data['data'] = [
|
||
|
|
'first' => 'Hi, '.$ta.'在找你!',
|
||
|
|
'keyword1' => $message->created_at->toDateTimeString(),
|
||
|
|
'keyword2' => $user->nickname,
|
||
|
|
'remark' => '本通知可在福恋小程序 我的-设置 中关闭。',
|
||
|
|
];
|
||
|
|
SendTemplateMsg::dispatch($data)->onQueue('start_message');
|
||
|
|
}catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|