资产模块前台接口

This commit is contained in:
luofei 2023-08-04 11:47:43 +08:00
parent a8ab318735
commit 1074620740
5 changed files with 324 additions and 356 deletions

View File

@ -1,108 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\PropertyLists;
use app\adminapi\logic\PropertyLogic;
use app\adminapi\validate\PropertyValidate;
/**
* Property控制器
* Class PropertyController
* @package app\adminapi\controller
*/
class PropertyController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/08/02 16:35
*/
public function lists()
{
return $this->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);
}
}

View File

@ -1,112 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic;
use app\common\model\Property;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* Property逻辑
* Class PropertyLogic
* @package app\adminapi\logic
*/
class PropertyLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/02 16:35
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Property::create([
'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 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();
}
}

View File

@ -1,102 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* Property验证器
* Class PropertyValidate
* @package app\adminapi\validate
*/
class PropertyValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => '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三轮车 2XXX 3XXX',
];
/**
* @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']);
}
}

View File

@ -0,0 +1,324 @@
<?php
namespace app\api\controller;
use app\common\logic\UserLogic as CommonUserLogic;
use app\common\model\auth\Admin;
use app\common\model\Company;
use app\common\model\contract\Contract;
use think\facade\Db;
/**
* 搜索
* Class PropertyController
* @package app\api\controller
*/
class PropertyController extends BaseApiController
{
public array $notNeedLogin = ['propertyContractByCompany','propertyContractByPerson','propertyRentByCompany','propertyRentByPerson','propertyRentLists','propertyRentInf','carInfo','carTravelList','carSituationList','addCarSituation'];
//公司签约
public function propertyContractByCompany() {
//获取参数
$param = $this->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('添加失败');
}
}
}

View File

@ -1,34 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model;
use app\common\model\BaseModel;
/**
* Property模型
* Class Property
* @package app\common\model
*/
class Property extends BaseModel
{
protected $name = 'property';
}