From 5dda512af620da19c0f2defcc8ee2a0576e8c5b6 Mon Sep 17 00:00:00 2001 From: xuanchen120 <122383162@qq.com> Date: Mon, 28 Feb 2022 13:40:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E7=9F=B3=E6=B2=B9=E7=AE=80=E5=8D=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Controllers/PetroController.php | 58 ++++++++++ app/Admin/routes.php | 1 + app/Api/Controllers/PetroController.php | 129 ++++++++++++++++++++++ app/Api/routes.php | 4 + composer.json | 3 +- 5 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 app/Admin/Controllers/PetroController.php create mode 100644 app/Api/Controllers/PetroController.php diff --git a/app/Admin/Controllers/PetroController.php b/app/Admin/Controllers/PetroController.php new file mode 100644 index 0000000..8d5221e --- /dev/null +++ b/app/Admin/Controllers/PetroController.php @@ -0,0 +1,58 @@ +setParams([ +// 'matchDate' => Carbon::now()->format('Ymd'), +// 'pageNo' => 1, +// 'dzmaxResult' => 1000, +// 'random' => Str::random(6), +// ])->start(); +// dd($res); + +// dd('作废'); +// $res = Petro::Invalid()->setParams([ +// 'cxcouponNo' => '61578832475977235', +// 'random' => Str::random(6), +// ])->start(); +// dd($res); + +// dd('查询'); + $res = Petro::Detail()->setParams([ + 'couponNo' => '61578832475977235', + 'random' => Str::random(6), + ])->start(); +// + dd($res); +// $grant = [ +// 'requestCode' => 'Z591xRQ9fv1u', +// 'tradeId' => 111222, +// 'ticketSum' => 1, +// 'amount' => 10, +// 'random' => Str::random(6), +// ]; +// +// $res = Petro::Grant()->setParams($grant)->start(); +// dd($res); + + } catch (\Exception $exception) { + dd('error'.$exception->getMessage()); + } + + + } + +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 277804e..4acc227 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -14,6 +14,7 @@ Route::group([ $router->get('test', 'TestController@index')->name('test.index'); $router->get('test/coupon', 'TestController@coupon'); $router->get('test/check_coupon_log', 'TestController@checkCouponLog'); + $router->get('petro', 'PetroController@index'); $router->post('uploads/editor', 'UploadController@editor')->name('uploads.editor'); diff --git a/app/Api/Controllers/PetroController.php b/app/Api/Controllers/PetroController.php new file mode 100644 index 0000000..e533b41 --- /dev/null +++ b/app/Api/Controllers/PetroController.php @@ -0,0 +1,129 @@ +all(); + $res = $this->checkSign($request); + + //获取解密后数据 + $inputdata['jiemi'] = $res; + $this->log = $this->createLog($request->url(), 'POST', $inputdata, 'grant'); //添加日志 + + if (is_string($res)) { + return $this->error($res, $this->log); + } + + $validator = \Validator::make($res, [ + 'activityId' => 'required', + 'outletId' => 'required', + 'mobile' => 'required', + ], [ + 'activityId.required' => '缺少活动编码', + 'outletId.required' => '缺少网点id', + 'mobile.required' => '缺少手机号', + ]); + + if ($validator->fails()) { + return $this->error($validator->errors()->first(), $this->log); + } + + $grant = [ + 'requestCode' => $res['activityId'], + 'tradeId' => $res['tradeId'], + 'ticketSum' => 1, + 'amount' => $res['amount'], + 'random' => Str::random(6), + ]; + + $res = Petro::Grant()->setParams($grant)->start(); + return $this->success($res, $this->log); + } catch (\Exception $exception) { + return $this->error($exception->getMessage(), $this->log); + } + } + + public function query(Request $request) + { + try { + $inputdata = $request->all(); + $res = $this->checkSign($request); + + //获取解密后数据 + $inputdata['jiemi'] = $res; + $this->log = $this->createLog($request->url(), 'POST', $inputdata, 'query'); //添加日志 + + if (is_string($res)) { + return $this->error($res, $this->log); + } + + $validator = \Validator::make($res, [ + 'couponNo' => 'required', + ], [ + 'couponNo.required' => '缺少券码', + ]); + + if ($validator->fails()) { + return $this->error($validator->errors()->first(), $this->log); + } + + $res = Petro::Detail()->setParams([ + 'couponNo' => $res['couponNo'], + 'random' => Str::random(6), + ])->start(); + + return $this->success($res, $this->log); + } catch (\Exception $exception) { + return $this->error($exception->getMessage(), $this->log); + } + } + + public function destroy(Request $request) + { + try { + $inputdata = $request->all(); + $res = $this->checkSign($request); + + //获取解密后数据 + $inputdata['jiemi'] = $res; + $this->log = $this->createLog($request->url(), 'POST', $inputdata, 'query'); //添加日志 + + if (is_string($res)) { + return $this->error($res, $this->log); + } + + $validator = \Validator::make($res, [ + 'couponNo' => 'required', + ], [ + 'couponNo.required' => '缺少券码', + ]); + + if ($validator->fails()) { + return $this->error($validator->errors()->first(), $this->log); + } + + $res = Petro::Invalid()->setParams([ + 'cxcouponNo' => $res['couponNo'], + 'random' => Str::random(6), + ])->start(); + + return $this->success($res, $this->log); + } catch (\Exception $exception) { + return $this->error($exception->getMessage(), $this->log); + } + } + + +} diff --git a/app/Api/routes.php b/app/Api/routes.php index 6a30333..6b27305 100644 --- a/app/Api/routes.php +++ b/app/Api/routes.php @@ -20,4 +20,8 @@ Route::group(['prefix' => 'V1'], function () { Route::post('ticket/cancel', 'WoController@cancel'); //退业务 Route::post('ticket/query', 'WoController@query'); //退业务 + //中石油 + Route::post('petro/grant', 'PetroController@grant'); //发券 + Route::post('petro/query', 'PetroController@query'); //查询 + Route::post('petro/destroy', 'PetroController@destroy'); //作废 }); diff --git a/composer.json b/composer.json index 9cfbbbc..59eb19c 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "laravel/tinker": "^2.5", "maatwebsite/excel": "^3.1", "predis/predis": "^1.1", - "xuanchen/coupon": "^1.0", + "xuanchen/coupon": "^1.1", + "xuanchen/petro": "^0.0.1", "xuanchen/unionpay": "^3.0.0" }, "require-dev": {