Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hdg_mqtt
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
杨苏杭
hdg_mqtt
Commits
00fc2ae3
Commit
00fc2ae3
authored
Oct 23, 2018
by
banice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构状态模式
parent
83f1318e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
0 deletions
+134
-0
lib/state/Order.php
+48
-0
lib/state/ReturnWaiting.php
+50
-0
lib/state/Update.php
+36
-0
No files found.
lib/state/Order.php
0 → 100644
View file @
00fc2ae3
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/23
* Time: 下午7:58
*/
namespace
Lib\state
;
class
Order
{
private
$state
=
0
;
private
$outTradeNo
=
''
;
private
$returnDoorNum
=
0
;
private
$returnDoorId
=
0
;
private
$returnBoxId
=
0
;
private
$returnBoxNum
=
0
;
private
$boxCode
=
''
;
public
function
__get
(
$name
)
{
return
$this
->
$name
;
}
public
function
__set
(
$name
,
$value
)
{
$this
->
$name
=
$value
;
}
public
function
getCacheKey
()
{
return
config
(
'redis_key.ORDER_CACHE'
)
.
':'
.
$this
->
outTradeNo
;
}
}
\ No newline at end of file
lib/state/ReturnWaiting.php
0 → 100644
View file @
00fc2ae3
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/23
* Time: 下午7:56
*/
namespace
Lib\state
;
use
Lib\aliyun\api\PublishToTopic
;
use
Lib\aliyun\Client
;
use
Lib\command\ConfirmOpenDoor
;
class
ReturnWaiting
{
const
STATE
=
2
;
private
$order
;
public
function
__construct
(
Order
$order
)
{
$this
->
order
=
$order
;
}
public
function
toReturnDoorConfirm
()
{
$this
->
order
->
state
=
self
::
STATE
;
$update
=
new
Update
(
$this
->
order
);
$update
->
update
([
'state'
]);
//todo 推送websocket消息 确认门已打开
//todo 回复确认门已打开消息
$confirmOpenDoor
=
new
ConfirmOpenDoor
();
$confirmOpenDoor
->
setOrderId
(
$this
->
order
->
outTradeNo
);
$publishToTopic
=
new
PublishToTopic
();
$publishToTopic
->
setMessageContent
(
$confirmOpenDoor
->
getMessage
());
$publishToTopic
->
setProductKey
(
env
(
'MQTT_PRODUCT_KEY'
));
$publishToTopic
->
setTopicFullName
(
Box
::
getOpenDoorTopic
(
$this
->
order
->
boxCode
));
$client
=
new
Client
();
$client
->
setApi
(
$publishToTopic
);
if
(
$client
->
request
()
===
true
)
{
}
}
\ No newline at end of file
lib/state/Update.php
0 → 100644
View file @
00fc2ae3
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/23
* Time: 下午8:03
*/
namespace
Lib\state
;
class
Update
{
private
$order
;
public
function
__construct
(
Order
$order
)
{
$this
->
order
=
$order
;
}
public
function
update
(
array
$attribute
)
{
$redis
=
app
(
'Redis'
);
if
(
$redis
instanceof
\Redis
)
{
$update
=
[];
foreach
(
$attribute
as
$item
)
{
$update
[
$item
]
=
$this
->
order
->
$item
;
}
$redis
->
hMset
(
$this
->
order
->
getCacheKey
(),
$update
);
}
}
}
\ 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