This commit is contained in:
全栈小学生 2023-04-21 09:56:53 +08:00
parent ed0d35cb92
commit 791e3c456c
3 changed files with 246 additions and 42 deletions

View File

@ -329,6 +329,7 @@ function format_round_money($number)
{
return round($number, 2);
}
/**
* 基础属性过滤(特殊字符..)
* @param $string
@ -364,6 +365,7 @@ function mkdirs($dir, $mode = 0777)
if (!mkdirs(dirname($dir), $mode)) return false;
return @mkdir($dir, $mode);
}
/**
* 获取唯一随机字符串
* @param int $len
@ -400,14 +402,10 @@ function check_event_result($result)
*/
function array_merge2(array $array1, array $array2)
{
foreach ($array2 as $array2_k => $array2_v)
{
if(array_key_exists($array2_k, $array1))
{
foreach ($array2_v as $array2_kk => $array2_vv)
{
if(array_key_exists($array2_kk, $array1[$array2_k]))
{
foreach ($array2 as $array2_k => $array2_v) {
if (array_key_exists($array2_k, $array1)) {
foreach ($array2_v as $array2_kk => $array2_vv) {
if (array_key_exists($array2_kk, $array1[$array2_k])) {
$array1[$array2_k][$array2_kk] = array_merge($array1[$array2_k][$array2_kk], $array2_vv);
} else
$array1[$array2_k][$array2_kk] = $array2_vv;
@ -417,3 +415,183 @@ function array_merge2(array $array1, array $array2)
}
return $array1;
}
/**
* 通过目录获取文件结构1
* @param $dir
* @return array
*/
function get_files_by_dir($dir)
{
$dh = @opendir($dir); //打开目录,返回一个目录流
$return = array();
while ($file = @readdir($dh)) { //循环读取目录下的文件
if ($file != '.' and $file != '..') {
$path = $dir . DIRECTORY_SEPARATOR . $file; //设置目录,用于含有子目录的情况
if (is_dir($path)) {
$return[] = $file;
}
}
}
@closedir($dh); //关闭目录流
return $return; //返回文件
}
/**
* 文件夹文件拷贝
* @param string $src 来源文件夹
* @param string $dst 目的地文件夹
* @return bool
*/
function dir_copy(string $src = '', string $dst = '')
{
if (empty($src) || empty($dst)) {
return false;
}
$dir = opendir($src);
dir_mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
dir_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
return true;
}
/**
* 删除文件
* @param string $dst
* @param array $dirs
* @return bool
*/
function dir_remove(string $dst = '', array $dirs = [])
{
if (empty($dirs) || empty($dst)) {
return false;
}
foreach($dirs as $v){
@unlink($dst.$v);
}
return true;
}
/**
* 创建文件夹
*
* @param string $path 文件夹路径
* @param int $mode 访问权限
* @param bool $recursive 是否递归创建
* @return bool
*/
function dir_mkdir($path = '', $mode = 0777, $recursive = true)
{
clearstatcache();
if (!is_dir($path)) {
mkdir($path, $mode, $recursive);
return chmod($path, $mode);
}
return true;
}
/**
* 分割sql语句
* @param string $content sql内容
* @param bool $string 如果为真则只返回一条sql语句默认以数组形式返回
* @param array $replace 替换前缀,如:['my_' => 'me_']表示将表前缀my_替换成me_
* @return array|string 除去注释之后的sql语句数组或一条语句
*/
function parse_sql($content = '', $string = false, $replace = [])
{
// 纯sql内容
$pure_sql = [];
// 被替换的前缀
$from = '';
// 要替换的前缀
$to = '';
// 替换表前缀
if (!empty($replace)) {
$to = current($replace);
$from = current(array_flip($replace));
}
if ($content != '') {
// 多行注释标记
$comment = false;
// 按行分割,兼容多个平台
$content = str_replace(["\r\n", "\r"], "\n", $content);
$content = explode("\n", trim($content));
// 循环处理每一行
foreach ($content as $key => $line) {
// 跳过空行
if ($line == '') {
continue;
}
// 跳过以#或者--开头的单行注释
if (preg_match("/^(#|--)/", $line)) {
continue;
}
// 跳过以/**/包裹起来的单行注释
if (preg_match("/^\/\*(.*?)\*\//", $line)) {
continue;
}
// 多行注释开始
if (substr($line, 0, 2) == '/*') {
$comment = true;
continue;
}
// 多行注释结束
if (substr($line, -2) == '*/') {
$comment = false;
continue;
}
// 多行注释没有结束,继续跳过
if ($comment) {
continue;
}
// 替换表前缀
if ($from != '') {
$line = str_replace('`' . $from, '`' . $to, $line);
}
// sql语句
$pure_sql[] = $line;
}
// 只返回一条语句
if ($string) {
return implode("", $pure_sql);
}
// 以数组形式返回sql语句
$pure_sql = implode("\n", $pure_sql);
$pure_sql = explode(";\n", $pure_sql);
}
return $pure_sql;
}
/**
* 递归查询目录下所有文件
* @param $path
* @param $data
* @return void
*/
function search_dir($path, &$data, $search = '')
{
if (is_dir($path)) {
$path .= DIRECTORY_SEPARATOR;
$fp = dir($path);
while ($file = $fp->read()) {
if ($file != '.' && $file != '..') {
search_dir($path . '/' . $file, $data, $search);
}
}
$fp->close();
}
if (is_file($path)) {
if($search) $path = str_replace($search, '', $path);
$data[] = $path;
}
}

View File

@ -55,11 +55,11 @@ class Index extends BaseInstall
$root_path = str_replace("\\", DIRECTORY_SEPARATOR, dirname(dirname(dirname(dirname(__FILE__)))));
$root_path = str_replace("../", DIRECTORY_SEPARATOR, $root_path);
$dirs_list = [
[ "path" => $root_path . DIRECTORY_SEPARATOR . ".env", "path_name" => "env", "name" => "env" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . ".example.env", "path_name" => "example_env", "name" => "env" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . 'runtime', "path_name" => "runtime", "name" => "runtime" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . 'public/upload/', "path_name" => "upload", "name" => "upload" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . 'app/install', "path_name" => "app/install", "name" => "安装目录" ]
[ "path" => $root_path . DIRECTORY_SEPARATOR . ".env", "path_name" => "niucloud/.env", "name" => "env" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . ".example.env", "path_name" => "niucloud/.example_env", "name" => "env" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . 'runtime/', "path_name" => "niucloud/runtime", "name" => "runtime" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . 'public/upload/', "path_name" => "niucloud/public/upload", "name" => "upload" ],
[ "path" => $root_path . DIRECTORY_SEPARATOR . 'app/install/', "path_name" => "niucloud/app/install", "name" => "安装目录" ]
];
//目录 可读 可写检测
$is_dir = true;

View File

@ -137,9 +137,13 @@ class CorePayService extends BaseCoreService
* @param string $out_trade_no
* @return void
*/
public function returnTo(int $site_id, string $out_trade_no){
public function returnTo(int $site_id, $pay_item){
if(is_object($pay_item)){
$pay = $pay_item;
}else{
$out_trade_no = $pay_item;
$pay = $this->findPayInfoByOutTradeNo($site_id, $out_trade_no);
}
if($pay->isEmpty()) return true;
if($pay['status'] != PayEnum::STATUS_ING) return true;
if(empty($pay->type)) return true;
@ -157,7 +161,7 @@ class CorePayService extends BaseCoreService
$pay->save($data);
}
return true;
return $close;
}
/**
@ -307,4 +311,26 @@ class CorePayService extends BaseCoreService
}
}
public function reset(int $site_id, string $out_trade_no, float $money){
$pay = $this->findPayInfoByOutTradeNo($site_id, $out_trade_no);
if($pay->isEmpty()) throw new PayException(700000);
if(!in_array($pay['status'], [
PayEnum::STATUS_WAIT,
PayEnum::STATUS_ING
])) throw new PayException(700011);//只有待支付可以重置支付
if($pay['status'] == PayEnum::STATUS_ING){
if(!$this->returnTo($site_id, $pay)){
throw new PayException(700012);
}
}
$out_trade_no = create_no('pay', $pay['main_id']);
$data = array(
'out_trade_no' => $out_trade_no,
'money' => $money
);
$pay->save($data);
//todo 需要考虑是业务调用重置支付,还是支付重置反馈业务
return $out_trade_no;
}
}