feat/task1-c-wallet
devil_gong 2018-09-29 13:12:14 +08:00
parent 4d8a164398
commit 6e30e405b2
39 changed files with 174 additions and 67 deletions

View File

@ -14,6 +14,7 @@ use Service\ResourcesService;
class PaymentController extends CommonController
{
private $payment_dir;
private $payment_business_type_all;
/**
* [_initialize 前置操作-继承公共前置方法]
@ -35,6 +36,9 @@ class PaymentController extends CommonController
// 插件目录
$this->payment_dir = APP_PATH.'Library'.DS.'Payment'.DS;
// 支付业务类型
$this->payment_business_type_all = C('payment_business_type_all');
}
/**
@ -279,6 +283,28 @@ class PaymentController extends CommonController
}
}
/**
* [PowerCheck 权限校验]
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-09-29T00:01:49+0800
*/
private function PowerCheck()
{
// 主目录权限
if(!is_writable(ROOT_PATH))
{
$this->ajaxReturn(L('common_is_writable_error').'['.ROOT_PATH.']', -3);
}
// 插件权限
if(!is_writable($this->payment_dir))
{
$this->ajaxReturn(L('common_is_writable_error').'['.$this->payment_dir.']', -3);
}
}
/**
* 安装
* @author Devil
@ -294,6 +320,9 @@ class PaymentController extends CommonController
$this->error(L('common_unauthorized_access'));
}
// 权限
$this->PowerCheck();
// 参数
if(empty($_POST['id']))
{
@ -317,6 +346,9 @@ class PaymentController extends CommonController
{
if($m->add($data))
{
// 入口文件生成
$this->PaymentEntranceCreated($payment);
$this->ajaxReturn(L('common_install_success'));
} else {
$this->ajaxReturn(L('common_install_error'), -100);
@ -351,8 +383,12 @@ class PaymentController extends CommonController
}
// 开始卸载
if(M('Payment')->where(['payment'=>I('id')])->delete())
$payment = I('id');
if(M('Payment')->where(['payment'=>$payment])->delete())
{
// 删除入口文件
$this->PaymentEntranceDelete($payment);
$this->ajaxReturn(L('common_uninstall_success'));
} else {
$this->ajaxReturn(L('common_uninstall_error'), -100);
@ -374,6 +410,9 @@ class PaymentController extends CommonController
$this->error(L('common_unauthorized_access'));
}
// 权限
$this->PowerCheck();
// 参数
if(empty($_POST['id']))
{
@ -381,7 +420,8 @@ class PaymentController extends CommonController
}
// 是否存在
$file = $this->payment_dir.I('id').'.class.php';
$payment = I('id');
$file = $this->payment_dir.$payment.'.class.php';
if(!file_exists($file))
{
$this->ajaxReturn(L('common_data_no_exist_error'), -2);
@ -398,6 +438,9 @@ class PaymentController extends CommonController
$this->ajaxReturn(L('common_operation_delete_error'), -100);
}
// 删除入口文件
$this->PaymentEntranceDelete($payment);
$this->ajaxReturn(L('common_operation_delete_success'));
}
@ -417,6 +460,9 @@ class PaymentController extends CommonController
$this->error(L('common_unauthorized_access'));
}
// 权限
$this->PowerCheck();
// 文件上传校验
$error = FileUploadError('file');
if($error !== true)
@ -453,5 +499,98 @@ class PaymentController extends CommonController
}
$this->ajaxReturn(L('common_upload_success'));
}
/**
* [PaymentEntranceCreated 入口文件创建]
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-09-28T23:38:52+0800
* @param [string] $payment [支付唯一标记]
*/
private function PaymentEntranceCreated($payment)
{
// 批量创建
foreach($this->payment_business_type_all as $v)
{
// 异步
$notify=<<<php
<?php
/**
* {$v['desc']}支付异步入口
*/
// 默认绑定模块
\$_GET['m'] = 'Api';
\$_GET['c'] = '{$v['name']}Notify';
\$_GET['a'] = 'Notify';
// 支付模块标记
define('PAYMENT_TYPE', '{$payment}');
// 引入公共入口文件
require './core.php';
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
?>
php;
// 同步
$respond=<<<php
<?php
/**
* {$v['desc']}支付同步入口
*/
// 默认绑定模块
\$_GET['m'] = 'Home';
\$_GET['c'] = '{$v['name']}';
\$_GET['a'] = 'Respond';
// 支付模块标记
define('PAYMENT_TYPE', '{$payment}');
// 引入公共入口文件
require './core.php';
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
?>
php;
$name = strtolower($v['name']);
@file_put_contents(ROOT_PATH.'payment_'.$name.'_'.strtolower($payment).'_notify.php', $notify);
@file_put_contents(ROOT_PATH.'payment_'.$name.'_'.strtolower($payment).'_respond.php', $respond);
}
}
/**
* [PaymentEntranceDelete 入口文件删除]
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2018-09-28T23:38:52+0800
* @param [string] $payment [支付唯一标记]
*/
private function PaymentEntranceDelete($payment)
{
$payment = strtolower($payment);
foreach($this->payment_business_type_all as $v)
{
$name = strtolower($v['name']);
if(file_exists(ROOT_PATH.'payment_'.$name.'_'.$payment.'_notify.php'))
{
@unlink(ROOT_PATH.'payment_'.$name.'_'.$payment.'_notify.php');
}
if(file_exists(ROOT_PATH.'payment_'.$name.'_'.$payment.'_respond.php'))
{
@unlink(ROOT_PATH.'payment_'.$name.'_'.$payment.'_respond.php');
}
}
}
}
?>

