83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Jobs\SendTemplateMsg;
|
|
use App\Models\CommunityActivity;
|
|
use App\Models\Server\TouristOrder;
|
|
use App\Models\TemplateMsgLog;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SendActivityCommentNotice extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'sendActivityCommentNotice';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '活动结束1小时发送 去评价通知';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
$now_date = date('Y-m-d H:i:s');
|
|
$now_time = time();
|
|
$activities = CommunityActivity::whereNotNull('end_time')->where('type','business')->where('class','one')->get();
|
|
$list = [];
|
|
foreach ($activities as $key => $activity) {
|
|
//未结束或结束不到一小时 不发
|
|
if($activity->end_time > $now_date || $now_time - strtotime($activity->end_time) < 3600) continue;
|
|
if($this->isSendNotice($activity->id)) continue;
|
|
//发送通知的活动id
|
|
$list[] = $activity->id;
|
|
}
|
|
if(empty($list)) return ;
|
|
foreach ($list as $value) { //value 活动id
|
|
$com = CommunityActivity::where('id',$value)->first();
|
|
//已经评价过的不发
|
|
$orders = TouristOrder::where('type','community')->where('type_id',$value)->whereIn('pay_status',[1,4])->whereNull('Praise')->get();
|
|
foreach ($orders as $order) {
|
|
$data['touser'] = $order->openid;
|
|
$data['template_id'] = '9aPSHmzsULb-YnSkJ1Y4B-larsOKdURX6UlfatPZxgY';
|
|
$data['activity_id'] = $value;
|
|
$data['url'] = env('APP_URL').'/pu/#/mySignUp?merchant_id='.$com->merchant_id.'&actioveLabel=1';
|
|
$data['data'] = [
|
|
'first' => '您好,你参与的活动《'.$com->title.'》已经结束',
|
|
'keyword1' =>$com->title,
|
|
'keyword2' =>$com->end_time,
|
|
'remark' => '点击进入详情页可对我们的活动进行评价哦!',
|
|
'activity_id'=>$value
|
|
];
|
|
SendTemplateMsg::dispatch($data)->onQueue('template_message');
|
|
}
|
|
}
|
|
}
|
|
//判断该活动是否发送过通知
|
|
public function isSendNotice($activity_id){
|
|
$log = TemplateMsgLog::where('user_id',$activity_id)->where('template_id','9aPSHmzsULb-YnSkJ1Y4B-larsOKdURX6UlfatPZxgY')->first();
|
|
if($log) return 1;
|
|
return 0;
|
|
}
|
|
}
|