Ejemplo n.º 1
0
Archivo: list.php Proyecto: hqd276/bigs
 function draw()
 {
     global $display;
     $cond = ' 1 ';
     $memcache_key = '';
     $slug = Url::get('slug');
     $sql = 'SELECT * FROM seo_keywords WHERE safe_key="' . $slug . '"';
     $keyword = mysql_fetch_assoc(DB::query($sql));
     $district_id = $keyword['did'];
     $count_supplier = 0;
     if (is_numeric($district_id) && $district_id > 0) {
         $cond .= " AND CONCAT(',', brand_did, ',') LIKE '%," . $district_id . ",%' ";
         $sql = 'SELECT * FROM district WHERE id=' . $district_id;
         $district = mysql_fetch_assoc(DB::query($sql));
         $display->add('district', $district);
     }
     $cond .= " AND is_active = 1 ";
     //list food type
     $list_foodtype = array();
     $sql = 'SELECT  * FROM food_type';
     $re = DB::query($sql);
     if ($re) {
         while ($row = mysql_fetch_assoc($re)) {
             $list_foodtype[] = $row;
         }
     }
     $total_row = 0;
     $list_supplier = array();
     if (!$list_supplier) {
         $list_supplier = array();
         $sql = 'SELECT distinct supplier.* FROM  `supplier`, food_res AS fr WHERE ' . $cond . ' AND fr.name LIKE "%' . $keyword['keyword'] . '%" AND supplier.id = fr.rid ORDER BY is_promoted DESC, name ASC ';
         $re = DB::query($sql);
         if ($re) {
             while ($row = mysql_fetch_assoc($re)) {
                 $arr_foodtype = explode(',', $row['fid']);
                 $temp = array();
                 if (count($arr_foodtype) > 0) {
                     for ($i = 0; $i < count($arr_foodtype); $i++) {
                         for ($j = 0; $j < count($list_foodtype); $j++) {
                             if ($list_foodtype[$j]['id'] == $arr_foodtype[$i]) {
                                 $temp[] = $list_foodtype[$j]['name'];
                             }
                         }
                     }
                 }
                 $row['food_type'] = $temp;
                 $district_fees = unserialize($row['fees']);
                 if (isset($district_fees[$district_id])) {
                     $row['delivery_time'] = $district_fees[$district_id][4];
                 } else {
                     $row['delivery_time'] = '';
                 }
                 $row['open_now'] = Restaurant::check_open($row);
                 $row['introduce'] = strip_tags(htmlspecialchars_decode($row['introduce']));
                 $row['introduce_en'] = strip_tags($row['introduce_en']);
                 if ($row['logo'] != '') {
                     if (strstr($row['logo'], 'supplier/')) {
                         $row['logo'] = IMAGE_PATH . 'thumb/180_180/' . $row['logo'];
                     } else {
                         $row['logo'] = IMAGE_PATH . $row['logo'];
                     }
                 }
                 if ($row['open_now']) {
                     $total_row++;
                     $row['time_order_str'] = '';
                     $open_hours = unserialize($row['open_hours']);
                     $day_of_week = intval(date("N")) + 1;
                     $hour = $open_hours[$day_of_week];
                     $str_hours = array();
                     for ($index = 0; $index < count($hour['from_hours']); $index++) {
                         if (!empty($hour['from_hours'][$index]) && !empty($hour['to_hours'][$index])) {
                             $str_hours[] = trim($hour['from_hours'][$index]) . ',' . trim($hour['to_hours'][$index]);
                         }
                     }
                     if (count($str_hours) > 0) {
                         $str_hours = implode('-', $str_hours);
                     } elseif (count($str_hours) == 1) {
                         $str_hours = $str_hours[0];
                     } elseif (count($str_hours) == 0) {
                         $str_hours = '';
                     }
                     if (strlen($str_hours) > 0) {
                         $row['time_order_str'] = EClassApi::convert_open_time($str_hours);
                     }
                 }
                 $list_supplier[] = $row;
             }
         }
         mysql_free_result($re);
     }
     //list keyword
     $list_keyword = array();
     $sql = 'SELECT  * FROM seo_keywords';
     $re = DB::query($sql);
     if ($re) {
         while ($row = mysql_fetch_assoc($re)) {
             $list_keyword[] = $row;
         }
     }
     $display->add('slug', $keyword);
     $display->add('district_id', $district_id);
     $display->add('total_row', $total_row);
     $display->add('list_supplier', $list_supplier);
     $display->add('list_keyword', $list_keyword);
     $display->output("list");
 }