chore(src): 所有代码上传

This commit is contained in:
2025-12-02 15:36:42 +08:00
parent ce8e59902c
commit eb79ad260c
669 changed files with 86838 additions and 87639 deletions

66
src/extend/BaiDuApi.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
namespace extend;
class BaiDuApi
{
protected $apiKey = '';
protected $secretKey = '';
const tokenUrl = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=%s&client_secret=%s';
const splitUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer?access_token=%s&charset=UTF-8';
public function __construct($config = [])
{
$this->apiKey = $config['apiKey'] ?? '';
$this->secretKey = $config['secretKey'] ?? '';
}
/**
* 获取token
*/
public function getAccessToken() {
$url = sprintf(self::tokenUrl,$this->apiKey,$this->secretKey);
$data = file_get_contents($url);
$resData = json_decode($data,true);
if(!empty($resData['access_token'])) {
// 成功
return ['error' => 0,'msg' => '获取数据成功','access_token' => $resData['access_token']];
}else {
return $resData;
}
}
public function request($keyword) {
$data = $this->getAccessToken();
if($data['error'] == 0) {
$accessToken = $data['access_token'];
}else {
return $data;
}
$url = sprintf(self::splitUrl,$accessToken);
$data = http_url($url,json_encode(['text' => $keyword]),['Content-Type' => 'application/json']);
return json_decode($data,true);
}
/**
* 获取所有的拆词
* @param $keyword
* @return array|mixed|void
*/
public function splitWords($keyword) {
$result = $this->request($keyword);
if(!is_array($result) || empty($result['items'])){
return [];
}
$wordList = [];
foreach ($result['items'] as $val) {
foreach ($val['basic_words'] as $v) {
$wordList[] = $v;
}
}
return $wordList;
}
}

View File

