Initial project files: BESCMS full source
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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'])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
|
||||
// 交易下单
|
||||
class Buy extends \Phpcmf\Common {
|
||||
|
||||
public function index() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!$id) {
|
||||
$this->_msg(0, dr_lang('商品id参数不能为空'));
|
||||
}
|
||||
|
||||
$fid = (int)\Phpcmf\Service::L('input')->get('fid');
|
||||
if (!$fid) {
|
||||
$this->_msg(0, dr_lang('支付字段fid参数不能为空'));
|
||||
}
|
||||
|
||||
$num = max(1, (int)\Phpcmf\Service::L('input')->get('num'));
|
||||
$sku = dr_safe_replace(\Phpcmf\Service::L('input')->get('sku'), 'undefined');
|
||||
|
||||
$field = $this->get_cache('table-field', $fid);
|
||||
if (!$field) {
|
||||
$this->_msg(0, dr_lang('支付字段[%s]不存在', $fid));
|
||||
}
|
||||
|
||||
// 获取付款价格
|
||||
$rt = \Phpcmf\Service::M('pay', 'pay')->get_pay_info($id, $field, $num, $sku);
|
||||
if (isset($rt['code']) && !$rt['code']) {
|
||||
$this->_msg(0, $rt['msg']);
|
||||
}
|
||||
|
||||
// 挂钩点 购买商品之前
|
||||
\Phpcmf\Hooks::trigger('member_buy_before', $rt);
|
||||
|
||||
\Phpcmf\Service::V()->assign($rt);
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'num' => $rt['num'],
|
||||
'price' => $rt['price'],
|
||||
'total' => $rt['total'],
|
||||
'total_price' => $rt['total'],
|
||||
'payform' => dr_payform($rt['mid'], $rt['total'], $rt['title'].$rt['sku_string'], $rt['url']),
|
||||
'meta_title' => dr_lang('在线付款').SITE_SEOJOIN.SITE_NAME,
|
||||
'meta_keywords' => $this->get_cache('site', SITE_ID, 'config', 'SITE_KEYWORDS'),
|
||||
'meta_description' => $this->get_cache('site', SITE_ID, 'config', 'SITE_DESCRIPTION')
|
||||
]);
|
||||
\Phpcmf\Service::V()->module('pay');
|
||||
if (!is_file(\Phpcmf\Service::V()->get_dir().'buy.html')) {
|
||||
\Phpcmf\Service::V()->module('api');
|
||||
}
|
||||
\Phpcmf\Service::V()->display('buy.html');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php namespace Phpcmf\Controllers;
|
||||
|
||||
class Home extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
// 付款
|
||||
public function index() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = \Phpcmf\Service::M()->table('member_paylog')->get($id);
|
||||
if (!$data) {
|
||||
$this->_msg(0, dr_lang('该账单不存在'));
|
||||
} elseif ($data['status'] == 1) {
|
||||
$this->_msg(0, dr_lang('该账单已被支付'));
|
||||
}
|
||||
|
||||
// 付钱之前再次验证
|
||||
if ($data['mid'] && strpos($data['mid'], 'my-') !== false) {
|
||||
list($rname, $rid, $fid, $num, $sku) = explode('-', $data['mid']);
|
||||
if ($rname == 'my') {
|
||||
list($app, $class) = explode('_', $rid);
|
||||
$classFile = dr_get_app_dir($app).'Models/'.ucfirst($class).'.php';
|
||||
if (is_file($classFile)) {
|
||||
$obj = \Phpcmf\Service::M($class, $app);
|
||||
if (method_exists($obj, 'paylog_before')) {
|
||||
$error = $obj->paylog_before($fid, $num, $sku, $data);
|
||||
if ($error) {
|
||||
$this->_msg(0, $error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0元支付
|
||||
if (empty($data['value'])) {
|
||||
$rt = \Phpcmf\Service::M('Pay','pay')->paysuccess(
|
||||
\Phpcmf\Service::M('Pay','pay')->get_pay_sn($data),
|
||||
0
|
||||
);
|
||||
if (!$rt['code']) {
|
||||
$this->_msg(0, $rt['msg'], $rt['data']['url']);
|
||||
}
|
||||
dr_redirect(ROOT_URL.'index.php?s=api&c=pay&m=call&id='.$rt['code']);exit;
|
||||
}
|
||||
|
||||
// 支付接口文件
|
||||
$apifile = ROOTPATH.'api/pay/'.$data['type'].'/pay.php';
|
||||
if (!is_file($apifile)) {
|
||||
$this->_msg(0, dr_lang('支付接口文件(%s)不存在', $data['type']));
|
||||
} elseif ($data['type'] != 'finecms' && (!isset($this->member_cache['payapi'][$data['type']]) || !$this->member_cache['payapi'][$data['type']])) {
|
||||
$this->_msg(0, dr_lang('支付接口(%s)未启用', $data['type']));
|
||||
}
|
||||
|
||||
// 发起支付
|
||||
$rt = \Phpcmf\Service::M('pay', 'pay')->dopay($apifile, $data);
|
||||
if (!$rt['code']) {
|
||||
$this->_msg(0, $rt['msg'], $rt['data']['url']);
|
||||
} elseif (isset($rt['data']['rturl']) && strlen($rt['data']['rturl']) > 10) {
|
||||
$this->_msg(1, $rt['msg'], $rt['data']['rturl']);
|
||||
}
|
||||
|
||||
// 请求模式下返回结果
|
||||
if (IS_API_HTTP || (\Phpcmf\Service::L('input')->get('is_ajax') || IS_API_HTTP || IS_AJAX)) {
|
||||
$this->_json(1, $rt['msg'], $rt['data']);
|
||||
}
|
||||
|
||||
// 运行模式直接输出代码
|
||||
switch ($rt['msg']) {
|
||||
case 'html':
|
||||
echo $rt['data'];
|
||||
exit;
|
||||
|
||||
case 'url':
|
||||
dr_redirect($rt['data']);
|
||||
break;
|
||||
}
|
||||
|
||||
$data['html'] = $rt['data'];
|
||||
if (SITE_IS_MOBILE && \Phpcmf\Service::IS_MOBILE_TPL()) {
|
||||
// 开启了移动端时,支付判断模板是否是移动端的
|
||||
\Phpcmf\Service::V()->init('mobile');
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'pay' => $data,
|
||||
'pay_name' => dr_pay_type_html($data['type']),
|
||||
'meta_title' => $data['title']
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::V()->module('pay');
|
||||
if (!is_file(\Phpcmf\Service::V()->get_dir().'pay.html')) {
|
||||
\Phpcmf\Service::V()->module('api');
|
||||
}
|
||||
\Phpcmf\Service::V()->display('pay.html');exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付接口js-ajax回调
|
||||
*/
|
||||
public function ajax() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
$data = \Phpcmf\Service::M()->table('member_paylog')->get($id);
|
||||
if (!$data) {
|
||||
$this->_jsonp(0, dr_lang('支付记录不存在'));
|
||||
} elseif ($data['status']) {
|
||||
$this->_jsonp(1, dr_lang('已经支付完成'));
|
||||
}
|
||||
|
||||
// 调用接口
|
||||
$apifile = ROOTPATH.'api/pay/'.$data['type'].'/notify_js.php';
|
||||
if (!is_file($apifile)) {
|
||||
$this->_jsonp(0, dr_lang('支付接口文件不存在'));
|
||||
}
|
||||
|
||||
$return = [];
|
||||
$result = dr_string2array($data['result']);
|
||||
|
||||
// 接口配置参数
|
||||
$config = $this->member_cache['payapi'][$data['type']];
|
||||
|
||||
require $apifile;
|
||||
|
||||
$this->_jsonp($return['code'], $return['msg']);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付接口返回
|
||||
*/
|
||||
public function call() {
|
||||
|
||||
$id = (int)\Phpcmf\Service::L('input')->get('id');
|
||||
if (!$id) {
|
||||
$this->_msg(0, dr_lang('支付ID号不存在'));
|
||||
}
|
||||
|
||||
$data = \Phpcmf\Service::M()->table('member_paylog')->get($id);
|
||||
if (!$data) {
|
||||
$this->_msg(0, dr_lang('支付记录[%s]不存在', $id));
|
||||
} elseif (!$data['status']) {
|
||||
$this->_msg(0, dr_lang('支付记录[%s]未完成支付', $id));
|
||||
}
|
||||
|
||||
// 支付回调钩子
|
||||
\Phpcmf\Hooks::trigger('pay_call', $data);
|
||||
|
||||
if (SITE_IS_MOBILE && \Phpcmf\Service::IS_MOBILE_TPL()) {
|
||||
// 开启了移动端时,支付判断模板是否是移动端的
|
||||
\Phpcmf\Service::V()->init('mobile');
|
||||
}
|
||||
|
||||
// 获取支付回调地址
|
||||
$url = \Phpcmf\Service::M('pay')->paycall_url($data);
|
||||
|
||||
$this->_msg(1, dr_lang('支付成功'), $url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php namespace Phpcmf\Controllers\Member;
|
||||
/**
|
||||
* https://www.besyun.com
|
||||
* BESCMS
|
||||
* 本文件是框架系统文件,二次开发时不可以修改本文件
|
||||
**/
|
||||
|
||||
class Pay extends \Phpcmf\Common
|
||||
{
|
||||
|
||||
/**
|
||||
* 提交支付账单
|
||||
*/
|
||||
public function index() {
|
||||
|
||||
if (IS_POST) {
|
||||
$pay = \Phpcmf\Service::L('input')->post('pay');
|
||||
$pay['uid'] = (int)$this->member['uid'];
|
||||
$pay['username'] = (string)$this->member['username'];
|
||||
$money = floatval($pay['money']);
|
||||
if (!$money) {
|
||||
$this->_msg(0, dr_lang('金额(%s)不正确', $money));
|
||||
exit;
|
||||
}
|
||||
$rt = \Phpcmf\Service::M('Pay')->post($pay);
|
||||
if (!$rt['code']) {
|
||||
$this->_msg(0, $rt['msg'], $rt['data']);
|
||||
}
|
||||
$url = PAY_URL.'index.php?s=pay&id='.$rt['code'];
|
||||
if (IS_API_HTTP || (\Phpcmf\Service::L('input')->get('is_ajax') || IS_API_HTTP || IS_AJAX)) {
|
||||
// 回调页面
|
||||
$this->_json($rt['code'], $url, $rt['data']);
|
||||
} else {
|
||||
// 跳转到支付页面,必须跳转到统一的主域名中付款
|
||||
dr_redirect($url, 'auto');
|
||||
}
|
||||
exit;
|
||||
} else {
|
||||
$this->_msg(0, dr_lang('POST请求错误'));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php namespace Phpcmf\Controllers\Member;
|
||||
|
||||
class Paylog extends \Phpcmf\Table
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
// 支持附表存储
|
||||
$this->is_data = 0;
|
||||
// 表单显示名称
|
||||
$this->name = dr_lang('资金流水');
|
||||
// 初始化数据表
|
||||
$this->_init([
|
||||
'table' => 'member_paylog',
|
||||
'order_by' => 'inputtime desc',
|
||||
'date_field' => 'inputtime',
|
||||
]);
|
||||
}
|
||||
|
||||
// index
|
||||
public function index() {
|
||||
|
||||
$tid = (int)\Phpcmf\Service::L('input')->get('tid');
|
||||
$where = ['`uid`='.$this->uid];
|
||||
switch ($tid) {
|
||||
case 1: // 收入
|
||||
$where[] = '`value` > 0';
|
||||
break;
|
||||
case -1: // 消费
|
||||
$where[] = '`value` < 0';
|
||||
break;
|
||||
default : // 全部
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($this->member_cache['pay']['year']) && $this->member_cache['pay']['year']) {
|
||||
$year = (int)$this->member_cache['pay']['year'];
|
||||
if ($year) {
|
||||
$where[] = 'inputtime > '.strtotime('-'.$year.' year');
|
||||
}
|
||||
}
|
||||
|
||||
\Phpcmf\Service::M()->set_where_list(implode(' AND ', $where));
|
||||
list($tpl, $data) = $this->_List(['tid' => $tid]);
|
||||
|
||||
// 初始化
|
||||
$data['param']['tid'] = $data['param']['total'] = 0;
|
||||
|
||||
// 列出类别
|
||||
$my = [];
|
||||
$type = ['0' => '全部', '1' => '收入', '-1' => '消费'];
|
||||
foreach ($type as $i => $t) {
|
||||
$data['param']['tid'] = $i;
|
||||
$my[$i] = [
|
||||
'name' => dr_lang($t),
|
||||
'url' => dr_member_url('pay/paylog/index', $data['param'])
|
||||
];
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'tid' => $tid,
|
||||
'type' => $my,
|
||||
]);
|
||||
|
||||
\Phpcmf\Service::V()->display('paylog_index.html');
|
||||
}
|
||||
|
||||
public function show() {
|
||||
|
||||
$id = \Phpcmf\Service::L('input')->get('id');
|
||||
if (strpos($id, '-') !== false) {
|
||||
list($a, $id) = explode('-', $id);
|
||||
}
|
||||
|
||||
list($a, $data) = $this->_Show((int)$id);
|
||||
if (!$data) {
|
||||
$this->_msg(0, dr_lang('交易记录不存在'));exit;
|
||||
} elseif ($data['uid'] != $this->uid) {
|
||||
$this->_msg(0, dr_lang('无权限查看'));exit;
|
||||
}
|
||||
|
||||
\Phpcmf\Service::V()->display('paylog_show.html');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php namespace Phpcmf\Controllers\Member;
|
||||
|
||||
class Recharge extends \Phpcmf\Common {
|
||||
|
||||
/**
|
||||
* 在线充值
|
||||
*/
|
||||
public function index() {
|
||||
define('FC_PAY', 1);
|
||||
$value = max(floatval(\Phpcmf\Service::L('input')->get('value')), floatval($this->member_cache['pay']['min']));
|
||||
\Phpcmf\Service::V()->assign([
|
||||
'payfield' => dr_payform('recharge', $value ? $value : '', '', '', 1),
|
||||
]);
|
||||
\Phpcmf\Service::V()->display('recharge_index.html');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user