Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cdz_gateway_v2
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_v2
Commits
29296654
Commit
29296654
authored
Apr 30, 2019
by
杨苏杭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
封存
parent
6118513a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
435 additions
and
136 deletions
+435
-136
.idea/workspace.xml
+0
-0
application/Events.php
+56
-11
application/controller/accept/AccessController.php
+17
-17
application/controller/accept/CertifyController.php
+4
-3
application/controller/business/charger/OverController.php
+7
-7
application/controller/card/charger/OverController.php
+32
-8
application/controller/card/charger/RequestController.php
+33
-13
application/controller/card/charger/StartController.php
+19
-2
lib/cdz/card_order/state/ChargerState.php
+11
-7
lib/cdz/card_order/state/ExceptionState.php
+1
-1
lib/cdz/card_order/state/OfflineNetState.php
+4
-4
lib/cdz/card_order/state/OfflinePowerState.php
+4
-4
lib/cdz/card_order/state/PowerExceedState.php
+1
-1
lib/cdz/card_order/state/PowerFullState.php
+1
-1
lib/cdz/card_order/state/ShedState.php
+11
-5
lib/cdz/card_order/state/ShedTimeoutState.php
+1
-1
lib/cdz/card_order/state/State.php
+1
-3
lib/cdz/card_order/state/TimeoutState.php
+1
-1
lib/cdz/card_order/state/WaitingState.php
+1
-6
lib/cdz/order/Order.php
+25
-5
lib/cdz/order/save/OrderSaveRedis.php
+8
-2
lib/cdz/order/state/ChargerState.php
+11
-5
lib/cdz/order/state/ShedState.php
+9
-5
lib/cdz/order/state/WaitingState.php
+18
-6
lib/order_check/DelayOrder.php
+72
-0
lib/remote/api/message/ChargerFullMessage.php
+62
-3
lib/station/gateway/port/Port.php
+18
-7
src/BroadcastToAgent.php
+5
-3
src/command/StopChargerCommand.php
+2
-5
No files found.
.idea/workspace.xml
View file @
29296654
This diff is collapsed.
Click to expand it.
application/Events.php
View file @
29296654
...
...
@@ -15,6 +15,9 @@ use Lib\station\gateway\Gateway;
use
Lib\station\gateway\port\Port
;
use
Workerman\Lib\Timer
;
use
GuzzleHttp\Client
;
use
Lib\order_check\DelayOrder
;
use
Lib\cdz\order\Order
;
use
Src\command\StopChargerCommand
;
class
Events
{
...
...
@@ -32,9 +35,14 @@ class Events
/**
*
*/
public
static
function
onWorkerStart
()
public
static
function
onWorkerStart
(
\GatewayWorker\BusinessWorker
$businessWorker
)
{
\Lib\log\Log
::
bootLog
();
if
(
$businessWorker
->
id
===
0
)
{
Timer
::
add
(
10
*
6
*
10
,
function
()
{
$client
=
new
Client
([
...
...
@@ -56,7 +64,7 @@ class Events
static
::
$redis
->
pconnect
(
getenv
(
'REDIS_HOST'
),
getenv
(
'REDIS_PORT'
),
0
);
if
(
getenv
(
'REDIS_AUTH'
)
!==
false
)
{
if
(
getenv
(
'REDIS_AUTH'
)
!==
false
)
{
static
::
$redis
->
auth
(
getenv
(
'REDIS_AUTH'
));
...
...
@@ -64,8 +72,45 @@ class Events
static
::
$redis
->
select
(
'4'
);
Timer
::
add
(
2
,
function
()
{
\Lib\log\Log
::
bootLog
();
$delayOrder
=
new
DelayOrder
();
$delayOrderIds
=
$delayOrder
->
getDelayOrder
();
$order
=
new
Order
();
$stopCommand
=
new
StopChargerCommand
();
foreach
(
$delayOrderIds
as
$delayOrderId
)
{
$order
->
setId
(
$delayOrderId
);
$order
->
getOrderCache
(
static
::
$redis
);
$orderState
=
$order
->
getStateCode
();
if
(
$orderState
==
-
1
)
{
$stopCommand
->
setOutTradeNo
(
$delayOrderId
);
$stopCommand
->
setFinishType
(
43
);
$stopCommand
->
setPortLogic
(
$order
->
getPortLogicId
());
$body
=
$stopCommand
->
getMessage
();
$length
=
sprintf
(
'%04x'
,
(
8
+
strlen
(
$body
)
/
2
));
$nonce
=
sprintf
(
'%02x'
,
dechex
(
rand
(
0
,
255
)));
$exceptCrc
=
'ffaa0405'
.
$length
.
$nonce
.
$body
;
$crc
=
substr
(
sprintf
(
'%08x'
,
Crc
::
crc
(
$exceptCrc
)),
0
,
2
);
//下发结束充电命令和释放口子
\GatewayWorker\Lib\Gateway
::
sendToUid
(
$order
->
getGatewayMac
(),
$exceptCrc
.
$crc
);
$port
=
new
Port
(
$order
->
getPortId
());
$port
->
freePort
();
}
$delayOrder
->
deleteDelayOrder
(
$delayOrderId
);
}
});
}
}
...
...
@@ -92,7 +137,7 @@ class Events
$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
))
)
{
Log
::
error
(
"message crc wrong (
$message
)"
);
return
;
}
...
...
@@ -101,11 +146,11 @@ class Events
$api
=
new
Api
();
$api
->
boot
();
if
(
isset
(
$api
->
route
[
$command
])
)
{
if
(
isset
(
$api
->
route
[
$command
])
)
{
$route
=
$api
->
route
[
$command
];
if
(
$route
instanceof
Route
)
{
if
(
$route
instanceof
Route
)
{
$reflection
=
$route
->
getController
();
...
...
@@ -137,7 +182,7 @@ class Events
$stationName
=
isset
(
$_SESSION
[
'station_name'
])
?
$_SESSION
[
'station_name'
]
:
''
;
$gatewayName
=
isset
(
$_SESSION
[
'gateway_name'
])
?
$_SESSION
[
'gateway_name'
]
:
''
;
if
(
$gatewayId
===
''
||
$stationId
===
''
||
$gatewayName
===
''
||
$stationName
===
''
)
{
if
(
$gatewayId
===
''
||
$stationId
===
''
||
$gatewayName
===
''
||
$stationName
===
''
)
{
Log
::
error
(
'client close can not find station_id or gateway_id'
);
return
;
}
...
...
@@ -148,7 +193,7 @@ class Events
$exceptionModel
=
new
\Application\model\ExceptionModel
();
if
(
isset
(
$_SESSION
[
'station_id'
])
&&
isset
(
$_SESSION
[
'gateway_id'
])
)
{
if
(
isset
(
$_SESSION
[
'station_id'
])
&&
isset
(
$_SESSION
[
'gateway_id'
])
)
{
$exceptionModel
->
insertRow
([
'message'
=>
'网关离线'
,
'gateway_id'
=>
$gatewayId
,
...
...
@@ -164,7 +209,7 @@ class Events
//网关状态设置为离线
$gateway
->
setState
(
$gatewayId
,
0
);
if
(
isset
(
$_SESSION
[
'port_mac_id'
])
===
false
)
{
if
(
isset
(
$_SESSION
[
'port_mac_id'
])
===
false
)
{
Log
::
error
(
'gateway close can not find port_mac_id in session'
);
return
;
...
...
@@ -202,9 +247,9 @@ class Events
//端口当前订单记录离线时间
if
(
$portUsingOrderId
!=
false
&&
$portUsingOrderId
!=
''
)
{
if
(
$portUsingOrderId
!=
false
&&
$portUsingOrderId
!=
''
)
{
$order
=
new
\Lib\cdz\order\Order
(
$portUsingOrderId
);
if
(
$order
->
getOrderCache
(
static
::
$redis
)
!=
false
)
{
if
(
$order
->
getOrderCache
(
static
::
$redis
)
!=
false
)
{
$order
->
setOfflineTime
(
time
());
$saveOrder
=
new
\Lib\cdz\order\save\OrderSaveRedis
(
$order
);
$saveOrder
->
save
([
'offlineTime'
]);
...
...
application/controller/accept/AccessController.php
View file @
29296654
...
...
@@ -65,8 +65,8 @@ class AccessController extends Controller
$gatewayModel
=
new
GatewayModel
();
if
(
isset
(
$_SESSION
[
'gateway_mac'
])
)
{
if
(
$_SESSION
[
'gateway_mac'
]
!=
$mac
)
{
if
(
isset
(
$_SESSION
[
'gateway_mac'
])
)
{
if
(
$_SESSION
[
'gateway_mac'
]
!=
$mac
)
{
Gateway
::
closeClient
(
$this
->
clientId
);
}
...
...
@@ -78,7 +78,7 @@ class AccessController extends Controller
'type_id'
],
'mac_address = '
.
"'
$mac
'"
);
if
(
$gatewayModelResult
==
false
)
{
if
(
$gatewayModelResult
==
false
)
{
Gateway
::
closeClient
(
$this
->
clientId
);
return
;
}
...
...
@@ -103,14 +103,14 @@ class AccessController extends Controller
'name'
,
],
'id = '
.
$stationId
);
if
(
isset
(
$stationData
[
'park_id'
])
&&
isset
(
$stationData
[
'name'
])
)
{
if
(
isset
(
$stationData
[
'park_id'
])
&&
isset
(
$stationData
[
'name'
])
)
{
$parkId
=
$stationData
[
'park_id'
];
$_SESSION
[
'station_name'
]
=
$stationData
[
'name'
];
if
(
isset
(
$parkId
)
)
{
if
(
isset
(
$parkId
)
)
{
$parkModel
=
new
ParkModel
();
$_SESSION
[
'park_id'
]
=
$parkId
;
$agentId
=
$parkModel
->
getColumn
(
'agent_id'
,
'id = '
.
$parkId
);
if
(
isset
(
$agentId
)
)
{
if
(
isset
(
$agentId
)
)
{
$_SESSION
[
'agent_id'
]
=
$agentId
;
}
...
...
@@ -185,7 +185,7 @@ class AccessController extends Controller
$portMacState
=
[];
if
(
strlen
(
$this
->
message
)
<
(
12
*
2
+
9
*
2
*
$count
)
)
{
if
(
strlen
(
$this
->
message
)
<
(
12
*
2
+
9
*
2
*
$count
)
)
{
return
;
}
...
...
@@ -197,7 +197,7 @@ class AccessController extends Controller
$portMacState
[
$mac
]
=
hexdec
(
$state
);
}
if
(
isset
(
$_SESSION
[
'port_mac_id'
])
==
false
)
{
if
(
isset
(
$_SESSION
[
'port_mac_id'
])
==
false
)
{
return
;
}
...
...
@@ -211,7 +211,7 @@ class AccessController extends Controller
$portsId
=
[];
foreach
(
$portMacState
as
$mac
=>
$state
)
{
if
(
isset
(
$portsMacId
[
$mac
])
)
{
if
(
isset
(
$portsMacId
[
$mac
])
)
{
array_push
(
$portsId
,
$portsMacId
[
$mac
]);
}
}
...
...
@@ -222,14 +222,14 @@ class AccessController extends Controller
foreach
(
$portMacState
as
$mac
=>
$state
)
{
$portId
=
isset
(
$portsMacId
[
$mac
])
?
$portsMacId
[
$mac
]
:
false
;
if
(
$portId
===
false
)
{
if
(
$portId
===
false
)
{
continue
;
}
$port
->
setPortId
(
$portId
);
if
(
isset
(
$portsIdStatus
[
$portId
])
)
{
if
(
$portsIdStatus
[
$portId
]
===
8
)
{
if
(
isset
(
$portsIdStatus
[
$portId
])
)
{
if
(
$portsIdStatus
[
$portId
]
===
8
)
{
$state
=
8
;
}
...
...
@@ -246,7 +246,7 @@ class AccessController extends Controller
$deviceModel
=
new
DeviceModel
();
if
(
isset
(
$_SESSION
[
'port_logic_id'
])
)
{
if
(
isset
(
$_SESSION
[
'port_logic_id'
])
)
{
$_SESSION
[
'port_logic_id'
]
=
$_SESSION
[
'port_logic_id'
]
+
$portsLogicId
;
}
else
{
$_SESSION
[
'port_logic_id'
]
=
$portsLogicId
;
...
...
@@ -273,18 +273,18 @@ class AccessController extends Controller
$port
->
setPortId
(
$portId
);
$orderId
=
$port
->
getPortUsingOrderId
();
if
(
$orderId
==
false
||
$orderId
==
''
)
{
if
(
$orderId
==
false
||
$orderId
==
''
)
{
continue
;
}
$order
->
setId
(
$orderId
);
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
==
false
)
{
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
==
false
)
{
continue
;
}
$order
->
setOnlineTime
(
time
());
if
(
$offlineReason
==
0
)
{
if
(
$offlineReason
==
0
)
{
$orderState
=
new
OfflineNetState
(
$order
);
}
else
{
$orderState
=
new
OfflinePowerState
(
$order
);
...
...
@@ -292,7 +292,7 @@ class AccessController extends Controller
}
$remainTime
=
$orderState
->
getRemainChargerTime
();
if
(
$remainTime
>
0
)
{
if
(
$remainTime
>
0
)
{
$logicNum
=
sprintf
(
'%02x'
,
$order
->
getPortLogicId
());
$orderId
=
sprintf
(
'%012x'
,
$order
->
getId
());
$time
=
sprintf
(
'%04x'
,
$remainTime
);
...
...
application/controller/accept/CertifyController.php
View file @
29296654
...
...
@@ -62,14 +62,15 @@ class CertifyController extends Controller
'type_id'
],
'mac_address = '
.
"'
$mac
'"
);
if
(
$gatewayModelResult
==
false
)
{
if
(
$gatewayModelResult
==
false
)
{
Gateway
::
closeClient
(
$this
->
clientId
);
return
;
}
$stationId
=
$gatewayModelResult
[
'station_id'
];
$gatewayId
=
$gatewayModelResult
[
'id'
];
$gatewayType
=
$gatewayModelResult
[
'type_id'
];
$_SESSION
[
'gateway_type'
]
=
$gatewayType
;
$_SESSION
[
'station_id'
]
=
$stationId
;
$_SESSION
[
'gateway_id'
]
=
$gatewayId
;
...
...
@@ -81,7 +82,7 @@ class CertifyController extends Controller
$sign
=
substr
(
$sign
,
0
,
8
);
if
(
Gateway
::
isUidOnline
(
$mac
)
===
1
)
{
if
(
Gateway
::
isUidOnline
(
$mac
)
===
1
)
{
$clients
=
Gateway
::
getclientIdByUid
(
$mac
);
foreach
(
$clients
as
$client
)
{
...
...
application/controller/business/charger/OverController.php
View file @
29296654
...
...
@@ -59,22 +59,22 @@ class OverController extends Controller
$this
->
logRecord
->
setOrderId
(
$orderId
);
$order
=
new
Order
(
$orderId
);
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
!=
false
)
{
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
!=
false
)
{
$orderStateCode
=
$order
->
getStateCode
();
$order
->
setEndCapacity
(
$capacity
);
$order
->
setEndCode
(
$state
);
$order
->
setFinishTime
(
time
());
$portId
=
isset
(
$_SESSION
[
'port_logic_id'
][
$logicId
])
?
$_SESSION
[
'port_logic_id'
][
$logicId
]
:
0
;
if
(
$portId
!==
0
)
{
if
(
$portId
!==
0
)
{
$this
->
logRecord
->
setPortId
(
$portId
);
}
if
(
Gateway
::
isUidOnline
(
$order
->
getUserId
())
===
1
)
{
if
(
Gateway
::
isUidOnline
(
$order
->
getUserId
())
===
1
)
{
Gateway
::
sendToUid
(
$order
->
getUserId
(),
json_encode
([
'code'
=>
10000
]));
}
Log
::
debug
(
'order state code '
.
$orderStateCode
);
switch
(
$orderStateCode
)
{
case
StateCode
::
WAITING
:
$orderState
=
new
WaitingState
(
$order
);
...
...
@@ -89,7 +89,7 @@ class OverController extends Controller
break
;
}
if
(
isset
(
$orderState
)
)
{
if
(
isset
(
$orderState
)
)
{
switch
(
$state
)
{
case
StateCode
::
PORT_EXCEPTION
://
口子打开失败
,
适配zegbee设备
$this
->
logRecord
->
setDesc
(
'口子打开失败结束'
);
...
...
@@ -134,7 +134,7 @@ class OverController extends Controller
case
StateCode
::
CHANGE_PORT
:
if
(
isset
(
$_SESSION
[
'port_logic_id'
])
)
{
if
(
isset
(
$_SESSION
[
'port_logic_id'
])
)
{
$portId
=
isset
(
$_SESSION
[
'port_logic_id'
][
$logicId
])
?
$_SESSION
[
'port_logic_id'
][
$logicId
]
:
0
;
$port
=
new
Port
(
$portId
);
...
...
application/controller/card/charger/OverController.php
View file @
29296654
...
...
@@ -11,9 +11,11 @@ namespace Application\controller\card\charger;
use
Application\controller\Controller
;
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\cdz\card_order\state\ChargerState
;
use
Lib\cdz\card_order\state\ShedState
;
use
Lib\cdz\card_order\state\WaitingState
;
use
Lib\Gateway
;
use
Lib\log\Log
;
use
Lib\StateCode
;
use
Lib\Tool
;
...
...
@@ -42,10 +44,16 @@ class OverController extends Controller
$order
=
new
Order
(
$orderId
);
$order
->
setEndCapacity
(
$capacity
);
Log
::
debug
(
$capacity
);
Log
::
debug
(
$state
);
Log
::
debug
(
$order
->
getEndCapacity
());
$order
->
setEndCode
(
$state
);
$this
->
logRecord
->
setOrderId
(
$orderId
);
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
!==
false
)
{
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
!==
false
)
{
$orderStateCode
=
$order
->
getStateCode
();
$order
->
setEndCapacity
(
$capacity
);
$this
->
logRecord
->
setPortId
(
$order
->
getPortId
());
...
...
@@ -60,13 +68,20 @@ class OverController extends Controller
$orderState
=
new
WaitingState
(
$order
);
break
;
default
:
break
;
}
if
(
isset
(
$orderState
)
)
{
if
(
isset
(
$orderState
)
)
{
switch
(
$state
)
{
case
StateCode
::
FINISH_USER
:
$orderState
->
toUserFinish
();
break
;
case
StateCode
::
FINISH_TIME_END
:
$orderState
->
toTimeoutState
();
break
;
...
...
@@ -76,15 +91,24 @@ class OverController extends Controller
case
StateCode
::
FINISH_EXCEED
:
$orderState
->
toPowerExceedState
();
break
;
default
:
case
StateCode
::
FINISH_REFUND
:
$orderState
->
toRefundFinish
();
break
;
}
case
StateCode
::
FINISH_FULL
:
//充满自停
$this
->
logRecord
->
setDesc
(
'充满自停结束->'
.
$state
);
$orderState
->
toPowerFullState
();
default
:
break
;
}
}
}
Gateway
::
sendToUid
(
$order
->
getUserId
(),
json_encode
([
'command'
=>
'11'
]));
$this
->
response
->
send
(
'
4
5'
,
Tool
::
padding
(
$orderId
,
6
));
$this
->
response
->
send
(
'
5
5'
,
Tool
::
padding
(
$orderId
,
6
));
}
...
...
application/controller/card/charger/RequestController.php
View file @
29296654
...
...
@@ -16,6 +16,8 @@ use Application\model\UserModel;
use
Lib\cdz\order\Order
;
use
Lib\cdz\order\save\OrderSaveRedis
;
use
Lib\log\Log
;
use
Lib\order_check\DelayOrder
;
use
Lib\station\gateway\port\Port
;
use
Lib\Tool
;
class
RequestController
extends
Controller
...
...
@@ -42,21 +44,20 @@ class RequestController extends Controller
$time
=
hexdec
(
$this
->
request
->
get
(
'time'
));
$price
=
hexdec
(
$this
->
request
->
get
(
'price'
));
if
(
(
isset
(
$_SESSION
[
'gateway_id'
])
&&
isset
(
$_SESSION
[
'station_id'
])
&&
isset
(
$_SESSION
[
'station_name'
]))
===
false
)
{
if
(
(
isset
(
$_SESSION
[
'gateway_id'
])
&&
isset
(
$_SESSION
[
'station_id'
])
&&
isset
(
$_SESSION
[
'station_name'
]))
===
false
)
{
Log
::
debug
(
'miss gateway)id'
);
return
;
}
if
(
isset
(
$_SESSION
[
'port_logic_id'
]))
{
Log
::
debug
(
'port_logic_id'
,
$_SESSION
[
'port_logic_id'
]);
if
(
isset
(
$_SESSION
[
'port_logic_id'
])
)
{
if
(
isset
(
$_SESSION
[
'port_logic_id'
][
$logicId
])
)
{
if
(
isset
(
$_SESSION
[
'port_logic_id'
][
$logicId
])
)
{
$portId
=
$_SESSION
[
'port_logic_id'
][
$logicId
];
}
}
if
(
isset
(
$portId
)
===
false
)
{
if
(
isset
(
$portId
)
===
false
)
{
return
;
}
...
...
@@ -64,14 +65,12 @@ class RequestController extends Controller
$userId
=
$cardModel
->
getColumn
(
'user_id'
,
'mac = '
.
"'
$cardId
'"
);
Log
::
debug
(
$userId
);
if
(
isset
(
$userId
))
{
if
(
isset
(
$userId
)
)
{
$userModel
=
new
UserModel
();
$balance
=
$userModel
->
getColumn
(
'wallet_balance'
,
'id = '
.
$userId
);
}
$balance
=
isset
(
$balance
)
?
$balance
:
0
;
if
(
(
int
)
$balance
<
(
int
)
$price
)
{
if
(
(
int
)
$balance
<
(
int
)
$price
)
{
$orderId
=
0
;
}
else
{
...
...
@@ -85,37 +84,58 @@ class RequestController extends Controller
$orderModel
->
insertRow
([
'gateway_id'
=>
$gatewayId
,
'station_id'
=>
$stationId
,
'order_amount'
=>
$price
,
'port_id'
=>
$portId
,
'wx_user_id'
=>
$userId
,
'out_trade_no'
=>
$outTradeNo
,
'pay_amount'
=>
$price
,
'charger_time'
=>
$time
,
'created_at'
=>
$date
,
'logic_num'
=>
$logicId
,
'pay_type'
=>
3
,
'pay_type'
=>
2
,
'station_name'
=>
$stationName
,
]);
$orderId
=
$orderModel
->
getColumn
(
'id'
,
'out_trade_no = '
.
$outTradeNo
);
$orderId
=
$orderModel
->
getColumn
(
'id'
,
'out_trade_no = '
.
"'
$outTradeNo
'"
);
}
$this
->
response
->
send
(
'33'
,
$type
.
Tool
::
padding
(
$logicId
,
1
)
.
Tool
::
padding
(
$time
,
2
)
.
Tool
::
padding
(
$price
,
2
)
.
Tool
::
padding
(
$orderId
,
6
)
.
Tool
::
padding
(
$balance
,
4
));
if
(
$orderId
!=
0
)
{
if
(
$orderId
!=
0
)
{
//todo 订单缓存存储
$port
=
new
Port
();
$port
->
setPortId
(
$portId
);
$port
->
setPortUsingOrderId
(
$userId
,
$orderId
);
$port
->
setState
(
-
1
);
$port
->
updatePortState
();
$order
=
new
Order
(
$orderId
);
$order
->
setStationId
(
$stationId
);
$order
->
setOutTradeNo
(
$outTradeNo
);
$order
->
setGatewayMac
(
$_SESSION
[
'gateway_mac'
]);
$order
->
setPortName
(
$_SESSION
[
'port_id_name'
][
$portId
]);
$order
->
setPortId
(
$portId
);
$order
->
setGatewayId
(
$gatewayId
);
$order
->
setCardId
(
$cardId
);
$order
->
setStationId
(
$stationId
);
$order
->
setStationName
(
$stationName
);
$order
->
setCreatedTime
(
time
());
$order
->
setPayAmount
(
$price
);
$order
->
setUserId
(
$userId
);
$order
->
setPurchaseTime
(
$time
);
$order
->
setPortLogicId
(
$logicId
);
$order
->
setStateCode
(
-
1
);
$order
->
setGatewayType
(
$_SESSION
[
'gateway_type'
]);
$saveOrder
=
new
OrderSaveRedis
(
$order
);
$saveOrder
->
saveAll
();
$delayOrder
=
new
DelayOrder
();
$delayOrder
->
setOrder
(
$order
);
$delayOrder
->
setDelay
();
}
...
...
application/controller/card/charger/StartController.php
View file @
29296654
...
...
@@ -10,8 +10,10 @@ namespace Application\controller\card\charger;
use
Application\controller\Controller
;
use
Application\model\UserModel
;
use
Lib\cdz\order\Order
;
use
Lib\cdz_order\state\WaitingState
;
use
Lib\cdz\card_order\state\WaitingState
;
use
Lib\log\Log
;
use
Lib\StateCode
;
use
Lib\Tool
;
...
...
@@ -41,7 +43,15 @@ class StartController extends Controller
$capacity
=
hexdec
(
$this
->
request
->
get
(
'capacity'
));
$order
=
new
Order
(
$orderId
);
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
!=
false
)
{
if
(
$order
->
getOrderCache
(
\Events
::
getRedis
())
!=
false
)
{
$price
=
$order
->
getPayAmount
();
$userId
=
$order
->
getUserId
();
$userModel
=
new
UserModel
();
Log
::
debug
(
'order_cache'
,
$order
->
getOrderCache
(
\Events
::
getRedis
()));
$orderStateCode
=
$order
->
getStateCode
();
$order
->
setStartCapacity
(
$capacity
);
...
...
@@ -60,6 +70,13 @@ class StartController extends Controller
switch
(
$state
)
{
case
StateCode
::
PORT_CHARGER
:
Log
::
debug
(
$price
);
$db
=
\Events
::
getDb
();
$db
->
query
(
"UPDATE `wx_users` SET `wallet_balance` = `wallet_balance` -
$price
WHERE id =
$userId
"
);
Log
::
debug
(
'decrease wallet'
);
$orderState
->
toChargerState
();
break
;
case
StateCode
::
PORT_SHED
:
...
...
lib/cdz/card_order/state/ChargerState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:21
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Application\model\OrderExceptionModel
;
...
...
@@ -40,6 +40,8 @@ class ChargerState extends State
public
function
toUserFinish
()
{
$orderModel
=
new
OrderModel
();
$orderModel
->
update
([
'is_stop'
=>
$this
->
order
->
getEndCode
(),
'end_capacity'
=>
$this
->
order
->
getEndCapacity
(),
...
...
@@ -48,6 +50,7 @@ class ChargerState extends State
'state'
=>
1
,
],
'id = '
.
$this
->
order
->
getId
());
$port
=
new
Port
();
$port
->
setState
(
StateCode
::
PORT_ONLINE
);
$port
->
setPortId
(
$this
->
order
->
getPortId
());
...
...
@@ -72,7 +75,7 @@ class ChargerState extends State
$finishByUserMessage
->
setOrderAmount
(
$this
->
order
->
getPayAmount
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
Log
::
error
(
'send finish by user message fail'
);
}
...
...
@@ -145,7 +148,7 @@ class ChargerState extends State
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$powerExceedMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$powerExceedMessage
)
===
false
)
{
Log
::
error
(
'send power exceed message fail'
);
//todo tcp异常上报
}
...
...
@@ -197,7 +200,7 @@ class ChargerState extends State
$chargerFullMessage
->
setPurchaseTime
(
$this
->
order
->
getPurchaseTime
());
$chargerFullMessage
->
setRemark
(
$chargerFullMessage
->
getRemark
()
.
'\n'
.
sprintf
(
'%012x'
,
$this
->
order
->
getId
()));
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerFullMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$chargerFullMessage
)
===
false
)
{
Log
::
error
(
'send charger full message fail'
);
}
$port
=
new
Port
();
...
...
@@ -268,7 +271,7 @@ class ChargerState extends State
$chargerShedMessage
->
setDate
(
$this
->
nowDate
);
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerShedMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$chargerShedMessage
)
==
false
)
{
Log
::
error
(
'send port shed message fail'
);
}
...
...
@@ -338,13 +341,14 @@ class ChargerState extends State
$chargerTimeoutMessage
->
setOrderAmount
(
$this
->
order
->
getPayAmount
());
$chargerTimeoutMessage
->
setEndTime
(
$this
->
nowDate
);
$chargerTimeoutMessage
->
setUserId
(
$this
->
order
->
getUserId
());
$chargerTime
=
$this
->
now
TimeStamp
-
$this
->
order
->
getStartTime
();
$chargerTime
=
$this
->
now
Date
-
$this
->
order
->
getStartTime
();
$chargerTime
/=
60
;
$chargerTime
=
ceil
(
$chargerTime
);
$chargerTimeoutMessage
->
setChargerTime
((
int
)
$chargerTime
);
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
==
false
)
{
Log
::
error
(
'send charger timeout message fail'
);
}
...
...
lib/cdz/card_order/state/ExceptionState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:22
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
lib/cdz/card_order/state/OfflineNetState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 下午6:45
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\NoticePortShed
;
...
...
@@ -28,7 +28,7 @@ class OfflineNetState extends State
$startTime
=
$this
->
order
->
getStartTime
();
if
(
$startTime
===
''
||
$this
->
order
->
getOfflineTime
()
==
'0'
)
{
if
(
$startTime
===
''
||
$this
->
order
->
getOfflineTime
()
==
'0'
)
{
$this
->
remainChargerTime
=
(
int
)(
$this
->
order
->
getPurchaseTime
());
}
else
{
$purchaseTime
=
$this
->
order
->
getPurchaseTime
();
...
...
@@ -57,7 +57,7 @@ class OfflineNetState extends State
public
function
toChargerState
()
{
if
(
$this
->
order
->
getIsRefund
()
===
1
)
{
if
(
$this
->
order
->
getIsRefund
()
===
1
)
{
//已经退款 下发结束充电命令
$this
->
order
->
stop
(
$this
->
order
,
$_SESSION
[
'client_id'
],
43
);
return
;
...
...
@@ -87,7 +87,7 @@ class OfflineNetState extends State
*/
public
function
toShedState
()
{
if
(
$this
->
remainChargerTime
>
0
)
{
if
(
$this
->
remainChargerTime
>
0
)
{
$this
->
publishPortShed
(
$this
->
order
);
}
...
...
lib/cdz/card_order/state/OfflinePowerState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 下午6:45
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
@@ -21,7 +21,7 @@ class OfflinePowerState extends State
public
function
__construct
(
Order
$order
)
{
parent
::
__construct
(
$order
);
if
(
$this
->
order
->
getIsRefund
()
===
1
)
{
if
(
$this
->
order
->
getIsRefund
()
===
1
)
{
//已经退款 下发结束充电命令
//$this->order->stop($this->order,$_SESSION['client_id'],43);
$this
->
remainChargerTime
=
0
;
...
...
@@ -31,7 +31,7 @@ class OfflinePowerState extends State
$offlineTime
=
$this
->
order
->
getOfflineTime
();
$startTime
=
$this
->
order
->
getStartTime
();
if
(
$startTime
===
''
||
$this
->
order
->
getOfflineTime
()
==
'0'
)
{
if
(
$startTime
===
''
||
$this
->
order
->
getOfflineTime
()
==
'0'
)
{
$this
->
remainChargerTime
=
(
int
)(
$this
->
order
->
getPurchaseTime
());
}
else
{
...
...
@@ -56,7 +56,7 @@ class OfflinePowerState extends State
public
function
toChargerState
()
{
if
(
$this
->
order
->
getIsRefund
()
===
1
)
{
if
(
$this
->
order
->
getIsRefund
()
===
1
)
{
//已经退款 下发结束充电命令
//$this->order->stop($this->order,$_SESSION['client_id'],43);
$this
->
remainChargerTime
=
0
;
...
...
lib/cdz/card_order/state/PowerExceedState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:22
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
lib/cdz/card_order/state/PowerFullState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:22
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
lib/cdz/card_order/state/ShedState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:21
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Application\model\OrderExceptionModel
;
...
...
@@ -64,7 +64,7 @@ class ShedState extends State
$finishByUserMessage
->
setOrderAmount
(
$this
->
order
->
getPayAmount
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
Log
::
error
(
'send finish by user message fail'
);
}
...
...
@@ -115,7 +115,7 @@ class ShedState extends State
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerReloadMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$chargerReloadMessage
)
===
false
)
{
Log
::
error
(
'send order reload message fail'
);
}
...
...
@@ -198,7 +198,7 @@ class ShedState extends State
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$shedTimeoutMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$shedTimeoutMessage
)
===
false
)
{
Log
::
error
(
'send shed timeout message fail'
);
}
...
...
@@ -257,7 +257,7 @@ class ShedState extends State
$chargerTimeoutMessage
->
setStationName
(
$this
->
order
->
getStationName
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
===
false
)
{
Log
::
error
(
'shed state order send charger timeout message fail'
);
}
...
...
@@ -270,5 +270,10 @@ class ShedState extends State
// TODO: Implement stopFail() method.
}
public
function
toRefundFinish
()
{
}
}
\ No newline at end of file
lib/cdz/card_order/state/ShedTimeoutState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:23
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
lib/cdz/card_order/state/State.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:21
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
@@ -82,5 +82,4 @@ abstract class State
}
}
\ No newline at end of file
lib/cdz/card_order/state/TimeoutState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:23
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Lib\cdz\order\Order
;
...
...
lib/cdz/card_order/state/WaitingState.php
View file @
29296654
...
...
@@ -6,7 +6,7 @@
* Time: 上午11:21
*/
namespace
Lib\cdz_order\state
;
namespace
Lib\cdz
\card
_order\state
;
use
Application\model\OrderExceptionModel
;
...
...
@@ -14,13 +14,8 @@ use Application\model\OrderModel;
use
Lib\cdz\order\Order
;
use
Lib\cdz\order\save\OrderSaveRedis
;
use
Lib\log\Log
;
use
Lib\remote\api\message\FailMessage
;
use
Lib\remote\api\message\SendMessage
;
use
Lib\remote\api\message\StartMessage
;
use
Lib\StateCode
;
use
Lib\station\gateway\port\Port
;
use
Src\command\SendCommand
;
use
Src\command\StopChargerCommand
;
class
WaitingState
extends
State
{
...
...
lib/cdz/order/Order.php
View file @
29296654
...
...
@@ -20,6 +20,9 @@ class Order
private
$isChangeState
=
false
;
private
$gatewayType
=
0
;
/**
* @var int
*/
...
...
@@ -68,7 +71,7 @@ class Order
* 订单状态
* @var int
*/
private
$stateCode
;
private
$stateCode
=
-
2
;
/**
* @var int
...
...
@@ -184,12 +187,12 @@ class Order
{
if
(
isset
(
$this
->
orderCache
)
==
false
||
(
is_array
(
$this
->
orderCache
)
&&
count
(
$this
->
orderCache
)
===
0
)
)
{
if
(
isset
(
$this
->
orderCache
)
==
false
||
(
is_array
(
$this
->
orderCache
)
&&
count
(
$this
->
orderCache
)
===
0
)
)
{
$keyName
=
$this
->
getCacheKeyName
();
if
(
$redis
->
exists
(
$keyName
)
==
false
)
{
if
(
$redis
->
exists
(
$keyName
)
==
false
)
{
return
false
;
...
...
@@ -197,7 +200,7 @@ class Order
$this
->
orderCache
=
$redis
->
hGetAll
(
$keyName
);
if
(
count
(
$this
->
orderCache
)
<
5
)
{
if
(
count
(
$this
->
orderCache
)
<
5
)
{
return
false
;
}
...
...
@@ -231,7 +234,7 @@ class Order
{
$keyName
=
$this
->
getCacheKeyName
();
if
(
$redis
->
exists
(
$keyName
)
==
false
)
{
if
(
$redis
->
exists
(
$keyName
)
==
false
)
{
return
false
;
...
...
@@ -668,5 +671,21 @@ class Order
$this
->
isChangeState
=
$isChangeState
;
}
/**
* @return int
*/
public
function
getGatewayType
()
:
int
{
return
$this
->
gatewayType
;
}
/**
* @param int $gatewayType
*/
public
function
setGatewayType
(
int
$gatewayType
)
:
void
{
$this
->
gatewayType
=
$gatewayType
;
}
}
\ No newline at end of file
lib/cdz/order/save/OrderSaveRedis.php
View file @
29296654
...
...
@@ -40,7 +40,7 @@ class OrderSaveRedis
$update
=
[];
foreach
(
$keys
as
$key
)
{
if
(
$this
->
order
->
$key
!==
""
)
{
if
(
$this
->
order
->
$key
!==
""
)
{
$update
[
$key
]
=
$this
->
order
->
$key
;
}
}
...
...
@@ -64,9 +64,13 @@ class OrderSaveRedis
$reflection
=
new
\ReflectionClass
(
$this
->
order
);
$properties
=
$reflection
->
getDefaultProperties
();
$properties
=
array_keys
(
$properties
);
foreach
(
$properties
as
$property
)
{
if
(
isset
(
$this
->
order
->
$property
)
&&
$this
->
order
->
$property
!=
''
)
{
if
(
$this
->
order
->
$property
!==
''
)
{
Log
::
debug
(
'value'
.
$this
->
order
->
$property
);
$update
[
$property
]
=
$this
->
order
->
$property
;
}
}
...
...
@@ -77,6 +81,8 @@ class OrderSaveRedis
}
Log
::
debug
(
'save all'
,
$update
);
$this
->
redis
->
hMset
(
$this
->
order
->
getCacheKeyName
(),
$update
);
$this
->
redis
->
expire
(
$this
->
order
->
getCacheKeyName
(),
60
*
60
*
24
);
...
...
lib/cdz/order/state/ChargerState.php
View file @
29296654
...
...
@@ -76,7 +76,7 @@ class ChargerState extends State
$finishByUserMessage
->
setOrderAmount
(
$this
->
order
->
getPayAmount
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
Log
::
error
(
'send finish by user message fail'
);
}
...
...
@@ -162,7 +162,7 @@ class ChargerState extends State
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$powerExceedMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$powerExceedMessage
)
===
false
)
{
Log
::
error
(
'send power exceed message fail'
);
//todo tcp异常上报
}
...
...
@@ -214,11 +214,16 @@ class ChargerState extends State
$chargerFullMessage
=
new
ChargerFullMessage
();
$chargerFullMessage
->
setEndTime
(
$this
->
nowDate
);
$chargerFullMessage
->
setStartTime
(
date
(
'Y-m-d H:i:s'
,
$this
->
order
->
getStartTime
()));
$chargerFullMessage
->
setChargerTime
(
abs
(
ceil
((
$this
->
order
->
getStartTime
()
-
$this
->
order
->
getFinishTime
())
/
60
)));
$chargerFullMessage
->
setPurchaseTime
(
$this
->
order
->
getPurchaseTime
());
$chargerFullMessage
->
setUserId
(
$this
->
order
->
getUserId
());
$chargerFullMessage
->
setEndTime
(
$this
->
nowDate
);
$chargerFullMessage
->
setAddress
(
$this
->
order
->
getStationName
()
.
'--'
.
$this
->
order
->
getPortName
());
$chargerFullMessage
->
setAmount
(
$this
->
order
->
getPayAmount
());
$chargerFullMessage
->
setRemark
(
$chargerFullMessage
->
getRemark
()
.
'('
.
$this
->
order
->
getOutTradeNo
()
.
')'
);
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerFullMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$chargerFullMessage
)
===
false
)
{
Log
::
error
(
'send charger full message fail'
);
}
$port
=
new
Port
();
...
...
@@ -300,7 +305,7 @@ class ChargerState extends State
$chargerShedMessage
->
setDate
(
$this
->
nowDate
);
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerShedMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$chargerShedMessage
)
==
false
)
{
Log
::
error
(
'send port shed message fail'
);
}
...
...
@@ -318,6 +323,7 @@ class ChargerState extends State
'check_times'
=>
1
,
'gateway_id'
=>
$this
->
order
->
getGatewayId
(),
'station_id'
=>
$_SESSION
[
'station_id'
],
'gateway_type'
=>
$_SESSION
[
'gateway_type'
],
]);
}
catch
(
\Exception
$exception
)
{
...
...
@@ -376,7 +382,7 @@ class ChargerState extends State
$chargerTimeoutMessage
->
setChargerTime
(
ceil
(
$chargerTime
));
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
==
false
)
{
Log
::
error
(
'send charger timeout message fail'
);
}
...
...
lib/cdz/order/state/ShedState.php
View file @
29296654
...
...
@@ -65,7 +65,7 @@ class ShedState extends State
$finishByUserMessage
->
setOrderAmount
(
$this
->
order
->
getPayAmount
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
if
(
$sendMessage
->
request
(
$finishByUserMessage
)
==
false
)
{
Log
::
error
(
'send finish by user message fail'
);
}
...
...
@@ -116,7 +116,7 @@ class ShedState extends State
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerReloadMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$chargerReloadMessage
)
===
false
)
{
Log
::
error
(
'send order reload message fail'
);
}
...
...
@@ -186,7 +186,6 @@ class ShedState extends State
],
'id = '
.
$this
->
order
->
getId
());
$port
=
new
Port
(
$this
->
order
->
getPortId
());
$port
->
setState
(
StateCode
::
PORT_ONLINE
);
$port
->
setStationId
(
$this
->
order
->
getStationId
());
...
...
@@ -201,7 +200,7 @@ class ShedState extends State
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$shedTimeoutMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$shedTimeoutMessage
)
===
false
)
{
Log
::
error
(
'send shed timeout message fail'
);
}
...
...
@@ -260,7 +259,7 @@ class ShedState extends State
$chargerTimeoutMessage
->
setStationName
(
$this
->
order
->
getStationName
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$chargerTimeoutMessage
)
===
false
)
{
Log
::
error
(
'shed state order send charger timeout message fail'
);
}
...
...
@@ -268,6 +267,11 @@ class ShedState extends State
}
public
function
toRefundFinish
()
{
}
public
function
stopFail
()
{
// TODO: Implement stopFail() method.
...
...
lib/cdz/order/state/WaitingState.php
View file @
29296654
...
...
@@ -11,6 +11,7 @@ namespace Lib\cdz\order\state;
use
Application\model\OrderExceptionModel
;
use
Application\model\OrderModel
;
use
Application\model\UserModel
;
use
Lib\cdz\order\Order
;
use
Lib\cdz\order\save\OrderSaveRedis
;
use
Lib\Gateway
;
...
...
@@ -88,7 +89,7 @@ class WaitingState extends State
//订单已经退款则直接结束
if
(
$this
->
order
->
getIsRefund
()
==
1
)
{
if
(
$this
->
order
->
getIsRefund
()
==
1
)
{
// 下发结束充电命令
$orderId
=
$this
->
order
->
getId
();
$portLogic
=
$this
->
order
->
getPortLogicId
();
...
...
@@ -108,7 +109,7 @@ class WaitingState extends State
$this
->
order
->
setStateCode
(
12
);
\Events
::
pipe
();
$orderSaveRedis
=
new
OrderSaveRedis
(
$this
->
order
);
if
(
$this
->
order
->
isChangeState
()
===
false
)
{
if
(
$this
->
order
->
isChangeState
()
===
false
)
{
$orderSaveRedis
->
save
([
'stateCode'
,
'startTime'
,
'startCapacity'
]);
}
else
{
$orderSaveRedis
->
save
([
'stateCode'
,
'startTime'
]);
...
...
@@ -132,18 +133,29 @@ class WaitingState extends State
$startMessage
->
setOrderId
(
$this
->
order
->
getOutTradeNo
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$startMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$startMessage
)
===
false
)
{
Log
::
error
(
'推送开始充电失败'
);
}
if
(
$this
->
order
->
getCardId
()
!=
''
)
{
$userId
=
$this
->
order
->
getUserId
();
$price
=
$this
->
order
->
getPayAmount
();
$db
=
\Events
::
getDb
();
$db
->
query
(
"UPDATE `wx_users` SET `wallet_balance` = `wallet_balance` -
$price
WHERE id =
$userId
"
);
}
$update
=
[
'is_charger'
=>
StateCode
::
PORT_CHARGER
,
'start_time'
=>
date
(
'Y-m-d H:i:s'
,
$this
->
order
->
getStartTime
()),
];
//更新订单状态
$startCapacity
=
$this
->
order
->
getStartCapacity
();
if
(
$startCapacity
!==
-
2
&&
$startCapacity
>=
0
)
{
if
(
$startCapacity
!==
-
2
&&
$startCapacity
>=
0
)
{
$update
[
'start_capacity'
]
=
(
int
)
$this
->
order
->
getStartCapacity
();
}
$orderModel
=
new
OrderModel
();
...
...
@@ -196,7 +208,7 @@ class WaitingState extends State
$failMessage
->
setOrderId
(
$this
->
order
->
getOutTradeNo
());
$failMessage
->
setUserId
(
$this
->
order
->
getUserId
());
$sendMessage
=
new
SendMessage
();
if
(
$sendMessage
->
request
(
$failMessage
)
===
false
)
{
if
(
$sendMessage
->
request
(
$failMessage
)
===
false
)
{
Log
::
error
(
'充电失败,推送消息失败'
,
$this
->
order
->
getOrderCache
(
\Events
::
getRedis
()));
}
...
...
@@ -236,7 +248,7 @@ class WaitingState extends State
Log
::
debug
(
'waiting to shed ->start_capacity'
.
$this
->
order
->
getStartCapacity
());
if
(
$this
->
order
->
getStartCapacity
()
>=
0
)
{
if
(
$this
->
order
->
getStartCapacity
()
>=
0
)
{
$orderModel
->
update
([
'start_capacity'
=>
(
int
)
$this
->
order
->
getStartCapacity
(),
],
'id = '
.
$this
->
order
->
getId
());
...
...
lib/order_check/DelayOrder.php
0 → 100644
View file @
29296654
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2019/1/26
* Time: 下午4:13
*/
namespace
Lib\order_check
;
use
Lib\cdz\order\Order
;
class
DelayOrder
{
const
DELAY_KEY
=
'cdz:delay:check_charger_start:zset'
;
/**
* @var Order
*/
private
$order
;
private
$redis
;
public
function
__construct
()
{
$this
->
redis
=
\Events
::
getRedis
();
}
public
function
deleteDelayOrder
(
int
$orderId
)
{
$this
->
redis
->
zDelete
(
self
::
DELAY_KEY
,
$orderId
);
}
public
function
getDelayOrder
()
{
return
$this
->
redis
->
zRangeByScore
(
self
::
DELAY_KEY
,
0
,
time
());
}
public
function
setDelay
()
{
$this
->
redis
->
zAdd
(
self
::
DELAY_KEY
,
time
()
+
3
*
60
,
$this
->
order
->
getId
());
}
/**
* @return Order
*/
public
function
getOrder
()
:
Order
{
return
$this
->
order
;
}
/**
* @param Order $order
*/
public
function
setOrder
(
Order
$order
)
:
void
{
$this
->
order
=
$order
;
}
}
\ No newline at end of file
lib/remote/api/message/ChargerFullMessage.php
View file @
29296654
...
...
@@ -21,6 +21,12 @@ class ChargerFullMessage extends Message
private
$purchaseTime
;
private
$address
=
''
;
private
$amount
=
0
;
private
$chargerTime
=
0
;
private
$remark
=
'温馨提示:您的爱车已停止充电,如有疑问您可以在公众号后台留言或直接拨打客服热线进行咨询。
感谢您的使用'
;
...
...
@@ -41,16 +47,20 @@ class ChargerFullMessage extends Message
],
'keyword1'
=>
[
'value'
=>
$this
->
start
Time
,
'value'
=>
$this
->
end
Time
,
'color'
=>
'#333'
,
],
'keyword2'
=>
[
'value'
=>
$this
->
purchaseTime
,
'value'
=>
$this
->
address
,
'color'
=>
'#333'
,
],
'keyword3'
=>
[
'value'
=>
$this
->
endTime
,
'value'
=>
$this
->
chargerTime
,
'color'
=>
'#333'
,
],
'keyword4'
=>
[
'value'
=>
$this
->
amount
,
'color'
=>
'#333'
,
],
'remark'
=>
[
...
...
@@ -150,5 +160,53 @@ class ChargerFullMessage extends Message
$this
->
remark
=
$remark
;
}
/**
* @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
getAmount
()
:
int
{
return
$this
->
amount
;
}
/**
* @param int $amount
*/
public
function
setAmount
(
int
$amount
)
:
void
{
$this
->
amount
=
$amount
;
}
/**
* @return int
*/
public
function
getChargerTime
()
:
int
{
return
$this
->
chargerTime
;
}
/**
* @param int $chargerTime
*/
public
function
setChargerTime
(
int
$chargerTime
)
:
void
{
$this
->
chargerTime
=
$chargerTime
;
}
}
\ No newline at end of file
lib/station/gateway/port/Port.php
View file @
29296654
...
...
@@ -75,11 +75,11 @@ class Port
public
function
isPortBan
()
{
if
(
isset
(
$_SESSION
[
'port_id_status'
])
)
{
if
(
isset
(
$_SESSION
[
'port_id_status'
])
)
{
$portIdStatus
=
$_SESSION
[
'port_id_status'
];
if
(
isset
(
$portIdStatus
[
$this
->
portId
])
)
{
if
(
isset
(
$portIdStatus
[
$this
->
portId
])
)
{
if
(
$portIdStatus
[
$this
->
portId
]
===
8
)
{
if
(
$portIdStatus
[
$this
->
portId
]
===
8
)
{
return
true
;
}
}
...
...
@@ -99,8 +99,8 @@ class Port
$redis
->
zAdd
(
self
::
PORT_STATE
,
$this
->
state
,
$this
->
portId
);
if
(
$this
->
stationId
===
0
||
$this
->
gatewayId
===
0
)
{
if
(
isset
(
$_SESSION
[
'gateway_id'
])
&&
isset
(
$_SESSION
[
'station_id'
])
)
{
if
(
$this
->
stationId
===
0
||
$this
->
gatewayId
===
0
)
{
if
(
isset
(
$_SESSION
[
'gateway_id'
])
&&
isset
(
$_SESSION
[
'station_id'
])
)
{
$this
->
stationId
=
$_SESSION
[
'station_id'
];
$this
->
gatewayId
=
$_SESSION
[
'gateway_id'
];
}
else
{
...
...
@@ -118,12 +118,23 @@ class Port
'updated_at'
=>
date
(
'Y-m-d H:i:s'
)
],
'id = '
.
$this
->
portId
);
if
(
$orderId
!==
0
)
{
if
(
$orderId
!==
0
)
{
$redis
->
zAdd
(
'cdz:order:state:zset'
,
$this
->
state
,
$orderId
);
}
}
public
function
setPortUsingOrderId
(
$userId
,
$orderId
)
{
$redis
=
\Events
::
getRedis
();
$redis
->
hSet
(
self
::
USING_ORDER_ID
,
$this
->
portId
,
$orderId
);
$redis
->
zAdd
(
self
::
USING_USER_ID
,
$userId
,
$this
->
portId
);
}
/**
* @return string
*/
...
...
@@ -149,7 +160,7 @@ class Port
$this
->
updatePortState
(
$orderId
);
if
(
$orderId
!=
0
)
{
if
(
$orderId
!=
0
)
{
$redis
->
zRem
(
'cdz:order:state:zset'
,
$orderId
);
$redis
->
del
(
'cdz:order:state:'
.
$orderId
);
}
...
...
src/BroadcastToAgent.php
View file @
29296654
...
...
@@ -19,7 +19,7 @@ class BroadcastToAgent
public
function
__construct
()
{
if
(
isset
(
$_SESSION
[
'agent_id'
])
)
{
if
(
isset
(
$_SESSION
[
'agent_id'
])
)
{
$this
->
agentId
=
$_SESSION
[
'agent_id'
];
}
...
...
@@ -27,6 +27,7 @@ class BroadcastToAgent
public
function
broadcast
(
array
$data
)
{
Log
::
debug
(
'agent_id'
.
$this
->
agentId
);
$redis
=
\Events
::
getRedis
();
$superAgentIds
=
$redis
->
hGetAll
(
'cdz:super_agent_id:hash'
);
...
...
@@ -34,11 +35,12 @@ class BroadcastToAgent
Gateway
::
sendToUid
(
$id
,
json_encode
(
$data
));
}
if
(
$this
->
agentId
!==
''
)
{
if
(
$this
->
agentId
!==
''
)
{
Gateway
::
sendToUid
(
$this
->
agentId
,
json_encode
(
$data
));
return
true
;
}
else
{
}
else
{
Log
::
error
(
'agent_id can not find'
);
return
false
;
}
...
...
src/command/StopChargerCommand.php
View file @
29296654
...
...
@@ -22,12 +22,11 @@ class StopChargerCommand implements Command
public
function
getMessage
()
:
string
{
$this
->
type
=
sprintf
(
'%02x'
,
$this
->
type
);
$this
->
portLogic
=
sprintf
(
'%02x'
,
$this
->
portLogic
);
$this
->
outTradeNo
=
sprintf
(
'%12x'
,
$this
->
outTradeNo
);
$this
->
outTradeNo
=
sprintf
(
'%
0
12x'
,
$this
->
outTradeNo
);
$this
->
finishType
=
sprintf
(
'%02x'
,
$this
->
finishType
);
return
$this
->
type
.
$this
->
portLogic
.
$this
->
outTradeNo
.
$this
->
finishType
;
return
$this
->
portLogic
.
$this
->
outTradeNo
.
$this
->
finishType
;
}
...
...
@@ -96,5 +95,4 @@ class StopChargerCommand implements Command
}
}
\ No newline at end of file
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