From 1074620740964a0cc00e173721967fbcb51979e1 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 4 Aug 2023 11:47:43 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B5=84=E4=BA=A7=E6=A8=A1=E5=9D=97=E5=89=8D?= =?UTF-8?q?=E5=8F=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../property/PropertyController.php | 108 ------ app/adminapi/logic/property/PropertyLogic.php | 112 ------ .../validate/property/PropertyValidate.php | 102 ------ app/api/controller/PropertyController.php | 324 ++++++++++++++++++ app/common/model/property/Property.php | 34 -- 5 files changed, 324 insertions(+), 356 deletions(-) delete mode 100644 app/adminapi/controller/property/PropertyController.php delete mode 100644 app/adminapi/logic/property/PropertyLogic.php delete mode 100644 app/adminapi/validate/property/PropertyValidate.php create mode 100644 app/api/controller/PropertyController.php delete mode 100644 app/common/model/property/Property.php diff --git a/app/adminapi/controller/property/PropertyController.php b/app/adminapi/controller/property/PropertyController.php deleted file mode 100644 index 87dcdae9d..000000000 --- a/app/adminapi/controller/property/PropertyController.php +++ /dev/null @@ -1,108 +0,0 @@ -dataLists(new PropertyLists()); - } - - - /** - * @notes 添加 - * @return \think\response\Json - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function add() - { - $params = (new PropertyValidate())->post()->goCheck('add'); - $result = PropertyLogic::add($params); - if (true === $result) { - return $this->success('添加成功', [], 1, 1); - } - return $this->fail(PropertyLogic::getError()); - } - - - /** - * @notes 编辑 - * @return \think\response\Json - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function edit() - { - $params = (new PropertyValidate())->post()->goCheck('edit'); - $result = PropertyLogic::edit($params); - if (true === $result) { - return $this->success('编辑成功', [], 1, 1); - } - return $this->fail(PropertyLogic::getError()); - } - - - /** - * @notes 删除 - * @return \think\response\Json - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function delete() - { - $params = (new PropertyValidate())->post()->goCheck('delete'); - PropertyLogic::delete($params); - return $this->success('删除成功', [], 1, 1); - } - - - /** - * @notes 获取详情 - * @return \think\response\Json - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function detail() - { - $params = (new PropertyValidate())->goCheck('detail'); - $result = PropertyLogic::detail($params); - return $this->data($result); - } - - -} \ No newline at end of file diff --git a/app/adminapi/logic/property/PropertyLogic.php b/app/adminapi/logic/property/PropertyLogic.php deleted file mode 100644 index 14c31039c..000000000 --- a/app/adminapi/logic/property/PropertyLogic.php +++ /dev/null @@ -1,112 +0,0 @@ - $params['company_id'], - 'name' => $params['name'], - 'status' => $params['status'], - 'type' => $params['type'] - ]); - - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - self::setError($e->getMessage()); - return false; - } - } - - - /** - * @notes 编辑 - * @param array $params - * @return bool - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public static function edit(array $params): bool - { - Db::startTrans(); - try { - Property::where('id', $params['id'])->update([ - 'company_id' => $params['company_id'], - 'name' => $params['name'], - 'status' => $params['status'], - 'type' => $params['type'] - ]); - - Db::commit(); - return true; - } catch (\Exception $e) { - Db::rollback(); - self::setError($e->getMessage()); - return false; - } - } - - - /** - * @notes 删除 - * @param array $params - * @return bool - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public static function delete(array $params): bool - { - return Property::destroy($params['id']); - } - - - /** - * @notes 获取详情 - * @param $params - * @return array - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public static function detail($params): array - { - return Property::findOrEmpty($params['id'])->toArray(); - } -} \ No newline at end of file diff --git a/app/adminapi/validate/property/PropertyValidate.php b/app/adminapi/validate/property/PropertyValidate.php deleted file mode 100644 index 8f7d2aba4..000000000 --- a/app/adminapi/validate/property/PropertyValidate.php +++ /dev/null @@ -1,102 +0,0 @@ - 'require', - 'company_id' => 'require', - 'name' => 'require', - 'status' => 'require', - 'type' => 'require', - ]; - - - /** - * 参数描述 - * @var string[] - */ - protected $field = [ - 'id' => 'id', - 'company_id' => '所属公司id', - 'name' => '资产名称', - 'status' => '资产状态 0:未出租 1:已出租', - 'type' => '资产类型 1:三轮车 2:XXX 3:XXX', - ]; - - - /** - * @notes 添加场景 - * @return PropertyValidate - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function sceneAdd() - { - return $this->only(['company_id','name','status','type']); - } - - - /** - * @notes 编辑场景 - * @return PropertyValidate - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function sceneEdit() - { - return $this->only(['id','company_id','name','status','type']); - } - - - /** - * @notes 删除场景 - * @return PropertyValidate - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function sceneDelete() - { - return $this->only(['id']); - } - - - /** - * @notes 详情场景 - * @return PropertyValidate - * @author likeadmin - * @date 2023/08/02 16:35 - */ - public function sceneDetail() - { - return $this->only(['id']); - } - -} \ No newline at end of file diff --git a/app/api/controller/PropertyController.php b/app/api/controller/PropertyController.php new file mode 100644 index 000000000..76644a18d --- /dev/null +++ b/app/api/controller/PropertyController.php @@ -0,0 +1,324 @@ +request->param(); + $param['admin_id'] = $this->userId = 107; + if(!isset($param['company_id'])) { + return $this->fail('请选择公司'); + } + if(!isset($param['num'])) { + return $this->fail('请填写数量'); + } + if(!isset($param['start_time'])) { + return $this->fail('请选择开始时间'); + } + if(!isset($param['end_time'])) { + return $this->fail('请选择结束时间'); + } + $party_a = Db::name('user')->where('id',$param['admin_id'])->value('company_id'); + if(!$party_a){ + return $this->fail('甲方公司不存在,请先完善公司信息'); + } + //组装数据 + $value['party_a'] = $party_a; + $value['party_b'] = $param['company_id']; + $value['num'] = $param['num']; + $value['type'] = 1; + $value['start_time'] = strtotime($param['start_time']); + $value['end_time'] = strtotime($param['end_time']); + $value['admin_id'] = $param['admin_id']; + $value['contract_no'] = 'HT'.date('YmdHis').rand(1000,9999); + $value['create_time'] = time(); + //生成合同 + $res = Db::name('property_contract')->save($value); + if($res){ + return $this->success('发起成功,等待平台风控部上传合同'); + } + return $this->fail('发起失败'); + } + + //个人签约 + public function propertyContractByPerson() { + //获取参数 + $param = $this->request->param(); + $param['admin_id'] = $this->userId = 107; + if(!isset($param['user_id'])) { + return $this->fail('请选择签约人'); + } + if(!isset($param['car_id'])) { + return $this->fail('请选择三轮车'); + } + if(!isset($param['start_time'])) { + return $this->fail('请选择开始时间'); + } + if(!isset($param['end_time'])) { + return $this->fail('请选择结束时间'); + } + if(!isset($param['rent_id'])) { + return $this->fail('缺少关键参数'); + } + //组装数据 + $value['party_a'] = Db::name('user')->where('id',$param['admin_id'])->value('company_id'); + $value['user_id'] = $param['user_id']; + $value['num'] = 1; + $value['type'] = 2; + $value['start_time'] = strtotime($param['start_time']); + $value['end_time'] = strtotime($param['end_time']); + $value['admin_id'] = $param['admin_id']; + $value['contract_no'] = 'HT'.date('YmdHis').rand(1000,9999); + $value['create_time'] = time(); + //生成合同 + Db::startTrans(); + try { + $insertId = Db::name('property_contract')->insertGetId($value); + Db::name('property_contract_info')->save( + [ + 'contract_id' => $insertId, + 'car_id' => $param['car_id'], + 'rent_id' => $param['rent_id'], + 'user_id' => $param['user_id'], + ] + ); + Db::commit(); + return $this->success('发起成功,等待平台风控部上传合同'); + }catch(\Exception $e){ + Db::rollback(); + return $this->fail('发起失败'.$e->getMessage()); + } + } + + //生成公司租赁信息 + public function propertyRentByCompany() { + //获取参数 + $contract_id = $this->request->param('contract_id'); + //验证参数 + if(!isset($contract_id)){ + return $this->fail('请选择合同'); + } + try { + //获取合同数据 + $contractInfo = Db::name('property_contract')->where('id',$contract_id)->find(); + $carsids = Db::name('property')->where('status',0)->limit($contractInfo['num'])->column('id'); + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + $data['cars'] = []; + foreach($carsids as $v){ + $arr['id'] = $v; + $arr['status'] = 0; + array_push($data['cars'],$arr); + } + $value['company_id'] = $contractInfo['party_b']; + $value['company_from_id'] = $contractInfo['party_a']; + $value['contract_id'] = $contractInfo['id']; + $value['num'] = $contractInfo['num']; + $value['start_time'] = $contractInfo['start_time']; + $value['end_time'] = $contractInfo['end_time']; + $value['cars'] = json_encode($data['cars']); + //生成数据 + Db::startTrans(); + try { + Db::name('property_rent')->save($value); + Db::name('property')->where('id','in',$carsids)->update(['status'=>1]); + Db::commit(); + return $this->success('租赁成功'); + }catch(\Exception $e){ + Db::rollback(); + return $this->fail('租赁失败'); + } + } + + //生成个人租赁信息 + public function propertyRentByPerson(){ + //获取参数 + $contract_id = $this->request->param('contract_id'); + //验证参数 + if(!isset($contract_id)){ + return $this->fail('请选择合同'); + } + try { + //获取合同数据 + $contractInfo = Db::name('property_contract')->alias('c')->leftJoin('property_contract_info i','c.id = i.contract_id')->where('c.id',$contract_id)->find(); + + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + $value['user_id'] = $contractInfo['user_id']; + $value['company_from_id'] = $contractInfo['party_a']; + $value['contract_id'] = $contract_id; + $value['num'] = 1; + $value['start_time'] = $contractInfo['start_time']; + $value['end_time'] = $contractInfo['end_time']; + $value['cars'] = json_encode(['id'=>$contractInfo['car_id'],'status'=>1]); + //生成数据 + Db::startTrans(); + try { + Db::name('property_rent')->save($value); + $rentInfo = Db::name('property_rent')->where('id',$contractInfo['rent_id'])->find(); + $cars = json_decode($rentInfo['cars'],true); + foreach($cars as $k=>$v) { + if($v['id'] == $contractInfo['car_id']) { + $cars[$k]['status'] = 1; + } + } + $cars = json_encode($cars); + Db::name('property_rent')->where('id',$contractInfo['rent_id'])->update(['cars'=>$cars]); + Db::commit(); + return $this->success('租赁成功'); + }catch(\Exception $e){ + Db::rollback(); + return $this->fail('租赁失败'); + } + } + + //获取租赁列表 + public function propertyRentLists() { + //获取参数 + $company_id = $this->request->param('company_id'); + //获取数据 + $data = Db::name('property_rent')->withoutField('cars')->where('company_id',$company_id)->select()->each(function($item,$key){ + $item['diif_time'] = ceil(($item['end_time']-$item['start_time'])/86400); + $item['start_time'] = date('Y-m-d',$item['start_time']); + $item['end_time'] = date('Y-m-d',$item['end_time']); + $company = Db::name('company')->where('id',$item['company_from_id'])->find(); + $item['company_user'] = $company['master_name']; + $item['company_phone'] = $company['master_phone']; + $item['contract_file'] = Db::name('property_contract')->where('id',$item['contract_id'])->value('contract_url'); + $item['model'] = '电动三轮车'; + return $item; + })->toArray(); + //返回 + return $this->success('获取成功',$data,1,1); + } + + //获取租赁详情列表 + public function propertyRentInfo() { + //获取参数 + $rent_id = $this->request->param('rent_id'); + //获取数据 + $data = Db::name('property_rent')->where('id',$rent_id)->find(); + $company = Db::name('company')->where('id',$data['company_from_id'])->find(); + $data['company_name'] = $company['company_name']; + $data['company_phone'] = $company['master_phone']; + $data['cars'] = json_decode($data['cars'],true); + foreach($data['cars'] as $k=>$v) { + $data['cars'][$k]['status_name'] = $v['status'] == 1 ? '已租赁' : '未租赁'; + $data['cars'][$k]['car_info'] = Db::name('property')->where('id',$v['id'])->find(); + if($v['status'] == 1) { + $rentInfo = Db::name('property_contract_info')->where('rent_id',$rent_id)->where('car_id',$v['id'])->find(); + $data['cars'][$k]['user_info'] = Db::name('user')->field('nickname,mobile')->where('id',$rentInfo['user_id'])->find(); + } + } + //返回 + return $this->success('获取成功',$data,1,1); + } + + //车辆详情 + public function carInfo() { + //获取参数 + $car_id = $this->request->param('car_id'); + $rent_id = $this->request->param('rent_id'); + if(!isset($car_id) || !isset($rent_id)) { + return $this->fail('参数错误'); + } + //获取数据 + $data = Db::name('property_rent')->alias('p') + ->leftJoin('company c','p.company_from_id = c.id') + ->leftJoin('user u','u.id = p.user_id') + ->field('p.*,c.company_name,c.master_phone as company_phone,u.nickname as user_name,u.mobile as user_phone') + ->where('p.id',$rent_id)->find(); + + $data['cars'] = json_decode($data['cars'],true); + if($car_id != $data['cars']['id']) { + return $this->fail('参数错误'); + } + $carInfo = Db::name('property')->field('name as car_name,pic as car_pic')->where('id',$car_id)->find(); + $data['cars']['car_name'] = $carInfo['car_name']; + $data['cars']['car_pic'] = $carInfo['car_pic']; + //返回 + return $this->success('获取成功',$data,1,1); + } + + //车辆行驶记录 + public function carTravelList() { + //获取参数 + $car_id = $this->request->param('car_id'); + $rent_id = $this->request->param('rent_id'); + $page_size = $this->request->param('page_size',10); + $page_num = $this->request->param('page_num',1); + if(!isset($car_id) || !isset($rent_id)) { + return $this->fail('参数错误'); + } + $kilometers_count = 0; + $data = Db::name('property_rent_car_travel')->field('create_time,kilometers')->where('car_id',$car_id)->where('rent_id',$rent_id)->order('create_time desc')->paginate([ + 'list_rows'=> $page_size, + 'page' => $page_num, + ])->each(function($item,$key) use (&$kilometers_count){ + $kilometers_count += $item['kilometers']; + return $item; + })->toArray(); + $data['kilometers_count'] = $kilometers_count; + return $this->success('获取成功',$data,1,1); + } + + //三轮车近况列表 + public function carSituationList() { + //获取参数 + $car_id = $this->request->param('car_id'); + $rent_id = $this->request->param('rent_id'); + $page_size = $this->request->param('page_size',10); + $page_num = $this->request->param('page_num',1); + if(!isset($car_id) || !isset($rent_id)) { + return $this->fail('参数错误'); + } + $data = Db::name('property_rent_car_situation')->field('create_time,content')->where('car_id',$car_id)->where('rent_id',$rent_id)->order('create_time desc')->paginate([ + 'list_rows'=> $page_size, + 'page' => $page_num, + ])->toArray(); + + return $this->success('获取成功',$data,1,1); + } + + //填写三轮车近况 + public function addCarSituation() { + //获取参数 + $car_id = $this->request->param('car_id'); + $rent_id = $this->request->param('rent_id'); + $content = $this->request->param('content'); + if(!isset($car_id) || !isset($rent_id) || !isset($content)) { + return $this->fail('参数错误'); + } + $data = [ + 'car_id' => $car_id, + 'rent_id' => $rent_id, + 'content' => $content, + 'create_time' => time(), + ]; + $res = Db::name('property_rent_car_situation')->insert($data); + if($res) { + return $this->success('添加成功'); + }else { + return $this->fail('添加失败'); + } + } +} diff --git a/app/common/model/property/Property.php b/app/common/model/property/Property.php deleted file mode 100644 index 9241f9475..000000000 --- a/app/common/model/property/Property.php +++ /dev/null @@ -1,34 +0,0 @@ -