示例#1
0
 public function getLocation()
 {
     $i = 0;
     $push_num = 1;
     $infolbsModel = new Model_InfoLbs();
     $filter['where'] = " customer_id='{$this->customer_id}' and state='1' and x_dian!='' ";
     $sql = $infolbsModel->select($filter);
     $inforesult = $infolbsModel->fetchAll($sql);
     $infocount = count($inforesult);
     for ($i = 0; $i < $infocount; $i++) {
         $inforesult[$i]['location_desc'] = strip_tags($inforesult[$i]['location_desc']);
         $short_intro = cut_str(strip_tags($inforesult[$i]['location_intro']), 120, $start = 0, $code = 'UTF-8');
         $inforesult[$i]['location_desc'] = $inforesult[$i]['location_desc'] != '' ? $inforesult[$i]['location_desc'] : $short_intro;
         $inforesult[$i]['faraway'] = $this->get_distance($this->location_x, $this->location_y, $inforesult[$i]['x_dian'], $inforesult[$i]['y_dian']);
     }
     $newlocallist = multi_array_sort($inforesult, 'faraway', $sort = SORT_ASC);
     $customerconfigModel = new Model_CustomerConfig();
     $filter['where'] = " customer_id='{$this->customer_id}' and c_type='lbs_push' ";
     $sql = $customerconfigModel->select($filter);
     $inforesult = $customerconfigModel->fetchRow($sql);
     if ($inforesult['c_value']) {
         $push_num = $inforesult['c_value'];
     } else {
         if ($i >= 2) {
             $push_num = 2;
         }
     }
     $push_num = $push_num <= $i ? $push_num : $i;
     for ($j = 0; $j < $push_num; $j++) {
         if ($j >= 10) {
             $push_num = 10;
             break;
         }
         $sql = "update info_lbs set push_num=push_num+1 where id='" . $newlocallist[$j]['id'] . "' limit 1";
         $customerconfigModel->query($sql);
         $infolbsrecordModel = new Model_InfoLbsRecord();
         $row['lbs_id'] = $newlocallist[$j]['id'];
         $row['customer_id'] = $this->customer_id;
         $row['fromuser'] = $this->fromuser;
         $row['fromwhere'] = $this->fromwhere;
         $row['ip'] = $_WGT['IP'];
         $row['create_date'] = date("Y-m-d H:i:s");
         $infolbsrecordModel->insert($row);
         $url = 'http://' . $_SERVER['HTTP_HOST'] . "/mobile/info.php?t=location&id=" . $newlocallist[$j]['id'];
         $itemlist .= "<item>\n\t\t <Title><![CDATA[[" . $newlocallist[$j]['faraway'] . "公里]" . $newlocallist[$j]['location_name'] . "]]></Title>\n\t\t <Description><![CDATA[" . $newlocallist[$j]['location_desc'] . "]]></Description>\n\t\t <PicUrl><![CDATA[http://" . $_SERVER['HTTP_HOST'] . "/data/image_c/" . $newlocallist[$j]['location_pic'] . "]]></PicUrl>\n\t\t <Url><![CDATA[{$url}]]></Url>\n\t\t </item>";
     }
     if ($i > 0) {
         $Bodystr = "\n\t\t\t <ArticleCount>{$push_num}</ArticleCount>\n\t\t\t <Articles>\n\t\t\t {$itemlist}\n\t\t\t </Articles>";
         $data['msgtype'] = 'news';
         $data['bodystr'] = $Bodystr;
         return $data;
     }
 }