View File

@ -114,22 +114,19 @@ return array(
// 图片host, 数据库图片地址以/Public/...开头
'IMAGE_HOST' => substr(__MY_URL__, 0, -1),
'IMAGE_HOST' => substr(__MY_URL__, 0, -1),
// 缓存路径
'data_cache_dir' => TEMP_PATH,
'data_cache_dir' => TEMP_PATH,
// 开启U带域名
'url_domain_deploy' => true,
'url_domain_deploy' => true,
// 支付宝appid
'alipay_mini_appid' => '2018071160553916',
'alipay_mini_appid' => '2018071160553916',
// 支付宝密钥
'alipay_key_secret' =>
[
'id' => '2088131739974941',
'key' => 'tbhpeal8zsqzxc0b5s6r2jrvzjoo74il',
'name' => 'byjzglm@dingtalk.com',
],
// 支付业务类型,支付插件根据业务类型自动生成支付入口文件
'payment_business_type_all' => [
['name' => 'Order', 'desc' => '订单'],
],
);

View File

View File

View File

View File

View File

View File

0
service/Application/Home/Lang/zh-cn/buy.php Normal file → Executable file
View File

0
service/Application/Home/Lang/zh-cn/useraddress.php Normal file → Executable file
View File

0
service/Application/Home/View/Default/Buy/Index.html Normal file → Executable file
View File

0
service/Application/Home/View/Default/Cart/Index.html Normal file → Executable file
View File

View File

View File

0
service/Application/Home/View/Default/Order/Index.html Normal file → Executable file
View File

View File

View File

View File

View File

View File

0
service/Application/Library/Payment/Alipay.class.php Normal file → Executable file
View File

View File

View File

0
service/Application/Service/BuyService.class.php Normal file → Executable file
View File

71
service/Application/Service/OrderService.class.php Normal file → Executable file
View File

