97 lines
3.0 KiB
PHP
97 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\App\Team;
|
|
use App\Models\Message;
|
|
use App\Models\User;
|
|
use App\Models\UserInfo;
|
|
use App\Models\Wechat;
|
|
use App\Utils\Messenger as Messengers;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class GroupChatUnreadNotice implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
/**
|
|
* 群聊id
|
|
* @var
|
|
*/
|
|
protected $team_id;
|
|
|
|
/**
|
|
* 用户id
|
|
* @var
|
|
*/
|
|
protected $user_id;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($team_id,$user_id)
|
|
{
|
|
$this->team_id = $team_id;
|
|
$this->user_id = $user_id;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$user = User::find($this->user_id);
|
|
|
|
//消息提醒开关
|
|
$user_info = UserInfo::firstOrCreate(['user_id'=>$user->id]);
|
|
if($user_info->message_notice == 0){
|
|
return;
|
|
}
|
|
|
|
$mobile = $user->mobile;
|
|
$official_openid = Wechat::where('user_id', $this->user_id)->value('official_openid');
|
|
$team = Team::find($this->team_id);
|
|
$is_subscribe = \WechatService::officialIsSubscribed($official_openid);
|
|
//未关注公众号 发短信通知
|
|
if(!$is_subscribe && $mobile){
|
|
$url = \CommonUtilsService::getWecharLink("/pages/tabBar/news");
|
|
$short_url_data = \CommonUtilsService::shortUrl(env('APP_URL') . '/h5/#/jump_url?url=' . $url);
|
|
$url = $short_url_data['url'] ?? '';
|
|
$content = "收到一条群通知,请点击{$url} 查看信息,敬请微信关注“福恋智能”公众号,以便接收通知!";
|
|
Message::create([
|
|
'phone' => $mobile,
|
|
'message' => $content,
|
|
'confirmed' => 1,
|
|
'ip' => request() ? request()->ip() : '127.0.0.1',
|
|
]);
|
|
Messengers::sendSMS($mobile, $content);
|
|
return;
|
|
}
|
|
if (!$official_openid) {
|
|
return;
|
|
}
|
|
//模板消息通知
|
|
$data['touser'] = $official_openid;
|
|
$data['template_id'] = config('wechat.tpls.start_message_notice');
|
|
$data['url'] = '';
|
|
$data['miniprogram'] = [
|
|
'appid'=> config('wechat.mini_program.app_id'),
|
|
'pagepath'=>'/pages/tabBar/news'
|
|
];
|
|
$data['data'] = [
|
|
'first' => "{$user->nickname},您有群聊《{$team->tname}》消息未读",
|
|
'keyword1' => date('Y-m-d H:i:s'),
|
|
'keyword2' => "{$user->nickname},您有群聊《{$team->tname}》消息未读",
|
|
'remark' => '本通知可在福恋小程序 我的-设置 中关闭。',
|
|
];
|
|
SendTemplateMsg::dispatch($data)->onQueue('start_message');
|
|
}
|
|
} |