Skip to content

Commit b8f333a

Browse files
committed
á
1 parent 4a7b36a commit b8f333a

26 files changed

+482
-399
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Classes\Repository;
4+
5+
use App\Classes\Repository\Interfaces\ICouponSettingRepository;
6+
use App\Models\CouponSetting;
7+
8+
class CouponSettingRepository extends BaseRepository implements ICouponSettingRepository
9+
{
10+
11+
public function model()
12+
{
13+
return CouponSetting::class;
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Classes\Repository;
4+
5+
use App\Classes\Repository\Interfaces\ICouponUserRepository;
6+
use App\Models\CouponUser;
7+
8+
class CouponUserRepository extends BaseRepository implements ICouponUserRepository
9+
{
10+
11+
public function model()
12+
{
13+
return CouponUser::class;
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Classes\Repository\Interfaces;
4+
5+
6+
interface ICouponSettingRepository extends IBaseRepository
7+
{
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App\Classes\Repository\Interfaces;
4+
5+
6+
interface ICouponUserRepository extends IBaseRepository
7+
{
8+
9+
}

app/Classes/RepositoryProvider.php

+2
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ public function register()
3838
App::bind(IRepository\IOrderRepository::class, Repository\OrderRepository::class);
3939
App::bind(IRepository\IOrderFoodRepository::class, Repository\OrderFoodRepository::class);
4040
App::bind(IRepository\IRestaurantTableRepository::class, Repository\RestaurantTableRepository::class);
41+
App::bind(IRepository\ICouponSettingRepository::class, Repository\CouponSettingRepository::class);
42+
App::bind(IRepository\ICouponUserRepository::class, Repository\CouponUserRepository::class);
4143
}
4244
}

app/Classes/ServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ public function register()
3232
App::bind(IService\ISettingFoodService::class, Service\SettingFoodService::class);
3333
App::bind(IService\IRestaurantService::class, Service\RestaurantService::class);
3434
App::bind(IService\IOrderService::class, Service\OrderService::class);
35+
App::bind(IService\ICouponService::class, Service\CouponService::class);
3536
}
3637
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Classes\Services;
4+
5+
use App\Classes\Repository\Interfaces\ICouponSettingRepository;
6+
use App\Classes\Repository\Interfaces\ICouponUserRepository;
7+
use App\Classes\Services\Interfaces\ICouponService;
8+
9+
class CouponService extends BaseService implements ICouponService
10+
{
11+
12+
protected $couponSettingRepository, $couponUserRepository;
13+
public function __construct(
14+
ICouponSettingRepository $couponSettingRepository,
15+
ICouponUserRepository $couponUserRepository,
16+
)
17+
{
18+
$this->couponSettingRepository = $couponSettingRepository;
19+
$this->couponUserRepository = $couponUserRepository;
20+
}
21+
22+
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Classes\Services\Interfaces;
4+
5+
interface ICouponService
6+
{
7+
8+
}

app/Classes/Services/Interfaces/IRestaurantService.php

+12
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,16 @@ public function getHomeClient($restaurant_id);
5353
* @param int $id
5454
*/
5555
public function getRestaurantMealById($id);
56+
57+
/**
58+
* create table restaurant
59+
* @param array $array
60+
* @param mixed $filename
61+
*/
62+
public function createTable($array, $filename);
63+
64+
/**
65+
* find table
66+
*/
67+
public function findTable($data);
5668
}

app/Classes/Services/RestaurantService.php

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Classes\Repository\Interfaces\IRestaurantSettingRepository;
88
use App\Classes\Repository\Interfaces\IRestaurantTableRepository;
99
use App\Classes\Services\Interfaces\IRestaurantService;
10+
use Illuminate\Support\Facades\Config;
1011
use Illuminate\Support\Facades\DB;
1112
use Illuminate\Support\Facades\Log;
1213
use Illuminate\Support\Facades\Storage;
@@ -179,4 +180,30 @@ public function getRestaurantMealById($id)
179180
return $this->restaurantMealRepository->find($id);
180181
}
181182

183+
/**
184+
* @inheritDoc
185+
*/
186+
public function createTable($array, $filename)
187+
{
188+
$attr = [
189+
'restaurant_id' => $array['restaurant_id'],
190+
'status' => Config::get('const.food.status.Active'),
191+
'table_id' => $array['table_id'],
192+
'qr' => $filename,
193+
'memo' => '',
194+
];
195+
return $this->restaurantTableRepository->create($attr);
196+
}
197+
198+
/**
199+
* @inheritDoc
200+
*/
201+
public function findTable($data)
202+
{
203+
$attr = [
204+
'restaurant_id' => $data['restaurant_id'],
205+
'table_id' => $data['table_id'],
206+
];
207+
return $this->restaurantTableRepository->findOne($attr);
208+
}
182209
}

app/Classes/Services/UserService.php

