From 2d3e878e11b44b8e0863d25e9f1def3ab63cbd36 Mon Sep 17 00:00:00 2001 From: Hankin Date: Mon, 27 Apr 2026 11:32:30 +0800 Subject: [PATCH] callback --- app/Helpers/TokenHelper.php | 91 ++ .../Controllers/Admin/EarningController.php | 431 +++---- app/Http/Controllers/Controller.php | 9 +- app/Services/WechatService.php | 1050 +++++++++-------- 4 files changed, 894 insertions(+), 687 deletions(-) create mode 100644 app/Helpers/TokenHelper.php diff --git a/app/Helpers/TokenHelper.php b/app/Helpers/TokenHelper.php new file mode 100644 index 0000000..a473cd0 --- /dev/null +++ b/app/Helpers/TokenHelper.php @@ -0,0 +1,91 @@ + $userId, + 'iat' => $now, + 'exp' => $expires + ]; + + // 使用更简单的方式:base64 编码(避免版本兼容问题) + $encoded = base64_encode(json_encode($payload)); + + // 添加签名 + $signature = hash_hmac('sha256', $encoded, self::$secret); + + return $encoded . '.' . $signature; + } + + /** + * 验证 token + * @return array|false + */ + public static function verify($tokenString) + { + try { + $parts = explode('.', $tokenString); + if (count($parts) != 2) { + return false; + } + + list($payloadEncoded, $signature) = $parts; + + // 验证签名 + $expectedSignature = hash_hmac('sha256', $payloadEncoded, self::$secret); + if (!hash_equals($expectedSignature, $signature)) { + return false; + } + + // 解码 payload + $payload = json_decode(base64_decode($payloadEncoded), true); + if (!$payload) { + return false; + } + + // 检查是否过期 + $now = time(); + if (isset($payload['exp']) && $payload['exp'] < $now) { + return false; + } + + return [ + 'user_id' => $payload['user_id'], + 'expires_at' => $payload['exp'] + ]; + + } catch (\Exception $e) { + return false; + } + } + + /** + * 刷新 token + */ + public static function refresh($oldToken, $expiresIn = 60) + { + $payload = self::verify($oldToken); + if (!$payload) { + return false; + } + + return self::generate($payload['user_id'], $expiresIn); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/EarningController.php b/app/Http/Controllers/Admin/EarningController.php index b3ddc1a..36bbb6a 100644 --- a/app/Http/Controllers/Admin/EarningController.php +++ b/app/Http/Controllers/Admin/EarningController.php @@ -48,7 +48,8 @@ class EarningController extends Controller public function updateRule(Request $request, $id) { $rule = EarningRule::find($id); - if (empty($rule)) return $this->failure("修改失败,收益规则不存在"); + if (empty($rule)) + return $this->failure("修改失败,收益规则不存在"); $ratio = $request->input('ratio'); if ($request->has('ratio') && $ratio != $rule->ratio) { $rule->ratio = $ratio; @@ -84,9 +85,9 @@ class EarningController extends Controller $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); - $accounts = $accounts->whereHas('user', function ($sql) use($keyword) { - $sql->where('mobile', 'like', '%'.$keyword.'%') - ->orWhere('nickname', 'like', '%'.$keyword.'%'); + $accounts = $accounts->whereHas('user', function ($sql) use ($keyword) { + $sql->where('mobile', 'like', '%' . $keyword . '%') + ->orWhere('nickname', 'like', '%' . $keyword . '%'); }); } $accounts = $accounts->where('user_id', '<>', 0)->orderBy('id', 'desc')->paginate(); @@ -96,7 +97,8 @@ class EarningController extends Controller public function accountEarnings(Request $request, $id) { $account = EarningAccount::find($id); - if (empty($account)) return $this->failure('收益账号不存在'); + if (empty($account)) + return $this->failure('收益账号不存在'); $earnings = $account->earnings()->with('order:id,goods')->orderBy('id', 'desc')->paginate(); return $this->success('ok', compact('account', 'earnings')); } @@ -104,7 +106,8 @@ class EarningController extends Controller public function accountWithdraws(Request $request, $id) { $account = EarningAccount::find($id); - if (empty($account)) return $this->failure('收益账号不存在'); + if (empty($account)) + return $this->failure('收益账号不存在'); $withdraws = $account->withdraws()->orderBy('id', 'desc')->paginate(); return $this->success('ok', compact('account', 'withdraws')); } @@ -114,25 +117,25 @@ class EarningController extends Controller $withdraws = EarningWithdraw::with("user"); $status = $request->input('status'); if ($status) { - $withdraws = $withdraws->where('status',$status); + $withdraws = $withdraws->where('status', $status); } $keyword = $request->input('keyword'); if ($keyword) { - $withdraws = $withdraws->where(function ($sql) use($keyword) { - $sql->where(function ($query) use($keyword){ - $query->where('name', 'like', '%'.$keyword.'%') - ->orWhere('account', 'like', '%'.$keyword.'%'); - })->orwhereHas("user", function($query) use($keyword) { - $query->where('nickname', 'like', '%'.$keyword.'%'); + $withdraws = $withdraws->where(function ($sql) use ($keyword) { + $sql->where(function ($query) use ($keyword) { + $query->where('name', 'like', '%' . $keyword . '%') + ->orWhere('account', 'like', '%' . $keyword . '%'); + })->orwhereHas("user", function ($query) use ($keyword) { + $query->where('nickname', 'like', '%' . $keyword . '%'); }); }); - }else { + } else { $withdraws = $withdraws->whereHas('user'); } $withdraws = $withdraws->orderByDesc('id')->paginate(); foreach ($withdraws as $withdraw) { - $withdraw->name = $withdraw->name?:$withdraw->user->nickname; + $withdraw->name = $withdraw->name ?: $withdraw->user->nickname; } return $this->success('ok', $withdraws); } @@ -142,21 +145,25 @@ class EarningController extends Controller Log::info("审核商家提现"); try { $log = EarningWithdraw::find($id); - if (empty($log)) throw new Exception("提现记录不存在"); - if ($log->status == 'canceled' || ($log->status == 'finished' && empty($log->err_msg))) return $this->failure("该提现记录已审核"); + if (empty($log)) + throw new Exception("提现记录不存在"); + if ($log->status == 'canceled' || ($log->status == 'finished' && empty($log->err_msg))) + return $this->failure("该提现记录已审核"); //获取该用户的收益账号 $account = $log->earningAccount; - if (empty($account)) throw new Exception("提现账号不存在"); + if (empty($account)) + throw new Exception("提现账号不存在"); $balance = $account->balance;//账户余额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 //如果当前用户冻结提现金额 小于 本次提现金额 - if($frozen_withdraw < $log->value) throw new Exception('当前账户异常,提现金额大于实际金额'); + if ($frozen_withdraw < $log->value) + throw new Exception('当前账户异常,提现金额大于实际金额'); $user = $log->user; - if($log->way == 'alipay'){ + if ($log->way == 'alipay') { $transfer_way = '支付宝'; - }elseif($log->way == 'weixin'){ + } elseif ($log->way == 'weixin') { $transfer_way = '微信'; - }elseif($log->way == 'bank'){ + } elseif ($log->way == 'bank') { $transfer_way = '银行卡'; } DB::beginTransaction(); @@ -164,49 +171,50 @@ class EarningController extends Controller $admin_id = auth()->id(); if ($status == 'canceled') { $err_msg = $request->input('err_msg'); - if (empty($err_msg)) return $this->failure("请输入拒绝理由"); - EarningWithdraw::where('id',$id)->update(['status'=>$status, 'err_msg'=>$err_msg, 'admin_id'=>$admin_id, 'audit_at'=>date('Y-m-d H:i:s')]); + if (empty($err_msg)) + return $this->failure("请输入拒绝理由"); + EarningWithdraw::where('id', $id)->update(['status' => $status, 'err_msg' => $err_msg, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]); $account->increment('balance', $log->value); $account->decrement("frozen_withdraw", $log->value); DB::commit(); return $this->success('ok'); } $data = [ - 'remark'=>"提现到账", - 'payee_account'=>$log->account, - 'payee_real_name'=>$log->name, - 'amount'=>$log->real_value, - 'out_biz_no'=>$log->trade_no, + 'remark' => "提现到账", + 'payee_account' => $log->account, + 'payee_real_name' => $log->name, + 'amount' => $log->real_value, + 'out_biz_no' => $log->trade_no, ]; Log::info($data); switch ($log->way) { case 'alipay': $ali = new LiveAlipayService(); - if($log->alipay_id){//通过支付宝id打款 + if ($log->alipay_id) {//通过支付宝id打款 $data['payee_account'] = $log->alipay_id; $result = $ali->UserTransferAccount($data); - }else{//通过支付宝账号和名字打款 + } else {//通过支付宝账号和名字打款 $result = $ali->platTransferAccount($data); } break; case "weixin": - $result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,$data['remark']); + $result = \WechatService::officialUserTransferV2($log->trade_no, $log->account, $log->real_value * 100, $data['remark']); Log::info($result); break; } $err_msg = null; if (is_array($result)) { $err_msg = isset($result['msg']) ? $result['msg'] : $result['err_code_des']; - }else { + } else { $account->increment('withdrawl', $log->value); $account->decrement("frozen_withdraw", $log->value); } - EarningWithdraw::where('id',$id)->update(['status'=>$status, 'err_msg'=>$err_msg, 'admin_id'=>$admin_id, 'audit_at'=>date('Y-m-d H:i:s')]); + EarningWithdraw::where('id', $id)->update(['status' => $status, 'err_msg' => $err_msg, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]); //todo 通知 DB::commit(); return $this->success('审核完成'); - }catch (Exception $e) { + } catch (Exception $e) { DB::rollBack(); $this->getError($e); return $this->failure(); @@ -236,17 +244,17 @@ class EarningController extends Controller $keyword = $request->input('keyword'); if ($keyword) { $keyword = trim($keyword); - $orders = $orders->where(function($sql) use($keyword) { - $sql->where('users.nickname', 'like', '%'.$keyword.'%') - ->orWhere('users.mobile', 'like', '%'.$keyword.'%') - ->orWhere('orders.goods', 'like', '%'.$keyword.'%'); + $orders = $orders->where(function ($sql) use ($keyword) { + $sql->where('users.nickname', 'like', '%' . $keyword . '%') + ->orWhere('users.mobile', 'like', '%' . $keyword . '%') + ->orWhere('orders.goods', 'like', '%' . $keyword . '%'); }); } $users = DB::table('users')->selectRaw('id as user_id, nickname as sharer_user_name, photo as sharer_user_pic, mobile as sharer_user_mobile'); - $earnings = $earnings->joinSub($orders, 'ufutx_o', function($join) { - $join->on('earnings.order_id', '=','o.orders_id'); - })->leftJoinSub($users, 'ufutx_u', function($join) { - $join->on('earnings.user_id', '=','u.user_id'); + $earnings = $earnings->joinSub($orders, 'ufutx_o', function ($join) { + $join->on('earnings.order_id', '=', 'o.orders_id'); + })->leftJoinSub($users, 'ufutx_u', function ($join) { + $join->on('earnings.user_id', '=', 'u.user_id'); })->paginate(); foreach ($earnings as $earning) { $earning->order_price = PayOrder::where('trade_no', $earning->trade_no)->value('cash'); @@ -255,52 +263,53 @@ class EarningController extends Controller } //提现审核列表 - public function withdrawalLogs(Request $request){ + public function withdrawalLogs(Request $request) + { $keyword = $request->keyword; - $type = $request->type ??'saas'; + $type = $request->type ?? 'saas'; $has_withdraw = 0; $start_time = date('Y-m-d 00:00:00'); $end_time = date('Y-m-d 23:59:59'); - $status = $request->status??'freezing'; //freezing未审核 finished审核通过 canceled审核失败 - if($type == 'saas'){//saas 商家提现列表 - $logs = MEarningwithdraws::with('anchor:id,m_id,name,mobile,pic','admin:id,nickname,name,mobile,circle_avatar,app_avatar')->where('status',$status)->where('m_user_id',0)->where('created_at','>','2022-02-24 00:00:00'); - if($keyword){ + $status = $request->status ?? 'freezing'; //freezing未审核 finished审核通过 canceled审核失败 + if ($type == 'saas') {//saas 商家提现列表 + $logs = MEarningwithdraws::with('anchor:id,m_id,name,mobile,pic', 'admin:id,nickname,name,mobile,circle_avatar,app_avatar')->where('status', $status)->where('m_user_id', 0)->where('created_at', '>', '2022-02-24 00:00:00'); + if ($keyword) { $keyword = trim($keyword); - $logs->whereHas('anchor',function($sql) use($keyword){ - $sql->where('name','like','%'.$keyword.'%') - ->orWhere('mobile','like','%'.$keyword.'%'); + $logs->whereHas('anchor', function ($sql) use ($keyword) { + $sql->where('name', 'like', '%' . $keyword . '%') + ->orWhere('mobile', 'like', '%' . $keyword . '%'); }); } - }elseif($type == 'h5'){//福恋h5用户提现列表 - $logs = EarningWithdraw::with('user:id,name,nickname,mobile,circle_avatar,app_avatar','admin:id,nickname,name,mobile,circle_avatar,app_avatar')->where('status',$status)->where('created_at','>','2022-02-24 00:00:00'); - if($keyword){ + } elseif ($type == 'h5') {//福恋h5用户提现列表 + $logs = EarningWithdraw::with('user:id,name,nickname,mobile,circle_avatar,app_avatar', 'admin:id,nickname,name,mobile,circle_avatar,app_avatar')->where('status', $status)->where('created_at', '>', '2022-02-24 00:00:00'); + if ($keyword) { $keyword = trim($keyword); - $logs->whereHas('user',function($sql) use($keyword){ - $sql->where('name','like','%'.$keyword.'%') - ->orWhere('mobile','like','%'.$keyword.'%') - ->orWhere('nickname','like','%'.$keyword.'%'); + $logs->whereHas('user', function ($sql) use ($keyword) { + $sql->where('name', 'like', '%' . $keyword . '%') + ->orWhere('mobile', 'like', '%' . $keyword . '%') + ->orWhere('nickname', 'like', '%' . $keyword . '%'); }); } - }else{//saas H5用户提现列表 - $logs = MEarningwithdraws::with('user:id,nickname,mobile,pic as avatar','admin:id,nickname,name,mobile,circle_avatar,app_avatar')->where('status',$status)->where('m_user_id','<>',0)->where('created_at','>','2022-02-24 00:00:00'); - if($keyword){ + } else {//saas H5用户提现列表 + $logs = MEarningwithdraws::with('user:id,nickname,mobile,pic as avatar', 'admin:id,nickname,name,mobile,circle_avatar,app_avatar')->where('status', $status)->where('m_user_id', '<>', 0)->where('created_at', '>', '2022-02-24 00:00:00'); + if ($keyword) { $keyword = trim($keyword); - $logs->whereHas('user',function($sql) use($keyword){ - $sql->where('nickname','like','%'.$keyword.'%') - ->orWhere('mobile','like','%'.$keyword.'%'); + $logs->whereHas('user', function ($sql) use ($keyword) { + $sql->where('nickname', 'like', '%' . $keyword . '%') + ->orWhere('mobile', 'like', '%' . $keyword . '%'); }); } } - $logs = $logs->orderBy('id','desc')->paginate(); + $logs = $logs->orderBy('id', 'desc')->paginate(); foreach ($logs as $key => $log) { - if($log->m_id){//saas端提现 - $has_withdraw = MEarningwithdraws::where(['m_id'=>$log->m_id,'m_user_id'=>$log->m_user_id,'status'=>'finished'])->whereBetWeen('created_at',[$start_time,$end_time])->sum('value'); - }elseif($log->user_id){//h5提现 - $has_withdraw = EarningWithdraw::where(['user_id'=>$log->user_id,'status'=>'finished'])->whereBetWeen('created_at',[$start_time,$end_time])->sum('value'); + if ($log->m_id) {//saas端提现 + $has_withdraw = MEarningwithdraws::where(['m_id' => $log->m_id, 'm_user_id' => $log->m_user_id, 'status' => 'finished'])->whereBetWeen('created_at', [$start_time, $end_time])->sum('value'); + } elseif ($log->user_id) {//h5提现 + $has_withdraw = EarningWithdraw::where(['user_id' => $log->user_id, 'status' => 'finished'])->whereBetWeen('created_at', [$start_time, $end_time])->sum('value'); } $log->has_withdraw = $has_withdraw;//用户当日提现金额 } - return $this->success('ok',$logs); + return $this->success('ok', $logs); } /** @@ -310,64 +319,73 @@ class EarningController extends Controller * @param $id * @return JsonResponse|string */ - public function auditWithdraw(Request $request,$id){ + public function auditWithdraw(Request $request, $id) + { try { $admin_id = auth()->id(); - $log = MEarningwithdraws::where('id',$id)->where('status','freezing')->first(); - if(empty($log)) return $this->failure('该记录不存在或已被其他管理员审核'); + $log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first(); + if (empty($log)) + return $this->failure('该记录不存在或已被其他管理员审核'); //获取该商户的收益账号 - $account = MEarningAccount::where('m_id',$log->m_id)->where('m_user_id',0)->first(); + $account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', 0)->first(); $balance = $account->balance;//账户余额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 //如果当前用户冻结提现金额 小于 本次提现金额 - if($frozen_withdraw < $log->value) return $this->failure('当前账户异常,联系开发人员处理'); - $anchor = Anchor::where('m_id',$log->m_id)->first(); - $openid = MerchantAccount::where('id',$log->m_id)->value('openid');//商家openid - if(empty($openid)) $openid = $anchor->openid; - if($log->way == 'alipay'){ + if ($frozen_withdraw < $log->value) + return $this->failure('当前账户异常,联系开发人员处理'); + $anchor = Anchor::where('m_id', $log->m_id)->first(); + $openid = MerchantAccount::where('id', $log->m_id)->value('openid');//商家openid + if (empty($openid)) + $openid = $anchor->openid; + if ($log->way == 'alipay') { $transfer_way = '支付宝'; - }elseif($log->way == 'weixin'){ + } elseif ($log->way == 'weixin') { $transfer_way = '微信'; - }elseif($log->way == 'bank'){ + } elseif ($log->way == 'bank') { $transfer_way = '银行卡'; } $status = $request->status; - if(!in_array($status,['finished','canceled','manual'])) throw new \Exception("提供审核参数有误",1); + if (!in_array($status, ['finished', 'canceled', 'manual'])) + throw new \Exception("提供审核参数有误", 1); $data = []; $data['remark'] = '提现已到账'; //提现备注 $data['out_biz_no'] = $log->trade_no; $data['amount'] = $log->real_value;//实际到账金额 $data['payee_account'] = $log->account;//支付宝账号 $data['payee_real_name'] = $log->name;//支付宝绑定姓名 - if($log->alipay_id) $data['payee_account'] = $log->alipay_id; + if ($log->alipay_id) + $data['payee_account'] = $log->alipay_id; $url = ''; DB::beginTransaction(); - switch ($status){ + switch ($status) { case 'finished': //审核通过 - if($log->way == 'alipay'){ + if ($log->way == 'alipay') { $ali = new LiveAlipayService(); - if($log->alipay_id){//通过支付宝id打款 + if ($log->alipay_id) {//通过支付宝id打款 $result = $ali->UserTransferAccount($data); - }else{//通过支付宝账号和名字打款 + } else {//通过支付宝账号和名字打款 $result = $ali->platTransferAccount($data); } - }elseif($log->way == 'weixin'){ - $result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,'提现已到账'); - }elseif($log->way == 'bank'){ - $result = \WechatService::bankTransfer($log->trade_no,$log->account,$log->name,$log->bank_code,$log->real_value * 100,'打款至个人银行卡'); + } elseif ($log->way == 'weixin') { + // $result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,'提现已到账'); + // 商家转账(需用户确认) + $result = \WechatService::officialUserTransferV3($log); + + } elseif ($log->way == 'bank') { + $result = \WechatService::bankTransfer($log->trade_no, $log->account, $log->name, $log->bank_code, $log->real_value * 100, '打款至个人银行卡'); } //\Log::info($result); //判断打款是否成功 - if(is_array($result)){//失败 + if (is_array($result)) {//失败 //\Log::info('打款失败'); $err_msg = isset($result['msg']) ? $result['msg'] : $result['err_code_des']; return $this->failure($err_msg); - $log->update(['status'=>'canceled','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'err_msg'=>$err_msg]); - $account->update(['frozen_withdraw'=>$frozen_withdraw - $log->value,'balance'=>$balance + $log->value]); + $log->update(['status' => 'canceled', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $err_msg]); + $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); // 短信通知 邓智锋 $mobile = '15707534403'; $message = '商户' . $anchor->name . ' 提现' . $log->real_value . '元失败,原因:' . $err_msg; - $this->sentMessage($mobile,$message); + $this->sentMessage($mobile, $message); //模板通知 邓智锋 $data['touser'] = ['oPC_2vnSECnYp5p--uaq3rca3Ry0', 'oPC_2vpJd34uN2E1tTsFbf8Lhlcs']; $data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs'; @@ -381,13 +399,13 @@ class EarningController extends Controller ]; SendTemplateMsg::dispatch($data)->onQueue('template_message'); //短信通知 - $message = $anchor->name.',提现'.$log->real_value.'元失败,具体原因请查看你的后台系统的提现反馈。'; - $this->sentMessage($anchor->mobile,$message); + $message = $anchor->name . ',提现' . $log->real_value . '元失败,具体原因请查看你的后台系统的提现反馈。'; + $this->sentMessage($anchor->mobile, $message); DB::commit(); return $this->failure($err_msg); - }else{//成功 + } else {//成功 //\Log::info('打款成功'); - $log->update(['status'=>'finished','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s')]); + $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]); //将冻结提现金额 换成已提现金额 //冻结提现金额 0 $account->withdrawl = $account->withdrawl + $log->value; $account->frozen_withdraw = $account->frozen_withdraw - $log->value; @@ -397,23 +415,24 @@ class EarningController extends Controller $data['template_id'] = 'aV4ic7jr5bOlf55CgR0jmMsFYyhdRAiVmqqXEjnUqQU'; $data['url'] = $url; $data['data'] = [ - 'first' => '提现已到账,请在'.$transfer_way.'查收', + 'first' => '提现已到账,请在' . $transfer_way . '查收', 'keyword1' => $log->real_value . '元', 'keyword2' => date('Y-m-d H:i:s'), - 'keyword3' => '提现到'.$transfer_way.'余额', + 'keyword3' => '提现到' . $transfer_way . '余额', 'remark' => '感谢您的的使用', ]; SendTemplateMsg::dispatch($data)->onQueue('template_message'); //短信通知 - $message = $anchor->name.',提现金额'.$log->real_value.'元已到账,请在'.$transfer_way.'查收。'; - $this->sentMessage($anchor->mobile,$message); + $message = $anchor->name . ',提现金额' . $log->real_value . '元已到账,请在' . $transfer_way . '查收。'; + $this->sentMessage($anchor->mobile, $message); } break; case 'canceled': //审核拒绝 $reason = $request->reason; - if(!$reason) return $this->failure('请输入拒绝理由'); - $account->update(['frozen_withdraw'=>$frozen_withdraw - $log->value,'balance'=>$balance + $log->value]); - $log->update(['status'=>$status,'admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'err_msg'=>$request->reason]); + if (!$reason) + return $this->failure('请输入拒绝理由'); + $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); + $log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]); $data['touser'] = $openid; $data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs'; $data['url'] = $url; @@ -424,24 +443,24 @@ class EarningController extends Controller 'keyword3' => $reason, 'remark' => '账号信息存在异常', ]; - $message = $anchor->name.',提现'.$log->real_value.'元失败,失败原因:'.$reason.',具体原因请查看你的后台系统的提现反馈。'; - $this->sentMessage($anchor->mobile,$message); + $message = $anchor->name . ',提现' . $log->real_value . '元失败,失败原因:' . $reason . ',具体原因请查看你的后台系统的提现反馈。'; + $this->sentMessage($anchor->mobile, $message); SendTemplateMsg::dispatch($data)->onQueue('template_message'); break; case 'manual': //手工处理 //\Log::info('打款已经由人工处理'); - $log->update(['status'=>'finished','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'way'=>'manual']); + $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'way' => 'manual']); //将冻结提现金额 换成已提现金额 //冻结提现金额 0 $account->withdrawl = $account->withdrawl + $log->value; $account->frozen_withdraw = $account->frozen_withdraw - $log->value; $account->save(); //模板通知用户 - $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4','oPC_2vuTj7YRgUzQQY7PlSJVLBBc']; + $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4', 'oPC_2vuTj7YRgUzQQY7PlSJVLBBc']; $data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY'; $data['url'] = $url; $data['data'] = [ 'first' => '商户:' . $anchor->name . '提现人工审核通过,处理方式:手工打款,请即时处理', - 'keyword1' => $anchor->name, + 'keyword1' => $anchor->name, 'keyword2' => date('Y-m-d H:i:s'), 'keyword3' => $log->real_value . '元', 'keyword4' => '手动打款处理', @@ -462,56 +481,61 @@ class EarningController extends Controller } //福恋h5提现审核 - public function auditWithdrawH5(Request $request,$id){ + public function auditWithdrawH5(Request $request, $id) + { try { $admin_id = auth()->id(); - $log = EarningWithdraw::where('id',$id)->where('status','freezing')->first(); - if(empty($log)) return $this->failure('该记录不存在或已被其他管理员审核'); + $log = EarningWithdraw::where('id', $id)->where('status', 'freezing')->first(); + if (empty($log)) + return $this->failure('该记录不存在或已被其他管理员审核'); //获取该用户的收益账号 - $account = EarningAccount::where('user_id',$log->user_id)->first(); + $account = EarningAccount::where('user_id', $log->user_id)->first(); $balance = $account->balance;//账户余额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 //如果当前用户冻结提现金额 小于 本次提现金额 - if($frozen_withdraw < $log->value) return $this->failure('当前账户异常,联系开发人员处理'); - $user = User::where('id',$log->user_id)->first(); + if ($frozen_withdraw < $log->value) + return $this->failure('当前账户异常,联系开发人员处理'); + $user = User::where('id', $log->user_id)->first(); $openid = $user->wechat ? $user->wechat->official_openid : ''; $transfer_way = $log->way == 'alipay' ? '支付宝' : '微信';//转账方式 $status = $request->status; - if(!in_array($status,['finished','canceled','manual'])) throw new \Exception("提供审核参数有误",1); + if (!in_array($status, ['finished', 'canceled', 'manual'])) + throw new \Exception("提供审核参数有误", 1); $data = []; $data['remark'] = '提现已到账'; //提现备注 $data['out_biz_no'] = $log->trade_no; $data['amount'] = $log->real_value;//实际到账金额 $data['payee_account'] = $log->account;//支付宝账号 $data['payee_real_name'] = $log->name;//支付宝绑定姓名 - if($log->alipay_id) $data['payee_account'] = $log->alipay_id; + if ($log->alipay_id) + $data['payee_account'] = $log->alipay_id; $ali = new LiveAlipayService(); $url = ''; - $alipay_real_name = empty($data['payee_real_name']) ? $data['alipay_id'] :$data['payee_real_name']; + $alipay_real_name = empty($data['payee_real_name']) ? $data['alipay_id'] : $data['payee_real_name']; DB::beginTransaction(); - if($status == 'finished'){//审核通过 + if ($status == 'finished') {//审核通过 //todo 打款 发送通知 - if($log->way == 'alipay'){ - if($log->alipay_id){//通过支付宝id打款 + if ($log->way == 'alipay') { + if ($log->alipay_id) {//通过支付宝id打款 $result = $ali->UserTransferAccount($data); - }else{//通过支付宝账号和名字打款 + } else {//通过支付宝账号和名字打款 $result = $ali->platTransferAccount($data); } - }elseif($log->way == 'weixin'){ - $result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,'提现已到账'); + } elseif ($log->way == 'weixin') { + $result = \WechatService::officialUserTransferV2($log->trade_no, $log->account, $log->real_value * 100, '提现已到账'); } //\Log::info($result); //判断打款是否成功 - if(is_array($result)){//失败 + if (is_array($result)) {//失败 //\Log::info('打款失败'); $err_msg = isset($result['msg']) ? $result['msg'] : $result['err_code_des']; return $this->failure($err_msg); - $log->update(['status'=>'canceled','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'err_msg'=>$err_msg]); - $account->update(['frozen_withdraw'=>$frozen_withdraw - $log->value,'balance'=>$balance + $log->value]); + $log->update(['status' => 'canceled', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $err_msg]); + $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); // 短信通知 邓智锋 $mobile = '15707534403'; $message = '福恋h5用户' . $alipay_real_name . ' 提现' . $log->value . '元失败,原因:' . $err_msg; - $this->sentMessage($mobile,$message); + $this->sentMessage($mobile, $message); //模板通知 邓智锋 $data['touser'] = ['oPC_2vnSECnYp5p--uaq3rca3Ry0', 'oPC_2vpJd34uN2E1tTsFbf8Lhlcs']; $data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs'; @@ -525,13 +549,13 @@ class EarningController extends Controller ]; SendTemplateMsg::dispatch($data)->onQueue('template_message'); //短信通知 - $message = $user->name.',提现'.$log->value.'元失败,具体原因请查看你的后台系统的提现反馈。'; - $this->sentMessage($user->mobile,$message); + $message = $user->name . ',提现' . $log->value . '元失败,具体原因请查看你的后台系统的提现反馈。'; + $this->sentMessage($user->mobile, $message); DB::commit(); return $this->failure($err_msg); - }else{//成功 + } else {//成功 //\Log::info('打款成功'); - $log->update(['status'=>'finished','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s')]); + $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]); //将冻结提现金额 换成已提现金额 //冻结提现金额 0 $account->withdrawl = $account->withdrawl + $log->value; $account->frozen_withdraw = $account->frozen_withdraw - $log->value; @@ -541,22 +565,23 @@ class EarningController extends Controller $data['template_id'] = 'aV4ic7jr5bOlf55CgR0jmMsFYyhdRAiVmqqXEjnUqQU'; $data['url'] = $url; $data['data'] = [ - 'first' => '提现已到账,请在'.$transfer_way.'查收', + 'first' => '提现已到账,请在' . $transfer_way . '查收', 'keyword1' => $log->real_value . '元', 'keyword2' => date('Y-m-d H:i:s'), - 'keyword3' => '提现到'.$transfer_way.'余额', + 'keyword3' => '提现到' . $transfer_way . '余额', 'remark' => '感谢您的的使用', ]; SendTemplateMsg::dispatch($data)->onQueue('template_message'); //短信通知 - $message = $user->name.',提现金额'.$log->real_value.'元已到账,请在'.$transfer_way.'查收。'; - $this->sentMessage($user->mobile,$message); + $message = $user->name . ',提现金额' . $log->real_value . '元已到账,请在' . $transfer_way . '查收。'; + $this->sentMessage($user->mobile, $message); } - }elseif($status == 'canceled'){//审核失败 + } elseif ($status == 'canceled') {//审核失败 $reason = $request->reason; - if(!$reason) return $this->failure('请输入拒绝理由'); - $account->update(['frozen_withdraw'=>$frozen_withdraw - $log->value,'balance'=>$balance + $log->value]); - $log->update(['status'=>$status,'admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'err_msg'=>$request->reason]); + if (!$reason) + return $this->failure('请输入拒绝理由'); + $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); + $log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]); //todo 短信通知 公众号通知拒绝理由 $data['touser'] = $openid; $data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs'; @@ -568,23 +593,23 @@ class EarningController extends Controller 'keyword3' => $reason, 'remark' => '账号信息存在异常', ]; - $message = $user->name.',提现'.$log->real_value.'元失败,失败原因:'.$reason.',具体原因请查看你的后台系统的提现反馈。'; - $this->sentMessage($user->mobile,$message); + $message = $user->name . ',提现' . $log->real_value . '元失败,失败原因:' . $reason . ',具体原因请查看你的后台系统的提现反馈。'; + $this->sentMessage($user->mobile, $message); SendTemplateMsg::dispatch($data)->onQueue('template_message'); - }elseif($status == 'manual'){ + } elseif ($status == 'manual') { //\Log::info('打款已经由人工处理'); - $log->update(['status'=>'finished','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'way'=>'manual']); + $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'way' => 'manual']); //将冻结提现金额 换成已提现金额 //冻结提现金额 0 $account->withdrawl = $account->withdrawl + $log->value; $account->frozen_withdraw = $account->frozen_withdraw - $log->value; $account->save(); //模板通知用户 - $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4','oPC_2vuTj7YRgUzQQY7PlSJVLBBc']; + $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4', 'oPC_2vuTj7YRgUzQQY7PlSJVLBBc']; $data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY'; $data['url'] = $url; $data['data'] = [ 'first' => '商户:' . $alipay_real_name . '提现人工审核通过,处理方式:手工打款,请即时处理', - 'keyword1' => $alipay_real_name, + 'keyword1' => $alipay_real_name, 'keyword2' => date('Y-m-d H:i:s'), 'keyword3' => $log->real_value . '元', 'keyword4' => '手动打款处理', @@ -608,61 +633,66 @@ class EarningController extends Controller * @param $id * @return JsonResponse|string */ - public function auditWithdrawSaasH5(Request $request,$id){ + public function auditWithdrawSaasH5(Request $request, $id) + { try { $admin_id = auth()->id(); - $log = MEarningwithdraws::where('id',$id)->where('status','freezing')->first(); - if(empty($log)) return $this->failure('该记录不存在或已被其他管理员审核'); + $log = MEarningwithdraws::where('id', $id)->where('status', 'freezing')->first(); + if (empty($log)) + return $this->failure('该记录不存在或已被其他管理员审核'); //获取该用户的收益账号 - $account = MEarningAccount::where('m_id',$log->m_id)->where('m_user_id',$log->m_user_id)->first(); + $account = MEarningAccount::where('m_id', $log->m_id)->where('m_user_id', $log->m_user_id)->first(); $balance = $account->balance;//账户余额 $frozen_withdraw = $account->frozen_withdraw;//账户冻结提现金额 //如果当前用户冻结提现金额 小于 本次提现金额 - if($frozen_withdraw < $log->value) return $this->failure('当前账户异常,联系开发人员处理'); - $merchant_user = MerchantUser::where('id',$log->m_user_id)->first(); + if ($frozen_withdraw < $log->value) + return $this->failure('当前账户异常,联系开发人员处理'); + $merchant_user = MerchantUser::where('id', $log->m_user_id)->first(); $status = $request->status; - if($log->way == 'alipay'){ + if ($log->way == 'alipay') { $transfer_way = '支付宝'; - }elseif($log->way == 'weixin'){ + } elseif ($log->way == 'weixin') { $transfer_way = '微信'; - }elseif($log->way == 'bank'){ + } elseif ($log->way == 'bank') { $transfer_way = '银行卡'; } - if(!in_array($status,['finished','canceled','manual'])) throw new \Exception("提供审核参数有误",1); + if (!in_array($status, ['finished', 'canceled', 'manual'])) + throw new \Exception("提供审核参数有误", 1); $data = []; $data['remark'] = '提现已到账'; //提现备注 $data['out_biz_no'] = $log->trade_no; $data['amount'] = $log->real_value;//实际到账金额 $data['payee_account'] = $log->account;//支付宝账号 $data['payee_real_name'] = $log->name;//支付宝绑定姓名 - if($log->alipay_id) $data['payee_account'] = $log->alipay_id; + if ($log->alipay_id) + $data['payee_account'] = $log->alipay_id; $ali = new LiveAlipayService(); $url = ''; - $alipay_real_name = empty($data['payee_real_name']) ? $log->alipay_id :$data['payee_real_name']; + $alipay_real_name = empty($data['payee_real_name']) ? $log->alipay_id : $data['payee_real_name']; DB::beginTransaction(); - switch ($status){ + switch ($status) { case 'finished': //审核通过 - if($log->way == 'alipay'){ - if($log->alipay_id){//通过支付宝id打款 + if ($log->way == 'alipay') { + if ($log->alipay_id) {//通过支付宝id打款 $result = $ali->UserTransferAccount($data); - }else{//通过支付宝账号和名字打款 + } else {//通过支付宝账号和名字打款 $result = $ali->platTransferAccount($data); } - }elseif($log->way == 'weixin'){ - $result = \WechatService::officialUserTransferV2($log->trade_no,$log->account,$log->real_value * 100,'提现已到账'); + } elseif ($log->way == 'weixin') { + $result = \WechatService::officialUserTransferV2($log->trade_no, $log->account, $log->real_value * 100, '提现已到账'); } //\Log::info($result); //判断打款是否成功 - if(is_array($result)){//失败 + if (is_array($result)) {//失败 $err_msg = isset($result['msg']) ? $result['msg'] : $result['err_code_des']; //\Log::info('打款失败'); return $this->failure($err_msg); - $log->update(['status'=>'canceled','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'err_msg'=>$err_msg]); - $account->update(['frozen_withdraw'=>$frozen_withdraw - $log->value,'balance'=>$balance + $log->value]); + $log->update(['status' => 'canceled', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $err_msg]); + $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); // 短信通知 邓智锋 $mobile = '15707534403'; $message = 's端用户' . $alipay_real_name . ' 提现' . $log->real_value . '元失败,原因:' . $err_msg; - $this->sentMessage($mobile,$message); + $this->sentMessage($mobile, $message); //模板通知 邓智锋 $data['touser'] = ['oPC_2vnSECnYp5p--uaq3rca3Ry0', 'oPC_2vpJd34uN2E1tTsFbf8Lhlcs']; $data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs'; @@ -676,13 +706,13 @@ class EarningController extends Controller ]; SendTemplateMsg::dispatch($data)->onQueue('template_message'); //短信通知 - $message = $log->name.',提现'.$log->real_value.'元失败,具体原因请查看你的后台系统的提现反馈。'; - $this->sentMessage($merchant_user->mobile,$message); + $message = $log->name . ',提现' . $log->real_value . '元失败,具体原因请查看你的后台系统的提现反馈。'; + $this->sentMessage($merchant_user->mobile, $message); DB::commit(); return $this->failure($err_msg); - }else{//成功 + } else {//成功 //\Log::info('打款成功'); - $log->update(['status'=>'finished','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s')]); + $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s')]); //将冻结提现金额 换成已提现金额 //冻结提现金额 0 $account->withdrawl = $account->withdrawl + $log->value; $account->frozen_withdraw = $account->frozen_withdraw - $log->value; @@ -692,23 +722,24 @@ class EarningController extends Controller $data['template_id'] = 'aV4ic7jr5bOlf55CgR0jmMsFYyhdRAiVmqqXEjnUqQU'; $data['url'] = $url; $data['data'] = [ - 'first' => '提现已到账,请在'.$transfer_way.'查收', + 'first' => '提现已到账,请在' . $transfer_way . '查收', 'keyword1' => $log->real_value . '元', 'keyword2' => date('Y-m-d H:i:s'), - 'keyword3' => '提现到'.$transfer_way.'余额', + 'keyword3' => '提现到' . $transfer_way . '余额', 'remark' => '感谢您的使用', ]; SendTemplateMsg::dispatch($data)->onQueue('template_message'); //短信通知 - $message = $log->name.',提现金额'.$log->real_value.'元已到账,请在'.$transfer_way.'查收。'; - $this->sentMessage($merchant_user->mobile,$message); + $message = $log->name . ',提现金额' . $log->real_value . '元已到账,请在' . $transfer_way . '查收。'; + $this->sentMessage($merchant_user->mobile, $message); } break; case 'canceled': //审核拒绝 $reason = $request->reason; - if(!$reason) return $this->failure('请输入拒绝理由'); - $account->update(['frozen_withdraw'=>$frozen_withdraw - $log->value,'balance'=>$balance + $log->value]); - $log->update(['status'=>$status,'admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'err_msg'=>$request->reason]); + if (!$reason) + return $this->failure('请输入拒绝理由'); + $account->update(['frozen_withdraw' => $frozen_withdraw - $log->value, 'balance' => $balance + $log->value]); + $log->update(['status' => $status, 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'err_msg' => $request->reason]); //todo 短信通知 公众号通知拒绝理由 $data['touser'] = $merchant_user->openid; $data['template_id'] = 'AqwVt0liVmQfzfnX3ZGvmVOdOh62nkCbhlOUI0NVQGs'; @@ -720,24 +751,24 @@ class EarningController extends Controller 'keyword3' => $reason, 'remark' => '账号信息存在异常', ]; - $message = $log->name.',提现'.$log->real_value.'元失败,失败原因:'.$reason.',具体原因请查看你的后台系统的提现反馈。'; - $this->sentMessage($merchant_user->mobile,$message); + $message = $log->name . ',提现' . $log->real_value . '元失败,失败原因:' . $reason . ',具体原因请查看你的后台系统的提现反馈。'; + $this->sentMessage($merchant_user->mobile, $message); SendTemplateMsg::dispatch($data)->onQueue('template_message'); break; case 'manual': //手工处理 //\Log::info('打款已经由人工处理'); - $log->update(['status'=>'finished','admin_id'=>$admin_id,'audit_at'=>date('Y-m-d H:i:s'),'way'=>'manual']); + $log->update(['status' => 'finished', 'admin_id' => $admin_id, 'audit_at' => date('Y-m-d H:i:s'), 'way' => 'manual']); //将冻结提现金额 换成已提现金额 //冻结提现金额 0 $account->withdrawl = $account->withdrawl + $log->value; $account->frozen_withdraw = $account->frozen_withdraw - $log->value; $account->save(); //模板通知用户 - $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4','oPC_2vuTj7YRgUzQQY7PlSJVLBBc']; + $data['touser'] = ['oPC_2vudVLVHj2U7dNinr2IEDHR4', 'oPC_2vuTj7YRgUzQQY7PlSJVLBBc']; $data['template_id'] = 'OwXPF2dKEjPQUoGyzH944ATsJ6SgxpZ8kzB-KVVxanY'; $data['url'] = $url; $data['data'] = [ 'first' => 's端用户:' . $log->name . '提现人工审核通过,处理方式:手工打款,请即时处理', - 'keyword1' => $log->name, + 'keyword1' => $log->name, 'keyword2' => date('Y-m-d H:i:s'), 'keyword3' => $log->real_value . '元', 'keyword4' => '手动打款处理', @@ -763,15 +794,15 @@ class EarningController extends Controller $users = EarningUser::with('user:id,nickname,name,mobile,photo,app_avatar'); $keyword = $request->input('keyword'); if ($keyword) { - $users = $users->whereHas('user', function ($sql) use($keyword) { - $sql->where('name', 'like', '%'.$keyword.'%') - ->orWhere("nickname", 'like', '%'.$keyword.'%') - ->orWhere('mobile', 'like', '%'.$keyword.'%'); + $users = $users->whereHas('user', function ($sql) use ($keyword) { + $sql->where('name', 'like', '%' . $keyword . '%') + ->orWhere("nickname", 'like', '%' . $keyword . '%') + ->orWhere('mobile', 'like', '%' . $keyword . '%'); }); } $users = $users->orderByDesc('id')->paginate(); return $this->success('ok', $users); - }catch (Exception $e) { + } catch (Exception $e) { $this->getError($e); return $this->failure("获取信息失败,请联系开发人员"); } @@ -781,16 +812,17 @@ class EarningController extends Controller { try { $user_id = $request->input('user_id'); - if (empty($user_id)) throw new Exception("缺少用户id参数"); + if (empty($user_id)) + throw new Exception("缺少用户id参数"); $user = User::find($user_id); $euser = EarningUser::where('user_id', $user_id)->first(); if (empty($euser)) { - $euser = EarningUser::create(['user_id'=>$user_id]); + $euser = EarningUser::create(['user_id' => $user_id]); //短信通知 - SendEasySms::dispatch(['mobile'=>$user->mobile, 'message'=>'恭喜你,已成为福恋合作老师,邀请新朋友注册产生消费,将会获得对应比例的收益,快邀请身边的单身朋友加入吧'])->onQueue('love'); + SendEasySms::dispatch(['mobile' => $user->mobile, 'message' => '恭喜你,已成为福恋合作老师,邀请新朋友注册产生消费,将会获得对应比例的收益,快邀请身边的单身朋友加入吧'])->onQueue('love'); } return $this->success('ok', $euser); - }catch (Exception $e) { + } catch (Exception $e) { $this->getError($e); return $this->failure("增加收益用户失败,请联系开发人员"); } @@ -800,10 +832,11 @@ class EarningController extends Controller { try { $user_id = $request->input('user_id'); - if (empty($user_id)) throw new Exception("缺少用户id参数"); - EarningUser::where('user_id', $user_id)->delete(); + if (empty($user_id)) + throw new Exception("缺少用户id参数"); + EarningUser::where('user_id', $user_id)->delete(); return $this->success('ok'); - }catch (Exception $e) { + } catch (Exception $e) { $this->getError($e); return $this->failure("删除收益用户失败,请联系开发人员"); } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index f86f03a..f871a25 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -7,6 +7,7 @@ use App\Exports\MessengerExport; use App\Exports\ReportExport; use App\Facades\QrcodeRectService; use App\Facades\WechatService; +use App\Helpers\TokenHelper; use App\Jobs\AddUnionUser; use App\Jobs\MakeSurveyQrcode; use App\Jobs\SaasEarningMPNotice; @@ -41,6 +42,7 @@ use App\Models\UnionUser; use App\Server\ReportFile; use App\Services\LiveAlipayService; use App\Services\OrderService; +use GuzzleHttp\RequestOptions; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Routing\Controller as BaseController; use Illuminate\Foundation\Validation\ValidatesRequests; @@ -144,6 +146,8 @@ use App\Models\Server\MerchantAdmins; use App\Models\Server\TouristOrder; use Illuminate\Support\Facades\Hash; use App\Imports\TestImport; +use GuzzleHttp\Client; + class Controller extends BaseController { use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ResponseJson; @@ -2167,10 +2171,7 @@ class Controller extends BaseController public function test(Request $request) { - $order = TouristOrder::find($request->order_id); - $orderService = new OrderService(); - $res = $orderService->storeUftxCustomer($order); - dd($res); + } public function postIndex() diff --git a/app/Services/WechatService.php b/app/Services/WechatService.php index 555742f..9b1dae5 100644 --- a/app/Services/WechatService.php +++ b/app/Services/WechatService.php @@ -1,7 +1,11 @@ -user->get($openid); - $result = !empty($wechatUser)&&isset($wechatUser['subscribe']); - $is_subscribe = $result?$wechatUser['subscribe']:0; + $result = !empty($wechatUser) && isset($wechatUser['subscribe']); + $is_subscribe = $result ? $wechatUser['subscribe'] : 0; return $is_subscribe; } @@ -82,14 +86,14 @@ class WechatService { $merchantId = config('wechat.service_payment.mch_id'); // 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名 - $merchantPrivateKeyFilePath = 'file://'.config('wechat.service_payment.key_path'); + $merchantPrivateKeyFilePath = 'file://' . config('wechat.service_payment.key_path'); $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath, Rsa::KEY_TYPE_PRIVATE); // 「商户API证书」的「证书序列号」 $merchantCertificateSerial = config('wechat.service_payment.serial'); // 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名 - $platformCertificateFilePath = 'file://'.config('wechat.service_payment.cert_path'); + $platformCertificateFilePath = 'file://' . config('wechat.service_payment.cert_path'); $platformPublicKeyInstance = Rsa::from($platformCertificateFilePath, Rsa::KEY_TYPE_PUBLIC); // 从「微信支付平台证书」中获取「证书序列号」 @@ -97,17 +101,18 @@ class WechatService // 构造一个 APIv3 客户端实例 $instance = Builder::factory([ - 'mchid' => $merchantId, - 'serial' => $merchantCertificateSerial, + 'mchid' => $merchantId, + 'serial' => $merchantCertificateSerial, 'privateKey' => $merchantPrivateKeyInstance, - 'certs' => [ + 'certs' => [ $platformCertificateSerial => $platformPublicKeyInstance, ], ]); return $instance; } - public function app(){ + public function app() + { return $this->app; } @@ -133,58 +138,58 @@ class WechatService //通用发短信任务 public function sentMessage($mobile, $message) { - $this->sms->sentMessage( $mobile, $message); + $this->sms->sentMessage($mobile, $message); } - public function constructWXH5Pay($pay_order, $user_id, $detail, $activity_id=null,$callback='') + public function constructWXH5Pay($pay_order, $user_id, $detail, $activity_id = null, $callback = '') { $spbill_create_ip = $this->getClientIp(); // $spbill_create_ip = $_SERVER['REMOTE_ADDR']; // $spbill_create_ip = '113.97.32.78'; - if(!$callback) - $callback = config('app.url').'/api/mark/order/pay/'.$pay_order['trade_no']; + if (!$callback) + $callback = config('app.url') . '/api/mark/order/pay/' . $pay_order['trade_no']; $attributes = array( - 'trade_type' => 'MWEB', // JSAPI,NATIVE,APP... - 'body' => $detail, - 'detail' => $detail, - 'out_trade_no' => $pay_order['trade_no'], - 'total_fee' => ($pay_order['cash']*100), - 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'trade_type' => 'MWEB', // JSAPI,NATIVE,APP... + 'body' => $detail, + 'detail' => $detail, + 'out_trade_no' => $pay_order['trade_no'], + 'total_fee' => ($pay_order['cash'] * 100), + 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'spbill_create_ip' => $spbill_create_ip, ); if ($detail == '购买认证') { - $redirect_url = env('APP_URL').'/mobile/#/authentication'; - }elseif ($detail == '会员充值') { - $redirect_url = env('APP_URL').'/mobile/#/upgrade'; - }elseif ($detail == '参加活动') { - $redirect_url = env('APP_URL').'/mobile/#/activityDetail/'.$activity_id; - }elseif ($detail == '福恋约见') { - $redirect_url = env('APP_URL').'/mobile/#/'; - }elseif ($detail == '奉献金') { - $redirect_url = env('APP_URL').'/mobile/#/'; - }elseif ($detail == '购买课程') { - $redirect_url = env('APP_URL').'/mobile/#/'; + $redirect_url = env('APP_URL') . '/mobile/#/authentication'; + } elseif ($detail == '会员充值') { + $redirect_url = env('APP_URL') . '/mobile/#/upgrade'; + } elseif ($detail == '参加活动') { + $redirect_url = env('APP_URL') . '/mobile/#/activityDetail/' . $activity_id; + } elseif ($detail == '福恋约见') { + $redirect_url = env('APP_URL') . '/mobile/#/'; + } elseif ($detail == '奉献金') { + $redirect_url = env('APP_URL') . '/mobile/#/'; + } elseif ($detail == '购买课程') { + $redirect_url = env('APP_URL') . '/mobile/#/'; } $result = $this->officialPay($attributes, $redirect_url); return $result; } - public function constructWXPay($pay_order, $user_id, $detail='福币充值',$callback='') + public function constructWXPay($pay_order, $user_id, $detail = '福币充值', $callback = '') { $openid = Wechat::where('user_id', $user_id)->value('openid'); - if(!$openid) - $openid = Viewer::where('user_id', $user_id)->value('openid'); - if(!$callback) - $callback = config('app.url').'/api/mark/order/pay/'.$pay_order['trade_no']; + if (!$openid) + $openid = Viewer::where('user_id', $user_id)->value('openid'); + if (!$callback) + $callback = config('app.url') . '/api/mark/order/pay/' . $pay_order['trade_no']; $attributes = array( - 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... - 'body' => $detail, - 'detail' => $detail, - 'out_trade_no' => $pay_order['trade_no'], - 'total_fee' => ($pay_order['cash']*100), - 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 - 'openid' => $openid, + 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... + 'body' => $detail, + 'detail' => $detail, + 'out_trade_no' => $pay_order['trade_no'], + 'total_fee' => ($pay_order['cash'] * 100), + 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'openid' => $openid, ); $result = $this->pay($attributes); return $result; @@ -193,29 +198,29 @@ class WechatService public function constructMiniPay($trade_no, $openid, $total_fee, $body, $detail, $callback) { $attributes = array( - 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... - 'body' => $body, - 'detail' => $detail, - 'out_trade_no' => $trade_no, - 'total_fee' => ($total_fee*100), - 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 - 'openid' => $openid, + 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... + 'body' => $body, + 'detail' => $detail, + 'out_trade_no' => $trade_no, + 'total_fee' => ($total_fee * 100), + 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'openid' => $openid, ); $result = $this->pay($attributes); return $result; } - public function constructSWXPay($order, $openid, $detail='',$callback='') + public function constructSWXPay($order, $openid, $detail = '', $callback = '') { $attributes = array( - 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... - 'body' => $detail, - 'detail' => '打赏金额:'.$order['price'], - 'out_trade_no' => $order['trade_no'], - 'total_fee' => ($order['price']*100), - 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 - 'openid' => $openid, + 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... + 'body' => $detail, + 'detail' => '打赏金额:' . $order['price'], + 'out_trade_no' => $order['trade_no'], + 'total_fee' => ($order['price'] * 100), + 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'openid' => $openid, ); $result = $this->officialPay($attributes); return $result; @@ -224,36 +229,36 @@ class WechatService public function constructSWXServicePay($order, $openid, $body, $detail, $callback) { $attributes = array( - 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... - 'body' => $body, - 'detail' => $detail, - 'out_trade_no' => $order['trade_no'], - 'total_fee' => ($order['price']*100), - 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 - 'openid' => $openid, + 'trade_type' => 'JSAPI', // JSAPI,NATIVE,APP... + 'body' => $body, + 'detail' => $detail, + 'out_trade_no' => $order['trade_no'], + 'total_fee' => ($order['price'] * 100), + 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'openid' => $openid, ); return $attributes; } - public function constructWXAppPay($pay_order, $user_id, $detail="福币充值", $callback='',$link=false) + public function constructWXAppPay($pay_order, $user_id, $detail = "福币充值", $callback = '', $link = false) { $spbill_create_ip = $this->getClientIp(); $attributes = array( - 'trade_type' => 'APP', // JSAPI,NATIVE,APP... - 'body' => '福币充值', - 'detail' => '福币充值', - 'out_trade_no' => $pay_order['trade_no'], - 'total_fee' => ($pay_order['cash']*100), - 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 + 'trade_type' => 'APP', // JSAPI,NATIVE,APP... + 'body' => '福币充值', + 'detail' => '福币充值', + 'out_trade_no' => $pay_order['trade_no'], + 'total_fee' => ($pay_order['cash'] * 100), + 'notify_url' => $callback, // 支付结果通知网址,如果不设置则会使用配置里的默认地址 'spbill_create_ip' => $spbill_create_ip, ); $PayLog = new PayLog; $PayLog->type = 'activity'; $PayLog->user_id = $user_id; - $PayLog->trade_no =$pay_order['trade_no']??''; + $PayLog->trade_no = $pay_order['trade_no'] ?? ''; $PayLog->remark = $callback; $PayLog->save(); - $result = $this->appPay($attributes,$link); + $result = $this->appPay($attributes, $link); return $result; } @@ -264,7 +269,7 @@ class WechatService $and_version = request()->header('version-name'); //\Log::info($ios_version); //\Log::info($and_version); - if(request()->header('ios_version') || request()->header('and_version')) { + if (request()->header('ios_version') || request()->header('and_version')) { return true; } $ios_arr = explode('.', $ios_version); @@ -272,36 +277,36 @@ class WechatService if ($ios_version) { if ($ios_arr[0] > 1) { return true; - }elseif ($ios_arr[0] >= 1 && $ios_arr[1] > 3) { + } elseif ($ios_arr[0] >= 1 && $ios_arr[1] > 3) { + return true; + } elseif ($ios_arr[0] >= 1 && $ios_arr[1] >= 3 && $ios_arr[2] >= 8) { return true; - }elseif ($ios_arr[0] >= 1 && $ios_arr[1] >= 3 && $ios_arr[2] >= 8) { - return true; } } if ($and_version) { if ($and_arr[0] > 1) { return true; - }elseif ($and_arr[0] >= 1 && $and_arr[1] > 3) { + } elseif ($and_arr[0] >= 1 && $and_arr[1] > 3) { + return true; + } elseif ($and_arr[0] >= 1 && $and_arr[1] >= 3 && $and_arr[2] >= 13) { return true; - }elseif ($and_arr[0] >= 1 && $and_arr[1] >= 3 && $and_arr[2] >= 13) { - return true; } } return false; } - public function appPay($attributes,$link=false) + public function appPay($attributes, $link = false) { $attributes['body'] = mb_substr($attributes['body'], 0, 42, 'utf-8'); //新版本换成福恋智能 - if(!$link){ + if (!$link) { $love_pay = $this->isLovePay(); - }else{ + } else { $love_pay = true; } if ($love_pay) { $config = config('wechat.payment'); - }else{ + } else { //旧版本用友福同享 $config = config('wechat.ufutx_payment'); } @@ -314,7 +319,7 @@ class WechatService // $jssdk = $payment->jssdk; $prepayId = ''; $code_url = null; - if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $prepayId = $result['prepay_id']; $result = $payment->jssdk->appConfig($prepayId);//第二次签名 @@ -327,14 +332,15 @@ class WechatService ); } - public function getClientIp() { - if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { + public function getClientIp() + { + if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) { $ip = getenv('HTTP_CLIENT_IP'); - } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { + } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); - } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { + } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) { $ip = getenv('REMOTE_ADDR'); - } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { + } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) { $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = '0.0.0.0'; @@ -343,23 +349,23 @@ class WechatService } - public function officialPay($attributes, $redirect_url='') + public function officialPay($attributes, $redirect_url = '') { try { $attributes['body'] = mb_substr($attributes['body'], 0, 42, 'utf-8'); - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return [ // 'js'=> $this->app->js->config(['chooseWXPay']), - 'config'=>[ - "appId"=> "wxc41491431733671e", - "nonceStr"=> "5cab16345cfbd", - "package"=> "prepay_id=wx081736523006918b9335320e1318134367", - "paySign"=> "394FBA790DD24032EFBD54122FF1373B", - "signType"=> "MD5", - "timestamp"=> "1554716212", + 'config' => [ + "appId" => "wxc41491431733671e", + "nonceStr" => "5cab16345cfbd", + "package" => "prepay_id=wx081736523006918b9335320e1318134367", + "paySign" => "394FBA790DD24032EFBD54122FF1373B", + "signType" => "MD5", + "timestamp" => "1554716212", ], - 'attributes'=>$attributes, - 'pay_qrcode'=>'http://shop.ufutx.com/qrcode/pay/wx20170606161524da84bf4e090195877403', + 'attributes' => $attributes, + 'pay_qrcode' => 'http://shop.ufutx.com/qrcode/pay/wx20170606161524da84bf4e090195877403', ]; } $config = config('wechat.payment'); @@ -370,7 +376,7 @@ class WechatService $jssdk = $payment->jssdk; $prepayId = ''; $code_url = null; - if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $prepayId = $result['prepay_id']; // 这个很重要。有了这个才能调用支付。 // if($attributes['trade_type'] == 'NATIVE'){ @@ -378,14 +384,14 @@ class WechatService // $code_url = $result['code_url']; // } } else { - throw new \Exception($result['err_code_des']??'支付失败', 1); + throw new \Exception($result['err_code_des'] ?? '支付失败', 1); } $config = $jssdk->sdkConfig($prepayId); // 这个方法是取得js里支付所必须的参数用的。 没这个啥也做不了,除非你自己把js的参数生成一遍 return array( - 'config' => $config, - 'attributes' => $attributes, - 'mweb_url' => isset($result['mweb_url'])?$result['mweb_url'].'&redirect_url='.urlencode($redirect_url):'', - ); + 'config' => $config, + 'attributes' => $attributes, + 'mweb_url' => isset($result['mweb_url']) ? $result['mweb_url'] . '&redirect_url=' . urlencode($redirect_url) : '', + ); } catch (\Exception $e) { $this->getError($e); return false; @@ -400,26 +406,26 @@ class WechatService * @param null $is_share 是否启用分帐 * @return array|false */ - public function officialServicePay($attributes, $sub_merchant_id,$is_share = null) + public function officialServicePay($attributes, $sub_merchant_id, $is_share = null) { try { $config = config('wechat.service_payment'); $config['notify_url'] = $attributes['notify_url']; - if($is_share){ + if ($is_share) { $attributes['profit_sharing'] = 'Y'; } $app = Factory::payment($config); $app->setSubMerchant($sub_merchant_id); $result = $app->order->unify($attributes); - if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $config['appId'] = config('wechat.official_account.new.app_id'); $prepayId = $result['prepay_id']; $jssdk = $app->jssdk; $config = $jssdk->sdkConfig($prepayId); - }else{ + } else { $attributes = $result; } - return ['config'=>$config, 'attributes'=>$attributes]; + return ['config' => $config, 'attributes' => $attributes]; } catch (Exception $e) { $this->getError($e); return false; @@ -433,7 +439,7 @@ class WechatService $config = config('wechat.payment'); $config['app_id'] = config('wechat.mini_program.app_id'); $config['notify_url'] = $attributes['notify_url']; - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return array( 'config' => $config, 'attributes' => $attributes, @@ -445,7 +451,7 @@ class WechatService $jssdk = $payment->jssdk; $prepayId = ''; $code_url = null; - if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $prepayId = $result['prepay_id']; // 这个很重要。有了这个才能调用支付。 // if($attributes['trade_type'] == 'NATIVE'){ @@ -453,15 +459,15 @@ class WechatService // $code_url = $result['code_url']; // } } else { - throw new \Exception($result['err_code_des']??'支付失败', 1); + throw new \Exception($result['err_code_des'] ?? '支付失败', 1); } $config = $jssdk->sdkConfig($prepayId); // 这个方法是取得js里支付所必须的参数用的。 没这个啥也做不了,除非你自己把js的参数生成一遍 return array( - // 'js' => $this->app->js->config(['chooseWXPay']), - 'config' => $config, - 'attributes' => $attributes, - 'mweb_url' => isset($result['mweb_url'])?$result['mweb_url']:'', - ); + // 'js' => $this->app->js->config(['chooseWXPay']), + 'config' => $config, + 'attributes' => $attributes, + 'mweb_url' => isset($result['mweb_url']) ? $result['mweb_url'] : '', + ); } catch (\Exception $e) { $this->getError($e); return false; @@ -470,9 +476,9 @@ class WechatService } //发红包 - public function sendNormalRedPack($trade_no, $send_name, $total_amount, $openid, $wishing, $act_name, $remark='') + public function sendNormalRedPack($trade_no, $send_name, $total_amount, $openid, $wishing, $act_name, $remark = '') { - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } $config = config('wechat.payment'); @@ -480,33 +486,33 @@ class WechatService $payment = Factory::payment($config); $redpack = $payment->redpack; $redpackData = [ - 'mch_billno' => $trade_no, - 'send_name' => $send_name, - 're_openid' => $openid, - 'total_num' => 1, //固定为1,可不传 + 'mch_billno' => $trade_no, + 'send_name' => $send_name, + 're_openid' => $openid, + 'total_num' => 1, //固定为1,可不传 'total_amount' => $total_amount, //单位为分,不小于100 - 'wishing' => $wishing, + 'wishing' => $wishing, // 'client_ip' => '192.168.0.1', //可不传,不传则由 SDK 取当前客户端 IP - 'act_name' => $act_name, - 'remark' => $remark, + 'act_name' => $act_name, + 'remark' => $remark, // ... ]; -// \Log::info($redpackData); + // \Log::info($redpackData); // \Log::info($config); $result = $redpack->sendNormal($redpackData); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { //\Log::info($trade_no.'红包订单错误'.json_encode($result)); // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); return false; } - return ; + return; } - public static function sendNormalRedPackV2($trade_no, $send_name, $total_amount, $openid, $wishing, $act_name='', $remark='') + public static function sendNormalRedPackV2($trade_no, $send_name, $total_amount, $openid, $wishing, $act_name = '', $remark = '') { - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } try { @@ -515,21 +521,21 @@ class WechatService $payment = Factory::payment($config); $redpack = $payment->redpack; $redpackData = [ - 'mch_billno' => $trade_no, - 'send_name' => $send_name, - 're_openid' => $openid, - 'total_num' => 1, //固定为1,可不传 + 'mch_billno' => $trade_no, + 'send_name' => $send_name, + 're_openid' => $openid, + 'total_num' => 1, //固定为1,可不传 'total_amount' => $total_amount, //单位为分,不小于100 - 'wishing' => $wishing, + 'wishing' => $wishing, // 'client_ip' => '192.168.0.1', //可不传,不传则由 SDK 取当前客户端 IP - 'act_name' => $act_name, - 'remark' => $remark, + 'act_name' => $act_name, + 'remark' => $remark, // ... ]; $result = $redpack->sendNormal($redpackData); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { //\Log::info($trade_no.'红包订单错误'.json_encode($result)); return $result; // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); @@ -544,29 +550,29 @@ class WechatService } //发红包 - public function sendGroupRedPack($trade_no, $send_name, $total_num=3, $total_amount, $openid, $wishing, $act_name='', $remark='') + public function sendGroupRedPack($trade_no, $send_name, $total_num = 3, $total_amount, $openid, $wishing, $act_name = '', $remark = '') { $config = config('wechat.payment'); $config['app_id'] = config('wechat.app_id'); $payment = Factory::payment($config); $redpack = $payment->redpack; $redpackData = [ - 'mch_billno' => $trade_no, - 'send_name' => $send_name, - 're_openid' => $openid, - 'total_num' => $total_num, //固定为1,可不传 + 'mch_billno' => $trade_no, + 'send_name' => $send_name, + 're_openid' => $openid, + 'total_num' => $total_num, //固定为1,可不传 'total_amount' => $total_amount, //单位为分,不小于100 - 'wishing' => $wishing, + 'wishing' => $wishing, // 'client_ip' => '192.168.0.1', //可不传,不传则由 SDK 取当前客户端 IP - 'act_name' => $act_name, - 'remark' => $remark, + 'act_name' => $act_name, + 'remark' => $remark, // ... ]; $result = $redpack->sendGroup($redpackData); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; // $this->sms->sentMessage('15872844805', '裂变红包发送成功'); - }else{ + } else { //\Log::info($trade_no.'红包订单错误'.json_encode($result)); return $result; // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); @@ -576,9 +582,9 @@ class WechatService return false; } - public static function checkNormalRedPack($trade_no=1576766055175987) + public static function checkNormalRedPack($trade_no = 1576766055175987) { - $res = (object)null; + $res = (object) null; $config = config('wechat.payment'); $config['app_id'] = config('wechat.app_id'); $app = Factory::payment($config); @@ -587,9 +593,9 @@ class WechatService $res->result = $result; $res->status = false; - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { $res->status = true; - }else{ + } else { //\Log::info($trade_no.'红包订单错误'.json_encode($result)); // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); } @@ -601,7 +607,7 @@ class WechatService { //\Log::info('transfer2'); //测试不检查 - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } try { @@ -618,9 +624,9 @@ class WechatService ]; $result = $app->transfer->toBalance($arr); // dd($result); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { //\Log::info($result); //\Log::info($trade_no.'订单转账错误, 错误返回码'.json_encode($result)); // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); @@ -628,7 +634,7 @@ class WechatService } } catch (\Exception $e) { // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误'); - \Log::debug($trade_no.'订单转账错误:'.$e->getMessage()); + \Log::debug($trade_no . '订单转账错误:' . $e->getMessage()); return false; } } @@ -638,7 +644,7 @@ class WechatService { //\Log::info('transfer2'); //测试不检查 - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } $app_id = config('wechat.app_id'); @@ -662,16 +668,16 @@ class WechatService ]; $result = $app->transfer->toBalance($arr); // dd($res) - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return null; - }else{ + } else { //\Log::info($trade_no.'订单转账错误, 错误返回码'.json_encode($result)); // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); return $result; } } catch (Exception $e) { - $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误'); - \Log::debug($trade_no.'订单转账错误:'.$e->getMessage()); + $this->sms->sentMessage('15872844805', $trade_no . '订单转账错误'); + \Log::debug($trade_no . '订单转账错误:' . $e->getMessage()); return true; } } @@ -681,7 +687,7 @@ class WechatService { //\Log::info('transfer2'); //测试不检查 - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } $app_id = config('wechat.official_account.new.app_id'); @@ -704,22 +710,22 @@ class WechatService 'desc' => $desc, // 企业付款操作说明信息。必填 ]; $result = $app->transfer->toBalance($arr); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return null; - }else{ - \Log::info($trade_no.'订单转账错误, 错误返回码'.json_encode($result)); + } else { + \Log::info($trade_no . '订单转账错误, 错误返回码' . json_encode($result)); // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); return $result; } } catch (Exception $e) { - $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误'); - \Log::debug($trade_no.'订单转账错误:'.$e->getMessage()); - return ["msg"=>$e->getMessage(), "err_code_des"=>$e->getMessage()]; + $this->sms->sentMessage('15872844805', $trade_no . '订单转账错误'); + \Log::debug($trade_no . '订单转账错误:' . $e->getMessage()); + return ["msg" => $e->getMessage(), "err_code_des" => $e->getMessage()]; } } //企业付款到个人银行卡 公众号 - public function bankTransfer($trade_no,$bank_no,$enc_true_name, $bank_code,$amount,$desc) + public function bankTransfer($trade_no, $bank_no, $enc_true_name, $bank_code, $amount, $desc) { //\Log::info('transferBank'); //测试不检查 @@ -727,11 +733,11 @@ class WechatService // return true; // } $app_id = config('wechat.official_account.new.app_id'); - $result = $this->officialBankTransfer($app_id, $trade_no,$bank_no,$enc_true_name,$bank_code,$amount, $desc); + $result = $this->officialBankTransfer($app_id, $trade_no, $bank_no, $enc_true_name, $bank_code, $amount, $desc); return $result; } - public function officialBankTransfer($app_id, $trade_no,$bank_no,$enc_true_name,$bank_code, $amount, $desc) + public function officialBankTransfer($app_id, $trade_no, $bank_no, $enc_true_name, $bank_code, $amount, $desc) { try { $config = config('wechat.payment'); @@ -740,22 +746,22 @@ class WechatService $arr = [ 'partner_trade_no' => $trade_no, // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) 'enc_bank_no' => $bank_no, //银行卡号 - 'enc_true_name'=>$enc_true_name, //银行卡对应的用户真实姓名 + 'enc_true_name' => $enc_true_name, //银行卡对应的用户真实姓名 'bank_code' => $bank_code, // 银行编号 例1001 'amount' => $amount, // 付款金额:RMB分(支付总额,不含手续费) 'desc' => $desc, // 付款到银行卡付款说明,即订单备注 非必填 ]; $result = $app->transfer->toBankCard($arr); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return null; - }else{ - \Log::info($trade_no.'订单转账错误, 错误返回码'.json_encode($result)); - $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); + } else { + \Log::info($trade_no . '订单转账错误, 错误返回码' . json_encode($result)); + $this->sms->sentMessage('15872844805', $trade_no . '订单转账错误, 错误原因'); return $result; } } catch (Exception $e) { - $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误'); - \Log::debug($trade_no.'订单转账错误:'.$e->getMessage()); + $this->sms->sentMessage('15872844805', $trade_no . '订单转账错误'); + \Log::debug($trade_no . '订单转账错误:' . $e->getMessage()); $this->getError($e); // return $result; } @@ -775,28 +781,28 @@ class WechatService } //查询企业付款到个人银行卡 公众号 - public function queryBankOrder($app_id,$partner_trade_no) + public function queryBankOrder($app_id, $partner_trade_no) { - try { - $config = config('wechat.payment'); - $config['app_id'] = $app_id; - $app = Factory::payment($config); - $result = $app->transfer->queryBankCardOrder($partner_trade_no); - dd($result); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ - return null; - }else{ - //\Log::info($partner_trade_no.'订单转账错误, 错误返回码'.json_encode($result)); - // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); - return $result; + try { + $config = config('wechat.payment'); + $config['app_id'] = $app_id; + $app = Factory::payment($config); + $result = $app->transfer->queryBankCardOrder($partner_trade_no); + dd($result); + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { + return null; + } else { + //\Log::info($partner_trade_no.'订单转账错误, 错误返回码'.json_encode($result)); + // $this->sms->sentMessage('15872844805', $trade_no.'订单转账错误, 错误原因'); + return $result; + } + } catch (Exception $e) { + // $this->sms->sentMessage('18171893605', $trade_no.'订单转账错误'); + // \Log::debug($trade_no.'订单转账错误:'.$e->getMessage()); + $this->getError($e); + // return $result; } - } catch (Exception $e) { - // $this->sms->sentMessage('18171893605', $trade_no.'订单转账错误'); - // \Log::debug($trade_no.'订单转账错误:'.$e->getMessage()); - $this->getError($e); - // return $result; } -} public function transferred($trade_no) { @@ -820,30 +826,31 @@ class WechatService $app = Factory::payment($config); $result = $app->transfer->queryBalanceOrder($trade_no); // \Log::info('result: '. json_encode($result)); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ - \Log::info($trade_no.'订单检查转账错误, 错误返回码'.json_encode($result)); + } else { + \Log::info($trade_no . '订单检查转账错误, 错误返回码' . json_encode($result)); // $this->sms->sentMessage('15872844805', $trade_no.'订单检查转账错误, 错误原因'.$result['return_msg'].'业务结果'.$result['result_code']); return false; } } catch (Exception $e) { - $this->sms->sentMessage('15872844805', $trade_no.'查询订单订单转账错误'); - \Log::debug($trade_no.'订单检查转账错误:'.$e->getMessage()); + $this->sms->sentMessage('15872844805', $trade_no . '查询订单订单转账错误'); + \Log::debug($trade_no . '订单检查转账错误:' . $e->getMessage()); return false; } } //查询订单支付成功? - public function orderPaid($orderid){ + public function orderPaid($orderid) + { //测试不检查 - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } - try{ + try { $order = LoveOrder::where('trade_no', $orderid)->first(); $tourist_order = TouristOrder::where('trade_no', $orderid)->first(); - if ((isset($order->pay_type) && $order->pay_type== 'wechat') || (isset($tourist_order->pay_type) && $tourist_order->pay_type == 'wechat')) {//app支付 + if ((isset($order->pay_type) && $order->pay_type == 'wechat') || (isset($tourist_order->pay_type) && $tourist_order->pay_type == 'wechat')) {//app支付 $love_config = config('wechat.payment'); $love_config['app_id'] = config('wechat.love_app_id'); $payment = Factory::payment($love_config); @@ -856,27 +863,27 @@ class WechatService $payment = Factory::payment($ufutx_config); $rs = $payment->order->queryByOutTradeNumber($orderid); } - }else{ + } else { $config = config('wechat.payment'); $config['app_id'] = config('wechat.mini_program.app_id'); $payment = Factory::payment($config); $rs = $payment->order->queryByOutTradeNumber($orderid); } - if($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS'){ - if($rs['trade_state'] == 'SUCCESS'){ + if ($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS') { + if ($rs['trade_state'] == 'SUCCESS') { return true; - }else{ - \Log::debug($orderid.'交易状态:'.$rs['trade_state']); + } else { + \Log::debug($orderid . '交易状态:' . $rs['trade_state']); return false; } - }else{ - \Log::debug($orderid.'业务状态:'.$rs['err_code'].$rs['err_code_des']); + } else { + \Log::debug($orderid . '业务状态:' . $rs['err_code'] . $rs['err_code_des']); return false; } - }catch(\Exception $e){ + } catch (\Exception $e) { //abort(505, $orderid.'订单查询异常:'.$e->getMessage()); - \Log::debug($orderid.'订单查询异常:'.$e->getMessage()); + \Log::debug($orderid . '订单查询异常:' . $e->getMessage()); return false; } } @@ -884,13 +891,14 @@ class WechatService /** * 服务端查询H5订单支付是否成功? */ - public function serverH5OrderPaid($order_id){ + public function serverH5OrderPaid($order_id) + { //测试不检查 - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } - try{ + try { $order = TouristOrder::where('trade_no', $order_id)->first(); $love_config = config('wechat.payment'); $love_config['app_id'] = config('wechat.official_account.new.app_id'); @@ -899,31 +907,32 @@ class WechatService //\Log::info($rs); - if($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS'){ - if($rs['trade_state'] == 'SUCCESS'){ + if ($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS') { + if ($rs['trade_state'] == 'SUCCESS') { return true; - }else{ - \Log::debug($order_id.'交易状态:'.$rs['trade_state']); + } else { + \Log::debug($order_id . '交易状态:' . $rs['trade_state']); return false; } - }else{ - \Log::debug($order_id.'业务状态:'.$rs['err_code'].$rs['err_code_des']); + } else { + \Log::debug($order_id . '业务状态:' . $rs['err_code'] . $rs['err_code_des']); return false; } - }catch(\Exception $e){ + } catch (\Exception $e) { //abort(505, $orderid.'订单查询异常:'.$e->getMessage()); - \Log::debug($order_id.'订单查询异常:'.$e->getMessage()); + \Log::debug($order_id . '订单查询异常:' . $e->getMessage()); return false; } } //查询h5订单支付成功? - public function officialOrderPaid($orderid){ + public function officialOrderPaid($orderid) + { //测试不检查 - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } - try{ + try { $order = LoveOrder::where('trade_no', $orderid)->first(); if ($order->pay_type == 'h5') {//h5支付 $love_config = config('wechat.payment'); @@ -933,20 +942,20 @@ class WechatService //\Log::info($rs); } - if($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS'){ - if($rs['trade_state'] == 'SUCCESS'){ + if ($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS') { + if ($rs['trade_state'] == 'SUCCESS') { return true; - }else{ - \Log::debug($orderid.'交易状态:'.$rs['trade_state']); + } else { + \Log::debug($orderid . '交易状态:' . $rs['trade_state']); return false; } - }else{ - \Log::debug($orderid.'业务状态:'.$rs['err_code'].$rs['err_code_des']); + } else { + \Log::debug($orderid . '业务状态:' . $rs['err_code'] . $rs['err_code_des']); return false; } - }catch(\Exception $e){ + } catch (\Exception $e) { //abort(505, $orderid.'订单查询异常:'.$e->getMessage()); - \Log::debug($orderid.'订单查询异常:'.$e->getMessage()); + \Log::debug($orderid . '订单查询异常:' . $e->getMessage()); return false; } } @@ -958,25 +967,25 @@ class WechatService */ public function orderRefunded($refund_trade_no) { - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } - try{ + try { $config = config('wechat.payment'); $config['app_id'] = config('wechat.mini_program.app_id'); $payment = Factory::payment($config); $rs = $payment->refund->queryByOutRefundNumber($refund_trade_no); - if($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS'){ + if ($rs['return_code'] == 'SUCCESS' && $rs['result_code'] == 'SUCCESS') { return true; - }else{ - \Log::debug($refund_trade_no.'业务状态:'.$rs['err_code'].$rs['err_code_des']); - $this->sms->sentMessage('15872844805', $refund_trade_no.'订单查询退款异常, 错误返回码'.$rs['err_code']); + } else { + \Log::debug($refund_trade_no . '业务状态:' . $rs['err_code'] . $rs['err_code_des']); + $this->sms->sentMessage('15872844805', $refund_trade_no . '订单查询退款异常, 错误返回码' . $rs['err_code']); return false; } - }catch(\Exception $e){ + } catch (\Exception $e) { //abort(505, $orderid.'订单查询异常:'.$e->getMessage()); - \Log::debug($refund_trade_no.'订单查询退款异常:'.$e->getMessage()); - $this->sms->sentMessage('15872844805', $refund_trade_no.'订单查询退款异常'); + \Log::debug($refund_trade_no . '订单查询退款异常:' . $e->getMessage()); + $this->sms->sentMessage('15872844805', $refund_trade_no . '订单查询退款异常'); return false; } } @@ -990,37 +999,37 @@ class WechatService * @param array $array 其他参数 * @return bool 是否成功 */ - public function orderRefund($trade_no, $refund_trade_no, $total_fee, $refund_fee, $array=[]) + public function orderRefund($trade_no, $refund_trade_no, $total_fee, $refund_fee, $array = []) { - if(config('wechat.payment.debug')){ + if (config('wechat.payment.debug')) { return true; } try { - $array['notify_url'] = env('APP_URL').'/api/admin/order/refun/callback'; + $array['notify_url'] = env('APP_URL') . '/api/admin/order/refun/callback'; $config = config('wechat.payment'); $config['app_id'] = config('wechat.mini_program.app_id'); - $config['notify_url'] = config('app.url').'/api/admin/order/refun/callback'; + $config['notify_url'] = config('app.url') . '/api/admin/order/refun/callback'; $payment = Factory::payment($config); - $total_fee = (int)number_format($total_fee, 2, '', ''); - $refund_fee = (int)number_format($refund_fee, 2, '', ''); + $total_fee = (int) number_format($total_fee, 2, '', ''); + $refund_fee = (int) number_format($refund_fee, 2, '', ''); Log::info("退款信息:"); Log::info($trade_no); Log::info($refund_trade_no); Log::info($total_fee); Log::info($refund_fee); - Log::info("arr",$array); + Log::info("arr", $array); // 参数分别为:商户订单号、商户退款单号、订单金额、退款金额、其他参数 $result = $payment->refund->byOutTradeNumber($trade_no, $refund_trade_no, $total_fee, $refund_fee, $array); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ - return ['status'=>true,'err_msg'=>null]; - }else{ - \Log::info($refund_trade_no.'订单退款异常, 错误返回码'.json_encode($result));//err_code_des - $this->sms->sentMessage('15872844805', $refund_trade_no.'订单退款异常, 业务结果'.$result['err_code']); - return ['status'=>false,'err_msg'=>$result['err_code_des']]; + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { + return ['status' => true, 'err_msg' => null]; + } else { + \Log::info($refund_trade_no . '订单退款异常, 错误返回码' . json_encode($result));//err_code_des + $this->sms->sentMessage('15872844805', $refund_trade_no . '订单退款异常, 业务结果' . $result['err_code']); + return ['status' => false, 'err_msg' => $result['err_code_des']]; } } catch (Exception $e) { - $this->sms->sentMessage('15872844805', $refund_trade_no.'订单退款异常'); - \Log::debug($refund_trade_no.'订单退款异常:'.$e->getMessage()); + $this->sms->sentMessage('15872844805', $refund_trade_no . '订单退款异常'); + \Log::debug($refund_trade_no . '订单退款异常:' . $e->getMessage()); return false; } } @@ -1028,16 +1037,16 @@ class WechatService /** * 聊天通知 */ - public function chatMessageNotice($param=[]) + public function chatMessageNotice($param = []) { $template_id = config('wechat.tpls.chat_message_notice'); $page = 'pages/users/myMessage'; $openid = $param['openid']; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['name'], - 'keyword2'=>$param['created_at'], - 'keyword3'=>$param['message'], + 'keyword1' => $param['name'], + 'keyword2' => $param['created_at'], + 'keyword3' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1045,7 +1054,7 @@ class WechatService /** * 等级升级通知 */ - public function rankNotice($param=[]) + public function rankNotice($param = []) { //\Log::info('测试'); $template_id = config('wechat.tpls.rank_notice'); @@ -1053,9 +1062,9 @@ class WechatService $openid = $param['openid']; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['rank_name'], - 'keyword2'=>'终身会员', - 'keyword3'=>$param['privilege'], + 'keyword1' => $param['rank_name'], + 'keyword2' => '终身会员', + 'keyword3' => $param['privilege'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1063,15 +1072,15 @@ class WechatService /** * 访问通知 */ - public function visitNotice($param=[]) + public function visitNotice($param = []) { $template_id = config('wechat.tpls.visit_notice'); - $page = 'pages/home/information?id='.$param['user_id']; + $page = 'pages/home/information?id=' . $param['user_id']; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['user_name'], - 'keyword2'=>$param['visit_time'], - 'keyword3'=>$param['message'], + 'keyword1' => $param['user_name'], + 'keyword2' => $param['visit_time'], + 'keyword3' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1079,15 +1088,15 @@ class WechatService /** * 临时会员到期通知 */ - public function VIPEndNotice($param=[]) + public function VIPEndNotice($param = []) { $template_id = config('wechat.tpls.vip_end_notice'); $page = 'pages/tabBar/home'; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['rank_name'], - 'keyword2'=>$param['time'], - 'keyword3'=>$param['message'], + 'keyword1' => $param['rank_name'], + 'keyword2' => $param['time'], + 'keyword3' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1095,15 +1104,15 @@ class WechatService /** * 临时会员到期通知 */ - public function VIPStartNotice($param=[]) + public function VIPStartNotice($param = []) { $template_id = config('wechat.tpls.vip_start_notice'); $page = 'pages/tabBar/user'; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['rank_name'], - 'keyword2'=>$param['name'], - 'keyword3'=>$param['end_time'], + 'keyword1' => $param['rank_name'], + 'keyword2' => $param['name'], + 'keyword3' => $param['end_time'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1113,15 +1122,15 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function recommendSingleNotice($param=[]) + public function recommendSingleNotice($param = []) { $template_id = config('wechat.tpls.recommend_single'); - $page = 'pages/home/information?id='.$param['user_id'].'&channel='.((isset($param['channel']))?$param['channel']:''); + $page = 'pages/home/information?id=' . $param['user_id'] . '&channel=' . ((isset($param['channel'])) ? $param['channel'] : ''); $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['name'], - 'keyword2'=>$param['time'], - 'keyword3'=>$param['message'], + 'keyword1' => $param['name'], + 'keyword2' => $param['time'], + 'keyword3' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1130,15 +1139,15 @@ class WechatService * 好友申请通知 * @param array $param [description] */ - public function addFriendNotice($param=[]) + public function addFriendNotice($param = []) { $template_id = config('wechat.tpls.add_friend_notice'); - $page = 'pages/users/friendRequest?id='.$param['user_id']; + $page = 'pages/users/friendRequest?id=' . $param['user_id']; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['name'], - 'keyword2'=>$param['time'], - 'keyword3'=>$param['message'], + 'keyword1' => $param['name'], + 'keyword2' => $param['time'], + 'keyword3' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1148,14 +1157,14 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function dealFriendRequest($param=[]) + public function dealFriendRequest($param = []) { $template_id = config('wechat.tpls.deal_friend_request'); - $page = 'pages/home/information?id='.$param['user_id']; + $page = 'pages/home/information?id=' . $param['user_id']; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['name'], - 'keyword2'=>$param['message'], + 'keyword1' => $param['name'], + 'keyword2' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } @@ -1165,72 +1174,75 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function vipDeadline($param=[]) + public function vipDeadline($param = []) { $template_id = config('wechat.tpls.vip_deadline'); $page = 'pages/tabBar/home/indexv2'; $form_id = $param['form_id']; $data = [ - 'keyword1'=>$param['rank_name'], - 'keyword2'=>$param['remain_time'], - 'keyword3'=>$param['deadline'], - 'keyword4'=>$param['message'], + 'keyword1' => $param['rank_name'], + 'keyword2' => $param['remain_time'], + 'keyword3' => $param['deadline'], + 'keyword4' => $param['message'], ]; return $this->send($param['openid'], $template_id, $page, $form_id, $data); } - public function agRecommendNotcie($param=[]) + public function agRecommendNotcie($param = []) { $template_id = config('wechat.tpls.ag_recommend_notice'); - $path = 'pages/home/information?id='.$param['user_id'].'&channel='.((isset($param['channel']))?$param['channel']:'');; + $path = 'pages/home/information?id=' . $param['user_id'] . '&channel=' . ((isset($param['channel'])) ? $param['channel'] : ''); + ; $data = [ - 'first'=> $param['title'], - 'keyword1'=>$param['host'], - 'keyword2'=>[ - 'value'=>$param['user_info'], - 'color'=>'#e74c3c' + 'first' => $param['title'], + 'keyword1' => $param['host'], + 'keyword2' => [ + 'value' => $param['user_info'], + 'color' => '#e74c3c' ], - 'keyword3'=>date('Y-m-d H:i:s'), - 'remark'=> $param['remark'], + 'keyword3' => date('Y-m-d H:i:s'), + 'remark' => $param['remark'], ]; - $url = env('APP_URL')."/mobile/#/information/".$param['user_id']; + $url = env('APP_URL') . "/mobile/#/information/" . $param['user_id']; return $this->sendToMiniProgram($param['openid'], $template_id, $path, $data, $url); } /** * 访客提醒 */ - public function visitNoticeV2($param=[]) + public function visitNoticeV2($param = []) { $template_id = config('wechat.tpls.visit_notice_v2'); - $path = 'pages/home/information?id='.$param['user_id']; + $path = 'pages/home/information?id=' . $param['user_id']; $data = [ - 'thing1'=>["value"=>$param['name']], - 'time2'=>["value"=>$param['date']], - 'thing9'=>["value"=>$param['from']], + 'thing1' => ["value" => $param['name']], + 'time2' => ["value" => $param['date']], + 'thing9' => ["value" => $param['from']], ]; - $url = env('APP_URL')."/mobile/#/information/".$param['user_id']; + $url = env('APP_URL') . "/mobile/#/information/" . $param['user_id']; if (isset($param['openid']) && $param['openid']) { return $this->sendToMiniProgram($param['openid'], $template_id, $path, $data, $url); } } /** 受邀请后,注册成功,提示邀请者 */ - public function beRecommendNotcie($user_id,$nickname,$title,$touser_openid){ + public function beRecommendNotcie($user_id, $nickname, $title, $touser_openid) + { $template_id = config('wechat.tpls.be_invite_succeed_notice'); - $path = 'pages/home/information?id='.$user_id; + $path = 'pages/home/information?id=' . $user_id; $data = [ - 'first'=> $title, - 'keyword1'=>$nickname, - 'keyword2'=>date('Y-m-d H:i:s'), - 'remark'=> '感谢您的使用', + 'first' => $title, + 'keyword1' => $nickname, + 'keyword2' => date('Y-m-d H:i:s'), + 'remark' => '感谢您的使用', ]; - $url = env('APP_URL')."/mobile/#/information/".$user_id; + $url = env('APP_URL') . "/mobile/#/information/" . $user_id; return $this->sendToMiniProgram($touser_openid, $template_id, $path, $data, $url); } /** 客服收到新消息 提示客服 */ - public function remindServiceClient($user,$service){ + public function remindServiceClient($user, $service) + { $param['touser'] = $service->wechat ? $service->wechat->official_openid : null; $name = $user->nickname ?: $user->name; // $param['template_id'] = config('wechat.tpls.activity_audited_notice'); @@ -1241,67 +1253,67 @@ class WechatService 'keyword2' => $user->mobile,//客户手机 'remark' => '请及时处理', ]; - $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram']??null); + $this->send($param['touser'], $param['template_id'], $param['url'], $param['data'], $param['miniprogram'] ?? null); } - public function ShareSuccessNotice($param=[]) + public function ShareSuccessNotice($param = []) { - $url = env('APP_URL').'/red/packet/activity/wechat/auth'; + $url = env('APP_URL') . '/red/packet/activity/wechat/auth'; $template_id = config('wechat.tpls.ag_recommend_notice'); $data = [ - 'first'=> '【集九果分百万红包】分享成功', - 'keyword1'=> $param['share_user_name'], - 'keyword2'=>$param['user_name'], - 'remark'=> '恭喜您!获得'.$param['chance'].'次收集果子机会,马上领取GO!', + 'first' => '【集九果分百万红包】分享成功', + 'keyword1' => $param['share_user_name'], + 'keyword2' => $param['user_name'], + 'remark' => '恭喜您!获得' . $param['chance'] . '次收集果子机会,马上领取GO!', ]; $url = $param['url']; return $this->sendToOfficial($param['openid'], $template_id, $data, $url); } - public function reportStatisticNotice($param=[]) + public function reportStatisticNotice($param = []) { $template_id = 'aE8sNkjBajSdX8qcV2pwFhSNXQcCfjjKtwEXfbddVdA'; $data = [ - 'first'=> $param['first'], - 'keyword1'=> $param['keyword1'], - 'keyword2'=>$param['keyword2'], - 'keyword3'=>$param['keyword3'], - 'remark'=> $param['remark'], + 'first' => $param['first'], + 'keyword1' => $param['keyword1'], + 'keyword2' => $param['keyword2'], + 'keyword3' => $param['keyword3'], + 'remark' => $param['remark'], ]; $url = ''; return $this->sendToOfficial($param['openid'], $template_id, $data, $url); } - public function activitySuccessNotice($param=[]) + public function activitySuccessNotice($param = []) { $template_id = config('wechat.tpls.activity_success_notice'); - $path = 'pages/party/detail?party_id='.$param['activity_id']; + $path = 'pages/party/detail?party_id=' . $param['activity_id']; $data = [ - 'first'=> '活动报名通知', - 'keyword1'=> $param['title'], - 'keyword2'=> $param['start_time'], - 'keyword3'=> $param['address'], - 'remark'=> '用户'.$param['user_name'].'['.$param['user_mobile'].']报名活动成功', + 'first' => '活动报名通知', + 'keyword1' => $param['title'], + 'keyword2' => $param['start_time'], + 'keyword3' => $param['address'], + 'remark' => '用户' . $param['user_name'] . '[' . $param['user_mobile'] . ']报名活动成功', ]; // $url = env('APP_URL')."/mobile/#/information/".$param['activity_id']; return $this->sendToMiniProgram($param['openid'], $template_id, $path, $data); } - public function sendToOfficial($openid, $template_id, $data, $url='') + public function sendToOfficial($openid, $template_id, $data, $url = '') { try { $data = [ 'touser' => $openid, 'template_id' => $template_id, 'url' => $url, - 'data' =>$data, + 'data' => $data, ]; - $result = $this->official_app->template_message->send($data); + $result = $this->official_app->template_message->send($data); //Log::info($result); if ($result['errcode'] == 0) {//记录模板消息发送成功 $data['status'] = 1; $data['err_msg'] = null; - }else{ + } else { $data['status'] = 0; $data['err_msg'] = $result['errmsg']; } @@ -1315,13 +1327,13 @@ class WechatService } - public function sendToMiniProgram($openid, $template_id, $path, $data, $url='') + public function sendToMiniProgram($openid, $template_id, $path, $data, $url = '') { try { $data = [ 'touser' => $openid, 'template_id' => $template_id, - 'url'=> $url, + 'url' => $url, 'miniprogram' => [ 'appid' => config('wechat.mini_program.app_id'), 'pagepath' => $path, @@ -1333,7 +1345,7 @@ class WechatService if ($result['errcode'] == 0) {//记录模板消息发送成功 $data['status'] = 1; $data['err_msg'] = null; - }else{ + } else { $data['status'] = 0; $data['err_msg'] = $result['errmsg']; } @@ -1349,21 +1361,22 @@ class WechatService /** * 发送模板消息 */ - public function send($openid, $template_id, $page, $form_id,$data=[]){ + public function send($openid, $template_id, $page, $form_id, $data = []) + { try { $all_data = [ 'touser' => $openid, 'template_id' => $template_id, 'page' => $page, 'form_id' => $form_id, - 'data' =>$data, + 'data' => $data, ]; - $result = $this->app->template_message->send($all_data); + $result = $this->app->template_message->send($all_data); //Log::info($result); if ($result['errcode'] == 0) {//记录模板消息发送成功 $all_data['status'] = 1; $all_data['err_msg'] = null; - }else{ + } else { $all_data['status'] = 0; $all_data['err_msg'] = $result['errmsg']; } @@ -1380,15 +1393,15 @@ class WechatService * 订阅消息 */ //活动报名成功订阅通知 - public function activitySuccessSubNotice($param=[]) + public function activitySuccessSubNotice($param = []) { $template_id = config('wechat.sub_tpls.activity_success_notice'); - $page = "pages/party/detail?party_id=".$param['activity_id']; + $page = "pages/party/detail?party_id=" . $param['activity_id']; $data = [ - 'thing2'=>["value"=>$param['title']], - 'thing3'=>["value"=>$param['address']], - 'time4'=>["value"=>$param['start_time']], - 'phrase1'=>["value"=>"已报名"], + 'thing2' => ["value" => $param['title']], + 'thing3' => ["value" => $param['address']], + 'time4' => ["value" => $param['start_time']], + 'phrase1' => ["value" => "已报名"], ]; return $this->subSend($param['openid'], $template_id, $page, $data); } @@ -1396,15 +1409,15 @@ class WechatService /** * 订单支付成功通知 */ - public function orderSuccessSubNotice($param=[]) + public function orderSuccessSubNotice($param = []) { $template_id = config('wechat.sub_tpls.order_success_notice'); $page = "pages/users/myPay"; $data = [ - 'thing1'=>["value"=>$param['name']], - 'amount5'=>["value"=>$param['price']], - 'date6'=>["value"=>$param['updated_at']], - 'thing8'=>["value"=>""], + 'thing1' => ["value" => $param['name']], + 'amount5' => ["value" => $param['price']], + 'date6' => ["value" => $param['updated_at']], + 'thing8' => ["value" => ""], ]; return $this->subSend($param['openid'], $template_id, $page, $data); } @@ -1414,7 +1427,7 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function signInSubNotice($param=[]) + public function signInSubNotice($param = []) { $template_id = config('wechat.sub_tpls.sign_in_notice'); $page = "pages/tabBar/welcome"; @@ -1432,10 +1445,10 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function followedNotice($param=[]) + public function followedNotice($param = []) { $template_id = config('wechat.sub_tpls.follow_notice'); - $page = "pages/home/information?id=".$param['user_id']; + $page = "pages/home/information?id=" . $param['user_id']; $data = [ 'name1' => ['value' => $param['nickname']], // 用户昵称 'time2' => ['value' => $param['time']], // 关注时间 @@ -1443,7 +1456,7 @@ class WechatService return $this->subSend($param['openid'], $template_id, $page, $data); } - public function friendRequestNotice($param=[]) + public function friendRequestNotice($param = []) { $template_id = config('wechat.sub_tpls.add_friend_notice'); $page = "pages/users/friendRequest"; @@ -1456,10 +1469,10 @@ class WechatService } //活动结束发送问卷调查 - public function sendActivityQuestionaireSurvey($param=[]) + public function sendActivityQuestionaireSurvey($param = []) { $template_id = config('wechat.sub_tpls.activity_questionaire_servey_notice'); - $page = "pages/users/questionnaire?type_id=".$param['activity_id']; + $page = "pages/users/questionnaire?type_id=" . $param['activity_id']; $data = [ 'thing1' => ['value' => $param['nickname']], // 用户昵称 'thing2' => ['value' => $param['theme']], // 活动主题 @@ -1470,12 +1483,12 @@ class WechatService } //团约组团成功通知(发送给拼团人员) - public function sendJoinGroupNotice($param=[]) + public function sendJoinGroupNotice($param = []) { //\Log::info('join_group_success_notice'); $template_id = config('wechat.sub_tpls.join_group_success_notice'); // $page = "pages/users/questionnaire?type_id=".$param['type_id'];/pages/party/SpellGroupOrder - $page = "pages/party/SpellGroupData?order_id=".$param['order_id']."&history_id=".$param['history_id']; + $page = "pages/party/SpellGroupData?order_id=" . $param['order_id'] . "&history_id=" . $param['history_id']; $desc = $param['status'] == 0 ? $param['team_desc'] : $param['desc']; $data = [ 'thing1' => ['value' => $param['title']], // 拼团商品名 @@ -1488,9 +1501,10 @@ class WechatService } //拼团开始通知(发给团长的通知) - public function stratGroupNotice($param){ + public function stratGroupNotice($param) + { $template_id = config('wechat.sub_tpls.start_group_notice'); - $page = "pages/party/SpellGroupOrder?order_id=".$param['order_id']; + $page = "pages/party/SpellGroupOrder?order_id=" . $param['order_id']; $time = date('Y-m-d H:i:s'); //\Log::info('start_group_notice '.$template_id . 'openid='.$param['openid']); $data = [ @@ -1502,15 +1516,16 @@ class WechatService return $this->subSendV2($param['openid'], $template_id, $page, $data); } - public function subSendV2($openid, $template_id, $page, $data=[]) + public function subSendV2($openid, $template_id, $page, $data = []) { try { - if (empty($openid)) return false; + if (empty($openid)) + return false; $all_data = [ - 'template_id'=>$template_id, - 'touser'=>$openid, - 'page'=>$page, - 'data'=>$data, + 'template_id' => $template_id, + 'touser' => $openid, + 'page' => $page, + 'data' => $data, ]; $app = $this->app(); $result = $app->subscribe_message->send($all_data); @@ -1518,7 +1533,7 @@ class WechatService if ($result['errcode'] == 0) {//记录模板消息发送成功 $all_data['status'] = 1; $all_data['err_msg'] = null; - }else{ + } else { $all_data['status'] = 0; $all_data['err_msg'] = $result['errmsg']; } @@ -1537,7 +1552,7 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function matchNotice($param=[]) + public function matchNotice($param = []) { $template_id = config('wechat.sub_tpls.match_notice'); $page = "pages/tabBar/welcome"; @@ -1554,13 +1569,13 @@ class WechatService * @param array $param [description] * @return [type] [description] */ - public function dealFriendRequestNotice($param=[]) + public function dealFriendRequestNotice($param = []) { $template_id = config('wechat.sub_tpls.deal_friend_request_notice'); - if(!$template_id || is_bool($param) || empty($param['user_id'])){ + if (!$template_id || is_bool($param) || empty($param['user_id'])) { return false; } - $page = "pages/home/information?id=".$param['user_id']; + $page = "pages/home/information?id=" . $param['user_id']; $data = [ 'name1' => ['value' => $param['nickname']], // 昵称 'time2' => ['value' => $param['time']], // 时间 @@ -1569,7 +1584,7 @@ class WechatService return $this->subSend($param['openid'], $template_id, $page, $data); } - public function vistitLogNotice($param=[]) + public function vistitLogNotice($param = []) { $template_id = config('wechat.sub_tpls.day_visit_notice'); $page = "pages/users/visitor"; @@ -1580,22 +1595,23 @@ class WechatService return $this->subSend($param['openid'], $template_id, $page, $data); } - public function subSend($openid, $template_id, $page, $data=[]) + public function subSend($openid, $template_id, $page, $data = []) { try { - if (empty($openid)) return false; + if (empty($openid)) + return false; $all_data = [ - 'template_id'=>$template_id, - 'touser'=>$openid, - 'page'=>$page, - 'data'=>$data, + 'template_id' => $template_id, + 'touser' => $openid, + 'page' => $page, + 'data' => $data, ]; $app = $this->app(); $result = $app->subscribe_message->send($all_data); if ($result['errcode'] == 0) {//记录模板消息发送成功 $all_data['status'] = 1; $all_data['err_msg'] = null; - }else{ + } else { $all_data['status'] = 0; $all_data['err_msg'] = $result['errmsg']; } @@ -1611,7 +1627,7 @@ class WechatService public function addTemplateMsgLog($data) { - $where = $data['type'] == 'mp'?['openid'=>$data['touser']]:['official_openid'=>$data['touser']]; + $where = $data['type'] == 'mp' ? ['openid' => $data['touser']] : ['official_openid' => $data['touser']]; $user_id = Wechat::where($where)->value('user_id'); $log = new TemplateMsgLog; $log->user_id = $user_id; @@ -1628,16 +1644,17 @@ class WechatService /** * 获取关注公众号的用户列表 */ - public function getOfficialAccountsUserOpenId(){ - $result = $this->official_app->user->list(); - if(!empty($result) && !empty($result['data']['openid'])){ + public function getOfficialAccountsUserOpenId() + { + $result = $this->official_app->user->list(); + if (!empty($result) && !empty($result['data']['openid'])) { $redis = Redis::connection('big_data'); $old_user_openId_list = $redis->keys('officialAccountsUserOpenIdList:*'); - if(!empty($old_user_openId_list)){ + if (!empty($old_user_openId_list)) { $redis->del($old_user_openId_list); } - $user_openId_list_key = 'officialAccountsUserOpenIdList:'.date('Y-m-d H:i:s'); - $redis->set($user_openId_list_key,json_encode(['data'=>$result['data']['openid']])); + $user_openId_list_key = 'officialAccountsUserOpenIdList:' . date('Y-m-d H:i:s'); + $redis->set($user_openId_list_key, json_encode(['data' => $result['data']['openid']])); return $result['data']['openid']; } } @@ -1660,16 +1677,17 @@ class WechatService * @param $receivers * @param $sub_merchant_id */ - public function wechatShare($transaction_id,$out_trade_no,$receivers,$sub_merchant_id){ + public function wechatShare($transaction_id, $out_trade_no, $receivers, $sub_merchant_id) + { $config = config('wechat.service_payment'); $config['cert_path'] = storage_path('wechat/service-cert.pem'); $config['key_path'] = storage_path('wechat/service-key.pem'); $payment = Factory::payment($config); $payment->setSubMerchant($sub_merchant_id); - $result = $payment->profit_sharing->share($transaction_id,$out_trade_no,$receivers); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + $result = $payment->profit_sharing->share($transaction_id, $out_trade_no, $receivers); + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { return false; } } @@ -1681,16 +1699,17 @@ class WechatService * @param $receivers * @param $sub_merchant_id */ - public function wechatMultiShare($transaction_id,$out_trade_no,$receivers,$sub_merchant_id){ + public function wechatMultiShare($transaction_id, $out_trade_no, $receivers, $sub_merchant_id) + { $config = config('wechat.service_payment'); $config['cert_path'] = storage_path('wechat/service_cert.pem'); $config['key_path'] = storage_path('wechat/service_key.pem'); $payment = Factory::payment($config); $payment->setSubMerchant($sub_merchant_id); - $result = $payment->profit_sharing->multiShare($transaction_id,$out_trade_no,$receivers); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + $result = $payment->profit_sharing->multiShare($transaction_id, $out_trade_no, $receivers); + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { return false; } } @@ -1704,14 +1723,15 @@ class WechatService * @throws EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException */ - public function addReceivers($receiver,$sub_merchant_id){ + public function addReceivers($receiver, $sub_merchant_id) + { $config = config('wechat.service_payment'); $payment = Factory::payment($config); $payment->setSubMerchant($sub_merchant_id); $result = $payment->profit_sharing->addReceiver($receiver); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { return false; } } @@ -1722,7 +1742,8 @@ class WechatService * @param $out_trade_no //商户分账单号,即商户订单号 * @param $sub_merchant_id */ - public function markOrderAsFinished($transaction_id,$out_trade_no,$sub_merchant_id){ + public function markOrderAsFinished($transaction_id, $out_trade_no, $sub_merchant_id) + { $config = config('wechat.service_payment'); $config['cert_path'] = storage_path('wechat/service-cert.pem'); $config['key_path'] = storage_path('wechat/service-key.pem'); @@ -1730,13 +1751,13 @@ class WechatService $payment->setSubMerchant($sub_merchant_id); $params = [ "transaction_id" => $transaction_id, - "out_order_no" => $out_trade_no, - "description" => "分账完成" + "out_order_no" => $out_trade_no, + "description" => "分账完成" ]; $result = $payment->profit_sharing->markOrderAsFinished($params); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { return false; } } @@ -1747,14 +1768,15 @@ class WechatService * @param $out_trade_no //商户分账单号,即商户订单号 * @param $sub_merchant_id */ - public function wechatShareQuery($transaction_id,$out_trade_no,$sub_merchant_id){ + public function wechatShareQuery($transaction_id, $out_trade_no, $sub_merchant_id) + { $config = config('wechat.service_payment'); $payment = Factory::payment($config); $payment->setSubMerchant($sub_merchant_id); - $result = $payment->profit_sharing->query($transaction_id,$out_trade_no); - if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ + $result = $payment->profit_sharing->query($transaction_id, $out_trade_no); + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') { return true; - }else{ + } else { return false; } } @@ -1769,7 +1791,7 @@ class WechatService */ public function transferBatches($trade_no, $batch_name, $batch_remark, $total_amount, $transfer_list) { -// $transfer_list = [ + // $transfer_list = [ // [ // 'out_detail_no' => \App\Facades\CommonUtilsService::getTradeNO(), // 'transfer_amount' => 1, @@ -1781,17 +1803,19 @@ class WechatService try { $resp = $this->instance ->chain('v3/transfer/batches') - ->post(['json' => [ - 'appid' => config('wechat.official_account.new.app_id'), - 'out_trade_no' => $trade_no, - 'batch_name' => $batch_name, - 'batch_remark' => $batch_remark, - 'total_amount' => $total_amount, - 'total_num' => count($transfer_list), - 'transfer_detail_list' => $transfer_list, - 'transfer_scene_id' => '', - ]]); - }catch (\Exception $e) { + ->post([ + 'json' => [ + 'appid' => config('wechat.official_account.new.app_id'), + 'out_trade_no' => $trade_no, + 'batch_name' => $batch_name, + 'batch_remark' => $batch_remark, + 'total_amount' => $total_amount, + 'total_num' => count($transfer_list), + 'transfer_detail_list' => $transfer_list, + 'transfer_scene_id' => '', + ] + ]); + } catch (\Exception $e) { dd($e->getMessage()); } } @@ -1805,33 +1829,36 @@ class WechatService $accessToken = $app->access_token; $token = $accessToken->getToken(); $access_token = $token['access_token']; - $url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=".$access_token; -// dd($params); + $url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" . $access_token; + // dd($params); $client = new Client(); $response = $client->request('POST', $url, [ 'json' => $params ]); $res = json_decode($response->getBody(), true); - if (isset($res['errcode']) && $res['errcode'] == 0) return $res['url_link']; - throw new Exception("请求url link失败, ". $res['errmsg']); + if (isset($res['errcode']) && $res['errcode'] == 0) + return $res['url_link']; + throw new Exception("请求url link失败, " . $res['errmsg']); } /** * 申请服务商签约商户 */ - public function applymentSub($business_code, $contact_info, $subject_info,$business_info, $settlement_info, $bank_account_info, $addition_info) + public function applymentSub($business_code, $contact_info, $subject_info, $business_info, $settlement_info, $bank_account_info, $addition_info) { $instance = $this->paymentInstance(); $resp = $instance->chain('v3/applyment4sub/applyment/') - ->post(['json' => [ - 'business_code' => $business_code, - 'contact_info' => $contact_info, - 'subject_info' => $subject_info, - 'business_info' => $business_info, - 'settlement_info' => $settlement_info, - 'bank_account_info' => $bank_account_info, - 'addition_info' => $addition_info, - ]]); + ->post([ + 'json' => [ + 'business_code' => $business_code, + 'contact_info' => $contact_info, + 'subject_info' => $subject_info, + 'business_info' => $business_info, + 'settlement_info' => $settlement_info, + 'bank_account_info' => $bank_account_info, + 'addition_info' => $addition_info, + ] + ]); return json_decode($resp->getBody()); } @@ -1855,7 +1882,7 @@ class WechatService function getEncrypt($str) { //$str是待加密字符串 - $public_key_path = 'file://'.config('wechat.payment.cert_path'); //平台证书路径 + $public_key_path = 'file://' . config('wechat.payment.cert_path'); //平台证书路径 $public_key = file_get_contents($public_key_path); $encrypted = ''; if (openssl_public_encrypt($str, $encrypted, $public_key, OPENSSL_PKCS1_OAEP_PADDING)) { @@ -1874,9 +1901,9 @@ class WechatService $instance = $this->paymentInstance(); $resp = $instance->chain("v3/merchant/media/upload") ->post([ - "body" => $media->getStream(), - "headers" => [ - "content-type" => $media->getContentType(), + "body" => $media->getStream(), + "headers" => [ + "content-type" => $media->getContentType(), ] ]); return json_decode($resp->getBody()); @@ -1884,19 +1911,19 @@ class WechatService public function partnerPay($order_id, $sub_mchid, $total, $openid, $trade_no, $notify_url, $desc) { -// $openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw"; + // $openid = "oPC_2vneOWpQbicNZQAUCxuwZ4mw"; $attributes = [ - 'sp_appid' => config('wechat.service_payment.app_id'), - 'sp_mchid' => config('wechat.service_payment.mch_id'), - 'sub_mchid' => $sub_mchid, - 'description' => $desc, - 'out_trade_no' => $trade_no, - 'notify_url' => $notify_url, - 'amount' => [ - "total" => (int)number_format( $total * 100, 0,'',''), - 'currency' => 'CNY' + 'sp_appid' => config('wechat.service_payment.app_id'), + 'sp_mchid' => config('wechat.service_payment.mch_id'), + 'sub_mchid' => $sub_mchid, + 'description' => $desc, + 'out_trade_no' => $trade_no, + 'notify_url' => $notify_url, + 'amount' => [ + "total" => (int) number_format($total * 100, 0, '', ''), + 'currency' => 'CNY' ], - 'payer' => [ + 'payer' => [ 'sp_openid' => $openid, ] ]; @@ -1908,7 +1935,7 @@ class WechatService $config = $this->paySign($prepay_id); $config['prepay_id'] = $prepay_id; $attributes['order_id'] = $order_id; - return ['config'=>$config, 'attributes'=>$attributes]; + return ['config' => $config, 'attributes' => $attributes]; } public function partnerOrderPaid($trade_no, $sub_mchid) @@ -1927,19 +1954,74 @@ class WechatService */ public function paySign($prepay_id) { - $merchantPrivateKeyFilePath = 'file://'.config('wechat.service_payment.key_path'); + $merchantPrivateKeyFilePath = 'file://' . config('wechat.service_payment.key_path'); $merchantPrivateKeyInstance = Rsa::from($merchantPrivateKeyFilePath); $params = [ - 'appId' => config('wechat.official_account.new.app_id'), - 'timestamp' => (string)Formatter::timestamp(), - 'nonceStr' => Formatter::nonce(), - 'package' => 'prepay_id='.$prepay_id, + 'appId' => config('wechat.official_account.new.app_id'), + 'timestamp' => (string) Formatter::timestamp(), + 'nonceStr' => Formatter::nonce(), + 'package' => 'prepay_id=' . $prepay_id, + ]; + $params += [ + 'paySign' => Rsa::sign( + Formatter::joinedByLineFeed(...array_values($params)), + $merchantPrivateKeyInstance + ), + 'signType' => 'RSA' ]; - $params += ['paySign' => Rsa::sign( - Formatter::joinedByLineFeed(...array_values($params)), - $merchantPrivateKeyInstance - ), 'signType' => 'RSA']; return $params; } + + public function officialUserTransferV3($withdraw) + { + try { + DB::beginTransaction(); + + Log::info("转账请求"); + $url = config("app.url") . "/util/api/wechatpay/admin/mch/transfer"; + $notify_url = config("app.url") . "/api/s/h5/communities/UserWithdrawal/callback"; + Log::info("转账请求链接:" . $url); + $data = [ + "trade_no" => $withdraw->trade_no, + "openid" => $withdraw->account, + "amount" => (int) ($withdraw->real_value * 100), + "remark" => "用户提现", + "notify_url" => $notify_url, + ]; + $token = TokenHelper::generate(auth()->id()); + $header = [ + 'Authorization' => "Bearer " . $token, + 'Content-Type' => 'application/json' + ]; + $options = [ + RequestOptions::TIMEOUT => 3, + RequestOptions::HTTP_ERRORS => false, + RequestOptions::HEADERS => $header, + RequestOptions::QUERY => $data, + ]; + $client = new Client(); + $response = $client->post($url, $options); + $content = $response->getBody(); + $res = json_decode($content, true); + if ($res && isset($res['code'])) { + if ($res['code']) { + throw new Exception($res['message']); + } + } else { + throw new Exception("提现失败"); + } + $package_info = $res["data"]["data"]["package_info"]; + $withdraw->package_info = $package_info; + $withdraw->status = "wait_user_confirm"; + $withdraw->save(); + DB::commit(); + return null; + } catch (Exception $e) { + DB::rollBack(); + $this->getError($e); + return ["msg" => $e->getMessage(), "err_code_des" => ""]; + } + + } }