From 3129da5df48bbab828ac2fc88bc62d31f6f2d1e0 Mon Sep 17 00:00:00 2001 From: Too Date: Mon, 25 Jun 2018 18:16:20 +0800 Subject: [PATCH 1/2] get_time_limit --- app/Http/Controllers/BookingController.php | 6 ++-- app/SettingCredit.php | 2 +- database/factories/SettingCreditFactory.php | 3 +- ...43_add_time_limit_setting_credit_table.php | 32 +++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 database/migrations/2018_06_25_101043_add_time_limit_setting_credit_table.php diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index ea7332b2..607d70b2 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -29,7 +29,8 @@ class BookingController extends Controller // set timeout $date1 = new DateTime($booking->created_at); $date2 = new DateTime(); - $difference_in_seconds = ($date1->format('U') + 600) - ($date2->format('U')); + $time_in_seconds = SettingCredit::orderby('updated_at','desc')->first()->time_limit; + $difference_in_seconds = ($date1->format('U') + $time_in_seconds) - ($date2->format('U')); $booking->timeout = $difference_in_seconds; // TODO : you can make it better @@ -79,7 +80,8 @@ class BookingController extends Controller // set timeout $date1 = new DateTime($booking->created_at); $date2 = new DateTime(); - $difference_in_seconds = ($date1->format('U') + 600) - ($date2->format('U')); + $time_in_seconds = SettingCredit::orderby('updated_at','desc')->first()->time_limit; + $difference_in_seconds = ($date1->format('U') + $time_in_seconds) - ($date2->format('U')); $booking->timeout = $difference_in_seconds; // TODO : you can make it better diff --git a/app/SettingCredit.php b/app/SettingCredit.php index 872fec8e..5d567ab3 100644 --- a/app/SettingCredit.php +++ b/app/SettingCredit.php @@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model; class SettingCredit extends Model { - protected $fillable = ['rmb_credit_limit','usd_credit_limit']; + protected $fillable = ['rmb_credit_limit','usd_credit_limit','time_limit']; } diff --git a/database/factories/SettingCreditFactory.php b/database/factories/SettingCreditFactory.php index 2eb3fafc..f1d4eeba 100644 --- a/database/factories/SettingCreditFactory.php +++ b/database/factories/SettingCreditFactory.php @@ -5,6 +5,7 @@ use Faker\Generator as Faker; $factory->define(App\SettingCredit::class, function (Faker $faker) { return [ 'rmb_credit_limit' => $faker->randomDigit, - 'usd_credit_limit' => $faker->randomDigit + 'usd_credit_limit' => $faker->randomDigit, + 'time_limit' => $faker->randomDigit ]; }); diff --git a/database/migrations/2018_06_25_101043_add_time_limit_setting_credit_table.php b/database/migrations/2018_06_25_101043_add_time_limit_setting_credit_table.php new file mode 100644 index 00000000..4e0aefef --- /dev/null +++ b/database/migrations/2018_06_25_101043_add_time_limit_setting_credit_table.php @@ -0,0 +1,32 @@ +integer('time_limit'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('setting_credits', function (Blueprint $table) { + // $table->dropColumn('time_limit'); + }); + } +} \ No newline at end of file From ec6db693730239fe04097e76fdecc430bc7cb1ab Mon Sep 17 00:00:00 2001 From: Too Date: Tue, 26 Jun 2018 11:28:53 +0800 Subject: [PATCH 2/2] Add ETA for booking table --- app/Booking.php | 2 +- app/Http/Controllers/BookingController.php | 1 + ...018_06_26_031229_add_eta_booking_table.php | 32 +++++++++++++++++++ tests/Feature/BookingTest.php | 3 +- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2018_06_26_031229_add_eta_booking_table.php diff --git a/app/Booking.php b/app/Booking.php index cffe157c..59c2d830 100644 --- a/app/Booking.php +++ b/app/Booking.php @@ -24,7 +24,7 @@ class Booking extends Model "usd_book_bank_branch"); protected $fillable = ['term', 'rate_id', 'user_id', 'amount', 'account_name', 'account_num', 'bank_name', - 'bank_branch', 'company_name']; + 'bank_branch', 'company_name' , 'estimated_arrival_time']; public $timestamps = true; diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 607d70b2..bc2ab042 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -238,6 +238,7 @@ class BookingController extends Controller $booking->rmb_book_amount = $request->input('amount'); $booking->status = 2; $booking->bia = $bia; + $booking->estimated_arrival_time = $request->input('estimated_arrival_time'); // $booking->user_id = $user->id; $booking->user()->associate($user); diff --git a/database/migrations/2018_06_26_031229_add_eta_booking_table.php b/database/migrations/2018_06_26_031229_add_eta_booking_table.php new file mode 100644 index 00000000..460f269d --- /dev/null +++ b/database/migrations/2018_06_26_031229_add_eta_booking_table.php @@ -0,0 +1,32 @@ +integer('estimated_arrival_time'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('bookings', function (Blueprint $table) { + // $table->dropColumn('estimated_arrival_time'); + }); + } +} diff --git a/tests/Feature/BookingTest.php b/tests/Feature/BookingTest.php index ee02d4f7..39aa871e 100644 --- a/tests/Feature/BookingTest.php +++ b/tests/Feature/BookingTest.php @@ -69,7 +69,8 @@ class BookingTest extends TestCase 'usd_book_swift_code' => '2131rew', 'usd_book_cnap' => '2131rew', 'usd_book_bank_branch' => '2131rew', - 'verification_status' => '1' + 'verification_status' => '1', + 'estimated_arrival_time' => '123' ]); if(14000 > $this->setting_credit->rmb_credit_limit){