111 lines
2.7 KiB
PHP
111 lines
2.7 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 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([
|
|
'company_id' => $params['company_id'],
|
|
'license' => $params['license'],
|
|
'gps_imei' => $params['gps_imei'],
|
|
'type' => 1,
|
|
'status' => 1,
|
|
'is_del' => 1,
|
|
'is_check' => 1,
|
|
]);
|
|
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([
|
|
'company_id' => $params['company_id'],
|
|
'license' => $params['license'],
|
|
'gps_imei' => $params['gps_imei'],
|
|
'type' => $params['type'],
|
|
'status' => $params['status'],
|
|
'is_check' => $params['is_check']
|
|
]);
|
|
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 delete(array $params): bool
|
|
{
|
|
try {
|
|
$data = Vehicle::where('id', $params['id'])->find();
|
|
if($data['is_del'] !== 1){
|
|
return false;
|
|
}
|
|
Vehicle::where('id', $params['id'])->update(['is_del' => 2]);
|
|
return true;
|
|
}catch (\Exception $e){
|
|
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::where('is_del',1)->findOrEmpty($params['id']);
|
|
return $data->toArray();
|
|
}
|
|
} |