fetch($shop_id, false, $lng, $lat); return $shop; } # 获取店铺基本信息 public function get($city, $lng, $lat, $name = '', $method = 'fetch', $shop_id = false) { if (!$city) { Dever::alert('请传入城市'); } if (!$lng || !$lat) { Dever::alert('请传入用户坐标'); } $data = $this->fetch(false, $city, $lng, $lat, 1, $name, $method); # 验证本城市内有没有店 if (!$data) { $data = $this->fetch(false, $city, $lng, $lat, 2, $name, $method); } if ($data) { if ($method == 'fetch') { $data = $this->getInfo($data); } else { foreach ($data as $k => $v) { $data[$k] = $this->getInfo($data[$k]); if ($shop_id == $v['id']) { $data[$k]['cur'] = 1; } else { $data[$k]['cur'] = 2; } } } } return $data; } # 获取店铺的商品列表 public function getGoods($shop, $column = false) { $table = 'shop/goods'; $where['shop_id'] = isset($shop['id']) ? $shop['id'] : $shop; if ($column) { $where['column'] = $column; $method = 'getData'; } else { $method = 'getDataPage'; } $name = Dever::input('name'); if ($name) { $where['name'] = $name; } $data = Dever::db($table)->$method($where); if ($data) { foreach ($data as $k => $v) { $data[$k] = $this->getGoodsInfo($where['shop_id'], $v); } } return $data; } # 获取详细信息 private function getInfo($data) { if ($data['worktime']) { $time = date('Hi'); $worktime = str_replace(':', '', $data['worktime']); $temp = explode('~', $worktime); if ($time < $temp[0] || $time > $temp[1]) { $data['open'] = 2; } } return $data; } # 获取距离 private function fetch($id, $city, $lng, $lat, $type = 1, $name = '', $method = 'fetch') { $page = array(); if ($method == 'fetchAll') { $page['template'] = 'list'; $page['num'] = 10; } else { $page = false; } $where = 'type = '.$type.' and status = 1 and state = 1'; $county = Dever::db('area/county')->find($city); if ($county) { $city = $county['id']; } if ($type == 1 && $city) { $where .= ' and city = ' . $city; } if ($name) { $where .= ' and name like("%'.$name.'%")'; } if ($id) { $where .= ' and id = ' . $id; } $sql = 'select id,name,`desc`,truename,mobile,lng,lat,address,open,worktime,method,gotime,pdesc,round((st_distance(point(lng, lat), point('.$lng.', '.$lat.'))*111195)/1000, 2) as distance from {table} where '.$where.' order by distance asc'; $data = Dever::db('shop/info')->$method($sql, array(), $page); return $data; } # 获取库存 public function getGoodsInfo($shop_id, $info, $sku_id = false, $attr = true) { $where['shop_id'] = $shop_id; $where['goods_id'] = isset($info['goods_id']) ? $info['goods_id'] : $info; $other = Dever::db('shop/goods_sku')->getData($where); $data = Dever::load('goods/lib/info')->getInfo($info, $attr, array($other, array('total'))); if($data) { $sku_id = $sku_id ? $sku_id : $data['sku_id']; $data['total'] = 0; if ($data['price_type'] == 4) { if (isset($data['goods']) && is_array($data['goods'])) { foreach ($data['goods'] as $k => $v) { $data['goods'][$k]['total'] = $this->getTotal($other, -1); if ($data['total'] > $data['goods'][$k]['total']) { $data['total'] = $data['goods'][$k]['total']; } } } } else { $data['total'] = $this->getTotal($other, $sku_id); } } return $data; } # 验证库存 public function checkTotal(&$num, $goods_id, $shop_id, $sku_id, $state = 1) { $info = $this->getGoodsInfo($shop_id, $goods_id, $sku_id, false); if (!$info) { Dever::alert('商品不存在'); } $total = $info['total']; if ($num > $total) { if ($state == 2) { Dever::alert('库存不足'); } $num = $total; } return $total; } # 获取库存 public function getTotal($other, $sku_id) { if (isset($other[$sku_id])) { return $other[$sku_id]['total']; } else { return 0; } } }