diff --git a/app/Http/Controllers/user/UserController.php b/app/Http/Controllers/user/UserController.php index 9765ff9..d1bf576 100644 --- a/app/Http/Controllers/user/UserController.php +++ b/app/Http/Controllers/user/UserController.php @@ -17,9 +17,37 @@ use Illuminate\Support\Facades\Storage; class UserController extends Controller { public function index(){ + $m = new UserModel; + $userRole = Auth::user()->role; + + if($userRole == "store_owner"){ + $storeId = Auth::user()->store_id; + + $countStoreOrder = $m->countStoreOrder($storeId); + $storeIncome = $m->storeIncome($storeId); + $countStoreProduct = $m->countStoreProduct($storeId); + $countStorePublishedProduct = $m->countStorePublishedProduct($storeId); + + $post_data = array( + 'isStoreOwner' => true, + 'store_order' => $countStoreOrder[0]->count_order, + 'store_income' => $storeIncome[0]->store_income, + 'store_product_count' => $countStoreProduct[0]->store_product_count, + 'store_published_product' => $countStorePublishedProduct[0]->store_published_product + ); + }else{ + $post_data = array( + 'isStoreOwner' => false, + 'store_order' => "", + 'store_income' => "", + 'store_product_count' => "", + 'store_published_product' => "" + ); + } + + // $post_data = json_encode($post_data, JSON_FORCE_OBJECT); + return view('user-layouts.index')->with('data', $post_data); - return view('user-layouts.index'); - } public function addressBook(){ diff --git a/app/Models/user/UserModel.php b/app/Models/user/UserModel.php index d34b964..0193076 100644 --- a/app/Models/user/UserModel.php +++ b/app/Models/user/UserModel.php @@ -317,4 +317,35 @@ class UserModel extends Model { } + function countStoreOrder($storeId){ + $pdo = DB::connection()->getPdo(); + $query = $pdo->prepare("SELECT SUM(o.Quantity) AS count_order FROM orders AS o WHERE o.StoreId = :storeId"); + $query->execute([':storeId'=>$storeId]); + $row = $query->fetchAll(\PDO::FETCH_OBJ); + return $row; + } + + function storeIncome($storeId){ + $pdo = DB::connection()->getPdo(); + $query = $pdo->prepare("SELECT SUM(o.Price) AS store_income FROM orders AS o WHERE o.StoreId = :storeId"); + $query->execute([':storeId'=>$storeId]); + $row = $query->fetchAll(\PDO::FETCH_OBJ); + return $row; + } + + function countStoreProduct($storeId){ + $pdo = DB::connection()->getPdo(); + $query = $pdo->prepare("SELECT COUNT(Id) AS store_product_count FROM teamstore_products AS tp WHERE tp.TeamStoreId = :storeId"); + $query->execute([':storeId'=>$storeId]); + $row = $query->fetchAll(\PDO::FETCH_OBJ); + return $row; + } + + function countStorePublishedProduct($storeId){ + $pdo = DB::connection()->getPdo(); + $query = $pdo->prepare("SELECT COUNT(Id) AS store_published_product FROM teamstore_products AS tp WHERE tp.TeamStoreId = :storeId AND PrivacyStatus = 'public'"); + $query->execute([':storeId'=>$storeId]); + $row = $query->fetchAll(\PDO::FETCH_OBJ); + return $row; + } } \ No newline at end of file diff --git a/resources/views/user-layouts/index.blade.php b/resources/views/user-layouts/index.blade.php index 43bf4f6..2aaf9d8 100644 --- a/resources/views/user-layouts/index.blade.php +++ b/resources/views/user-layouts/index.blade.php @@ -17,15 +17,80 @@
@if(Auth::user()->email_is_verified == "0") -
- -

To do!

- Please verify your Email Address. Click here -
-