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; } }