|
@@ -153,4 +153,69 @@ class Companys extends Api
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function save()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ //验证参数
|
|
|
+ $id = $this->request->param('id',0);
|
|
|
+ $userId = $this->auth->id;
|
|
|
+ $scene = !empty($id) ? 'edit' : 'add';
|
|
|
+ $validate = validate('Companys');
|
|
|
+ if(!$validate->check($this->request->param(),[],$scene)){
|
|
|
+ throw new Exception($validate->getError());
|
|
|
+ }
|
|
|
+ if (!empty($id)) {
|
|
|
+ $where['user_id'] = $userId;
|
|
|
+ $where['id'] = $id;
|
|
|
+ $companyData = $this->model->where($where)->find();
|
|
|
+ if (empty($companyData)) {
|
|
|
+ throw new Exception('未找到相关信息');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $where['user_id'] = $userId;
|
|
|
+ $companyData = $this->model->where($where)->find();
|
|
|
+ if (!empty($companyData)) {
|
|
|
+ throw new Exception('您已申请过入驻');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $time = time();
|
|
|
+ $areaData = getProvince($this->request->param());
|
|
|
+ $fullAddress = $areaData['full_address'];
|
|
|
+ $data = [
|
|
|
+ 'contacts' => $this->request->param('contacts', ''),
|
|
|
+ 'mobile' => $this->request->param('mobile', ''),
|
|
|
+ 'province_id' => $this->request->param('province_id', 0),
|
|
|
+ 'city_id' => $this->request->param('city_id', 0),
|
|
|
+ 'area_id' => $this->request->param('area_id', 0),
|
|
|
+ 'province_name' => $areaData['province_name'],
|
|
|
+ 'city_name' => $areaData['city_name'],
|
|
|
+ 'area_name' => $areaData['area_name'],
|
|
|
+ 'address' => $this->request->param('address', ''),
|
|
|
+ 'full_address' => $fullAddress,
|
|
|
+ 'aptitude_images' => $this->request->param('aptitude_images', ''),
|
|
|
+ 'status' => 1,
|
|
|
+ ];
|
|
|
+ if (empty($id)) {
|
|
|
+ $data['user_id'] = $userId;
|
|
|
+ $data['createtime'] = $time;
|
|
|
+ $res = $this->model->insertGetId($data);
|
|
|
+ } else {
|
|
|
+ $data['updatetime'] = $time;
|
|
|
+ $where['id'] = $id;
|
|
|
+ $where['user_id'] = $userId;
|
|
|
+ $res = $this->model->where($where)->update($data);
|
|
|
+ }
|
|
|
+ if (!$res) {
|
|
|
+ throw new Exception('操作失败');
|
|
|
+ }
|
|
|
+ $this->success('操作成功');
|
|
|
+ } catch (Exception $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|