作者 景龙
1 个管道 的构建 失败 耗费 2 秒

增加从余额支付

... ... @@ -6,7 +6,7 @@ use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
* 系统消息接口
* 系统消息接口**
*/
class Smessages extends Api
{
... ...
... ... @@ -40,6 +40,7 @@ class Wxpay extends Api
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="openid", type="string", required=true, description="小程序openid")
* @ApiParams (name="pay_order_sn", type="string", required=true, description="支付订单号")
* @ApiParams (name="type", type="integer", required=true, description="支付方式(0:微信支付,1:余额支付)")
* @ApiReturn ({code: 0, msg: "无效的订单", time: "1554176100", data: null})
*/
public function pay(){
... ... @@ -48,8 +49,11 @@ class Wxpay extends Api
$pay = Pay::wechat(Service::getConfig('wechat'));
$openid = $this->request->post('openid');//小程序传递openid
$pay_order_sn = $this->request->post('pay_order_sn');//支付订单号
if(empty($openid) && empty($pay_order_sn)){
$this->error('无效的参数');
$type = $this->request->post('type');//支付方式(wx:微信支付,balance:余额支付)
$rule = config('site.pay');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['openid'=>$openid,'pay_order_sn'=>$pay_order_sn,'type'=>$type])) {
$this->error($validate->getError());
}
//查询订单是否已支付
$is_pay = Db::table('gc_porder')
... ... @@ -71,17 +75,44 @@ class Wxpay extends Api
foreach ($exist as $value) {
$total_price += $value['total_price'];
}
//构建订单信息
$order = [
'out_trade_no' => $pay_order_sn,//支付订单号
'body' => '广西小纸皮再生资源回收有限公司',
'total_fee' => 1,
if($type == 'wx'){
//构建订单信息
$order = [
'out_trade_no' => $pay_order_sn,//支付订单号
'body' => '广西小纸皮再生资源回收有限公司',
'total_fee' => 1,
// 'total_fee' => floatval($total_price)*100,//单位:分
'openid' => $openid,
'notify_url' => url('api/Wxpay/notify','','',true),
];
//跳转或输出
$this->success('成功',$pay->miniapp($order));
'openid' => $openid,
'notify_url' => url('api/Wxpay/notify','','',true),
];
//跳转或输出
$this->success('成功',$pay->miniapp($order));
}else if($type == 'balance'){
//从余额扣取
$userModel = new User();
$user = $userModel->where(['openid'=>$openid])->find();
if(!$user){
$this->error('未找到该用户');
}
if($user['money'] < $total_price){
$this->error('余额不足');
}
//从账户扣取费用
$sur_money = $user['money'] - $total_price;
$res = $userModel->where(['openid'=>$openid])->update(['money'=>$sur_money]);
//更新订单状态
$porderModel = new Porder();
$res1 = $porderModel->where(['pay_order_sn'=>$pay_order_sn])->update(['status'=>$this->order_status[1]]);
//减库存,删相应购物车记录
$this->handle($pay_order_sn,$openid);
if($res && $res1){
$this->success('成功');
}else{
$this->error('失败');
}
}else{
$this->error('支付方式有误');
}
}else{
$this->error('请求方式错误');
... ... @@ -133,6 +164,7 @@ class Wxpay extends Api
try {
$data = $pay->verify();
if($data['result_code'] == 'SUCCESS' && $data['return_code'] == 'SUCCESS'){
//更新订单状态
$porderModel = new Porder();
$porderModel->where(['pay_order_sn'=>$data['out_trade_no']])->update(['status'=>$this->order_status[1]]);
//减库存,删相应购物车记录
... ... @@ -249,7 +281,7 @@ class Wxpay extends Api
* @param $pay_order_sn
* @param $openid
*/
public function handle($pay_order_sn,$openid){
private function handle($pay_order_sn,$openid){
//查询订单信息的商品id,数量num
$data = Db::table('gc_porder')
->where(['pay_order_sn'=>$pay_order_sn])
... ...
... ... @@ -294,4 +294,16 @@ return array (
'open_bank' => '开户行最多不超过10个字符',
]
],
'pay' => [
'rule' => [
'openid' => 'require',
'pay_order_sn' => 'require',
'type' => 'require',
],
'msg' => [
'openid.require' => 'openid不能为空',
'pay_order_sn.require' => '支付单号不能为空',
'type' => '请选择支付类型',
]
],
);
\ No newline at end of file
... ...
... ... @@ -27,7 +27,6 @@
</head>
<body id="page-top">
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
... ... @@ -38,17 +37,17 @@
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-menu">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://www.fastadmin.net" target="_blank">{:__('Home')}</a></li>
<li><a href="https://www.fastadmin.net/store.html" target="_blank">{:__('Store')}</a></li>
<li><a href="https://www.fastadmin.net/wxapp.html" target="_blank">{:__('Wxapp')}</a></li>
<li><a href="https://www.fastadmin.net/service.html" target="_blank">{:__('Services')}</a></li>
<li><a href="https://www.fastadmin.net/download.html" target="_blank">{:__('Download')}</a></li>
<li><a href="https://www.fastadmin.net/demo.html" target="_blank">{:__('Demo')}</a></li>
<li><a href="https://www.fastadmin.net/donate.html" target="_blank">{:__('Donation')}</a></li>
<li><a href="https://forum.fastadmin.net" target="_blank">{:__('Forum')}</a></li>
<li><a href="https://doc.fastadmin.net" target="_blank">{:__('Docs')}</a></li>
</ul>
<!--<ul class="nav navbar-nav navbar-right">-->
<!--<li><a href="https://www.fastadmin.net" target="_blank">{:__('Home')}</a></li>-->
<!--<li><a href="https://www.fastadmin.net/store.html" target="_blank">{:__('Store')}</a></li>-->
<!--<li><a href="https://www.fastadmin.net/wxapp.html" target="_blank">{:__('Wxapp')}</a></li>-->
<!--<li><a href="https://www.fastadmin.net/service.html" target="_blank">{:__('Services')}</a></li>-->
<!--<li><a href="https://www.fastadmin.net/download.html" target="_blank">{:__('Download')}</a></li>-->
<!--<li><a href="https://www.fastadmin.net/demo.html" target="_blank">{:__('Demo')}</a></li>-->
<!--<li><a href="https://www.fastadmin.net/donate.html" target="_blank">{:__('Donation')}</a></li>-->
<!--<li><a href="https://forum.fastadmin.net" target="_blank">{:__('Forum')}</a></li>-->
<!--<li><a href="https://doc.fastadmin.net" target="_blank">{:__('Docs')}</a></li>-->
<!--</ul>-->
</div>
<!-- /.navbar-collapse -->
</div>
... ... @@ -63,8 +62,8 @@
<div class="header-content-inner">
<h1>FastAdmin</h1>
<h3>{:__('The fastest framework based on ThinkPHP5 and Bootstrap')}</h3>
<a href="{:url('admin/index/login')}" class="btn btn-warning btn-xl page-scroll">{:__('Go to Dashboard')}</a>
<a href="{:url('index/user/index')}" class="btn btn-outline btn-xl page-scroll">{:__('Go to Member center')}</a>
<!--<a href="{:url('admin/index/login')}" class="btn btn-warning btn-xl page-scroll">{:__('Go to Dashboard')}</a>-->
<!--<a href="{:url('index/user/index')}" class="btn btn-outline btn-xl page-scroll">{:__('Go to Member center')}</a>-->
</div>
</div>
</div>
... ... @@ -72,95 +71,95 @@
</div>
</header>
<section id="features" class="features">
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<div class="section-heading">
<h2>{:__('Features')}</h2>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<div class="feature-item">
<i class="icon-user text-primary"></i>
<h3>{:__('Auth')}</h3>
<p class="text-muted">{:__('Auth tips')}</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<i class="icon-screen-smartphone text-primary"></i>
<h3>{:__('Responsive')}</h3>
<p class="text-muted">{:__('Responsive tips')}</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<i class="icon-present text-primary"></i>
<h3>{:__('Languages')}</h3>
<p class="text-muted">{:__('Languages tips')}</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<i class="icon-layers text-primary"></i>
<h3>{:__('Module')}</h3>
<p class="text-muted">{:__('Module tips')}</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<i class="icon-docs text-primary"></i>
<h3>{:__('CRUD')}</h3>
<p class="text-muted">{:__('CRUD tips')}</p>
</div>
</div>
<div class="col-md-4">
<div class="feature-item">
<i class="icon-puzzle text-primary"></i>
<h3>{:__('Extension')}</h3>
<p class="text-muted">{:__('Extension tips')}</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section class="cta">
<div class="cta-content">
<div class="container">
<h2>{:__('Do not hesitate')}<br>{:__('Start to act')}</h2>
<a href="https://doc.fastadmin.net/docs/contributing.html" class="btn btn-outline btn-xl page-scroll">{:__('Contribution')}</a>
</div>
</div>
<div class="overlay"></div>
</section>
<footer>
<div class="container">
<!-- FastAdmin是开源程序,建议在您的网站底部保留一个FastAdmin的链接 -->
<p>&copy; 2017-2018 <a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>. All Rights Reserved.</p>
<ul class="list-inline">
<li>
<a href="https://gitee.com/karson/fastadmin">{:__('Gitee')}</a>
</li>
<li>
<a href="https://github.com/karsonzhang/fastadmin">{:__('Github')}</a>
</li>
<li>
<a href="https://shang.qq.com/wpa/qunwpa?idkey=46c326e570d0f97cfae1f8257ae82322192ec8841c79b2136446df0b3b62028c">{:__('QQ group')}</a>
</li>
</ul>
</div>
</footer>
<!--<section id="features" class="features">-->
<!--<div class="container">-->
<!--<div class="row">-->
<!--<div class="col-lg-12 text-center">-->
<!--<div class="section-heading">-->
<!--<h2>{:__('Features')}</h2>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--<div class="row">-->
<!--<div class="col-md-12">-->
<!--<div class="container-fluid">-->
<!--<div class="row">-->
<!--<div class="col-md-4">-->
<!--<div class="feature-item">-->
<!--<i class="icon-user text-primary"></i>-->
<!--<h3>{:__('Auth')}</h3>-->
<!--<p class="text-muted">{:__('Auth tips')}</p>-->
<!--</div>-->
<!--</div>-->
<!--<div class="col-md-4">-->
<!--<div class="feature-item">-->
<!--<i class="icon-screen-smartphone text-primary"></i>-->
<!--<h3>{:__('Responsive')}</h3>-->
<!--<p class="text-muted">{:__('Responsive tips')}</p>-->
<!--</div>-->
<!--</div>-->
<!--<div class="col-md-4">-->
<!--<div class="feature-item">-->
<!--<i class="icon-present text-primary"></i>-->
<!--<h3>{:__('Languages')}</h3>-->
<!--<p class="text-muted">{:__('Languages tips')}</p>-->
<!--</div>-->
<!--</div>-->
<!--<div class="col-md-4">-->
<!--<div class="feature-item">-->
<!--<i class="icon-layers text-primary"></i>-->
<!--<h3>{:__('Module')}</h3>-->
<!--<p class="text-muted">{:__('Module tips')}</p>-->
<!--</div>-->
<!--</div>-->
<!--<div class="col-md-4">-->
<!--<div class="feature-item">-->
<!--<i class="icon-docs text-primary"></i>-->
<!--<h3>{:__('CRUD')}</h3>-->
<!--<p class="text-muted">{:__('CRUD tips')}</p>-->
<!--</div>-->
<!--</div>-->
<!--<div class="col-md-4">-->
<!--<div class="feature-item">-->
<!--<i class="icon-puzzle text-primary"></i>-->
<!--<h3>{:__('Extension')}</h3>-->
<!--<p class="text-muted">{:__('Extension tips')}</p>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</section>-->
<!--<section class="cta">-->
<!--<div class="cta-content">-->
<!--<div class="container">-->
<!--<h2>{:__('Do not hesitate')}<br>{:__('Start to act')}</h2>-->
<!--<a href="https://doc.fastadmin.net/docs/contributing.html" class="btn btn-outline btn-xl page-scroll">{:__('Contribution')}</a>-->
<!--</div>-->
<!--</div>-->
<!--<div class="overlay"></div>-->
<!--</section>-->
<!--<footer>-->
<!--<div class="container">-->
<!--&lt;!&ndash; FastAdmin是开源程序,建议在您的网站底部保留一个FastAdmin的链接 &ndash;&gt;-->
<!--<p>&copy; 2017-2018 <a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>. All Rights Reserved.</p>-->
<!--<ul class="list-inline">-->
<!--<li>-->
<!--<a href="https://gitee.com/karson/fastadmin">{:__('Gitee')}</a>-->
<!--</li>-->
<!--<li>-->
<!--<a href="https://github.com/karsonzhang/fastadmin">{:__('Github')}</a>-->
<!--</li>-->
<!--<li>-->
<!--<a href="https://shang.qq.com/wpa/qunwpa?idkey=46c326e570d0f97cfae1f8257ae82322192ec8841c79b2136446df0b3b62028c">{:__('QQ group')}</a>-->
<!--</li>-->
<!--</ul>-->
<!--</div>-->
<!--</footer>-->
<!-- jQuery -->
<script src=https://cdn.staticfile.org/jquery/2.1.4/jquery.min.js></script>
... ...
... ... @@ -245,8 +245,8 @@
<div class="child collapse" id="卖废品接口**">
<a href="javascript:;" data-id="57" class="list-group-item">卖废品信息添加</a>
</div>
<a href="#系统消息接口" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">系统消息接口 <i class="fa fa-caret-down"></i></a>
<div class="child collapse" id="系统消息接口">
<a href="#系统消息接口**" class="list-group-item" data-toggle="collapse" data-parent="#sidebar">系统消息接口** <i class="fa fa-caret-down"></i></a>
<div class="child collapse" id="系统消息接口**">
<a href="javascript:;" data-id="58" class="list-group-item">系统消息列表</a>
<a href="javascript:;" data-id="59" class="list-group-item">系统消息详情</a>
</div>
... ... @@ -296,7 +296,6 @@
<a href="javascript:;" data-id="86" class="list-group-item">充值</a>
<a href="javascript:;" data-id="87" class="list-group-item">微信异步通知(不需调用)</a>
<a href="javascript:;" data-id="88" class="list-group-item">分享购买成功调用,增加积分并获得相应的积分</a>
<a href="javascript:;" data-id="89" class="list-group-item">支付完成处理库存,购物车(不需调用)</a>
</div>
</div>
</div>
... ... @@ -8106,7 +8105,7 @@
</div>
</div>
</div>
<h2>系统消息接口</h2>
<h2>系统消息接口**</h2>
<hr>
<div class="panel panel-default">
<div class="panel-heading" id="heading-58">
... ... @@ -11316,6 +11315,12 @@
<td></td>
<td>支付订单号</td>
</tr>
<tr>
<td>type</td>
<td>integer</td>
<td></td>
<td>支付方式(0:微信支付,1:余额支付)</td>
</tr>
</tbody>
</table>
</div>
... ... @@ -11354,6 +11359,10 @@
<input type="string" class="form-control input-sm" id="pay_order_sn" required placeholder="支付订单号" name="pay_order_sn">
</div>
<div class="form-group">
<label class="control-label" for="type">type</label>
<input type="integer" class="form-control input-sm" id="type" required placeholder="支付方式(0:微信支付,1:余额支付)" name="type">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success send" rel="83">提交</button>
<button type="reset" class="btn btn-info" rel="83">重置</button>
</div>
... ... @@ -12008,133 +12017,13 @@
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" id="heading-89">
<h4 class="panel-title">
<span class="label label-success">GET</span>
<a data-toggle="collapse" data-parent="#accordion89" href="#collapseOne89"> 支付完成处理库存,购物车(不需调用) <span class="text-muted">/api/wxpay/handle</span></a>
</h4>
</div>
<div id="collapseOne89" class="panel-collapse collapse">
<div class="panel-body">
<!-- Nav tabs -->
<ul class="nav nav-tabs" id="doctab89">
<li class="active"><a href="#info89" data-toggle="tab">基础信息</a></li>
<li><a href="#sandbox89" data-toggle="tab">在线测试</a></li>
<li><a href="#sample89" data-toggle="tab">返回示例</a></li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="info89">
<div class="well">
支付完成处理库存,购物车(不需调用) </div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Headers</strong></div>
<div class="panel-body">
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>参数</strong></div>
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必选</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>$pay_order_sn</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>$openid</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>正文</strong></div>
<div class="panel-body">
</div>
</div>
</div><!-- #info -->
<div class="tab-pane" id="sandbox89">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading"><strong>参数</strong></div>
<div class="panel-body">
<form enctype="application/x-www-form-urlencoded" role="form" action="/api/wxpay/handle" method="get" name="form89" id="form89">
<div class="form-group">
<label class="control-label" for=""></label>
<input type="$pay_order_sn" class="form-control input-sm" id="" required placeholder="" name="">
</div>
<div class="form-group">
<label class="control-label" for=""></label>
<input type="$openid" class="form-control input-sm" id="" required placeholder="" name="">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success send" rel="89">提交</button>
<button type="reset" class="btn btn-info" rel="89">重置</button>
</div>
</form>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>响应输出</strong></div>
<div class="panel-body">
<div class="row">
<div class="col-md-12" style="overflow-x:auto">
<pre id="response_headers89"></pre>
<pre id="response89"></pre>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>返回参数</strong></div>
<div class="panel-body">
</div>
</div>
</div>
</div>
</div><!-- #sandbox -->
<div class="tab-pane" id="sample89">
<div class="row">
<div class="col-md-12">
<pre id="sample_response89"></pre>
</div>
</div>
</div><!-- #sample -->
</div><!-- .tab-content -->
</div>
</div>
</div>
</div>
<hr>
<div class="row mt0 footer">
<div class="col-md-6" align="left">
Generated on 2019-04-04 15:53:15 </div>
Generated on 2019-04-04 17:50:01 </div>
<div class="col-md-6" align="right">
<a href="https://www.fastadmin.net" target="_blank">FastAdmin</a>
</div>
... ...