-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ public function postForgotByEmail($email)
191191
'token' => $token,
192192
];
193193
$password_token = $this->passwordResetToken->create($attr);
194-
dd($password_token);
195194
Mail::to($user->email)->send(new ResetPassword($user));
196195
return true;
197196
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Classes\Services\Interfaces\ICouponService;
6+
use App\Http\Controllers\Controller;
7+
use Illuminate\Http\Request;
8+
9+
class CouponController extends Controller
10+
{
11+
protected $couponService;
12+
13+
public function __construct(
14+
ICouponService $couponService,
15+
16+
) {
17+
$this->couponService = $couponService;
18+
}
19+
20+
/**
21+
* get blade coupon
22+
*/
23+
public function index()
24+
{
25+
return view('admin.coupon.index');
26+
}
27+
}

app/Http/Controllers/Admin/TableSettingController.php

+25-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ public function __construct(
2222
/**
2323
* get list table restaurant
2424
*/
25-
public function index()
25+
public function index(Request $request)
2626
{
2727
$list_restaurant = $this->restaurantService->getRestaurants();
28-
$restaurant = $list_restaurant->first();
28+
if ($request->input('restaurant_id')) {
29+
$restaurant = $list_restaurant->where('id', $request->input('restaurant_id'))->first();
30+
}else{
31+
$restaurant = $list_restaurant->first();
32+
}
2933
return view('admin.table_setting.index', compact('list_restaurant','restaurant'));
3034
}
3135

@@ -35,12 +39,28 @@ public function index()
3539
*/
3640
public function createQrCode(Request $request)
3741
{
38-
$url = 'https://example.com';
42+
$restaurant_id = $request->restaurant_id;
43+
$table_id = $request->table_id;
44+
$url = route('client.home') . '?restaurant_id=' . $restaurant_id . '&table_id=' . $table_id;
3945
$qrCode = QrCode::size(300)->generate($url);
4046

41-
$filename = 'qr_code.svg';
42-
$path = 'qr_codes/' . $filename;
47+
$filename = 'restaurant_id_'.$restaurant_id.'_table_id_'.$table_id.'.svg';
48+
$path = 'public/qr_codes/' . $filename;
4349

4450
Storage::disk('local')->put($path, $qrCode);
51+
52+
$table = $this->restaurantService->createTable($request->all(), $filename);
53+
$modal = view('admin.table_setting.partials._modal-show', compact('table'))->render();
54+
return response()->json($modal);
55+
}
56+
57+
/**
58+
* show qr code blade
59+
*/
60+
public function showQrCode(Request $request)
61+
{
62+
$table = $this->restaurantService->findTable($request->all());
63+
$modal = view('admin.table_setting.partials._modal-show', compact('table'))->render();
64+
return response()->json($modal);
4565
}
4666
}

app/Models/CouponSetting.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class CouponSetting extends Model
9+
{
10+
use HasFactory;
11+
public $table = "coupon_setting";
12+
protected $guarded = [];
13+
14+
}

app/Models/CouponUser.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
9+
class CouponUser extends Model
10+
{
11+
use HasFactory, SoftDeletes;
12+
public $table = "coupon_user";
13+
protected $guarded = [];
14+
15+
public function user()
16+
{
17+
return $this->belongsTo(User::class, 'user_id');
18+
}
19+
20+
public function coupon()
21+
{
22+
return $this->belongsTo(CouponSetting::class, 'coupon_id');
23+
}
24+
25+
public function order()
26+
{
27+
return $this->belongsTo(Order::class, 'order_id');
28+
}
29+
}

database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
public function up(): void
1313
{
1414
Schema::create('password_reset_tokens', function (Blueprint $table) {
15-
$table->string('email')->primary();
15+
$table->id();
16+
$table->string('email');
1617
$table->string('token');
1718
$table->timestamps();
1819
});

database/migrations/2023_11_02_110232_create_restaurant_table_table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function up(): void
1414
Schema::create('restaurant_table', function (Blueprint $table) {
1515
$table->id();
1616
$table->unsignedBigInteger('restaurant_id');
17-
$table->integer('table');
17+
$table->integer('table_id');
1818
$table->tinyInteger('status')->default(0);
1919
$table->string('qr')->nullable();
2020
$table->string('memo')->nullable();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('coupon_setting', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('code');
17+
$table->string('percent')->nullable();
18+
$table->integer('price')->nullable();
19+
$table->integer('type');
20+
$table->string('memo')->nullable();
21+
$table->integer('status')->default(0);
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('coupon_setting');
32+
}
33+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('coupon_user', function (Blueprint $table) {
15+
$table->id();
16+
$table->unsignedBigInteger('user_id');
17+
$table->unsignedBigInteger('coupon_id');
18+
$table->unsignedBigInteger('order_id');
19+
$table->string('price')->nullable();
20+
$table->timestamps();
21+
$table->softDeletes();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*/
28+
public function down(): void
29+
{
30+
Schema::dropIfExists('coupon_user');
31+
}
32+
};

0 commit comments

Comments
 (0)