forked from summerblue/phphub5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add calculate maintainer works logic
- Loading branch information
1 parent
06f14dc
commit 319e2fd
Showing
5 changed files
with
111 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Carbon\Carbon; | ||
use App\Models\Role; | ||
use App\Models\User; | ||
use App\Models\MaintainerLog; | ||
|
||
class CalculateMaintainerWorks extends Command | ||
{ | ||
|
||
protected $signature = 'phphub:calculate-maintainer-works'; | ||
protected $description = 'Calculate maintainer works'; | ||
|
||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$start_time = Carbon::now()->subDays(7)->toDateString(); | ||
$end_time = Carbon::now()->toDateString(); | ||
|
||
$role = Role::find(2); | ||
$maintainers = User::byRolesName($role->name); | ||
|
||
foreach ($maintainers as $user) { | ||
$data = []; | ||
|
||
$topics_count = $user->topics() | ||
->whereBetween('created_at', [$start_time, $end_time]) | ||
->count(); | ||
|
||
$replies_count = $user->replies() | ||
->whereBetween('created_at', [$start_time, $end_time]) | ||
->count(); | ||
|
||
$excellent_count = $user->revisions() | ||
->where('key', 'is_excellent') | ||
->whereBetween('created_at', [$start_time, $end_time]) | ||
->get(); | ||
|
||
$sink_count = $user->revisions() | ||
->where('key', 'order') | ||
->whereBetween('created_at', [$start_time, $end_time]) | ||
->count(); | ||
|
||
$data = compact('topics_count', 'replies_count', 'excellent_count', 'sink_count'); | ||
$data['user_id'] = $user->id; | ||
$data['start_time'] = $start_time; | ||
$data['end_time'] = $end_time; | ||
MaintainerLog::create($data); | ||
} | ||
|
||
$this->info('Done'); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class MaintainerLog extends Model | ||
{ | ||
protected $guarded = ['id']; | ||
|
||
public function user() | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
database/migrations/2016_10_16_225901_create_maintainer_logs.php
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,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateMaintainerLogs extends Migration | ||
{ | ||
|
||
public function up() | ||
{ | ||
Schema::create('maintainer_logs', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->timestamp('start_time'); | ||
$table->timestamp('end_time'); | ||
$table->integer('user_id')->unsigned()->index(); | ||
$table->integer('topics_count')->unsigned(); | ||
$table->integer('replies_Count')->unsigned(); | ||
$table->integer('excellent_count')->unsigned(); | ||
$table->integer('sink_count')->unsigned(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::drop('maintainer_logs'); | ||
} | ||
} |