|
@@ -1,129 +1,102 @@
|
|
|
<?php
|
|
|
namespace app\api\controller;
|
|
|
-use \think\Db;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+use addons\epay\library\Service;
|
|
|
/**
|
|
|
* 订单支付回调
|
|
|
*/
|
|
|
class Notify extends Api
|
|
|
{
|
|
|
+ protected $noNeedLogin = ['*'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ //充值金币 异步回调对外方法
|
|
|
+ public function recharge_notify_base(){
|
|
|
+
|
|
|
+ //验签
|
|
|
+ $paytype = input('paytype','wechat');
|
|
|
+ $notify_file = $this->notify_log_start($paytype);
|
|
|
+ $pay = Service::checkNotify($paytype);
|
|
|
+ if (!$pay) {
|
|
|
+ echo '签名错误';
|
|
|
+ exit;
|
|
|
+ }
|
|
|
|
|
|
- //pc端充值金币
|
|
|
- public function rechargepaysucc($orderId,$args){
|
|
|
- $order = Db::name('pay_order')->where(array('pay_no'=>$orderId,'status'=>2))->find();
|
|
|
-
|
|
|
- if( $order )
|
|
|
- {
|
|
|
+ //验证,拿订单号等信息
|
|
|
+ $data = $pay->verify();
|
|
|
+ $out_trade_no = $data['out_trade_no'];
|
|
|
+ //订单查询
|
|
|
+ $info = Db::name('pay_order')->where('out_trade_no',$out_trade_no)->find();
|
|
|
|
|
|
- Db::startTrans();
|
|
|
- //更新订单状态
|
|
|
- $rs = Db::name('pay_order')->where(['id'=>$order['id']])->update(['status'=>1]);
|
|
|
- if(!$rs){
|
|
|
- Db::rollback();
|
|
|
- filePut('[wallet][paySucc] pay_order update fail'.$orderId);
|
|
|
- abort(500,'订单更新失败');
|
|
|
- }
|
|
|
+ if(empty($info)){
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
|
|
|
- //先充值
|
|
|
- $result = model('Wallet')->lockChangeAccountRemain($args['user_id'],'gold',$args['gold'],10, '金币充值:'.$orderId,'pay_order',$order['id']);
|
|
|
- if($result['status']===false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- filePut('[wallet][paySucc]网银充值入账更新余额失败 recharge money fail'.$orderId.$result['msg']);
|
|
|
- abort(500,'网银充值入账 model wallet recharge money fail');
|
|
|
- }
|
|
|
+ if($info['order_status'] != 0)
|
|
|
+ {
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ //你可以在此编写订单逻辑
|
|
|
+ $rs = $this->recharge_notify_do($out_trade_no);
|
|
|
+ if($rs === false){
|
|
|
+ //不论结果都应返回success
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }else{
|
|
|
+ //不论结果都应返回success
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
|
|
|
- Db::commit();
|
|
|
+ //默认
|
|
|
+ echo $pay->success();
|
|
|
+ exit;
|
|
|
+ }
|
|
|
|
|
|
+ //异步逻辑
|
|
|
+ private function recharge_notify_do($out_trade_no){
|
|
|
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- filePut('[wallet][paySucc]在线支付订单有误 '.$orderId);
|
|
|
- abort(500,'model wallet fail');
|
|
|
+ Db::startTrans();
|
|
|
+ $orderInfo = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
|
|
|
+ if (empty($orderInfo)) {
|
|
|
+ Db::rollback();
|
|
|
return false;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- //app充值金币
|
|
|
- public function goldpaysucc($orderId,$args){
|
|
|
- $order = Db::name('pay_order')->where(array('pay_no'=>$orderId,'status'=>2))->find();
|
|
|
+ if($orderInfo['order_status'] != 0){
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- if( $order )
|
|
|
+ //逻辑开始
|
|
|
+ $args = json_decode($orderInfo['args'],true);
|
|
|
+ $result = model('Wallet')->lockChangeAccountRemain($orderInfo['user_id'],'gold',$args['gold'],10, '金币充值','pay_order',$orderInfo['id']);
|
|
|
+ if($result['status']===false)
|
|
|
{
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //逻辑结束
|
|
|
|
|
|
- Db::startTrans();
|
|
|
- //更新订单状态
|
|
|
- $rs = Db::name('pay_order')->where(['id'=>$order['id']])->update(['status'=>1]);
|
|
|
- if(!$rs){
|
|
|
- Db::rollback();
|
|
|
- filePut('[wallet][paySucc] pay_order update fail'.$orderId);
|
|
|
- abort(500,'订单更新失败');
|
|
|
- }
|
|
|
-
|
|
|
- //先充值
|
|
|
- $result = model('Wallet')->lockChangeAccountRemain($args['user_id'],'gold',$args['gold'],10, '金币充值:'.$orderId,'pay_order',$order['id']);
|
|
|
- if($result['status']===false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- filePut('[wallet][paySucc]网银充值入账更新余额失败 recharge money fail'.$orderId.$result['msg']);
|
|
|
- abort(500,'网银充值入账 model wallet recharge money fail');
|
|
|
- }
|
|
|
+ //状态
|
|
|
+ $ros = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->update(['order_status'=>1,'notifytime'=>time()]);
|
|
|
+ if($ros === false) {
|
|
|
+ Db::rollback();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- //首充
|
|
|
- $first_map = [
|
|
|
- 'uid' => $args['user_id'],
|
|
|
- 'pg_id' => $args['pg_id'],
|
|
|
- ];
|
|
|
- $first_check = Db::name('user_paygold_log')->where($first_map)->find();
|
|
|
- if(empty($first_check)){
|
|
|
-
|
|
|
- //首充日志
|
|
|
- $first_map['createtime'] = time();
|
|
|
- $first_log_id = Db::name('user_paygold_log')->insertGetId($first_map);
|
|
|
- if(!$first_log_id){
|
|
|
- Db::rollback();
|
|
|
- abort(500,'首充赠送失败');
|
|
|
- }
|
|
|
- //送金币
|
|
|
- if(isset($args['first_gold']) && $args['first_gold'] > 0){
|
|
|
- $result = model('Wallet')->lockChangeAccountRemain($args['user_id'],'gold',$args['first_gold'],14, '金币充值:'.$orderId,'pay_order',$order['id']);
|
|
|
- if($result['status']===false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- filePut('[wallet][paySucc]网银充值入账更新余额失败 recharge money fail'.$orderId.$result['msg']);
|
|
|
- abort(500,'网银充值入账 model wallet recharge money fail');
|
|
|
- }
|
|
|
- }
|
|
|
- //送vip
|
|
|
- if(isset($args['first_vipdays']) && $args['first_vipdays'] > 0){
|
|
|
- $user_info = Db::name('user_wallet')->where('user_id',$args['user_id'])->lock(true)->find();
|
|
|
- if($user_info['vip_endtime'] < time()){
|
|
|
- //过期了
|
|
|
- $vip_endtime = time() + (intval($args['first_vipdays']) * 86400);
|
|
|
- }else{
|
|
|
- //追加vip
|
|
|
- $vip_endtime = $user_info['vip_endtime'] + (intval($args['first_vipdays']) * 86400);
|
|
|
- }
|
|
|
- $result = Db::name('user_wallet')->where('user_id',$args['user_id'])->update(['vip_endtime'=>$vip_endtime]);
|
|
|
- if($result === false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- filePut('[wallet][paySucc]网银充值入账更新vip时间失败 recharge money fail'.$orderId);
|
|
|
- abort(500,'网银充值入账 model wallet recharge money fail');
|
|
|
- }
|
|
|
- }
|
|
|
+ //默认提交
|
|
|
+ Db::commit();
|
|
|
+ return true;
|
|
|
|
|
|
- }
|
|
|
|
|
|
- Db::commit();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- return true;
|
|
|
- }else{
|
|
|
- filePut('[wallet][paySucc]在线支付订单有误 '.$orderId);
|
|
|
- abort(500,'model wallet fail');
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
//app充值vip
|
|
|
public function vippaysucc($orderId,$args){
|
|
|
$order = Db::name('pay_order')->where(array('pay_no'=>$orderId,'status'=>2))->find();
|