...
|
...
|
@@ -406,51 +406,39 @@ class Pay extends Api |
|
|
//判断用户充值金额是否大于等于8000
|
|
|
if($data['money']>=8000){
|
|
|
//大于等于的情况
|
|
|
$res = Db::name('toporder')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
$arr = Db::name('user')->where('id',$data['user_id'])->find();
|
|
|
//判断用户是否已经是会员了
|
|
|
if($arr['is_vip'] == 1){
|
|
|
//已经是会员
|
|
|
$list['money'] = $arr['money'] + $money;
|
|
|
$info = Db::name('user')->where('id',$data['user_id'])->update(['money'=>$list['money']]);
|
|
|
if($res && $info){
|
|
|
true;
|
|
|
}
|
|
|
Db::name('user')->where('id',$data['user_id'])->update(['money'=>$list['money']]);
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
}else{
|
|
|
//不是会员
|
|
|
$list['money'] = $arr['money'] + $money;
|
|
|
$list['is_vip'] = 1;
|
|
|
$info = Db::name('user')->where('id',$data['user_id'])->update($list);
|
|
|
if($res && $info){
|
|
|
true;
|
|
|
}
|
|
|
Db::name('user')->where('id',$data['user_id'])->update($list);
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
}
|
|
|
}else{
|
|
|
//小于8000的情况
|
|
|
$res = Db::name('toporder')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
$arr = Db::name('user')->where('id',$data['user_id'])->find();
|
|
|
$list['money'] = $arr['money'] + $money;
|
|
|
$info = Db::name('user')->where('id',$data['user_id'])->update(['money'=>$list['money']]);
|
|
|
if($res && $info){
|
|
|
true;
|
|
|
}
|
|
|
Db::name('user')->where('id',$data['user_id'])->update(['money'=>$list['money']]);
|
|
|
// 提交事务
|
|
|
Db::commit();
|
|
|
}
|
|
|
$this->success('SUCCESS');
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
|
// 回滚事务
|
|
|
Db::rollback();
|
|
|
$this->error(['code'=>2,'msg'=>'充值失败']);
|
|
|
}
|
|
|
}else{
|
|
|
$toporder['status'] = 1;
|
|
|
//支付失败
|
|
|
Db::name('toporder')->where('num',$message['out_trade_no'])->update(['status'=>1]);
|
|
|
Db::name('toporder')->where('num',$message['out_trade_no'])->update($toporder);
|
|
|
}
|
|
|
}else{
|
|
|
return $fail('通信失败,请稍后再通知我');
|
...
|
...
|
|