Example #1
0
 /**
  * 用户列表 跑腿服务
  *  周围排序
  *
  * @return Response
  */
 public function postList()
 {
     $location = Input::get('location');
     $pageSize = Input::get('count', 10);
     $service_type = Input::get('service_type', 3);
     $sort_by = Input::get('sort_by', self::TIME_DESC);
     $limit = $pageSize + 1;
     $offset = '';
     $hasMore = 0;
     $total = 0;
     $orderWhere = '`M`.services_id = ' . $service_type . ' AND `M`.user_id = `U`.id AND `U`.`role` = ' . User::FREEMAN . ' AND `U`.`status` = ' . User::STATUS_OK;
     //按页码分页
     if (Input::has('by_no')) {
         $page = abs(Input::get('by_no', 1));
         $page > 1 || ($page = 1);
         $offset = ' OFFSET ' . $pageSize * ($page - 1);
         //按id分页,
     } elseif (Input::has('by_id')) {
         $lastId = Input::get('by_id');
         if ($lastId > 0) {
             $orderWhere .= ' AND `M`.`id` < ' . $lastId;
         }
     }
     if ($sort_by == self::PRICE_DESC) {
         //价格降序排列
         $orderBy = ' ORDER BY `M`.`price` DESC';
     } elseif ($sort_by == self::PRICE_ASC) {
         //价格升序排列
         $orderBy = ' ORDER BY `M`.`price` ASC';
     } elseif ($sort_by == self::LOCATION_ASC) {
         //按照距离有近到远排序
         $orderBy = " ORDER BY GetDistance({$location['lat']}, {$location['lon']}, `U`.`lat`, `U`.`lon`)  ASC";
     } elseif ($sort_by == self::RANK_DESC) {
         //评价从高到低
         $orderBy = ' ORDER BY `U`.`comment_goodrate` DESC';
     } elseif ($sort_by == self::RANK_ASC) {
         //评价从低到高
         $orderBy = ' ORDER BY `U`.`comment_goodrate` ASC';
     }
     $squares = returnSquarePoint($location['lon'], $location['lat']);
     // select b.id as id,a.id as fid,b.name as name,a.name as fname from 表名1 a inner join 表名1 b on a.id=b.uid
     $sql = "SELECT *\r\n                     FROM `o2omobile_my_services` AS `M`\r\n                     INNER JOIN `o2omobile_users` AS `U`\r\n                     WHERE {$orderWhere}  AND `U`.`lat`<>0\r\n                     AND `U`.deleted_at is NULL\r\n                     {$orderBy}\r\n                     LIMIT {$limit}\r\n                     {$offset}";
     $userIds = DB::select($sql);
     // print_r($userIds);exit;
     $collection = new Collection();
     foreach ($userIds as $user) {
         $collection->add(with(new User())->fill((array) $user));
     }
     $users = array();
     if (!empty($collection)) {
         if (count($collection) > $pageSize) {
             $hasMore = 1;
             $collection->pop();
             //弹出最后一条
         }
         //格式化
         foreach ($collection as $user) {
             $users[] = $user->simpleFormatToApi();
         }
     }
     //endif
     $return = array('total' => $total, 'count' => count($users) < $pageSize ? count($users) : $pageSize, 'more' => $hasMore, 'users' => $users);
     return $this->json($return);
 }
 /**
  * 功能:获取附近商家
  */
 public function getNearbyList()
 {
     $page = intval(I('post.page'));
     //当前页数
     if ($page < 1) {
         $page = 1;
     }
     $long = I('post.long');
     //经度
     $lat = I('post.lat');
     //纬度
     $city_id = intval(I('post.city_id'));
     //城市ID
     $one_id = intval(I('post.one_id'));
     //第一级分类
     $industry_class_id = intval(I('post.industry_class_id'));
     //第二级分类
     $district_id = intval(I('post.district_id'));
     //商圈ID
     $rice = intval(I('post.rice'));
     //多少米
     $map['city_id'] = $city_id;
     $map['status'] = 1;
     if ($one_id > 0) {
         $map['one_id'] = $one_id;
     }
     if ($industry_class_id > 0) {
         $map['industry_class_id'] = $industry_class_id;
     }
     if ($district_id > 0) {
         $map['district_id'] = $district_id;
     }
     switch ($rice) {
         case 500:
             //500米
             $rice = 0.05;
             break;
         case 1000:
             //1000米
             $rice = 0.1;
             break;
         case 3000:
             //3000米
             $rice = 0.3;
             break;
         case 5000:
             //5000米
             $rice = 0.5;
             break;
         default:
             $rice = 0;
     }
     if ($rice > 0) {
         $squares = returnSquarePoint($lng, $lat, $rice);
         $map['_string'] = "lat<>0 and lat>{$squares['right-bottom']['lat']} and lat<{$squares['left-top']['lat']} and lng>{$squares['left-top']['lng']} and lng<{$squares['right-bottom']['lng']}";
     }
     $list = M('Shop')->field('id,lng,lat')->where($map)->select();
     //echo M('Shop')->getlastsql();
     if (!$list) {
         $list = array();
     }
     $shoplist = array();
     //var_dump($list);exit;
     foreach ($list as $key => $item) {
         $range = getDistance($long, $lat, $item['lng'], $item['lat']);
         $shoprange[] = array('id' => $item['id'], 'range' => $range);
         $shoplist[] = $range;
         //$keyid	=	$item['id'];
     }
     $base_num = $shoplist[$keyid];
     /*foreach($shoplist as $shop_id=>$range)
     		{
     		}*/
     //var_dump($shoplist);exit;
     sort($shoplist);
     $new_shoplist = array();
     foreach ($shoplist as $item) {
         foreach ($shoprange as $key => $val) {
             if ($item == $val['range']) {
                 $new_shoplist[] = array('shop_id' => $val['id'], 'range' => $item);
                 unset($shoprange[$key]);
                 break;
             }
         }
     }
     //var_dump($new_shoplist);exit;
     //var_dump($shoplist);exit;
     $arr = array();
     $list1 = array_slice($new_shoplist, ($page - 1) * 20, 20);
     //var_dump($list1);exit;
     foreach ($list1 as $shop_id => $item) {
         $field = 'id,member_id,title as full_name,star,fans_num,area_id,district_id';
         $shop = M('Shop')->field($field)->where(array('id' => $item['shop_id']))->find();
         $item['full_name'] = strip_tags(htmlspecialchars_decode($item['full_name']));
         $member = M('Member')->where(array('id' => $shop['member_id']))->find();
         $shop['face'] = $member['face'];
         //echo M('Shop')->getlastsql().'<br>';
         $shop['range'] = $item['range'];
         $arr[] = $shop;
     }
     //var_dump($arr);exit;
     if (count($arr) < 1) {
         $arr = array(array('id' => ''));
     }
     $this->json_ok($arr);
 }
 /**
  * 周围订单列表
  *
  * @return json
  */
 public function postAround()
 {
     $location = Input::get('location');
     $pageSize = Input::get('count', 10);
     $sort_by = Input::get('sort_by', self::TIME_DESC);
     $limit = $pageSize + 1;
     $offset = '';
     $hasMore = 0;
     $total = 0;
     $orderWhere = '`O`.`order_status` = ' . Orders::OS_PUBLISHED;
     //按页码分页
     if (Input::has('by_no')) {
         $page = abs(Input::get('by_no', 1));
         $page > 1 || ($page = 1);
         $offset = ' OFFSET ' . $pageSize * ($page - 1);
         //按id分页,
     } elseif (Input::has('by_id')) {
         $lastId = Input::get('by_id');
         if ($lastId > 0) {
             $orderWhere .= ' AND `O`.`id` < ' . $lastId;
         }
     }
     if ($sort_by == self::PRICE_DESC) {
         //价格降序排列
         $orderBy = ' ORDER BY `O`.`offer_price` DESC';
     } elseif ($sort_by == self::PRICE_ASC) {
         //价格升序排列
         $orderBy = ' ORDER BY `O`.`offer_price` ASC';
     } elseif ($sort_by == self::TIME_DESC) {
         //时间排序
         $orderBy = ' ORDER BY `O`.`created_at` DESC';
     } elseif ($sort_by == self::LOCATION_ASC) {
         //按照距离有近到远排序
         $orderBy = " ORDER BY GetDistance({$location['lat']}, {$location['lon']}, `O`.`lat`, `O`.`lon`)  ASC";
     } elseif ($sort_by == self::RANK_DESC) {
         //评价从高到低
         $orderBy = ' ORDER BY `O`.`rank` DESC';
     } elseif ($sort_by == self::RANK_ASC) {
         //评价从低到高
         $orderBy = ' ORDER BY `O`.`rank` ASC';
     }
     $squares = returnSquarePoint($location['lon'], $location['lat']);
     $sql = "SELECT *\n                     FROM `o2omobile_orders` AS `O`\n                     WHERE {$orderWhere}  AND `O`.`lat`<>0\n                     AND `O`.`lat`>{$squares['right-bottom']['lat']}\n                     AND `O`.`lat`<{$squares['left-top']['lat']}\n                     AND `O`.`lon`>{$squares['left-top']['lon']}\n                     AND `O`.`lon`<{$squares['right-bottom']['lon']}\n                     AND `O`.deleted_at is NULL\n                     {$orderBy}\n                     LIMIT {$limit}\n                     {$offset}";
     $orderIds = DB::select($sql);
     // print_r($orderIds);exit;
     $collection = new Collection();
     foreach ($orderIds as $order) {
         $collection->add(with(new Orders())->fill((array) $order));
     }
     $orders = array();
     if (!empty($collection)) {
         if (count($collection) > $pageSize) {
             $hasMore = 1;
             $collection->pop();
             //弹出最后一条
         }
         //格式化
         foreach ($collection as $order) {
             $orders[] = $order->formatToApi();
         }
     }
     //endif
     $return = array('total' => $total, 'count' => count($orders) < $pageSize ? count($orders) : $pageSize, 'more' => $hasMore, 'orders' => $orders);
     return $this->json($return);
 }
