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
ae14f02f
Commit
ae14f02f
authored
May 23, 2018
by
BANice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志类完善,未添加一次性写入全部日志
parent
e9cf0ed4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
96 additions
and
27 deletions
+96
-27
.idea/workspace.xml
+0
-0
Application/Controller/AccessController.php
+0
-2
Application/Controller/PowerController.php
+17
-0
Application/Events.php
+16
-2
Application/Model.php
+21
-0
Application/Model/OrderModel.php
+23
-0
Lib/Log.php
+14
-21
start.php
+5
-2
No files found.
.idea/workspace.xml
View file @
ae14f02f
This diff is collapsed.
Click to expand it.
Application/Controller/AccessController.php
View file @
ae14f02f
...
...
@@ -48,8 +48,6 @@ class AccessController extends Controller
if
(
$gatewayId
!=
false
)
{
echo
'bind mac - '
.
$mac
.
PHP_EOL
;
//tcp绑定uid
Gateway
::
bindUid
(
$this
->
clientId
,
$mac
);
...
...
Application/Controller/PowerController.php
View file @
ae14f02f
...
...
@@ -10,6 +10,7 @@ namespace Application\Controller;
use
Application\Controller
;
use
Application\Model\OrderModel
;
class
PowerController
extends
Controller
{
...
...
@@ -39,6 +40,9 @@ class PowerController extends Controller
];
/**
* 硬件开始充电
*/
public
function
charger
()
{
...
...
@@ -50,6 +54,13 @@ class PowerController extends Controller
$outTradeNo
=
$this
->
get
(
'outTradeNo'
);
//fixme 修改订单表中,订单的状态位
$orderModel
=
new
OrderModel
();
$row
=
$orderModel
->
update
([
'state'
=>
1
],
'out_trade_no = '
.
$outTradeNo
);
var_dump
(
$row
);
}
...
...
@@ -59,6 +70,9 @@ class PowerController extends Controller
}
/**
* 硬件充电结束
*/
public
function
stop
()
{
...
...
@@ -78,6 +92,9 @@ class PowerController extends Controller
}
/**
* 上报充电功率
*/
public
function
power
()
{
...
...
Application/Events.php
View file @
ae14f02f
...
...
@@ -12,6 +12,7 @@ use Lib\Crc;
use
GatewayWorker\Lib\Gateway
;
use
Route\Api
;
use
Lib\Route
;
use
Lib\Log
;
define
(
'APP'
,
'Application\\Controller\\'
);
...
...
@@ -60,11 +61,22 @@ class Events
}
public
static
function
onConnect
(
$clientId
)
{
Log
::
debug
(
'connect'
,[
'time'
=>
date
(
'H:i:s'
)
]);
}
public
static
function
onMessage
(
$clientId
,
$message
)
{
//$message = mb_strtoupper($message);
var_dump
(
$message
);
...
...
@@ -78,6 +90,7 @@ class Events
}
else
{
$command
=
substr
(
$message
,
6
,
2
);
var_dump
(
$command
);
...
...
@@ -91,12 +104,13 @@ class Events
$method
=
$route
->
getMethod
();
$controllerName
=
APP
.
$controllerName
;
//去除crc字节
$message
=
substr
(
$message
,
0
,
-
2
);
$message
=
mb_strtoupper
(
$message
);
$controller
=
new
$controllerName
(
$clientId
,
$message
,
$command
);
$controller
->
$method
();
...
...
Application/Model.php
View file @
ae14f02f
...
...
@@ -73,6 +73,11 @@ class Model
}
/**
* @param $where
* @return array
*/
public
function
getRow
(
$where
)
{
...
...
@@ -80,6 +85,10 @@ class Model
}
/**
* @param array $data
* @return mixed
*/
public
function
insertRow
(
Array
$data
)
{
return
$this
->
db
->
insert
(
$this
->
table
)
->
cols
(
$data
)
->
query
();
...
...
@@ -87,6 +96,18 @@ class Model
}
/**
* @param array $update
* @param $where
* @return mixed
*/
public
function
update
(
array
$update
,
$where
)
{
return
$this
->
db
->
update
(
$this
->
table
)
->
cols
(
$update
)
->
where
(
$where
)
->
query
();
}
...
...
Application/Model/OrderModel.php
0 → 100644
View file @
ae14f02f
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/5/22
* Time: 下午2:53
*/
namespace
Application\Model
;
use
Application\Model
;
class
OrderModel
extends
Model
{
protected
$table
=
'wx_charger_order'
;
}
\ No newline at end of file
Lib/Log.php
View file @
ae14f02f
...
...
@@ -15,10 +15,9 @@ use Monolog\Logger;
/**
*
* @method static debug($info,$context = [])
* @method static warn($info,$context = [])
* @method static alert($info,$context = [])
* @method static error($info,$context = [])
* @method static warn($info, $context = [])
* @method static alert($info, $context = [])
* @method static error($info, $context = [])
*
* Class Log
* @package Lib
...
...
@@ -34,33 +33,27 @@ class Log
private
function
__construct
(
string
$logName
)
{
$this
->
log
=
new
Logger
(
$logName
);
$this
->
log
->
pushHandler
(
new
RotatingFileHandler
(
$logName
,
30
,
Env
::
get
(
'LOG_LEVEL'
)));
$this
->
log
->
pushProcessor
(
function
(
$record
){
$record
[
'extra'
][
'gateway_mac'
]
=
S_SESSION
[
'gateway_mac'
]
??
'no mac'
;
});
}
public
static
function
bootLog
(
string
$logName
=
'
error
'
)
public
static
function
bootLog
(
string
$logName
=
'
./storage/log/gateway
'
)
{
if
(
static
::
$log
instanceof
Log
)
{
if
(
static
::
$log
instanceof
Log
)
{
return
static
::
$log
;
}
else
{
}
else
{
static
::
$log
=
new
Log
(
$logName
);
static
::
$log
=
new
Log
ger
(
$logName
);
static
::
$log
->
pushHandler
(
new
RotatingFileHandler
(
$logName
,
30
,
Env
::
get
(
'LOG_LEVEL'
)));
// static::$log->pushProcessor(function ($record) {
//
// $record['extra']['gateway_mac'] = S_SESSION['gateway_mac'] ?? 'no mac';
//
// });
}
}
...
...
@@ -72,7 +65,7 @@ class Log
public
static
function
__callStatic
(
$name
,
$arguments
)
{
static
::
$log
->
$name
(
$arguments
);
return
call_user_func_array
([
static
::
$log
,
$name
],
$arguments
);
}
...
...
start.php
View file @
ae14f02f
...
...
@@ -31,7 +31,7 @@ function exceptionHandle($exception)
{
$logger
=
new
\Monolog\Logger
(
'error'
);
$logger
->
pushHandler
(
new
\Monolog\Handler\RotatingFileHandler
(
'./storage/error'
,
30
));
$logger
->
pushHandler
(
new
\Monolog\Handler\RotatingFileHandler
(
'./storage/
log/
error'
,
30
));
try
{
$logger
->
error
(
$exception
->
getMessage
(),[
...
...
@@ -65,9 +65,11 @@ foreach (glob(__DIR__ . '/Application/start*.php') as $start_file) {
}
}
require_once
$start_file
;
//
require_once $start_file;
}
\Lib\Log
::
bootLog
();
\Route\Api
::
boot
();
Worker
::
runAll
();
\ 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