Notify.php
4.6 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/4/22
* Time: 16:37
*/
namespace app\index\controller;
use app\common\controller\Api;
use app\common\controller\Frontend;
use app\index\model\OrderDetail;
use app\index\model\Store;
use app\index\model\Viporder;
use think\Db;
class Notify extends Frontend
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 购买会员
* @return bool
*/
public function index1(){
$param = $this->request->param();
if(empty($param)){
$this->error('缺少必要参数');
}
cache('param',$param);
$result = \alipay\Notify::check($param);
cache('result',$result);
$out_trade_no = $param['out_trade_no'];
$vipOrderModel = new Viporder();
$data = $vipOrderModel->findData(['num'=>$out_trade_no]);
if (empty($data)) { // 如果订单不存在
return false;
}
// 如果订单存在
if (!empty($data['paytime'])) {
return true;
}
$userModel = new \app\index\model\User();
$user = $userModel->findData(['id'=>$data['user_id']]);
$storeModel = new Store();
$store = $storeModel->findData(['user_id'=>$data['user_id']]);
// 用户是否支付成功
if(!empty($result)){
if($data['vip_type'] == '1'){
//普通会员
if($user['is_vip'] == '1'){
$vip_passtime = $user['vip_passtime'] + 365*24*60*60;
}else{
$vip_passtime = time() + 365*24*60*60;
}
$userModel->updateData(['id'=>$user['id']],['vip_passtime'=>$vip_passtime,'province_ids'=>",".$data['province_ids'].","]);
if(!empty($store)){
$storeModel->updateData(['id'=>$user['id']],['vip_passtime'=>$vip_passtime,'province_ids'=>",".$data['province_ids'].","]);
}
}else if($data['vip_type'] == '2'){
//超级会员
if($user['is_svip'] == '1'){
$svip_passtime = $user['svip_passtime'] + 365*24*60*60;
}else{
$svip_passtime = time() + 365*24*60*60;
}
$userModel->updateData(['id'=>$user['id']],['svip_passtime'=>$svip_passtime]);
if(!empty($store)){
$storeModel->updateData(['id'=>$user['id']],['svip_passtime'=>$svip_passtime]);
}
}
$arr['status'] = "2";
$arr['paytime'] = time();
$vipOrderModel->updateData(['id'=>$data['id']],$arr);
}
return true; // 返回处理完成
}
/**
* 购买商品
* @return bool
*/
public function index2(){
$param = $this->request->param();
if(empty($param)){
$this->error('缺少必要参数');
}
cache('param',$param);
$result = \alipay\Notify::check($param);
cache('result',$result);
$out_trade_no = $param['out_trade_no'];
$identification = substr($out_trade_no, -1);
$orderModel = new \app\index\model\Order();
$orderDetailModel = new OrderDetail();
if($identification == 1){
$data = $orderModel->findData(['num'=>$out_trade_no]);
}else{
$data = $orderDetailModel->findData(['num'=>$out_trade_no]);
}
if (empty($data)) { // 如果订单不存在
return false;
}
// 如果订单存在
if (!empty($data['paytime'])) {
return true;
}
$userModel = new \app\index\model\User();
$user = $userModel->findData(['id'=>$data['user_id']]);
// 用户是否支付成功
if(!empty($result)){
if($identification == 1){
$orderModel->updateData(['id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
$orderDetailModel->updateData(['order_id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
}else{
$orderDetailModel->updateData(['id'=>$data['id']],['paytime'=>time(),'status'=>'2']);
$order_detail_status1_count = $orderDetailModel->findData(['order_id'=>$data['order_id'],'status'=>'1']);
if($order_detail_status1_count == 0){
$orderModel->updateData(['id'=>$data['order_id']],['paytime'=>time(),'status'=>'2']);
}
}
}
return true; // 返回处理完成
}
public function demo(){
dump(cache('param'));
dump(cache('result'));
}
}