ChargeController.php
1.8 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
<?php
/**
* Created by PhpStorm.
* User: yhbr
* Date: 2018/10/16
* Time: 13:38
*/
namespace app\charge\controller;
use cmf\controller\HomeBaseController;
use think\Db;
class ChargeController extends HomeBaseController
{
function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
require_once EXTEND_PATH . '/Charge.php';
}
public function charge()
{
$request = request();
if ($request->isAjax()) {
$info = Db::name('charge')->where(['id' => $request->param('id')])->find();
$pay = new \Payment($request->param('id'), session('user.openid'), '充值', 1/*$info['denomination'] * 100*/);
$this->success('微信充值', '', $pay->pay());
}
}
public function notify()
{
$pay = new \Payment();
$return = $pay->handleNotify();
if (!empty($return)) {
$info = Db::name('charge')->where(['id' => $return['attach']])->find();
$balance = $info['denomination'] + $info['bonus'];
Db::startTrans();
if (Db::name('user')->where(['openid' => $return['openid']])->setInc('balance', $balance)) {
$data = [
'user_id' => session('user.id'),
'type' => 1,
'cost' => $balance,
'create_time' => time()
];
if (Db::name('my_wallet')->insert($data)) {
//Db::commit();
echo "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
exit();
} else {
Db::rollback();
}
} else {
Db::rollback();
}
}
}
}