|
@@ -5,7 +5,10 @@ namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
|
|
use App\Models\PaymentLogModel;
|
|
use App\Models\PaymentLogModel;
|
|
|
|
+use App\Models\User;
|
|
|
|
+use App\Models\UserVipLogModel;
|
|
use App\Services\PayService;
|
|
use App\Services\PayService;
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Log;
|
|
use PHPUnit\Util\Exception;
|
|
use PHPUnit\Util\Exception;
|
|
use Yansongda\Pay\Pay;
|
|
use Yansongda\Pay\Pay;
|
|
@@ -17,13 +20,16 @@ class PayNotifyController extends Controller
|
|
*/
|
|
*/
|
|
public function wx_notify(){
|
|
public function wx_notify(){
|
|
$wxpay = Pay::wechat(PayService::wx_config());
|
|
$wxpay = Pay::wechat(PayService::wx_config());
|
|
|
|
+ DB::beginTransaction();
|
|
try{
|
|
try{
|
|
$data = $wxpay->verify();
|
|
$data = $wxpay->verify();
|
|
Log::info($data);
|
|
Log::info($data);
|
|
$order_no = $data->out_trade_no;
|
|
$order_no = $data->out_trade_no;
|
|
$this->order_do_sth($order_no);
|
|
$this->order_do_sth($order_no);
|
|
- Log::debug('Wechat notify', $data->all());
|
|
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
|
+ DB::rollBack();
|
|
Log::info($e->getMessage());
|
|
Log::info($e->getMessage());
|
|
}
|
|
}
|
|
return $wxpay->success();
|
|
return $wxpay->success();
|
|
@@ -34,13 +40,15 @@ class PayNotifyController extends Controller
|
|
*/
|
|
*/
|
|
public function ali_notify(){
|
|
public function ali_notify(){
|
|
$alipay = Pay::alipay(PayService::ali_config());
|
|
$alipay = Pay::alipay(PayService::ali_config());
|
|
|
|
+ DB::beginTransaction();
|
|
try{
|
|
try{
|
|
$data = $alipay->verify();
|
|
$data = $alipay->verify();
|
|
Log::info($data);
|
|
Log::info($data);
|
|
$order_no = $data->out_trade_no;
|
|
$order_no = $data->out_trade_no;
|
|
$this->order_do_sth($order_no);
|
|
$this->order_do_sth($order_no);
|
|
- Log::debug('Wechat notify', $data->all());
|
|
|
|
|
|
+ DB::commit();
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
|
+ DB::rollBack();
|
|
Log::info($e->getMessage());
|
|
Log::info($e->getMessage());
|
|
}
|
|
}
|
|
return $alipay->success();
|
|
return $alipay->success();
|
|
@@ -57,6 +65,34 @@ class PayNotifyController extends Controller
|
|
if($order['status']==1){
|
|
if($order['status']==1){
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+ //修改订单状态
|
|
|
|
+ $order->status = 1;
|
|
|
|
+ $order->save();
|
|
|
|
+
|
|
|
|
+ $vip_info = json_decode($order->content,true);
|
|
|
|
|
|
|
|
+ //修改用户vip状态
|
|
|
|
+ $user = User::query()->where(['id'=>$order->user_id])->first();
|
|
|
|
+ if($user->is_vip==0){
|
|
|
|
+ $user->is_vip = 1;
|
|
|
|
+ $user->save();
|
|
|
|
+ }
|
|
|
|
+ //变更vip记录
|
|
|
|
+ $user_vip_log = UserVipLogModel::query()->where(['user_id'=>$order->user_id])->first();
|
|
|
|
+ if(!$user_vip_log){
|
|
|
|
+ UserVipLogModel::query()->create([
|
|
|
|
+ 'user_id'=>$order->user_id,
|
|
|
|
+ 'status'=>1,
|
|
|
|
+ 'day'=>$vip_info['day'],
|
|
|
|
+ 'end_day'=> date("Y-m-d H:i:s",strtotime("+".$vip_info['day']." day")),
|
|
|
|
+ ]);
|
|
|
|
+ }elseif($user_vip_log->status==1){
|
|
|
|
+ $user_vip_log->end_day = date("Y-m-d H:i:s",strtotime($user_vip_log->end_day."+".$vip_info['day']." day"));
|
|
|
|
+ $user_vip_log->save();
|
|
|
|
+ }elseif ($user_vip_log->status==0){
|
|
|
|
+ $user_vip_log->end_day = date("Y-m-d H:i:s",strtotime("+".$vip_info['day']." day"));
|
|
|
|
+ $user_vip_log->status = 1;
|
|
|
|
+ $user_vip_log->save();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|