提交 63957f08 编写于 作者: 李光春's avatar 李光春

- 小数门面的四舍五入方法优化

- IP信息文件调整回旧的方法
- 增加表格服务
上级 3dc3c083
## v6.0.118 / 2020-10-10
- 小数门面的四舍五入方法优化
- IP信息文件调整回旧的方法
- 增加表格服务
## v6.0.117 / 2020-09-25
- 淘宝联盟接口增加
- 小数门面增加函数
......
......@@ -25,7 +25,7 @@ use DtApp\ThinkLibrary\service\SystemService;
/**
* 定义当前版本
*/
const VERSION = '6.0.117';
const VERSION = '6.0.118';
if (!function_exists('get_ip_info')) {
/**
......
......@@ -18,8 +18,6 @@
// +----------------------------------------------------------------------
return [
// IP数据库文件存放位置
'ip_path' => app()->getRuntimePath() . 'dtapp/ip/',
// 淘宝
'taobao' => [
// 淘宝客
......
......@@ -32,7 +32,7 @@ use think\Facade;
* @mixin helper
*
* @method static int intval($num) 直接取整,舍弃小数保留整数
* @method static float round($num) 四舍五入取整
* @method static float round($num, $bl = 0) 四舍五入
* @method static false|float ceil($num) 有小数,就在整数的基础上加一
* @method static false|float floor($num) 有小数,就取整数位
* @method static bool judge($num) 判断是不是小数
......
......@@ -41,11 +41,12 @@ class Decimals
/**
* 四舍五入取整
* @param $num
* @param int $bl
* @return float
*/
public function round($num)
public function round($num, $bl = 0): float
{
return round($num);
return round($num, $bl);
}
/**
......
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Exception;
/**
* 表格服务
* Class ExcelService
* @package DtApp\ThinkLibrary\service
*/
class ExcelService extends Service
{
/**
* 头部
* @var array
*/
private $head = [];
/**
* 设置头部
* [
* [
* [
* 'index' => 1,
* 'value' => '标题'
* ],
* [
* 'index' => 2,
* 'value' => '名称'
* ]
* ],
* [
* [
* 'index' => 1,
* 'value' => '标题2'
* ],
* [
* 'index' => 2,
* 'value' => '名称2'
* ]
* ]
* ];
* @param array $head
* @return ExcelService
*/
public function setHead(array $head = []): ExcelService
{
$this->head = $head;
return $this;
}
/**
* 头部长度
* @var array
*/
private $head_length = 0;
/**
* 设置头部长度
* @param int $length
* @return ExcelService
*/
public function setHeadLength(int $length = 0): ExcelService
{
$this->head_length = $length;
return $this;
}
/**
* 内容
* @var array
*/
private $content = [];
/**
* 设置内容
* [
* [
* [
* 'index' => 1,
* 'value' => '标题'
* ],
* [
* 'index' => 2,
* 'value' => '名称'
* ]
* ],
* [
* [
* 'index' => 1,
* 'value' => '标题2'
* ],
* [
* 'index' => 2,
* 'value' => '名称2'
* ]
* ]
* ];
* @param array $content
* @return ExcelService
*/
public function setContent(array $content = []): ExcelService
{
$this->content = $content;
return $this;
}
/**
* 文件名
* @var string
*/
private $file_name = '';
/**
* 设置文件名(不需要后缀名)
* @param string $file_name
* @return $this
*/
public function setFileName(string $file_name = ''): self
{
$this->file_name = $file_name;
return $this;
}
/**
* 生成表格文件
* @return string
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws Exception
*/
public function generate(): string
{
// 生成表格
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
if (empty($this->head)) {
throw new Exception('头部内容未设置!');
}
if (empty($this->head_length)) {
throw new Exception('头部长度未设置!');
}
if (empty($this->file_name)) {
throw new Exception('文件保存路径未设置!');
}
//设置工作表标题名称
//设置单元格内容
foreach ($this->head as $key => $value) {
foreach ($value as $k => $v) {
$sheet->setCellValueByColumnAndRow($v['index'], $key + 1, $v['value']);
}
}
foreach ($this->content as $key => $value) {
foreach ($value as $k => $v) {
$sheet->setCellValueByColumnAndRow($v['index'], $key + $this->head_length, $v['value']);
}
}
$writer = new Xlsx($spreadsheet);
$writer->save("{$this->file_name}.xlsx");
return "{$this->file_name}.xlsx";
}
}
\ No newline at end of file
......@@ -19,7 +19,6 @@
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use Exception;
use think\App;
......@@ -36,12 +35,6 @@ class IpIpService extends Service
*/
public $reader;
/**
* IP数据库文件存放位置
* @var mixed
*/
private $ipPath;
/**
* IpIpService constructor.
* @param App $app
......@@ -49,11 +42,7 @@ class IpIpService extends Service
*/
public function __construct(App $app)
{
$this->ipPath = config('dtapp.ip_path', '');
if (empty($this->ipPath)) {
throw new DtaException('请检查配置文件是否配置了IP数据库文件存放位置');
}
$this->reader = new IpIpReader($this->ipPath . 'ipipfree.ipdb');
$this->reader = new IpIpReader(__DIR__ . '../bin/ipipfree.ipdb');
parent::__construct($app);
}
......
......@@ -61,25 +61,14 @@ class QqWryService extends Service
*/
private $unknown = '未知';
/**
* IP数据库文件存放位置
* @var mixed
*/
private $ipPath;
/**
* 构造函数,打开 QQWry.Dat 文件并初始化类中的信息
* @param App $app
* @throws DtaException
*/
public function __construct(App $app)
{
$this->ipPath = config('dtapp.ip_path', '');
if (empty($this->ipPath)) {
throw new DtaException('请检查配置文件是否配置了IP数据库文件存放位置');
}
$this->fp = 0;
if (($this->fp = fopen($this->ipPath . 'qqwry.dat', 'rb')) !== false) {
if (($this->fp = fopen(__DIR__ . '/bin/qqwry.dat', 'rb')) !== false) {
$this->firstIp = $this->getLong();
$this->lastIp = $this->getLong();
$this->totalIp = ($this->lastIp - $this->firstIp) / 7;
......@@ -425,7 +414,7 @@ class QqWryService extends Service
$district['lng'] = '';
if (!empty($province_name)) {
$json_province = json_decode(file_get_contents($this->ipPath . 'province.json'), true);
$json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true);
foreach ($json_province['rows'] as $key => $value) {
if ($value['name'] == $province_name) {
$province['name'] = $value['name'];
......@@ -436,7 +425,7 @@ class QqWryService extends Service
}
}
if (!empty($city_name)) {
$json_city = json_decode(file_get_contents($this->ipPath . 'city.json'), true);
$json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true);
foreach ($json_city['rows'] as $key => $value) {
if ($value['name'] == $city_name) {
$city['name'] = $value['name'];
......@@ -447,7 +436,7 @@ class QqWryService extends Service
}
}
if (!empty($district_name)) {
$json_district = json_decode(file_get_contents($this->ipPath . 'district.json'), true);
$json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true);
foreach ($json_district['rows'] as $key => $value) {
if ($value['name'] == $district_name) {
$district['name'] = $value['name'];
......
此差异已折叠。
此差异已折叠。
{
"rows": [
{
"adcode": "360000",
"people_count_2010": 43976312,
"lat": 28.676493,
"lng": 115.892151,
"name": "江西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "410000",
"people_count_2010": 96486884,
"lat": 34.757975,
"lng": 113.665412,
"name": "河南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "510000",
"people_count_2010": 85974759,
"lat": 30.659462,
"lng": 104.065735,
"name": "四川省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "500000",
"people_count_2010": 28458101,
"lat": 29.533155,
"lng": 106.504962,
"name": "重庆市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "540000",
"people_count_2010": 2554907,
"lat": 29.660361,
"lng": 91.132212,
"name": "西藏自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "520000",
"people_count_2010": 25119376,
"lat": 26.578343,
"lng": 106.713478,
"name": "贵州省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "210000",
"people_count_2010": 43149614,
"lat": 41.796767,
"lng": 123.429096,
"name": "辽宁省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "650000",
"people_count_2010": 29070614,
"lat": 43.792818,
"lng": 87.617733,
"name": "新疆维吾尔自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "370000",
"people_count_2010": 94646230,
"lat": 36.675807,
"lng": 117.000923,
"name": "山东省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "310000",
"people_count_2010": 21135161,
"lat": 31.231706,
"lng": 121.472644,
"name": "上海市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "820000",
"people_count_2010": null,
"lat": 22.198951,
"lng": 113.54909,
"name": "澳門特別行政區",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "140000",
"people_count_2010": 34364492,
"lat": 37.857014,
"lng": 112.549248,
"name": "山西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "330000",
"people_count_2010": 53807755,
"lat": 30.287459,
"lng": 120.153576,
"name": "浙江省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "460000",
"people_count_2010": 42028870,
"lat": 20.031971,
"lng": 110.33119,
"name": "海南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "350000",
"people_count_2010": 39026582,
"lat": 26.075302,
"lng": 119.306239,
"name": "福建省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "630000",
"people_count_2010": 5619543,
"lat": 36.623178,
"lng": 101.778916,
"name": "青海省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "640000",
"people_count_2010": 6466366,
"lat": 38.46637,
"lng": 106.278179,
"name": "宁夏回族自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "420000",
"people_count_2010": 62160766,
"lat": 30.584355,
"lng": 114.298572,
"name": "湖北省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "620000",
"people_count_2010": 27957557,
"lat": 36.058039,
"lng": 103.823557,
"name": "甘肃省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "340000",
"people_count_2010": 57217014,
"lat": 31.86119,
"lng": 117.283042,
"name": "安徽省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "710000",
"people_count_2010": null,
"lat": 25.044332,
"lng": 121.509062,
"name": "台湾省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "610000",
"people_count_2010": 35876998,
"lat": 34.263161,
"lng": 108.948024,
"name": "陕西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "450000",
"people_count_2010": 47082115,
"lat": 22.82402,
"lng": 108.320004,
"name": "广西壮族自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "120000",
"people_count_2010": 15298136,
"lat": 39.125596,
"lng": 117.190182,
"name": "天津市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "530000",
"people_count_2010": 72840959,
"lat": 25.040609,
"lng": 102.712251,
"name": "云南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "230000",
"people_count_2010": 40734477,
"lat": 45.756967,
"lng": 126.642464,
"name": "黑龙江省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "440000",
"people_count_2010": 107131199,
"lat": 23.125178,
"lng": 113.280637,
"name": "广东省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "430000",
"people_count_2010": 67158313,
"lat": 28.19409,
"lng": 112.982279,
"name": "湖南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "130000",
"people_count_2010": 106816280,
"lat": 38.045474,
"lng": 114.502461,
"name": "河北省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "150000",
"people_count_2010": 26353789,
"lat": 40.818311,
"lng": 111.670801,
"name": "内蒙古自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "220000",
"people_count_2010": 26423220,
"lat": 43.886841,
"lng": 125.3245,
"name": "吉林省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "320000",
"people_count_2010": 79104628,
"lat": 32.041544,
"lng": 118.767413,
"name": "江苏省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "110000",
"people_count_2010": 18934592,
"lat": 39.904989,
"lng": 116.405285,
"name": "北京市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "810000",
"people_count_2010": null,
"lat": 22.320048,
"lng": 114.173355,
"name": "香港特別行政區",
"level": "province",
"parent": "中华人民共和国"
}
],
"total": 34
}
......@@ -35,6 +35,7 @@ class MiniService extends Service
* @var
*/
private $app_id, $app_secret;
/**
* @var string
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册