Commit 2abe7fc5 by banice

将response也写入日志当中

parent 354ef632
...@@ -2,7 +2,7 @@ REDIS_HOST=redis.test.senthink.com ...@@ -2,7 +2,7 @@ REDIS_HOST=redis.test.senthink.com
REGISTER_IP=127.0.0.1 REGISTER_IP=127.0.0.1
REGISTER_PORT=1239 REGISTER_PORT=1239
GATEWAY_PORT=8282 GATEWAY_PORT=8283
GATEWAY_IP=127.0.0.1 GATEWAY_IP=127.0.0.1
GATEWAY_COUNT=1 GATEWAY_COUNT=1
GATEWAY_START_PORT=2130 GATEWAY_START_PORT=2130
...@@ -25,6 +25,9 @@ MESSAGE_API_URL=https://cdzback2.test.senthink.com ...@@ -25,6 +25,9 @@ MESSAGE_API_URL=https://cdzback2.test.senthink.com
MESSAGE_START=L9SEWl3X73v3PBYHtFBZlTlJeBMdO9DDNIwRgHX6SrY MESSAGE_START=L9SEWl3X73v3PBYHtFBZlTlJeBMdO9DDNIwRgHX6SrY
MESSAGE_FAIL=0al-a6kkNsdqFyXPEe97m4jjtbfOXjEC3eCjEsMHJdw MESSAGE_FAIL=0al-a6kkNsdqFyXPEe97m4jjtbfOXjEC3eCjEsMHJdw
MESSAGE_POWER_EXCEED=rdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU MESSAGE_POWER_EXCEED=rdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU
MESSAGE_FINISH_USER=f0DDXSxvRTbHyzkCnwnYijtgteFTdfdUR7J8REwTYJ8
MESSAGE_PORT_SHED=C0LvfETe-1rCR_IhOydDGPTUwwYkrWZxgfwMsETrhw8
MESSAGE_CHARGER_TIMEOUT=f0DDXSxvRTbHyzkCnwnYijtgteFTdfdUR7J8REwTYJ8
LOW_POWER_LIMIT=30
...@@ -26,5 +26,4 @@ MESSAGE_START=L9SEWl3X73v3PBYHtFBZlTlJeBMdO9DDNIwRgHX6SrY ...@@ -26,5 +26,4 @@ MESSAGE_START=L9SEWl3X73v3PBYHtFBZlTlJeBMdO9DDNIwRgHX6SrY
MESSAGE_FAIL=0al-a6kkNsdqFyXPEe97m4jjtbfOXjEC3eCjEsMHJdw MESSAGE_FAIL=0al-a6kkNsdqFyXPEe97m4jjtbfOXjEC3eCjEsMHJdw
MESSAGE_POWER_EXCEED=rdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU MESSAGE_POWER_EXCEED=rdzTNQ7t4uRXkP0SkuwW10WH77A_CIgYFiJykXJ0utU
LOW_POWER_LIMIT=30
...@@ -72,6 +72,7 @@ class Events ...@@ -72,6 +72,7 @@ class Events
$crc = substr($message, -2); $crc = substr($message, -2);
var_dump($message);
$crcConfirm = sprintf('%08x', Crc::crc(substr($message, 0, strlen($message) - 2))); $crcConfirm = sprintf('%08x', Crc::crc(substr($message, 0, strlen($message) - 2)));
if ($crc != mb_strtoupper(substr($crcConfirm, 0, 2))) { if ($crc != mb_strtoupper(substr($crcConfirm, 0, 2))) {
...@@ -79,6 +80,7 @@ class Events ...@@ -79,6 +80,7 @@ class Events
return; return;
} }
$command = substr($message, 6, 2); $command = substr($message, 6, 2);
$api = new Api(); $api = new Api();
$api->boot(); $api->boot();
...@@ -110,6 +112,8 @@ class Events ...@@ -110,6 +112,8 @@ class Events
public static function onClose($clientId) public static function onClose($clientId)
{ {
var_dump('close');
Events::pipe(); Events::pipe();
$gatewayId = $_SESSION['gateway_id']; $gatewayId = $_SESSION['gateway_id'];
$gateway = new Gateway(); $gateway = new Gateway();
......
...@@ -171,11 +171,17 @@ class Controller ...@@ -171,11 +171,17 @@ class Controller
} }
public function __destruct() public function __destruct()
{ {
$logWriter = new GatewayLogWriter(); $logWriter = new GatewayLogWriter();
if($this->response->getResponseMessage() !== '')
{
$this->logRecord->setResponse($this->response->getResponseMessage());
}
$logWriter->write($this->logRecord); $logWriter->write($this->logRecord);
} }
/** /**
...@@ -493,4 +499,6 @@ class Controller ...@@ -493,4 +499,6 @@ class Controller
return $this; return $this;
} }
} }
\ No newline at end of file
...@@ -25,9 +25,9 @@ class HeartController extends Controller ...@@ -25,9 +25,9 @@ class HeartController extends Controller
] ]
]; ];
public function __construct(string $clientId, string $message, Route $route) public function __construct(string $clientId, string $message, string $command)
{ {
parent::__construct($clientId, $message, $route); parent::__construct($clientId, $message, $command);
} }
public function break() public function break()
......
...@@ -67,10 +67,12 @@ class AccessController extends Controller ...@@ -67,10 +67,12 @@ class AccessController extends Controller
'id', 'id',
], 'mac_address = ' . "'$mac'"); ], 'mac_address = ' . "'$mac'");
if (count($gatewayModelResult) === 0) { var_dump($gatewayModelResult);
if($gatewayModelResult == false)
{
Gateway::closeClient($this->clientId); Gateway::closeClient($this->clientId);
return;
} }
$stationId = $gatewayModelResult['station_id']; $stationId = $gatewayModelResult['station_id'];
$gatewayId = $gatewayModelResult['id']; $gatewayId = $gatewayModelResult['id'];
...@@ -114,12 +116,10 @@ class AccessController extends Controller ...@@ -114,12 +116,10 @@ class AccessController extends Controller
$gateway = new \Lib\station\gateway\Gateway(); $gateway = new \Lib\station\gateway\Gateway();
$gateway->setState($gatewayId,1); $gateway->setState($gatewayId, 1);
$this->response->send('02', $sessionId); $this->response->send('02', $sessionId);
unset($this->response);
} }
} }
...@@ -152,6 +152,11 @@ class AccessController extends Controller ...@@ -152,6 +152,11 @@ class AccessController extends Controller
} }
if(isset($_SESSION['port_mac_id']) == false)
{
return ;
}
$portsMacId = $_SESSION['port_mac_id']; $portsMacId = $_SESSION['port_mac_id'];
...@@ -186,9 +191,8 @@ class AccessController extends Controller ...@@ -186,9 +191,8 @@ class AccessController extends Controller
$_SESSION['port_logic_id'] = $portsLogicId; $_SESSION['port_logic_id'] = $portsLogicId;
//更新逻辑地址 //更新逻辑地址
foreach ($portsLogicId as $portId => $logicId) foreach ($portsLogicId as $portId => $logicId) {
{ $deviceModel->update(['logic_num' => $logicId], 'id = ' . $portId);
$deviceModel->update(['logic_num' => $logicId],'id = '.$portId);
} }
$order = new Order(); $order = new Order();
...@@ -196,28 +200,27 @@ class AccessController extends Controller ...@@ -196,28 +200,27 @@ class AccessController extends Controller
$offlineReason = hexdec(substr($this->message, $this->plc, 2)); $offlineReason = hexdec(substr($this->message, $this->plc, 2));
$orderCount = '00';
foreach ($portsId as $portId) { foreach ($portsId as $portId) {
$port->setPortId($portId); $port->setPortId($portId);
$orderId = $port->getPortUsingOrderId(); $orderId = $port->getPortUsingOrderId();
if($orderId == false || $orderId == '') if ($orderId == false || $orderId == '') {
{
continue; continue;
} }
$order->setId($orderId); $order->setId($orderId);
if($order->getOrderCache(\Events::getRedis()) ==false) if ($order->getOrderCache(\Events::getRedis()) == false) {
{
continue; continue;
} }
if($offlineReason === 1) if ($offlineReason === 1) {
{
$orderState = new OfflinePowerState($order); $orderState = new OfflinePowerState($order);
}else{ } else {
$orderState = new OfflineNetState($order); $orderState = new OfflineNetState($order);
} }
...@@ -226,33 +229,27 @@ class AccessController extends Controller ...@@ -226,33 +229,27 @@ class AccessController extends Controller
$remainTime = $orderState->getRemainChargerTime(); $remainTime = $orderState->getRemainChargerTime();
if($remainTime > 0) if ($remainTime > 0) {
{ $logicNum = sprintf('%02x', $order->getPortLogicId());
$logicNum = sprintf('%02x',$order->getPortLogicId()); $orderId = sprintf('%012x', $order->getId());
$orderId = sprintf('%012x',$order->getId()); $time = sprintf('%04x', $remainTime);
$time = sprintf('%04x',$remainTime);
array_push($responseOrder,$logicNum.$orderId.$time); array_push($responseOrder, $logicNum . $orderId . $time);
} }
$logicStart = sprintf('%02x',$logicStart);
$count = sprintf('%02x',$count);
$totalCount = sprintf('%02x',$totalCount);
$orderCount = sprintf('%02x',count($responseOrder));
$this->response->send('03',$logicStart.$count.$totalCount.$orderCount.implode('',$responseOrder));;
} }
$logicStart = sprintf('%02x', $logicStart);
$count = sprintf('%02x', $count);
$totalCount = sprintf('%02x', $totalCount);
$orderCount = sprintf('%02x', count($responseOrder));
var_dump($logicStart);
$this->response->send('03', $logicStart . $count . $totalCount . $orderCount . implode('', $responseOrder));;
} }
......
...@@ -62,6 +62,8 @@ class CertifyController extends Controller ...@@ -62,6 +62,8 @@ class CertifyController extends Controller
$clients = Gateway::getclientIdByUid($mac); $clients = Gateway::getclientIdByUid($mac);
foreach ($clients as $client) { foreach ($clients as $client) {
var_dump('hello');
Gateway::closeClient($client); Gateway::closeClient($client);
} }
......
...@@ -10,19 +10,141 @@ namespace Application\controller\business\charger; ...@@ -10,19 +10,141 @@ namespace Application\controller\business\charger;
use Application\controller\Controller; use Application\controller\Controller;
use Application\model\OrderModel;
use Lib\cdz\order\Order;
use Lib\cdz\order\state\ChargerState;
use Lib\cdz\order\state\ShedState;
use Lib\cdz\order\state\WaitingState;
use Lib\StateCode;
use Src\route\Route; use Src\route\Route;
class OverController extends Controller class OverController extends Controller
{ {
protected $parameterMap = [
'05' => [
'type' => 1,
'logic_id' => 1,
'state' => 1,
'order_id' => 6,
'capacity' => 4,
]
];
public function __construct(string $clientId, string $message, string $command) public function __construct(string $clientId, string $message, string $command)
{ {
parent::__construct($clientId, $message, $command); parent::__construct($clientId, $message, $command);
} }
/**
* 订单结束
* 更新数据库中的订单结束状态和结束电量等信息
* 释放口子,删除订单的redis缓存
* 推送必要的微信通知
* 订单记录异常
*/
public function over() public function over()
{ {
$type = $this->request->get('type');
$logicId = $this->request->get('logic_id');
$state = hexdec($this->request->get('state'));
$orderId = hexdec($this->request->get('order_id'));
$capacity = hexdec($this->request->get('capacity'));
$this->logRecord->setOrderId($orderId);
$order = new Order();
if ($order->getOrderCache(\Events::getRedis()) != false) {
$orderStateCode = $order->getStateCode();
$order->setEndCapacity($capacity);
$order->setEndCode($state);
switch ($orderStateCode) {
case StateCode::WAITING:
$orderState = new WaitingState($order);
break;
case StateCode::PORT_CHARGER:
$orderState = new ChargerState($order);
break;
case StateCode::CHARGER_SHED:
$orderState = new ShedState($order);
break;
default:
break;
}
if (isset($orderState)) {
switch ($state) {
case StateCode::FINISH_USER: //用户主动结束
$orderState->toUserFinish();
break;
case StateCode::FINISH_SHED_TIMEOUT: //端口脱落超时
$orderState->toShedTimeoutState();
break;
case StateCode::FINISH_REFUND: //充电失败退款
$orderState->toRefundFinish();
break;
case StateCode::FINISH_EXCEED: //功率超限
$orderState->toPowerExceedState();
break;
case StateCode::FINISH_FULL: //充满自停
$orderState->toPowerFullState();
break;
case StateCode::FINISH_TIME_END: //充电时间结束
$orderState->toTimeoutState();
break;
default:
break;
}
} else {
$this->logRecord->setException(0);
$this->logRecord->setDesc('redis副本订单状态异常,非可结束订单状态');
} }
} else {
$this->logRecord->setException(0);
$this->logRecord->setDesc('未查找到订单redis副本');
}
$this->response->send('05', $logicId . sprintf('%12x', $orderId));
}
} }
...@@ -13,6 +13,7 @@ use Application\controller\Controller; ...@@ -13,6 +13,7 @@ use Application\controller\Controller;
use Application\model\OrderModel; use Application\model\OrderModel;
use Application\model\OrderPowerModel; use Application\model\OrderPowerModel;
use Lib\cdz\order\Order; use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
class PowerController extends Controller class PowerController extends Controller
...@@ -68,7 +69,12 @@ class PowerController extends Controller ...@@ -68,7 +69,12 @@ class PowerController extends Controller
if ($order->getStartCapacity() === -1) { if ($order->getStartCapacity() === -1) {
$orderModel = new OrderModel(); $orderModel = new OrderModel();
$orderModel->update(['start_capacity' => $capacity], 'id = ' . $orderId); $orderModel->update(['start_capacity' => $capacity], 'id = ' . $orderId);
$saveOrderRedis = new OrderSaveRedis($order);
$saveOrderRedis->save(['startCapacity']);
} else {
$orderModel = new OrderModel();
$orderModel->update(['end_capacity' => $capacity], 'id = ' . $orderId);
} }
} }
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 上午10:17
*/
namespace Application\controller\business\power;
use Application\controller\Controller;
class ShutdownController extends Controller
{
protected $parameterMap = [
'04' => []
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
public function shutdown()
{
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 上午10:05
*/
namespace Application\controller\setting;
use Application\controller\Controller;
use Application\model\ConfigModel;
use Application\model\StationModel;
class SettingController extends Controller
{
protected $parameterMap = [
'0a' => []
];
public function __construct(string $clientId, string $message, string $command)
{
parent::__construct($clientId, $message, $command);
}
/**
* 硬件获取设置参数
*/
public function get()
{
$configModel = new ConfigModel();
$configs = $configModel->getIdConfigValue();
$idConfigsValue = [];
foreach ($configs as $config) {
$idConfigsValue[$config['id']] = $config['config_value'];
}
$invertalTime = $idConfigsValue['5']; //设备上报数据间隔单位 秒
$stationId = $_SESSION['station_id'];
$stationModel = new StationModel();
$stationMaxCep = $stationModel->getColumn('max_cep', 'id = ' . $stationId);
$powerUpperLimit = isset($stationMaxCep) ? $stationMaxCep : $idConfigsValue['1'];
$getPriceConfig = $idConfigsValue['6'];
$powerSaturateInvertalTime = $idConfigsValue['7'];
$extraTime = $idConfigsValue['8'];
$powerLowerLimit = getenv('LOW_POWER_LIMIT');
$detectTime = 5;
$afterFormat = $this->adaptor([
[$invertalTime, 4],
[$getPriceConfig, 2],
[$powerUpperLimit, 4],
[$powerSaturateInvertalTime, 2],
[$extraTime, 2],
[$powerLowerLimit, 2],
[$detectTime, 2],
]);
$this->response->send('0a', implode($afterFormat));
}
/**
* @param array $data
* @return array
*/
private function adaptor(array $data)
{
$afterFormat = [];
foreach ($data as $item) {
array_push($afterFormat, sprintf('%0' . $item[1] . 'x', $item[0]));
}
return $afterFormat;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 上午10:06
*/
namespace Application\model;
class ConfigModel extends Model
{
protected $table = 'configs';
public function getIdConfigValue()
{
return $this->db->query('SELECT id , config_value FROM '.$this->table);
}
//最大功率限制
public function getPowerUpperLimit()
{
return $this->getColumn('config_value', 'id = 1');
}
//数据上报间隔时间
public function getInvertalTime()
{
return $this->getColumn('config_value', 'id = 5');
}
//获取计价配置时间间隔
public function getPriceConfig()
{
return $this->getColumn('config_value', 'id = 6');
}
//充满自停的功率检测此时
public function getPowerSaturateInvertalTime()
{
return $this->getColumn('config_value', 'id = 7');
}
//充满自停额外的供电时间
public function getExtraTime()
{
return $this->getColumn('config_value', 'id = 8');
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 上午10:11
*/
namespace Application\model;
class StationModel extends Model
{
protected $table = 'stations';
}
\ No newline at end of file
...@@ -33,6 +33,8 @@ class Api ...@@ -33,6 +33,8 @@ class Api
$this->add('08','business\port\OnlineController@online'); $this->add('08','business\port\OnlineController@online');
$this->add('09','business\port\OfflineController@offline'); $this->add('09','business\port\OfflineController@offline');
$this->add('0f','business\power\ShutdownController@shutdown');
$this->add('0a','setting\SettingController@get');
} }
......
...@@ -19,7 +19,7 @@ $gateway->startPort = getenv('GATEWAY_START_PORT'); ...@@ -19,7 +19,7 @@ $gateway->startPort = getenv('GATEWAY_START_PORT');
$gateway->registerAddress = getenv('REGISTER_IP') . ':' . getenv('REGISTER_PORT'); $gateway->registerAddress = getenv('REGISTER_IP') . ':' . getenv('REGISTER_PORT');
// 心跳间隔 // 心跳间隔
$gateway->pingInterval = 45; $gateway->pingInterval = 50;
// 心跳数据 // 心跳数据
$gateway->pingNotResponseLimit = 2; $gateway->pingNotResponseLimit = 2;
......
...@@ -139,6 +139,11 @@ class Order ...@@ -139,6 +139,11 @@ class Order
*/ */
private $isRefund = 0; private $isRefund = 0;
/**
* @var int
*/
private $endCode = 0;
/** /**
* @param $name * @param $name
...@@ -571,5 +576,23 @@ class Order ...@@ -571,5 +576,23 @@ class Order
$this->onlineTime = $onlineTime; $this->onlineTime = $onlineTime;
} }
/**
* @return int
*/
public function getEndCode(): int
{
return $this->endCode;
}
/**
* @param int $endCode
*/
public function setEndCode(int $endCode): void
{
$this->endCode = $endCode;
}
} }
\ No newline at end of file
...@@ -11,15 +11,75 @@ namespace Lib\cdz\order\state; ...@@ -11,15 +11,75 @@ namespace Lib\cdz\order\state;
use Application\model\OrderExceptionModel; use Application\model\OrderExceptionModel;
use Application\model\OrderModel; use Application\model\OrderModel;
use Lib\cdz\order\Order;
use Lib\cdz\order\save\OrderSaveRedis;
use Lib\log\Log; use Lib\log\Log;
use Lib\rabbitmq\PublishPortShed;
use Lib\remote\api\message\ChargerFullMessage; use Lib\remote\api\message\ChargerFullMessage;
use Lib\remote\api\message\ChargerTimeoutMessage;
use Lib\remote\api\message\FinishByUserMessage;
use Lib\remote\api\message\PowerExceedMessage; use Lib\remote\api\message\PowerExceedMessage;
use Lib\remote\api\message\SendMessage; use Lib\remote\api\message\SendMessage;
use Lib\remote\api\message\ShedMessage;
use Lib\StateCode; use Lib\StateCode;
use Lib\station\gateway\port\Port; use Lib\station\gateway\port\Port;
class ChargerState extends State class ChargerState extends State
{ {
public function __construct(Order $order)
{
parent::__construct($order);
}
/**
* 用户主动结束充电
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function toUserFinish()
{
$orderModel = new OrderModel();
$orderModel->update([
'is_stop' => $this->order->getEndCode(),
'end_capacity' => $this->order->getEndCapacity(),
'updated_at' => date('Y-m-d H:i:s'),
'state' => 1,
], 'id = ' . $this->order->getId());
$port = new Port();
$port->setPortId($this->order->getPortId());
$port->freePort();
//用户主动结束充电推送
$finishByUserMessage = new FinishByUserMessage();
$finishByUserMessage->setOrderId($this->order->getId());
$finishByUserMessage->setAddress($this->order->getStationName() . '--' . $this->order->getPortName());
$chargerTime = time() - $this->order->getStartTime();
$chargerTime /= 60;
$chargerTime = (int)$chargerTime;
$finishByUserMessage->setChargerTime($chargerTime);
$finishByUserMessage->setEndTime($this->nowDate);
$finishByUserMessage->setOrderAmount($this->order->getPayAmount());
$sendMessage = new SendMessage();
if ($sendMessage->request($finishByUserMessage) == false) {
Log::error('send finish by user message fail');
}
$orderException = new OrderExceptionModel();
$orderException->insertRow([
'order_id' => $this->order->getId(),
'state' => StateCode::PORT_CHARGER . StateCode::FINISH_USER,
'desc' => '用户主动结束充电',
'created_at' => $this->nowDate,
]);
}
public function toWaitingState() public function toWaitingState()
{ {
Log::error('charger state can not change to waiting state'); Log::error('charger state can not change to waiting state');
...@@ -130,20 +190,151 @@ class ChargerState extends State ...@@ -130,20 +190,151 @@ class ChargerState extends State
$port->freePort(); $port->freePort();
} }
/**
* 口子脱落
* redis订单状态副本更新
* 推送用户信息
* 发布延时任务十分钟后检测端口
*
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \AMQPConnectionException
* @throws \AMQPExchangeException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function toShedState() public function toShedState()
{ {
// TODO: Implement toShedState() method. $this->order->setStateCode(StateCode::PORT_SHED);
$this->order->setShedTime($this->nowTimeStamp);
$orderSaveRedis = new OrderSaveRedis($this->order);
$orderSaveRedis->save([
'stateCode',
'shedTime'
]);
$orderModel = new OrderModel();
$orderModel->update([
'updated_at' => $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' => '口子脱落',
'created_at' => $this->nowDate,
]);
$shedMessage = new ShedMessage();
$shedMessage->setOrderId($this->order->getId());
$shedMessage->setPortName($this->order->getPortName());
$shedMessage->setStationName($this->order->getStationName());
$shedMessage->setTime($this->nowDate);
$sendMessage = new SendMessage();
if ($sendMessage->request($shedMessage) == false) {
Log::error('send port shed message fail');
}
//todo publish 十分钟的延迟任务
try {
$publish = new PublishPortShed();
$publish->publishOrder([
'order_id' => $this->order->getId(),
'shed_time' => $this->nowTimeStamp,
'port_id' => $this->order->getPortId()
]);
} catch (\Exception $exception) {
Log::error($exception->getMessage());
}
} }
public function toShedTimeoutState() public function toShedTimeoutState()
{ {
// TODO: Implement toShedTimeoutState() method. Log::error('charger state can not change to shed timeout');
} }
/**
* 更新订单记录
* 释放口子
* 清楚订单redis副本
* 推送用户消息
* @throws \GuzzleHttp\Exception\GuzzleException
*
*/
public function toTimeoutState() public function toTimeoutState()
{ {
// TODO: Implement toTimeoutState() method. $orderModel = new OrderModel();
$orderModel->update([
'is_stop' => StateCode::FINISH_TIME_END,
'end_capacity' => $this->order->getEndCapacity(),
'updated_at' => $this->nowDate,
], 'id = ' . $this->order->getId());
$port = new Port();
$port->setPortId($this->order->getId());
$port->freePort();
$chargerTimeoutMessage = new ChargerTimeoutMessage();
$chargerTimeoutMessage->setStationName($this->order->getStationName());
$chargerTimeoutMessage->setPortName($this->order->getPortName());
$chargerTimeoutMessage->setOrderId($this->order->getId());
$chargerTimeoutMessage->setEndTime($this->nowDate);
$chargerTime = $this->nowTimeStamp - $this->order->getStartTime();
$chargerTime /= 60;
$chargerTimeoutMessage->setChargerTime((int)$chargerTime);
$sendMessage = new SendMessage();
if ($sendMessage->request($chargerTimeoutMessage) == false) {
Log::error('send charger timeout message fail');
}
} }
} }
...@@ -13,11 +13,18 @@ use Lib\cdz\order\Order; ...@@ -13,11 +13,18 @@ use Lib\cdz\order\Order;
class ExceptionState extends State class ExceptionState extends State
{ {
public function __construct(Order $order) public function __construct(Order $order)
{ {
parent::__construct($order); parent::__construct($order);
} }
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
public function toWaitingState() public function toWaitingState()
{ {
// TODO: Implement toWaitingState() method. // TODO: Implement toWaitingState() method.
......
...@@ -36,6 +36,12 @@ class OfflineNetState extends State ...@@ -36,6 +36,12 @@ class OfflineNetState extends State
} }
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
public function toWaitingState() public function toWaitingState()
{ {
// TODO: Implement toWaitingState() method. // TODO: Implement toWaitingState() method.
......
...@@ -18,6 +18,12 @@ class OfflinePowerState extends State ...@@ -18,6 +18,12 @@ class OfflinePowerState extends State
parent::__construct($order); parent::__construct($order);
} }
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
/** /**
* @var int * @var int
*/ */
......
...@@ -18,6 +18,12 @@ class PowerExceedState extends State ...@@ -18,6 +18,12 @@ class PowerExceedState extends State
parent::__construct($order); parent::__construct($order);
} }
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
public function toWaitingState() public function toWaitingState()
{ {
// TODO: Implement toWaitingState() method. // TODO: Implement toWaitingState() method.
......
...@@ -9,7 +9,60 @@ ...@@ -9,7 +9,60 @@
namespace Lib\cdz\order\state; namespace Lib\cdz\order\state;
class PowerFullState use Lib\cdz\order\Order;
class PowerFullState extends State
{ {
public function __construct(Order $order)
{
parent::__construct($order);
}
public function toWaitingState()
{
// TODO: Implement toWaitingState() method.
}
public function toChargerState()
{
// TODO: Implement toChargerState() method.
}
public function toExceptionState()
{
// TODO: Implement toExceptionState() method.
}
public function toPowerExceedState()
{
// TODO: Implement toPowerExceedState() method.
}
public function toPowerFullState()
{
// TODO: Implement toPowerFullState() method.
}
public function toShedState()
{
// TODO: Implement toShedState() method.
}
public function toShedTimeoutState()
{
// TODO: Implement toShedTimeoutState() method.
}
public function toTimeoutState()
{
// TODO: Implement toTimeoutState() method.
}
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
} }
\ No newline at end of file
...@@ -19,6 +19,12 @@ class ShedState extends State ...@@ -19,6 +19,12 @@ class ShedState extends State
parent::__construct($order); parent::__construct($order);
} }
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
public function toWaitingState() public function toWaitingState()
{ {
// TODO: Implement toWaitingState() method. // TODO: Implement toWaitingState() method.
......
...@@ -9,7 +9,59 @@ ...@@ -9,7 +9,59 @@
namespace Lib\cdz\order\state; namespace Lib\cdz\order\state;
class ShedTimeoutState use Lib\cdz\order\Order;
class ShedTimeoutState extends State
{ {
public function __construct(Order $order)
{
parent::__construct($order);
}
public function toWaitingState()
{
// TODO: Implement toWaitingState() method.
}
public function toChargerState()
{
// TODO: Implement toChargerState() method.
}
public function toExceptionState()
{
// TODO: Implement toExceptionState() method.
}
public function toPowerExceedState()
{
// TODO: Implement toPowerExceedState() method.
}
public function toPowerFullState()
{
// TODO: Implement toPowerFullState() method.
}
public function toShedState()
{
// TODO: Implement toShedState() method.
}
public function toShedTimeoutState()
{
// TODO: Implement toShedTimeoutState() method.
}
public function toTimeoutState()
{
// TODO: Implement toTimeoutState() method.
}
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
} }
\ No newline at end of file
...@@ -48,16 +48,19 @@ abstract class State ...@@ -48,16 +48,19 @@ abstract class State
public abstract function toChargerState(); public abstract function toChargerState();
public abstract function toExceptionState(); public abstract function toExceptionState();//充电异常
public abstract function toPowerExceedState(); public abstract function toPowerExceedState(); //功率超限
public abstract function toPowerFullState(); public abstract function toPowerFullState(); //充满自停
public abstract function toShedState(); public abstract function toShedState(); //口子脱落
public abstract function toShedTimeoutState(); public abstract function toShedTimeoutState(); //口子脱落超时
public abstract function toTimeoutState(); //时间耗尽
public abstract function toUserFinish();
public abstract function toTimeoutState();
} }
\ No newline at end of file
...@@ -9,7 +9,60 @@ ...@@ -9,7 +9,60 @@
namespace Lib\cdz\order\state; namespace Lib\cdz\order\state;
class TimeoutState use Lib\cdz\order\Order;
class TimeoutState extends State
{ {
public function __construct(Order $order)
{
parent::__construct($order);
}
public function toWaitingState()
{
// TODO: Implement toWaitingState() method.
}
public function toChargerState()
{
// TODO: Implement toChargerState() method.
}
public function toExceptionState()
{
// TODO: Implement toExceptionState() method.
}
public function toPowerExceedState()
{
// TODO: Implement toPowerExceedState() method.
}
public function toPowerFullState()
{
// TODO: Implement toPowerFullState() method.
}
public function toShedState()
{
// TODO: Implement toShedState() method.
}
public function toShedTimeoutState()
{
// TODO: Implement toShedTimeoutState() method.
}
public function toTimeoutState()
{
// TODO: Implement toTimeoutState() method.
}
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
} }
\ No newline at end of file
...@@ -26,6 +26,10 @@ use Src\command\StopChargerCommand; ...@@ -26,6 +26,10 @@ use Src\command\StopChargerCommand;
class WaitingState extends State class WaitingState extends State
{ {
/**
* WaitingState constructor.
* @param Order $order
*/
public function __construct(Order $order) public function __construct(Order $order)
{ {
...@@ -33,6 +37,14 @@ class WaitingState extends State ...@@ -33,6 +37,14 @@ class WaitingState extends State
} }
/**
*
*/
public function toUserFinish()
{
// TODO: Implement toUserFinish() method.
}
public function toWaitingState() public function toWaitingState()
{ {
} }
......
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 下午3:12
*/
namespace Lib\remote\api\message;
class ChargerTimeoutMessage extends Message
{
/**
* @var string
*/
protected $templateId = '';
/**
* @var string
*/
private $first = '亲爱的用户,您的爱车已经完成充电啦';
/**
* @var string
*/
private $endTime = '';
/**
* @var string
*/
private $stationName = '';
/**
* @var string
*/
private $portName = '';
/**
* @var string
*/
private $chargerTime;
/**
* @var int
*/
private $orderAmount;
public function __construct()
{
$this->templateId = getenv('MESSAGE_CHARGER_TIMEOUT');
}
/**
* @var string
*/
private $remark = '感谢你的使用';
public function getPushJson(): string
{
return json_encode([
'first' => [
'value' => $this->first,
'color' => '#333',
],
'keyword1' => [
'value' => $this->endTime,
'color' => '#333',
],
'keyword2' => [
'value' => $this->stationName.'--'.$this->portName,
'color' => '#333',
],
'keyword3' => [
'value' => $this->chargerTime.'分钟',
'color' => '#333',
],
'keyword4' => [
'value' => '¥'.number_format($this->orderAmount/100,2),
'color' => '#333',
],
'remark' => [
'value' => $this->remark,
'color' => '#333',
],
]);
}
/**
* @return string
*/
public function getEndTime(): string
{
return $this->endTime;
}
/**
* @param string $endTime
*/
public function setEndTime(string $endTime): void
{
$this->endTime = $endTime;
}
/**
* @return string
*/
public function getStationName(): string
{
return $this->stationName;
}
/**
* @param string $stationName
*/
public function setStationName(string $stationName): void
{
$this->stationName = $stationName;
}
/**
* @return string
*/
public function getPortName(): string
{
return $this->portName;
}
/**
* @param string $portName
*/
public function setPortName(string $portName): void
{
$this->portName = $portName;
}
/**
* @return string
*/
public function getChargerTime(): string
{
return $this->chargerTime;
}
/**
* @param string $chargerTime
*/
public function setChargerTime(string $chargerTime): void
{
$this->chargerTime = $chargerTime;
}
/**
* @return int
*/
public function getOrderAmount(): int
{
return $this->orderAmount;
}
/**
* @param int $orderAmount
*/
public function setOrderAmount(int $orderAmount): void
{
$this->orderAmount = $orderAmount;
}
/**
* @return string
*/
public function getRemark(): string
{
return $this->remark;
}
/**
* @param string $remark
*/
public function setRemark(string $remark): void
{
$this->remark = $remark;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 下午1:40
*/
namespace Lib\remote\api\message;
/**
* 用户主动结束充电消息 e
* Class FinishByUserMessage
* @package Lib\remote\api\message
*/
class FinishByUserMessage extends Message
{
protected $templateId = '';
private $first = '亲爱的用户,您的爱车已经完成充电啦';
private $endTime = '';
private $address= '';
private $chargerTime = 0;
private $orderAmount =0;
private $remark = '感谢你的使用';
/**
* FinishByUserMessage constructor.
*/
public function __construct()
{
$this->templateId = getenv('MESSAGE_FINISH_USER');
}
public function getPushJson(): string
{
return json_encode([
'first' => [
'value' => $this->first,
'color' => '#333',
],
'keyword1' => [
'value' => $this->endTime,
'color' => '#333',
],
'keyword2' => [
'value' => $this->address,
'color' => '#333',
],
'keyword3' => [
'value' => $this->chargerTime.'分钟',
'color' => '#333',
],
'keyword4' => [
'value' => '¥'.number_format($this->orderAmount/100,2),
'color' => '#333',
],
'remark' => [
'value' => $this->remark,
'color' => '#333',
],
]);
}
/**
* @return string
*/
public function getFirst(): string
{
return $this->first;
}
/**
* @param string $first
*/
public function setFirst(string $first): void
{
$this->first = $first;
}
/**
* @return string
*/
public function getEndTime(): string
{
return $this->endTime;
}
/**
* @param string $endTime
*/
public function setEndTime(string $endTime): void
{
$this->endTime = $endTime;
}
/**
* @return string
*/
public function getAddress(): string
{
return $this->address;
}
/**
* @param string $address
*/
public function setAddress(string $address): void
{
$this->address = $address;
}
/**
* @return int
*/
public function getChargerTime(): int
{
return $this->chargerTime;
}
/**
* @param int $chargerTime
*/
public function setChargerTime(int $chargerTime): void
{
$this->chargerTime = $chargerTime;
}
/**
* @return int
*/
public function getOrderAmount(): int
{
return $this->orderAmount;
}
/**
* @param int $orderAmount
*/
public function setOrderAmount(int $orderAmount): void
{
$this->orderAmount = $orderAmount;
}
/**
* @return string
*/
public function getRemark(): string
{
return $this->remark;
}
/**
* @param string $remark
*/
public function setRemark(string $remark): void
{
$this->remark = $remark;
}
}
\ No newline at end of file
...@@ -61,5 +61,22 @@ abstract class Message ...@@ -61,5 +61,22 @@ abstract class Message
$this->userId = $userId; $this->userId = $userId;
} }
/**
* @return string
*/
public function getOrderId(): string
{
return $this->orderId;
}
/**
* @param string $orderId
*/
public function setOrderId(string $orderId): void
{
$this->orderId = $orderId;
}
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/8/22
* Time: 下午2:44
*/
namespace Lib\remote\api\message;
class ShedMessage extends Message
{
protected $templateId = '';
/**
* @var string
*/
private $first = '尊敬的用户,充电端未检测到插头,请您在%s分钟内接入。';
/**
* @var string
*/
private $portName = '';
/**
* @var string
*/
private $stationName = '';
/**
* @var string
*/
private $time = '';
/**
* @var int
*/
private $waitingTime = 10;
/**
* @var string
*/
private $remark = '超时将关闭此次交易哦,支付金额会在1个工作日内退回您的余额或零钱,请注意查看,若未收到请联系我们的客服为您处理。若为充电口异常,请您及时更换至其它充电口充电';
/**
* ShedMessage constructor.
*/
public function __construct()
{
$this->templateId = getenv('MESSAGE_PORT_SHED');
}
public function getPushJson(): string
{
$this->first = sprintf($this->first,$this->waitingTime);
return json_encode([
'first' => [
'value' => $this->first,
'color' => '#333',
],
'keyword1' => [
'value' => $this->stationName . "--$this->portName",
'color' => '#333',
],
'keyword2' => [
'value' => $this->time,
'color' => '#333',
],
'remark' => [
'value' => $this->remark,
'color' => '#333',
],
]);
}
/**
* @return string
*/
public function getFirst(): string
{
return $this->first;
}
/**
* @param string $first
*/
public function setFirst(string $first): void
{
$this->first = $first;
}
/**
* @return string
*/
public function getPortName(): string
{
return $this->portName;
}
/**
* @param string $portName
*/
public function setPortName(string $portName): void
{
$this->portName = $portName;
}
/**
* @return string
*/
public function getStationName(): string
{
return $this->stationName;
}
/**
* @param string $stationName
*/
public function setStationName(string $stationName): void
{
$this->stationName = $stationName;
}
/**
* @return int
*/
public function getWaitingTime(): int
{
return $this->waitingTime;
}
/**
* @param int $waitingTime
*/
public function setWaitingTime(int $waitingTime): void
{
$this->waitingTime = $waitingTime;
}
/**
* @return string
*/
public function getTime(): string
{
return $this->time;
}
/**
* @param string $time
*/
public function setTime(string $time): void
{
$this->time = $time;
}
/**
* @return string
*/
public function getRemark(): string
{
return $this->remark;
}
/**
* @param string $remark
*/
public function setRemark(string $remark): void
{
$this->remark = $remark;
}
}
\ No newline at end of file
...@@ -29,16 +29,28 @@ class GatewayLogWriter ...@@ -29,16 +29,28 @@ class GatewayLogWriter
public function write(Record $record) public function write(Record $record)
{ {
$this->gatewayLogModel->insertRow([ $update =
[
'command' => $record->getCommand(), 'command' => $record->getCommand(),
'port_id' => $record->getPortId(), 'port_id' => $record->getPortId(),
'order_id' => $record->getOrderId(), 'order_id' => $record->getOrderId(),
'body' => $record->getBody(), 'request' => $record->getBody(),
'gateway_id' => $record->getGatewayId(), 'gateway_id' => $record->getGatewayId(),
'station_id' => $record->getStationId(), 'station_id' => $record->getStationId(),
'created_at' => date('Y-m-d H:i:s', $record->getTime()), 'created_at' => date('Y-m-d H:i:s', $record->getTime()),
]); 'exception' => $record->getException(),
];
if($record->getResponse() != '')
{
$update['response'] = $record->getResponse();
}
if ($record->getDesc() != '') {
$update['desc'] = $record->getDesc();
}
$this->gatewayLogModel->insertRow($update);
} }
......
...@@ -31,6 +31,11 @@ class Record ...@@ -31,6 +31,11 @@ class Record
protected $body = ''; protected $body = '';
/** /**
* @var string
*/
protected $response = '';
/**
* @var int * @var int
*/ */
protected $portId = 0; protected $portId = 0;
...@@ -45,6 +50,17 @@ class Record ...@@ -45,6 +50,17 @@ class Record
protected $time = 0; protected $time = 0;
/**
* @var int
*/
protected $exception = 1;
/**
* @var string
*/
protected $desc = '';
public function __construct() public function __construct()
{ {
$this->time = time(); $this->time = time();
...@@ -167,5 +183,56 @@ class Record ...@@ -167,5 +183,56 @@ class Record
$this->time = $time; $this->time = $time;
} }
/**
* @return int
*/
public function getException(): int
{
return $this->exception;
}
/**
* @param int $exception
*/
public function setException(int $exception): void
{
$this->exception = $exception;
}
/**
* @return string
*/
public function getDesc(): string
{
return $this->desc;
}
/**
* @param string $desc
*/
public function setDesc(string $desc): void
{
$this->desc = $desc;
}
/**
* @return string
*/
public function getResponse(): string
{
return $this->response;
}
/**
* @param string $response
*/
public function setResponse(string $response): void
{
$this->response = $response;
}
} }
\ No newline at end of file
...@@ -104,14 +104,29 @@ class Response ...@@ -104,14 +104,29 @@ class Response
$crc = substr(sprintf('%08x', Crc::crc($exceptCrc)), 0, 2); $crc = substr(sprintf('%08x', Crc::crc($exceptCrc)), 0, 2);
return $this->responseMessage = $exceptCrc . $crc;
var_dump($exceptCrc); }
return $this->responseMessage = $exceptCrc . $crc; /**
* @return string
*/
public function getResponseMessage(): string
{
return $this->responseMessage;
}
/**
* @param string $responseMessage
*/
public function setResponseMessage(string $responseMessage): void
{
$this->responseMessage = $responseMessage;
} }
} }
......
...@@ -25,7 +25,6 @@ class Bintohex ...@@ -25,7 +25,6 @@ class Bintohex
$data = $data[1]; $data = $data[1];
$packageLength = strlen($data); $packageLength = strlen($data);
$packageLength/=2; $packageLength/=2;
...@@ -39,6 +38,8 @@ class Bintohex ...@@ -39,6 +38,8 @@ class Bintohex
//数据非ffaa开头直接断开连接 //数据非ffaa开头直接断开连接
if(substr($data,0,4) !== 'ffaa') if(substr($data,0,4) !== 'ffaa')
{ {
var_dump('111');
$tcpConnection->close(); $tcpConnection->close();
} }
......
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