msgid = $msgid; Log::info(date('Y-m-d H:i:d').':'.$msgid); } /** * Execute the job. * * @return void */ public function handle() { $result = $this->goaaa(); /*if($result === false){ //防止失败 $key = 'kgelavarel_giftjob_'.$this->msgid; $limit_rs = $this->apiLimit(2,3600000,$key);//一小时最多另执行2次 if($limit_rs === true){ //echo 123; dispatch((new GiftJob($this->msgid))->delay(60));//加入队列 }else{ //echo 345; } }*/ } //主要调用 public function goaaa(){ // $data = DB::table('mt_user_match_video_log')->where('id',$this->msgid)->where('plantask_status',0)->first(); if(empty($data)){return true;} DB::beginTransaction(); $gold = bcsub($data->money,$data->free_money,1); if($gold > 0){ $Alltools = new Alltools; $result = $Alltools->shouyi($data->to_user_id,$gold,'user_match_video_log',$this->msgid); if($result !== true){ DB::rollBack(); return false; } } // $update = [ 'plantask_status' => 1, ]; $rs_update = DB::table('mt_user_match_video_log')->where('id',$this->msgid)->update($update); if(!$rs_update){ Db::rollBack(); return false; } DB::commit(); return true; } private function apiLimit($apiLimit = 1, $apiLimitTime = 1000, $key = '') { $app_name = Config::get('app.name');// laravel name $key = "{$app_name}:{$key}"; $redis = Redis::connection(); // //指定键值新增+1 并获取 $count = $redis->incr($key); if ($count > $apiLimit) { return false; } //设置过期时间 if ($count == 1) { $redis->pExpire($key, $apiLimitTime); } return true; } }