Example #4
0
 public function nearshops($long, $lat, $order, $sort = "asc", $offset = "0", $limit = "10", $get_distance = "", $wheres = "")
 {
     $limit = $limit ? $limit : '12';
     //$order = $order ? $order : "`juli` ASC";
     $where = "";
     $where2 = "";
     $WebUserInfo = show_distance();
     $db_prefix = option('system.DB_PREFIX');
     $order_juli = "";
     $orders = "";
     if ($order == 'juli') {
         $order_juli = " order by c.juli " . $sort;
     } else {
         $orders = " order by " . $order . ' ' . $sort;
     }
     $julis = "";
     if ($get_distance) {
         $squares = returnSquarePoint($WebUserInfo['long'], $WebUserInfo['lat'], $get_distance);
         $where .= "and sc.lat<>0 and sc.lat>{$squares['right-bottom']['lat']} and sc.lat<{$squares['left-top']['lat']} and sc.long>{$squares['left-top']['lng']} and sc.long<{$squares['right-bottom']['lng']}";
         $get_distance = $get_distance * 1000;
         $julis .= " where c.juli < " . $get_distance;
     }
     $sql = "select * from (select `s`.`store_id`, `s`.`name`, `s`.`logo`, `s`.`intro`,`sc`.`long`,`sc`.`lat`, ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat}*PI()/180-`sc`.`lat`*PI()/180)/2),2)+COS({$lat}*PI()/180)*COS(`sc`.`lat`*PI()/180)*POW(SIN(({$long}*PI()/180-`sc`.`long`*PI()/180)/2),2)))*1000) AS juli from " . $db_prefix . "store_contact as sc, " . $db_prefix . "store as s where " . $wheres . " s.status = 1 and sc.store_id = s.store_id " . $where . $orders . " ) as c " . $julis . $order_juli . "  limit {$offset},{$limit}";
     $near_store_list = $this->db->query($sql);
     foreach ($near_store_list as $key => $value) {
         $value['url'] = option('config.wap_site_url') . '/home.php?id=' . $value['store_id'] . '&platform=1';
         $value['pcurl'] = url_rewrite('store:index', array('id' => $value['store_id']));
         if (empty($value['logo'])) {
             $value['logo'] = getAttachmentUrl('images/default_shop_2.jpg', false);
         } else {
             $value['logo'] = getAttachmentUrl($value['logo']);
         }
         $near_store_list[$key]['logo'] = $value['logo'];
         $near_store_list[$key]['url'] = $value['url'];
         $near_store_list[$key]['pcurl'] = $value['pcurl'];
     }
     return $near_store_list;
 }