Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "library",
"license": "MIT",
"require": {
"apache/log4php": "2.3.0"
"apache/log4php": "2.3.0",
"topthink/think-log": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
241 changes: 239 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions src/Service/AppLogger.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
<?php

namespace App\Service;
use think\LogManager;


class AppLogger
{
const TYPE_LOG4PHP = 'log4php';
const TYPE_THINK_LOG = 'think-log';

private $logger;
private $type;

public function __construct($type = self::TYPE_LOG4PHP)
{
$this->type = $type;
if ($type == self::TYPE_LOG4PHP) {
$this->logger = \Logger::getLogger("Log");
}elseif ($type == self::TYPE_THINK_LOG){
$this->logger = new LogManager();;
}
}

public function info($message = '')
{
$this->logger->info($message);
$this->logger->info($this->msgToUpper($message));
}

public function debug($message = '')
{
$this->logger->debug($message);
$this->logger->debug($this->msgToUpper($message));
}

public function error($message = '')
{
$this->logger->error($message);
$this->logger->error($this->msgToUpper($message));
}

private function msgToUpper($message){
if($this->type == self::TYPE_THINK_LOG){
$message = strtoupper($message);
}
return $message;
}
}
16 changes: 16 additions & 0 deletions src/Service/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public function geoHelperAddress($address, $merchant_id = '')
return 0;
}
}
/* 、
代码评审
1、直接使用地址作redis的key不科学,可以用地址字符md5后做key,或者前缀加商家ID作key。
2、redis未设置过期时间,凡是缓存都需要设置过期时间以避免无用数据长期占用内存。
3、返回值不科学,可以使用状态码加数据返回
4、在使用商家ID获取到坐标后没有写进缓存
5、'-999,-999'可定义为常量
7、该方法拆分为两个方法会更优,方法一只有地址参数,根据地址返回坐标;方法二只有商家ID参数,外部先调用方法一返回失败状态码后再调用方法二
* */

// 回调状态过滤
public static function checkStatusCallback($order_id, $status)
Expand All @@ -92,4 +101,11 @@ public static function checkStatusCallback($order_id, $status)
$open_status_arr = ['901' => 1, '902' => 2, '903' => 3];
return $order_id.'-'.$open_status_arr[$status];
}
/* 、
代码评审
1、应该定义一个枚举类,解锁工作单 不回调状态码 放到一个枚举方法中
2、$open_status_arr应做成一个常量数组;
3、方法的返回值不规范,可以使用状态码加数据返回
4、$open_status_arr[$status]可能会不存在而报错,保险起见可以先判断$status和$open_status_arr[$status]是否存在不为空
* */
}
23 changes: 23 additions & 0 deletions tests/Service/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Test\Service;


class Helper
{
/**
* Note: 将二维数组的某列时间转移为时间戳
* @param $arr array 二维数组
* @param $field string 要转移列的键名
* @return array
* @Author: Wong
* @Time: 2022/8/16 23:25
*/
static function ArrConvertToTime($arr, $field = 'create_at') {

foreach ($arr as &$value) {
$value[$field] = strtotime($value[$field]);
}
return $arr;
}
}
Loading