function getBannersClicked($banid, $userid = null)
{
    $rarray = array();
    $update_qry = "UPDATE banners set number_of_click = number_of_click+1 where id={$banid}";
    if (updateByQuery($update_qry)) {
        if (!empty($userid)) {
            $add_details = findByIdArray($banid, 'banners');
            $already_exists_query = "SELECT * from point_details where type='B' and parent_id=" . $add_details['id'] . " and user_id=" . $userid;
            $if_exist = findByQuery($already_exists_query);
            echo '<pre>';
            //var_dump($add_details);
            var_dump($if_exist);
            //var_dump($add_details);
            if (!empty($add_details) && $add_details['target_click'] >= $add_details['number_of_click'] && empty($if_exist)) {
                $given_point_details = findByConditionArray(array('id' => $add_details['mpoint_name']), 'point_master');
                $given_point_exipre_date = $given_point_details[0]['expire_date'];
                $temp = array();
                $temp['user_id'] = $userid;
                $temp['points'] = $add_details['mpoint_get_per_click'];
                $temp['point_id'] = $add_details['mpoint_name'];
                $temp['merchant_id'] = $add_details['merchant_id'];
                $temp['source'] = "earn from banner click";
                $temp['type'] = 'B';
                $temp['parent_id'] = $add_details['id'];
                $temp['date'] = $add_details['start_date'];
                $temp['expire_date'] = $given_point_exipre_date;
                $temp['redeemed_points'] = 0;
                $temp['redeemed_points'] = 0;
                $temp['remaining_points'] = $add_details['mpoint_get_per_click'];
                $t = add(json_encode(array('save_data' => $temp)), 'points');
                $temp = array();
                $temp['user_id'] = $userid;
                $temp['points'] = $add_details['mpoint_get_per_click'];
                $temp['point_id'] = $add_details['mpoint_name'];
                $temp['merchant_id'] = $add_details['merchant_id'];
                $temp['source'] = "earn from banner click";
                $temp['type'] = 'B';
                $temp['parent_id'] = $add_details['id'];
                $temp['date'] = $add_details['start_date'];
                $temp['expire_date'] = $given_point_exipre_date;
                $temp['redeemed_points'] = 0;
                $temp['remaining_points'] = $add_details['mpoint_get_per_click'];
                $temp['transaction_type'] = 0;
                $t = add(json_encode(array('save_data' => $temp)), 'point_details');
                $rarray = array('type' => 'success', 'message' => 'Congratulation. You have got ' . $add_details['mpoint_get_per_click'] . ' m-points.');
            } else {
                //echo 'helllo';
                //$rarray = array('type' => 'error', 'message' => 'Banners not found.');
            }
        } else {
            $rarray = array('type' => 'success', 'message' => 'Banners clicked successfully.');
        }
    } else {
        $rarray = array('type' => 'error', 'message' => 'Internal error. Please try again later.');
    }
    echo json_encode($rarray);
}
function cornForCartValidity()
{
    $cur_time = time();
    //echo $cur_time;
    $cartsql = "select * from cart where  validity <= '" . $cur_time . "'";
    $cartres = findByQuery($cartsql);
    if (!empty($cartres)) {
        foreach ($cartres as $cartres_key => $cartres_val) {
            $offer_id = $cartres_val['offer_id'];
            $offer_qty = $cartres_val['quantity'];
            $cart_id = $cartres_val['id'];
            //$offer_details = findByConditionArray(array('id' => $offer_id),'offers');
            //print_r
            $up_query = "UPDATE offers SET buy_count=buy_count -" . $offer_qty . " where id=" . $offer_id;
            updateByQuery($up_query);
            delete('cart', $cart_id);
        }
    }
}
function updateCheckType()
{
    $request = Slim::getInstance()->request();
    $body = json_decode($request->getBody());
    //print_r($body);
    //exit;
    $rarray = array();
    if (!empty($body->item)) {
        foreach ($body->item as $bodykey => $bodyval) {
            if ($bodyval->payments == 1) {
                $payment = 1;
            } else {
                $payment = 0;
            }
            if ($bodyval->paymentscash == 1) {
                $paymentcash = 1;
            } else {
                $paymentcash = 0;
            }
            //$item = $body->item;
            $offer_id = $bodyval->offer_id;
            $query = "UPDATE cart set price=" . $paymentcash . ", point=" . $payment . " where user_id=" . $body->user_id . " and offer_id=" . $bodyval->offer_id;
            updateByQuery($query);
        }
        //foreach()
    }
    $rarray = array('type' => 'success', 'data' => 'ok');
    echo json_encode($rarray);
}