@ -69,13 +69,14 @@ class OrderService
}
// 发起支付
$url = __MY_URL__.'payment_order_'.strtolower($payment[0]['payment']);
$pay_data = array(
'out_user' => md5($params['user']['id']),
'order_sn' => date('YmdHis').$data['id'],
'name' => '订单支付',
'total_price' => $data['total_price'],
'notify_url' => __MY_URL__.'notify_order.php',
'call_back_url' => __MY_URL__.'respond_order.php',
'notify_url' => $url.'_notify.php',
'call_back_url' => $url.'_respond.php',
);
$pay_name = '\Library\Payment\\'.$payment[0]['payment'];
$ret = (new $pay_name($payment[0]['config']))->Pay($pay_data);
@ -106,11 +107,6 @@ class OrderService
'key_name' => 'user',
'error_msg' => '用户信息有误',
],
[
'checked_type' => 'empty',
'key_name' => 'out_trade_no',
'error_msg' => '支付回调参数缺失[out_trade_no]',
],
];
$ret = params_checked($params, $p);
if($ret !== true)
@ -118,28 +114,15 @@ class OrderService
return DataReturn($ret, -1);
}
// 获取订单信息
$where = ['id'=>self::OutTradeNoParsing($params['out_trade_no']), 'user_id' => $params['user']['id']];
$data = M('Order')->where($where)->field('id,status,payment_id')->find();
if(empty($data))
{
return DataReturn(L('common_data_no_exist_error'), -1);
}
if($data['status'] > 1)
{
$status_text = L('common_order_user_status')[$data['status']]['name'];
return DataReturn('状态不可操作['.$status_text.']', -1);
}
// 支付方式
$payment = ResourcesService::PaymentList(['where'=>['id'=>$data['payment_id']]]);
$payment = ResourcesService::PaymentList(['where'=>['payment'=>PAYMENT_TYPE]]);
if(empty($payment[0]))
{
return DataReturn('支付方式有误', -1);
}
// 支付数据校验
$pay_name = '\Library\Payment\\'.$payment[0]['payment'];
$pay_name = '\Library\Payment\\'.PAYMENT_TYPE;
return (new $pay_name($payment[0]['config']))->Respond();
}
@ -154,24 +137,24 @@ class OrderService
*/
public static function Notify($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'out_trade_no',
'error_msg' => '支付回调参数缺失[out_trade_no]',
],
];
$ret = params_checked($params, $p);
if($ret !== true)
// 支付方式
$payment = ResourcesService::PaymentList(['where'=>['payment'=>PAYMENT_TYPE]]);
if(empty($payment[0]))
{
file_put_contents('/data/www/project/shopxo/service/gggggg.txt', json_encode($_REQUEST));
return DataReturn($ret, -1);
return DataReturn('支付方式有误', -1);
}
// 支付数据校验
$pay_name = '\Library\Payment\\'.PAYMENT_TYPE;
$ret = (new $pay_name($payment[0]['config']))->Respond();
if(!isset($ret['code']) || $ret['code'] != 0)
{
return $ret;
}
// 获取订单信息
$m = M('Order');
$where = ['id'=>self::OutTradeNoParsing($params['out_trade_no'])];
$where = ['id'=>self::OutTradeNoParsing($ret['data']['out_trade_no'])];
$data = $m->where($where)->field('id,status,total_price,payment_id,user_id,shop_id')->find();
file_put_contents('/data/www/project/shopxo/service/dddddd.txt', json_encode($data));
if(empty($data))
@ -184,22 +167,6 @@ class OrderService
return DataReturn('状态不可操作['.$status_text.']', 0);
}
// 支付方式
$payment = ResourcesService::PaymentList(['where'=>['id'=>$data['payment_id']]]);
if(empty($payment[0]))
{
return DataReturn('支付方式有误', -1);
}
// 支付数据校验
$pay_name = '\Library\Payment\\'.$payment[0]['payment'];
$ret = (new $pay_name($payment[0]['config']))->Respond();
if(!isset($ret['code']) || $ret['code'] != 0)
{
return $ret;
}
file_put_contents('/data/www/project/shopxo/service/rrrrrr.txt', json_encode($ret));
// 兼容web版本支付参数
$buyer_email = isset($ret['data']['buyer_logon_id']) ? $ret['data']['buyer_logon_id'] : (isset($ret['data']['buyer_email']) ? $ret['data']['buyer_email'] : '');
$total_amount = isset($ret['data']['total_amount']) ? $ret['data']['total_amount'] : (isset($ret['data']['total_fee']) ? $ret['data']['total_fee'] : '');
@ -217,7 +184,6 @@ class OrderService
'business_type' => 0,
'add_time' => time(),
];
file_put_contents('/data/www/project/shopxo/service/llllll.txt', json_encode($pay_log_data));
M('PayLog')->add($pay_log_data);
// 消息通知
@ -235,7 +201,6 @@ class OrderService
'pay_time' => time(),
'upd_time' => time(),
);
file_put_contents('/data/www/project/shopxo/service/uuuuuu.txt', json_encode($upd_data));
if($m->where(['id'=>$data['id']])->save($upd_data))
{
// 提交事务

0
service/Application/Service/ResourcesService.class.php Normal file → Executable file
View File

0
service/Application/Service/SearchService.class.php Normal file → Executable file
View File

0
service/Application/Service/UserService.class.php Normal file → Executable file
View File

0
service/Public/Home/Default/Css/Buy.css Normal file → Executable file
View File

0
service/Public/Home/Default/Css/Cart.css Normal file → Executable file
View File

0
service/Public/Home/Default/Css/Category.css Normal file → Executable file
View File

View File

@ -416,7 +416,7 @@ background:url(../Images/ibar_sprites.png) no-repeat;background-position:0px -23
/* 公共错误提示页面 */
.tips-error, .tips-success { margin: 10% 0; }
.tips-pay-success, .tips-pay-error { box-shadow: none; text-align: center; }
.tips-error i.am-icon-times-circle, .tips-success i.am-icon-check-circle { font-size: 32px; }
.tips-error i.am-icon-times-circle, .tips-success i.am-icon-check-circle { font-size: 26px; }
.tips-error i.am-icon-times-circle { color: #F44336; }
.tips-success i.am-icon-check-circle { color: #4CAF50; }
.tips-error span.msg, .tips-success span.msg { font-size: 22px; margin-left: 10px; }

0
service/Public/Home/Default/Css/UserAddress.css Normal file → Executable file
View File

0
service/Public/Home/Default/Js/Buy.js Normal file → Executable file
View File

0
service/Public/Home/Default/Js/Cart.js Normal file → Executable file
View File

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -9,6 +9,9 @@ $_GET['m'] = 'Api';
$_GET['c'] = 'OrderNotify';
$_GET['a'] = 'Notify';
// 支付模块标记
define('PAYMENT_TYPE', 'Alipay');
// 引入公共入口文件
require './core.php';

View File

@ -9,6 +9,9 @@ $_GET['m'] = 'Home';
$_GET['c'] = 'Order';
$_GET['a'] = 'Respond';
// 支付模块标记
define('PAYMENT_TYPE', 'Alipay');
// 引入公共入口文件
require './core.php';