58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Jobs;
|
||
|
|
|
||
|
|
use App\Models\App\UserTeam;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Queue\InteractsWithQueue;
|
||
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||
|
|
|
||
|
|
class SendTeamMessageTemplate implements ShouldQueue
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
|
|
||
|
|
public $tries = 1;
|
||
|
|
public $team_id, $user;
|
||
|
|
/**
|
||
|
|
* Create a new job instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($team_id, $user)
|
||
|
|
{
|
||
|
|
$this->team_id = $team_id;
|
||
|
|
$this->user = $user;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the job.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
|
||
|
|
\Log::info("群id".$this->team_id."发送模板消息");
|
||
|
|
$logs = UserTeam::with('user')->whereHas("user")->where("user_id", "<>", $this->user->id)->where("team_id",$this->team_id)->get();
|
||
|
|
foreach ($logs as $log) {
|
||
|
|
if ($log->user->wechat->official_openid) {
|
||
|
|
$data['touser'] = $log->user->wechat->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'] = [
|
||
|
|
'keyword1' => date('Y-m-d H:i:s'),
|
||
|
|
'keyword2' => "您有新的群消息",
|
||
|
|
];
|
||
|
|
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|