<?php 

require 'db.php';

if(isset($_GET['sid']) && isset($_GET['token']))
{
    $shop_id = $_GET['sid'];
    $shop_code = $_GET['token'];

    include 'token_check.php';
    
    if($token_check)
    {
        $sels = $con->query("select * from user where shop_id='$shop_id' and shop_code='$shop_code' order by use_date DESC");
        while($rows = $sels->fetch_assoc())
        {
            $p['id'] = $rows['id'];
        	$p['name'] = $rows['name'];
        	$uid = $rows['id'];
        	$ad =  $con->query("select * from address where uid='$uid'");
        	if($row1 = $ad->fetch_assoc())
        	$p['address'] = $row1['hno'].','.$row1['street'].','.$row1['landmark'].','.$row1['area'].','.$row1['pincode'];
        	$p['mobile'] = $rows['mobile'];
        	$p['email'] = $rows['email'];
        	$dd = new DateTime($rows['use_date']);
            $p['r_date'] = $dd->format('d-m-Y'); 
        	$cat =  $con->query("select count(uid) as uids from orders where uid=".$rows['id']." and status = 'completed'");
        	if($row = $cat->fetch_assoc())
        	$p['total_orders'] = $row['uids'];
        	$p['status'] = $rows['status'];
        	$cp[] = $p;
        }
        
        echo json_encode($cp);
    }
    else
    {
        $rows = array('status'=>"",'message' => 'Data Error');
        echo json_encode($rows);
    }
}

?>