Commit ae14f02f by BANice

日志类完善,未添加一次性写入全部日志

parent e9cf0ed4
...@@ -48,8 +48,6 @@ class AccessController extends Controller ...@@ -48,8 +48,6 @@ class AccessController extends Controller
if ($gatewayId != false) { if ($gatewayId != false) {
echo 'bind mac - '.$mac.PHP_EOL;
//tcp绑定uid //tcp绑定uid
Gateway::bindUid($this->clientId, $mac); Gateway::bindUid($this->clientId, $mac);
......
...@@ -10,6 +10,7 @@ namespace Application\Controller; ...@@ -10,6 +10,7 @@ namespace Application\Controller;
use Application\Controller; use Application\Controller;
use Application\Model\OrderModel;
class PowerController extends Controller class PowerController extends Controller
{ {
...@@ -39,6 +40,9 @@ class PowerController extends Controller ...@@ -39,6 +40,9 @@ class PowerController extends Controller
]; ];
/**
* 硬件开始充电
*/
public function charger() public function charger()
{ {
...@@ -50,6 +54,13 @@ class PowerController extends Controller ...@@ -50,6 +54,13 @@ class PowerController extends Controller
$outTradeNo = $this->get('outTradeNo'); $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 ...@@ -59,6 +70,9 @@ class PowerController extends Controller
} }
/**
* 硬件充电结束
*/
public function stop() public function stop()
{ {
...@@ -78,6 +92,9 @@ class PowerController extends Controller ...@@ -78,6 +92,9 @@ class PowerController extends Controller
} }
/**
* 上报充电功率
*/
public function power() public function power()
{ {
......
...@@ -12,6 +12,7 @@ use Lib\Crc; ...@@ -12,6 +12,7 @@ use Lib\Crc;
use GatewayWorker\Lib\Gateway; use GatewayWorker\Lib\Gateway;
use Route\Api; use Route\Api;
use Lib\Route; use Lib\Route;
use Lib\Log;
define('APP','Application\\Controller\\'); define('APP','Application\\Controller\\');
...@@ -60,11 +61,22 @@ class Events ...@@ -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) public static function onMessage($clientId,$message)
{ {
//$message = mb_strtoupper($message);
var_dump($message); var_dump($message);
...@@ -78,6 +90,7 @@ class Events ...@@ -78,6 +90,7 @@ class Events
}else{ }else{
$command = substr($message,6,2); $command = substr($message,6,2);
var_dump($command); var_dump($command);
...@@ -91,12 +104,13 @@ class Events ...@@ -91,12 +104,13 @@ class Events
$method = $route->getMethod(); $method = $route->getMethod();
$controllerName = APP.$controllerName; $controllerName = APP.$controllerName;
//去除crc字节 //去除crc字节
$message = substr($message,0,-2); $message = substr($message,0,-2);
$message = mb_strtoupper($message);
$controller = new $controllerName($clientId,$message,$command); $controller = new $controllerName($clientId,$message,$command);
$controller->$method(); $controller->$method();
......
...@@ -73,6 +73,11 @@ class Model ...@@ -73,6 +73,11 @@ class Model
} }
/**
* @param $where
* @return array
*/
public function getRow($where) public function getRow($where)
{ {
...@@ -80,6 +85,10 @@ class Model ...@@ -80,6 +85,10 @@ class Model
} }
/**
* @param array $data
* @return mixed
*/
public function insertRow(Array $data) public function insertRow(Array $data)
{ {
return $this->db->insert($this->table)->cols($data)->query(); return $this->db->insert($this->table)->cols($data)->query();
...@@ -87,6 +96,18 @@ class Model ...@@ -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();
}
......
<?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
...@@ -15,10 +15,9 @@ use Monolog\Logger; ...@@ -15,10 +15,9 @@ use Monolog\Logger;
/** /**
* *
* @method static debug($info,$context = []) * @method static warn($info, $context = [])
* @method static warn($info,$context = []) * @method static alert($info, $context = [])
* @method static alert($info,$context = []) * @method static error($info, $context = [])
* @method static error($info,$context = [])
* *
* Class Log * Class Log
* @package Lib * @package Lib
...@@ -34,33 +33,27 @@ class Log ...@@ -34,33 +33,27 @@ class Log
private function __construct(string $logName) 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; return static::$log;
}else{ } else {
static::$log = new Log($logName); static::$log = new Logger($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 ...@@ -72,7 +65,7 @@ class Log
public static function __callStatic($name, $arguments) public static function __callStatic($name, $arguments)
{ {
static::$log->$name($arguments); return call_user_func_array([static::$log,$name],$arguments);
} }
......
...@@ -31,7 +31,7 @@ function exceptionHandle($exception) ...@@ -31,7 +31,7 @@ function exceptionHandle($exception)
{ {
$logger = new \Monolog\Logger('error'); $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{ try{
$logger->error($exception->getMessage(),[ $logger->error($exception->getMessage(),[
...@@ -65,9 +65,11 @@ foreach (glob(__DIR__ . '/Application/start*.php') as $start_file) { ...@@ -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(); \Route\Api::boot();
Worker::runAll(); Worker::runAll();
\ No newline at end of file
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