Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cdz_gateway
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨苏杭
cdz_gateway
Commits
741f7b68
Commit
741f7b68
authored
Jul 17, 2018
by
BANice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
由于掉电离线,服务端只能根据心跳检测连线有延迟,所有当设备重新上线时自动断开之前的tcp触发close时间防止错误
parent
914e138d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
114 additions
and
53 deletions
+114
-53
.idea/workspace.xml
+0
-0
Application/Controller/AccessController.php
+1
-8
Application/Controller/CertifyController.php
+17
-7
Application/Controller/PortController.php
+30
-2
Application/Controller/PowerController.php
+14
-16
Application/Events.php
+2
-0
Lib/api/message/ChargerFinishMessage.php
+1
-1
Lib/cdz_order/Order.php
+0
-4
Lib/cdz_order/state/Charger.php
+8
-1
Lib/cdz_order/state/Offline.php
+20
-9
Lib/cdz_order/state/State.php
+20
-0
Lib/cdz_order/state/WaitingCharger.php
+0
-2
Lib/order_exception/Exception.php
+1
-0
Lib/port/Port.php
+0
-3
No files found.
.idea/workspace.xml
View file @
741f7b68
This diff is collapsed.
Click to expand it.
Application/Controller/AccessController.php
View file @
741f7b68
...
@@ -226,8 +226,6 @@ class AccessController extends Controller
...
@@ -226,8 +226,6 @@ class AccessController extends Controller
$orderId
=
$port
->
getPortUsingOrderId
(
$redis
,
$id
);
$orderId
=
$port
->
getPortUsingOrderId
(
$redis
,
$id
);
Log
::
debug
(
'order_id->'
.
$orderId
);
if
(
isset
(
$orderId
)
===
false
||
$orderId
===
false
||
$orderId
==
0
)
{
if
(
isset
(
$orderId
)
===
false
||
$orderId
===
false
||
$orderId
==
0
)
{
continue
;
continue
;
...
@@ -237,20 +235,15 @@ class AccessController extends Controller
...
@@ -237,20 +235,15 @@ class AccessController extends Controller
$order
->
setId
(
$orderId
);
$order
->
setId
(
$orderId
);
var_dump
(
$orderId
);
if
(
$order
->
getOrderCache
(
$redis
)
!==
false
)
{
if
(
$order
->
getOrderCache
(
$redis
)
!==
false
)
{
//订单从离线的状态变为正在充电状态
$orderState
=
new
Offline
(
$order
,
$redis
,
$offlineReason
);
$orderState
=
new
Offline
(
$order
,
$redis
,
$offlineReason
);
$orderState
->
toCharger
();
$orderState
->
toCharger
();
$remainChargerTime
=
$orderState
->
getRemainChargerTime
();
$remainChargerTime
=
$orderState
->
getRemainChargerTime
();
Log
::
debug
(
'remainChargerTime'
.
$remainChargerTime
);
if
(
$remainChargerTime
>
0
)
{
if
(
$remainChargerTime
>
0
)
{
array_push
(
$responseOrder
,
[
array_push
(
$responseOrder
,
[
...
...
Application/Controller/CertifyController.php
View file @
741f7b68
...
@@ -10,6 +10,7 @@ namespace Application\Controller;
...
@@ -10,6 +10,7 @@ namespace Application\Controller;
use
Application\Controller
;
use
Application\Controller
;
use
GatewayWorker\Lib\Gateway
;
use
Lib\Aes
;
use
Lib\Aes
;
use
Lib\Log
;
use
Lib\Log
;
...
@@ -19,8 +20,8 @@ class CertifyController extends Controller
...
@@ -19,8 +20,8 @@ class CertifyController extends Controller
protected
$parameterMap
=
[
protected
$parameterMap
=
[
'01'
=>
[
'01'
=>
[
'mac'
=>
6
'mac'
=>
6
,
]
]
,
];
];
/**
/**
...
@@ -29,11 +30,11 @@ class CertifyController extends Controller
...
@@ -29,11 +30,11 @@ class CertifyController extends Controller
public
function
certify
()
public
function
certify
()
{
{
Log
::
debug
(
'平台认证'
,
$this
->
getRequest
()
->
getParameters
());
Log
::
debug
(
'平台认证'
,
$this
->
getRequest
()
->
getParameters
());
$nonce
=
$this
->
getNonce
();
$nonce
=
$this
->
getNonce
();
$mac
=
$this
->
getRequest
()
->
get
(
'mac'
);
$mac
=
$this
->
getRequest
()
->
get
(
'mac'
);
//todo 验证mac地址是否存在,从数据库中获取producter_id生产sign
//todo 验证mac地址是否存在,从数据库中获取producter_id生产sign
...
@@ -43,12 +44,21 @@ class CertifyController extends Controller
...
@@ -43,12 +44,21 @@ class CertifyController extends Controller
$productId
=
'A22E4F4CDB05C460E450E46241DD6F89'
;
$productId
=
'A22E4F4CDB05C460E450E46241DD6F89'
;
$sign
=
bin2hex
(
Aes
::
encrypt
(
$nonce
,
$productId
));
$sign
=
bin2hex
(
Aes
::
encrypt
(
$nonce
,
$productId
));
$sign
=
substr
(
$sign
,
0
,
8
);
$sign
=
substr
(
$sign
,
0
,
8
);
if
(
Gateway
::
isUidOnline
(
$mac
)
===
1
)
{
$this
->
response
->
send
(
'01'
,
$sign
);
$clients
=
Gateway
::
getClientIdByUid
(
$mac
);
foreach
(
$clients
as
$client
)
{
Gateway
::
closeClient
(
$client
);
}
}
$this
->
response
->
send
(
'01'
,
$sign
);
}
}
...
...
Application/Controller/PortController.php
View file @
741f7b68
...
@@ -21,6 +21,7 @@ use Lib\api\message\ChargerStartMessage;
...
@@ -21,6 +21,7 @@ use Lib\api\message\ChargerStartMessage;
use
Lib\api\message\PortShedMessage
;
use
Lib\api\message\PortShedMessage
;
use
Lib\api\message\Push
;
use
Lib\api\message\Push
;
use
Lib\cdz_order\Order
;
use
Lib\cdz_order\Order
;
use
Lib\cdz_order\state\Charger
;
use
Lib\cdz_order\state\WaitingCharger
;
use
Lib\cdz_order\state\WaitingCharger
;
use
Lib\Gateway
;
use
Lib\Gateway
;
use
Lib\Log
;
use
Lib\Log
;
...
@@ -124,7 +125,6 @@ class PortController extends Controller
...
@@ -124,7 +125,6 @@ class PortController extends Controller
$offlinePortId
=
[];
$offlinePortId
=
[];
foreach
(
$portMacArray
as
$mac
)
{
foreach
(
$portMacArray
as
$mac
)
{
//todo 更新逻辑地址数据中
//todo 更新逻辑地址数据中
...
@@ -143,6 +143,26 @@ class PortController extends Controller
...
@@ -143,6 +143,26 @@ class PortController extends Controller
}
}
$port
=
new
Port
();
foreach
(
$offlinePortId
as
$portId
)
{
$orderId
=
$port
->
getPortUsingOrderId
(
\Events
::
getRedis
(),
$portId
);
$order
=
new
Order
();
$order
->
setId
(
$orderId
);
$charger
=
new
Charger
(
$order
,
\Events
::
getRedis
());
$charger
->
toOffline
();
unset
(
$charger
);
unset
(
$order
);
}
$port
->
offline
(
$offlinePortId
);
$port
->
offline
(
$offlinePortId
);
...
@@ -197,8 +217,16 @@ class PortController extends Controller
...
@@ -197,8 +217,16 @@ class PortController extends Controller
$update
[
'start_time'
]
=
$nowTime
;
$update
[
'start_time'
]
=
$nowTime
;
$row
=
$orderModel
->
update
(
$update
,
'id = '
.
$orderId
);
$orderModel
->
update
(
$update
,
'id = '
.
$orderId
);
//订单状态改为正在充电
$order
=
new
Order
();
$order
->
setId
(
$orderId
);
$waiting
=
new
WaitingCharger
(
$order
,
\Events
::
getRedis
());
$waiting
->
toCharger
();
}
catch
(
\Exception
$exception
)
{
}
catch
(
\Exception
$exception
)
{
Log
::
error
(
$exception
->
getMessage
());
Log
::
error
(
$exception
->
getMessage
());
...
...
Application/Controller/PowerController.php
View file @
741f7b68
...
@@ -15,18 +15,15 @@ use Application\Model\OrderExceptionModel;
...
@@ -15,18 +15,15 @@ use Application\Model\OrderExceptionModel;
use
Application\Model\OrderModel
;
use
Application\Model\OrderModel
;
use
Lib\api\message\ChargerExceedMessage
;
use
Lib\api\message\ChargerExceedMessage
;
use
Lib\api\message\ChargerExceptionMessage
;
use
Lib\api\message\ChargerExceptionMessage
;
use
Lib\api\message\ChargerExcessMessage
;
use
Lib\api\message\ChargerFailMessage
;
use
Lib\api\message\ChargerFinishMessage
;
use
Lib\api\message\ChargerFinishMessage
;
use
Lib\api\message\ChargerRefundMessage
;
use
Lib\api\message\ChargerRefundMessage
;
use
Lib\api\message\ChargerStartMessage
;
use
Lib\api\message\ChargerStartMessage
;
use
Lib\api\message\PortShedMessage
;
use
Lib\api\message\Push
;
use
Lib\api\message\Push
;
use
Lib\cdz_order\Order
;
use
Lib\cdz_order\Order
;
use
Lib\cdz_order\state\Charger
;
use
Lib\cdz_order\state\WaitingCharger
;
use
Lib\cdz_order\state\WaitingCharger
;
use
Lib\Gateway
;
use
Lib\Gateway
;
use
Lib\Log
;
use
Lib\Log
;
use
Lib\order_exception\OrderState
;
use
Lib\order_exception\OrderTrace
;
use
Lib\order_exception\OrderTrace
;
use
Lib\port\Port
;
use
Lib\port\Port
;
use
Lib\state\StateCode
;
use
Lib\state\StateCode
;
...
@@ -153,8 +150,6 @@ class PowerController extends Controller
...
@@ -153,8 +150,6 @@ class PowerController extends Controller
if
(
$order
->
getOrderCache
(
$redis
)
!==
false
)
if
(
$order
->
getOrderCache
(
$redis
)
!==
false
)
{
{
var_dump
(
$order
->
getOrderCache
(
$redis
));
$waiting
=
new
WaitingCharger
(
$order
,
$redis
);
$waiting
=
new
WaitingCharger
(
$order
,
$redis
);
$waiting
->
toCharger
();
$waiting
->
toCharger
();
...
@@ -290,6 +285,7 @@ class PowerController extends Controller
...
@@ -290,6 +285,7 @@ class PowerController extends Controller
$this
->
response
->
send
(
'15'
,
$orderId
);
$this
->
response
->
send
(
'15'
,
$orderId
);
return
;
return
;
}
else
{
}
else
{
//订单结束更新订单记录
//订单结束更新订单记录
...
@@ -297,10 +293,6 @@ class PowerController extends Controller
...
@@ -297,10 +293,6 @@ class PowerController extends Controller
$orderModel
->
update
([
'is_stop'
=>
$state
,
'state'
=>
1
,
'end_capacity'
=>
$capacity
,
'end_time'
=>
$time
],
' id = '
.
$id
);
$orderModel
->
update
([
'is_stop'
=>
$state
,
'state'
=>
1
,
'end_capacity'
=>
$capacity
,
'end_time'
=>
$time
],
' id = '
.
$id
);
$orderState
=
new
OrderState
(
$orderId
);
$orderState
->
setState
(
$state
);
}
}
...
@@ -314,20 +306,26 @@ class PowerController extends Controller
...
@@ -314,20 +306,26 @@ class PowerController extends Controller
Gateway
::
sendToUid
(
$userId
,
json_encode
([
'code'
=>
10000
]));
Gateway
::
sendToUid
(
$userId
,
json_encode
([
'code'
=>
10000
]));
}
}
if
(
isset
(
$orderInfo
[
'order_amount'
])
===
true
)
{
$orderInfo
[
'order_amount'
]
=
number_format
(
$orderInfo
[
'order_amount'
]
/
100
,
2
);
}
$port
->
setId
(
$portId
);
$port
->
setId
(
$portId
);
$port
->
freePort
();
$port
->
freePort
();
$order
=
new
Order
();
$order
->
setId
(
$id
);
$chargerState
=
new
Charger
(
$order
,
\Events
::
getRedis
());
$chargerState
->
setFinishState
(
$state
);
$chargerState
->
setEndTime
(
time
());
$chargerState
->
toFinish
();
switch
(
$state
)
{
switch
(
$state
)
{
case
StateCode
::
FINISH_EXCEED
:
case
StateCode
::
FINISH_EXCEED
:
$finishMessage
=
new
ChargerExceedMessage
();
$finishMessage
=
new
ChargerExceedMessage
();
$finishMessage
->
setUserId
(
$orderInfo
[
'wx_user_id'
]);
$finishMessage
->
setUserId
(
$orderInfo
[
'wx_user_id'
]);
...
...
Application/Events.php
View file @
741f7b68
...
@@ -151,6 +151,8 @@ class Events
...
@@ -151,6 +151,8 @@ class Events
$redis
=
Events
::
getRedis
();
$redis
=
Events
::
getRedis
();
Log
::
debug
(
'disconnect'
);
if
(
isset
(
$_SESSION
[
'gateway_id'
])
===
true
)
{
if
(
isset
(
$_SESSION
[
'gateway_id'
])
===
true
)
{
Log
::
info
(
'gateway_id('
.
$_SESSION
[
'gateway_id'
]
.
')'
.
'disconnect'
);
Log
::
info
(
'gateway_id('
.
$_SESSION
[
'gateway_id'
]
.
')'
.
'disconnect'
);
...
...
Lib/api/message/ChargerFinishMessage.php
View file @
741f7b68
...
@@ -77,7 +77,7 @@ class ChargerFinishMessage extends MessageData
...
@@ -77,7 +77,7 @@ class ChargerFinishMessage extends MessageData
'color'
=>
'#333'
,
'color'
=>
'#333'
,
],
],
'keyword4'
=>
[
'keyword4'
=>
[
'value'
=>
'¥'
.
$this
->
orderAmount
,
'value'
=>
'¥'
.
number_format
(
$this
->
orderAmount
/
100
,
2
)
,
'color'
=>
'#333'
,
'color'
=>
'#333'
,
],
],
'remark'
=>
[
'remark'
=>
[
...
...
Lib/cdz_order/Order.php
View file @
741f7b68
...
@@ -105,16 +105,12 @@ class Order
...
@@ -105,16 +105,12 @@ class Order
if
(
$redis
->
exists
(
$keyName
)
===
false
)
{
if
(
$redis
->
exists
(
$keyName
)
===
false
)
{
Log
::
debug
(
'exists false'
);
return
false
;
return
false
;
}
}
$this
->
orderCache
=
$redis
->
hGetAll
(
$keyName
);
$this
->
orderCache
=
$redis
->
hGetAll
(
$keyName
);
foreach
(
$this
->
orderCache
as
$key
=>
$value
)
{
foreach
(
$this
->
orderCache
as
$key
=>
$value
)
{
$this
->
$key
=
$value
;
$this
->
$key
=
$value
;
...
...
Lib/cdz_order/state/Charger.php
View file @
741f7b68
...
@@ -35,13 +35,20 @@ class Charger extends State
...
@@ -35,13 +35,20 @@ class Charger extends State
// TODO: Implement toFull() method.
// TODO: Implement toFull() method.
}
}
/**
* 充电结束记录充电结束状态和结束充电时间
*/
public
function
toFinish
()
public
function
toFinish
()
{
{
// TODO: Implement toFinish() method.
$this
->
redis
->
hMSet
(
$this
->
keyName
,
[
'finishState'
=>
$this
->
finishState
,
'endTime'
=>
$this
->
endTime
]);
}
}
public
function
toOffline
()
public
function
toOffline
()
{
{
$this
->
redis
->
hSet
(
$this
->
keyName
,
'offlineTime'
,
time
());
// TODO: Implement toOffline() method.
// TODO: Implement toOffline() method.
}
}
...
...
Lib/cdz_order/state/Offline.php
View file @
741f7b68
...
@@ -23,32 +23,43 @@ class Offline extends State
...
@@ -23,32 +23,43 @@ class Offline extends State
}
}
/**
/**
*
*记录了离线原因和上线时间
* 通过上线时间和离线时间根据离线原因计算剩余充电时间
*/
*/
public
function
toCharger
()
public
function
toCharger
()
{
{
$purchaseTime
=
$this
->
order
->
getPurchaseTime
();
$purchaseTime
=
$this
->
order
->
getPurchaseTime
();
$startTime
=
$this
->
getStartTime
();
$offlineTime
=
$this
->
getOfflineTime
();
$this
->
onlineTime
=
time
();
$this
->
onlineTime
=
time
();
if
(
$this
->
order
->
getStateCode
()
==
-
1
)
{
$this
->
remainChargerTime
=
$this
->
order
->
getPurchaseTime
();
if
(
$this
->
offlineReason
==
1
)
{
}
else
{
$remainTime
=
$purchaseTime
*
60
-
(
$offlineTime
-
$startTime
);
$
this
->
remainChargerTime
=
(
int
)
ceil
(
$remainTime
/
60
);
$
startTime
=
$this
->
getStartTime
(
);
}
else
{
$offlineTime
=
$this
->
getOfflineTime
();
$remainTime
=
$purchaseTime
*
60
-
(
$this
->
onlineTime
-
$startTime
);
if
(
$this
->
offlineReason
==
1
)
{
$this
->
remainChargerTime
=
(
int
)
ceil
(
$remainTime
/
60
);
$remainTime
=
$purchaseTime
*
60
-
(
$offlineTime
-
$startTime
);
$this
->
remainChargerTime
=
(
int
)
ceil
(
$remainTime
/
60
);
}
else
{
$remainTime
=
$purchaseTime
*
60
-
(
$this
->
onlineTime
-
$startTime
);
$this
->
remainChargerTime
=
(
int
)
ceil
(
$remainTime
/
60
);
}
}
}
$this
->
saveOrder
->
savePortOnlineTime
();
$this
->
saveOrder
->
savePortOnlineTime
();
...
...
Lib/cdz_order/state/State.php
View file @
741f7b68
...
@@ -95,6 +95,11 @@ abstract class State
...
@@ -95,6 +95,11 @@ abstract class State
*/
*/
protected
$remainChargerTime
;
protected
$remainChargerTime
;
/**
* @var int
*/
protected
$finishState
;
/**
/**
* State constructor.
* State constructor.
* @param Order $order
* @param Order $order
...
@@ -319,6 +324,21 @@ abstract class State
...
@@ -319,6 +324,21 @@ abstract class State
$this
->
endTime
=
$endTime
;
$this
->
endTime
=
$endTime
;
}
}
/**
* @return int
*/
public
function
getFinishState
()
:
int
{
return
$this
->
finishState
;
}
/**
* @param int $finishState
*/
public
function
setFinishState
(
int
$finishState
)
:
void
{
$this
->
finishState
=
$finishState
;
}
...
...
Lib/cdz_order/state/WaitingCharger.php
View file @
741f7b68
...
@@ -27,8 +27,6 @@ class WaitingCharger extends State
...
@@ -27,8 +27,6 @@ class WaitingCharger extends State
$this
->
order
->
setStateCode
(
12
);
$this
->
order
->
setStateCode
(
12
);
$this
->
order
->
setCurrentState
(
new
Charger
(
$this
->
order
,
$this
->
redis
));
$this
->
saveOrder
->
pipe
();
$this
->
saveOrder
->
pipe
();
$this
->
saveOrder
->
saveStartTime
();
$this
->
saveOrder
->
saveStartTime
();
...
...
Lib/order_exception/Exception.php
View file @
741f7b68
...
@@ -25,6 +25,7 @@ class Exception
...
@@ -25,6 +25,7 @@ class Exception
'99'
=>
'下发开始充电命令'
,
'99'
=>
'下发开始充电命令'
,
'98'
=>
'更换充电口'
,
'98'
=>
'更换充电口'
,
'97'
=>
'下发结束充电命令'
,
'97'
=>
'下发结束充电命令'
,
'96'
=>
'订单更换口子成功'
,
];
];
...
...
Lib/port/Port.php
View file @
741f7b68
...
@@ -185,9 +185,6 @@ class Port
...
@@ -185,9 +185,6 @@ class Port
{
{
// 口子充电结束,释放口子,删除正在使用的订单号和用户id,口子状态修改为1。
// 口子充电结束,释放口子,删除正在使用的订单号和用户id,口子状态修改为1。
Log
::
debug
(
'释放口子id->'
.
$this
->
id
);
$this
->
redis
->
hDel
(
RedisKey
::
PORT_USING_ORDER_ID
,
$this
->
id
);
$this
->
redis
->
hDel
(
RedisKey
::
PORT_USING_ORDER_ID
,
$this
->
id
);
$this
->
redis
->
zRem
(
RedisKey
::
PORT_USING_USER_ID
,
$this
->
id
);
$this
->
redis
->
zRem
(
RedisKey
::
PORT_USING_USER_ID
,
$this
->
id
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment