Пример #1
0
 function SearchBuildings($name = "", $created_uid = "", $address = "", $bids = "", $province = "", $city = "", $district = "", $street = "", $btype = "", $pageSize = "", $page = "", $checkUserPoints = true, $includeUserPoints = false, $maxLng = '', $maxLat = '', $minLng = '', $minLat = '', $keywords = '')
 {
     $sql = "select b.*,u.uname from building b left join user u on b.create_uid=u.uid";
     $order = " order by topic_count desc";
     $where = " where 1=1";
     $sqlcount = "select count(*) as rs from building b";
     if ($page > 0) {
         if ($pageSize == "" || $pageSize == 0) {
             $pageSize = $this->Config['building_pagesize'];
         }
         $startrecord = $pageSize * ($page - 1);
         $endrecord = $pageSize * $page;
         $limit = ' limit ' . $startrecord . ',' . $pageSize;
     }
     if ($name != "" && (!$keywords || $keywords == "")) {
         //$where.=" and b.bname like '%$name%'";
         $where .= " and b.bname ='{$name}'";
     }
     if ($created_uid != "") {
         $where .= " and b.create_uid={$created_uid}";
     }
     if ($address != "" && (!$keywords || $keywords == "")) {
         $where .= " and b.address like '%{$address}%'";
     }
     if ($keywords && $keywords != "") {
         $where .= " and (b.bname like '%{$keywords}%' or b.address like '%{$keywords}%' or description like '%{$keywords}%')";
     }
     if ($province != "" && $province != 0) {
         if (is_numeric($province)) {
             $where .= " and b.province='{$province}'";
         } else {
             $where .= " and b.province in( select id from common_district where name='{$province}')";
         }
     }
     if ($city != "" && $city != 0) {
         if (is_numeric($city)) {
             $where .= " and b.city='{$city}'";
         } else {
             $where .= " and b.city in( select id from common_district where name='{$city}')";
         }
     }
     if ($district != "") {
         $where .= " and b.district='{$district}'";
     }
     if ($street != "") {
         $where .= " and b.street='{$street}'";
     }
     if ($btype != '' && is_numeric($btype) && $btype > 0) {
         $where .= " and b.build_type_id={$btype}";
     }
     if (isset($bids) && $bids != '') {
         if (!$includeUserPoints) {
             $where .= " and b.bid in({$bids})";
         } else {
             $where .= " or b.bid in({$bids})";
         }
     }
     if ($maxLng && $maxLng != '') {
         $where .= " and b.point_lng<='{$maxLng}'";
     }
     if ($maxLat && $maxLat != '') {
         $where .= " and b.point_lat<='{$maxLat}'";
     }
     if ($minLng && $minLng != '') {
         $where .= " and b.point_lng>='{$minLng}'";
     }
     if ($minLat && $minLat != '') {
         $where .= " and b.point_lat>='{$minLat}'";
     }
     $result = array();
     $sqlcount = $sqlcount . $where . $order;
     $row = $this->DatabaseHandler->FetchFirst($sqlcount);
     if ($row != false) {
         $result['total'] = $row['rs'];
     } else {
         $result['total'] = 0;
     }
     $sqlr = trim($sql . $where . $order . $limit);
     $this->Logger->Write($sqlr);
     $query = $this->DatabaseHandler->Query($sqlr);
     $rows = $query->GetAll();
     //do other things which related with points
     $uid = $this->User['uid'];
     $data = array();
     foreach ($rows as $row) {
         $image = $row['face_url'];
         if ($image && $image != '') {
             $image_prefix = GetImagePrefix($image);
         }
         $image_profile_img = $image_prefix . "_p." . get_file_ext($image);
         if (file_exists($image_profile_img)) {
             $row['face_url_p'] = $image_profile_img;
         } else {
             $row['face_url_p'] = $row['face_url'];
         }
         $row['image_prefix'] = $image_profile_img;
         $bid = $row['bid'];
         if ($uid != "" && $checkUserPoints) {
             $fans = $this->DatabaseHandler->FetchFirst("select upid from userpoints where isfollowed=1 and uid={$uid} and building_id={$bid}");
             if ($fans && count($fans) >= 1) {
                 $row['fans'] = 1;
             }
             $ms = $this->DatabaseHandler->FetchFirst("select live_type from userpoints where changyong=1 and uid={$uid} and building_id={$bid}");
             $row['home'] = 0;
             $row['work'] = 0;
             $row['school'] = 0;
         }
         if ($ms && count($ms) >= 1) {
             $row['member'] = 1;
             foreach ($ms as $m) {
                 switch ($m['live_type']) {
                     case "1":
                         $row['home'] = 1;
                         $row['work'] = 0;
                         $row['school'] = 0;
                         break;
                     case "2":
                         $row['home'] = 0;
                         $row['work'] = 1;
                         $row['school'] = 0;
                         break;
                     case "3":
                         $row['home'] = 0;
                         $row['work'] = 0;
                         $row['school'] = 1;
                         break;
                 }
             }
         }
         $data[] = $row;
     }
     $result['data'] = $data;
     if ($result['total'] == 0) {
         $result['data'] = '';
     }
     return $result;
 }
