This commit is contained in:
MeSHard
2025-11-10 16:12:07 +08:00
parent 99f88bc53e
commit 94f7e83679
181 changed files with 15770 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?php
namespace app\controller\Bus;
use think\facade\Db;
class AlterBalance
{
public function ChangeSpecialUserBalance(): \think\response\Json
{
$save = Db::table("user_gongjiao")->where("openid", "o-wLg5DGWU_rYwfmp1-1Wck1lKGw")->save(["account" => 99999.00]);
if ((int)$save == 1) {
return json(["code" => 200, "msg" => "修改成功"]);
} else {
return json(["code" => 404, "msg" => "修改失败"]);
}
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace app\controller\Bus;
use app\controller\utils;
use app\model\Vinlicense;
use think\db\exception\DbException;
use think\facade\Db;
class BusBill extends utils
{
/**
* @throws DbException
*/
public function DataStatistics($start_time, $end_time): \think\response\Json
{
$DateWithMess = [];
$message = Vinlicense::column('EvcInfoNo');
$date = $this->getDateFromRange($start_time, $end_time);
$i = 0;
foreach (array_unique($message) as $a) {
$DateWithMess[$i]['序号'] = $i + 1;
// $DateWithMess[$i]['EvcInfoNo'] = $a;
$DateWithMess[$i]['车牌号'] = Vinlicense::where("EvcInfoNo", $a)->value("ParkNo");
$DateWithMess[$i]['车号'] = Vinlicense::where("EvcInfoNo", $a)->value("SelfCode");
$TotalCharge = 0;
foreach ($date as $d) {
$TotalPower = Db::table("charge_order_gongjiao")->where('EvcInfoNo', $a)->whereDay('charge_date', $d)->sum('TotalPower');
$TotalCharge += $TotalPower;
$DateWithMess[$i][$d] = round($TotalPower, 3);
}
$DateWithMess[$i]['充电电量(度)'] = round($TotalCharge, 3);
$DateWithMess[$i]['充电电费(元)'] = round(Db::table("charge_order_gongjiao")->where('EvcInfoNo', $a)->whereBetweenTime('charge_date', $start_time, $end_time)->sum('ElecMoney'), 2);
if ($DateWithMess[$i]['充电电量(度)'] != 0) {
$DateWithMess[$i]['平均电费'] = round($DateWithMess[$i]['充电电费(元)'] / $DateWithMess[$i]['充电电量(度)'], 3);
}
$charge_pile_number = Db::table("charge_order_gongjiao")->where('EvcInfoNo', $a)->value("Equipment_number");
$ddd = Db::table("charge_pile,charge_station")->where('charge_pile_number', $charge_pile_number)->where("charge_pile.charge_station_id=charge_station.charge_station_id")->value("charge_station_number");
$DateWithMess[$i]['充电服务费单价(元)'] = $this->Fee($ddd, "o-wLg5DGWU_rYwfmp1-1Wck1lKGw")['ServiceFee'][0]['univalence'];
$DateWithMess[$i]['充电服务费(元)'] = round(Db::table("charge_order_gongjiao")->where('EvcInfoNo', $a)->whereBetweenTime('charge_date', $start_time, $end_time)->sum('SeviceMoney'), 2);
$DateWithMess[$i]['充电费用(元)'] = round(Db::table("charge_order_gongjiao")->where('EvcInfoNo', $a)->whereBetweenTime('charge_date', $start_time, $end_time)->sum('TotalMoney'), 2);
$i += 1;
}
return $this->ResponseJson($DateWithMess, 200, "Request Success");
}
}

View File

@@ -0,0 +1,350 @@
<?php
namespace app\controller\Bus;
use app\controller\Aes;
use app\controller\HardMessage;
use app\controller\HMACMD5;
use app\model\ChargeOrder as ChargeOrderModel;
use app\model\Vinlicense;
use app\Request;
use DateInterval;
use DateTime;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Overtrue\Pinyin\Pinyin;
use think\facade\Db;
use think\facade\Log;
class PlugCharge
{
public function insert_start_charge(Request $request)
{
$params = file_get_contents('php://input');
$params = json_decode($params, true);
$OperatorID = empty($params['OperatorID']) ? '' : $params['OperatorID'];
$authorization = $request->header()['authorization'];//传递过来的token
$auths = explode(' ', trim($authorization));
$auth = $auths[count($auths) - 1];
$checkParams = $this->checkParams($params);
if ($checkParams != 2)
return json(['Msg' => $checkParams . '为空', 'Ret' => 4003, 'Data' => ['Status' => 1]]);
if ($auth) {
if ($this->checkToken_assess($auth) == 1) {
$data = json_encode(['Status' => 1]);
$data = $this->Encrypt($data);
$seq = empty($Seq) ? '0001' : $params['Seq'];
$datetime = empty($TimeStamp) ? date('YmdHis') : $params['TimeStamp'];
$sig = $OperatorID . $data . $datetime . $seq;
$s = $this->HmacMD5($sig);
return json(['Msg' => 'Token过期或者无效', 'Ret' => 4002, 'Data' => $data, 'Sig' => $s]);
}
$checkSig = $this->checkSig($params['OperatorID'], $params);
if ($checkSig == 1) {
$data = json_encode(['Status' => 1]);
$data = $this->Encrypt($data);
$seq = empty($Seq) ? '0001' : $params['Seq'];
$datetime = empty($TimeStamp) ? date('YmdHis') : $params['TimeStamp'];
$sig = $OperatorID . $data . $datetime . $seq;
$s = $this->HmacMD5($sig);
return json(['Msg' => '签名错误', 'Ret' => 4001, 'Data' => $data, 'Sig' => $s]);
}
$data = $this->Decrypt($params['Data']);
$data = json_decode($data, true);
if (isset($data['vin']) && isset($data['connectorID'])) {
Log::write("The Plug Message come on :" . $data['vin'] . $data['connectorID']);
$CheckVinIsExist = Db::table('vinlicense')->where('EvcInfoNo', $data['vin'])->find();
if (!empty($CheckVinIsExist)) {
$AppointmentTime = Db::table('appointment_time')->where('id', 1)->value('AppointmentTime');
$currentDate = new DateTime();
$combinedDateTime = new DateTime($currentDate->format('Y-m-d') . ' ' . $AppointmentTime);
$AppointmentTime = $combinedDateTime->format('Y-m-d H:i:s');
$nowTime = $currentDate->format('Y-m-d H:i:s');
$nowDay = $currentDate->format('Y-m-d');
$check = Db::table('appointment')->whereDay('action_time', $nowDay)->where('Vin', $data['vin'])->where('ConnectorID', $data['connectorID'])->find();
if (empty($check)) {
Db::table('appointment')->save(['action_time' => $nowTime, 'ConnectorID' => $data['connectorID'], 'Vin' => $data['vin'], 'plug_time' => $AppointmentTime]);
}
// $check = Db::table('appointment')->whereDay('action_time', $nowDay)->where('Vin', $data['vin'])->find();
// if (empty($check)) {
// Db::table('appointment')->save(['action_time' => $nowTime, 'ConnectorID' => $data['connectorID'], 'Vin' => $data['vin'], 'plug_time' => $AppointmentTime]);
// } else {
// $checkVin = Db::table('appointment')->whereDay('action_time', $nowDay)->where('Vin', $data['vin'])->value('ConnectorID');
// if ($checkVin != $data['connectorID']) {
// Db::table('appointment')->whereDay('action_time', $nowDay)->where('Vin', $data['vin'])->save(['action_time' => $nowTime, 'ConnectorID' => $data['connectorID']]);
// }
// }
}
$kk['SuccStat'] = 0;
$kk['FailReason'] = 0;
return $this->encodeData($kk, $params, 0);
} else {
$kk['SuccStat'] = 1;
$kk['FailReason'] = 1;
return $this->encodeData($kk, $params, 0);
}
}
return $this->encodeData(['Status' => 1], $params, 4002, 'Bearer 未添加');
// $OperatorID = Config::get('hard.OperatorID');
// $OperatorSecret = Config::get('hard.OperatorSecret');
}
public function PlugGennerateOrder($ConnectorID, $vin): array
{
$station_id = Db::table('charge_pile')->where('ConnectorID', $ConnectorID)->value('charge_station_id');
$EquipAuthSeq = Db::table('charge_pile')->where('ConnectorID', $ConnectorID)->value('EquipAuthSeq');
$no = Db::table('charge_pile')->where('ConnectorID', $ConnectorID)->value('no');
if (empty($EquipAuthSeq)) {
$EquipAuthSeq = $this->generate_EquipmentAuth(7);
Db::table('charge_pile')->where('ConnectorID', $ConnectorID)->update(['EquipAuthSeq' => $EquipAuthSeq]);
}
$Hard = new HardMessage();
$openid = 'o-wLg5DGWU_rYwfmp1-1Wck1lKGw';
$area = Db::table('user')->where('openid', $openid)->value('area');
$pinyin = new Pinyin();
$s = $pinyin->sentence($area);
$s = strtr($s, array(' ' => ''));
$table = 'charge_order_' . $s;
$table_user = 'user_' . $s;
$AuthMessage = $Hard->Get_query_equip_auth($EquipAuthSeq, $ConnectorID);
if (isset($AuthMessage['FailReason']) && isset($AuthMessage['SuccStat'])) {//认证成功 请求启动充电
if ($AuthMessage['FailReason'] == 0 && $AuthMessage['SuccStat'] == 0) {
$StartChargeSeq = $this->generate_StartChargeSeq(7);
ChargeOrderModel::insert(['openid' => $openid, 'area' => $area, 'StartChargeSeq' => $StartChargeSeq]);
$ChargeModel = 1;
$StartCharge = $Hard->Get_query_start_charge_test($StartChargeSeq, $ConnectorID, 'QRCode', $ChargeModel, $vin); //ChargeModel vin
if ($StartCharge['StartChargeSeqStat'] == 1 && $StartCharge['SuccStat'] == 0 && $StartCharge['FailReason'] == 0) {
$order_number = $this->generate_order(6);
$charge_date = date('Y-m-d', time());
$account = 200;
$Equipment_number = Db::table('charge_pile')->where('ConnectorID', $ConnectorID)->value('charge_pile_number');
$mess = [
'order_number' => $order_number,
'charge_station_id' => $station_id,
'openid' => $openid,
'charge_date' => $charge_date,
'Equipment_number' => $Equipment_number,
'StartChargeSeq' => $StartChargeSeq,
'status' => $StartCharge['StartChargeSeqStat'],
'StartChargeSeqStat' => $StartCharge['StartChargeSeqStat'],
'ConnectorID' => $ConnectorID,
'WithholdingMoney' => $account,
'EvcInfoNo' => $vin
];
Db::table($table_user)->where('openid', $openid)->update(['account' => Db::raw('account-' . $account)]);
Db::table($table)->save($mess);
$time = date('Y-m-d H:i:s');
Log::write('Reservation order has been generated. The Message is ' . $time . json($mess)->getContent());
return ['code' => 200, 'message' => '订单创建成功', 'order_number' => $order_number];
} elseif ($StartCharge['SuccStat'] == 1) {
if ($StartCharge['FailReason'] == 0) {
return ['code' => 1, 'message' => '设备认证操作结果失败'];
} elseif ($StartCharge['FailReason'] == 1) {
return ['code' => 1, 'message' => '设备认证操作结果失败 此设备不存在'];
} elseif ($StartCharge['FailReason'] == 2) {
return ['code' => 1, 'message' => '设备认证操作结果失败 此设备离线'];
} elseif ($StartCharge['FailReason'] == 90) {
return ['code' => 1, 'message' => '设备认证操作结果失败 车辆未备案'];
} elseif ($StartCharge['FailReason'] == 91) {
return ['code' => 2, 'message' => '设备认证操作结果失败 该车辆充电中'];
} else {
return ['code' => 1, 'message' => '未知错误 设备认证成功 请求充电失败'];
}
} else {
return ['code' => 1, 'message' => '未知错误 设备认证成功 请求充电失败'];
}
} elseif ($AuthMessage['SuccStat'] == 1) {
if ($AuthMessage['FailReason'] == 0) {
return ['code' => 1, 'message' => '设备认证操作结果失败'];
} elseif ($AuthMessage['FailReason'] == 1) {
return ['code' => 1, 'message' => '设备认证操作结果失败 此设备尚未插枪'];
} elseif ($AuthMessage['FailReason'] == 2) {
return ['code' => 1, 'message' => '设备认证操作结果失败 设备检测失败'];
} else {
return ['code' => 1, 'message' => '未知错误 设备认证失败'];
}
} else {
return ['code' => 1, ' message' => '未知错误 设备认证失败'];
}
} else {
return ['code' => 1, 'message' => '未知错误 设备认证失败'];
}
}
public function ModifyAppointmentTime($time): \think\response\Json
{
$dateTime = new DateTime($time);
$formattedTime = $dateTime->format('H:i:s');
$modify = Db::table('appointment_time')->where('id', 1)->save(['AppointmentTime' => $formattedTime]);
if ((int)$modify == 1) {
return json(['code' => 200, 'msg' => '修改成功']);
} else {
return json(['code' => 1, 'msg' => '修改失败']);
}
}
public function ShowAppointmentTime(): \think\response\Json
{
$AppointmentTime = Db::table('appointment_time')->where('id', 1)->value('AppointmentTime');
return json(['code' => 200, 'msg' => '显示成功', 'data' => $AppointmentTime]);
}
private function generate_StartChargeSeq($length): string
{
$chars = '0123456789';
$time = time();
$password = config('hard.OperatorID') . $time . '2';//2代表是生成的充电订单号
for ($i = 0; $i < $length; $i++) {
$password .= $chars[mt_rand(0, strlen($chars) - 1)];
}
return $password;
}
private function generate_order($length): string
{
$chars = '0123456789';
$time = time();
$password = 'DZZS' . $time;
for ($i = 0; $i < $length; $i++) {
$password .= $chars[mt_rand(0, strlen($chars) - 1)];
}
return $password;
}
private function generate_EquipmentAuth($length): string
{
$chars = '0123456789';
$time = time();
$password = config('hard.OperatorID') . $time . '1';//1代表是生成的设备认证流水号
for ($i = 0; $i < $length; $i++) {
$password .= $chars[mt_rand(0, strlen($chars) - 1)];
}
return $password;
}
public function Encrypt($data): string
{
$aes = new Aes();
return $aes->encrypt($data);
}
private function Decrypt($data)
{
$aes = new Aes();
return $aes->decrypt($data);
}
private function HmacMD5($data): string
{
$md5 = new HMACMD5();
return $md5->HMAC($data);
}
private function CurlSend($url, $data = '', $token = '')
{
$data = json_encode($data);
// echo $data;
$ch = curl_init();
$headers = array();
if ($token) {
$headers[] = 'Authorization: Bearer ' . $token;
}
$headers[] = 'Content-Type: application/json;charset=utf-8';
$headers[] = 'Content-Length: ' . strlen($data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$curl_return = curl_exec($ch);
curl_close($ch);
return json_decode(trim($curl_return), true);
}
private function checkParams($params)
{
$arr = ['OperatorID', 'Data', 'TimeStamp', 'Seq', 'Sig'];
// 参数检查
foreach ($arr as $v) {
if (empty($params[$v])) {
return $v;
}
}
return 2;
}
private function checkSig($OperatorID, $params): int
{
$sig = $OperatorID . $params['Data'] . $params['TimeStamp'] . $params['Seq'];
$ecry_sig = $this->HmacMD5($sig);
if ($params['Sig'] != $ecry_sig) {
return 1;
}
return 2;
}
public function signToken(): string
{
$key = config('hard.DataSecretIV'); //这里是自定义的一个随机字串应该写在config文件中的解密时也会用相当 于加密中常用的 盐 salt
$token = array(
"iss" => $key, //签发者 可以为空
"aud" => '', //面象的用户,可以为空
"iat" => time(), //签发时间
"nbf" => time() + 1, //在什么时候jwt开始生效 这里表示生成100秒后才生效
"exp" => time() + 7200, //token 过期时间
"data" => [ //记录的userid的信息这里是自已添加上去的如果有其它信息可以再添加数组的键值对
'name' => 'zuxing'
]
);
// print_r($token);
$jwt = JWT::encode($token, $key, "HS256"); //根据参数生成了 token
return $jwt;
}
//验证token
private function checkToken_assess($token): int
{
$key = config('hard.DataSecretIV');
$key = new Key($key, 'HS256');
$status = array("code" => 2);
try {
JWT::$leeway = 60;//当前时间减去60把时间留点余地
$decoded = JWT::decode($token, $key, array('HS256')); //HS256方式这里要和签发的时候对应
$arr = (array)$decoded;
$res['code'] = 1;
$res['data'] = $arr['data'];
return 2;
} catch (\Firebase\JWT\SignatureInvalidException $e) { //签名不正确
$status['msg'] = "签名不正确";
return 1;
} catch (\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用
$status['msg'] = "token失效";
return 1;
} catch (\Firebase\JWT\ExpiredException $e) { // token过期
$status['msg'] = "token失效";
return 1;
} catch (\Exception $e) { //其他错误
$status['msg'] = "未知错误";
return 1;
}
}
private function encodeData($data, $params, $ret, $msg = ''): \think\response\Json
{
$data = json_encode($data);
$data = $this->Encrypt($data);
$seq = empty($Seq) ? '0001' : $params['Seq'];
$datetime = empty($TimeStamp) ? date('YmdHis') : $params['TimeStamp'];
$sig = $params['OperatorID'] . $data . $datetime . $seq;
$s = $this->HmacMD5($sig);
return json(['Msg' => $msg, 'Ret' => $ret, 'Data' => $data, 'Sig' => $s]);
}
}

View File

@@ -0,0 +1,207 @@
<?php
namespace app\controller\Bus;
use app\controller\ChargeOrder;
use app\model\Vinlicense;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
class SearchMessage
{
/**
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @throws DbException
*/
public function BusOrder($message = "", $start_time = "", $end_time = ""): \think\response\Json
{
// $order = new ChargeOrder();
// $order->OrderList("o-wLg5DGWU_rYwfmp1-1Wck1lKGw");
if (!empty($end_time)) {
$end_time = date("Y-m-d", strtotime("+1day", strtotime($end_time)));
}
$busOrder = ["code" => 9001, "Msg" => "请输入正确的参数"];
if (empty($message) && empty($start_time) && empty($end_time)) {
$busOrder = Db::table("charge_order_gongjiao")->select();
} elseif (!empty($message) && empty($start_time) && empty($end_time)) {
$busOrder = Db::table("charge_order_gongjiao")->where('order_number', 'like', '%' . $message . '%')->select();
} elseif (empty($message) && !empty($start_time) && !empty($end_time)) {
$busOrder = Db::table("charge_order_gongjiao")->whereBetweenTime('start_time', $start_time, $end_time)->select();
} elseif (!empty($message) && !empty($start_time) && !empty($end_time)) {
$busOrder = Db::table("charge_order_gongjiao")->where('order_number', 'like', '%' . $message . '%')->whereBetweenTime('start_time', $start_time, $end_time)->select();
}
$busOrder = $busOrder->toArray();
for ($i = 0; $i < count($busOrder); $i++) {
if (!isset($busOrder['code'])) {
$busOrder[$i]["order_id"] = $i + 1;
$busOrder[$i]["charge_station_name"] = Db::table("charge_station")->where("charge_station_id", $busOrder[$i]["charge_station_id"])->value("charge_station_name");
$busOrder[$i]["charge_station_number"] = Db::table("charge_station")->where("charge_station_id", $busOrder[$i]["charge_station_id"])->value("charge_station_number");
$busOrder[$i]["no"] = Db::table("charge_pile")->where("charge_pile_number", $busOrder[$i]["Equipment_number"])->value("no");
$busOrder[$i]["parkNo"] = Vinlicense::where("EvcInfoNo", $busOrder[$i]["EvcInfoNo"])->value("ParkNo");
$busOrder[$i]["SelfCode"] = Vinlicense::where("EvcInfoNo", $busOrder[$i]["EvcInfoNo"])->value("SelfCode");
if ($busOrder[$i]["IdentCode"] == 7) {
$busOrder[$i]["IdentCode"] = '设备异常';
} elseif ($busOrder[$i]["IdentCode"] == 15) {
$busOrder[$i]["IdentCode"] = '系统异常';
}
if (strlen((string)$busOrder[$i]['stop_type']) != 0 && $busOrder[$i]['stop_type'] == 0) {
$busOrder[$i]['stop_type'] = '正常停止';
} elseif ($busOrder[$i]['stop_type'] == 4) {
$busOrder[$i]['stop_type'] = '连接器断开';
} elseif ($busOrder[$i]['stop_type'] == 5) {
$busOrder[$i]['stop_type'] = '电池已充满';
} elseif ($busOrder[$i]['stop_type'] == 7) {
$busOrder[$i]['stop_type'] = '设备异常';
} elseif ($busOrder[$i]['stop_type'] == 8) {
$busOrder[$i]['stop_type'] = '枪头被拔下';
} elseif ($busOrder[$i]['stop_type'] == 10) {
$busOrder[$i]['stop_type'] = '设备故障';
} elseif ($busOrder[$i]['stop_type'] == 11) {
$busOrder[$i]['stop_type'] = '车辆故障';
} elseif ($busOrder[$i]['stop_type'] == 14) {
$busOrder[$i]['stop_type'] = '未知';
} elseif ($busOrder[$i]['stop_type'] == 15) {
$busOrder[$i]['stop_type'] = '系统异常';
} elseif ($busOrder[$i]['stop_type'] == 22) {
$busOrder[$i]['stop_type'] = '车辆识别失败';
} elseif ($busOrder[$i]['stop_type'] == 24) {
$busOrder[$i]['stop_type'] = '设备终止';
} elseif ($busOrder[$i]['stop_type'] == 25) {
$busOrder[$i]['stop_type'] = '互联互通终止';
} elseif ($busOrder[$i]['stop_type'] == 26) {
$busOrder[$i]['stop_type'] = '平台终止';
} elseif ($busOrder[$i]['stop_type'] == 27) {
$busOrder[$i]['stop_type'] = 'SOC限制终止';
} elseif ($busOrder[$i]['stop_type'] == 13) {
$busOrder[$i]['stop_type'] = '急停按钮被按下';
} elseif ($busOrder[$i]['stop_type'] == 16) {
$busOrder[$i]['stop_type'] = '主动防护';
} elseif ($busOrder[$i]['stop_type'] == 6) {
$busOrder[$i]['stop_type'] = 'BMS异常';
} elseif ($busOrder[$i]['stop_type'] == 12) {
$busOrder[$i]['stop_type'] = '账户余额不足';
} elseif ($busOrder[$i]['stop_type'] == 31) {
$busOrder[$i]['stop_type'] = '操作频繁,请稍后再试';
} elseif ($busOrder[$i]['stop_type'] == 32) {
$busOrder[$i]['stop_type'] = '请重新插枪启动充电';
} elseif ($busOrder[$i]['stop_type'] == 33) {
$busOrder[$i]['stop_type'] = '账户超出限额';
} elseif (strlen((string)$busOrder[$i]['stop_type']) == 0) {
$busOrder[$i]['stop_type'] = null;
} else {
$busOrder[$i]['stop_type'] = '未知错误';
}
}
}
return json($busOrder);
}
public function BusOrderPark($start_time = "", $end_time = "", $parkNo = ""): \think\response\Json
{
// $order = new ChargeOrder();
// $order->OrderList("o-wLg5DGWU_rYwfmp1-1Wck1lKGw");
if (!empty($end_time)) {
$end_time = date("Y-m-d", strtotime("+1day", strtotime($end_time)));
}
$busOrder = ["code" => 9001, "Msg" => "请输入正确的参数"];
if (empty($parkNo) && empty($start_time) && empty($end_time)) {
$busOrder = Db::table("charge_order_gongjiao")->select();
} elseif (!empty($parkNo) && empty($start_time) && empty($end_time)) {
$vin = Vinlicense::where("ParkNo", $parkNo)->value("EvcInfoNo");
if (empty($vin)) {
$vin = "NotFound";
}
$busOrder = Db::table("charge_order_gongjiao")->where('EvcInfoNo', $vin)->select();
} elseif (empty($parkNo) && !empty($start_time) && !empty($end_time)) {
$busOrder = Db::table("charge_order_gongjiao")->whereBetweenTime('start_time', $start_time, $end_time)->select();
} elseif (!empty($parkNo) && !empty($start_time) && !empty($end_time)) {
$vin = Vinlicense::where("ParkNo", $parkNo)->value("EvcInfoNo");
if (empty($vin)) {
$vin = "NotFound";
}
$busOrder = Db::table("charge_order_gongjiao")->where('EvcInfoNo', $vin)->whereBetweenTime('start_time', $start_time, $end_time)->select();
}
$busOrder = $busOrder->toArray();
for ($i = 0; $i < count($busOrder); $i++) {
if (!isset($busOrder['code'])) {
$busOrder[$i]["order_id"] = $i + 1;
$busOrder[$i]["charge_station_name"] = Db::table("charge_station")->where("charge_station_id", $busOrder[$i]["charge_station_id"])->value("charge_station_name");
$busOrder[$i]["charge_station_number"] = Db::table("charge_station")->where("charge_station_id", $busOrder[$i]["charge_station_id"])->value("charge_station_number");
$busOrder[$i]["no"] = Db::table("charge_pile")->where("charge_pile_number", $busOrder[$i]["Equipment_number"])->value("no");
$busOrder[$i]["parkNo"] = Vinlicense::where("EvcInfoNo", $busOrder[$i]["EvcInfoNo"])->value("ParkNo");
$busOrder[$i]["SelfCode"] = Vinlicense::where("EvcInfoNo", $busOrder[$i]["EvcInfoNo"])->value("SelfCode");
if ($busOrder[$i]["IdentCode"] == 7) {
$busOrder[$i]["IdentCode"] = '设备异常';
} elseif ($busOrder[$i]["IdentCode"] == 15) {
$busOrder[$i]["IdentCode"] = '系统异常';
}
if (strlen((string)$busOrder[$i]['stop_type']) != 0 && $busOrder[$i]['stop_type'] == 0) {
$busOrder[$i]['stop_type'] = '正常停止';
} elseif ($busOrder[$i]['stop_type'] == 4) {
$busOrder[$i]['stop_type'] = '连接器断开';
} elseif ($busOrder[$i]['stop_type'] == 5) {
$busOrder[$i]['stop_type'] = '电池已充满';
} elseif ($busOrder[$i]['stop_type'] == 7) {
$busOrder[$i]['stop_type'] = '设备异常';
} elseif ($busOrder[$i]['stop_type'] == 8) {
$busOrder[$i]['stop_type'] = '枪头被拔下';
} elseif ($busOrder[$i]['stop_type'] == 10) {
$busOrder[$i]['stop_type'] = '设备故障';
} elseif ($busOrder[$i]['stop_type'] == 11) {
$busOrder[$i]['stop_type'] = '车辆故障';
} elseif ($busOrder[$i]['stop_type'] == 14) {
$busOrder[$i]['stop_type'] = '未知';
} elseif ($busOrder[$i]['stop_type'] == 15) {
$busOrder[$i]['stop_type'] = '系统异常';
} elseif ($busOrder[$i]['stop_type'] == 22) {
$busOrder[$i]['stop_type'] = '车辆识别失败';
} elseif ($busOrder[$i]['stop_type'] == 24) {
$busOrder[$i]['stop_type'] = '设备终止';
} elseif ($busOrder[$i]['stop_type'] == 25) {
$busOrder[$i]['stop_type'] = '互联互通终止';
} elseif ($busOrder[$i]['stop_type'] == 26) {
$busOrder[$i]['stop_type'] = '平台终止';
} elseif ($busOrder[$i]['stop_type'] == 27) {
$busOrder[$i]['stop_type'] = 'SOC限制终止';
} elseif ($busOrder[$i]['stop_type'] == 13) {
$busOrder[$i]['stop_type'] = '急停按钮被按下';
} elseif ($busOrder[$i]['stop_type'] == 16) {
$busOrder[$i]['stop_type'] = '主动防护';
} elseif ($busOrder[$i]['stop_type'] == 6) {
$busOrder[$i]['stop_type'] = 'BMS异常';
} elseif ($busOrder[$i]['stop_type'] == 12) {
$busOrder[$i]['stop_type'] = '账户余额不足';
} elseif ($busOrder[$i]['stop_type'] == 31) {
$busOrder[$i]['stop_type'] = '操作频繁,请稍后再试';
} elseif ($busOrder[$i]['stop_type'] == 32) {
$busOrder[$i]['stop_type'] = '请重新插枪启动充电';
} elseif ($busOrder[$i]['stop_type'] == 33) {
$busOrder[$i]['stop_type'] = '账户超出限额';
} elseif (strlen((string)$busOrder[$i]['stop_type']) == 0) {
$busOrder[$i]['stop_type'] = null;
} else {
$busOrder[$i]['stop_type'] = '未知错误';
}
}
}
return json($busOrder);
}
public function ParkNo(): \think\response\Json
{
$Park = (new \app\model\Vinlicense)->column("ParkNo");
$data = [];
foreach ($Park as $p) {
$data["children"][]["LicenseNumber"] = $p;
}
return json($data);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace app\controller\Bus;
use app\controller\utils;
use app\model\Vinlicense;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
class VinBindLicense extends utils
{
public function ShowVinLicense($parkNo = ""): \think\response\Json
{
if (!empty($parkNo)) {
$vin = Vinlicense::where("ParkNo", $parkNo)->value("EvcInfoNo");
$VinLicense = Vinlicense::where("EvcInfoNo", $vin)->select();
return $this->ResponseJson($VinLicense, 200, "Request Success");
}
$VinLicense = Vinlicense::select();
return $this->ResponseJson($VinLicense, 200, "Request Success");
}
/**
* @throws ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
*/
public function AddVinLicense($vin, $parkNo, $selfCode): \think\response\Json
{
$checkVin = Vinlicense::where("EvcInfoNo", $vin)->find();
$checkLicense = Vinlicense::where("ParkNo", $parkNo)->find();
$checkSelfCode = Vinlicense::where("SelfCode", $selfCode)->find();
if (empty($checkVin) && empty($checkLicense) && empty($checkSelfCode)) {
$AddVinLicense = (new \app\model\Vinlicense)->save([
"EvcInfoNo" => $vin,
'ParkNo' => $parkNo,
"SelfCode" => $selfCode
]);
if ($AddVinLicense == 1) {
$NewVinLicense = Vinlicense::where("EvcInfoNo", $vin)->select();
return $this->ResponseJson($NewVinLicense, 200, "新增成功");
} else {
return $this->ResponseJson([], 415, "新增失败");
}
} else {
return $this->ResponseJson([], 416, "Vin或车牌号已存在");
}
}
/**
* @throws ModelNotFoundException
* @throws DataNotFoundException
* @throws DbException
*/
public function UpdateVinLicense($id, $vin, $parkNo, $selfCode): \think\response\Json
{
$oldVin = Vinlicense::where("id", $id)->value('EvcInfoNo');
$oldParkNo = Vinlicense::where("id", $id)->value('ParkNo');
$oldSelfCode = Vinlicense::where("id", $id)->value('ParkNo');
if ($oldVin != $vin) {
$checkVin = Vinlicense::where("EvcInfoNo", $vin)->find();
if (!empty($checkVin)) {
return $this->ResponseJson([], 421, "所输入的vin已存在");
}
}
if ($oldParkNo != $parkNo) {
$checkLicense = Vinlicense::where("ParkNo", $parkNo)->find();
if (!empty($checkLicense)) {
return $this->ResponseJson([], 422, "所输入的车牌号已存在");
}
}
if ($oldSelfCode != $selfCode) {
$checkLicense = Vinlicense::where("SelfCode", $selfCode)->find();
if (!empty($checkLicense)) {
return $this->ResponseJson([], 423, "所输入的自编码已存在");
}
}
$checkId = Vinlicense::where("id", $id)->find();
if (empty($checkId)) {
return $this->ResponseJson([], 420, "没有找到该ID");
}
$UpdateVinLicense = Vinlicense::where("id", $id)->save([
'EvcInfoNo' => $vin,
'ParkNo' => $parkNo,
'SelfCode' => $selfCode
]);
if ($UpdateVinLicense == 1) {
$NewVinLicense = Vinlicense::where("id", $id)->select();
return $this->ResponseJson($NewVinLicense, 200, "修改成功");
} else {
return $this->ResponseJson([], 417, "修改失败");
}
}
public function DeleteVinLicense($id): \think\response\Json
{
$DeleteVinLicense = Vinlicense::where("id", $id)->delete();
if ($DeleteVinLicense != 0) {
return $this->ResponseJson([], 200, "删除成功");
} else {
return $this->ResponseJson([], 418, "删除失败");
}
}
}