added stat
This commit is contained in:
@@ -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(){
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user