<?php 
require 'db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['mobile'] == ''  || $data['password'] == '')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
    // $mobile = "7871632299";
    // $password = "123456";
    $mobile = strip_tags(mysqli_real_escape_string($con,$data['mobile']));
    $password = strip_tags(mysqli_real_escape_string($con,$data['password']));
    
    $chek = $con->query("SELECT 
                shop_details.shop_name,
                shop_settings.shop_id,
                shop_settings.shop_code
                FROM shop_settings
                INNER JOIN shop_details ON
                shop_settings.shop_id = shop_details.shop_id
                WHERE shop_settings.mobile_no = '$mobile' and shop_settings.password='$password'");
                
    $status = $con->query("select * from shop_details where status = '1' and (owner_mobile='$mobile' or manager_mobile = '$mobile')");

    if($status->num_rows != 0)
    {
        if($chek->num_rows !=0)
        {
            $c = $chek->fetch_assoc();
            $returnArr = array("merchant"=>$c,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Login successfully!");
        }
        else
        {
            $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Invalid Mobile-No or Password!");
        }
    }
    else  
    {
        $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"You're Not a Merchant!");
    }
}

echo json_encode($returnArr);
?>