Update .gitignore rules

This commit is contained in:
技术老胡
2025-04-18 18:10:02 +08:00
parent 748356cc6b
commit a6b5133cc3
35 changed files with 11 additions and 2521 deletions

View File

@@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace app\controller\api;
use think\Request;
use app\model\Order;
class ConsoleController
{
public function orderinfo(Request $request)
{
$date = (int)$request->get('time') ?: 0;
$time = match ($date) {
0 => [date('Y') . '-01-01 00:00:00', date('Y-m-d 23:59:59')],
1 => [date('Y-m-d H:i:s', strtotime('-30 days')), date('Y-m-d 23:59:59')],
2 => [date('Y-m-d H:i:s', strtotime('-6 months')), date('Y-m-d 23:59:59')],
3 => [date('Y-m-d H:i:s', strtotime('-1 year')), date('Y-m-d 23:59:59')],
default => []
};
if (!$time) {
return json(['code' => 400, 'msg' => '参数错误']);
}
$orders = Order::whereBetweenTime('create_time', $time[0], $time[1])->where('state', 1)->field('id,type,really_price')->select();
$data = [
'ordernum' => count($orders),
'totalmoney' => \number_format(array_sum(array_column($orders->toArray(), 'really_price')), 2),
'wxpay' => [
'num' => count($orders->where('type', 'wxpay')),
'money' => \number_format(array_sum(array_column($orders->where('type', 'wxpay')->toArray(), 'really_price')), 2)
],
'alipay' => [
'num' => count($orders->where('type', 'alipay')),
'money' => \number_format(array_sum(array_column($orders->where('type', 'alipay')->toArray(), 'really_price')), 2)
],
'unionpay' => [
'num' => count($orders->where('type', 'unionpay')),
'money' => \number_format(array_sum(array_column($orders->where('type', 'unionpay')->toArray(), 'really_price')), 2)
]
];
return json($data);
}
}

View File

@@ -1,196 +0,0 @@
<?php
declare(strict_types=1);
namespace app\controller\api;
use app\BaseController;
use app\model\Order;
use app\model\User;
class OrderController extends BaseController
{
// 查询订单
public function getOrders()
{
$query = $this->request->get();
$orders = Order::serchOrders($query)->order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]);
if ($orders) {
return json(['code' => 0, 'msg' => 'OK', 'count' => $orders->total(), 'data' => $orders->items()]);
} else {
return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]);
}
}
// 修改订单支付状态
public function changeOrderState()
{
$info = $this->request->post();
$uporder_res = Order::update(['state' => $info['state'], 'id' => $info['id']]);
if ($uporder_res) {
return json(\backMsg(0, '修改成功'));
} else {
return json(\backMsg(1, '修改失败'));
}
}
// 手动补单
public function doPayOrder()
{
$info = $this->request->post();
// 修改支付状态
$order = Order::find($info['id']);
$order->state = $info['state'];
$res = $order->save();
if ($res) {
// 创建通知
$notify = self::crateNotify($order);
// 字符串签名
$user_key = User::where('pid', $order->pid)->value('secret_key');
$sign = self::getSign($notify, $user_key);
$notify['sign'] = $sign;
// 异步通知
$notify_url = $order->notify_url . '?' . http_build_query($notify);
if (strpos($order->notify_url, '?')) $notify_url = $order->notify_url . '&' . http_build_query($notify);
$res_notify = self::getHttpResponse($notify_url);
if ($res_notify === 'success') {
return json(\backMsg(0, '订单通知成功'));
} else {
return json(\backMsg(1, '异步通知失败'));
}
} else {
return json(\backMsg(1, '支付状态修改失败'));
}
}
// 重新通知
public function redoPayOrder()
{
$id = $this->request->post('id');
// 修改支付状态
$order = Order::find($id);
if ($order) {
// 创建通知
$notify = self::crateNotify($order);
// 字符串签名
$user_key = User::where('pid', $order->pid)->value('secret_key');
$sign = self::getSign($notify, $user_key);
$notify['sign'] = $sign;
// 异步通知
$notify_url = $order->notify_url . '?' . http_build_query($notify);
if (strpos($order->notify_url, '?')) $notify_url = $order->notify_url . '&' . http_build_query($notify);
$res_notify = self::getHttpResponse($notify_url);
if ($res_notify === 'success') {
return json(\backMsg(0, '订单通知成功'));
} else {
return json(\backMsg(1, '异步通知失败'));
}
} else {
return json(\backMsg(1, '订单不存在'));
}
}
// 删除订单
public function deleteOrder()
{
$id = $this->request->post('id');
$del_res = Order::destroy($id);
if ($del_res) {
return json(\backMsg(0, '删除成功'));
} else {
return json(\backMsg(1, '删除失败'));
}
}
// 批量删除订单
public function batchRemove()
{
$ids = $this->request->post('ids');
if (!$ids) {
return json(\backMsg(1, '参数错误'));
}
$del_res = Order::destroy($ids);
if ($del_res) {
return json(\backMsg(0, '删除成功'));
} else {
return json(\backMsg(1, '删除失败'));
}
}
// 清空超时订单
public function batchTimeout()
{
$ids = Order::scope('timeoutOrder')->column('id');
if (!$ids) {
return json(\backMsg(1, '无过期订单'));
}
$batch_del_res = Order::destroy($ids);
if ($batch_del_res) {
return json(\backMsg(0, '清理成功'));
} else {
return json(\backMsg(1, '清理失败'));
}
}
// 签名方法
private static function getSign(array $param = [], string $key = ''): string
{
if (!$param)
return '参数错误';
if (!$key)
return '密钥错误';
ksort($param);
reset($param);
$signstr = '';
foreach ($param as $k => $v) {
if ($k != "sign" && $k != "sign_type" && $v != '') {
$signstr .= $k . '=' . $v . '&';
}
}
$signstr = substr($signstr, 0, -1);
$signstr .= $key;
$sign = md5($signstr);
return $sign;
}
// 构建通知参数
private static function crateNotify($param): array
{
$notify = [
'pid' => $param->pid,
'trade_no' => $param->order_id,
'out_trade_no' => $param->out_trade_no,
'type' => $param->type,
'name' => $param->name,
'money' => $param->money,
'trade_status' => 'TRADE_SUCCESS',
'sign_type' => 'MD5',
];
// 添加扩展参数
// $notify = array_merge($notify, unserialize($param->param));
$notify['param'] = unserialize($param->param);
// 删除空值
foreach ($notify as $key => $val) {
if ($val === '') unset($notify[$key]);
}
return $notify;
}
// 请求外部资源
private static function getHttpResponse($url, $header = [], $post = null, $timeout = 10)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if ($header) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} else {
$httpheader[] = "Accept: */*";
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.8";
$httpheader[] = "Connection: close";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
}
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($post) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}