@@ -1,280 +1,272 @@
<?php
/**
*/
namespace extend;
/**
* 文件处理
* @author Administrator
*
*/
class File
{
/**
* 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
*
* @param string $file 文件/目录
* @return boolean
*/
public function is_write($file)
{
if (is_dir($file)) {
$dir = $file;
if ($fp = @fopen("$dir/test.txt", 'w')) {
@fclose($fp);
@unlink("$dir/test.txt");
$writeable = true;
} else {
$writeable = false;
}
} else {
if ($fp = @fopen($file, 'a+')) {
@fclose($fp);
$writeable = true;
} else {
$writeable = false;
}
}
return $writeable;
}
/**
* 文件尺寸大小
* @param unknown $dir
* @return number
*/
public function get_dir_size($dir_path)
{
$size = 0;
if (is_dir($dir_path)) {
$handle = opendir($dir_path);
while (false !== ( $entry = readdir($handle) )) {
if ($entry != '.' && $entry != '..') {
if (is_dir("{$dir_path}/{$entry}")) {
$size += get_dir_size("{$dir_path}/{$entry}");
} else {
$size += filesize("{$dir_path}/{$entry}");
}
}
}
closedir($handle);
}
return $size;
}
/**
* 文件尺寸大小换算
* @param unknown $size
* @return string
*/
public function size_conversion($size_num)
{
switch ( $size_num ) {
case $size_num >= 1073741824:
$size_str = round($size_num / 1073741824 * 100) / 100 . ' GB';
break;
case $size_num >= 1048576:
$size_str = round($size_num / 1048576 * 100) / 100 . ' MB';
break;
case $size_num >= 1024:
$size_str = round($size_num / 1024 * 100) / 100 . ' KB';
break;
default:
$size_str = $size_num . ' Bytes';
break;
}
return $size_str;
}
/**
* 删除指定目录下的文件和文件夹
* @param unknown $dirpath
* @return boolean
*/
public function del_dir($dirpath)
{
$dh = opendir($dirpath);
while (( $file = readdir($dh) ) !== false) {
if ($file != "." && $file != "..") {
$fullpath = $dirpath . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
} else {
$this->del_dir($fullpath);
rmdir($fullpath);
}
}
}
closedir($dh);
$isEmpty = true;
$dh = opendir($dirpath);
while (( $file = readdir($dh) ) !== false) {
if ($file != "." && $file != "..") {
$isEmpty = false;
break;
}
}
return $isEmpty;
}
/**
* 文件强制下载
* @param unknown $dir
*/
public function dir_readfile($dir)
{
if (file_exists($dir)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($dir));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($dir));
ob_clean();
flush();
readfile($dir);
}
}
/**
* 压缩文件夹
* @param unknown $dir
* @param unknown $zipfile
*/
public function zip_dir($dir, $zipfile, $newdir = '')
{
$zip = new ZipArchive();
if ($zip->open($zipfile, ZipArchive::CREATE) === TRUE) {
add_file_toZip($dir, $zip, $newdir); //调用方法对要打包的根目录进行操作并将ZipArchive的对象传递给方法
$zip->close(); //关闭处理的zip文件
}
}
/**
* 读取文件单文件压缩 zipdir方法调用
* @param unknown $dir
* @param unknown $zip
*/
public function add_file_toZip($dir, $zip, $newdir = '')
{
$handler = opendir($dir); //打开当前文件夹由$dir指定
$filename = readdir($handler);
while (( $filename = readdir($handler) ) !== false) {
if ($filename != "." && $filename != "..") {//文件夹文件名字为'.'和‘..',不要对他们进行操作
if (is_dir($dir . '/' . $filename)) {// 如果读取的某个对象是文件夹,则递归
$this->add_file_toZip($dir . "/" . $filename, $zip, $newdir);
} else { //将文件加入zip对象
$new_dir_sep = substr($dir, strpos($dir, $newdir));
$zip->addFile($dir . "/" . $filename, $new_dir_sep . '/' . $filename);
}
}
}
@closedir($dir);
}
/**
* 将读取到的目录以数组的形式展现出来
* @param array $files 所有的文件条目的存放数组
* @param string $file 返回的文件条目
* @param string $dir 文件的路径
* @param resource $handle 打开的文件目录句柄
* @return array
* opendir() 函数打开一个目录句柄,可由 closedir()readdir() 和 rewinddir() 使用。
* is_dir() 函数检查指定的文件是否是目录。
* readdir() 函数返回由 opendir() 打开目录句柄中的条目。
*/
public function dir_scan($dir)
{
//定义一个数组
$files = array ();
//检测是否存在文件
if (is_dir($dir)) {
//打开目录
if ($handle = opendir($dir)) {
//返回当前文件的条目
while (( $file = readdir($handle) ) !== false) {
//去除特殊目录
if ($file != "." && $file != "..") {
//判断子目录是否还存在子目录
if (is_dir($dir . "/" . $file)) {
//递归调用本函数,再次获取目录
$files[ $file ] = dir_scan($dir . "/" . $file);
} else {
//获取目录数组
$files[] = $file;
}
}
}
//关闭文件夹
closedir($handle);
//返回文件夹数组
return $files;
}
}
}
/**
* 创建文件夹
*
* @param string $path 文件夹路径
* @param int $mode 访问权限
* @param bool $recursive 是否递归创建
* @return bool
*/
public function dir_mkdir($path = '', $mode = 0777, $recursive = true)
{
clearstatcache();
if (!is_dir($path)) {
mkdir($path, $mode, $recursive);
return chmod($path, $mode);
}
return true;
}
/**
* 文件夹文件拷贝
*
* @param string $src 来源文件夹
* @param string $dst 目的地文件夹
* @return bool
*/
public function dir_copy($src = '', $dst = '')
{
if (empty($src) || empty($dst)) {
return false;
}
$dir = opendir($src);
$this->dir_mkdir($dst);
while (false !== ( $file = readdir($dir) )) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($src . '/' . $file)) {
$this->dir_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
return true;
}
<?php
namespace extend;
/**
* 文件处理
* @author Administrator
*
*/
class File
{
/**
* 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
*
* @param string $file 文件/目录
* @return boolean
*/
public function is_write($file)
{
if (is_dir($file)) {
$dir = $file;
if ($fp = @fopen("$dir/test.txt", 'w')) {
@fclose($fp);
@unlink("$dir/test.txt");
$writeable = true;
} else {
$writeable = false;
}
} else {
if ($fp = @fopen($file, 'a+')) {
@fclose($fp);
$writeable = true;
} else {
$writeable = false;
}
}
return $writeable;
}
/**
* 文件尺寸大小
* @param unknown $dir
* @return number
*/
public function get_dir_size($dir_path)
{
$size = 0;
if (is_dir($dir_path)) {
$handle = opendir($dir_path);
while (false !== ( $entry = readdir($handle) )) {
if ($entry != '.' && $entry != '..') {
if (is_dir("{$dir_path}/{$entry}")) {
$size += get_dir_size("{$dir_path}/{$entry}");
} else {
$size += filesize("{$dir_path}/{$entry}");
}
}
}
closedir($handle);
}
return $size;
}
/**
* 文件尺寸大小换算
* @param unknown $size
* @return string
*/
public function size_conversion($size_num)
{
switch ( $size_num ) {
case $size_num >= 1073741824:
$size_str = round($size_num / 1073741824 * 100) / 100 . ' GB';
break;
case $size_num >= 1048576:
$size_str = round($size_num / 1048576 * 100) / 100 . ' MB';
break;
case $size_num >= 1024:
$size_str = round($size_num / 1024 * 100) / 100 . ' KB';
break;
default:
$size_str = $size_num . ' Bytes';
break;
}
return $size_str;
}
/**
* 删除指定目录下的文件和文件夹
* @param unknown $dirpath
* @return boolean
*/
public function del_dir($dirpath)
{
$dh = opendir($dirpath);
while (( $file = readdir($dh) ) !== false) {
if ($file != "." && $file != "..") {
$fullpath = $dirpath . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
} else {
$this->del_dir($fullpath);
rmdir($fullpath);
}
}
}
closedir($dh);
$isEmpty = true;
$dh = opendir($dirpath);
while (( $file = readdir($dh) ) !== false) {
if ($file != "." && $file != "..") {
$isEmpty = false;
break;
}
}
return $isEmpty;
}
/**
* 文件强制下载
* @param unknown $dir
*/
public function dir_readfile($dir)
{
if (file_exists($dir)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($dir));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($dir));
ob_clean();
flush();
readfile($dir);
}
}
/**
* 压缩文件夹
* @param unknown $dir
* @param unknown $zipfile
*/
public function zip_dir($dir, $zipfile, $newdir = '')
{
$zip = new ZipArchive();
if ($zip->open($zipfile, ZipArchive::CREATE) === TRUE) {
add_file_toZip($dir, $zip, $newdir); //调用方法对要打包的根目录进行操作并将ZipArchive的对象传递给方法
$zip->close(); //关闭处理的zip文件
}
}
/**
* 读取文件单文件压缩 zipdir方法调用
* @param unknown $dir
* @param unknown $zip
*/
public function add_file_toZip($dir, $zip, $newdir = '')
{
$handler = opendir($dir); //打开当前文件夹由$dir指定
$filename = readdir($handler);
while (( $filename = readdir($handler) ) !== false) {
if ($filename != "." && $filename != "..") {//文件夹文件名字为'.'和‘..',不要对他们进行操作
if (is_dir($dir . '/' . $filename)) {// 如果读取的某个对象是文件夹,则递归
$this->add_file_toZip($dir . "/" . $filename, $zip, $newdir);
} else { //将文件加入zip对象
$new_dir_sep = substr($dir, strpos($dir, $newdir));
$zip->addFile($dir . "/" . $filename, $new_dir_sep . '/' . $filename);
}
}
}
@closedir($dir);
}
/**
* 将读取到的目录以数组的形式展现出来
* @param array $files 所有的文件条目的存放数组
* @param string $file 返回的文件条目
* @param string $dir 文件的路径
* @param resource $handle 打开的文件目录句柄
* @return array
* opendir() 函数打开一个目录句柄,可由 closedir()readdir() 和 rewinddir() 使用。
* is_dir() 函数检查指定的文件是否是目录。
* readdir() 函数返回由 opendir() 打开的目录句柄中的条目。
*/
public function dir_scan($dir)
{
//定义一个数组
$files = array ();
//检测是否存在文件
if (is_dir($dir)) {
//打开目录
if ($handle = opendir($dir)) {
//返回当前文件的条目
while (( $file = readdir($handle) ) !== false) {
//去除特殊目录
if ($file != "." && $file != "..") {
//判断子目录是否存在子目录
if (is_dir($dir . "/" . $file)) {
//递归调用本函数,再次获取目录
$files[ $file ] = dir_scan($dir . "/" . $file);
} else {
//获取目录数组
$files[] = $file;
}
}
}
//关闭文件夹
closedir($handle);
//返回文件夹数组
return $files;
}
}
}
/**
* 创建文件夹
*
* @param string $path 文件夹路径
* @param int $mode 访问权限
* @param bool $recursive 是否递归创建
* @return bool
*/
public function dir_mkdir($path = '', $mode = 0777, $recursive = true)
{
clearstatcache();
if (!is_dir($path)) {
mkdir($path, $mode, $recursive);
return chmod($path, $mode);
}
return true;
}
/**
* 文件夹文件拷贝
*
* @param string $src 来源文件夹
* @param string $dst 目的地文件夹
* @return bool
*/
public function dir_copy($src = '', $dst = '')
{
if (empty($src) || empty($dst)) {
return false;
}
$dir = opendir($src);
$this->dir_mkdir($dst);
while (false !== ( $file = readdir($dir) )) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($src . '/' . $file)) {
$this->dir_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
return true;
}
}

