diff --git a/composer.json b/composer.json index 9bed123..e9cf56c 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/composer.lock b/composer.lock index 024f793..1fc2081 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "749ac5337b052c3042060bfa3a567f57", + "content-hash": "d00f8c36be7864115ed59d670a6252f6", "packages": [ { "name": "apache/log4php", @@ -42,6 +42,243 @@ ], "abandoned": true, "time": "2012-10-26T09:13:25+00:00" + }, + { + "name": "psr/container", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "2ae37329ee82f91efadc282cc2d527fd6065a5ef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/2ae37329ee82f91efadc282cc2d527fd6065a5ef", + "reference": "2ae37329ee82f91efadc282cc2d527fd6065a5ef", + "shasum": "" + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/2.0.1" + }, + "time": "2021-03-24T13:40:57+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "topthink/think-container", + "version": "v2.0.5", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-container.git", + "reference": "2189b39e42af2c14203ed4372b92e38989e9dabb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-container/zipball/2189b39e42af2c14203ed4372b92e38989e9dabb", + "reference": "2189b39e42af2c14203ed4372b92e38989e9dabb", + "shasum": "" + }, + "require": { + "php": ">=7.2.0", + "psr/container": "^1.0|^2.0", + "topthink/think-helper": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0|^8.0" + }, + "type": "library", + "autoload": { + "files": [], + "psr-4": { + "think\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "PHP Container & Facade Manager", + "support": { + "issues": "https://github.com/top-think/think-container/issues", + "source": "https://github.com/top-think/think-container/tree/v2.0.5" + }, + "time": "2022-05-23T06:24:54+00:00" + }, + { + "name": "topthink/think-helper", + "version": "v3.1.6", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-helper.git", + "reference": "769acbe50a4274327162f9c68ec2e89a38eb2aff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-helper/zipball/769acbe50a4274327162f9c68ec2e89a38eb2aff", + "reference": "769acbe50a4274327162f9c68ec2e89a38eb2aff", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/helper.php" + ], + "psr-4": { + "think\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "yunwuxin", + "email": "448901948@qq.com" + } + ], + "description": "The ThinkPHP6 Helper Package", + "support": { + "issues": "https://github.com/top-think/think-helper/issues", + "source": "https://github.com/top-think/think-helper/tree/v3.1.6" + }, + "time": "2021-12-15T04:27:55+00:00" + }, + { + "name": "topthink/think-log", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/top-think/think-log.git", + "reference": "de0bf6644228b39f03239cdc03251040d34a7b07" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/top-think/think-log/zipball/de0bf6644228b39f03239cdc03251040d34a7b07", + "reference": "de0bf6644228b39f03239cdc03251040d34a7b07", + "shasum": "" + }, + "require": { + "php": ">=7.1.0", + "psr/log": "~1.0", + "topthink/think-container": "^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "think\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + } + ], + "description": "think log", + "support": { + "issues": "https://github.com/top-think/think-log/issues", + "source": "https://github.com/top-think/think-log/tree/v2.0.1" + }, + "time": "2019-07-07T14:47:46+00:00" } ], "packages-dev": [ @@ -2009,5 +2246,5 @@ "prefer-lowest": false, "platform": [], "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.3.0" } diff --git a/src/Service/AppLogger.php b/src/Service/AppLogger.php index 185e191..f84b92a 100644 --- a/src/Service/AppLogger.php +++ b/src/Service/AppLogger.php @@ -1,32 +1,46 @@ 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; } } \ No newline at end of file diff --git a/src/Service/Common.php b/src/Service/Common.php index 934d11e..f2ac820 100644 --- a/src/Service/Common.php +++ b/src/Service/Common.php @@ -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) @@ -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]是否存在不为空 + * */ } diff --git a/tests/Service/Helper.php b/tests/Service/Helper.php new file mode 100644 index 0000000..bfe1c3f --- /dev/null +++ b/tests/Service/Helper.php @@ -0,0 +1,23 @@ +