View File

@@ -1,181 +0,0 @@
<?php
declare(strict_types=1);
namespace app\controller\api;
use app\BaseController;
use app\model\PayAccount;
use app\model\PayChannel;
class PayManageController extends BaseController
{
// 获取账号列表
public function getPayAccount()
{
$query = $this->request->get();
$accounts = PayAccount::serchAccount($query)->order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]);
if ($accounts) {
return json(['code' => 0, 'msg' => 'OK', 'count' => $accounts->total(), 'data' => $accounts->items()]);
} else {
return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]);
}
}
// 收款终端列表
public function getChannelList()
{
$aid = $this->request->post('aid');
$res = PayChannel::where(['account_id' => $aid])->order('last_time', 'desc')->select();
if ($res) {
return json(backMsg(0, '获取成功', $res));
} else {
return json(backMsg(1, '失败'));
}
}
// 账号状态
public function accountEnable()
{
$info = $this->request->post();
$up_res = PayAccount::update($info);
if ($up_res) {
return json(backMsg(0, '成功'));
} else {
return json(backMsg(1, '失败'));
}
}
// 添加账号
public function addAccount()
{
$info = $this->request->post();
$pid = $this->request->session('pid');
$info['pid'] = $pid;
$info['params'] = '{}';
$check_acc = PayAccount::where(['account' => $info['account'], 'platform' => $info['platform'], 'pid' => $pid])->find();
if ($check_acc) {
return json(backMsg(1, '账号已存在'));
}
$acc = PayAccount::create($info);
if ($acc) {
return json(backMsg(0, '添加成功'));
} else {
return json(backMsg(1, '添加失败'));
}
}
// 编辑账号
public function editAccount()
{
$info = $this->request->post();
$up_res = PayAccount::update($info);
if ($up_res) {
return json(backMsg(0, '修改成功'));
} else {
return json(backMsg(1, '修改失败'));
}
}
// 删除账号
public function delAccount()
{
$ids = $this->request->post('ids');
$res = PayAccount::destroy($ids);
$res2 = PayChannel::whereIn('account_id', $ids)->select()->delete();
if ($res && $res2) {
return json(backMsg(0, '已删除'));
} else {
return json(backMsg(1, '失败'));
}
}
// 添加收款终端
public function addChannel()
{
$info = $this->request->post();
$check = PayChannel::where(['account_id' => $info['account_id'], 'channel' => $info['channel']])->count();
if ($check) {
return json(backMsg(1, '编号已存在'));
}
$info['last_time'] = date('Y-m-d H:i:s');
$res = PayChannel::create($info);
if ($res) {
return json(backMsg(0, '添加成功'));
} else {
return json(backMsg(1, '添加失败'));
}
}
// 编辑收款终端
public function editChannel()
{
$info = $this->request->post();
$up_res = PayChannel::update($info);
if ($up_res) {
return json(backMsg(0, '修改成功'));
} else {
return json(backMsg(1, '修改失败'));
}
}
// 删除收款终端
public function delChannel()
{
$cid = $this->request->post('id');
$res = PayChannel::destroy($cid);
if ($res) {
return json(backMsg(0, '已删除'));
} else {
return json(backMsg(1, '失败'));
}
}
// 上传二维码图片
public function uploadQrcode()
{
$img = $this->request->file('codeimg');
if (!$img) {
return json(backMsg(1, '请选择要上传的文件'));
}
// 验证文件类型
$allowedTypes = ['image/png', 'image/jpeg', 'image/gif'];
$fileMimeType = $img->getMime();
if (!in_array($fileMimeType, $allowedTypes)) {
return json(backMsg(1, '只允许上传PNG、JPEG或GIF格式的图片'));
}
// 生成唯一文件名
$filename = 'img_' . time() . '_' . uniqid() . '.' . $img->getOriginalExtension();
// 设置文件保存路径
$path = public_path() . '/files/qrcode/';
if (!is_dir($path)) {
mkdir($path, 0755, true);
}
// 移动文件到指定目录
$info = $img->move($path, $filename);
if ($info) {
$imgpath = '/files/qrcode/' . $filename;
return json(backMsg(0, '上传成功', ['imgpath' => $imgpath]));
} else {
return json(backMsg(1, '上传失败'));
}
}
// 获取账号交易流水
public function getAccountTrade()
{
$req_info = $this->request->get();
$req_pid = $req_info['pid'];
$req_aid = $req_info['aid'];
// 加载配置文件
$config = PayAccount::getAccountConfig($req_aid);
if ($config === false) return json(backMsg(1, '账号配置文件错误'));
if ($req_aid != $config['aid'] || $req_pid != session('pid')) return json(backMsg(1, '监听收款配置不一致'));
// 登陆账号
$pay_config = ['username' => $config['account'], 'password' => $config['password']];
// 收款查询
$params = $config['params'];
// 实例监听客户端
$payclient_name = $config['payclass'];
$payclient_path = "\\payclient\\{$payclient_name}";
$Payclient = new $payclient_path($pay_config);
// 获取支付明细
$records = $Payclient->getOrderInfo($params);
if ($records['code'] === 0) {
// 收款流水
return json(backMsg(0, '查询成功', $records['data']));
} else {
return json(['code' => 1, 'msg' => $records['msg']]);
}
}
}

