Commit 93410bf8 by banice

修复开始充电无开始用电量问题

parent 29a8f66c
......@@ -357,7 +357,7 @@ class AccessController extends Controller
}
$order->setOnlineTime(time());
if ($offlineReason == 1) {
if ($offlineReason == 0) {
$orderState = new OfflineNetState($order);
} else {
$orderState = new OfflinePowerState($order);
......
......@@ -24,9 +24,9 @@ class StartController extends Controller
'04' => [
'type' => 1,
'type' => 1,
'logic_id' => 1,
'state' => 1,
'state' => 1,
'order_id' => 6,
'capacity' => 4,
],
......@@ -49,9 +49,7 @@ class StartController extends Controller
$this->logRecord->setOrderId($orderId);
$capacity = hexdec($this->getRequest()->get('capacity'));
Log::debug($this->getRequest()->get('capacity'));
Log::debug('order_id-->' . $orderId);
Log::debug('capacity-->' . $capacity);
if ($type == 1) {
......@@ -87,29 +85,24 @@ class StartController extends Controller
}
}
$lastState = $order->getStateCode();
$orderState = new WaitingState($order);
// break;
// case StateCode::PORT_CHARGER;
// $orderState = new ChargerState($order);
// break;
//
// }
$portId = $orderState->getOrder()->getPortId();
$this->logRecord->setPortId($portId);
switch ($state) {
case StateCode::PORT_CHARGER:
$orderState->toChargerState();
break;
case StateCode::PORT_EXCEPTION:
$orderState->toExceptionState();
break;
case StateCode::PORT_SHED:
Log::debug('port_shed');
$orderState->toShedState();
break;
case StateCode::FINISH_EXCEED:
Log::debug('exceed');
$orderState->toPowerExceedState();
break;
......
......@@ -111,6 +111,7 @@ class PowerController extends Controller
public function plural()
{
//todo 最近的用电量作为结束用电量更新
$logicId = hexdec($this->request->get('logic_id'));
$startTime = hexdec($this->request->get('start_time'));
$intervalTime = hexdec($this->request->get('interval_time'));
......@@ -170,6 +171,13 @@ class PowerController extends Controller
]);
$startTime += $intervalTime;
//更新结束充电用电量
if ($i === ($count - 1)) {
$orderModel = new OrderModel();
$orderModel->update([
'end_capacity' => hexdec($capacitys[$i]),
], 'id = ' . $orderId);
}
}
} else {
......
......@@ -10,6 +10,7 @@ namespace Application\controller\update;
use Application\controller\Controller;
use Application\model\DeviceModel;
use Application\model\GatewayModel;
use Application\model\GatewayUpdateModel;
use GatewayWorker\Lib\Gateway;
......@@ -23,6 +24,10 @@ class QueryController extends Controller
'D1' => [
'hardware_version' => 4,
'software_version' => 4,
],
'CD' => [
'hardware_version' => 4,
'software_version' => 4,
]
];
......@@ -36,6 +41,19 @@ class QueryController extends Controller
parent::__destruct();
}
public function currentVersion()
{
$gatewayModel = new GatewayModel();
$gatewayModel->update([
'hardware_version' => $this->request->get('hardware_version'),
'software_version' => $this->request->get('software_version'),
], 'id = ' . $_SESSION['gateway_id']);
}
/**
* @throws \Exception
*/
......@@ -85,11 +103,20 @@ class QueryController extends Controller
$urlHex .= $hex;
}
Log::debug($updateSoftwareVersion);
Log::debug($updateHardwareVersion);
Log::debug($sign);
Log::debug($urlHex);
$this->response->send('d1', $returnCode . $updateHardwareVersion . $updateSoftwareVersion . $sign . $urlHex);
return;
}
$this->response->send('d1', $returnCode);
return;
}
$this->response->send('d1', '11');
return;
}
......
......@@ -45,6 +45,8 @@ class Api
$this->add('0E', 'setting\DeviceMacController@getAll');
$this->add('D1', 'update\QueryController@check');
$this->add('CD', 'update\QueryController@currentVersion');
}
......
......@@ -41,11 +41,11 @@ class ChargerState extends State
{
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => $this->order->getEndCode(),
'is_stop' => $this->order->getEndCode(),
'end_capacity' => $this->order->getEndCapacity(),
'updated_at' => $this->nowDate,
'end_time' => $this->nowDate,
'state' => 1,
'updated_at' => $this->nowDate,
'end_time' => $this->nowDate,
'state' => 1,
], 'id = ' . $this->order->getId());
$port = new Port();
......@@ -78,9 +78,9 @@ class ChargerState extends State
$orderException = new OrderExceptionModel();
$orderException->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_USER,
'desc' => '用户主动结束充电',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_USER,
'desc' => '用户主动结束充电',
'created_at' => $this->nowDate,
]);
......@@ -122,17 +122,17 @@ class ChargerState extends State
//更新订单状态
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_EXCEED,
'is_stop' => StateCode::FINISH_EXCEED,
'end_capacity' => $this->order->getEndCapacity(),
'end_time' => $this->nowDate,
'state' => 1,
'end_time' => $this->nowDate,
'state' => 1,
], 'id = ' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_EXCEED,
'desc' => '功率超限',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_EXCEED,
'desc' => '功率超限',
'created_at' => date('Y-m-d H:i:s', $this->nowTimeStamp),
]);
......@@ -177,17 +177,17 @@ class ChargerState extends State
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_FULL,
'end_time' => $this->nowDate,
'is_stop' => StateCode::FINISH_FULL,
'end_time' => $this->nowDate,
'end_capacity' => $this->order->getEndCapacity(),
'state' => 1,
'state' => 1,
], 'id = ' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_FULL,
'desc' => '订单充电自停',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_FULL,
'desc' => '订单充电自停',
'created_at' => $this->nowDate,
]);
......@@ -241,16 +241,16 @@ class ChargerState extends State
$orderModel = new OrderModel();
$orderModel->update([
'updated_at' => $this->nowDate,
'shed_time' => $this->nowDate,
'shed_time' => $this->nowDate,
], 'id = ' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::PORT_SHED,
'desc' => '口子脱落',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::PORT_SHED,
'desc' => '口子脱落',
'created_at' => $this->nowDate,
]);
......@@ -279,13 +279,13 @@ class ChargerState extends State
$publish = new PublishPortShed();
$publish->publishOrder([
'order_id' => $this->order->getId(),
'shed_time' => $this->nowTimeStamp,
'port_id' => $this->order->getPortId(),
'order_id' => $this->order->getId(),
'shed_time' => $this->nowTimeStamp,
'port_id' => $this->order->getPortId(),
'gateway_mac' => $this->order->getGatewayMac(),
'check_times' => 1,
'gateway_id' => $this->order->getGatewayId(),
'station_id' => $_SESSION['station_id'],
'gateway_id' => $this->order->getGatewayId(),
'station_id' => $_SESSION['station_id'],
]);
} catch (\Exception $exception) {
......@@ -317,11 +317,11 @@ class ChargerState extends State
{
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_TIME_END,
'is_stop' => StateCode::FINISH_TIME_END,
'end_capacity' => $this->order->getEndCapacity(),
'end_time' => $this->nowDate,
'updated_at' => $this->nowDate,
'state' => 1,
'end_time' => $this->nowDate,
'updated_at' => $this->nowDate,
'state' => 1,
], 'id = ' . $this->order->getId());
$port = new Port();
......@@ -352,6 +352,12 @@ class ChargerState extends State
}
public function toRefundFinish()
{
Log::error('charger state can not change to refund finish');
}
/**
* 关闭失败
*/
......
......@@ -44,11 +44,11 @@ class ChargerState extends State
{
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => $this->order->getEndCode(),
'is_stop' => $this->order->getEndCode(),
'end_capacity' => $this->order->getEndCapacity(),
'updated_at' => $this->nowDate,
'end_time' => $this->nowDate,
'state' => 1,
'updated_at' => $this->nowDate,
'end_time' => $this->nowDate,
'state' => 1,
], 'id = ' . $this->order->getId());
$port = new Port();
......@@ -81,9 +81,9 @@ class ChargerState extends State
$orderException = new OrderExceptionModel();
$orderException->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_USER,
'desc' => '用户主动结束充电',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_USER,
'desc' => '用户主动结束充电',
'created_at' => $this->nowDate,
]);
......@@ -125,29 +125,29 @@ class ChargerState extends State
//更新订单状态
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_EXCEED,
'is_stop' => StateCode::FINISH_EXCEED,
'end_capacity' => $this->order->getEndCapacity(),
'end_time' => $this->nowDate,
'state' => 1,
'end_time' => $this->nowDate,
'state' => 1,
], 'id = ' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_EXCEED,
'desc' => '功率超限',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_EXCEED,
'desc' => '功率超限',
'created_at' => date('Y-m-d H:i:s', $this->nowTimeStamp),
]);
$exceptionModel = new ExceptionModel();
$exceptionModel->insertRow([
'message' => '功率超限',
'message' => '功率超限',
'gateway_id' => isset($_SESSION['gateway_id']) ? $_SESSION['gateway_id'] : '',
'station_id' => isset($_SESSION['station_id']) ? $_SESSION['station_id'] : '',
'port_id' => $this->order->getPortId(),
'port_id' => $this->order->getPortId(),
'created_at' => date('Y-m-d H:i:s'),
'type' => 2,
'type' => 2,
]);
......@@ -192,17 +192,17 @@ class ChargerState extends State
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_FULL,
'end_time' => $this->nowDate,
'is_stop' => StateCode::FINISH_FULL,
'end_time' => $this->nowDate,
'end_capacity' => $this->order->getEndCapacity(),
'state' => 1,
'state' => 1,
], 'id = ' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_FULL,
'desc' => '订单充满自停',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_FULL,
'desc' => '订单充满自停',
'created_at' => $this->nowDate,
]);
......@@ -259,27 +259,27 @@ class ChargerState extends State
$orderModel = new OrderModel();
$orderModel->update([
'updated_at' => $this->nowDate,
'shed_time' => $this->nowDate,
'shed_time' => $this->nowDate,
], 'id = ' . $this->order->getId());
$orderExceptionModel = new OrderExceptionModel();
$orderExceptionModel->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::PORT_SHED,
'desc' => '口子脱落',
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::PORT_SHED,
'desc' => '口子脱落',
'created_at' => $this->nowDate,
]);
$exceptionModel = new ExceptionModel();
$exceptionModel->insertRow([
'message' => '口子脱落',
'message' => '口子脱落',
'gateway_id' => isset($_SESSION['gateway_id']) ? $_SESSION['gateway_id'] : '',
'station_id' => isset($_SESSION['station_id']) ? $_SESSION['station_id'] : '',
'port_id' => $this->order->getPortId(),
'port_id' => $this->order->getPortId(),
'created_at' => date('Y-m-d H:i:s'),
'type' => 2,
'type' => 2,
]);
//更新端口状态和订单状态
......@@ -300,20 +300,20 @@ class ChargerState extends State
Log::error('send port shed message fail');
}
//todo publish 十分钟的延迟任务
// publish 十分钟的延迟任务
try {
$publish = new PublishPortShed();
$publish->publishOrder([
'order_id' => $this->order->getId(),
'shed_time' => $this->nowTimeStamp,
'port_id' => $this->order->getPortId(),
'order_id' => $this->order->getId(),
'shed_time' => $this->nowTimeStamp,
'port_id' => $this->order->getPortId(),
'gateway_mac' => $this->order->getGatewayMac(),
'check_times' => 1,
'gateway_id' => $this->order->getGatewayId(),
'station_id' => $_SESSION['station_id'],
'gateway_id' => $this->order->getGatewayId(),
'station_id' => $_SESSION['station_id'],
]);
} catch (\Exception $exception) {
......@@ -345,11 +345,11 @@ class ChargerState extends State
{
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_TIME_END,
'is_stop' => StateCode::FINISH_TIME_END,
'end_capacity' => $this->order->getEndCapacity(),
'end_time' => $this->nowDate,
'updated_at' => $this->nowDate,
'state' => 1,
'end_time' => $this->nowDate,
'updated_at' => $this->nowDate,
'state' => 1,
], 'id = ' . $this->order->getId());
$port = new Port();
......
......@@ -9,6 +9,7 @@
namespace Lib\cdz\order\state;
use GuzzleHttp\Psr7\LazyOpenStream;
use Lib\cdz\order\NoticePortShed;
use Lib\cdz\order\Order;
use Lib\log\Log;
......@@ -35,14 +36,20 @@ class OfflineNetState extends State
}
$startTime = $this->order->getStartTime();
$stateCode = $this->order->getStateCode();
if ($startTime === '' || $this->order->getOfflineTime() == '0') {
if ($startTime === '') {
Log::debug('time equal purchase time');
$this->remainChargerTime = (int)($this->order->getPurchaseTime());
} else {
$purchaseTime = $this->order->getPurchaseTime();
$this->remainChargerTime = $purchaseTime * 60 - ((int)$this->order->getOnlineTime() - $startTime);
Log::debug('off net');
Log::debug($this->order->getOnlineTime());
Log::debug($startTime . 'start_time');
Log::debug('remain charger time' . $this->remainChargerTime);
Log::debug('remain time' . ceil($this->remainChargerTime / 60));
$this->remainChargerTime = ceil($this->remainChargerTime / 60);
......
......@@ -40,6 +40,8 @@ class OfflinePowerState extends State
$purchaseTime = $this->order->getPurchaseTime();
$this->remainChargerTime = $purchaseTime * 60 - ($offlineTime - $startTime);
Log::debug($offlineTime . '---' . $startTime . '-----' . $this->remainChargerTime);
$this->order->setStartTime(strval((int)$startTime + ((int)time() - (int)$offlineTime)));
$this->remainChargerTime = ceil($this->remainChargerTime / 60);
$saveOrder = new OrderSaveRedis($this->order);
......
......@@ -84,6 +84,8 @@ class WaitingState extends State
*/
public function toChargerState(): void
{
//订单已经退款则直接结束
if ($this->order->getIsRefund() == 1) {
// 下发结束充电命令
......@@ -130,13 +132,15 @@ class WaitingState extends State
}
//更新订单状态
$update = [
'is_charger' => StateCode::PORT_CHARGER,
'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()),
'start_capacity' => $this->order->getStartCapacity(),
'is_charger' => StateCode::PORT_CHARGER,
'start_time' => date('Y-m-d H:i:s', $this->order->getStartTime()),
];
//更新订单状态
if ($this->order->getStartCapacity() !== -2) {
$update['start_capacity'] = (int)$this->order->getStartCapacity();
}
$orderModel = new OrderModel();
$orderModel->update($update, 'id = ' . $this->order->getId());
......
......@@ -44,7 +44,7 @@ class PublishPortShed
}
public function publishOrder(array $message, string $routeKey = 'delay_check_port_charger_state')
{
......
......@@ -69,6 +69,11 @@ class Bintohex
Log::error('encode error');
return;
}
if (ctype_xdigit($buffer) === false) {
Log::error('not hex fomat', ['buffer' => $buffer]);
return;
}
return pack('H*', bin2hex(hex2bin($buffer)));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment