140 lines
4.0 KiB
PHP
140 lines
4.0 KiB
PHP
<?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\vehicle;
|
||
|
||
|
||
use app\api\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 {
|
||
//获取gps_car_id
|
||
$car = (new GpsLogic()) -> info($params['gps_imei']);
|
||
if($car['code'] == 0){
|
||
self::setError('添加失败');
|
||
return false;
|
||
}
|
||
Vehicle::create([
|
||
'license' => $params['license'],
|
||
'gps_imei' => $params['gps_imei'],
|
||
'gps_carid' => $car['data']['carId'],
|
||
'status' => $params['status'],
|
||
'is_del' => 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 {
|
||
//获取数据
|
||
$data = Vehicle::where('id',$params['id'])->find();
|
||
if($data['gps_imei'] != $params['gps_imei']){
|
||
//获取gps_car_id
|
||
$car = (new GpsLogic()) -> info($params['gps_imei']);
|
||
if($car['code'] == 0){
|
||
self::setError('添加失败');
|
||
return false;
|
||
}
|
||
$data['gps_carid'] = $car['data']['carId'];
|
||
}
|
||
Vehicle::where('id', $params['id'])->update([
|
||
'license' => $params['license'],
|
||
'gps_imei' => $params['gps_imei'],
|
||
'gps_carid' => $data['gps_carid'],
|
||
'status' => $params['status']
|
||
]);
|
||
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'] !== 0){
|
||
return false;
|
||
}
|
||
Vehicle::where('id', $params['id'])->update(['is_del' => 1]);
|
||
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::findOrEmpty($params['id']);
|
||
$data['status_name'] = $data->status_name;
|
||
return $data->toArray();
|
||
}
|
||
} |