View File

@@ -1,235 +0,0 @@
<?php
declare(strict_types=1);
namespace app\controller\api;
use app\BaseController;
class PluginController extends BaseController
{
// 获取插件列表
public function getPluginList()
{
$local_plugin_config = self::getPluginConfig();
$show = $this->request->get('show', 1);
$plugin_config = match ((int)$show) {
0 => \Plugin::getAllPlugins($local_plugin_config),
1 => \Plugin::getInstall($local_plugin_config),
2 => \Plugin::getUninstallPlugins($local_plugin_config),
default => []
};
if ($plugin_config) {
return json(['code' => 0, 'msg' => 'OK', 'count' => count($plugin_config), 'data' => $plugin_config]);
} else {
return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]);
}
}
// 安装插件
public function installPlugin()
{
$platform = $this->request->post('platform');
if (!$platform) return json(backMsg(1, '请选择插件'));
$intall_info = \Plugin::installPlugin($platform);
if ($intall_info['code'] !== 0) return json(backMsg(1, $intall_info['msg']));
// 需要授权
if ($intall_info['data']['status'] === 0) {
return json(['code' => 0, 'msg' => '请支付', 'state' => 0, 'data' => $intall_info['data']]);
}
$saved = $this->saveNewPluginConfig($intall_info['data']);
if ($saved['code'] !== 0) return json(backMsg(1, $saved['msg']));
return json(['code' => 0, 'msg' => '授权成功', 'state' => 1]);
}
// 更新插件
public function updatePlugin()
{
$platform = $this->request->post('platform');
if (!$platform) return json(backMsg(1, '请选择插件'));
$update_info = \Plugin::updatePlugin($platform);
if ($update_info['code'] !== 0) return json(backMsg(1, $update_info['msg']));
$saved = $this->saveNewPluginConfig($update_info['data']);
if ($saved['code'] !== 0) return json(backMsg(1, $saved['msg']));
return json(['code' => 0, 'msg' => '更新成功']);
}
// 保存全部插件信息
private function saveNewPluginConfig(array $config = [])
{
$plugin_config = $config['config'];
$plugin_auth = $config['authcode'];
$plugin_file = $config['file'];
if (!$this->savePluginFile($plugin_file, $plugin_config)) return backMsg(1, '保存插件文件失败');
if (!$this->saveAuthCode($plugin_auth, $plugin_config)) return backMsg(1, '保存插件授权码失败');
if (!$this->addPlugin($plugin_config)) return backMsg(1, '保存插件配置失败');
return backMsg(0, 'ok');
}
// 卸载插件
public function uninstallPlugin()
{
$platform = $this->request->post('platform');
if (!$platform) return json(backMsg(1, '请选择插件'));
$this->delPluginFile($platform);
$this->delPlugin($platform);
return json(backMsg(0, '卸载成功'));
}
// 添加或更新插件
public function addPlugin(array $option = [])
{
$keys = ['platform', 'name', 'class_name', 'price', 'describe', 'website', 'helplink', 'version'];
$config = [];
foreach ($option as $key => $value) {
if (in_array($key, $keys)) $config[$key] = $value;
}
$config['state'] = 1;
$plugin_config = self::getPluginConfig();
$plugin_platform = $config['platform'] ?: '';
foreach ($plugin_config as $i => $value) {
if ($plugin_platform == $value['platform']) {
$plugin_config[$i] = $config;
$this->savePluginConfig($plugin_config, '支付插件列表');
return true;
}
}
$plugin_config[] = $config;
$this->savePluginConfig($plugin_config, '支付插件列表');
return true;
}
// 删除插件配置
private function delPlugin(string $plugin_name = '')
{
$plugin_config = self::getPluginConfig();
$index = null;
foreach ($plugin_config as $i => $value) {
if ($value['platform'] == $plugin_name) {
$index = $i;
break;
}
}
if ($index === null) return false;
unset($plugin_config[$index]);
$config = array_values($plugin_config);
$this->savePluginConfig($config, '支付插件列表');
return true;
}
// 删除插件类库文件
private function delPluginFile(string $platform = '')
{
$file_name = self::getPluginInfo($platform)['class_name'];
if (!$file_name) return false;
$plugin_path = root_path() . '/extend/payclient/' . $file_name . '.php';
if (!file_exists($plugin_path)) return false;
unlink($plugin_path);
return true;
}
// 修改插件
public function setPlugin($platform = '', $option = [])
{
$config = self::getPluginConfig();
if (!$platform) return 1;
if (!$option) return 2;
foreach ($config as $index => $options) {
if ($options['platform'] == $platform) {
foreach ($options as $key => $value) {
if (\array_key_exists($key, $option)) {
$config[$index][$key] = $option[$key];
}
}
$this->savePluginConfig($config, '支付插件列表');
return 0;
}
}
}
// 插件启用
public function pluginEnable()
{
$info = $this->request->post();
if (!$this->isPluginInstall($info['platform'])) return json(backMsg(1, '插件未安装'));
$up_res = $this->setPlugin($info['platform'], ['state' => $info['state']]);
if ($up_res) {
return json(backMsg(1, '失败'));
} else {
return json(backMsg(0, '成功'));
}
}
// 检测插件是否安装
public function isPluginInstall(string $platform): bool
{
$config = self::getPluginConfig();
$platforms = [];
foreach ($config as $key => $value) {
$platforms[] = $value['platform'];
}
if (in_array($platform, $platforms)) {
return true;
} else {
return false;
}
}
// 插件选项
public function pluginOption()
{
// 加载平台配置
$config = self::getPluginConfig();
$option = [];
foreach ($config as $value) {
if ($value['state'] == 0) {
continue;
}
$option[] = ['platform' => $value['platform'], 'name' => $value['name']];
}
return json($option);
}
// 获取指定插件配置
public static function getPluginInfo($platform = '')
{
$config = self::getPluginConfig();
$info = [];
foreach ($config as $item) {
if ($item['platform'] == $platform) {
$info = $item;
break;
}
}
return $info;
}
// 保存授权码
private function saveAuthCode(string $authcode = '', array $config = [])
{
$dir_path = runtime_path() . "auth/";
if (!is_dir($dir_path)) mkdir($dir_path, 755, true);
$auth_path = $dir_path . md5("{$config['platform']}payclient\\{$config['class_name']}") . '.json';
return file_put_contents($auth_path, json_encode(['authcode' => $authcode])) !== false ? true : false;
}
// 保存插件类库文件
private function savePluginFile($file_url = '', array $config = [])
{
if (empty($file_url)) return false;
$file_content = @file_get_contents($file_url);
if ($file_content === false) return false;
$save_dir = root_path() . 'extend/payclient/';
if (!is_dir($save_dir)) mkdir($save_dir, 0755, true);
$save_path = $save_dir . $config['class_name'] . '.php';
return file_put_contents($save_path, $file_content) !== false ? true : false;
}
// 获取插件配置
private static function getPluginConfig(): array
{
$payplugin_path = config_path() . '/extend/payplugin.php';
if (!file_exists($payplugin_path)) return [];
// 加载插件配置
$payplugin_config = require $payplugin_path;
return $payplugin_config;
}
// 保存插件配置
private function savePluginConfig(array $config, string $note = '说明')
{
$payplugin_path = config_path() . '/extend/payplugin.php';
$note_tpl = <<<EOF
// +----------------------------------------------------------------------
// | $note
// +----------------------------------------------------------------------
EOF;
$config_str = "<?php\n" . $note_tpl . "\n\nreturn " . var_export($config, true) . ";\n";
\file_put_contents($payplugin_path, $config_str);
}
}

