function getAllBlogs() { $rarray = array(); $conditions = array(); $restaurants = findByConditionArray(array(), 'blogs'); if (!empty($restaurants)) { $restaurants = array_map(function ($t) { $s = array(); $user = findByIdArray($t['user_id'], 'users'); $s['id'] = $t['id']; $s['user_id'] = $t['user_id']; //$s['merchant_name'] = (!empty($user['merchant_name'])?$user['merchant_name']:''); $s['title'] = $t['title']; $s['description'] = $t['description']; $s['image'] = $t['image']; if (!empty($s['image'])) { $s['image_url'] = SITEURL . 'blog_images/' . $s['image']; } $s['money_point'] = $t['money_point']; $s['posted_on'] = date('d M, Y h:i A', strtotime($t['posted_on'])); //$t['restaurant'] = findByIdArray( $t['restaurant_id'],'restaurants'); return $s; }, $restaurants); $rarray = array('type' => 'success', 'data' => $restaurants); } else { $rarray = array('type' => 'error', 'message' => 'No blogs found'); } echo json_encode($rarray); }
function getMerchantMenuCategory($user_id) { $rarray = array(); $result = findByConditionArray(array('user_id' => $user_id), 'merchant_menu_categories'); if (!empty($result)) { $rarray = array('type' => 'success', 'data' => $result); } else { $rarray = array('type' => 'error', 'message' => 'No category found.', 'data' => array()); } echo json_encode($rarray); }
function getAllActiveOfferType() { $rarray = array(); $offer_types = findByConditionArray(array('is_active' => 1), 'offer_types'); if (!empty($offer_types)) { $rarray = array("type" => "success", "data" => $offer_types); } else { $rarray = array("type" => "error", "message" => "No offer type found."); } echo json_encode($rarray); exit; }
function getMerchantsRestaurants($merchant_id) { $rarray = array(); $restaturants = findByConditionArray(array('user_id' => $merchant_id), 'merchantrestaurants'); if (!empty($restaturants)) { $restaturants = array_map(function ($s) { $s['imageurl'] = SITEURL . 'merchantrestaurant_images/' . $s['logo']; $s['iconurl'] = ""; if (!empty($s['icon'])) { $s['iconurl'] = SITEURL . 'merchantrestaurant_icon/' . $s['icon']; } return $s; }, $restaturants); $rarray = array('type' => 'success', 'restaurants' => $restaturants); } else { $rarray = array('type' => 'error', 'message' => 'No restaurants found.'); } echo json_encode($rarray); }
function getMerchantsOutlet($id) { $rarray = array(); $conditions = array(); $conditions['user_id'] = $id; $restaurants = findByConditionArray($conditions, 'merchantoutlets'); if (!empty($restaurants)) { $restaurants = array_map(function ($t) { $location = findByIdArray($t['location_id'], 'locations'); $t['city'] = $location['city']; $t['imageurl'] = SITEURL . 'merchantoutlet_images/' . $t['image']; return $t; }, $restaurants); for ($i = 0; $i < count($restaurants); $i++) { $restaurants[$i]['locations'] = json_decode(findByCondition(array('outlet_id' => $restaurants[$i]['id']), 'merchantoutlet_location_map')); } $rarray = array('type' => 'success', 'data' => $restaurants); } else { $rarray = array('type' => 'error', 'message' => 'No outlets found'); } echo json_encode($rarray); }
function getOutletDetails($id) { $rarray = array(); $temp = array(); $conditions = array(); $restaurants = findByIdArray($id, 'outlets'); if (!empty($restaurants)) { $temp['outlet'] = $restaurants; //$temp['location'] = findByIdArray( $restaurants['location_id'],'locations'); $temp['categories'] = findByConditionArray(array('outlet_id' => $id), 'outlet_category_map'); $temp['locations'] = findByConditionArray(array('outlet_id' => $id), 'outlet_location_map'); $rarray = array('type' => 'success', 'data' => $temp); } else { $rarray = array('type' => 'error', 'message' => 'No outlets found'); } echo json_encode($rarray); }
function getAllSubUserByUser($user_id) { $rarray = array(); $subusers = findByConditionArray(array('parent_id' => $user_id), 'users'); if (!empty($subusers)) { $subusers = array_map(function ($t) { if (!empty($t['roll'])) { if ($t['roll'] == 1) { $t['roll_name'] = "Back Office"; } else { if ($t['roll'] == 2) { $t['roll_name'] = "Operational"; } else { if ($t['roll'] == 3) { $t['roll_name'] = "Admin"; } } } } return $t; }, $subusers); $rarray = array('type' => 'success', 'data' => $subusers); } else { $rarray = array('type' => 'error', 'message' => 'No Sub User Found'); } echo json_encode($rarray); }
function success_payment() { $rarray = array(); if (!empty($_POST)) { $data = array(); $data['is_paid'] = 'P'; $payment_id = $_POST['payment_id']; $details = editByField(json_encode(array('save_data' => $data)), 'orders', array('payment_id' => $payment_id)); if ($details) { $sql = "SELECT * FROM orders WHERE payment_id=:payment_id"; $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("payment_id", $payment_id); $stmt->execute(); $user = $stmt->fetchObject(); $db = null; if ($user) { $userforEmail = findByConditionArray(array('id' => $user->user_id), 'users'); $emailForEmail = $userforEmail[0]['email']; $nameForEmail = $userforEmail[0]['first_name'] . ' ' . $userforEmail[0]['last_name']; $toMain = $emailForEmail; //'*****@*****.**'; $subjectMain = 'Download App Link'; $bodyMain = '<html><body><p>Dear ' . $nameForEmail . ',</p> <p>You can download the app from the link below:<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"><a href="https://linkmaker.itunes.apple.com/en-us/" target="_blank">Download From Apple Store</a> | <a href="https://play.google.com/store?utm_source=apac_med&utm_medium=hasem&utm_content=Jun2515&utm_campaign=evergreen&pcampaignid=MKT-DR-apac-in-all-med-hasem-py-evergreen-Jun2515-1-en-bkws&gclid=Cj0KEQjwzq63BRCrtIuGjImRoIIBEiQAGLHdYT7z3GaJyAPj3q9T0zqoX5Try5Eh6WEgR8Dvh7EEnMgaAscR8P8HAQ&gclsrc=aw.ds" target="_blank">Download From Google Store</a> </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; //echo $user->id; $sql = "SELECT * FROM order_details WHERE order_id=:order_id"; $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("order_id", $user->id); $stmt->execute(); $order_details = $stmt->fetchAll(PDO::FETCH_OBJ); $db = null; foreach ($order_details as $order_detail) { if ($order_detail->typemem == 'App' || $order_detail->typemem == 'Both') { sendMail($toMain, $subjectMain, $bodyMain); } if ($order_detail->event == 0) { $qty = $order_detail->quantity; $offer_details = json_decode(findById($order_detail->offer_id, 'offers')); //print_r($offer_details); $merchant_id = ''; $offer_id = ''; $point_id = ''; $point = ''; $merchant_id = $offer_details->merchant_id; $offer_id = $offer_details->id; $point_id = $offer_details->given_point_master_id; $needed_point_id = $offer_details->point_master_id; $point = $offer_details->mpoints_given; $given_point_details = findByConditionArray(array('id' => $point_id), 'point_master'); $given_point_exipre_date = $given_point_details[0]['expire_date']; if ($order_detail->resell == 0) { for ($i = 0; $i < $qty; $i++) { if ($offer_details->conditions == 0) { $voucher_data = array(); $voucher_data['offer_id'] = $order_detail->offer_id; $voucher_data['created_on'] = date('Y-m-d h:i:s'); $voucher_data['price'] = $offer_details->price; $voucher_data['offer_price'] = $offer_details->offer_price; $voucher_data['offer_percent'] = $offer_details->offer_percent; $voucher_data['from_date'] = $offer_details->offer_from_date; $voucher_data['to_date'] = $offer_details->offer_to_date; if ($offer_details->start_date_type == 'P') { $voucher_data['item_start_date'] = date('Y-m-d'); $voucher_data['item_expire_date'] = date('Y-m-d', strtotime("+" . $offer_details->valid_days . " days")); } else { $voucher_data['item_start_date'] = $offer_details->item_start_date; $voucher_data['item_expire_date'] = $offer_details->item_expire_date; } $voucher_data['item_start_hour'] = $offer_details->item_start_hour; $voucher_data['item_end_hour'] = $offer_details->item_end_hour; $voucher_data['is_active'] = 1; $voucher_data['purchase_type'] = 0; $s = add(json_encode(array('save_data' => $voucher_data)), 'vouchers'); $s = json_decode($s); //print_r($s); exit; $owner_data = array(); $owner_data['offer_id'] = $order_detail->offer_id; $owner_data['voucher_id'] = $s->id; $owner_data['from_user_id'] = 0; $owner_data['to_user_id'] = $order_detail->user_id; $owner_data['purchased_date'] = date('Y-m-d h:i:s'); $owner_data['is_active'] = 1; $owner_data['price'] = $offer_details->price; $owner_data['offer_price'] = $offer_details->offer_price; $owner_data['offer_percent'] = $offer_details->offer_percent; $owner_data['buy_price'] = $offer_details->offer_price; add(json_encode(array('save_data' => $owner_data)), 'voucher_owner'); $point_data = array(); $point_data['offer_id'] = $offer_id; $point_data['points'] = $point; $point_data['source'] = 'earn from promo click'; $point_data['user_id'] = $order_detail->user_id; $point_data['date'] = date('Y-m-d h:i:s'); $point_data['type'] = 'P'; $point_data['remaining_points'] = $point; $point_data['merchant_id'] = $merchant_id; $point_data['point_id'] = $point_id; $point_data['expire_date'] = $given_point_exipre_date; add(json_encode(array('save_data' => $point_data)), 'points'); $point_detail_data = array(); $point_detail_data['offer_id'] = $offer_id; $point_detail_data['points'] = $point; $point_detail_data['source'] = 'earn from promo click'; $point_detail_data['user_id'] = $order_detail->user_id; $point_detail_data['date'] = date('Y-m-d h:i:s'); $point_detail_data['type'] = 'P'; $point_detail_data['remaining_points'] = $point; $point_detail_data['merchant_id'] = $merchant_id; $point_detail_data['point_id'] = $point_id; $point_detail_data['expire_date'] = $given_point_exipre_date; $point_detail_data['transaction_type'] = 0; add(json_encode(array('save_data' => $point_detail_data)), 'point_details'); } } /********* Update Offer *************/ //$up_query = "UPDATE offers SET buy_count=buy_count+".$order_detail->quantity." where id=".$order_detail->offer_id; //updateByQuery($up_query); } elseif ($order_detail->resell == 1) { $resell_id = $order_detail->resell_id; $resellInfo = findByConditionArray(array('id' => $resell_id), 'voucher_resales'); $resell_point_id = $resellInfo[0]['point_id']; $resell_user_id = $resellInfo[0]['user_id']; $resell_price = $resellInfo[0]['price']; $to_user_id = $order_detail->user_id; $resellUserInfo = findByConditionArray(array('id' => $resell_user_id), 'users'); $toUserInfo = findByConditionArray(array('id' => $to_user_id), 'users'); $resell_user_email = $resellUserInfo[0]['email']; $to_user_email = $toUserInfo[0]['email']; $to_user_name = $toUserInfo[0]['first_name'] . ' ' . $toUserInfo[0]['last_name']; $resell_user_name = $resellUserInfo[0]['first_name'] . ' ' . $resellUserInfo[0]['last_name']; $mCashInfo = findByConditionArray(array('name' => 'mCash'), 'point_master'); $money_point = $mCashInfo[0]['money_point']; $point_val = $mCashInfo[0]['value']; $mCashExpireDate = $mCashInfo[0]['expire_date']; $mCashPointId = $mCashInfo[0]['id']; $total_point = round($resell_price / $point_val); $resell_voucher_id = $resellInfo[0]['voucher_id']; $voucherDetail = findByConditionArray(array('id' => $resell_voucher_id), 'vouchers'); $resellbidInfo = findByConditionArray(array('voucher_id' => $resell_voucher_id, 'user_id' => $to_user_id), 'voucher_bids'); if (empty($resellbidInfo)) { $resellownerInfo = findByConditionArray(array('voucher_id' => $resell_voucher_id, 'is_active' => 1), 'voucher_owner'); $voucher_owner_id = $resellownerInfo[0]['id']; $save_data = array(); $save_data['save_data']['voucher_status'] = 0; $voucher_edit = edit(json_encode($save_data), 'vouchers', $resell_voucher_id); $save_data = array(); $save_data['save_data']['resell_type'] = 2; $save_data['save_data']['is_active'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_owner', $voucher_owner_id); $save_data = array(); $save_data['save_data']['ispayment'] = 0; $save_data['save_data']['is_sold'] = '1'; $save_data['save_data']['sold_on'] = date('Y-m-d h:i:s'); $save_data['save_data']['accept_date'] = date('Y-m-d h:i:s'); $voucher_owner_edit = edit(json_encode($save_data), 'voucher_resales', $resell_id); $data = array(); $data['voucher_id'] = $resell_voucher_id; $data['offer_id'] = $voucherDetail[0]['offer_id']; $data['voucher_view_id'] = $voucherDetail[0]['view_id']; $data['from_user_id'] = $resell_user_id; $data['to_user_id'] = $to_user_id; $data['price'] = $voucherDetail[0]['price']; $data['offer_price'] = $voucherDetail[0]['offer_price']; $data['offer_percent'] = $voucherDetail[0]['offer_percent']; $data['is_active'] = '1'; $data['buy_price'] = $resell_price; $data['purchased_date'] = date('Y-m-d h:i:s'); $data['resell_type'] = 0; $data['owner_id'] = $voucher_owner_id; $newinfo['save_data'] = $data; $new_owner_details = add(json_encode($newinfo), 'voucher_owner'); } else { $resellownerInfo = findByConditionArray(array('voucher_id' => $resell_voucher_id, 'is_active' => 1), 'voucher_owner'); $voucher_owner_id = $resellownerInfo[0]['id']; $save_data = array(); $save_data['save_data']['voucher_status'] = 0; $voucher_edit = edit(json_encode($save_data), 'vouchers', $resell_voucher_id); $save_data = array(); $save_data['save_data']['resell_type'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_owner', $voucher_owner_id); $save_data = array(); $save_data['save_data']['ispayment'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_resales', $resell_id); } //$resellPointInfo = findByConditionArray(array('id' => $resell_point_id),'point_master'); if ($money_point == 1) { $point_detail_data = array(); $point_detail_data['offer_id'] = 0; $point_detail_data['points'] = $total_point; $point_detail_data['source'] = 'earn from promo click'; $point_detail_data['user_id'] = $resell_user_id; $point_detail_data['date'] = date('Y-m-d h:i:s'); $point_detail_data['type'] = 'P'; $point_detail_data['remaining_points'] = $total_point; $point_detail_data['merchant_id'] = 0; $point_detail_data['point_id'] = $mCashPointId; $point_detail_data['expire_date'] = $mCashExpireDate; $point_detail_data['transaction_type'] = 0; add(json_encode(array('save_data' => $point_detail_data)), 'point_details'); } $from = ADMINEMAIL; //$to = $saveresales->email; $to = $to_user_email; //'*****@*****.**'; $sviewid = 'MFG-000000000' . $voucherDetail[0]['id']; $sstartdate = date('d M, Y', strtotime($voucherDetail[0]['item_start_date'])); $senddate = date('d M, Y', strtotime($voucherDetail[0]['item_expire_date'])); $sprice = $voucherDetail[0]['price']; $resaleprice = $resell_price; $svname = $offer_details->title; $subject = 'Payment successfully'; $body = '<html><body><p>Dear ' . $to_user_name . ',</p> <p>You have successfully made payment for resell voucher<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Id :</span>' . $sviewid . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Name :</span>' . $svname . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Start Date :</span>' . $sstartdate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher End Date :</span>' . $senddate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher price :</span>' . $sprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Sell price :</span>' . $resaleprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">If we can help you with anything in the meantime just let us know by e-mailing </span>' . $from . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"></span><span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">! </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; sendMail($to, $subject, $body); $from = ADMINEMAIL; //$to = $saveresales->email; $to1 = $resell_user_email; //'*****@*****.**'; $subject1 = $to_user_name . ' has successfully made payment for your voucher'; $body1 = '<html><body><p>Dear ' . $resell_user_name . ',</p> <p> You have successfully sold voucher to ' . $to_user_name . '.<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Id :</span>' . $sviewid . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Name :</span>' . $svname . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Start Date :</span>' . $sstartdate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher End Date :</span>' . $senddate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher price :</span>' . $sprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Sell price :</span>' . $resaleprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">If we can help you with anything in the meantime just let us know by e-mailing </span>' . $from . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"></span><span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">! </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; sendMail($to1, $subject1, $body1); } } else { $event_id = $order_detail->event_id; $bid_id = $order_detail->event_bid_id; $temp = array(); $temp['event_id'] = $event_id; editByField(json_encode(array('save_data' => array('is_accepted' => 2))), 'event_bids', $temp); $t = edit(json_encode(array('save_data' => array('is_accepted' => 1))), 'event_bids', $bid_id); edit(json_encode(array('save_data' => array('status' => 'C'))), 'events', $event_id); $bidInfo = findByConditionArray(array('id' => $bid_id), 'event_bids'); $bid_user_id = $bidInfo[0]['user_id']; $from_user_id = $order_detail->user_id; $bidUserInfo = findByConditionArray(array('id' => $bid_user_id), 'users'); $fromUserInfo = findByConditionArray(array('id' => $from_user_id), 'users'); $bid_user_email = $bidUserInfo[0]['email']; $from_user_email = $fromUserInfo[0]['email']; $from_user_name = $fromUserInfo[0]['first_name'] . ' ' . $fromUserInfo[0]['last_name']; $bid_user_name = $bidUserInfo[0]['first_name'] . ' ' . $bidUserInfo[0]['last_name']; $from = ADMINEMAIL; //$to = $saveresales->email; $to1 = $bid_user_email; //$to1 = '*****@*****.**'; $subject1 = $from_user_name . ' accept the event that you have bidded and successfully made payment for the event'; $body1 = '<html><body><p>Dear ' . $bid_user_name . ',</p> <p> ' . $from_user_name . ' accept the event that you have bidded and successfully made payment for the event<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">If we can help you with anything in the meantime just let us know by e-mailing </span>' . $from . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"></span><span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">! </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; sendMail($to1, $subject1, $body1); } } // $orders = getlist('order_details',array('order_id' => $user->id)); //print_r($orders); } //print_r($user); //exit; } $rarray = array('type' => 'success'); } else { $rarray = array('type' => 'error'); } echo json_encode($rarray); exit; }
function getRestaurantByMerchant($id) { $rarray = array(); if (!empty($id)) { $restaurants = findByConditionArray(array('user_id' => $id), 'restaurants'); // print_r($restaurants); // exit; if (!empty($restaurants)) { $restaurants = array_map(function ($t) { if (!empty($t['logo'])) { $t['logo_url'] = SITEURL . "restaurant_images/" . $t['logo']; } $t['categories'] = findByConditionArray(array('restaurant_id' => $t['id']), 'resturant_category_map'); // $t['loaction'] = findByIdArray($t['location_id'],'locations'); return $t; }, $restaurants); $rarray = array('type' => 'success', 'restaurants' => $restaurants); } else { $rarray = array('type' => 'error', 'message' => 'No restaurant found.'); } } echo json_encode($rarray); }
function getMerchantsRelatedEvents($id) { $rarray = array(); $events = array(); $loc_events = array(); $cat_events = array(); if ($id) { $merchant_id = $id; $merchant_details = findByIdArray($merchant_id, 'users'); //print_r($merchant_details); $outlet_categories = array(); if (!empty($merchant_details)) { $merchant_outlets = findByConditionArray(array('user_id' => $merchant_id), 'outlets'); if (!empty($merchant_outlets)) { $outlet_ids = array_column($merchant_outlets, 'id'); $outlet_locations = array_column($merchant_outlets, 'location_id'); foreach ($outlet_ids as $oid) { $categories = findByConditionArray(array('outlet_id' => $oid), 'outlet_category_map'); foreach ($categories as $cat) { array_push($outlet_categories, $cat['category_id']); } // $outlet_categories.push } //$categories = findByConditionArray(array('outlet_id' => 'IN (1,2)'),'outlet_category_map'); //$outlet_categories = array_unique(array_column($categories, 'category_id')); //$db = getConnection(); //$in = str_repeat('?,', count($outlet_locations) - 1) . '?'; $sql = "SELECT * FROM event_location_map WHERE location_id in(" . implode(',', $outlet_locations) . ")"; //$stm = $db->prepare($sql); //$stm->execute($outlet_locations); $data = findByQuery($sql); if (!empty($data)) { $events = array_column($data, 'event_id'); } //$in = str_repeat('?,', count($outlet_categories) - 1) . '?'; $sql = "SELECT * FROM event_category_map WHERE category_id in(" . implode(',', $outlet_categories) . ")"; //$stm = $db->prepare($sql); //$stm->execute($outlet_categories); $cat_data = findByQuery($sql); //print_r($events); if (!empty($cat_data)) { $cat_events = array_column($cat_data, 'event_id'); if (!empty($cat_events)) { foreach ($cat_events as $ta) { $events[] = $ta; } } } //print_r($loc_events); //print_r($cat_events); //array_push($events, $loc_events, $cat_events); $events = array_values(array_unique($events)); //print_r($events); if (!empty($events)) { $tdt = date('Y-m-d H:i:s'); //$event_in = str_repeat('?,', count($events) - 1) . '?'; $sql = "SELECT * FROM events WHERE id in(" . implode(',', $events) . ") and offer_to_date > '" . $tdt . "' and status Not in('C','E')"; //$db = getConnection(); //$stmt = $db->prepare($sql); //$stmt->bindParam("user_id", $user_id); // $stmt->execute($events); $points = findByQuery($sql); //print_r($points); //exit; $count = count($points); for ($i = 0; $i < $count; $i++) { $eveBid = findByConditionArray(array('event_id' => $points[$i]['id'], 'user_id' => $merchant_id), 'event_bids'); $today = date('Y-m-d'); $checkdate = date('Y-m-d', strtotime($points[$i]['offer_to_date'])); $sql = "SELECT Max(price) as price FROM event_bids WHERE event_id = " . $points[$i]['id'] . ""; $maxp = findByQuery($sql); //echo '<pre>';print_r($maxp); $points[$i]['bid_price'] = number_format($maxp[0]['price'], 2, '.', ','); //echo 'Event_id:'.$points[$i]['id'].'| UserId:'.$merchant_id.'<br>'; //echo '<pre>';print_r($eveBid); if (!empty($eveBid)) { $points[$i]['is_bid'] = true; } else { $points[$i]['is_bid'] = false; } $created_on = date('m/d/Y', strtotime($points[$i]['created_on'])); $points[$i]['created_on'] = $created_on; $from_date = date('m/d/Y', strtotime($points[$i]['offer_from_date'])); $points[$i]['offer_from_date'] = $from_date; $to_date = date('m/d/Y', strtotime($points[$i]['offer_to_date'])); $points[$i]['offer_to_date'] = $to_date; $event_date = date('m/d/Y', strtotime($points[$i]['from_date'])); $points[$i]['event_date'] = $event_date; $event_start_time = date('h:i A', strtotime($points[$i]['from_date'])); $points[$i]['event_start_time'] = $event_start_time; $event_end_time = date('h:i A', strtotime($points[$i]['to_date'])); $points[$i]['event_end_time'] = $event_end_time; if (!empty($points[$i]['image'])) { $points[$i]['image_url'] = SITEURL . 'event_images/' . $points[$i]['image']; } if ($checkdate < $today) { $points[$i]['status'] = 'Expired'; } else { if ($points[$i]['status'] == 'O') { if ($points[$i]['is_bid']) { $points[$i]['status'] = 'Bid'; } else { $points[$i]['status'] = 'Open'; } } else { if ($points[$i]['status'] == 'E') { $points[$i]['status'] = 'Expired'; } else { $points[$i]['status'] = 'Completed'; } } } $points[$i]['categories'] = json_decode(findByCondition(array('event_id' => $points[$i]['id']), 'event_category_map')); $points[$i]['locations'] = json_decode(findByCondition(array('event_id' => $points[$i]['id']), 'event_location_map')); } /*if(!empty($points)) { $points = array_map(function($t,$k){ $t->sl = $k+1; //$t->type = ($t->type=='C'?'Credit':'Debit'); $t->date = date('m/d/Y', strtotime($t->date)); $t->expire_date = date('m/d/Y', strtotime($t->expire_date)); return $t; }, $points, array_keys($points)); }*/ $rarray = array('status' => 'success', 'data' => $points); //} } else { $rarray = array('type' => 'error', 'message' => 'No events found.'); } } else { $rarray = array('type' => 'error', 'message' => 'No outlet found'); } } else { $rarray = array('type' => 'error', 'message' => 'Merchant not found.'); } } echo json_encode($rarray); }
function getNewsByMerchant($id) { $rarray = array(); $details = findByConditionArray(array('user_id' => $id), 'news'); if (!empty($details)) { $details = array_map(function ($t) { if (!empty($t['image'])) { $t['imageurl'] = SITEURL . 'news_images/' . $t['image']; } $t['published_date'] = date('m/d/Y', strtotime($t['published_date'])); $restaurants = findByConditionArray(array('news_id' => $t['id']), 'news_restaurant_map'); if (!empty($restaurants)) { $t['restaurants_ids'] = array_map(function ($s) { $s['id'] = $s['restaurant_id']; return $s; }, $restaurants); $t['restaurants_ids'] = array_column($restaurants, 'restaurant_id'); } else { $t['restaurants_ids'] = array(); } return $t; }, $details); $rarray = array("type" => "success", "data" => $details); } else { $rarray = array("type" => "error", "data" => array(), "message" => "Sorry no news found."); } echo json_encode($rarray); exit; }
function addMemberUser() { $request = Slim::getInstance()->request(); $body = json_decode($request->getBody()); $body->created_dete = date('Y-m-d H:i:s'); $unique_field = array(); $unique_field['email'] = $body->email; //$unique_field['username']=$user->username; $rowCount = rowCount(json_encode($unique_field), 'users'); if ($rowCount == 0) { $from = ADMINEMAIL; //$to = $saveresales->email; $to = $body->email; //'*****@*****.**'; $subject = 'Register in mFoodGate'; $bodyy = '<html><body><p>Dear ' . $body->name . ',</p><br /> <span style="color:rgb(77, 76, 76); font-family:helvetica,arial">You need to register, please <a href="' . WEBSITEURL . 'register/' . $body->email . '">Click Here</a> </span><span style="color:rgb(77, 76, 76); font-family:helvetica,arial"> to verify your account.</span><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">If we can help you with anything in the meantime just let us know by e-mailing </span>' . $from . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"></span><span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">! </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; //print_r($body); //exit; $offercondition = array('visible_id' => $body->offer_visible_id); $offer_details = findByConditionArray($offercondition, 'offers'); if (!empty($offer_details)) { sendMail($to, $subject, $bodyy); //$body->offer_id = $body->offer_visible_id; $body->membership_start_date = date('Y-m-d h:i:s', strtotime($body->membership_start_date)); $body->membership_end_date = date('Y-m-d h:i:s', strtotime($body->membership_end_date)); //unset($body->offer_visible_id); //unset($body->member_start_date); //unset($body->member_end_date); $voucher_data = array(); $voucher_data['offer_id'] = $offer_details[0]['id']; $voucher_data['created_on'] = $body->membership_start_date; $voucher_data['price'] = $offer_details[0]['price']; $voucher_data['offer_price'] = $offer_details[0]['offer_price']; $voucher_data['offer_percent'] = $offer_details[0]['offer_percent']; $voucher_data['from_date'] = $body->membership_start_date; $voucher_data['to_date'] = $body->membership_end_date; $voucher_data['is_active'] = 1; $s = add(json_encode(array('save_data' => $voucher_data)), 'vouchers'); $s = json_decode($s); //print_r($s); exit; $owner_data = array(); $owner_data['offer_id'] = $offer_details[0]['id']; $owner_data['voucher_id'] = $s->id; $owner_data['from_user_id'] = 0; //$owner_data['to_user_id'] = $order_detail->user_id; $owner_data['purchased_date'] = $body->membership_start_date; $owner_data['is_active'] = 1; $owner_data['price'] = $offer_details[0]['price']; $owner_data['offer_price'] = $offer_details[0]['offer_price']; $owner_data['offer_percent'] = $offer_details[0]['offer_percent']; $owner_data['buy_price'] = $offer_details[0]['offer_price']; add(json_encode(array('save_data' => $owner_data)), 'voucher_owner'); $body->offer_id = $offer_details[0]['id']; $body->voucher_id = $s->id; unset($body->offer_visible_id); $allinfo['save_data'] = $body; $save_details = add(json_encode($allinfo), 'member_user_map'); $result = '{"type":"success","message":"Added succesfully and mail sent to the user"}'; } else { $result = '{"type":"failure","message":"offer_visible_id is not exist."}'; } } else { //exit; $condition = array('email' => $body->email); $user_details = findByConditionArray($condition, 'users'); //print_r($user_details); $user_id = $user_details[0]['id']; $body->user_id = $user_id; //print_r($body); //exit; $body->membership_start_date = date('Y-m-d h:i:s', strtotime($body->membership_start_date)); $body->membership_end_date = date('Y-m-d h:i:s', strtotime($body->membership_end_date)); //unset($body->offer_visible_id); //unset($body->member_start_date); //unset($body->member_end_date); $offercondition = array('visible_id' => $body->offer_visible_id); $offer_details = findByConditionArray($offercondition, 'offers'); //print_r($body); //print_r($offer_details); //exit; if (!empty($offer_details)) { $voucher_data = array(); $voucher_data['offer_id'] = $offer_details[0]['id']; $voucher_data['created_on'] = $body->membership_start_date; $voucher_data['price'] = $offer_details[0]['price']; $voucher_data['offer_price'] = $offer_details[0]['offer_price']; $voucher_data['offer_percent'] = $offer_details[0]['offer_percent']; $voucher_data['from_date'] = $body->membership_start_date; $voucher_data['to_date'] = $body->membership_end_date; $voucher_data['is_active'] = 1; $s = add(json_encode(array('save_data' => $voucher_data)), 'vouchers'); $s = json_decode($s); //print_r($s); exit; $owner_data = array(); $owner_data['offer_id'] = $offer_details[0]['id']; $owner_data['voucher_id'] = $s->id; $owner_data['from_user_id'] = 0; $owner_data['to_user_id'] = $user_id; $owner_data['purchased_date'] = $body->membership_start_date; $owner_data['is_active'] = 1; $owner_data['price'] = $offer_details[0]['price']; $owner_data['offer_price'] = $offer_details[0]['offer_price']; $owner_data['offer_percent'] = $offer_details[0]['offer_percent']; $owner_data['buy_price'] = $offer_details[0]['offer_price']; add(json_encode(array('save_data' => $owner_data)), 'voucher_owner'); $body->offer_id = $offer_details[0]['id']; $body->voucher_id = $s->id; unset($body->offer_visible_id); //print_r($body); //exit; $allinfo['save_data'] = $body; $save_details = add(json_encode($allinfo), 'member_user_map'); $result = '{"type":"success","message":"Added succesfully"}'; } else { $result = '{"type":"failure","message":"offer_visible_id is not exist."}'; } } echo $result; exit; }
function getRedeemVoucher($user_id) { $rarray = array(); $conditions = array(); $site_path = SITEURL; $allPromo = findByConditionArray(array('merchant_id' => $user_id), 'offers'); $all_promo_ids = array_column($allPromo, 'id'); //print_r($all_promo_ids); $reddeem_voucher_sql = "select merchantoutlets.title,merchantoutlets.restaurant_id,vouchers.id,vouchers.offer_id,vouchers.price,vouchers.offer_price,vouchers.to_date,vouchers.RedeemDate,vouchers.Status from vouchers,merchantoutlets where vouchers.redeem_outlet = merchantoutlets.outlet_id and vouchers.Status='redeem' and vouchers.offer_id in(" . implode(',', $all_promo_ids) . ")"; $reddeem_voucher_res = findByQuery($reddeem_voucher_sql); if (!empty($reddeem_voucher_res)) { foreach ($reddeem_voucher_res as $reddeem_voucher_res_key => $reddeem_voucher_res_val) { $reddeem_voucher_res[$reddeem_voucher_res_key]['price'] = number_format($reddeem_voucher_res[$reddeem_voucher_res_key]['price'], 0, '.', ','); $reddeem_voucher_res[$reddeem_voucher_res_key]['offer_price'] = number_format($reddeem_voucher_res[$reddeem_voucher_res_key]['offer_price'], 0, '.', ','); $reddeem_voucher_res[$reddeem_voucher_res_key]['to_date'] = date('m-d-Y', strtotime($reddeem_voucher_res[$reddeem_voucher_res_key]['to_date'])); $reddeem_voucher_res[$reddeem_voucher_res_key]['RedeemDate'] = date('m-d-Y', strtotime($reddeem_voucher_res[$reddeem_voucher_res_key]['RedeemDate'])); $offerdetail = findByIdArray($reddeem_voucher_res[$reddeem_voucher_res_key]['offer_id'], 'offers'); $reddeem_voucher_res[$reddeem_voucher_res_key]['offer_title'] = $offerdetail['title']; $reddeem_voucher_res[$reddeem_voucher_res_key]['voucher_number'] = 'MFG-000000000' . $offerdetail['id']; $restaurant_detail = findByIdArray($reddeem_voucher_res[$reddeem_voucher_res_key]['restaurant_id'], 'merchantrestaurants'); $reddeem_voucher_res[$reddeem_voucher_res_key]['restaurant_title'] = $offerdetail['title']; } $rarray = array('type' => 'success', 'data' => $reddeem_voucher_res); } else { $rarray = array('type' => 'success', 'data' => $reddeem_voucher_res); } echo json_encode($rarray); }
function updateCartQuantity() { $request = Slim::getInstance()->request(); $body = json_decode($request->getBody()); $rarray = array(); if (!empty($body->item)) { $item = $body->item; $offer_id = $item->offer_id; $promo_details = findByConditionArray(array('id' => $offer_id), 'offers'); //print_r($promo_details); $remaining_promo = $promo_details[0]['quantity'] - $promo_details[0]['buy_count']; $max_purchased = $promo_details[0]['max_purchased']; //$sql = "select * from voucher_owner where offer_id='".$offer_id."' and to_user_id='".$body->user_id."' and is_active=1"; //$voucher_result = findByQuery($sql); //$voucher_count = count($voucher_result); /*if($max_purchased > $voucher_count){ $qty = $max_purchased - $voucher_count; }else{ $qty = 0; }*/ //echo $max_purchased.'a'; //echo $qty.'b'; //echo $voucher_count.'c'; if ($item->quantity <= $remaining_promo) { if ($item->quantity <= $max_purchased) { if ($item->payments == true) { $point_id = $item->point_id; $needed_point = $item->mpoints; $needed_point = $needed_point * $item->quantity; $point_name = $item->point_name; $point_sql = "select * from point_details where user_id='" . $body->user_id . "' and point_id='" . $point_id . "'"; $point_res = findByQuery($point_sql); $available_point = 0; $total_point = 0; $redeem_point = 0; foreach ($point_res as $point_detail_val) { $total_point = $total_point + $point_detail_val['points']; $redeem_point = $redeem_point + $point_detail_val['redeemed_points']; } $available_point = $total_point - $redeem_point; if ($available_point >= $needed_point) { $query = "UPDATE cart set quantity=" . $item->quantity . " where user_id=" . $body->user_id . " and offer_id=" . $item->offer_id; updateByQuery($query); $rarray = array('type' => 'success', 'data' => 'ok'); } else { $rarray = array('type' => 'failure', 'data' => 'You dont have ' . $needed_point . ' ' . $point_name . ' point'); } } else { $query = "UPDATE cart set quantity=" . $item->quantity . " where user_id=" . $body->user_id . " and offer_id=" . $item->offer_id; updateByQuery($query); $rarray = array('type' => 'success', 'data' => 'ok'); } } else { $rarray = array('type' => 'failure', 'data' => 'Quantity must be less than of maximum purchased of this promo'); } } else { $rarray = array('type' => 'failure', 'data' => 'Quantity must be less than of remaining quantity'); } } echo json_encode($rarray); }
function getEventBidDetail($id) { $sql = "SELECT * from event_bids where event_bids.id=:id"; //echo $sql; $site_path = SITEURL; $offer_images = array(); $point_master_details = array(); try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("id", $id); $stmt->execute(); $offer = $stmt->fetchObject(); $count = $stmt->rowCount(); if ($count > 0) { $rid = $offer->resturant_id; $outlet_id = $offer->outlet_id; $event_id = $offer->event_id; $events = findById($event_id, 'events'); $events = json_decode($events); $allRes = findById($rid, 'merchantrestaurants'); $allRes = json_decode($allRes); $allOutlet = findById($outlet_id, 'merchantoutlets'); $allOutlet = json_decode($allOutlet); $promo_images = findByConditionArray(array('event_bid_id' => $id), 'event_bid_images'); if (!empty($promo_images)) { $prmcount = count($promo_images); for ($i = 0; $i < $prmcount; $i++) { $image = $site_path . "template_images/" . $promo_images[$i]['image']; $offer_images[$i]['image'] = $image; } } else { $image = $site_path . "template_images/default.png"; $offer_images[0]['image'] = $image; } $offer = json_encode($offer); $result = '{"type":"success","event_bid":' . $offer . ',"restaurant":' . json_encode($allRes) . ',"outlet":' . json_encode($allOutlet) . ',"events" : ' . json_encode($events) . ',"promo_images" : ' . json_encode($offer_images) . '}'; } else { $result = '{"type":"error","message":"Sorry no promo found"}'; } } catch (PDOException $e) { $result = '{"type":"error","message":' . $e->getMessage() . '}'; } echo $result; }
function checkResellPayment() { $cur_date = date('Y-m-d', strtotime("-3 days")); //echo $cur_date; $sql = "select * from voucher_resales where is_sold=1 and ispayment=1 and DATE(sold_on) <= '" . $cur_date . "'"; $res = findByQuery($sql); //echo '<pre>'; //print_r($res); if (!empty($res)) { foreach ($res as $key => $val) { $voucher_id = ''; $resell_id = ''; $voucher_id = $val['voucher_id']; $resell_id = $val['id']; //echo $resell_id; $voucherownerInfo = findByConditionArray(array('voucher_id' => $voucher_id, 'is_active' => 1), 'voucher_owner'); //print_r($voucherownerInfo); if (!empty($voucherownerInfo)) { $last_owner_id = $voucherownerInfo[0]['owner_id']; $owner_id = $voucherownerInfo[0]['id']; //echo $last_owner_id; //echo $owner_id; //exit; $save_data = array(); $save_data['save_data']['is_active'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_owner', $owner_id); //print_r($voucher_owner_edit); //exit; $save_data = array(); $save_data['save_data']['is_active'] = 1; $save_data['save_data']['resell_type'] = 0; $last_voucher_owner_edit = edit(json_encode($save_data), 'voucher_owner', $last_owner_id); } //$voucherresellInfo = findByConditionArray(array('id' => $resell_id),'voucher_resales'); //if(!empty($voucherresellInfo)){ $save_data = array(); $save_data['save_data']['is_sold'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_resales', $resell_id); //} $voucherResellBidInfo = findByConditionArray(array('voucher_resale_id' => $resell_id, 'is_accepted' => 1), 'voucher_bids'); if (!empty($voucherResellBidInfo)) { $bid_id = $voucherResellBidInfo[0]['id']; $save_data = array(); $save_data['save_data']['is_accepted'] = 0; $voucher_owner_bid_edit = edit(json_encode($save_data), 'voucher_bids', $bid_id); } } } }
function getAdsDetails($id) { $rarray = array(); $restaurant = findByIdArray($id, 'advertisements'); if (!empty($restaurant)) { $rarray['restaurant'] = $restaurant; if (!empty($restaurant['image'])) { $rarray['restaurant']['image_url'] = SITEURL . "advertisement_images/" . $restaurant['image']; } $rarray['locations'] = findByConditionArray(array('advertisement_id' => $id), 'advertisement_location_map'); $rarray['outlets'] = findByConditionArray(array('advertisement_id' => $id), 'advertisement_outlet_map'); $rarray['merchant'] = findByIdArray($restaurant['merchant_id'], 'users'); $result = json_encode(array('type' => "success", 'data' => $rarray)); } else { $result = '{type:"error",message:"Not Added"}'; } echo $result; exit; }
function redeemUserPoints() { $request = Slim::getInstance()->request(); $body = json_decode($request->getBody()); $user_id = $body->user_id; $points = $body->points; $needed_point = $points; $flag = 0; $carts = $body->cart; //print_r($carts); //exit; $offerr_id = $carts[0]->offer_id; $offer_detaill = json_decode(findById($offerr_id, 'offers')); $mer_id = $offer_detaill->merchant_id; //print_r($points); //print_r($carts); //exit; $rarray = array(); try { $points_left = $points; $points_redeemed = 0; $date = date('Y-m-d H:i:s'); /* $sql = "SELECT * FROM points WHERE user_id=:user_id and remaining_points>0 and merchant_id=:mer_id"; $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("user_id", $user_id); $stmt->bindParam("mer_id", $mer_id); //$stmt->bindParam("expire_date", $date); $stmt->execute(); $allpoints = $stmt->fetchAll(PDO::FETCH_OBJ);*/ //print_r($allpoints); //exit; /*if(!empty($allpoints)) { foreach($allpoints as $point) { if($points_left>0) { if($points_left>=$point->remaining_points) { //if($point->remaining_points>) //$temp = $points_redeemed $points_left = $points_left - $point->remaining_points; $points_redeemed = $points_redeemed + $point->remaining_points; $sqlInsert = 'UPDATE points set remaining_points=0, redeemed_points=redeemed_points + :redeemed_points, redeemed_date=:redeemed_date where id=:id'; $preparedStatement = $db->prepare($sqlInsert); $preparedStatement->bindParam("id", $point->id); $preparedStatement->bindParam("redeemed_points", $point->remaining_points); $preparedStatement->bindParam("redeemed_date",$date); $preparedStatement->execute(); } else { $rem_pt = $point->remaining_points - $points_left; $sqlInsert = 'UPDATE points set remaining_points=:remaining_points, redeemed_points= redeemed_points + :redeemed_points, redeemed_date=:redeemed_date where id=:id'; $preparedStatement = $db->prepare($sqlInsert); $preparedStatement->bindParam("id", $point->id); $preparedStatement->bindParam("remaining_points", $rem_pt); $preparedStatement->bindParam("redeemed_points", $points_left); $preparedStatement->bindParam("redeemed_date",$date); $preparedStatement->execute(); $points_left = 0; } } } }*/ //if($points_left==0) //{ foreach ($carts as $cart) { //print_r($cart); if ($cart->payments == 1) { if ($cart->resell == 0) { $offer_details = json_decode(findById($cart->offer_id, 'offers')); //print_r($offer_details); //exit; $merchant_id = ''; $offer_id = ''; $point_id = ''; $point = ''; $merchant_id = $offer_details->merchant_id; $offer_id = $offer_details->id; $point_id = $offer_details->given_point_master_id; $needed_point_id = $offer_details->point_master_id; $needed_point = $offer_details->mpoints; $point = $offer_details->mpoints_given; $given_point_details = findByConditionArray(array('id' => $point_id), 'point_master'); $given_point_exipre_date = $given_point_details[0]['expire_date']; $needed_point_details = findByConditionArray(array('id' => $needed_point_id), 'point_master'); $needed_point_exipre_date = $needed_point_details[0]['expire_date']; $qty = 0; $qty = $cart->quantity; for ($i = 0; $i < $qty; $i++) { $voucher_data = array(); $voucher_data['offer_id'] = $cart->offer_id; $voucher_data['created_on'] = $offer_details->created_on; $voucher_data['price'] = $offer_details->price; $voucher_data['offer_price'] = $offer_details->offer_price; $voucher_data['offer_percent'] = $offer_details->offer_percent; $voucher_data['from_date'] = $offer_details->offer_from_date; $voucher_data['to_date'] = $offer_details->offer_to_date; if ($offer_details->start_date_type == 'P') { $voucher_data['item_start_date'] = date('Y-m-d'); $voucher_data['item_expire_date'] = date('Y-m-d', strtotime("+" . $offer_details->valid_days . " days")); } else { $voucher_data['item_start_date'] = $offer_details->item_start_date; $voucher_data['item_expire_date'] = $offer_details->item_expire_date; } $voucher_data['is_active'] = 1; $voucher_data['purchase_type'] = 1; $s = add(json_encode(array('save_data' => $voucher_data)), 'vouchers'); $s = json_decode($s); $owner_data = array(); $owner_data['offer_id'] = $cart->offer_id; $owner_data['voucher_id'] = $s->id; $owner_data['from_user_id'] = 0; $owner_data['to_user_id'] = $user_id; $owner_data['purchased_date'] = date('Y-m-d h:i:s'); $owner_data['is_active'] = 1; $owner_data['price'] = $offer_details->price; $owner_data['offer_price'] = $offer_details->offer_price; $owner_data['offer_percent'] = $offer_details->offer_percent; $owner_data['buy_price'] = $offer_details->offer_price; add(json_encode(array('save_data' => $owner_data)), 'voucher_owner'); $point_data = array(); $point_data['offer_id'] = $offer_id; $point_data['points'] = $point; $point_data['source'] = 'earn from promo click'; $point_data['user_id'] = $user_id; $point_data['date'] = date('Y-m-d h:i:s'); $point_data['type'] = 'P'; $point_data['remaining_points'] = $point; $point_data['merchant_id'] = $merchant_id; $point_data['expire_date'] = $given_point_exipre_date; $point_data['point_id'] = $point_id; add(json_encode(array('save_data' => $point_data)), 'points'); $point_detail_data = array(); $point_detail_data['offer_id'] = $offer_id; $point_detail_data['points'] = 0; $point_detail_data['source'] = 'earn from promo click'; $point_detail_data['user_id'] = $user_id; $point_detail_data['date'] = date('Y-m-d h:i:s'); $point_detail_data['type'] = 'P'; $point_detail_data['remaining_points'] = 0; $point_detail_data['redeemed_points'] = $needed_point; $point_detail_data['merchant_id'] = $merchant_id; $point_detail_data['point_id'] = $needed_point_id; $point_detail_data['expire_date'] = $needed_point_exipre_date; $point_detail_data['redeemed_date'] = $date; $point_detail_data['transaction_type'] = 1; add(json_encode(array('save_data' => $point_detail_data)), 'point_details'); $point_detail_data = array(); $point_detail_data['offer_id'] = $offer_id; $point_detail_data['points'] = $point; $point_detail_data['source'] = 'earn from promo click'; $point_detail_data['user_id'] = $user_id; $point_detail_data['date'] = date('Y-m-d h:i:s'); $point_detail_data['type'] = 'P'; $point_detail_data['remaining_points'] = $point; $point_detail_data['merchant_id'] = $merchant_id; $point_detail_data['point_id'] = $point_id; $point_detail_data['expire_date'] = $given_point_exipre_date; $point_detail_data['transaction_type'] = 0; add(json_encode(array('save_data' => $point_detail_data)), 'point_details'); $flag = 1; } } elseif ($cart->resell == 1) { $resell_id = $cart->resell_id; $resellInfo = findByConditionArray(array('id' => $resell_id), 'voucher_resales'); $resell_point_id = $resellInfo[0]['point_id']; $resell_user_id = $resellInfo[0]['user_id']; $resell_price = $resellInfo[0]['price']; $resell_point = $resellInfo[0]['points']; $to_user_id = $user_id; $resellUserInfo = findByConditionArray(array('id' => $resell_user_id), 'users'); $toUserInfo = findByConditionArray(array('id' => $to_user_id), 'users'); $resell_user_email = $resellUserInfo[0]['email']; $to_user_email = $toUserInfo[0]['email']; $to_user_name = $toUserInfo[0]['first_name'] . ' ' . $toUserInfo[0]['last_name']; $resell_user_name = $resellUserInfo[0]['first_name'] . ' ' . $resellUserInfo[0]['last_name']; $mCashInfo = findByConditionArray(array('name' => 'mCash'), 'point_master'); $money_point = $mCashInfo[0]['money_point']; $point_val = $mCashInfo[0]['value']; $mCashExpireDate = $mCashInfo[0]['expire_date']; $mCashPointId = $mCashInfo[0]['id']; $total_point = round($resell_price / $point_val); $resellPointInfo = findByConditionArray(array('id' => $resell_point_id), 'point_master'); //$resell_point_val = $mCashInfo[0]['value']; $resellExpireDate = $resellPointInfo[0]['expire_date']; //$resellPointInfo = findByConditionArray(array('id' => $resell_point_id),'point_master'); $resell_voucher_id = $resellInfo[0]['voucher_id']; $resellbidInfo = findByConditionArray(array('voucher_id' => $resell_voucher_id, 'user_id' => $to_user_id), 'voucher_bids'); if (empty($resellbidInfo)) { $resellownerInfo = findByConditionArray(array('voucher_id' => $resell_voucher_id, 'is_active' => 1), 'voucher_owner'); $voucher_owner_id = $resellownerInfo[0]['id']; $voucherDetail = findByConditionArray(array('id' => $resell_voucher_id), 'vouchers'); $save_data = array(); $save_data['save_data']['voucher_status'] = 0; $voucher_edit = edit(json_encode($save_data), 'vouchers', $resell_voucher_id); $save_data = array(); $save_data['save_data']['resell_type'] = 2; $save_data['save_data']['is_active'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_owner', $voucher_owner_id); $save_data = array(); $save_data['save_data']['ispayment'] = 0; $save_data['save_data']['is_sold'] = '1'; $save_data['save_data']['sold_on'] = date('Y-m-d h:i:s'); $save_data['save_data']['accept_date'] = date('Y-m-d h:i:s'); $voucher_owner_edit = edit(json_encode($save_data), 'voucher_resales', $resell_id); $data = array(); $data['voucher_id'] = $resell_voucher_id; $data['offer_id'] = $voucherDetail[0]['offer_id']; $data['voucher_view_id'] = $voucherDetail[0]['view_id']; $data['from_user_id'] = $resell_user_id; $data['to_user_id'] = $to_user_id; $data['price'] = $voucherDetail[0]['price']; $data['offer_price'] = $voucherDetail[0]['offer_price']; $data['offer_percent'] = $voucherDetail[0]['offer_percent']; $data['is_active'] = '1'; $data['buy_price'] = $resell_price; $data['purchased_date'] = date('Y-m-d h:i:s'); $data['resell_type'] = 0; $data['owner_id'] = $voucher_owner_id; $newinfo['save_data'] = $data; $new_owner_details = add(json_encode($newinfo), 'voucher_owner'); } else { $resellownerInfo = findByConditionArray(array('voucher_id' => $resell_voucher_id, 'is_active' => 1), 'voucher_owner'); $voucher_owner_id = $resellownerInfo[0]['id']; $save_data = array(); $save_data['save_data']['voucher_status'] = 0; $voucher_edit = edit(json_encode($save_data), 'vouchers', $resell_voucher_id); $save_data = array(); $save_data['save_data']['resell_type'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_owner', $voucher_owner_id); $save_data = array(); $save_data['save_data']['ispayment'] = 0; $voucher_owner_edit = edit(json_encode($save_data), 'voucher_resales', $resell_id); } $point_detail_data = array(); $point_detail_data['offer_id'] = 0; $point_detail_data['points'] = 0; $point_detail_data['source'] = 'earn from promo click'; $point_detail_data['user_id'] = $user_id; $point_detail_data['date'] = date('Y-m-d h:i:s'); $point_detail_data['type'] = 'P'; $point_detail_data['remaining_points'] = 0; $point_detail_data['redeemed_points'] = $resell_point; $point_detail_data['merchant_id'] = 0; $point_detail_data['point_id'] = $resell_point_id; $point_detail_data['expire_date'] = $resellExpireDate; $point_detail_data['redeemed_date'] = $date; $point_detail_data['transaction_type'] = 1; add(json_encode(array('save_data' => $point_detail_data)), 'point_details'); if ($money_point == 1) { $point_detail_data = array(); $point_detail_data['offer_id'] = 0; $point_detail_data['points'] = $total_point; $point_detail_data['source'] = 'earn from promo click'; $point_detail_data['user_id'] = $resell_user_id; $point_detail_data['date'] = date('Y-m-d h:i:s'); $point_detail_data['type'] = 'P'; $point_detail_data['remaining_points'] = $total_point; $point_detail_data['merchant_id'] = 0; $point_detail_data['point_id'] = $mCashPointId; $point_detail_data['expire_date'] = $mCashExpireDate; $point_detail_data['transaction_type'] = 0; add(json_encode(array('save_data' => $point_detail_data)), 'point_details'); } $from = ADMINEMAIL; //$to = $saveresales->email; $to = $to_user_email; //'*****@*****.**'; $sviewid = 'MFG-000000000' . $voucherDetail[0]['id']; $sstartdate = date('d M, Y', strtotime($voucherDetail[0]['item_start_date'])); $senddate = date('d M, Y', strtotime($voucherDetail[0]['item_expire_date'])); $sprice = $voucherDetail[0]['price']; $resaleprice = $resell_price; $svname = $offer_details->title; $subject = 'Payment successfully'; $body = '<html><body><p>Dear ' . $to_user_name . ',</p> <p>You have successfully made payment for resell voucher<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Id :</span>' . $sviewid . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Name :</span>' . $svname . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Start Date :</span>' . $sstartdate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher End Date :</span>' . $senddate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher price :</span>' . $sprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Sell price :</span>' . $resaleprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">If we can help you with anything in the meantime just let us know by e-mailing </span>' . $from . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"></span><span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">! </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; sendMail($to, $subject, $body); $from = ADMINEMAIL; //$to = $saveresales->email; $to1 = $resell_user_email; //'*****@*****.**'; $subject1 = $to_user_name . ' has successfully made payment for your voucher'; $body1 = '<html><body><p>Dear ' . $resell_user_name . ',</p> <p> You have successfully sold voucher to ' . $to_user_name . '.<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Id :</span>' . $sviewid . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Name :</span>' . $svname . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher Start Date :</span>' . $sstartdate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher End Date :</span>' . $senddate . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Voucher price :</span>' . $sprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">Sell price :</span>' . $resaleprice . '<br /><br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">If we can help you with anything in the meantime just let us know by e-mailing </span>' . $from . '<br /> <span style="color:rgb(34, 34, 34); font-family:arial,sans-serif"></span><span style="color:rgb(34, 34, 34); font-family:arial,sans-serif">! </span></p> <p>Thanks,<br /> mFood Team</p> <p> </p></body></html>'; sendMail($to1, $subject1, $body1); $flag = 1; } } } //} if ($flag == 1) { $rarray = array('status' => 'success', 'data' => 'successfully redeemed'); } else { $rarray = array('status' => 'error', 'data' => 'redeem error'); } } catch (PDOException $ex) { $rarray = array('status' => 'error', 'error' => array('text' => $ex->getMessage())); } echo json_encode($rarray); exit; }
function getBannerDetails($id) { $rarray = array(); $restaurant = findByIdArray($id, 'banners'); if (!empty($restaurant)) { $rarray['banner'] = $restaurant; $rest = findByIdArray($restaurant['restaurant_id'], 'restaurants'); $merchant = findByIdArray($restaurant['merchant_id'], 'users'); $rarray['restaurant'] = $rest; $rarray['merchant'] = $merchant; if (!empty($restaurant['image'])) { $rarray['banner']['image_url'] = SITEURL . "banner_images/" . $restaurant['image']; } $outlets = findByConditionArray(array('banner_id' => $id), 'banners_outlet_map'); $result = json_encode(array('type' => "success", 'data' => $rarray, 'outlets' => $outlets)); } else { $result = '{type:"error",message:"Not Added"}'; } echo $result; exit; }
function getSwapVoucherDetail($sid) { $is_active = 1; $newdate = date('Y-m-d'); $sql = "SELECT offers.title, offers.price, offers.offer_percent, vouchers.item_expire_date as offer_to_date, offers.image, swap.id, swap.voucher_id, swap.user_id, swap.offer_id,swap.posted_on,swap.offering_end_date,swap.offering_start_date,swap.description FROM vouchers, swap, offers where swap.offer_id=offers.id and vouchers.id=swap.voucher_id and swap.is_active=1 and swap.id =:sid"; try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->bindParam("sid", $sid); $stmt->execute(); $vouchers = $stmt->fetchAll(PDO::FETCH_OBJ); $count = $stmt->rowCount(); for ($i = 0; $i < $count; $i++) { $todate = date('d M, Y', strtotime($vouchers[$i]->offer_to_date)); $vouchers[$i]->expire_date = $todate; if ($vouchers[$i]->offering_end_date == "0000-00-00 00:00:00") { $vouchers[$i]->offering_end_date = ""; } else { $vouchers[$i]->offering_end_date = date('d M, Y', strtotime($vouchers[$i]->offering_end_date)); } if ($vouchers[$i]->offering_start_date == "0000-00-00 00:00:00") { $vouchers[$i]->offering_start_date = ""; } else { $vouchers[$i]->offering_start_date = date('d M, Y', strtotime($vouchers[$i]->offering_start_date)); } $vouchers[$i]->posted_on = date('d M,Y', strtotime($vouchers[$i]->posted_on)); if (!empty($vouchers[$i]->image)) { $vouchers[$i]->image_url = SITEURL . 'voucher_images/' . $vouchers[$i]->image; } $netprice = $vouchers[$i]->price - $vouchers[$i]->price * $vouchers[$i]->offer_percent / 100; $vouchers[$i]->price = number_format($vouchers[$i]->price, 1, '.', ','); $vouchers[$i]->netprice = number_format($netprice, 1, '.', ','); //$vouchers[$i]->categories = json_decode(findByCondition(array('swap_id'=>$vouchers[$i]->id),'swap_category_map')); //$vouchers[$i]->locations = json_decode(findByCondition(array('swap_id'=>$vouchers[$i]->id),'swap_location_map')); $vouchers[$i]->locations = array(); $locations = findByConditionArray(array('swap_id' => $sid), 'swap_location_map'); foreach ($locations as $cat) { $vouchers[$i]->locations[] = findByIdArray($cat['location_id'], 'locations'); } $vouchers[$i]->categories = array(); $category = findByConditionArray(array('swap_id' => $sid), 'swap_category_map'); foreach ($category as $cat) { $vouchers[$i]->categories[] = findByIdArray($cat['category_id'], 'category'); } } $db = null; $vouchers = json_encode($vouchers); $result = '{"type":"success","data":' . $vouchers . ',"count":' . $count . '}'; } catch (PDOException $e) { $result = '{"type":"error","message":' . $e->getMessage() . '}'; } echo $result; }
function getActivePointMasterByMerchant($user_id) { $rarray = array(); $conditions = array(); $restaurants = array(); //$restaurants_query = "SELECT * FROM point_master WHERE " $restaurants = findByConditionArray(array('type' => 0), 'point_master'); if (!empty($restaurants)) { $restaurants = array_map(function ($t) { $s = array(); $user = findByIdArray($t['user_id'], 'users'); $s['id'] = $t['id']; $s['user_id'] = $t['user_id']; $s['merchant_name'] = !empty($user['merchant_name']) ? $user['merchant_name'] : ''; $s['name'] = $t['name']; $s['type'] = $t['type']; $s['value'] = $t['value']; $s['money_point'] = $t['money_point']; $s['valid_days'] = $t['valid_days']; $s['start_date'] = $t['start_date']; $s['expire_date'] = date('d M, Y', strtotime($t['expire_date'])); //$t['restaurant'] = findByIdArray( $t['restaurant_id'],'restaurants'); return $s; }, $restaurants); //$rarray = array('type' => 'success', 'data' => $restaurants); } //print_r($restaurants); if ($user_id != 1) { $merchant_point = findByConditionArray(array('user_id' => $user_id), 'point_master'); if (!empty($merchant_point)) { foreach ($merchant_point as $t) { $s = array(); $user = findByIdArray($t['user_id'], 'users'); $s['id'] = $t['id']; $s['user_id'] = $t['user_id']; $s['merchant_name'] = !empty($user['merchant_name']) ? $user['merchant_name'] : ''; $s['name'] = $t['name']; $s['type'] = $t['type']; $s['value'] = $t['value']; $s['money_point'] = $t['money_point']; $s['valid_days'] = $t['valid_days']; $s['start_date'] = $t['start_date']; $s['expire_date'] = date('d M, Y', strtotime($t['expire_date'])); $restaurants[] = $s; } /*$restaurants = array_map(function($t){ $s = array(); $user = findByIdArray( $t['user_id'],'users'); $s['id'] = $t['id']; $s['user_id'] = $t['user_id']; $s['merchant_name'] = (!empty($user['merchant_name'])?$user['merchant_name']:''); $s['name'] = $t['name']; $s['type'] = $t['type']; $s['value'] = $t['value']; $s['money_point'] = $t['money_point']; $s['valid_days'] = $t['valid_days']; $s['start_date'] = $t['start_date']; $s['expire_date'] = date('d M, Y', strtotime($t['expire_date'])); //$t['restaurant'] = findByIdArray( $t['restaurant_id'],'restaurants'); return $s; }, $restaurants);*/ //$rarray = array('type' => 'success', 'data' => $restaurants); } } if (!empty($restaurants)) { $rarray = array('type' => 'success', 'data' => $restaurants); } else { $rarray = array('type' => 'error', 'message' => 'No points found'); } echo json_encode($rarray); }
function transactionTabDetails() { $rarray = array(); $request = Slim::getInstance()->request(); $body = json_decode($request->getBody()); //print_r($body); //exit; $restaurant_id = array(); $outlet_id = array(); $offer_id = array(); $total_res_ids = array(); $total_outlet_ids = array(); $offers_ids = array(); $merchant_id = $body->merchant_id; $start_date = $body->start_date; $end_date = $body->end_date; if (isset($body->selRes)) { $restaurant_id = $body->selRes; //print_r($restaurant_id); foreach ($restaurant_id as $res_key => $res_value) { $res_ids = array(); $res_sql = "select * from restaurants where restaurant_id='" . $res_value . "'"; $res_sql_res = findByQuery($res_sql); $res_ids = array_column($res_sql_res, 'id'); if (!empty($res_ids)) { $total_res_ids[] = $res_ids[0]; } } } if (isset($body->selout)) { $outlet_id = $body->selout; foreach ($outlet_id as $outlet_key => $outlet_value) { $out_ids = array(); $out_sql = "select * from outlets where outlet_id='" . $outlet_value . "'"; $out_sql_res = findByQuery($out_sql); $out_ids = array_column($out_sql_res, 'id'); if (!empty($out_ids)) { $total_outlet_ids[] = $out_ids[0]; } } } $type = $body->type; if (!empty($total_res_ids)) { $sql = "SELECT * FROM offer_restaurent_map where offer_restaurent_map.restaurent_id in(" . implode(",", $total_res_ids) . ")"; $res_offer_res = findByQuery($sql); $offers_ids = array_column($res_offer_res, 'offer_id'); //print_r($offers_ids); } if (!empty($total_outlet_ids)) { if (!empty($offers_ids)) { $sql = "SELECT * FROM offer_outlet_map where offer_outlet_map.offer_id in(" . implode(",", $offers_ids) . ") and offer_outlet_map.outlet_id in(" . implode(",", $total_outlet_ids) . ")"; $out_offer_res = findByQuery($sql); $offers_ids = array_column($out_offer_res, 'offer_id'); //print_r($offers_ids); } } $allPaymentOffer = 0; $allMenuOffer = 0; $allMembershipOffer = 0; $allRedeemPaymentOffer = 0; $allRedeemMenuOffer = 0; $allRedeemMembershipOffer = 0; $allAvailablePaymentOffer = 0; $allAvailableMenuOffer = 0; $allAvailableMembershipOffer = 0; $offerPaymentOffer = 0; $offerMenuOffer = 0; $offerMembershipOffer = 0; $redeemPaymentOffer = 0; $redeemMenuOffer = 0; $redeemMembershipOffer = 0; $availablePaymentOffer = 0; $availableMenuOffer = 0; $availableMembershipOffer = 0; $willActivePaymentOffer = 0; $willActiveMenuOffer = 0; $willActiveMembershipOffer = 0; $newPaymentOffer = 0; $newMenuOffer = 0; $newMembershipOffer = 0; $hotPaymentOffer = 0; $hotMenuOffer = 0; $hotMembershipOffer = 0; $lastdayPaymentOffer = 0; $lastdayMenuOffer = 0; $lastdayMembershipOffer = 0; $specialPaymentOffer = 0; $specialMenuOffer = 0; $specialMembershipOffer = 0; $viewPaymentOffer = 0; $viewMenuOffer = 0; $viewMembershipOffer = 0; $willActiveNews = 0; $willActiveAddv = 0; $willActiveBanner = 0; $activeNews = 0; $activeAddv = 0; $activeBanner = 0; $targetNews = 0; $targetAddv = 0; $targetBanner = 0; $actualNews = 0; $actualAddv = 0; $actualBanner = 0; $remainingNews = 0; $remainingAddv = 0; $remainingBanner = 0; $exceedNews = 0; $exceedAddv = 0; $exceedBanner = 0; $exceedNews = 0; $exceedAddv = 0; $exceedBanner = 0; $availableEvent = 0; $dealEvent = 0; $openEvent = 0; $feedbackEvent = 0; $myEvent = 0; $myOfferEvent = 0; $generatedPoint = 0; $redeemPoint = 0; $expiredPoint = 0; $balancedPoint = 0; $nextMonthExpPoint = 0; $thisYearExpPoint = 0; //print_r($offers_ids); if (!empty($offers_ids)) { $payment_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=2"; $menu_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=1"; $membership_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=3"; $all_payment_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and offer_type_id=2"; $all_menu_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and offer_type_id=1"; $all_membership_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and offer_type_id=3"; $payment_promo_res = findByQuery($payment_promo_sql); $menu_promo_res = findByQuery($menu_promo_sql); $membership_promo_res = findByQuery($membership_promo_sql); $all_payment_promo_res = findByQuery($all_payment_promo_sql); $all_menu_promo_res = findByQuery($all_menu_promo_sql); $all_membership_promo_res = findByQuery($all_membership_promo_sql); //print_r($all_payment_promo_res); //print_r($all_menu_promo_res); //print_r($all_membership_promo_res); if (!empty($all_payment_promo_res)) { if ($type == 'unit') { $allPaymentOffer = count($all_payment_promo_res); $allRedeemPaymentOffer = 0; $allAvailablePaymentOffer = count($all_payment_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($all_payment_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $allPaymentOffer = $cntt; $allRedeemPaymentOffer = $cntr; $allAvailablePaymentOffer = $cnta; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($all_payment_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $allPaymentOffer = $cntt; $allRedeemPaymentOffer = $cntr; $allAvailablePaymentOffer = $cnta; } } if (!empty($all_menu_promo_res)) { if ($type == 'unit') { $allMenuOffer = count($all_menu_promo_res); $allRedeemMenuOffer = 0; $allAvailableMenuOffer = count($all_menu_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($all_menu_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $allMenuOffer = $cntt; $allRedeemMenuOffer = $cntr; $allAvailableMenuOffer = $cnta; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($all_menu_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $allMenuOffer = $cntt; $allRedeemMenuOffer = $cntr; $allAvailableMenuOffer = $cnta; } } if (!empty($all_membership_promo_res)) { if ($type == 'unit') { $allMembershipOffer = count($all_membership_promo_res); $allRedeemMembershipOffer = 0; $allAvailableMembershipOffer = count($all_membership_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($all_membership_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $allMembershipOffer = $cntt; $allRedeemMembershipOffer = $cntr; $allAvailableMembershipOffer = $cnta; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($all_membership_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $allMembershipOffer = $cntt; $allRedeemMembershipOffer = $cntr; $allAvailableMembershipOffer = $cnta; } } if (!empty($payment_promo_res)) { if ($type == 'unit') { $offerPaymentOffer = count($payment_promo_res); $redeemPaymentOffer = 0; $availablePaymentOffer = count($payment_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $offerPaymentOffer = $cntt; $redeemPaymentOffer = $cntr; $availablePaymentOffer = $cnta; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $offerPaymentOffer = $cntt; $redeemPaymentOffer = $cntr; $availablePaymentOffer = $cnta; } } if (!empty($menu_promo_res)) { if ($type == 'unit') { $offerMenuOffer = count($menu_promo_res); $redeemMenuOffer = 0; $availableMenuOffer = count($menu_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $offerMenuOffer = $cntt; $redeemMenuOffer = $cntr; $availableMenuOffer = $cnta; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $offerMenuOffer = $cntt; $redeemMenuOffer = $cntr; $availableMenuOffer = $cnta; } } if (!empty($membership_promo_res)) { if ($type == 'unit') { $offerMembershipOffer = count($membership_promo_res); $redeemMembershipOffer = 0; $availableMembershipOffer = count($membership_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $offerMembershipOffer = $cntt; $redeemMembershipOffer = $cntr; $availableMembershipOffer = $cnta; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $offerMembershipOffer = $cntt; $redeemMembershipOffer = $cntr; $availableMembershipOffer = $cnta; } } $payment_will_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date)>=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=2"; $menu_will_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date)>=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=1"; $membership_will_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date)>=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=3"; $payment_new_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date)=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=2"; $menu_new_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date)=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=1"; $membership_new_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date)=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=3"; $site_settings = findByIdArray('1', 'site_settings'); if (!empty($site_settings['hot_percentage'])) { $perc = $site_settings['hot_percentage']; } else { $perc = 0; } $payment_hot_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=2 and DATE(offer_from_date) <=CURDATE() and buy_count < quantity and ((buy_count/quantity)*100)>={$perc}"; $menu_hot_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=1 and DATE(offer_from_date) <=CURDATE() and buy_count < quantity and ((buy_count/quantity)*100)>={$perc}"; $membership_hot_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=3 and DATE(offer_from_date) <=CURDATE() and buy_count < quantity and ((buy_count/quantity)*100)>={$perc}"; $payment_last_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_to_date)=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=2"; $menu_last_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_to_date)=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=1"; $membership_last_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_to_date)=CURDATE() and id in(" . implode(',', $offers_ids) . ") and offer_type_id=3"; $payment_special_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=2 and is_special=1"; $menu_special_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=1 and is_special=1"; $membership_special_promo_sql = "select * from offers where merchant_id='" . $merchant_id . "' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and id in(" . implode(',', $offers_ids) . ") and offer_type_id=3 and is_special=1"; $payment_promo_view_sql = "select * from promo_visit where DATE(created_date) between '" . $start_date . "' AND '" . $end_date . "' and merchant_id='" . $merchant_id . "'"; $menu_promo_view_sql = "select * from promo_visit where DATE(created_date) between '" . $start_date . "' AND '" . $end_date . "' and merchant_id='" . $merchant_id . "'"; $membership_promo_view_sql = "select * from promo_visit where DATE(created_date) between '" . $start_date . "' AND '" . $end_date . "' and merchant_id='" . $merchant_id . "'"; $payment_will_promo_res = findByQuery($payment_will_promo_sql); $menu_will_promo_res = findByQuery($menu_will_promo_sql); $membership_will_promo_res = findByQuery($membership_will_promo_sql); $payment_new_promo_res = findByQuery($payment_new_promo_sql); $menu_new_promo_res = findByQuery($menu_new_promo_sql); $membership_new_promo_res = findByQuery($membership_new_promo_sql); $payment_hot_promo_res = findByQuery($payment_hot_promo_sql); $menu_hot_promo_res = findByQuery($menu_hot_promo_sql); $membership_hot_promo_res = findByQuery($membership_hot_promo_sql); $payment_last_promo_res = findByQuery($payment_last_promo_sql); $menu_last_promo_res = findByQuery($menu_last_promo_sql); $membership_last_promo_res = findByQuery($membership_last_promo_sql); $payment_special_promo_res = findByQuery($payment_special_promo_sql); $menu_special_promo_res = findByQuery($menu_special_promo_sql); $membership_special_promo_res = findByQuery($membership_special_promo_sql); $payment_promo_view_res = findByQuery($payment_promo_view_sql); $menu_promo_view_res = findByQuery($menu_promo_view_sql); $membership_promo_view_res = findByQuery($membership_promo_view_sql); if (!empty($payment_will_promo_res)) { if ($type == 'unit') { $willActivePaymentOffer = count($payment_will_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_will_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $willActivePaymentOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_will_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $willActivePaymentOffer = $cntt; } } if (!empty($menu_will_promo_res)) { if ($type == 'unit') { $willActiveMenuOffer = count($menu_will_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_will_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $willActiveMenuOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_will_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $willActiveMenuOffer = $cntt; } } if (!empty($membership_will_promo_res)) { if ($type == 'unit') { $willActiveMembershipOffer = count($membership_will_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_will_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $willActiveMembershipOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_will_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $willActiveMembershipOffer = $cntt; } } if (!empty($payment_new_promo_res)) { if ($type == 'unit') { $newPaymentOffer = count($payment_new_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_new_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $newPaymentOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_new_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $newPaymentOffer = $cntt; } } if (!empty($menu_new_promo_res)) { if ($type == 'unit') { $newMenuOffer = count($menu_new_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_new_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $newMenuOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_new_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $newMenuOffer = $cntt; } } if (!empty($membership_new_promo_res)) { if ($type == 'unit') { $newMembershipOffer = count($membership_new_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_new_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $newMembershipOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_new_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $newMembershipOffer = $cntt; } } if (!empty($payment_hot_promo_res)) { if ($type == 'unit') { $hotPaymentOffer = count($payment_hot_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_hot_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $hotPaymentOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_hot_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $hotPaymentOffer = $cntt; } } if (!empty($menu_hot_promo_res)) { if ($type == 'unit') { $hotMenuOffer = count($menu_hot_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_hot_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $hotMenuOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_hot_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $hotMenuOffer = $cntt; } } if (!empty($membership_hot_promo_res)) { if ($type == 'unit') { $hotMembershipOffer = count($membership_hot_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_hot_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $hotMembershipOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_hot_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $hotMembershipOffer = $cntt; } } if (!empty($payment_last_promo_res)) { if ($type == 'unit') { $lastdayPaymentOffer = count($payment_last_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_last_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $lastdayPaymentOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_last_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $lastdayPaymentOffer = $cntt; } } if (!empty($menu_last_promo_res)) { if ($type == 'unit') { $lastdayMenuOffer = count($menu_last_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_last_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $lastdayMenuOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_last_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $lastdayMenuOffer = $cntt; } } if (!empty($membership_last_promo_res)) { if ($type == 'unit') { $lastdayMembershipOffer = count($membership_last_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_last_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $lastdayMembershipOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_last_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $lastdayMembershipOffer = $cntt; } } if (!empty($payment_special_promo_res)) { if ($type == 'unit') { $specialPaymentOffer = count($payment_special_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_special_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $specialPaymentOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($payment_special_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $specialPaymentOffer = $cntt; } } if (!empty($menu_special_promo_res)) { if ($type == 'unit') { $specialMenuOffer = count($menu_special_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_special_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $specialMenuOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($menu_special_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $specialMenuOffer = $cntt; } } if (!empty($membership_special_promo_res)) { if ($type == 'unit') { $specialMembershipOffer = count($membership_special_promo_res); } elseif ($type == 'quantity') { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_special_promo_res as $key => $value) { $cntr = $cntr + $value['buy_count']; $cntt = $cntt + $value['quantity']; $available = 0; $available = $value['quantity'] - $value['buy_count']; $cnta = $cnta + $available; } $specialMembershipOffer = $cntt; } else { $cntr = 0; $cnta = 0; $cntt = 0; foreach ($membership_special_promo_res as $key => $value) { $cntr = $cntr + $value['offer_price'] * $value['buy_count']; $cntt = $cntt + $value['offer_price'] * $value['quantity']; $available = 0; $available = ($value['quantity'] - $value['buy_count']) * $value['offer_price']; $cnta = $cnta + $available; } $specialMembershipOffer = $cntt; } } if (!empty($payment_promo_view_res)) { if ($type == 'unit') { $viewPaymentOffer = count($payment_promo_view_res); } elseif ($type == 'quantity') { $viewPaymentOffer = count($payment_promo_view_res); } else { $viewPaymentOffer = count($payment_promo_view_res); } } if (!empty($menu_promo_view_res)) { if ($type == 'unit') { $viewMenuOffer = count($menu_promo_view_res); } elseif ($type == 'quantity') { $viewMenuOffer = count($menu_promo_view_res); } else { $viewMenuOffer = count($menu_promo_view_res); } } if (!empty($membership_promo_view_res)) { if ($type == 'unit') { $viewMembershipOffer = count($membership_promo_view_res); } elseif ($type == 'quantity') { $viewMembershipOffer = count($membership_promo_view_res); } else { $viewMembershipOffer = count($membership_promo_view_res); } } if (!empty($total_res_ids)) { $will_active_add_sql = "select * from advertisements where merchant_id='" . $merchant_id . "' and restaurant_id in(" . implode(',', $total_res_ids) . ") and DATE(start_date)>CURDATE() and is_active=1"; $active_add_sql = "select * from advertisements where merchant_id='" . $merchant_id . "' and restaurant_id in(" . implode(',', $total_res_ids) . ") and DATE(start_date) between '" . $start_date . "' AND '" . $end_date . "' and is_active=1"; $will_active_banner_sql = "select * from banners where merchant_id='" . $merchant_id . "' and restaurant_id in(" . implode(',', $total_res_ids) . ") and DATE(start_date)>CURDATE() and is_active=1"; $active_banner_sql = "select * from banners where merchant_id='" . $merchant_id . "' and restaurant_id in(" . implode(',', $total_res_ids) . ") and DATE(start_date) between '" . $start_date . "' AND '" . $end_date . "' and is_active=1"; $will_active_news_sql = "select * from news where user_id='" . $merchant_id . "' and DATE(published_date)>CURDATE()"; $active_news_sql = "select * from news where user_id='" . $merchant_id . "' and DATE(published_date) between '" . $start_date . "' AND '" . $end_date . "'"; $will_active_add_res = findByQuery($will_active_add_sql); $active_add_res = findByQuery($active_add_sql); $will_active_banner_res = findByQuery($will_active_banner_sql); $active_banner_res = findByQuery($active_banner_sql); $will_active_news_res = findByQuery($will_active_news_sql); $active_news_res = findByQuery($active_news_sql); if (!empty($will_active_add_res)) { $willActiveAddv = count($will_active_add_res); } if (!empty($will_active_banner_res)) { $willActiveBanner = count($will_active_banner_res); } if (!empty($will_active_news_res)) { $willActiveNews = count($will_active_news_res); } if (!empty($active_news_res)) { $activeNews = count($active_news_res); $targetNews = count($active_news_res); $actualNews = count($active_news_res); $remainingNews = count($active_news_res); $exceedNews = count($active_news_res); } if (!empty($active_add_res)) { $activeAddv = count($active_add_res); $cntt = 0; $cnta = 0; $cntr = 0; $cnte = 0; foreach ($active_add_res as $key => $value) { $cntt = $cntt + $value['target_click']; $cnta = $cnta + $value['number_of_click']; if ($value['target_click'] > $value['number_of_click']) { $cntr = $cntr + ($value['target_click'] - $value['number_of_click']); } else { $cnte = $cnte + ($value['number_of_click'] - $value['target_click']); } } $targetAddv = $cntt; $actualAddv = $cnta; $remainingAddv = $cntr; $exceedAddv = $cnte; } if (!empty($active_banner_res)) { $activeBanner = count($active_banner_res); $cntt = 0; $cnta = 0; $cntr = 0; $cnte = 0; foreach ($active_banner_res as $key => $value) { $cntt = $cntt + $value['target_click']; $cnta = $cnta + $value['number_of_click']; if ($value['target_click'] > $value['number_of_click']) { $cntr = $cntr + ($value['target_click'] - $value['number_of_click']); } else { $cnte = $cnte + ($value['number_of_click'] - $value['target_click']); } } $targetBanner = $cntt; $actualBanner = $cnta; $remainingBanner = $cntr; $exceedBanner = $cnte; } } } $available_event_sql = "select * from events where status='O' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and is_active=1"; $available_event_res = findByQuery($available_event_sql); $events_ids = array_column($available_event_res, 'id'); $availableEvent = count($available_event_res); //print_r($events_ids); //print_r($available_event_res); $deal_event_sql = "select * from events where status='C' and DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and is_active=1"; $deal_event_res = findByQuery($deal_event_sql); $dealEvent = count($deal_event_res); //print_r($deal_event_res); if (!empty($events_ids)) { $open_event_sql = "select * from event_bids where event_id NOT in(" . implode(',', $events_ids) . ") and is_accepted = 0"; $open_event_res = findByQuery($open_event_sql); $openEvent = count($open_event_res); //print_r($open_event_res); $feedback_event_sql = "select * from event_bids where event_id in(" . implode(',', $events_ids) . ") and is_accepted = 0 and user_id != '" . $merchant_id . "'"; $feedback_event_res = findByQuery($feedback_event_sql); $feedbackEvent = count($feedback_event_res); } $events = array(); $merchant_category = findByConditionArray(array('user_id' => $merchant_id), 'merchant_category_map'); $category_ids = array_column($merchant_category, 'category_id'); $merchant_location = findByConditionArray(array('user_id' => $merchant_id), 'merchant_location_map'); $location_ids = array_column($merchant_location, 'location_id'); $sql = "SELECT * FROM event_location_map WHERE location_id in(" . implode(',', $location_ids) . ")"; $data = findByQuery($sql); if (!empty($data)) { $events = array_column($data, 'event_id'); } $sql = "SELECT * FROM event_category_map WHERE category_id in(" . implode(',', $category_ids) . ")"; $cat_data = findByQuery($sql); if (!empty($cat_data)) { $cat_events = array_column($cat_data, 'event_id'); if (!empty($cat_events)) { foreach ($cat_events as $ta) { $events[] = $ta; } } } $events = array_values(array_unique($events)); if (!empty($events)) { $my_event_sql = "select * from events where DATE(offer_from_date) between '" . $start_date . "' AND '" . $end_date . "' and is_active=1 and id in(" . implode(',', $events) . ")"; $my_event_res = findByQuery($my_event_sql); $myeventsid = array_column($my_event_res, 'id'); $myEvent = count($my_event_res); if (!empty($myeventsid)) { $offer_event_sql = "select * from event_bids where event_id in(" . implode(',', $myeventsid) . ") and user_id = '" . $merchant_id . "'"; $offer_event_res = findByQuery($offer_event_sql); $myOfferEvent = count($offer_event_res); } } $cur_month = date('m'); $next_month = $cur_month + 1; $cur_year = date('Y'); $point_master_sql = "select * from point_master where user_id='" . $merchant_id . "' and DATE(start_date) between '" . $start_date . "' AND '" . $end_date . "'"; $exp_master_sql = "select * from point_master where user_id='" . $merchant_id . "' and DATE(expire_date) < CURDATE()"; $next_month_exp_master_sql = "select * from point_master where user_id='" . $merchant_id . "' and MONTH(expire_date)= '" . $next_month . "'"; $cur_year_exp_master_sql = "select * from point_master where user_id='" . $merchant_id . "' and YEAR(expire_date)= '" . $cur_year . "'"; $point_master_res = findByQuery($point_master_sql); $exp_master_res = findByQuery($exp_master_sql); $next_month_exp_master_res = findByQuery($next_month_exp_master_sql); $cur_year_exp_master_res = findByQuery($cur_year_exp_master_sql); $pointsid = array_column($point_master_res, 'id'); $exppointsid = array_column($exp_master_res, 'id'); $nextmonthpointsid = array_column($next_month_exp_master_res, 'id'); $curyearpointsid = array_column($cur_year_exp_master_res, 'id'); //print_r($pointsid); //print_r($exppointsid); //print_r($nextmonthpointsid); //print_r($curyearpointsid); if (!empty($pointsid)) { $generated_mpoint_sql = "select sum(points) as generated,sum(redeemed_points) as redeem,sum(remaining_points) as balance from point_details where merchant_id='" . $merchant_id . "' and point_id in(" . implode(',', $pointsid) . ")"; $generated_mpoint_res = findByQuery($generated_mpoint_sql); //print_r($generated_mpoint_res); if (!empty($generated_mpoint_res)) { $generatedPoint = $generated_mpoint_res[0]['generated']; $redeemPoint = $generated_mpoint_res[0]['redeem']; $balancedPoint = $generated_mpoint_res[0]['balance']; //echo $generatedPoint; } } if (!empty($exppointsid)) { $expired_mpoint_sql = "select sum(remaining_points) as balance from point_details where merchant_id='" . $merchant_id . "' and point_id in(" . implode(',', $exppointsid) . ")"; $expired_mpoint_res = findByQuery($expired_mpoint_sql); //print_r($expired_mpoint_res); if (!empty($expired_mpoint_res)) { $expiredPoint = $expired_mpoint_res[0]['balance']; //echo $expiredPoint; } } if (!empty($nextmonthpointsid)) { $nextmonth_mpoint_sql = "select sum(remaining_points) as balance from point_details where merchant_id='" . $merchant_id . "' and point_id in(" . implode(',', $nextmonthpointsid) . ")"; $nextmonth_mpoint_res = findByQuery($nextmonth_mpoint_sql); //print_r($nextmonth_mpoint_res); if (!empty($nextmonth_mpoint_res)) { $nextMonthExpPoint = $nextmonth_mpoint_res[0]['balance']; //echo $expiredPoint; } } if (!empty($curyearpointsid)) { $curyear_mpoint_sql = "select sum(remaining_points) as balance from point_details where merchant_id='" . $merchant_id . "' and point_id in(" . implode(',', $curyearpointsid) . ")"; $curyear_mpoint_res = findByQuery($curyear_mpoint_sql); //print_r($curyear_mpoint_res); if (!empty($curyear_mpoint_res)) { $thisYearExpPoint = $curyear_mpoint_res[0]['balance']; //echo $expiredPoint; } } //exit; $data = array('allMenuOffer' => $allMenuOffer, 'allMembershipOffer' => $allMembershipOffer, 'allPaymentOffer' => $allPaymentOffer, 'allRedeemPaymentOffer' => $allRedeemPaymentOffer, 'allRedeemMenuOffer' => $allRedeemMenuOffer, 'allRedeemMembershipOffer' => $allRedeemMembershipOffer, 'allAvailablePaymentOffer' => $allAvailablePaymentOffer, 'allAvailableMenuOffer' => $allAvailableMenuOffer, 'allAvailableMembershipOffer' => $allAvailableMembershipOffer, 'offerPaymentOffer' => $offerPaymentOffer, 'offerMenuOffer' => $offerMenuOffer, 'offerMembershipOffer' => $offerMembershipOffer, 'redeemPaymentOffer' => $redeemPaymentOffer, 'redeemMenuOffer' => $redeemMenuOffer, 'redeemMembershipOffer' => $redeemMembershipOffer, 'availablePaymentOffer' => $availablePaymentOffer, 'availableMenuOffer' => $availableMenuOffer, 'availableMembershipOffer' => $availableMembershipOffer, 'willActivePaymentOffer' => $willActivePaymentOffer, 'willActiveMenuOffer' => $willActiveMenuOffer, 'willActiveMembershipOffer' => $willActiveMembershipOffer, 'newPaymentOffer' => $newPaymentOffer, 'newMenuOffer' => $newMenuOffer, 'newMembershipOffer' => $newMembershipOffer, 'newMembershipOffer' => $newMembershipOffer, 'hotPaymentOffer' => $hotPaymentOffer, 'hotMenuOffer' => $hotMenuOffer, 'hotMembershipOffer' => $hotMembershipOffer, 'lastdayPaymentOffer' => $lastdayPaymentOffer, 'lastdayMenuOffer' => $lastdayMenuOffer, 'lastdayMembershipOffer' => $lastdayMembershipOffer, 'specialPaymentOffer' => $specialPaymentOffer, 'specialMenuOffer' => $specialMenuOffer, 'specialMembershipOffer' => $specialMembershipOffer, 'viewPaymentOffer' => $viewPaymentOffer, 'viewMenuOffer' => $viewMenuOffer, 'viewMembershipOffer' => $viewMembershipOffer, 'willActiveNews' => $willActiveNews, 'willActiveAddv' => $willActiveAddv, 'willActiveBanner' => $willActiveBanner, 'activeNews' => $activeNews, 'activeAddv' => $activeAddv, 'activeBanner' => $activeBanner, 'targetNews' => $targetNews, 'targetAddv' => $targetAddv, 'targetBanner' => $targetBanner, 'actualNews' => $actualNews, 'actualAddv' => $actualAddv, 'actualBanner' => $actualBanner, 'remainingNews' => $remainingNews, 'remainingAddv' => $remainingAddv, 'remainingBanner' => $remainingBanner, 'exceedNews' => $exceedNews, 'exceedAddv' => $exceedAddv, 'exceedBanner' => $exceedBanner, 'availableEvent' => $availableEvent, 'dealEvent' => $dealEvent, 'openEvent' => $openEvent, 'feedbackEvent' => $feedbackEvent, 'myEvent' => $myEvent, 'myOfferEvent' => $myOfferEvent, 'generatedPoint' => $generatedPoint, 'redeemPoint' => $redeemPoint, 'expiredPoint' => $expiredPoint, 'balancedPoint' => $balancedPoint, 'nextMonthExpPoint' => $nextMonthExpPoint, 'thisYearExpPoint' => $thisYearExpPoint); $rarray = array('type' => 'success', 'data' => $data); echo json_encode($rarray); }