-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5734e4d
commit bfa3f48
Showing
16 changed files
with
1,680 additions
and
402 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ItemSeenInsertJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
|
||
public $model_name; | ||
public $model_id; | ||
public $data; | ||
/** | ||
* Create a new job instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct($model_name,$model_id,$data) | ||
{ | ||
$this->model_name = $model_name; | ||
$this->model_id = $model_id; | ||
$this->data = $data; | ||
} | ||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$classNameString = strtoupper((new \ReflectionClass($this->model_name))->getShortName()); | ||
$data = $this->data; | ||
$model_id = $this->model_id; | ||
|
||
$item_seen = cache()->remember('item_seen_'.\MainHelper::slug($this->model_id).\MainHelper::slug($classNameString).$this->data['ip'],60*60*24,function()use($data,$model_id,$classNameString){ | ||
return \App\Models\ItemSeen::where('type_id',$model_id)->where('type',$classNameString)->where('ip',$data['ip'])->whereDate('created_at', \Carbon::today())->first(); | ||
}); | ||
|
||
|
||
if ($item_seen==null) { | ||
\App\Models\ItemSeen::insert([[ | ||
'type_id'=>$this->model_id, | ||
'type'=>$classNameString, | ||
'ip'=>$this->data['ip'], | ||
'prev_link'=>$this->data['prev_link'], | ||
'agent_name'=>$this->data['agent_name'], | ||
'browser'=>$this->data['browser'], | ||
'device'=>$this->data['device'], | ||
'operating_system'=>$this->data['operating_system'] | ||
]]); | ||
$className = $this->model_name; | ||
$className::where('id',$this->model_id)->increment('views'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class RateLimitInsertJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public $data; | ||
public $tries = 2; | ||
public $timeout = 0.1; | ||
/** | ||
* Create a new job instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct($data) | ||
{ | ||
$this->data= $data; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$data=$this->data; | ||
$last_insert = cache()->remember('rate_limit_'.\MainHelper::slug($data['ip']),60*20,function()use($data){ | ||
$last_insert = \App\Models\RateLimit::where('ip',$data['ip'])->where('created_at','>=',\Carbon::parse(now())->subMinutes(19))->orderBy('id','DESC')->first(); | ||
|
||
if($last_insert!=null){ | ||
return $last_insert; | ||
}if($last_insert==null){ | ||
$country=(new \UserSystemInfoHelper)->get_country_from_ip($data['ip']); | ||
$last_insert= \App\Models\RateLimit::create([ | ||
'traffic_landing'=>$data['traffic_landing'], | ||
'domain'=>$data['prev_domain'], | ||
'prev_link'=>$data['prev_url'], | ||
'ip'=>$data['ip'], | ||
'country_code'=>$country['country_code'], | ||
'country_name'=>$country['country'], | ||
'agent_name'=>$data['agent_name'], | ||
'user_id'=>$data['user_id'], | ||
'browser'=>$data['browser'], | ||
'device'=>$data['device'], | ||
'operating_system'=>$data['operating_system'], | ||
'created_at'=>\Carbon::parse(now())->format('Y-m-d H:i:s'), | ||
'updated_at'=>\Carbon::parse(now())->format('Y-m-d H:i:s'), | ||
]); | ||
return $last_insert; | ||
} | ||
|
||
}); | ||
$rate_limit_detail = \App\Models\RateLimitDetail::insert([[ | ||
'url'=>$data['traffic_landing'], | ||
'user_id'=> $data['user_id'], | ||
'rate_limit_id'=>$last_insert->id, | ||
'ip'=>$data['ip'], | ||
'created_at'=>\Carbon::parse(now())->format('Y-m-d H:i:s'), | ||
'updated_at'=>\Carbon::parse(now())->format('Y-m-d H:i:s'), | ||
]]); | ||
|
||
} | ||
} |
Oops, something went wrong.