|
@@ -215,60 +215,64 @@ class Payios extends Api
|
|
//苹果内购的验证收据
|
|
//苹果内购的验证收据
|
|
$receipt_data = input('apple_receipt', '', 'trim');
|
|
$receipt_data = input('apple_receipt', '', 'trim');
|
|
$password = input('password', '', 'trim');
|
|
$password = input('password', '', 'trim');
|
|
- if (!$receipt_data) {
|
|
|
|
|
|
+ $out_trade_no = input('out_trade_no', '', 'trim');
|
|
|
|
+ $transaction_id = input('transaction_id', '', 'trim');
|
|
|
|
+
|
|
|
|
+ if (!$receipt_data || !$out_trade_no || !$transaction_id) {
|
|
$this->error('缺少参数');
|
|
$this->error('缺少参数');
|
|
}
|
|
}
|
|
- filePut("\r\n\r\n");
|
|
|
|
- filePut('ios充值:参数apple_receipt['.$receipt_data.']');
|
|
|
|
|
|
+
|
|
|
|
+ filePut("\r\n\r\n".'新请求');
|
|
|
|
+ $prefix = 'ios充值,user_id:'.$this->auth->id.',out_trade_no:'.$out_trade_no.',transaction_id:'.$transaction_id.'。';
|
|
|
|
+ filePut($prefix.'参数apple_receipt:'.$receipt_data);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ // 查找订单
|
|
|
|
+ $order_map = [
|
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
|
+ 'out_trade_no' => $out_trade_no,
|
|
|
|
+ 'transaction_id' => $transaction_id,
|
|
|
|
+ ];
|
|
|
|
+ $order_info = Db::name('pay_order')->where($order_map)->lock(true)->find();
|
|
|
|
+ if (!$order_info) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ filePut($prefix.'不存在的订单');
|
|
|
|
+ $this->error('不存在的订单');
|
|
|
|
+ }
|
|
|
|
+ if ($order_info['order_status'] == 1) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ filePut($prefix.'早已完成');
|
|
|
|
+ $this->success('充值成功');
|
|
|
|
+ }
|
|
|
|
|
|
// 验证支付状态
|
|
// 验证支付状态
|
|
$result = $this->validate_apple_pay($receipt_data,$password);
|
|
$result = $this->validate_apple_pay($receipt_data,$password);
|
|
if (!$result['status']) {// 验证不通过
|
|
if (!$result['status']) {// 验证不通过
|
|
- filePut('ios充值:验证'.$result['message']);
|
|
|
|
|
|
+ Db::rollback();
|
|
|
|
+ filePut($prefix.'验证'.$result['message']);
|
|
$this->error($result['message']);
|
|
$this->error($result['message']);
|
|
}
|
|
}
|
|
|
|
|
|
$count = count($result['data']['receipt']['in_app']);
|
|
$count = count($result['data']['receipt']['in_app']);
|
|
$use_count = $count - 1;
|
|
$use_count = $count - 1;
|
|
$product_id = $result['data']['receipt']['in_app'][$use_count]['product_id'];
|
|
$product_id = $result['data']['receipt']['in_app'][$use_count]['product_id'];
|
|
- $transaction_id = $result['data']['receipt']['in_app'][$use_count]['transaction_id'];
|
|
|
|
|
|
|
|
-
|
|
|
|
- // 确认订单
|
|
|
|
- $order_map = [
|
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
|
- 'transaction_id' => $transaction_id,
|
|
|
|
- 'bundle_id' => $product_id,
|
|
|
|
- 'order_status' => 1,
|
|
|
|
- ];
|
|
|
|
- $order_check = Db::name('pay_order')->where($order_map)->find();
|
|
|
|
- if (!empty($order_check)) {
|
|
|
|
- filePut('ios充值:检查到out_trade_no='.$order_check['out_trade_no'].',订单已支付,不需要重复');
|
|
|
|
- $this->success('充值完成');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Db::startTrans();
|
|
|
|
- // 查找订单
|
|
|
|
- $order_map = [
|
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
|
- 'bundle_id' => $product_id,
|
|
|
|
- 'order_status' => 0,
|
|
|
|
- ];
|
|
|
|
- $order_info = Db::name('pay_order')->where($order_map)->order('id desc')->lock(true)->find();
|
|
|
|
- if (!$order_info) {
|
|
|
|
|
|
+ if($product_id != $order_info['bundle_id']){
|
|
Db::rollback();
|
|
Db::rollback();
|
|
- filePut('ios充值:订单不存在order_map='.json_encode($order_map));
|
|
|
|
- $this->error('订单不存在');
|
|
|
|
|
|
+ filePut($prefix.'验证'.'非法请求,请立刻停止'.$product_id.'!='.$order_info['bundle_id']);
|
|
|
|
+ $this->error('非法请求,请立刻停止');
|
|
}
|
|
}
|
|
- $args = json_decode($order_info['args'],true);
|
|
|
|
|
|
+
|
|
|
|
|
|
//逻辑开始
|
|
//逻辑开始
|
|
|
|
+ $args = json_decode($order_info['args'],true);
|
|
//先充值
|
|
//先充值
|
|
if($order_info['table_name'] == 'gold_recharge'){
|
|
if($order_info['table_name'] == 'gold_recharge'){
|
|
$result = model('Wallet')->lockChangeAccountRemain($order_info['user_id'],'gold',$args['gold'],10, '金币充值','pay_order',$order_info['id']);
|
|
$result = model('Wallet')->lockChangeAccountRemain($order_info['user_id'],'gold',$args['gold'],10, '金币充值','pay_order',$order_info['id']);
|
|
if($result['status']===false)
|
|
if($result['status']===false)
|
|
{
|
|
{
|
|
- filePut('ios充值:逻辑开始out_trade_no='.$order_info['out_trade_no'].',逻辑添加金币失败');
|
|
|
|
|
|
+ filePut($prefix.'逻辑添加金币失败');
|
|
Db::rollback();
|
|
Db::rollback();
|
|
$this->error('充值失败');
|
|
$this->error('充值失败');
|
|
}
|
|
}
|
|
@@ -289,7 +293,7 @@ class Payios extends Api
|
|
$result = Db::name('user_wallet')->where('user_id',$order_info['user_id'])->update($update_data);
|
|
$result = Db::name('user_wallet')->where('user_id',$order_info['user_id'])->update($update_data);
|
|
if($result === false)
|
|
if($result === false)
|
|
{
|
|
{
|
|
- filePut('ios充值:逻辑开始out_trade_no='.$order_info['out_trade_no'].',逻辑续费vip时间失败');
|
|
|
|
|
|
+ filePut($prefix.'逻辑续费vip时间失败');
|
|
Db::rollback();
|
|
Db::rollback();
|
|
$this->error('充值失败');
|
|
$this->error('充值失败');
|
|
}
|
|
}
|
|
@@ -298,13 +302,13 @@ class Payios extends Api
|
|
// 修改订单状态
|
|
// 修改订单状态
|
|
$ros = Db::name('pay_order')->where(['id' => $order_info['id']])->update(['order_status'=>1,'transaction_id' => $transaction_id,'notifytime'=>time()]);
|
|
$ros = Db::name('pay_order')->where(['id' => $order_info['id']])->update(['order_status'=>1,'transaction_id' => $transaction_id,'notifytime'=>time()]);
|
|
if($ros === false) {
|
|
if($ros === false) {
|
|
- filePut('ios充值:订单修改out_trade_no='.$order_info['out_trade_no'].',修改订单状态失败');
|
|
|
|
|
|
+ filePut($prefix.'修改订单状态失败');
|
|
Db::rollback();
|
|
Db::rollback();
|
|
$this->error('充值失败');
|
|
$this->error('充值失败');
|
|
}
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
Db::commit();
|
|
- filePut('ios充值:逻辑结束out_trade_no='.$order_info['out_trade_no'].',订单完成');
|
|
|
|
|
|
+ filePut($prefix.'充值成功');
|
|
$this->success('充值成功');
|
|
$this->success('充值成功');
|
|
|
|
|
|
//逻辑结束
|
|
//逻辑结束
|