Пример #2
0
 function SearchUsers($uids, $city, $district, $street, $startage = '', $endage = '', $gender = '', $hasQQ = false, $hasMSN = false, $hasPhone = false, $hastouxiang = false, $page, $pageSize, $paging = true, $current_uid = '', $checkFollowMe = false, $province = '', $orderBy = 'lastlogin')
 {
     $sql = "select u.push_uid,u.channel_id,u.device_type, u.password, case when u.gendar=1 then '他' when u.gendar=2 then '她' else 'TA' end as gendar_txt1,case when u.gendar=1 then '男' when u.gendar=2 then '女' else '未填写'  end as gendar_txt,u.uid,u.uname,u.face_url,u.aboutme,u.uemail,u.birthday,u.lastlogintime,UNIX_TIMESTAMP(u.birthday) as bint,u.gendar,u.fans_count,u.topic_count,u.follow_count,u.province,u.city,u.area,u.street,u.qq,u.phone,u.msn,u.secondemail,u.realname,u.regdate,";
     $sql .= "(select count(*) from userpoints where uid=u.uid and point_type='fans') as gpoints,";
     $sql .= "(select count(*) from buddys where uid=u.uid and isfriend=1) as friend_count,";
     $sql .= "(select name from common_district where id=u.province) as province_name,";
     $sql .= "(select name from common_district where id=u.city) as city_name,";
     $sql .= "(select name from common_district where id=u.area) as district_name,";
     $sql .= "(select name from common_district where id=u.street) as street_name ";
     if ($current_uid != '' && $current_uid > 0) {
         $sql .= ",(select isfriend from buddys where buddyid=u.uid and uid={$current_uid}) as isfriend ";
         $sql .= ",(select isfollowed from buddys where buddyid=u.uid and uid={$current_uid}) as isfollowed ";
     }
     if ($checkFollowMe) {
         $sql .= ",(select isfriend from buddys where buddyid={$current_uid} and uid=u.uid) as followme ";
     }
     // $sql.="(select id from buddys where uid=$loginId and buddyid=u.uid) as bid";
     $sql .= "from user u ";
     $sqlcount = "select count(u.uid) as rs from user u ";
     $where = "where 1=1 ";
     $orderby = "order by u.lastlogintime desc ";
     switch ($orderBy) {
         case "lastpost":
             $orderby = "order by u.lastposttime desc ";
             break;
         case "fanscount":
             $orderby = "order by u.fans_count desc ";
             break;
         case "name":
             $orderby = "order by u.uname asc ";
             break;
         case "lastlogin":
             $orderby = "order by u.lastlogintime desc ";
             break;
         default:
             $orderby = "order by u.lastlogintime desc ";
             break;
     }
     $limit = '';
     if ($page > 0) {
         if ($pageSize == "" || $pageSize == 0) {
             $pageSize = $this->Config['building_topic_pagesize'];
         }
         $startrecord = $pageSize * ($page - 1);
         $endrecord = $pageSize * $page;
         $limit = ' limit ' . $startrecord . ',' . $pageSize;
     }
     if ($uids && $uids != '') {
         $where .= "and u.uid in ({$uids}) ";
     }
     if ($province && $province != '') {
         $where .= "and u.province in ({$province}) ";
     }
     if ($city && $city != '') {
         $where .= "and u.city in ({$city}) ";
     }
     if ($district && $district != '') {
         $where .= "and u.area in ({$district}) ";
     }
     if ($street && $street != '') {
         $where .= "and u.street in ({$street}) ";
     }
     if ($startage && $startage != '') {
         $where .= "and u.birthday >= '{$startage}' ";
     }
     if ($endage && $endage != '') {
         $where .= "and u.birthday <= '{$endage}' ";
     }
     if ($gender && $gender != '') {
         $where .= "and u.gendar={$gender} ";
     }
     if ($hastouxiang) {
         $where .= "and u.face_url<>'' ";
     }
     if ($hasPhone && $hasPhone == true) {
         $where .= "and u.phone<>'' ";
     }
     if ($hasQQ && $hasQQ == true) {
         $where .= "and u.qq <>'' ";
     }
     if ($hasMSN && $hasMSN == true) {
         $where .= "and u.msn<>'' ";
     }
     $result = array();
     $result['data'] = array();
     $result['total'] = 0;
     //$this->Logger->Write($sqlcount.$where);
     $totalRow = $this->DatabaseHandler->FetchFirst($sqlcount . $where);
     if ($totalRow) {
         $result['total'] = $totalRow['rs'];
     }
     if ($result['total'] == 0) {
         return $result;
     }
     if ($paging) {
         $query = $this->DatabaseHandler->Query($sql . $where . $orderby . $limit);
     } else {
         $query = $this->DatabaseHandler->Query($sql . $where . $orderby);
     }
     $this->Logger->Write($sql . $where . $orderby . $limit);
     $list = array();
     if ($query) {
         $rows = $query->GetAll();
         foreach ($rows as $row) {
             $image = $row['face_url'];
             if ($image && $image != '') {
                 $image_prefix = GetImagePrefix($image);
             }
             $image_profile_img = $image_prefix . "_p." . get_file_ext($image);
             if (file_exists($image_profile_img)) {
                 $row['face_url_p'] = $image_profile_img;
             } else {
                 $row['face_url_p'] = $row['face_url'];
             }
             $row['image_prefix'] = $image_profile_img;
             $cdate = date('Y');
             $bdate = date('Y', $row['bint']);
             $row['age'] = $cdate - $bdate;
             $row['lastlogin'] = getTime($row['lastlogintime']);
             $row['regdate'] = getTime($row['regdate']);
             $list[] = $row;
         }
     }
     $result['data'] = $list;
     return $result;
 }