89 lines
2.1 KiB
PHP
89 lines
2.1 KiB
PHP
<?php
|
|
namespace app\adminapi\logic\vehicle;
|
|
|
|
use app\common\logic\GpsLogic;
|
|
use app\common\model\vehicle\Vehicle;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\vehicle\VehicleRent;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* Vehicle逻辑
|
|
* Class VehicleLogic
|
|
* @package app\adminapi\logic
|
|
*/
|
|
class VehicleLogic extends BaseLogic
|
|
{
|
|
/**
|
|
* @notes 添加
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2023/08/17 09:23
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Vehicle::create([
|
|
'license' => $params['license'],
|
|
'gps_imei' => $params['gps_imei'],
|
|
'type' => 0,
|
|
'status' => 0,
|
|
]);
|
|
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/17 09:23
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Vehicle::where('id', $params['id'])->update([
|
|
'license' => $params['license'],
|
|
'gps_imei' => $params['gps_imei'],
|
|
'type' => $params['type'],
|
|
'status' => $params['status'],
|
|
]);
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @notes 获取详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2023/08/17 09:23
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
$data = Vehicle::findOrEmpty($params['id']);
|
|
$data['mileage'] = 0;
|
|
if($data['status'] == 2){
|
|
//获取租赁信息
|
|
$data['rent_info'] = VehicleRent::where('car_id',$data['id'])->find();
|
|
|
|
}
|
|
return $data->toArray();
|
|
}
|
|
} |