NotifyCommonController.php
1.9 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
<?php
/**
* Created by PhpStorm.
* User: 29925
* Date: 2018/10/3
* Time: 13:34
*/
namespace app\portal\controller;
use app\portal\model\OrderModel;
use cmf\controller\HomeBaseController;
use think\Db;
class NotifyCommonController extends HomeBaseController
{
/**
* 公共订单处理方法(支付宝、微信)
* @param $order_sn 订单号
* @param $pay_type 支付类型
* @param $data 支付端返回的所有参数
*/
public function handle($order_sn, $pay_type, $total_fee, $transaction_id, $data) {
// 获取订单金额
$where = [
'order_sn' => $order_sn,
'delete_time' => 0
];
$where ['delete_time'] = 0;
$orderInfo = Db::name('Order')
->where($where)
->find();
$order_price = 0;
$orderInfo['options'] = json_decode($orderInfo['options'],true);
foreach ($orderInfo['options'] as $k=>$v) {
if($v['id'] == 64) {
$order_price = $v['user_choose'];
}
}
if($order_price == $total_fee) {
$order_model = new OrderModel();
$orderInfo = $order_model->where($where)->find();
if(!empty($orderInfo) && $orderInfo['status'] == 0) {
$order_model->startTrans();
$update = [
'status' => 1,
'pay_type' => $pay_type,
'pay_time' => time(),
'transaction_id' => $transaction_id,
'more' => json_encode($data)
];
$status = $order_model->where($where)->update($update);
if(!$status) {
$order_model->rollback();
return false;
} else {
$order_model->commit();
return true;
}
}
}
}
}