This commit is contained in:
devil_gong 2018-09-27 18:30:14 +08:00
parent 076a83bb7d
commit dc9512ac1c
8 changed files with 113 additions and 34 deletions

View File

@ -2,6 +2,8 @@
namespace Admin\Controller; namespace Admin\Controller;
use Service\ResourcesService;
/** /**
* 支付方式管理 * 支付方式管理
* @author Devil * @author Devil
@ -62,8 +64,6 @@ class PaymentController extends CommonController
$data = []; $data = [];
if(is_dir($this->payment_dir)) if(is_dir($this->payment_dir))
{ {
$image_host = C('IMAGE_HOST');
$db = M('Payment');
if($dh = opendir($this->payment_dir)) if($dh = opendir($this->payment_dir))
{ {
while(($temp_file = readdir($dh)) !== false) while(($temp_file = readdir($dh)) !== false)
@ -81,18 +81,17 @@ class PaymentController extends CommonController
$temp['payment'] = $payment; $temp['payment'] = $payment;
// 获取数据库配置信息 // 获取数据库配置信息
$db_config = $db->where(['payment'=>$payment])->find(); $db_config = ResourcesService::PaymentList(['where'=>['payment'=>$payment]]);
if(!empty($db_config)) if(!empty($db_config[0]))
{ {
$temp['is_install'] = 1; $temp['is_install'] = 1;
$temp['id'] = $db_config['id']; $temp['id'] = $db_config[0]['id'];
$temp['name'] = $db_config['name']; $temp['name'] = $db_config[0]['name'];
$temp['logo'] = empty($db_config['logo']) ? '' : $image_host.$db_config['logo']; $temp['logo'] = $db_config[0]['logo'];
$temp['apply_terminal'] = empty($db_config['apply_terminal']) ? '' : json_decode($db_config['apply_terminal'], true); $temp['apply_terminal'] = $db_config[0]['apply_terminal'];
$temp['is_enable'] = $db_config['is_enable']; $temp['is_enable'] = $db_config[0]['is_enable'];
$temp['config'] = empty($db_config['config']) ? '' : json_decode($db_config['config'], true); $temp['config'] = $db_config[0]['config'];
} }
$data[] = $temp; $data[] = $temp;
} }
} }

View File

@ -0,0 +1,51 @@
<?php
namespace Home\Controller;
use Service\OrderService;
/**
* 订单管理
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class OrderController extends CommonController
{
/**
* [_initialize 前置操作-继承公共前置方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-03T12:39:08+0800
*/
public function _initialize()
{
// 调用父类前置方法
parent::_initialize();
// 是否登录
$this->Is_Login();
}
/**
* [Index 首页]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-02-25T15:30:36+0800
*/
public function Pay()
{
$params = $_REQUEST;
$params['user'] = $this->user;
echo '<pre>';
$ret = OrderService::Pay($params);
print_r($ret);
}
}
?>

View File

@ -275,7 +275,7 @@ function BuySubmitBack(e)
} }
setTimeout(function() setTimeout(function()
{ {
alert(e.data.id); window.location.href = e.data.pay_url;
}, 1500); }, 1500);
} else { } else {
$('form.form-validation').find('button[type="submit"]').button('reset'); $('form.form-validation').find('button[type="submit"]').button('reset');

View File

@ -186,6 +186,8 @@ class Alipay
public function Pay($params = []) public function Pay($params = [])
{ {
// 编写代码 // 编写代码
return 'Pay success';
} }
/** /**
@ -200,6 +202,8 @@ class Alipay
public function Respond($params = []) public function Respond($params = [])
{ {
// 编写代码 // 编写代码
return 'Respond success';
} }
} }
?> ?>

View File

@ -641,7 +641,12 @@ class BuyService
default : default :
$msg = L('common_operation_success'); $msg = L('common_operation_success');
} }
return DataReturn($msg, 0, $m->find($order_id));
$result = [
'order' => $m->find($order_id),
'pay_url' => U('Home/Order/Pay', ['id'=>$order_id]),
];
return DataReturn($msg, 0, $result);
} }
} }
?> ?>

View File

@ -3,6 +3,7 @@
namespace Service; namespace Service;
use Service\GoodsService; use Service\GoodsService;
use Service\ResourcesService;
/** /**
* 订单服务层 * 订单服务层
@ -26,11 +27,11 @@ class OrderService
{ {
if(empty($params['id'])) if(empty($params['id']))
{ {
return DataReturn('请选择订单', -1); return DataReturn('订单id有误', -1);
} }
$m = M('Order'); $m = M('Order');
$where = ['id'=>intval($params['id']), 'user_id' => $this->user['id']]; $where = ['id'=>intval($params['id']), 'user_id' => $params['user']['id']];
$data = $m->where($where)->field('id,status,total_price,payment_id')->find(); $data = $m->where($where)->field('id,status,total_price,payment_id')->find();
if(empty($data)) if(empty($data))
{ {
@ -46,6 +47,13 @@ class OrderService
return DataReturn('状态不可操作['.$status_text.']', -1); return DataReturn('状态不可操作['.$status_text.']', -1);
} }
// 支付方式
$payment = ResourcesService::PaymentList(['where'=>['id'=>$data['payment_id']]]);
if(empty($payment[0]))
{
return DataReturn('支付方式有误', -1);
}
// 发起支付 // 发起支付
$notify_url = __MY_URL__.'Notify/order.php'; $notify_url = __MY_URL__.'Notify/order.php';
$pay_data = array( $pay_data = array(
@ -55,7 +63,8 @@ class OrderService
'total_price' => $data['total_price'], 'total_price' => $data['total_price'],
'notify_url' => $notify_url, 'notify_url' => $notify_url,
); );
$pay = (new \Library\Payment\Alipay())->Pay($pay_data); $pay_name = '\Library\Payment\\'.$payment[0]['payment'];
$pay = (new $pay_name($payment[0]['config']))->Pay($pay_data);
if(empty($pay)) if(empty($pay))
{ {
return DataReturn('支付接口异常', -1); return DataReturn('支付接口异常', -1);

View File

@ -61,8 +61,8 @@ class ResourcesService
*/ */
public static function PaymentList($params = []) public static function PaymentList($params = [])
{ {
$where = ['is_enable'=>1]; $where = empty($params['where']) ? ['is_enable'=>1] : $params['where'];
$data = M('Payment')->where($where)->field('id,logo,name,sort,payment')->order('sort asc')->select(); $data = M('Payment')->where($where)->field('id,logo,name,sort,payment,config,apply_terminal,apply_terminal,element,is_enable')->order('sort asc')->select();
if(!empty($data) && is_array($data)) if(!empty($data) && is_array($data))
{ {
$images_host = C('IMAGE_HOST'); $images_host = C('IMAGE_HOST');
@ -70,6 +70,9 @@ class ResourcesService
{ {
$v['logo_old'] = $v['logo']; $v['logo_old'] = $v['logo'];
$v['logo'] = empty($v['logo']) ? null : $images_host.$v['logo']; $v['logo'] = empty($v['logo']) ? null : $images_host.$v['logo'];
$v['element'] = empty($v['element']) ? '' : json_decode($v['element'], true);
$v['config'] = empty($v['config']) ? '' : json_decode($v['config'], true);
$v['apply_terminal'] = empty($v['apply_terminal']) ? '' : json_decode($v['apply_terminal'], true);
} }
} }
return $data; return $data;

File diff suppressed because one or more lines are too long