Skip to content

Commit

Permalink
add migration for rate
Browse files Browse the repository at this point in the history
  • Loading branch information
ZsgsDesign committed May 16, 2019
1 parent 27f6a8c commit 2213132
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Expand Up @@ -68,7 +68,8 @@ protected function create(array $data)
'email' => $data['email'],
'password' => Hash::make($data['password']),
'avatar' => "/static/img/avatar/default.png",
'contest_account' => null
'contest_account' => null,
'professional_rate' => 1500
]);
}

Expand Down
14 changes: 11 additions & 3 deletions app/Models/Rating/RatingCalculator.php
Expand Up @@ -147,9 +147,17 @@ public function calculate(){
}

public function storage(){
foreach($this->contestants as $contestant){
$newRating=$contestant["rating"]+$contestant["delta"];
}
$contestants=$this->contestants;
DB::transaction(function () use ($contestants) {
foreach($contestants as $contestant){
$newRating=$contestant["rating"]+$contestant["delta"];
DB::table("users")->where([
"uid"=>$contestant["uid"]
])->update([
"rate"=>$newRating
]);
}
}, 5);
}

private function validateDeltas(){
Expand Down
2 changes: 1 addition & 1 deletion config/database.php
Expand Up @@ -52,7 +52,7 @@
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'strict' => false,
'engine' => null,
],

Expand Down
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddProfessionalRateToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->integer('professional_rate')->nullable()->default(1500)->after('email_verified_at');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['professional_rate']);
});
}
}

0 comments on commit 2213132

Please sign in to comment.