public function index() { $where = array('token' => $this->token); if ($this->isBranch) { $id = intval($_GET['id']); $where['id'] = $id; $where['isbranch'] = 1; } else { $where['isbranch'] = 0; } $thisCompany = $this->company_model->where($where)->find(); if (!$this->isBranch) { $fatherCompany = $this->company_model->where(array('token' => $this->token, 'isbranch' => 0))->order('id ASC')->find(); if ($fatherCompany) { $tj = array('token' => $this->token); $tj['id'] = array('neq', intval($fatherCompany['id'])); $this->company_model->where($tj)->save(array('isbranch' => 1)); } } if (IS_POST) { $_POST['password'] = isset($_POST['password']) && $_POST['password'] ? md5(trim($_POST['password'])) : ''; if (!$thisCompany) { if ($this->isBranch) { $this->insert('Company', U('Company/branches', array('token' => $this->token, 'isBranch' => $this->isBranch))); } else { $this->insert('Company', U('Company/index', array('token' => $this->token, 'isBranch' => $this->isBranch))); } } else { $amap = new amap(); if (!$thisCompany['amapid'] && $thisCompany['longitude'] == $_POST['longitude']) { $locations = $amap->coordinateConvert($thisCompany['longitude'], $thisCompany['latitude']); $_POST['longitude'] = $locations['longitude']; $_POST['latitude'] = $locations['latitude']; } if (!$thisCompany['amapid']) { $ampaid = $amap->create($_POST['name'], $_POST['longitude'] . ',' . $_POST['latitude'], $_POST['tel'], $_POST['address']); $_POST['amapid'] = intval($ampaid); } else { $amap->update($thisCompany['amapid'], $_POST['name'], $_POST['longitude'] . ',' . $_POST['latitude'], $_POST['tel'], $_POST['address']); } // if ($this->company_model->create()) { if (empty($_POST['password'])) { unset($_POST['password']); } if ($this->company_model->where($where)->save($_POST)) { if ($this->isBranch) { $this->success('修改成功', U('Company/branches', array('token' => $this->token, 'isBranch' => $this->isBranch))); } else { $this->success('修改成功', U('Company/index', array('token' => $this->token, 'isBranch' => $this->isBranch))); } } else { $this->error('操作失败'); } } else { $this->error($this->company_model->getError()); } } } else { $this->assign('set', $thisCompany); $this->display(); } }
function map($x, $y) { if (C('baidu_map')) { $transUrl = 'http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=' . $x . '&y=' . $y; $json = Http::fsockopenDownload($transUrl); if ($json == false) { $json = file_get_contents($transUrl); } $arr = json_decode($json, true); $x = base64_decode($arr['x']); $y = base64_decode($arr['y']); } else { $amap = new amap(); $lact = $amap->coordinateConvert($y, $x, 'gps'); $x = $lact['latitude']; $y = $lact['longitude']; } $user_request_model = M('User_request'); $urWhere = array('token' => $this->_get('token'), 'msgtype' => 'text', 'uid' => $this->data['FromUserName']); $urWhere['time'] = array('gt', time() - 5 * 60); $user_request_row = $user_request_model->where($urWhere)->find(); if (!(strpos($user_request_row['keyword'], '附近') === FALSE)) { $user = M('Nearby_user')->where(array('token' => $this->_get('token'), 'uid' => $this->data['FromUserName']))->find(); $keyword = $user['keyword']; $radius = 2000; if (C('baidu_map')) { $map = new baiduMap($keyword, $x, $y); $str = $map->echoJson(); $array = json_decode($str); $map = array(); foreach ($array as $key => $vo) { $map[] = array($vo->title, $key, rtrim($this->siteUrl, '/') . '/tpl/static/images/home.jpg', $vo->url); } if ($map) { return array($map, 'news'); } else { $str = file_get_contents($this->siteUrl . '/map.php?keyword=' . urlencode($keyword) . '&x=' . $x . '&y=' . $y); $array = json_decode($str); $map = array(); foreach ($array as $key => $vo) { $map[] = array($vo->title, $key, rtrim($this->siteUrl, '/') . '/tpl/static/images/home.jpg', $vo->url); } if ($map) { return array($map, 'news'); } else { return array('附近信息无法调出,请稍候再试一下(关键词' . $keyword . ',坐标:' . $x . '-' . $y . ')', 'text'); } } } else { $amamp = new amap(); return $amamp->around($x, $y, $keyword, $radius); } } else { if (!(strpos($this->fun, 'lbsNews') === FALSE)) { $lbsImgClass = new lbsImgNews($this->token, $this->data['FromUserName'], $this->siteUrl); return $lbsImgClass->news($x, $y); } $mapAction = new Maps($this->token); if (!(strpos($user_request_row['keyword'], '开车去') === FALSE) || !(strpos($user_request_row['keyword'], '坐公交') === FALSE) || !(strpos($user_request_row['keyword'], '步行去') === FALSE)) { if (!(strpos($user_request_row['keyword'], '步行去') === FALSE)) { $companyid = str_replace('步行去', '', $user_request_row['keyword']); if (!$companyid) { $companyid = 1; } return $mapAction->walk($x, $y, $companyid); } if (!(strpos($user_request_row['keyword'], '开车去') === FALSE)) { $companyid = str_replace('开车去', '', $user_request_row['keyword']); if (!$companyid) { $companyid = 1; } return $mapAction->drive($x, $y, $companyid); } if (!(strpos($user_request_row['keyword'], '坐公交') === FALSE)) { $companyid = str_replace('坐公交', '', $user_request_row['keyword']); if (!$companyid) { $companyid = 1; } return $mapAction->bus($x, $y, $companyid); } } else { switch ($user_request_row['keyword']) { default: return $this->companyMap(); break; case '最近的': return $mapAction->nearest($x, $y); break; } } } }
public function index() { $where = array('token' => $this->token); if ($this->isBranch) { $id = intval($_GET['id']); $where['id'] = $id; $where['isbranch'] = 1; } else { $where['isbranch'] = 0; } $thisCompany = $this->company_model->where($where)->find(); if (!$this->isBranch) { $fatherCompany = $this->company_model->where(array('token' => $this->token, 'isbranch' => 0))->order('id ASC')->find(); if ($fatherCompany) { $tj = array('token' => $this->token); $tj['id'] = array('neq', intval($fatherCompany['id'])); $this->company_model->where($tj)->save(array('isbranch' => 1)); } } if (IS_POST) { $_POST['password'] = isset($_POST['password']) && $_POST['password'] ? md5(trim($_POST['password'])) : ''; $_POST['business_type'] = implode(',', $_POST['business_type']); if (empty($_POST['name'])) { $this->error('名称不能为空'); } if (empty($_POST['tel'])) { $this->error('电话不能为空'); } if (empty($_POST['province']) || empty($_POST['city']) || empty($_POST['district'])) { $this->error('门店地址不能为空'); } if (empty($_POST['address'])) { $this->error('详细地址不能为空'); } if (empty($_POST['logourl'])) { $this->error('Logo地址不能为空'); } if ($_POST['longitude'] == '') { $this->error('经度不能为空'); } if ($_POST['latitude'] == '') { $this->error('纬度不能为空'); } if (empty($_POST['business_type']) && $this->isBranch) { $this->error('经营类型不能为空'); } if (!$thisCompany) { if ($this->isBranch) { if (empty($_POST['username'])) { $this->error('分支登陆账号不能为空'); } if (empty($_POST['password'])) { $this->error('分支登陆密码不能为空'); } $this->insert('Company', U('Company/branches', array('token' => $this->token, 'isBranch' => $this->isBranch))); } else { $this->insert('Company', U('Company/index', array('token' => $this->token, 'isBranch' => $this->isBranch))); } } else { $amap = new amap(); if (!$thisCompany['amapid'] && ($thisCompany['longitude'] == $_POST['longitude'])) { $locations = $amap->coordinateConvert($thisCompany['longitude'], $thisCompany['latitude']); $_POST['longitude'] = $locations['longitude']; $_POST['latitude'] = $locations['latitude']; } if (!$thisCompany['amapid']) { $ampaid = $amap->create($_POST['name'], $_POST['longitude'] . ',' . $_POST['latitude'], $_POST['tel'], $_POST['address']); $_POST['amapid'] = intval($ampaid); } else { $amap->update($thisCompany['amapid'], $_POST['name'], $_POST['longitude'] . ',' . $_POST['latitude'], $_POST['tel'], $_POST['address']); } if ($this->company_model->create()) { if (empty($_POST['password'])) { unset($_POST['password']); } if ($this->company_model->where($where)->save($_POST)) { if ($this->isBranch) { $this->success('修改成功', U('Company/branches', array('token' => $this->token, 'isBranch' => $this->isBranch))); } else { $this->success('修改成功', U('Company/index', array('token' => $this->token, 'isBranch' => $this->isBranch))); } } else { $this->error('操作失败'); } } else { $this->error($this->company_model->getError()); } } } else { $thisCompany['business_type'] = explode(',', $thisCompany['business_type']); $this->assign('set', $thisCompany); $this->display(); } }