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_pay_order')->where('id',$this->msgid)->first(); if(empty($data)){return true;} $args = json_decode($data->args,true); $gold = isset($args['gold']) ? $args['gold'] : 0; if($gold <= 0){ return true; } DB::beginTransaction(); $Alltools = new Alltools; $result = $Alltools->recharge($data->user_id,$gold,'pay_order',$this->msgid); if($result !== true){ 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; } }