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

修改充值

... ... @@ -3,6 +3,7 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use app\admin\model\User;
use think\Db;
/**
... ... @@ -19,6 +20,7 @@ class Porder extends Backend
*/
protected $model = null;
protected $status = 0;
protected $percent = 0.01;//按照比例扣取费用1%
public function _initialize()
{
... ... @@ -93,4 +95,26 @@ class Porder extends Backend
}
return $this->view->fetch();
}
//按照比例扣取费用
public function finish($ids){
if ($ids) {
$pk = $this->model->getPk();
$res = $this->model->where($pk, '=', $ids)->find();
if ($res['is_due'] == 0) {
$data = $this->model->where($pk, '=', $ids)->find();
$userModel = new User();
$money = (1 - $this->percent) * $data['total_price'];
$result = $userModel->where(['id'=>$data['s_uid'],'status'=>'normal'])->setInc('money',$money);
if($result){
$this->success('扣取成功');
}else{
$this->error('扣取失败');
}
} else {
$this->error('您已经扣取过了');
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
}
... ...
... ... @@ -49,11 +49,11 @@ class Line extends Backend
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$uid = $this->request->ids;
$uid = $this->request->param('ids');
$total = $this->model
->with(['user'])
->where($where)
// ->where('uid',$uid)
->where('uid',$uid)
->group('off_uid')
->order($sort, $order)
->count();
... ... @@ -62,7 +62,7 @@ class Line extends Backend
->with(['user'])
->field('sum(s_score) as score')
->where($where)
// ->where('uid',$uid)
->where('uid',$uid)
->group('off_uid')
->order($sort, $order)
->limit($offset, $limit)
... ...
... ... @@ -7,6 +7,7 @@ use addons\epay\library\Service;
use app\admin\model\Porder;
use think\Db;
use Yansongda\Pay\Pay;
use app\admin\model\Account;
use think\Log;
use fast\Http;
use think\Validate;
... ... @@ -16,8 +17,8 @@ use Exception;
*/
class Wxpay extends Api
{
protected $noNeedLogin = ['notify','wechatReturn'];
protected $noNeedRight = ['notify','wechatReturn'];
protected $noNeedLogin = ['notify','wechatReturn','notifyCharge'];
protected $noNeedRight = ['notify','wechatReturn','notifyCharge'];
protected $user_id = '';//token存贮user_id
protected $order_status = [];//订单状态
public function _initialize()
... ... @@ -85,7 +86,46 @@ class Wxpay extends Api
}
}
//支付成功回调
/**
* @ApiTitle (商品订单去付款)
* @ApiSummary (商品订单去付款)
* @ApiMethod (POST)
* @ApiRoute (/api/wxpay/toPay)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="o_id", type="integer", required=true, description="订单id")
* @ApiReturn ({
"code": 1,
"msg": "成功",
"time": "1554184134",
"data": {
"pay_order_sn": "155418413436253500503"
}
})
*/
public function toPay(){
if($this->request->isGet()){
$o_id = $this->request->get('o_id');//订单id
$pay = $this->auth->genPayOrderSn();//支付订单号
$rule = config('site.orders');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['o_id'=>$o_id])) {
$this->error($validate->getError());
}
$p_order = new Porder();
$res = $p_order->where(['id'=>$o_id,'uid'=>$this->user_id])->update(['pay_order_sn'=>$pay]);
if($res){
$this->success('成功',['pay_order_sn'=>$pay]);
}else{
$this->error('失败');
}
}else{
$this->error('请求方式错误');
}
}
/**
* 支付成功回调
*/
public function notify(){
$pay = Service::checkNotify('wechat');
if (!$pay) {
... ... @@ -102,7 +142,9 @@ class Wxpay extends Api
return;
}
//微信异步通知
/**
* 微信异步通知
*/
public function wechatReturn(){
$pay = Service::checkReturn('wechat');
if (!$pay) {
... ... @@ -113,4 +155,53 @@ class Wxpay extends Api
return;
}
public function payCharge(){
if($this->request->isPost()){
$amount = $this->request->request('amount');
$openid = $this->request->post('openid');//小程序传递openid
if(empty($openid)){
$this->error("openid必填");
}
$pay = Pay::wechat(Service::getConfig('wechat'));
if (!$amount || $amount < 0) {
$this->error("充值金额必须大于0");
}
$pay_order_sn = $this->auth->genPayOrderSn();//支付订单号
//构建订单信息
$order = [
'out_trade_no' => $pay_order_sn,//支付订单号
'body' => '广西小纸皮再生资源回收有限公司',
// 'total_fee' => 1,
'total_fee' => floatval($amount)*100,//单位:分
'openid' => $openid,
'notify_url' => url('api/Wxpay/notifyCharge','','',true),
'return_url' => url('api/Wxpay/wechatReturn','','',true),
];
//跳转或输出
$this->success('成功',$pay->miniapp($order));
}else{
$this->error('请求方式错误');
}
}
/**
* 充值成功回调
*/
public function notifyCharge(){
$pay = Service::checkNotify('wechat');
if (!$pay) {
$this->error('签名错误');
}
//你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
$data = $pay->verify();
if($data['return_code'] == 'SUCCESS' && $data['result_code'] == 'SUCCESS') {
$accountModel = new Account();
Log::info($data);
Log::info('充值回调');
//下面这句必须要执行,且在此之前不能有任何输出
echo $pay->success();
}
return;
}
}
... ...
... ... @@ -268,4 +268,13 @@ return array (
'page.number' => '页码必须是数字',
]
],
'orders' => [
'rule' => [
'o_id' => 'require|number',
],
'msg' => [
'o_id.require' => '订单id不能为空',
'o_id.number' => '订单id必须是数字',
]
],
);
\ No newline at end of file
... ...
... ... @@ -27,8 +27,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'id', title: __('Id')},
{field: 'user.username', title: __('User.username')},
{field: 'user.avatar', title: __('User.avatar'),formatter:Table.api.formatter.image},
{field: 'bank.open_bank', title: __('Bank.open_bank')},
{field: 'bank.bank_num', title: __('Bank.bank_num')},
// {field: 'bank.open_bank', title: __('Bank.open_bank')},
// {field: 'bank.bank_num', title: __('Bank.bank_num')},
{field: 'money', title: __('Money'), operate:'BETWEEN'},
{field: 'type', title: __('Type'),formatter: Table.api.formatter.label,searchList: {0: __('Withdrawal'), 1: __('Recharge')}},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
... ...
... ... @@ -15,7 +15,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
... ... @@ -31,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
// {field: 'type', title: __('Type'),formatter: Table.api.formatter.label,searchList: {0: __('pre_list'), 1: __('purchase')}},
{field: 'score', title: __('Score')},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
... ... @@ -49,18 +48,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
},queryParams: function (params) {
// 自定义搜索条件
var filter = params.filter ? JSON.parse(params.filter) : {};
var op = params.op ? JSON.parse(params.op) : {};
//filter.后跟的是在ajax里使用的名称只需修改这两行
filter.uid = Config.ids;
//opop后跟的也是ajax里使用的名称,后面是条件
op.uid = 'in';
params.filter = JSON.stringify(filter);
params.op = JSON.stringify(op);
// console.log(params);
return params;
}
};
return Controller;
... ...
... ... @@ -39,7 +39,33 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'u_user.address', title: __('s_address')},
{field: 'status', title: __('status'), formatter: Table.api.formatter.flag,searchList: {'-1': __('cancel_pay'),0: __('to_pay'), 1: __('to_receive'),2: __('to_comment'), 3: __('finish')}},
{field: 'createtime', title: __('createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
{
name: 'ajax',
text: __('完成'),
title: __('完成'),
classname: 'btn btn-xs btn-success btn-magic btn-ajax',
icon: 'fa fa-magic',
url: 'porder/finish',
confirm: '确认完成',
success: function (data, ret) {
Layer.alert(ret.msg);
//如果需要阻止成功提示,则必须使用return false;
//return false;
},
error: function (data, ret) {
Layer.alert(ret.msg);
return false;
},visible: function (row) {
if(row.status == 3){
return true;
}else{
return false;
}
}
}
]}
]
]
});
... ...
... ... @@ -44,7 +44,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
{name: 'team', text: '我的团队', title: '我的团队', icon: 'fa fa-list', classname: 'btn btn-xs btn-success btn-dialog', url: 'off/line/index'}
{name: 'log', text: '我的团队', title: '我的团队', icon: 'fa fa-list', classname: 'btn btn-xs btn-success btn-dialog', url: "off/line/index"}
]}
]
]
... ...