From 61e8d24f3ed6e640c1a784ed97fecfe2267689d5 Mon Sep 17 00:00:00 2001 From: xuanchen <122383162@qq.com> Date: Tue, 29 Jun 2021 16:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.php | 10 ++-- src/Action/BaseAction.php | 16 +++++- src/Action/CouponAction.php | 99 +++++++++++++++++++++++++++---------- 3 files changed, 92 insertions(+), 33 deletions(-) diff --git a/config/config.php b/config/config.php index 1a846a1..7c7f1b2 100644 --- a/config/config.php +++ b/config/config.php @@ -17,8 +17,9 @@ return [ 'grant_type' => 'client_credentials', 'tokenUri' => 'https://open.cyzl.com/beta/auth/oauth/token', 'baseUri' => 'https://open.cyzl.com/beta/api', - 'urlKey' => env('WASH_CAR_URLKEY', ''),//免登陆跳转 - 'infoUrl' => env('WASH_CAR_INFOURL', ''),//优惠券详情地址 + 'indexUri' => 'https://v.cyzl.com/beta/activity/helongjiangWashCar/index.html?activityId={{activityId}}#/?accessToken={{accessToken}}', + 'infoUri' => 'https://v.cyzl.com/beta/xtz-v2/portal/index.html?activityId={{activityId}}#/heilongjiang-car-ticketInfo?ticketCode={{ticketCode}}&isShowHead=1&accessToken={{accessToken}}', + //优惠券详情地址 ], /** @@ -31,8 +32,9 @@ return [ 'grant_type' => 'client_credentials', 'tokenUri' => 'https://open.cyzl.com/api/auth/oauth/token', 'baseUri' => 'https://open.cyzl.com/api', - 'urlKey' => env('WASH_CAR_URLKEY', ''),//免登陆跳转 - 'infoUrl' => env('WASH_CAR_INFOURL', ''),//优惠券详情地址 + 'indexUri' => 'https://v.cyzl.com/activity/helongjiangWashCar/index.html?activityId={{activityId}}#/?accessToken={{accessToken}}', + 'infoUri' => 'https://v.cyzl.com/xtz-v2/portal/index.html?activityId={{activityId}}#/heilongjiang-car-ticketInfo?ticketCode={{ticketCode}}&isShowHead=1&accessToken={{accessToken}}', + //优惠券详情地址 ], ]; diff --git a/src/Action/BaseAction.php b/src/Action/BaseAction.php index b2d2291..6e77e21 100644 --- a/src/Action/BaseAction.php +++ b/src/Action/BaseAction.php @@ -5,9 +5,21 @@ namespace XuanChen\WashCar\Action; class BaseAction extends Init { - public function index() + /** + * Notes: 免登陆 + * @Author: 玄尘 + * @Date : 2021/6/29 10:49 + * @param string $method + * @return array + */ + public function getUnLoginUrl($method = 'POST') { - return 1; + $url = $this->config['baseUri'] . '/v2/h5/redirect/autoLogin/commonReturnUrl'; + + $params = $this->getParams(); + $this->http($url, $params, $method); + + return $this->getResponse(); } } diff --git a/src/Action/CouponAction.php b/src/Action/CouponAction.php index c23008f..b2700e6 100644 --- a/src/Action/CouponAction.php +++ b/src/Action/CouponAction.php @@ -2,6 +2,9 @@ namespace XuanChen\WashCar\Action; +use App\Models\Coupon; +use App\Models\CouponLog; + class CouponAction extends Init { @@ -12,17 +15,17 @@ class CouponAction extends Init */ public function getOrderUrl() { - $url = $this->config['baseUri'] . '/v2/h5/redirect/autoLogin/commonReturnUrl'; + $callback_url = $this->config['indexUri']; - $this->params = array_merge($this->params, [ - 'urlKey' => $this->config['urlKey'], - ]); + $callback_url = str_replace('{{activityId}}', $this->params['activityId'], $callback_url); + $callback_url .= '&' . $this->params['attr']; - $params = $this->getParams(); - - $this->http($url, $params); - - return $this->getResponse(); + return app('xuanchen.washcar')->base() + ->setParams([ + 'phone' => $this->params['phone'], + 'url' => $callback_url, + ]) + ->getUnLoginUrl(); } /** @@ -33,27 +36,18 @@ class CouponAction extends Init */ public function getCouponInfoUrl() { - $url = $this->config['baseUri'] . '/v2/h5/redirect/autoLogin/commonReturnUrl'; + $data = $this->params; - $accessToken = $this->getToken(); - $data = $this->params; + $callback_url = $this->config['infoUri']; + $callback_url = str_replace('{{ticketCode}}', $this->params['code'], $callback_url); - $callback_url = $this->config['infoUrl'] . '?' . http_build_query([ - 'activityId' => $data['activityId'], - 'code' => $data['code'], - 'accessToken' => $accessToken, - ]); + return app('xuanchen.washcar')->base() + ->setParams([ + 'phone' => $data['phone'], + 'url' => $callback_url, + ]) + ->getUnLoginUrl(); - $data = array_merge($data, ['url' => $callback_url]); - unset($data['code']); - unset($data['activityId']); - - $this->params = $data; - - $params = $this->getParams(); - $this->http($url, $params); - - return $this->getResponse(); } /** @@ -122,4 +116,55 @@ class CouponAction extends Init } + /** + * Notes: 回调地址 + * @Author: 玄尘 + * @Date : 2021/6/29 11:26 + */ + public function callback() + { + $couponCode = $this->params['couponCode']; + $verifyTime = $this->params['verifyTime']; + $this->url = $this->params['url']; + + //插入日志 + $this->addLog($this->params); + + $coupon = Coupon::where('code', $couponCode)->first(); + + if ($coupon) { + + if (in_array($coupon->status, [Coupon::STATUS_INIT, Coupon::STATUS_ERROR])) { + $coupon->status = Coupon::STATUS_USED; + $coupon->used_at = $verifyTime; + $coupon->source = $request->all(); + $coupon->save(); + + CouponLog::create([ + 'code' => $coupon->code, + 'from' => 'Washcar', + 'type' => 'callback', + 'remark' => '核销成功', + ]); + + //设置订单完成 + if ($coupon->order && $coupon->order->canComplete()) { + $coupon->order->complete(); + } + } + + $this->error = 0; + $this->message = '操作成功'; + + } else { + $this->error = 99; + $this->message = '优惠券码不存在'; + } + + $this->updateLog(['code' => $this->error, 'message' => $this->message]); + + return $this->getResponse(); + + } + }