View File

@@ -1,292 +1,284 @@
<?php
/**
*/
namespace extend;
use Carbon\Carbon;
/**
* 文件处理
* @author Administrator
*
*/
class Stat
{
private $json_stat = [
'stat_shop' => [
'site_id' => 1,
'year' => 0,
'month' => 0,
'day' => 0,
'day_time' => 0,
'order_total' => 0.00,
'shipping_total' => 0.00,
'refund_total' => 0.00,
'order_pay_count' => 0,
'goods_pay_count' => 0,
'shop_money' => 0,
'platform_money' => 0,
'create_time' => 0,
'modify_time' => 0,
'collect_shop' => 0,
'collect_goods' => 0,
'visit_count' => 0,
'order_count' => 0,
'goods_count' => 0,
'add_goods_count' => 0,
'member_count' => 0,
'order_member_count' => 0,
'order_refund_count' => 0,
'order_refund_grand_count' => 0,
'order_refund_grand_total_money' => 0.00,
'coupon_member_count' => 0,
'member_level_count' => 0,
'member_level_total_money' => 0.00,
'member_level_grand_count' => 0,
'member_level_grand_total_money' => 0.00,
'member_recharge_count' => 0,
'member_recharge_grand_count' => 0.00,
'member_recharge_total_money'=> 0.00,
'member_recharge_grand_total_money' => 0.00,
'member_recharge_member_count' => 0,
'member_giftcard_count' => 0,
'member_giftcard_grand_count' => 0,
'member_giftcard_total_money' => 0.00,
'h5_visit_count' => 0,
'wechat_visit_count' => 0,
'weapp_visit_count' => 0,
'pc_visit_count' => 0,
'expected_earnings_total_money' => 0.00,
'expenditure_total_money' => 0.00,
'earnings_total_money' => 0.00,
'member_withdraw_count' => 0,
'member_withdraw_total_money' => 0.00,
'coupon_count' => 0,
'add_coupon_count' => 0,
'order_pay_money' => 0.00,
'add_fenxiao_member_count' => 0,
'fenxiao_order_total_money' => 0.00,
'fenxiao_order_count' => 0,
'goods_on_type_count' => 0,
'goods_visited_type_count' => 0,
'goods_order_type_count' => 0,
'goods_exposure_count' => 0,
'goods_visit_count' => 0,
'goods_visit_member_count' => 0,
'goods_cart_count' => 0,
'goods_order_count' => 0.000,
'order_create_money' => 0.00,
'order_create_count' => 0,
'balance_deduction' => 0.00,
'cashier_billing_count' => 0,
'cashier_billing_money' => 0.00,
'cashier_buycard_count' => 0,
'cashier_buycard_money' => 0.00,
'cashier_recharge_count' => 0,
'cashier_recharge_money' => 0.00,
'cashier_refund_count' => 0,
'cashier_refund_money' => 0.00,
'cashier_order_member_count' => 0,
'cashier_balance_money' => 0.00,
'cashier_online_pay_money' => 0.00,
'cashier_online_refund_money' => 0.00,
'cashier_balance_deduction' => 0.00
],
'stat_shop_hour' => [
'site_id' => 1,
'year' => 0,
'month' => 0,
'day' => 0,
'hour' => 0,
'day_time' => 0,
'order_total' => 0.00,
'shipping_total' => 0.00,
'refund_total' => 0.00,
'order_pay_count' => 0,
'goods_pay_count' => 0,
'shop_money' => 0,
'platform_money' => 0,
'create_time' => 0,
'modify_time' => 0,
'collect_shop' => 0,
'collect_goods' => 0,
'visit_count' => 0,
'order_count' => 0,
'goods_count' => 0,
'add_goods_count' => 0,
'member_count' => 0,
'order_member_count' => 0,
'order_refund_count' => 0,
'order_refund_grand_count' => 0,
'order_refund_grand_total_money' => 0.00,
'coupon_member_count' => 0,
'member_level_count' => 0,
'member_level_total_money' => 0.00,
'member_level_grand_count' => 0,
'member_level_grand_total_money' => 0.00,
'member_recharge_count' => 0,
'member_recharge_grand_count' => 0.00,
'member_recharge_total_money'=> 0.00,
'member_recharge_grand_total_money' => 0.00,
'member_recharge_member_count' => 0,
'member_giftcard_count' => 0,
'member_giftcard_grand_count' => 0,
'member_giftcard_total_money' => 0.00,
'h5_visit_count' => 0,
'wechat_visit_count' => 0,
'weapp_visit_count' => 0,
'pc_visit_count' => 0,
'expected_earnings_total_money' => 0.00,
'expenditure_total_money' => 0.00,
'earnings_total_money' => 0.00,
'member_withdraw_count' => 0,
'member_withdraw_total_money' => 0.00,
'coupon_count' => 0,
'add_coupon_count' => 0,
'order_pay_money' => 0.00,
'add_fenxiao_member_count' => 0,
'fenxiao_order_total_money' => 0.00,
'fenxiao_order_count' => 0,
'goods_on_type_count' => 0,
'goods_visited_type_count' => 0,
'goods_order_type_count' => 0,
'goods_exposure_count' => 0,
'goods_visit_count' => 0,
'goods_visit_member_count' => 0,
'goods_cart_count' => 0,
'goods_order_count' => 0.000,
'order_create_money' => 0.00,
'order_create_count' => 0,
'balance_deduction' => 0.00,
'cashier_billing_count' => 0,
'cashier_billing_money' => 0.00,
'cashier_buycard_count' => 0,
'cashier_buycard_money' => 0.00,
'cashier_recharge_count' => 0,
'cashier_recharge_money' => 0.00,
'cashier_refund_count' => 0,
'cashier_refund_money' => 0.00,
'cashier_order_member_count' => 0,
'cashier_balance_money' => 0.00,
'cashier_online_pay_money' => 0.00,
'cashier_online_refund_money' => 0.00,
'cashier_balance_deduction' => 0.00
],
'stat_store' => [
'site_id' => 1,
'store_id' => 0,
'year' => 0,
'month' => 0,
'day' => 0,
'day_time' => 0,
'billing_count' => 0,
'billing_money' => 0.00,
'buycard_count' => 0,
'buycard_money' => 0.00,
'recharge_count' => 0,
'recharge_money' => 0.00,
'refund_count' => 0,
'refund_money' => 0.00,
'order_member_count' => 0,
'balance_money' => 0.00,
'online_pay_money' => 0.00,
'online_refund_money' => 0.00,
'balance_deduction' => 0.00,
],
'stat_store_hour' => [
'site_id' => 1,
'store_id' => 0,
'year' => 0,
'month' => 0,
'day' => 0,
'hour' => 0,
'day_time' => 0,
'billing_count' => 0,
'billing_money' => 0.00,
'buycard_count' => 0,
'buycard_money' => 0.00,
'recharge_count' => 0,
'recharge_money' => 0.00,
'refund_count' => 0,
'refund_money' => 0.00,
'order_member_count' => 0,
'balance_money' => 0.00,
'online_pay_money' => 0.00,
'online_refund_money' => 0.00,
'balance_deduction' => 0.00,
]
];
private $filename;
private $json_date;
private $site_id;
public function __construct($filename, $type,$site_id = 1) {
// file_put_contents(__DIR__ . '/debug.txt', var_export($site_id,true).PHP_EOL,FILE_APPEND);
$this->filename = $filename;
$this->json_stat['stat_shop']['site_id'] = $site_id;
$this->json_stat['stat_shop_hour']['site_id'] = $site_id;
$this->json_date = $this->json_stat[$type];
}
/**
* 不存在文件,创建
*/
public function check()
{
if(!file_exists($this->filename)){
}else{
}
}
/**
* 储存文件
* @param $data
*/
public function saveFile($data) {
$jsonData = json_encode($data);
while (!empty(cache($this->filename."_lock"))){}
cache($this->filename."_lock", 1);
//修改内容
file_put_contents($this->filename, $jsonData);
cache($this->filename."_lock", 0);
}
/**
* 读取文件
* @return mixed
*/
public function load() {
$jsonData = file_get_contents($this->filename);
$data = json_decode($jsonData, true);
return $data;
}
/**
* 数据处理
* @param $data
*/
public function handleData($data)
{
$file_data = $this->json_date;
foreach ($data as $key => $val){
$file_data[$key] = $val;
}
$carbon = Carbon::now();
$file_data['year'] = $carbon->year;
$file_data['month'] = $carbon->month;
$file_data['day'] = $carbon->day;
$file_data['day_time'] = time();
if (isset($file_data['hour'])) $file_data['hour'] = $carbon->hour;
$this->saveFile($file_data);
}
<?php
namespace extend;
use Carbon\Carbon;
/**
* 文件处理
* @author Administrator
*
*/
class Stat
{
private $json_stat = [
'stat_shop' => [
'site_id' => 1,
'year' => 0,
'month' => 0,
'day' => 0,
'day_time' => 0,
'order_total' => 0.00,
'shipping_total' => 0.00,
'refund_total' => 0.00,
'order_pay_count' => 0,
'goods_pay_count' => 0,
'shop_money' => 0,
'platform_money' => 0,
'create_time' => 0,
'modify_time' => 0,
'collect_shop' => 0,
'collect_goods' => 0,
'visit_count' => 0,
'order_count' => 0,
'goods_count' => 0,
'add_goods_count' => 0,
'member_count' => 0,
'order_member_count' => 0,
'order_refund_count' => 0,
'order_refund_grand_count' => 0,
'order_refund_grand_total_money' => 0.00,
'coupon_member_count' => 0,
'member_level_count' => 0,
'member_level_total_money' => 0.00,
'member_level_grand_count' => 0,
'member_level_grand_total_money' => 0.00,
'member_recharge_count' => 0,
'member_recharge_grand_count' => 0.00,
'member_recharge_total_money'=> 0.00,
'member_recharge_grand_total_money' => 0.00,
'member_recharge_member_count' => 0,
'member_giftcard_count' => 0,
'member_giftcard_grand_count' => 0,
'member_giftcard_total_money' => 0.00,
'h5_visit_count' => 0,
'wechat_visit_count' => 0,
'weapp_visit_count' => 0,
'pc_visit_count' => 0,
'expected_earnings_total_money' => 0.00,
'expenditure_total_money' => 0.00,
'earnings_total_money' => 0.00,
'member_withdraw_count' => 0,
'member_withdraw_total_money' => 0.00,
'coupon_count' => 0,
'add_coupon_count' => 0,
'order_pay_money' => 0.00,
'add_fenxiao_member_count' => 0,
'fenxiao_order_total_money' => 0.00,
'fenxiao_order_count' => 0,
'goods_on_type_count' => 0,
'goods_visited_type_count' => 0,
'goods_order_type_count' => 0,
'goods_exposure_count' => 0,
'goods_visit_count' => 0,
'goods_visit_member_count' => 0,
'goods_cart_count' => 0,
'goods_order_count' => 0.000,
'order_create_money' => 0.00,
'order_create_count' => 0,
'balance_deduction' => 0.00,
'cashier_billing_count' => 0,
'cashier_billing_money' => 0.00,
'cashier_buycard_count' => 0,
'cashier_buycard_money' => 0.00,
'cashier_recharge_count' => 0,
'cashier_recharge_money' => 0.00,
'cashier_refund_count' => 0,
'cashier_refund_money' => 0.00,
'cashier_order_member_count' => 0,
'cashier_balance_money' => 0.00,
'cashier_online_pay_money' => 0.00,
'cashier_online_refund_money' => 0.00,
'cashier_balance_deduction' => 0.00
],
'stat_shop_hour' => [
'site_id' => 1,
'year' => 0,
'month' => 0,
'day' => 0,
'hour' => 0,
'day_time' => 0,
'order_total' => 0.00,
'shipping_total' => 0.00,
'refund_total' => 0.00,
'order_pay_count' => 0,
'goods_pay_count' => 0,
'shop_money' => 0,
'platform_money' => 0,
'create_time' => 0,
'modify_time' => 0,
'collect_shop' => 0,
'collect_goods' => 0,
'visit_count' => 0,
'order_count' => 0,
'goods_count' => 0,
'add_goods_count' => 0,
'member_count' => 0,
'order_member_count' => 0,
'order_refund_count' => 0,
'order_refund_grand_count' => 0,
'order_refund_grand_total_money' => 0.00,
'coupon_member_count' => 0,
'member_level_count' => 0,
'member_level_total_money' => 0.00,
'member_level_grand_count' => 0,
'member_level_grand_total_money' => 0.00,
'member_recharge_count' => 0,
'member_recharge_grand_count' => 0.00,
'member_recharge_total_money'=> 0.00,
'member_recharge_grand_total_money' => 0.00,
'member_recharge_member_count' => 0,
'member_giftcard_count' => 0,
'member_giftcard_grand_count' => 0,
'member_giftcard_total_money' => 0.00,
'h5_visit_count' => 0,
'wechat_visit_count' => 0,
'weapp_visit_count' => 0,
'pc_visit_count' => 0,
'expected_earnings_total_money' => 0.00,
'expenditure_total_money' => 0.00,
'earnings_total_money' => 0.00,
'member_withdraw_count' => 0,
'member_withdraw_total_money' => 0.00,
'coupon_count' => 0,
'add_coupon_count' => 0,
'order_pay_money' => 0.00,
'add_fenxiao_member_count' => 0,
'fenxiao_order_total_money' => 0.00,
'fenxiao_order_count' => 0,
'goods_on_type_count' => 0,
'goods_visited_type_count' => 0,
'goods_order_type_count' => 0,
'goods_exposure_count' => 0,
'goods_visit_count' => 0,
'goods_visit_member_count' => 0,
'goods_cart_count' => 0,
'goods_order_count' => 0.000,
'order_create_money' => 0.00,
'order_create_count' => 0,
'balance_deduction' => 0.00,
'cashier_billing_count' => 0,
'cashier_billing_money' => 0.00,
'cashier_buycard_count' => 0,
'cashier_buycard_money' => 0.00,
'cashier_recharge_count' => 0,
'cashier_recharge_money' => 0.00,
'cashier_refund_count' => 0,
'cashier_refund_money' => 0.00,
'cashier_order_member_count' => 0,
'cashier_balance_money' => 0.00,
'cashier_online_pay_money' => 0.00,
'cashier_online_refund_money' => 0.00,
'cashier_balance_deduction' => 0.00
],
'stat_store' => [
'site_id' => 1,
'store_id' => 0,
'year' => 0,
'month' => 0,
'day' => 0,
'day_time' => 0,
'billing_count' => 0,
'billing_money' => 0.00,
'buycard_count' => 0,
'buycard_money' => 0.00,
'recharge_count' => 0,
'recharge_money' => 0.00,
'refund_count' => 0,
'refund_money' => 0.00,
'order_member_count' => 0,
'balance_money' => 0.00,
'online_pay_money' => 0.00,
'online_refund_money' => 0.00,
'balance_deduction' => 0.00,
],
'stat_store_hour' => [
'site_id' => 1,
'store_id' => 0,
'year' => 0,
'month' => 0,
'day' => 0,
'hour' => 0,
'day_time' => 0,
'billing_count' => 0,
'billing_money' => 0.00,
'buycard_count' => 0,
'buycard_money' => 0.00,
'recharge_count' => 0,
'recharge_money' => 0.00,
'refund_count' => 0,
'refund_money' => 0.00,
'order_member_count' => 0,
'balance_money' => 0.00,
'online_pay_money' => 0.00,
'online_refund_money' => 0.00,
'balance_deduction' => 0.00,
]
];
private $filename;
private $json_date;
private $site_id;
public function __construct($filename, $type,$site_id = 1) {
// file_put_contents(__DIR__ . '/debug.txt', var_export($site_id,true).PHP_EOL,FILE_APPEND);
$this->filename = $filename;
$this->json_stat['stat_shop']['site_id'] = $site_id;
$this->json_stat['stat_shop_hour']['site_id'] = $site_id;
$this->json_date = $this->json_stat[$type];
}
/**
* 不存在文件,创建
*/
public function check()
{
if(!file_exists($this->filename)){
}else{
}
}
/**
* 储存文件
* @param $data
*/
public function saveFile($data) {
$jsonData = json_encode($data);
while (!empty(cache($this->filename."_lock"))){}
cache($this->filename."_lock", 1);
//修改内容
file_put_contents($this->filename, $jsonData);
cache($this->filename."_lock", 0);
}
/**
* 读取文件
* @return mixed
*/
public function load() {
$jsonData = file_get_contents($this->filename);
$data = json_decode($jsonData, true);
return $data;
}
/**
* 数据处理
* @param $data
*/
public function handleData($data)
{
$file_data = $this->json_date;
foreach ($data as $key => $val){
$file_data[$key] = $val;
}
$carbon = Carbon::now();
$file_data['year'] = $carbon->year;
$file_data['month'] = $carbon->month;
$file_data['day'] = $carbon->day;
$file_data['day_time'] = time();
if (isset($file_data['hour'])) $file_data['hour'] = $carbon->hour;
$this->saveFile($file_data);
}
}

View File

@@ -1,426 +1,417 @@
<?php
/**
*/
namespace extend;
/**
* 上传控制器
* @author Administrator
*
*/
class Upload
{
/**
* @var string 错误信息
*/
public $error;
/**
* @var array 上传规则
*/
public $validate = [];
/**
* @var array 上传文件信息
*/
public $info;
/**
* @var string 当前完整文件名
*/
protected $filename;
/**
* @var array 上传文件信息
*/
public function __construct($filename = '')
{
$this->filename = $filename;
}
/**
* 设置上传信息
* @param unknown $filename
*/
public function setFilename($filename)
{
$this->file = $filename;
return $this;
}
/**
* 设置上传信息
* @param array $info
* @return \util\Upload
*/
public function setUploadInfo($info)
{
$this->info = $info;
return $this;
}
/**
* 获取上传文件的信息
* @access public
* @param string $name 信息名称
* @return array|string
*/
public function getInfo($name = '')
{
return isset($this->info[ $name ]) ? $this->info[ $name ] : $this->info;
}
/**
* 设置文件上传文件的验证规则
* @param array $rule
* @return \util\Upload
*/
public function setValidate(array $rule = [])
{
$this->validate = $rule;
return $this;
}
/**
* 验证目录是否可写
* @param unknown $path
* @return boolean
*/
public function checkPath($path)
{
if (is_dir($path) || mkdir($path, 0755, true)) {
return true;
}
$this->error = [ 'directory {:path} creation failed', [ 'path' => $path ] ];
if(!defined("initroute_tag")) exit();
return false;
}
/**
* 检测是否合法的上传文件
* @access public
* @return bool
*/
public function isValid()
{
return $this->isTest ? is_file($this->filename) : is_uploaded_file($this->filename);
}
/**
* 检测上传文件
* @access public
* @param array $rule 验证规则
* @return bool
*/
public function check($rule = [])
{
$rule = $this->validate;
/* 检查文件大小 */
if (isset($rule['size']) && !$this->checkSize($rule['size'])) {
$this->error = 'filesize not match';
return false;
}
/* 检查文件 Mime 类型 */
if (isset($rule['type']) && !$this->checkMime($rule['type'])) {
$this->error = 'mimetype to upload is not allowed';
return false;
}
/* 检查文件后缀 */
if (isset($rule['ext']) && !$this->checkExt($rule['ext'])) {
$this->error = 'extensions to upload is not allowed';
return false;
}
return true;
}
/**
* 检测上传文件大小
* @access public
* @param integer $size 最大大小
* @return bool
*/
public function checkSize($size)
{
return $this->getFileSize($this->info["tmp_name"]) <= $size;
}
/**
* 检测上传文件类型
* @access public
* @param array|string $mime 允许类型
* @return bool
*/
public function getFileSize($filename)
{
$filesize = filesize($filename);
clearstatcache();
return $filesize;
}
/**
* 获取文件类型
* @param unknown $filename
* @return unknown
*/
public function getFileType($filename)
{
// filetype($filePath);
$finfo = finfo_open(FILEINFO_MIME_TYPE); // 返回 mime 类型
$filetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $filetype;
}
/**
* 检测上传文件类型
* @access public
* @param array|string $mime 允许类型
* @return bool
*/
public function checkMime($mime)
{
$mime = is_string($mime) ? explode(',', $mime) : $mime;
return in_array(strtolower($this->getFileType($this->info["tmp_name"])), $mime);
}
/**
* 获取文件类型信息
* @access public
* @return string
*/
public function getMime()
{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
return finfo_file($finfo, $this->filename);
}
/**
* 检测上传文件后缀
* @access public
* @param array|string $ext 允许后缀
* @return bool
*/
public function checkExt($ext)
{
if (is_string($ext)) {
$ext = explode(',', $ext);
}
$extension = strtolower($this->getFileExt($this->getInfo('name')));
return in_array($extension, $ext);
}
/**
* 获取文件后缀
* @param unknown $filename
* @return mixed
*/
public function getFileExt($filename)
{
return pathinfo($filename, PATHINFO_EXTENSION);
}
/**
* 移动文件
* @param unknown $path
* @param string $savename
* @param string $replace
* @return boolean|\util\Upload
*/
public function move($path, $savename, $replace = true)
{
// 文件上传失败,捕获错误代码
if (!empty($this->info['error'])) {
$this->error($this->info['error']);
return false;
}
// 验证上传
if (!$this->check()) {
return false;
}
$path = rtrim($path, "/") . "/";
// 文件保存命名规则(有外部传入)
$filename = $path . $savename;
// 检测目录
if (false === $this->checkPath(dirname($filename))) {
return false;
}
// 不覆盖同名文件
if (!$replace && is_file($filename)) {
$this->error = [ 'has the same filename: {:filename}', [ 'filename' => $filename ] ];
return false;
}
/* 移动文件 */
if (!move_uploaded_file($this->filename, $filename)) {
$this->error = 'upload write error';
return false;
}
return $filename;
}
/**
* 检测图像文件
* @access public
* @return bool
*/
public function checkImg()
{
$extension = strtolower($this->getFileExt($this->getInfo('name')));
// 如果上传的不是图片,或者是图片而且后缀确实符合图片类型则返回 true
return !in_array($extension, [ 'gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf' ]) || in_array($this->getImageType($this->filename), [ 1, 2, 3, 4, 6, 13 ]);
}
/**
* 判断图像类型
* @access protected
* @param string $image 图片名称
* @return bool|int
*/
protected function getImageType($image)
{
if (function_exists('exif_imagetype')) {
return exif_imagetype($image);
}
try {
$info = getimagesize($image);
return $info ? $info[2] : false;
} catch (\Exception $e) {
return false;
}
}
/**
* 得到图片mime信息
* @param unknown $image
* @return boolean
*/
public function getImageInfo($image)
{
try {
$info = getimagesize($image);
return $info;
} catch (\Exception $e) {
return false;
}
}
/**
*获取一个新文件名
*/
public function createNewFileName()
{
$name = date('Ymdhis', time())
. sprintf('%03d', microtime(true) * 1000)
. sprintf('%02d', mt_rand(10, 99));
return $name;
}
/**
* 这里$data为一个数组类型
* $data[0] 为图像的宽度
* $data[1] 为图像的高度
* $data[2] 为图像的格式包括jpg、gif和png等
* $data[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy"
*/
private function getFileSizeData($file_name)
{
$data = getimagesize($file_name); // 图片名称
return $data;
}
/**
* 获取错误信息(支持多语言)
* @access public
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* 获取文件名称
* @param unknown $file_name
*/
public function getFileName($file_name)
{
return basename($file_name, "." . $this->getFileExt($file_name));
}
/**
* 获取错误代码信息
* @access private
* @param int $errorNo 错误号
* @return $this
*/
private function error($errorNo)
{
switch ($errorNo) {
case 1:
case 2:
$this->error = 'upload File size exceeds the maximum value';
break;
case 3:
$this->error = 'only the portion of file is uploaded';
break;
case 4:
$this->error = 'no file to uploaded';
break;
case 6:
$this->error = 'upload temp dir not found';
break;
case 7:
$this->error = 'file write error';
break;
default:
$this->error = 'unknown upload error';
}
return $this;
}
/**
* @param $path
* @return bool
*/
public function checkAll($path, $savename){
// 文件上传失败,捕获错误代码
if (!empty($this->info['error'])) {
$this->error($this->info['error']);
return false;
}
// 验证上传
if (!$this->check()) {
return false;
}
$path = rtrim($path, "/") . "/";
// 文件保存命名规则(有外部传入)
$filename = $path . $savename;
// 检测目录
if (false === $this->checkPath(dirname($filename))) {
return false;
}
return true;
}
<?php
namespace extend;
/**
* 上传控制器
* @author Administrator
*
*/
class Upload
{
/**
* @var string 错误信息
*/
public $error;
/**
* @var array 上传规则
*/
public $validate = [];
/**
* @var array 上传文件信息
*/
public $info;
/**
* @var string 当前完整文件名
*/
protected $filename;
/**
* @var array 上传文件信息
*/
public function __construct($filename = '')
{
$this->filename = $filename;
}
/**
* 设置上传信息
* @param unknown $filename
*/
public function setFilename($filename)
{
$this->file = $filename;
return $this;
}
/**
* 设置上传信息
* @param array $info
* @return \util\Upload
*/
public function setUploadInfo($info)
{
$this->info = $info;
return $this;
}
/**
* 获取上传文件的信息
* @access public
* @param string $name 信息名称
* @return array|string
*/
public function getInfo($name = '')
{
return isset($this->info[ $name ]) ? $this->info[ $name ] : $this->info;
}
/**
* 设置文件上传文件的验证规则
* @param array $rule
* @return \util\Upload
*/
public function setValidate(array $rule = [])
{
$this->validate = $rule;
return $this;
}
/**
* 验证目录是否可写
* @param unknown $path
* @return boolean
*/
public function checkPath($path)
{
if (is_dir($path) || mkdir($path, 0755, true)) {
return true;
}
$this->error = [ 'directory {:path} creation failed', [ 'path' => $path ] ];
if(!defined("initroute_tag")) exit();
return false;
}
/**
* 检测是否合法的上传文件
* @access public
* @return bool
*/
public function isValid()
{
return $this->isTest ? is_file($this->filename) : is_uploaded_file($this->filename);
}
/**
* 检测上传文件
* @access public
* @param array $rule 验证规则
* @return bool
*/
public function check($rule = [])
{
$rule = $this->validate;
/* 检查文件大小 */
if (isset($rule['size']) && !$this->checkSize($rule['size'])) {
$this->error = 'filesize not match';
return false;
}
/* 检查文件 Mime 类型 */
if (isset($rule['type']) && !$this->checkMime($rule['type'])) {
$this->error = 'mimetype to upload is not allowed';
return false;
}
/* 检查文件后缀 */
if (isset($rule['ext']) && !$this->checkExt($rule['ext'])) {
$this->error = 'extensions to upload is not allowed';
return false;
}
return true;
}
/**
* 检测上传文件大小
* @access public
* @param integer $size 最大大小
* @return bool
*/
public function checkSize($size)
{
return $this->getFileSize($this->info["tmp_name"]) <= $size;
}
/**
* 检测上传文件类型
* @access public
* @param array|string $mime 允许类型
* @return bool
*/
public function getFileSize($filename)
{
$filesize = filesize($filename);
clearstatcache();
return $filesize;
}
/**
* 获取文件类型
* @param unknown $filename
* @return unknown
*/
public function getFileType($filename)
{
// filetype($filePath);
$finfo = finfo_open(FILEINFO_MIME_TYPE); // 返回 mime 类型
$filetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $filetype;
}
/**
* 检测上传文件类型
* @access public
* @param array|string $mime 允许类型
* @return bool
*/
public function checkMime($mime)
{
$mime = is_string($mime) ? explode(',', $mime) : $mime;
return in_array(strtolower($this->getFileType($this->info["tmp_name"])), $mime);
}
/**
* 获取文件类型信息
* @access public
* @return string
*/
public function getMime()
{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
return finfo_file($finfo, $this->filename);
}
/**
* 检测上传文件后缀
* @access public
* @param array|string $ext 允许后缀
* @return bool
*/
public function checkExt($ext)
{
if (is_string($ext)) {
$ext = explode(',', $ext);
}
$extension = strtolower($this->getFileExt($this->getInfo('name')));
return in_array($extension, $ext);
}
/**
* 获取文件后缀
* @param unknown $filename
* @return mixed
*/
public function getFileExt($filename)
{
return pathinfo($filename, PATHINFO_EXTENSION);
}
/**
* 移动文件
* @param unknown $path
* @param string $savename
* @param string $replace
* @return boolean|\util\Upload
*/
public function move($path, $savename, $replace = true)
{
// 文件上传失败,捕获错误代码
if (!empty($this->info['error'])) {
$this->error($this->info['error']);
return false;
}
// 验证上传
if (!$this->check()) {
return false;
}
$path = rtrim($path, "/") . "/";
// 文件保存命名规则(有外部传入)
$filename = $path . $savename;
// 检测目录
if (false === $this->checkPath(dirname($filename))) {
return false;
}
// 不覆盖同名文件
if (!$replace && is_file($filename)) {
$this->error = [ 'has the same filename: {:filename}', [ 'filename' => $filename ] ];
return false;
}
/* 移动文件 */
if (!move_uploaded_file($this->filename, $filename)) {
$this->error = 'upload write error';
return false;
}
return $filename;
}
/**
* 检测图像文件
* @access public
* @return bool
*/
public function checkImg()
{
$extension = strtolower($this->getFileExt($this->getInfo('name')));
// 如果上传的不是图片,或者是图片而且后缀确实符合图片类型则返回 true
return !in_array($extension, [ 'gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf' ]) || in_array($this->getImageType($this->filename), [ 1, 2, 3, 4, 6, 13 ]);
}
/**
* 判断图像类型
* @access protected
* @param string $image 图片名称
* @return bool|int
*/
protected function getImageType($image)
{
if (function_exists('exif_imagetype')) {
return exif_imagetype($image);
}
try {
$info = getimagesize($image);
return $info ? $info[2] : false;
} catch (\Exception $e) {
return false;
}
}
/**
* 得到图片mime信息
* @param unknown $image
* @return boolean
*/
public function getImageInfo($image)
{
try {
$info = getimagesize($image);
return $info;
} catch (\Exception $e) {
return false;
}
}
/**
*获取一个新文件名
*/
public function createNewFileName()
{
$name = date('Ymdhis', time())
. sprintf('%03d', microtime(true) * 1000)
. sprintf('%02d', mt_rand(10, 99));
return $name;
}
/**
* 这里$data为一个数组类型
* $data[0] 为图像的宽度
* $data[1] 为图像的高度
* $data[2] 为图像的格式包括jpg、gif和png等
* $data[3] 为图像的宽度和高度,内容为 width="xxx" height="yyy"
*/
private function getFileSizeData($file_name)
{
$data = getimagesize($file_name); // 图片名称
return $data;
}
/**
* 获取错误信息(支持多语言)
* @access public
* @return string
*/
public function getError()
{
return $this->error;
}
/**
* 获取文件名称
* @param unknown $file_name
*/
public function getFileName($file_name)
{
return basename($file_name, "." . $this->getFileExt($file_name));
}
/**
* 获取错误代码信息
* @access private
* @param int $errorNo 错误号
* @return $this
*/
private function error($errorNo)
{
switch ($errorNo) {
case 1:
case 2:
$this->error = 'upload File size exceeds the maximum value';
break;
case 3:
$this->error = 'only the portion of file is uploaded';
break;
case 4:
$this->error = 'no file to uploaded';
break;
case 6:
$this->error = 'upload temp dir not found';
break;
case 7:
$this->error = 'file write error';
break;
default:
$this->error = 'unknown upload error';
}
return $this;
}
/**
* @param $path
* @return bool
*/
public function checkAll($path, $savename){
// 文件上传失败,捕获错误代码
if (!empty($this->info['error'])) {
$this->error($this->info['error']);
return false;
}
// 验证上传
if (!$this->check()) {
return false;
}
$path = rtrim($path, "/") . "/";
// 文件保存命名规则(有外部传入)
$filename = $path . $savename;
// 检测目录
if (false === $this->checkPath(dirname($filename))) {
return false;
}
return true;
}
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
<?php
namespace extend\exception;
use RuntimeException;
use Throwable;
/**
* 库存错误异常处理类
*/
class StockException extends RuntimeException
{
public function __construct($message = "", $code = -1, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}