|
@@ -15,7 +15,7 @@ class Payios extends Api
|
|
|
|
|
|
//vip ios用的
|
|
|
public function vip_config_ios(){
|
|
|
- $list = Db::name('payvip_config_ios')->where('is_show',1)->order('weight asc,id asc')->select();
|
|
|
+ $list = Db::name('payvip_config_ios')->field('id,money,days,title')->where('is_show',1)->order('weight asc,id asc')->select();
|
|
|
$data['vipconfig'] = $list;
|
|
|
$data['vip_endtime'] = model('wallet')->getWallet($this->auth->id,'vip_endtime');
|
|
|
$data['is_vip'] = $data['vip_endtime'] > time() ? 1 : 0;
|
|
@@ -139,8 +139,8 @@ class Payios extends Api
|
|
|
|
|
|
|
|
|
//金币充值
|
|
|
- public function gold_config(){
|
|
|
- $list = Db::name('paygold_webcon')->order('weigh asc,id asc')->select();
|
|
|
+ public function gold_config_ios(){
|
|
|
+ $list = Db::name('paygold_webcon_ios')->field('id,money,gold')->where('is_show',1)->order('weigh asc,id asc')->select();
|
|
|
$data['goldconfig'] = $list;
|
|
|
|
|
|
$wallet = model('wallet')->getWallet($this->auth->id);
|
|
@@ -150,32 +150,22 @@ class Payios extends Api
|
|
|
}
|
|
|
|
|
|
//充值金币 创建订单
|
|
|
- public function gold_recharge(){
|
|
|
+ public function gold_recharge_ios(){
|
|
|
|
|
|
$rc_id = input_post('rc_id',0);
|
|
|
- $pay_type = input_post('pay_type','wechat');
|
|
|
+ $pay_type = 'ios';
|
|
|
$platform = 'app';
|
|
|
- $freemoney = input_post('freemoney',0);
|
|
|
$uid = $this->auth->id;
|
|
|
|
|
|
- if(!$rc_id && !$freemoney){
|
|
|
- $this->error('请选择或填写充值金额');
|
|
|
+ if(!$rc_id){
|
|
|
+ $this->error('请选择充值金额');
|
|
|
}
|
|
|
|
|
|
//赋值money
|
|
|
- if($rc_id){
|
|
|
- $recharge_config = Db::name('paygold_webcon')->where('id',$rc_id)->find();
|
|
|
- $money = $recharge_config['money'] ?: 0;
|
|
|
- $gold = $recharge_config['gold'] ?: 0;
|
|
|
- }
|
|
|
+ $recharge_config = Db::name('paygold_webcon_ios')->where('id',$rc_id)->find();
|
|
|
+ $money = $recharge_config['money'] ?: 0;
|
|
|
+ $gold = $recharge_config['gold'] ?: 0;
|
|
|
|
|
|
- //自由输入覆盖
|
|
|
- if(!empty($freemoney)){
|
|
|
- $rc_id = 0;
|
|
|
- $money = floatval($freemoney);
|
|
|
- $bili = config('site.money_to_gold') ?: 10;
|
|
|
- $gold = bcmul($money,$bili,0);
|
|
|
- }
|
|
|
|
|
|
//
|
|
|
if($money<=0)
|
|
@@ -197,33 +187,75 @@ class Payios extends Api
|
|
|
$data['order_status'] = 0;
|
|
|
$data['table_name'] = 'gold_recharge';
|
|
|
$data['table_id'] = 0;
|
|
|
- $data['args'] = json_encode(['gold'=>$gold]);
|
|
|
+ $data['args'] = json_encode(['gold'=>$gold,'bundle_id'=>$recharge_config['bundle_id']]);
|
|
|
|
|
|
$orderid = Db::name('pay_order')->insertGetId($data);
|
|
|
|
|
|
-// $openid = $this->auth->mini_openid;
|
|
|
- //下单
|
|
|
- $params = [
|
|
|
- 'type' => $pay_type,
|
|
|
- 'orderid' => $data['out_trade_no'],
|
|
|
- 'title' => '支付订单',
|
|
|
- 'amount' => $data['order_amount'],
|
|
|
- 'method' => $platform,
|
|
|
-// 'openid' => $openid,
|
|
|
- 'notifyurl' => config('pay_notify_url').'/api/notify/recharge_notify_base/paytype/'.$pay_type,
|
|
|
- 'returnurl' => '',
|
|
|
- ];
|
|
|
+ $this->success('success',$data['out_trade_no']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //vip,苹果内购支付回调
|
|
|
+ public function gold_notify_ios(){
|
|
|
+ $notify_file = $this->notify_log_start('ios');
|
|
|
|
|
|
- $res = Service::submitOrder($params);
|
|
|
+ //苹果内购的验证收据
|
|
|
+ $receipt_data = input('apple_receipt', '', 'trim');
|
|
|
+ $order_no = input('order_no', '', 'trim');
|
|
|
|
|
|
- if($pay_type == 'wechat'){
|
|
|
- $this->success('success',json_decode($res,true));
|
|
|
- }else{
|
|
|
- $this->success('success',$res);
|
|
|
+ if (!$receipt_data || !$order_no) {
|
|
|
+ $this->error('缺少参数');
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ Db::startTrans();
|
|
|
+ // 查找订单
|
|
|
+ $order_info = Db::name('pay_order')->where(['out_trade_no' => $order_no])->lock(true)->find();
|
|
|
+ if (!$order_info) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('订单丢失');
|
|
|
+ }
|
|
|
+ if ($order_info['order_status'] == 1) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->success('充值成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证支付状态
|
|
|
+ $result = $this->validate_apple_pay($receipt_data);
|
|
|
+ if (!$result['status']) {// 验证不通过
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($result['message']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $count = count($result['data']['receipt']['in_app']);
|
|
|
+ $use_count = $count - 1;
|
|
|
+ $args = json_decode($order_info['args'],true);
|
|
|
+ if ($result['data']['receipt']['in_app'][$use_count]['product_id'] != $args['bundle_id']) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('非法请求,请立刻停止');
|
|
|
+ }
|
|
|
+
|
|
|
+ //逻辑开始
|
|
|
+ //先充值
|
|
|
+ $result = model('Wallet')->lockChangeAccountRemain($order_info['user_id'],'gold',$args['gold'],10, '金币充值','pay_order',$order_info['id']);
|
|
|
+ if($result['status']===false)
|
|
|
+ {
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改订单状态
|
|
|
+ $ros = Db::name('pay_order')->where(['out_trade_no' => $order_no])->update(['order_status'=>1,'notifytime'=>time()]);
|
|
|
+ if($ros === false) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('充值失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('充值成功');
|
|
|
+
|
|
|
+ //逻辑结束
|
|
|
+ }
|
|
|
|
|
|
+///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
//异步日志
|
|
|
private function notify_log_start($paytype = 'ios'){
|
|
|
//记录支付回调数据
|