diff --git a/app/Http/Controllers/Admin/BaseController.php b/app/Http/Controllers/Admin/BaseController.php index fea44f2..50e3103 100644 --- a/app/Http/Controllers/Admin/BaseController.php +++ b/app/Http/Controllers/Admin/BaseController.php @@ -102,7 +102,13 @@ class BaseController extends Controller public function errorJosn($msg){ return ['error'=>1,'msg'=>$msg]; } + protected function beforeStore($request){ + } + + protected function beforeSave($request,$id){ + + } /** * 全局检测表单是否错误,如果又返回错误数组,否则空数组 * @param $request @@ -309,6 +315,13 @@ class BaseController extends Controller */ protected function setModel(){ + } + + protected function afterStore($request){ + + } + protected function afterUpdate(){ + } protected function getShow($id){ $show=$this->setModel()->find($id); diff --git a/app/Http/Controllers/Admin/BaseDefaultController.php b/app/Http/Controllers/Admin/BaseDefaultController.php index 475360d..5703df5 100644 --- a/app/Http/Controllers/Admin/BaseDefaultController.php +++ b/app/Http/Controllers/Admin/BaseDefaultController.php @@ -17,7 +17,10 @@ class BaseDefaultController extends BaseController public function store(Request $request) { $permission = $this->setModel(); - return $this->saveData($request,$permission); + $this->beforeStore($request); + $saveData = $this->saveData($request, $permission); + $this->afterStore($request); + return $saveData; } public function show($id) @@ -34,8 +37,10 @@ class BaseDefaultController extends BaseController { $model = $this->setModel(); $model = $model->findOrFail($id); - return $this->saveData($request,$model,$id); - + $this->beforeSave($request,$id); + $saveData= $this->saveData($request,$model,$id); + $this->afterUpdate(); + return $saveData; } public function apiJson(Request $request) { diff --git a/app/Http/Controllers/Admin/MerchantController.php b/app/Http/Controllers/Admin/MerchantController.php index f8a32b8..fab8546 100644 --- a/app/Http/Controllers/Admin/MerchantController.php +++ b/app/Http/Controllers/Admin/MerchantController.php @@ -65,6 +65,7 @@ class MerchantController extends BaseDefaultController return [ 'name' => 'required', 'email' => 'required|unique:merchants|max:255', + 'total_price' => 'required', //'ratio' => 'required', @@ -73,7 +74,7 @@ class MerchantController extends BaseDefaultController return [ 'name' => 'required', 'email' => 'required', - + 'total_price' => 'required', //'ratio' => 'required', diff --git a/app/Http/Controllers/Admin/ZhanxinController.php b/app/Http/Controllers/Admin/ZhanxinController.php index 4a9bbb0..d6f9772 100644 --- a/app/Http/Controllers/Admin/ZhanxinController.php +++ b/app/Http/Controllers/Admin/ZhanxinController.php @@ -6,7 +6,9 @@ use App\Models\Gateway; use App\Models\UploadQrcode; use Illuminate\Http\Request; use App\Http\Controllers\Controller; - +use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\URL; +use Ixudra\Curl\Facades\Curl; class ZhanxinController extends BaseDefaultController { public function setPagesInfo() @@ -18,10 +20,35 @@ class ZhanxinController extends BaseDefaultController } public function postDataDb($request, $id = '') { - $data=$request->all(); + $data = $request->all(); + return $data; } + public function beforeStore($request) + { + $data = $request->all(); + $has_order = (new UploadQrcode())::where('uid', $data['uid'])->first(); + if ($has_order) { + return response()->json([ + 'error' => 1, + 'msg' => '用户id已存在' + ]); + } + } + + public function beforeSave($request,$id) + { + $data = $request->all(); + $has_order = (new UploadQrcode())::where('id', $id)->first(); + if ($has_order->uid != $data['uid']) { + return response()->json([ + 'error' => 1, + 'msg' => '用户id错误' + ]); + } + } + public function checkRule( $id='') { @@ -29,13 +56,15 @@ class ZhanxinController extends BaseDefaultController return [ 'username' => 'required', 'introduce' => 'required', - //'app_id'=> 'required', + 'uid'=> 'required', + 'money'=> 'required', ]; } return [ 'username' => 'required', 'introduce' => 'required', - //'app_id'=> 'required', + 'uid'=> 'required', + 'money'=> 'required', ]; } public function setErrorMsg(){ @@ -53,10 +82,51 @@ class ZhanxinController extends BaseDefaultController } public function saveAfter($request, $model, $id = '') { - // write_gateway();//写入配置文件 + // write_gateway();//写入配置文件 } + protected function afterStore($request){ + $chanxinconfig = config('qrcodeurl.zhanxin'); + $data = [ + 'userId' => intval($request->uid), 'name' => $request->username, + 'url' => $chanxinconfig['notify_url'] . $chanxinconfig['notify'], 'ts' => strval(time()) + ]; + $sinpa = [ + 'uid' => $request->uid, + 'ts' => $data['ts'] + ]; + $str = ''; + foreach ($sinpa as $k => $v) { + $str .= '&' . $k . '=' . $v; + } + $str = trim($str, '&'); + $data['key'] = strtolower(md5($str . '&' . $chanxinconfig['secret'])); + Log::channel('zhanxin')->info('请求数据', $data); + $res = $this->posturl($chanxinconfig['baseurl'] . $chanxinconfig['add'], $data); + $resArr = json_decode($res, true); + Log::channel('zhanxin')->info('返回数据', is_array($resArr) ? $resArr : []); + return $resArr; + } + + private function posturl($url, $data = []) + { + $data = (is_array($data)) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data; + + $headerArray = array("Content-type:application/json;charset='utf-8'", "Accept:application/json"); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + $output = curl_exec($curl); + curl_close($curl); + return $output; + } + //通道写入文件 function write_gateway() { @@ -74,7 +144,7 @@ class ZhanxinController extends BaseDefaultController public function setModel() { - $upload= new UploadQrcode(['upload_user'=>admin('id')]); + $upload = new UploadQrcode(['upload_user' => admin('id')]); return $upload; } diff --git a/app/Http/Controllers/Web/OrderController.php b/app/Http/Controllers/Web/OrderController.php index 1a35aaa..145c7ee 100644 --- a/app/Http/Controllers/Web/OrderController.php +++ b/app/Http/Controllers/Web/OrderController.php @@ -6,8 +6,10 @@ use App\Models\Good; use App\Models\Merchant; use App\Models\NotifyMoneys; use App\Models\Order; +use App\Models\UploadQrcode; use App\ServicePay\ApiOrderServices; use App\ServicePay\LocalOrderServices; +use App\ServicePay\ZhanXinPayServices; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use DB; @@ -165,6 +167,41 @@ class OrderController extends BaseController return $pay->order($request); } + //回调的时候 查询订单 + private function queryOrder($orderid,$uid){ + $chanxinconfig = config('qrcodeurl.zhanxin'); + $data=[ + 'uid'=>$uid, + 'ts'=>time(), + ]; + $data['key']=md5(http_build_query(array_merge($data,['key'=>$chanxinconfig['secret']]))); + + $curl=$this->curlGet($chanxinconfig['baseurl'].$chanxinconfig['query'].'?'.http_build_query($data)); + } + + private function curlGet($url){ + $curl = curl_init(); + $headerArray = array("Content-Type: application/json;", "Accept: application/json"); + curl_setopt_array($curl, array( + CURLOPT_URL =>$url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_HTTPHEADER => $headerArray, + )); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + $response = curl_exec($curl); + + curl_close($curl); + return $response; + } + + //接收回调展信回调 public function notify(Request $request){ $insert = []; if (!isset($request['title'])) { @@ -183,21 +220,66 @@ class OrderController extends BaseController return 'fail'; } $insert['to'] = $request['to']; + + if (!isset($request['ts'])) { + return 'fail'; + } + $insert['ts'] = $request['ts']; + if (!isset($request['orderid'])) { return 'fail'; } $insert['orderid'] = $request['orderid']; - if (!isset($request['time'])) { - $insert['receive_time'] = time(); - } else { - $insert['receive_time'] = $request['time']; - } - try { - $money = new NotifyMoneys(); - $money->insert($insert); - } catch (\Exception $e) { + if (!isset($request['ts'])) { return 'fail'; } + + $insert['receive_time'] = $request['ts']; + $chanxinconfig = config('qrcodeurl.zhanxin'); + $sinpa = [ + 'ts' => $insert['ts'], + 'key' => $chanxinconfig['secret'], + 'money' => $insert['money'], + 'from' => $insert['from'], + 'to' => $insert['to'], + 'orderid' => $insert['orderid'], + ]; + if (isset($request['serialnumber'])) { + $insert['serialnumber'] = $request['serialnumber']; + } + $str = ''; + foreach ($sinpa as $k => $v) { + $str .= '&' . $k . '=' . $v; + } + $str = trim($str, '&'); + $sign = strtolower(md5($str)); + if (!isset($request['key']) || $request['key'] != $sign) { + return 'fail8'; + } + try { + //检查有没有发过这个 + $money = new NotifyMoneys(); + $isset = $money->findByOrder($request['orderid']); + if ($isset) { + return 'isset'; + } + $insert['create_at'] = time(); + $qrcode = new UploadQrcode(); + $info = $qrcode->updateExpireTime($insert['to']); + if (empty($info)) { + return 'faili'; + } + $insert['out_trade_sn'] = $info->session_id; + + unset($insert['key'], $insert['ts']); + $res = $money->insert($insert); + $service = new ZhanXinPayServices(); + $service->afterPay($insert); + } catch (\Exception $e) { + Log::channel('zhanxin')->info('ineed 给我回调=>exception' . $e->getMessage(), []); + return 'faile'; + } + Log::channel('zhanxin')->info('ineed 给我回调=>success', []); return 'success'; } } diff --git a/app/Http/Controllers/Web/ZhanxinController.php b/app/Http/Controllers/Web/ZhanxinController.php index 2dd4292..e4bff55 100644 --- a/app/Http/Controllers/Web/ZhanxinController.php +++ b/app/Http/Controllers/Web/ZhanxinController.php @@ -47,108 +47,6 @@ class ZhanxinController extends BaseController } - /** - * 检查订单 - * @param Request $request - * @return mixed - */ - public function orderCheck(Request $request){ - $order_sn = $request->input('order_sn'); - $out_trade_sn = $request->input('out_trade_sn'); - $key = $request->input('app_id'); - $time=$request->input('time'); - if (empty($time) || $time < time() - 60) { - $data = [ - 'error' => 1, - 'msg' => '请求错误', - 'order' => [], - 'backurl' => '', - ]; - return response()->json($data); - } - Log::channel('pay_order')->info('merch查询订单', $request->input()); - - if ((!$order_sn && empty($out_trade_sn)) || empty($key)) { - $data = [ - 'error' => 1, - 'msg' => '订单不存在', - 'order'=>[], - 'backurl' => '', - ]; - }else{ -// $merchent=Merchant::where('app_key',$key)->first(["token"]); - $merchent = get_merchant($key);//取得商户 - if(empty($merchent)){ - $data = [ - 'error' => 2, - 'msg' => '商户不存在', - 'order'=>[], - 'backurl' => '', - ]; - return response()->json($data); - } - $params=$request->input(); - - ksort($params); - $secret=''; - $paramsign=$params['sign']??""; - unset($params['sign']); - foreach ($params as $k => $d) { - if (!empty($d)) { - $secret .= $k . '=' . $d . '&'; - } - } - $token=$merchent['token']; - $secret .= 'token=' . $token; - $sign = md5(strtolower(trim($secret, '&'))); - if($sign!=$paramsign){ - $data = [ - 'error' => 3, - 'msg' => '签名不正确', - 'order'=>[], - 'backurl' => '', - ]; - return response()->json($data); - } - //查询这个订单是否已经支付 - if (!empty($order_sn)) { - $order = Order::where('order_sn', $order_sn)->first(); - } else { - $order = Order::where('out_trade_sn', $out_trade_sn)->first(); - } - if (is_null($order['order_sn'])) { - $data = [ - 'error' => 1, - 'msg' => '订单不存在', - 'order'=>[], - 'backurl' => '', - ]; - return response()->json($data); - } - $orderData = [ - 'order_sn' => $order['order_sn'], - 'order_money' => $order['order_money'], - 'pay_status' => $order['pay_status'], - 'pay_money' => $order['pay_money'], - 'order_at' => $order['order_at'] - ]; - ksort($orderData); - $secret = ''; - foreach ($orderData as $k => $d) { - $secret .= $k . '=' . $d . '&'; - } - $secret .= 'token=' . $token; - $sign = md5(strtolower(trim($secret, '&'))); - $orderData['sign']=$sign; - $data = [ - 'error' => 0, - 'msg' => '', - 'order' =>$orderData - ]; - } - return response()->json($data); - } - public function localOrderPost($request) { // $pay = new LocalOrderServices(); diff --git a/app/Models/NotifyMoneys.php b/app/Models/NotifyMoneys.php index 4290335..2cab3ca 100644 --- a/app/Models/NotifyMoneys.php +++ b/app/Models/NotifyMoneys.php @@ -7,4 +7,7 @@ use Illuminate\Database\Eloquent\Model; class NotifyMoneys extends Model { // + public function findByOrder($orderid){ + return $this->where('orderid',$orderid)->first(); + } } diff --git a/app/Models/UploadQrcode.php b/app/Models/UploadQrcode.php index 5378cf5..1718985 100644 --- a/app/Models/UploadQrcode.php +++ b/app/Models/UploadQrcode.php @@ -23,17 +23,44 @@ class UploadQrcode extends BaseModel public function findOneQrcode($request){ $time = time(); $token = $request->input('_token'); - $old = $this::where([['session_id', '=', $token], ['expire_time', '>', intval($time)]])->orderBy('order_id', 'asc')->first(); + $old = $this::where([['session_id', '=', $token], ['expire_time', '>', intval($time)]])->orderBy('order_count', 'asc')->first(); if ($old) { return $old; } - $has_order = $this::where([['expire_time', '<', intval($time)]])->orderBy('order_id', 'asc')->first(); + $has_order = $this::where([['expire_time', '<', intval($time)]])->orderBy('order_count', 'asc')->first(); if ($has_order) { - $this::where('id', $has_order->id)->update(['session_id' => $token, 'expire_time' => $time + 1800, 'order_id' => $has_order->order_id + 1]); + $this::where('id', $has_order->id)->update(['session_id' => $token, 'expire_time' => $time + 1800, 'order_count' => $has_order->order_count + 1]); } else { return $this->msg(['error' => 1, 'msg' => '无可用二维码']); } return $has_order; } + //ineed支付使用 + public function findOneQrCodeByPay($orderData){ + $time = time(); + $old = $this::where([['session_id', '=', $orderData['out_trade_sn']], ['expire_time', '>', intval($time)], ['money', '=', $orderData['order_money']]]) + ->orderBy('order_count', 'asc')->first(); + if ($old) { + return $old; + } + $has_order = $this::where([['expire_time', '<', intval($time)], ['money', '=', $orderData['order_money']]])->orderBy('order_count', 'asc')->first(); + + if ($has_order) { + $this::where('id', $has_order->id)->update(['session_id' => $orderData['out_trade_sn'], 'expire_time' => $time + 1800, 'order_count' => $has_order->order_count + 1]); + } else { + return $this->msg(['error' => 1, 'msg' => '无可用二维码']); + } + $has_order = $this::where('id', $has_order->id)->first(); + return $has_order; + } + + //接收到ineed回调 + public function updateExpireTime($uid){ + $has_order = $this::where([['uid', '=', $uid], ['expire_time', '>', intval(time())]])->orderBy('order_count', 'asc')->first(); + if ($has_order) { + // $this::where('id', $has_order->id)->orderBy('order_count', 'asc')->update(['expire_time' => time()]); + } + return $has_order; + } } diff --git a/app/ServicePay/ApiOrderServices.php b/app/ServicePay/ApiOrderServices.php index 1920963..c2104a5 100644 --- a/app/ServicePay/ApiOrderServices.php +++ b/app/ServicePay/ApiOrderServices.php @@ -83,6 +83,7 @@ class ApiOrderServices } //取得商户信息 $this->merchant = get_merchant($request->input('app_id')); + //检查商户 $this->checkMerchant($request); //检查签名 @@ -100,6 +101,12 @@ class ApiOrderServices //设置附加订单数据 $this->setOrderInfo($request); + //展信支付 + if ($this->pay_type == 'zhanxinpay') { + $this->pay_service->payConfig($this->pay_type); + $this->pay_service->beforeCreateOrder(self::$orderData,$this->merchant); + } + if ($this->createOrder()) { $this->debugLog('选择通道是---' . $this->gateway['id'] . '方式是--' . $this->pay_method); diff --git a/app/ServicePay/PayApiProvidesTrait.php b/app/ServicePay/PayApiProvidesTrait.php index f0644e5..a2b6248 100644 --- a/app/ServicePay/PayApiProvidesTrait.php +++ b/app/ServicePay/PayApiProvidesTrait.php @@ -59,6 +59,8 @@ trait PayApiProvidesTrait return $this->pay_service = new ShanDianServices(); case 'rongyipay': return $this->pay_service = new RongYiServices(); + case 'zhanxinpay': + return $this->pay_service = new ZhanXinPayServices(); break; } } diff --git a/app/ServicePay/ZhanXinPayServices.php b/app/ServicePay/ZhanXinPayServices.php new file mode 100644 index 0000000..37db05f --- /dev/null +++ b/app/ServicePay/ZhanXinPayServices.php @@ -0,0 +1,309 @@ + 'http://pay.bypay1688.com/pay/Preorder/alipay', + 'debug' => 1,//调试 + 'logDir' => to_linux_path(storage_path() . '/logs/'), + 'mch_id' => $this->pay_gateway['app_id'], //客户交易者账号 + 'token' => $this->pay_gateway['app_key'], + 'interface' => $this->pay_gateway['mch_id'], + 'return_url' => action('Pay\PayController@returnNotify', ['type' => $type]), + 'notify_url' => action('Pay\PayController@notify', ['type' => $type]), + ]; + $this->pay_config = $config; + } + + //统一下单支付 + public function pay($pay_data) + { + //商户号 + $accountId = $this->pay_config['mch_id']; + //商户秘钥 +// $key = $this->pay_config['token']; +// $payData = [ +// 'cpid' => $accountId,//商户 +// 'orderid' => strval($pay_data['out_trade_no']),//订单号 +// 'describe' => $pay_data['subject'], +// 'product' => mt_rand(100000, 999999), //商品名称 +// 'amount' => intval($pay_data['total_amount']), //订单金额(元) +//// 'pay_bankcode' => $this->pay_gateway['mch_id'],//对应的三方通道 +// 'ip' => request()->getClientIp(), +// 'synurl' => strval($this->pay_config['notify_url']),// //异步回调地址 +// 'jumpurl' => strval($this->pay_config['return_url']),// //页面跳转通知 +// ]; + + $data = [ + 'url' => $this->qrcodeInfo->thumb, + 'order' => $this->qrcodeInfo->id, + 'username' => $this->qrcodeInfo->username, + 'pic_content' => $this->qrcodeInfo->pic_content, + 'type_name' => '展信支付' + ]; + return view('web.zhanxin.scan', $data); + } + + //统一验证签名 + public function verify(): bool + { + return true; + } + + + //返回给支付商的成功 + public function success() + { + echo 'SUCCESS'; + exit; + } + + //统一回调处理 + + /** + * 回调第一部,如果是同步,直接回传 + * @param $return + * @param $pay_type + * @param $request + * @deprecated + * @return bool|\Illuminate\Http\RedirectResponse + */ + public function notify($return, $pay_type, $request) + { + $this->setLogName($pay_type); + Log::channel('pay_order')->info('回调原始数据', $request->all()); + $this->pay_type = 'zhanxinpay'; + $this->request = $request; + + //取得订单,是否有此订单,如果没有直接返回空 + $order_sn = $request->input('orderId'); + //检查回调订单状态 + //判断有没支付成功先,没有的话,直接就没有下一步了 + $pay_status = $request->input('pay_msg'); + if ($pay_status != 'SUCCESS') { + $this->debugLog('订单支付失败', $this->request->all()); + return '订单支付失败'; + } + //取得订单 + $this->getOrder($order_sn); + + $return = ($return) ? 1 : 0; + if ($return) { + + //判断是否是商户id + if ($this->order->merchant_id == 0) { + return redirect()->route('web.user.index'); + } + // + return $this->merchantReturnSend(); + } + + /* $this->order = Order::where('order_sn', $order_sn)->first(); + if(empty($this->order)) + { + return false; + }*/ + //取得通道id + $this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id]; + //dd($this->gateway); + //取得支付配置 + $this->payConfig($this->pay_type); + + $this->result_data = $request->all(); + //检查三方的订单 + + //dump($this->result_data); + //进行验证签名 + if (!$this->verify()) { + $this->debugLog('签名验证失败'); + return '签名验证失败'; + } + + return $this->payNotify(); + } + + + /** + * 同步回调 + * @return \Illuminate\Http\RedirectResponse + */ + public function returnPay() + { + //判断是否是商户id + if ($this->order->merchant_id == 0) { + return redirect()->route('web.user.index'); + } + // + return $this->merchantReturnSend(); + } + + //异步回调 + + /** + * 获得通道信息,取得支付配置模型,验证签名, + * @return bool|void + */ + private function payNotify() + { + //取得通道信息内容 + $data = $this->result_data; + //如果应答状态不是01/A6表示支付失败 + + $this->debugLog('-------------' . $this->order->order_sn . '--选择----' . $this->pay_type . '----' . $this->pay_method . '----开始回调处理-------------------------'); + + try { + $pay_cn_name = ''; + //统一格式化 + $this->unionHandle(['order_sn'=>$this->order->order_sn,'money'=>$data['money'],'orderId'=>$data['orderid']]); + //支付返回信息 + $this->pay_data = $data; + $this->debugLog('验证签名成功,数据', $data); + //更新订单 + $this->updateOrder(); + $this->debugLog('updateOrder Ok'); + + } catch (\Exception $exception) { + $this->debugLog('失败异常内容:' . $exception->getMessage()); + + $this->order->notify_status = 1;//支付回调成功 + $this->order->pay_status = 1;//支付状态 + $this->order->pay_ok_at = date('Y-m-d H:i:s'); + $this->order->save();//保存 + Log::channel('pay_success')->info($pay_cn_name . '支付成功,但处理订单失败', ['data' => json_encode($data)]); + } + } + + /** + * 统一格式化 + */ + public function unionHandle($data) + { + + $result = [ + 'order_sn' => $data['orderId'],//我方订单号 + 'pay_order_sn' => $data['orderId'],//三方的订单号 + 'pay_money' => $data['money'], + 'pay_type' => 'zhanxinpay', + 'account' => '' + ]; + + $this->setResult($result); + Log::channel('pay_success')->info('支付成功', [ + 'pay_type' => $result['pay_type'], 'pay_money' => $result['pay_money'], + 'account' => $result['account'], 'order_sn' => $result['order_sn'], + 'pay_order_sn' => $result['pay_order_sn']]); + + } + + + private function getOrder($order_sn) + { + $this->order = Order::where('out_trade_sn', $order_sn)->first(); + //订单不存在返回空 + if (empty($this->order)) { + $this->debugLog('订单不存在:' . $order_sn); + return false; + } + $this->pay_method = $this->order->gateway_method;//支付方法 + $this->gateway_id = $this->order->gateway_id;//通道ID + $this->merchant = Merchant::find($this->order->merchant_id); + } + + //ineed回调验证完后执行这个方法 + public function afterPay($notifyMoney){ + $pay_type='zhanxinpay'; + + $this->setLogName($pay_type); + Log::channel('zhanxin')->info('回调原始数据', $notifyMoney); + $this->pay_type = $pay_type; + + $this->result_data = $notifyMoney; + //取得订单,是否有此订单,如果没有直接返回空 + $order_sn = $notifyMoney['out_trade_sn']; + //检查回调订单状态 + //判断有没支付成功先,没有的话,直接就没有下一步了 + + +// dd($this->order); +// var_dump($this->order);exit; + Log::channel('zhanxin')->info('订单数据', $this->order->toArray()); + //取得订单 + $this->getOrder($order_sn); + if ($notifyMoney['money'] != $this->order->order_money) { + Log::channel('zhanxin')->info('支付金额不一致', []); + return '支付金额不一致'; + } + //取得通道id + $this->gateway = $this->pay_gateway = config('gateway.config')[$this->gateway_id]; + //dd($this->gateway); + //取得支付配置 + $this->payConfig($this->pay_type); + + //dump($this->result_data); + //进行验证签名 + if (!$this->verify()) { + $this->debugLog('签名验证失败'); + return '签名验证失败'; + } + + return $this->payNotify(); + } + + //这个在pay 之前执行 + public function beforeCreateOrder($orderData){ + $merchant = \App\Models\Merchant::where('id', $orderData['merchant_id'])->first(); + if ($merchant && isset($merchant['total_price']) && !is_null($merchant['total_price'])) { + $walts = \App\Models\MerchantWallet::where('merchant_id', $orderData['merchant_id'])->first(); + if ($walts->trans_money + $orderData['order_money'] > $merchant['total_price']) { + return $this->msg(['error' => 1, 'msg' => '额度不足']); + } + } + $qrcode = new UploadQrcode(); + $picinfo = $qrcode->findOneQrCodeByPay($orderData);//查询一个可用的二维码 + $this->qrcodeInfo = $picinfo; + } + + + /** + * 这个调试需要配置在config/logging.php + * @param $pay_type + */ + public function setLogName($pay_type) + { + $name = 'zhanxinpay_'; + $this->log_name = $name; + } +} \ No newline at end of file diff --git a/config/adconfig.php b/config/adconfig.php index 9a7f769..90ccd50 100644 --- a/config/adconfig.php +++ b/config/adconfig.php @@ -57,6 +57,7 @@ return [ 'dalepay' =>'大乐支付', 'shandianpay' =>'闪电支付', 'rongyipay' =>'融易支付', + 'zhanxinpay' =>'展信支付', ], 'payfor_status' => [ 0 => '等待处理', diff --git a/config/logging.php b/config/logging.php index 93fd1d5..dee0f2c 100644 --- a/config/logging.php +++ b/config/logging.php @@ -184,6 +184,12 @@ return [ 'level' => 'info', 'days' => 1, ], + 'zhanxin' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/zhanxin.log'), + 'level' => 'info', + 'days' => 90, + ], ], diff --git a/config/qrcodeurl.php b/config/qrcodeurl.php index 3503348..2d2b046 100644 --- a/config/qrcodeurl.php +++ b/config/qrcodeurl.php @@ -2,8 +2,12 @@ return [ 'zhanxin' => [ - 'baseurl'=>'', - 'del' => 'ssss/ddd', - 'add' => '/guest/add' + 'notify_url'=>'https://wujie.la',//本机域名 + 'notify'=>'/order/notify',//给本机回调的 + 'baseurl'=>'https://imx.88mk.com:9290',//ineed 地址 + 'del' => '/guest/del', + 'add' => '/guest/add', + 'query' => '/notify/query', + 'secret'=>'notifyqwe123+asdfffggb=' ] ]; \ No newline at end of file diff --git a/resources/views/admin/merchant/create.blade.php b/resources/views/admin/merchant/create.blade.php index 3aa1416..1772733 100644 --- a/resources/views/admin/merchant/create.blade.php +++ b/resources/views/admin/merchant/create.blade.php @@ -159,6 +159,15 @@
单位:元
+
+ +
+ +
+
单位:元
+
diff --git a/resources/views/admin/merchant/edit.blade.php b/resources/views/admin/merchant/edit.blade.php index eeb9413..dc725a6 100644 --- a/resources/views/admin/merchant/edit.blade.php +++ b/resources/views/admin/merchant/edit.blade.php @@ -121,6 +121,14 @@
单位:元
+
+ +
+ +
+
单位:元
+
diff --git a/resources/views/admin/zhanxin/create.blade.php b/resources/views/admin/zhanxin/create.blade.php index a5e5dcf..889cbab 100644 --- a/resources/views/admin/zhanxin/create.blade.php +++ b/resources/views/admin/zhanxin/create.blade.php @@ -39,12 +39,25 @@
+
+ +
+ +
+
+
+ +
+ +
+
+
diff --git a/resources/views/admin/zhanxin/edit.blade.php b/resources/views/admin/zhanxin/edit.blade.php index becd8dd..9f76f12 100644 --- a/resources/views/admin/zhanxin/edit.blade.php +++ b/resources/views/admin/zhanxin/edit.blade.php @@ -49,6 +49,18 @@ data-obj=".insert_upload_logo">图片空间
+
+ +
+ +
+
+
+ +
+ +
+
diff --git a/resources/views/admin/zhanxin/index.blade.php b/resources/views/admin/zhanxin/index.blade.php index f0f7bf6..0283dc6 100644 --- a/resources/views/admin/zhanxin/index.blade.php +++ b/resources/views/admin/zhanxin/index.blade.php @@ -44,6 +44,8 @@ , {field: 'id', width: 80, title: 'ID', sort: true} , {field: 'username', title: '收款人姓名',minWidth: 120} , {field: 'thumb', title: '图片',templet: '#imgTpl'} + , {field: 'uid', title: '收款人ID',minWidth: 100} + , {field: 'money', title: '收款金额',minWidth: 100} , {field: 'created_at', title: '创建时间',minWidth: 250} , {title: '操作', minWidth: 200, align: 'center', toolbar: '#table-useradmin-admin'} ]]; diff --git a/routes/web.php b/routes/web.php index ecfcf34..53ce967 100644 --- a/routes/web.php +++ b/routes/web.php @@ -52,7 +52,6 @@ Route::name('web.')->group(function ($route) { Route::group(['prefix' => 'zhanxin'], function ($route) { $route->get('/', 'ZhanxinController@index')->name('zhanxin.index'); $route->post('/order', 'ZhanxinController@orderPost')->name('zhanxin.orderPost'); - $route->post('/check', 'ZhanxinController@orderCheck')->name('zhanxin.orderCheck');//检查订单 });