View File

@@ -1,95 +0,0 @@
<?php
declare(strict_types=1);
namespace app\controller\api;
use app\BaseController;
use think\facade\Session;
use app\model\User;
class UserController extends BaseController
{
protected $middleware = ['Auth' => ['except' => ['login']]];
public function login()
{
$login_info = $this->request->post();
$userinfo = self::checkUser($login_info);
if ($userinfo['code'] === 0) {
Session::set('userid', $userinfo['data']->id);
Session::set('pid', $userinfo['data']->pid);
Session::set('nickname', $userinfo['data']->nickname);
Session::set('userrole', $userinfo['data']->role);
Session::set('islogin', true);
return json(backMsg(0, 'ok'));
} else {
return json($userinfo);
}
}
public function logout()
{
Session::clear();
return json(backMsg(0, '注销成功'));
}
public function editUser()
{
$userid = session('userid');
$info = $this->request->post();
$res = User::update($info, ['id' => $userid]);
if (!$res) {
return json(backMsg(1, '修改失败'));
}
return json(backMsg(0, '重置成功'));
}
public function changePassword()
{
$userid = session('userid');
$user_info = User::find($userid);
$post_info = $this->request->post();
if (password_verify($post_info['old_password'], $user_info->password)) {
$new_password = password_hash($post_info['new_password'], PASSWORD_DEFAULT);
$res = User::update(['password' => $new_password], ['id' => $userid]);
if (!$res) {
return json(backMsg(1, '修改失败'));
}
return json(backMsg(0, '修改成功'));
} else {
return json(backMsg(1, '原密码错误'));
}
}
public function resetKey()
{
$userid = session('userid');
$res = User::update(['secret_key' => $this->generateKey()], ['id' => $userid]);
if (!$res) {
return json(backMsg(1, '重置失败'));
}
return json(backMsg(0, '重置成功'));
}
private function checkUser(array $login_info): array
{
$username = $login_info['username'];
$password = $login_info['password'];
$userinfo = User::where('username', $username)->find();
if ($userinfo) {
if (password_verify($password, $userinfo->password)) {
return ['code' => 0, 'data' => $userinfo];
} else {
return backMsg(1, '登陆密码错误');
}
} else {
return backMsg(2, '用户不存在');
}
}
private function generateKey(bool $strong = true)
{
$bytes = openssl_random_pseudo_bytes(16, $strong);
if ($strong) {
$key = bin2hex($bytes);
return md5($key);
} else {
return false;
}
}
}