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(); } }
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(); } }