PayView.php
4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2019/10/29
* Time: 9:12
*/
namespace app\admin\controller;
use app\common\controller\Backend;
use fast\Random;
use think\Db;
class PayView extends Backend
{
/**
* 页面
* @return mixed|\think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index(){
//商户信息
$admin = Db::name('admin')->where(['id'=>$this->auth->id])->find();
//红包券充值比例
$exp_ratio = Db::name('exp_ratio')->where(['id'=>1])->find();
$this->assign('exp_ratio',$exp_ratio);
$this->assign('admin',$admin);
return $this->fetch();
}
/**
* 创建订单
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function create_order(){
$admin_id = $this->request->param('admin_id',0,'intval');
$total = $this->request->param('total',0,'intval');
if(empty($admin_id) || empty($total)){
$this->error('缺少必要参数');
}
//红包券充值比例
$exp_ratio = Db::name('exp_ratio')->where(['id'=>1])->find();
$admin = Db::name('admin')->where(['id'=>$admin_id])->find();
$arr['num'] = date("YmdHis") . Random::alnum(6);
$arr['admin_id'] = $admin_id;
$arr['user_id'] = $admin['user_id'];
$arr['total'] = $total;
$arr['money'] = $exp_ratio['ratio']/0.01*$total;//$total*$exp_ratio['ratio']*0.01;
$arr['create_time'] = time();
$arr['status'] = 1;
$order_id = Db::name('order')->insertGetId($arr);
$this->success('','',['order_id'=>$order_id]);
}
/**
* 唤起支付
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function pay(){
$order_id = $this->request->param('order_id',0,'intval');
$data = Db::name('order')->where(['id'=>$order_id])->find();
dump($data);
exit();
$pay = new Pay();
$code_url = $pay->index($data);
if(empty($code_url)){
$this->error('生成二维码失败');
}
\PHPQRCode\QRcode::png($code_url);
}
/**
* 订单是否支付
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function order_pay(){
$order_id = $this->request->param('order_id',0,'intval');
$data = Db::name('order')->where(['id'=>$order_id])->find();
if($data['status'] != 2){
$this->error('');
}
$this->success();
}
/**
* 创建提现记录
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function create_withdraw(){
$admin_id = $this->request->param('admin_id',0,'intval');
$money = $this->request->param('money',0,'intval');
if(empty($admin_id) || empty($money)){
$this->error('缺少必要参数');
}
//商户信息
$admin = Db::name('admin')->where(['id'=>$admin_id])->find();
//红包券充值比例
$exp_ratio = Db::name('exp_ratio')->where(['id'=>1])->find();
if($exp_ratio['ratio']*$admin['money']*0.01<$money){
$this->error('余额不足');
}
Db::startTrans();
//储存记录
$arr1['admin_id'] = $admin_id;
$arr1['before_money'] = $admin['money'];
$arr1['money'] = $exp_ratio['ratio']/0.01*$money;
$arr1['after_money'] = $admin['money'] - $arr1['money'];
$arr1['type'] = 1;
$arr1['createtime'] = time();
$result1 = Db::name('user_money_log')->insert($arr1);
if(empty($result1)){
Db::rollback();
$this->error('sql执行失败');
}
//扣除商户余额
$result2 = Db::name('admin')->where(['id'=>$admin_id])->setDec('money',$arr1['money']);
if(empty($result2)){
Db::rollback();
$this->error('sql执行失败');
}
Db::commit();
$this->success();
}
}