everyMinute(); } /** * 执行任务 * @return mixed */ protected function execute() { try { $atListQueue=Cache::get('atListQueue'); if($atListQueue){ foreach ($atListQueue as $key=>$val){ $message=Message::where('msg_id',$key)->value('at'); $atList=($message ?? null) ? explode(',',$message): []; // 两个数组取差集 $uniqueArr=array_unique($val); $newAtList = array_filter($atList, function ($value) use ($uniqueArr) { return !in_array($value, $uniqueArr); }); Message::where('msg_id',$key)->update(['at'=>implode(',',$newAtList)]); } Cache::delete('atListQueue'); } print "****************设置已读成功******************\n"; } catch (Exception $e) { print '设置已读失败:'.$e->getMessage()."\n"; } } }