update car

This commit is contained in:
unknown 2023-08-22 17:25:38 +08:00
parent 8f44220de9
commit 28a7008376
2 changed files with 15 additions and 20 deletions

View File

@ -1,20 +1,8 @@
<?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\api\controller;
use app\api\logic\VehicleLogic;
use think\response\Json;
/**
* 车辆管理
@ -28,7 +16,8 @@ class VehicleController extends BaseApiController
/*
* 获取去未出租的三轮车列表
*/
public function tricycle() {
public function tricycle():Json
{
//获取参数
$params = $this->request->get(['page_no','page_size']);
//获取数据
@ -40,11 +29,12 @@ class VehicleController extends BaseApiController
/*
* 三轮车批量出租
*/
public function multipleRent() {
public function multipleRent():Json
{
//获取参数
$params = $this->request->post(['company_id','car_ids','start_time','end_time']);
$params = $this->request->post(['company_id','contract_id','car_ids','start_time','end_time']);
//验证参数
if(empty($params['company_id']) || empty($params['car_ids']) || empty($params['start_time']) || empty($params['end_time'])) {
if(empty($params['company_id']) || empty($params['contract_id']) || empty($params['car_ids']) || empty($params['start_time']) || empty($params['end_time'])) {
return $this->fail('缺少必要参数');
}
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){
@ -63,11 +53,12 @@ class VehicleController extends BaseApiController
/*
* 三轮车单辆出租
*/
public function singleRent() {
public function singleRent():Json
{
//获取参数
$params = $this->request->post(['lessor_company_id','tenant_company_id','car_id','start_time','end_time']);
$params = $this->request->post(['lessor_company_id','tenant_company_id','contract_id','car_id','start_time','end_time']);
//验证参数
if(empty($params['lessor_company_id']) || empty($params['tenant_company_id']) || empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){
if(empty($params['lessor_company_id']) || empty($params['tenant_company_id']) || empty($params['contract_id']) || empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){
return $this->fail('缺少必要参数');
}
if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){

View File

@ -57,6 +57,7 @@ class VehicleLogic extends BaseLogic
if($car){
$data[] = [
'car_id' => $v,
'lessee_one_contract_id' => $params['contract_id'],
'lessee_one_company_id' => $company['id'],
'lessee_one_company' => $company['company_name'],
'lessee_one_user_id' => $company['user_id'],
@ -72,6 +73,8 @@ class VehicleLogic extends BaseLogic
VehicleRent::startTrans();
try {
(new VehicleRent()) -> saveAll($data);
//更新车辆列表中的车辆状态
Vehicle::where('id','in',$ids)->update(['status'=>1]);
VehicleRent::commit();
return ['code'=>1,'msg'=>'请求成功'];
}catch (\Exception $e) {
@ -102,6 +105,7 @@ class VehicleLogic extends BaseLogic
//设置数据
$data = [
'id' => $rent['id'],
'lessee_two_contract_id' => $params['contract_id'],
'lessee_two_company_id' => $company['id'],
'lessee_two_company_name' => $company['company_name'],
'lessee_two_user_id' => $company['user_id'],