Notify.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
65
<?php
namespace app\api\controller;
use addons\epay\library\Service;
use app\common\controller\Api;
use Exception;
/**
* @ApiInternal
*/
class Notify extends Api
{
protected $noNeedRight = ['*'];
protected $noNeedLogin = ['*'];
/**
* 订单支付回调
*/
public function orderNotify()
{
$paytype = $this->request->param('type');
$pay = Service::checkNotify($paytype);
if (!$pay) {
echo '签名错误';
return;
}
$data = $pay->verify();
$model = new \app\api\model\Order();
$goodsmodel = new \app\api\model\OrderGoods();
$skumodel = new \app\api\model\GoodsSpec();
try {
$out_trade_no = $data['out_trade_no'];
$order = $model
->where('order_no',$out_trade_no)
->where('pay_status','10')
->where('order_status','10')
->find();
if (!$order) $this->error('订单不存在');
$order->pay_status = '20';
$order->transaction_id = $data['transaction_id'];
$order->pay_time = time();
$order->isUpdate()->save();
// 减少库存
$list = $goodsmodel->where('order_id',$order['id'])->select();
foreach ($list as $key => $value){
if ($value['deduct_stock_type'] == 20){
$skumodel->where('goods_spec_id',$value['goods_spec_id'])->setDec('stock_num',$value['total_num']);
}
}
// 判断是否邀请成功
$user = \app\api\model\User::get($order['user_id']);
if ($user['invite_user_id'] > 0 && $user['invite_status'] != 1) {
$user->invite_status = '1';
$user->isUpdate()->save();
}
//你可以在此编写订单逻辑
} catch (Exception $e) {
}
echo $pay->success()->send();
}
}