Initial project files: BESCMS full source

This commit is contained in:
bes
2026-08-13 23:37:46 +08:00
parent fa6cddb540
commit 2e26f85723
2166 changed files with 396625 additions and 0 deletions
+222
View File
@@ -0,0 +1,222 @@
<?php namespace Phpcmf\Controllers\Admin;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
class Pay extends \Phpcmf\Common {
public function __construct() {
parent::__construct();
$fdata = \Phpcmf\Service::L('Field')->sys_field(['uid']);
$fdata['uid']['name'] = dr_lang('用户账号');
\Phpcmf\Service::V()->assign([
'form' => dr_form_hidden(),
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'用户充值' => ['pay/pay/index', 'fa fa-rmb'],
'资金冻结' => ['pay/pay/freeze_index', 'bi bi-dash-circle-fill'],
'help' => [ 600 ],
]
),
'myfield' => dr_rp(\Phpcmf\Service::L('Field')->toform(0, $fdata), 'width:100%;', 'width:300px;'),
]);
}
public function index() {
if (IS_AJAX_POST) {
$post = \Phpcmf\Service::L('input')->post('data');
if (!$post['uid']) {
$this->_json(0, dr_lang('账号不能为空'), ['field' => 'uid']);
}
$user = \Phpcmf\Service::M()->db->table('member')->where('username', $post['uid'])->get()->getRowArray();
if (!$user) {
$this->_json(0, dr_lang('账号[%s]不存在', $post['uid']), ['field' => 'uid']);
} elseif (!$post['value']) {
$this->_json(0, dr_lang('金额值未填写'), ['field' => 'value']);
} elseif (!$post['unit']) {
$this->_json(0, dr_lang('充值类型未选择'), ['field' => 'unit']);
} elseif (!$post['note']) {
$this->_json(0, dr_lang('备注说明未填写'), ['field' => 'note']);
}
if ($post['type'] == 1) {
// 增加
$post['value'] = abs($post['value']);
$msg = '充值%s成功';
} else {
// 减少
$post['value'] = abs($post['value']) * -1;
$msg = '扣减%s成功';
}
if ($post['unit'] == 1) {
// 积分
if ($user['score'] + $post['value'] < 0) {
$this->_json(0, dr_lang('账号%s不足', SITE_SCORE), ['field' => 'value']);
}
// 付款方的钱
$rt = \Phpcmf\Service::M('member')->add_score($user['id'], $post['value'], $post['note']);
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
$this->_json(1, dr_lang($msg, SITE_SCORE.$post['value']));
} elseif ($post['unit'] == 3) {
// 升级值
if ($user['experience'] + $post['value'] < 0) {
$this->_json(0, dr_lang('账号%s不足', SITE_EXPERIENCE), ['field' => 'value']);
}
// 付款方的钱
$rt = \Phpcmf\Service::M('member')->add_experience($user['id'], $post['value'], $post['note']);
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
$this->_json(1, dr_lang($msg, SITE_EXPERIENCE.$post['value']));
} else {
// rmb
if ($user['money'] + $post['value'] < 0) {
$this->_json(0, dr_lang('账号余额不足'), ['field' => 'value']);
}
// 付款方的钱
$rt = \Phpcmf\Service::M('Pay')->add_money($user['id'], $post['value']);
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
// 增加到交易流水
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $user['id'],
'touid' => $user['id'],
'mid' => 'system',
'title' => dr_lang('后台充值'),
'value' => $post['value'],
'type' => 'system',
'status' => 1,
'result' => $post['note'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
$call = [
'uid' => $user['id'],
'username' => $user['username'],
'email' => $user['email'],
'phone' => $user['phone'],
'value' => $post['value'],
'url' => \Phpcmf\Service::L('Router')->member_url('pay/paylog/show', ['id' => $rt['code']]),
'result' => $post['note'],
];
// 通知
\Phpcmf\Service::L('Notice')->send_notice('pay_admin', $call);
// 钩子
\Phpcmf\Hooks::trigger('pay_admin_after', $call);
$this->_json(1, dr_lang($msg, 'RMB'.$post['value']));
}
}
\Phpcmf\Service::V()->display('pay.html');
}
public function freeze_index() {
if (IS_AJAX_POST) {
$post = \Phpcmf\Service::L('input')->post('data');
if (!$post['uid']) {
$this->_json(0, dr_lang('账号不能为空'), ['field' => 'uid']);
}
$user = \Phpcmf\Service::M()->db->table('member')->where('username', $post['uid'])->get()->getRowArray();
if (!$user) {
$this->_json(0, dr_lang('账号[%s]不存在', $post['uid']), ['field' => 'uid']);
} elseif (!$post['note']) {
$this->_json(0, dr_lang('备注说明未填写'), ['field' => 'note']);
}
$post['value'] = abs($post['value']);
if ($post['type'] == 1) {
// 冻结
if (!$post['value']) {
$this->_json(0, dr_lang('金额值未填写'), ['field' => 'value']);
} elseif ($user['money'] - $post['value'] < 0) {
$this->_json(0, dr_lang('账号可用金额不足'), ['field' => 'value']);
}
\Phpcmf\Service::M('member')->add_freeze($user['id'], $post['value']);
// 增加到交易流水
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $user['id'],
'touid' => $user['id'],
'mid' => 'admin-freeze',
'title' => '后台冻结资金',
'value' => -$post['value'],
'type' => 'system',
'status' => 1,
'result' => $post['note'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
$msg = '冻结%s成功';
} elseif ($post['type'] == 0) {
// 解冻
if (!$post['value']) {
$this->_json(0, dr_lang('金额值未填写'), ['field' => 'value']);
} elseif ($user['freeze'] - $post['value'] < 0) {
$this->_json(0, dr_lang('账号可用冻结金额不足'), ['field' => 'value']);
}
\Phpcmf\Service::M('member')->cancel_freeze($user['id'], $post['value']);
// 增加到交易流水
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $user['id'],
'touid' => $user['id'],
'mid' => 'admin-freeze',
'title' => '后台解冻资金',
'value' => abs($post['value']),
'type' => 'system',
'status' => 1,
'result' => $post['note'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
$msg = '解冻%s成功';
} else {
// 指定任意值
\Phpcmf\Service::M()->table('member')->update($user['id'], ['freeze' => $post['value'] ]);
// 增加到交易流水
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $user['id'],
'touid' => $user['id'],
'mid' => 'admin-freeze',
'title' => '后台设置指定冻结资金',
'value' => abs($post['value']),
'type' => 'system',
'status' => 1,
'result' => $post['note'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
$msg = '设置指定冻结资金%s';
}
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
$call = [
'uid' => $user['id'],
'username' => $user['username'],
'email' => $user['email'],
'phone' => $user['phone'],
'value' => $post['value'],
'url' => \Phpcmf\Service::L('Router')->member_url('pay/paylog/show', ['id' => $rt['code']]),
'result' => $post['note'],
];
// 通知
\Phpcmf\Service::L('Notice')->send_notice('pay_admin_freeze', $call);
// 钩子
\Phpcmf\Hooks::trigger('pay_admin_freeze', $call);
$this->_json(1, dr_lang($msg, abs($post['value'])));
}
\Phpcmf\Service::V()->display('pay_freeze.html');
}
}
+129
View File
@@ -0,0 +1,129 @@
<?php namespace Phpcmf\Controllers\Admin;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
class Payapi extends \Phpcmf\Common
{
public function index() {
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'payapi')->get()->getRowArray();
$data = dr_string2array($data['value']);
if (IS_AJAX_POST) {
$post = \Phpcmf\Service::L('input')->post('data');
\Phpcmf\Service::M()->db->table('member_setting')->replace([
'name' => 'payapi',
'value' => dr_array2string($post)
]);
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
$this->_json(1, dr_lang('操作成功'));
}
$local = dr_dir_map(ROOTPATH.'api/pay/', 1);
foreach ($local as $dir) {
if ($dir != 'finecms' && is_file(ROOTPATH.'api/pay/'.$dir.'/config.php')) {
$config = require ROOTPATH.'api/pay/'.$dir.'/config.php';
if ($data[$dir]) {
$data[$dir]['config'] = $config;
} else {
$data[$dir] = [
'config' => $config,
];
}
}
}
\Phpcmf\Service::V()->assign([
'data' => $data,
'form' => dr_form_hidden(),
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'支付接口' => ['pay/payapi/index', 'fa fa-code'],
'help' => [387]
]
),
]);
\Phpcmf\Service::V()->display('payapi.html');
}
/**
* 检测微信退款 API 证书是否可用
*/
public function check_cert() {
$cert = trim((string)\Phpcmf\Service::L('input')->get('sslcert_path'));
$key = trim((string)\Phpcmf\Service::L('input')->get('sslkey_path'));
$default_cert = ROOTPATH.'api/pay/weixin/cert/apiclient_cert.pem';
$default_key = ROOTPATH.'api/pay/weixin/cert/apiclient_key.pem';
if ($cert === '') {
$row = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'payapi')->get()->getRowArray();
$payapi = dr_string2array($row['value']);
if (!empty($payapi['weixin']['sslcert_path'])) {
$cert = $payapi['weixin']['sslcert_path'];
}
}
if ($key === '') {
if (!isset($payapi)) {
$row = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'payapi')->get()->getRowArray();
$payapi = dr_string2array($row['value']);
}
if (!empty($payapi['weixin']['sslkey_path'])) {
$key = $payapi['weixin']['sslkey_path'];
}
}
if ($cert === '') {
$cert = $default_cert;
}
if ($key === '') {
$key = $default_key;
}
$errors = [];
if (!is_file($cert)) {
$errors[] = dr_lang('证书文件不存在').''.$cert;
} elseif (!is_readable($cert)) {
$errors[] = dr_lang('证书文件不可读').''.$cert;
} else {
$cert_body = (string)@file_get_contents($cert);
if (strpos($cert_body, 'BEGIN CERTIFICATE') === false) {
$errors[] = dr_lang('证书文件不是有效的 PEM 格式').''.$cert;
} elseif (function_exists('openssl_x509_read')) {
$x509 = @openssl_x509_read($cert_body);
if (!$x509) {
$errors[] = dr_lang('证书文件无法被 OpenSSL 解析').''.$cert;
}
}
}
if (!is_file($key)) {
$errors[] = dr_lang('密钥文件不存在').''.$key;
} elseif (!is_readable($key)) {
$errors[] = dr_lang('密钥文件不可读').''.$key;
} else {
$key_body = (string)@file_get_contents($key);
if (strpos($key_body, 'PRIVATE KEY') === false) {
$errors[] = dr_lang('密钥文件不是有效的 PEM 格式').''.$key;
} elseif (function_exists('openssl_pkey_get_private')) {
$pkey = @openssl_pkey_get_private($key_body);
if (!$pkey) {
$errors[] = dr_lang('密钥文件无法被 OpenSSL 解析').''.$key;
}
}
}
if ($errors) {
$this->_json(0, implode('<br>', $errors));
}
$this->_json(1, dr_lang('证书可用').''.$cert.' / '.$key);
}
}
@@ -0,0 +1,43 @@
<?php namespace Phpcmf\Controllers\Admin;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
class Payconfig extends \Phpcmf\Common
{
public function index() {
$data = \Phpcmf\Service::M()->db->table('member_setting')->where('name', 'pay')->get()->getRowArray();
$data = dr_string2array($data['value']);
if (IS_AJAX_POST) {
$post = \Phpcmf\Service::L('input')->post('data', true);
\Phpcmf\Service::M()->db->table('member_setting')->replace([
'name' => 'pay',
'value' => dr_array2string($post)
]);
\Phpcmf\Service::M('cache')->sync_cache('member'); // 自动更新缓存
$this->_json(1, dr_lang('操作成功'));
}
$page = intval(\Phpcmf\Service::L('input')->get('page'));
\Phpcmf\Service::V()->assign([
'data' => $data,
'page' => $page,
'form' => dr_form_hidden(['page' => $page]),
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'支付设置' => ['pay/payconfig/index', 'fa fa-cog'],
'help' => [625],
]
)
]);
\Phpcmf\Service::V()->display('payconfig.html');
}
}
+228
View File
@@ -0,0 +1,228 @@
<?php namespace Phpcmf\Controllers\Admin;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 资金流水
class Paylog extends \Phpcmf\Table
{
public function __construct()
{
parent::__construct();
// 支持附表存储
$this->is_data = 0;
// 模板前缀(避免混淆)
$this->my_field = array(
'title' => array(
'ismain' => 1,
'name' => dr_lang('关键字'),
'fieldname' => 'title',
'fieldtype' => 'Text',
'setting' => array(
'option' => array(
'width' => 200,
),
)
),
'touid' => array(
'ismain' => 1,
'name' => dr_lang('收款人'),
'fieldname' => 'touid',
'fieldtype' => 'Uid',
'setting' => array(
'option' => array(
'width' => 200,
),
)
),
'uid' => array(
'ismain' => 1,
'isint' => 1,
'name' => dr_lang('付款人'),
'fieldname' => 'uid',
'fieldtype' => 'Uid',
'setting' => array(
'option' => array(
'width' => 200,
),
)
),
);
// 表单显示名称
$this->name = dr_lang('资金流水');
// 初始化数据表
$this->_init([
'table' => 'member_paylog',
'field' => $this->my_field,
'order_by' => 'inputtime desc',
'date_field' => 'inputtime',
]);
\Phpcmf\Service::V()->assign([
'field' => $this->my_field,
]);
}
// index
public function index() {
\Phpcmf\Service::M()->set_where_list('`status`=1');
$this->_List();
\Phpcmf\Service::V()->assign([
'not_pay' => 1,
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'已付流水' => [ 'pay/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-calendar'],
'help' => [ 594 ],
]
),
]);
\Phpcmf\Service::V()->display('paylog_list.html');
}
// index
public function not_index() {
\Phpcmf\Service::M()->set_where_list('`status`=0');
$this->_List();
\Phpcmf\Service::V()->assign([
'not_pay' => 1,
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'未付流水' => ['pay/'.\Phpcmf\Service::L('Router')->class.'/not_index', 'fa fa-calendar'],
'help' => [ 595 ],
]
),
]);
\Phpcmf\Service::V()->display('paylog_list.html');
}
// edit
public function edit() {
list($tpl, $data) = $this->_Post((int)\Phpcmf\Service::L('input')->get('id'), [], 1);
if (!$data) {
$this->_admin_msg(0, dr_lang('支付记录不存在'));
}
if (!$data['status']) {
\Phpcmf\Service::V()->assign([
'data' => $data,
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'未付流水' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/not_index', 'fa fa-calendar'],
'付款详情' => [APP_DIR.'/'.\Phpcmf\Service::L('Router')->class.'/edit', 'fa fa-edit'],
]
),
'reply_url' => str_replace('m=index', 'm=not_index', \Phpcmf\Service::V()->get_value('reply_url'))
]);
} else {
\Phpcmf\Service::V()->assign([
'data' => $data,
'menu' => \Phpcmf\Service::M('auth')->_admin_menu(
[
'已付流水' => [ 'pay/'.\Phpcmf\Service::L('Router')->class.'/index', 'fa fa-calendar'],
'help' => [ 594 ],
]
),
]);
}
\Phpcmf\Service::V()->display('paylog_edit.html');
}
// 系统回收
public function system_edit() {
$id = (int)\Phpcmf\Service::L('input')->get('id');
$data = \Phpcmf\Service::M('Pay')->table('member_paylog')->get($id);
if (!$data) {
$this->_json(0, dr_lang('支付记录不存在'));
} elseif (1 != $data['status']) {
$this->_json(0, dr_lang('支付记录不满足回收条件'));
} elseif ($data['value'] < 0) {
$this->_json(0, dr_lang('付款金额不满足回收条件'));
} elseif ($data['mid'] != 'recharge') {
$this->_json(0, dr_lang('只能回收充值金额'));
} elseif (\Phpcmf\Service::M()->table('member_paylog')->where('mid', 'system-recovery-'.$id)->counts()) {
$this->_json(0, dr_lang('此交易已经被回收过'));
}
$user = \Phpcmf\Service::M('member')->table('member')->get($data['uid']);
if (!$user) {
$this->_json(0, dr_lang('用户记录不存在'));
}
if (IS_AJAX_POST) {
$post = \Phpcmf\Service::L('input')->post('data');
if ($user['money'] - $data['value'] < 0) {
$this->_json(0, dr_lang('付款账号余额不足'));
} elseif (!$post['note']) {
$this->_json(0, dr_lang('回收备注一定要填写'), ['field' => 'note']);
}
// 扣除付款方的钱
$rt = \Phpcmf\Service::M('Pay')->add_money($data['uid'], -$data['value']);
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
// 增加到交易流水
$rt = \Phpcmf\Service::M('Pay')->add_paylog([
'uid' => $data['uid'],
'touid' => 0,
'mid' => 'system-recovery-'.$id,
'title' => dr_lang('系统回收'),
'value' => -$data['value'],
'type' => 'finecms',
'status' => 1,
'result' => $post['note'],
'paytime' => SYS_TIME,
'inputtime' => SYS_TIME,
]);
if (!$rt['code']) {
$this->_json(0, $rt['msg']);
}
$this->_json(1, dr_lang('操作成功'));
}
\Phpcmf\Service::V()->assign([
'data' => $data,
'user' => $user,
'form' => dr_form_hidden(),
]);
\Phpcmf\Service::V()->display('paylog_system.html');exit;
}
// 短信催付
public function notice_del() {
$ids = \Phpcmf\Service::L('input')->get_post_ids();
if (!$ids) {
$this->_json(0, dr_lang('所选数据不存在'));
}
$sql = 'select phone from `'.\Phpcmf\Service::M()->dbprefix('member').'` where `id` in (select `uid` from `'.\Phpcmf\Service::M()->dbprefix('member_paylog').'` where `id` in ('.implode(',', $ids).') )';
$data = \Phpcmf\Service::M()->db->query($sql)->getResultArray();
if (!$data) {
$this->_json(0, dr_lang('所选数据不存在'));
}
$i = 0;
foreach ($data as $t) {
$rt = \Phpcmf\Service::M('member')->sendsms_text($t['phone'], dr_lang('您还有未付款的交易,请尽快付款;若已付,请忽略此消息'));
if ($rt['code']) {
$i ++;
}
}
$this->_json(1, dr_lang('已发送给%s个用户', $i));
}
// 删除
public function del() {
$this->_Del(
\Phpcmf\Service::L('input')->get_post_ids(),
null,
null,
\Phpcmf\Service::M()->dbprefix($this->init['table'])
);
}
}