Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1cac561b38 | |||
| 3b3a3601da | |||
| 61e8d24f3e | |||
| add71f3d4c | |||
| 711940ecce | |||
| 563db90d6b | |||
| 23caf3a0c1 | |||
| 32f6391d1f | |||
| 25ff64defe |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xuanchen/washcar",
|
"name": "xuanchen/washcar",
|
||||||
"description": "平安sdk",
|
"description": "洗车券",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "http://git.yuzhankeji.cn/xuanchen/PingAnWashCar.git",
|
"homepage": "http://git.yuzhankeji.cn/xuanchen/PingAnWashCar.git",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|||||||
@@ -6,8 +6,36 @@ return [
|
|||||||
* 平安洗车券
|
* 平安洗车券
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'appId' => 122121,
|
'this_type' => env('WASH_TYPE'),
|
||||||
'appSecret' => '122121',
|
/**
|
||||||
|
* 测试环境参数
|
||||||
|
*/
|
||||||
|
'test' => [
|
||||||
|
'client_id' => env('WASH_CAR_TEST_APPID', ''),//就是 appId
|
||||||
|
'client_secret' => env('WASH_CAR_TEST_SECRET', ''),// 就是 client_secret
|
||||||
'apiVersion' => 'v2',
|
'apiVersion' => 'v2',
|
||||||
|
'grant_type' => 'client_credentials',
|
||||||
|
'tokenUri' => 'https://open.cyzl.com/beta/auth/oauth/token',
|
||||||
|
'baseUri' => 'https://open.cyzl.com/beta/api',
|
||||||
|
'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}}&activityNo=default#/car-ticketInfo?ticketCode={{ticketCode}}&isShowHead=1&accessToken={{accessToken}}',
|
||||||
|
],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生产环境参数
|
||||||
|
*/
|
||||||
|
'dev' => [
|
||||||
|
'client_id' => env('WASH_CAR_DEV_APPID', ''),//就是 appId
|
||||||
|
'client_secret' => env('WASH_CAR_DEV_SECRET', ''),// 就是 client_secret
|
||||||
|
'apiVersion' => 'v2',
|
||||||
|
'grant_type' => 'client_credentials',
|
||||||
|
'tokenUri' => 'https://open.cyzl.com/api/auth/oauth/token',
|
||||||
|
'baseUri' => 'https://open.cyzl.com/api',
|
||||||
|
//首页购买页
|
||||||
|
'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}}&activityNo=default#/car-ticketInfo?ticketCode={{ticketCode}}&isShowHead=1&accessToken={{accessToken}}',
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateWashcarCouponsTable extends Migration
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('washcar_coupons', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->morphs('order');
|
||||||
|
$table->string('code');
|
||||||
|
$table->boolean('status')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('washcar_coupons');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateWashcarLogsTable extends Migration
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('washcar_logs', function (Blueprint $table) {
|
||||||
|
$table->bigIncrements('id');
|
||||||
|
$table->string('url')->comment('地址');
|
||||||
|
$table->text('in_source')->comment('入参');
|
||||||
|
$table->text('out_source')->comment('出参')->nullable();
|
||||||
|
$table->boolean('status')->default(1);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('washcar_logs');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,9 +5,21 @@ namespace XuanChen\WashCar\Action;
|
|||||||
class BaseAction extends Init
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
188
src/Action/CouponAction.php
Normal file
188
src/Action/CouponAction.php
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Action;
|
||||||
|
|
||||||
|
use App\Models\Coupon;
|
||||||
|
use App\Models\CouponLog;
|
||||||
|
|
||||||
|
class CouponAction extends Init
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 跳转到下单url
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:11
|
||||||
|
*/
|
||||||
|
public function getOrderUrl()
|
||||||
|
{
|
||||||
|
$callback_url = $this->config['indexUri'];
|
||||||
|
|
||||||
|
$callback_url = str_replace('{{activityId}}', $this->params['activityId'], $callback_url);
|
||||||
|
$callback_url .= '&' . $this->params['attr'];
|
||||||
|
|
||||||
|
return app('xuanchen.washcar')->base()
|
||||||
|
->setParams([
|
||||||
|
'phone' => $this->params['phone'],
|
||||||
|
'url' => $callback_url,
|
||||||
|
])
|
||||||
|
->getUnLoginUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 获取优惠券详情H5地址
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/25 14:16
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getCouponInfoUrl()
|
||||||
|
{
|
||||||
|
$data = $this->params;
|
||||||
|
|
||||||
|
$callback_url = $this->config['infoUri'];
|
||||||
|
$callback_url = str_replace('{{ticketCode}}', $this->params['code'], $callback_url);
|
||||||
|
|
||||||
|
return app('xuanchen.washcar')->base()
|
||||||
|
->setParams([
|
||||||
|
'phone' => $data['phone'],
|
||||||
|
'url' => $callback_url,
|
||||||
|
])
|
||||||
|
->getUnLoginUrl();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 发券
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:26
|
||||||
|
*/
|
||||||
|
public function grant()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/getCoupon';
|
||||||
|
|
||||||
|
$params = $this->getParams();
|
||||||
|
$this->http($url, $params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 查询优惠券状态
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:28
|
||||||
|
*/
|
||||||
|
public function query()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/getCouponStatus';
|
||||||
|
|
||||||
|
$params = $this->getParams();
|
||||||
|
|
||||||
|
$this->http($url, $params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 查询优惠券信息
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/9 15:22
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function info()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/getCouponInfo';
|
||||||
|
|
||||||
|
$params = $this->getParams();
|
||||||
|
|
||||||
|
$this->http($url, $params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 取消优惠券
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:29
|
||||||
|
*/
|
||||||
|
public function cancel()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/rights/coupon/recedeCoupon';
|
||||||
|
|
||||||
|
$params = $this->getParams();
|
||||||
|
|
||||||
|
$this->http($url, $params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 回调地址
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/29 11:26
|
||||||
|
*/
|
||||||
|
public function callback()
|
||||||
|
{
|
||||||
|
$validator = \Validator::make($this->params, [
|
||||||
|
'couponCode' => 'required',
|
||||||
|
'verifyTime' => 'required',
|
||||||
|
'url' => 'required',
|
||||||
|
], [
|
||||||
|
'couponCode.required' => '缺少参数:couponCode',
|
||||||
|
'verifyTime.required' => '缺少参数:verifyTime',
|
||||||
|
'url.required' => '缺少参数:url',
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()) {
|
||||||
|
$this->error = 999;
|
||||||
|
$this->message = $validator->errors()->first();
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//插入日志
|
||||||
|
$this->addLog($this->params);
|
||||||
|
|
||||||
|
$couponCode = $this->params['couponCode'];
|
||||||
|
$verifyTime = $this->params['verifyTime'];
|
||||||
|
$this->url = $this->params['url'];
|
||||||
|
|
||||||
|
$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 = $this->params;
|
||||||
|
$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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,26 +4,118 @@ namespace XuanChen\WashCar\Action;
|
|||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use XuanChen\WashCar\Models\WashcarLog;
|
||||||
|
|
||||||
class Init
|
class Init
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $appId;
|
/**
|
||||||
|
* @var 入参
|
||||||
protected $appSecret;
|
*/
|
||||||
|
|
||||||
protected $apiVersion = 'v2';
|
|
||||||
|
|
||||||
protected $params;
|
protected $params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var 待校验的签名
|
||||||
|
*/
|
||||||
protected $sign;
|
protected $sign;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var 环境
|
||||||
|
*/
|
||||||
|
protected $this_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var token
|
||||||
|
*/
|
||||||
|
protected $access_token;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @var 错误标识
|
||||||
|
*/
|
||||||
|
protected $error = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @var 错误原因
|
||||||
|
*/
|
||||||
|
protected $message;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var 返回的数据
|
||||||
|
*/
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var 日志
|
||||||
|
*/
|
||||||
|
protected $log;
|
||||||
|
|
||||||
protected $url;
|
protected $url;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->appId = config('pingan.appId');
|
$this->this_type = config('washcar.this_type');
|
||||||
$this->appSecret = config('pingan.appSecret');
|
$this->config = config('washcar.' . $this->this_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取access_token
|
||||||
|
* @return void [type] [description]
|
||||||
|
*/
|
||||||
|
public function getToken()
|
||||||
|
{
|
||||||
|
//从缓存里找token
|
||||||
|
$access_token = Cache::get('token_' . $this->config['grant_type']);
|
||||||
|
if ($access_token) {
|
||||||
|
$this->access_token = $access_token;
|
||||||
|
} else {
|
||||||
|
$this->getAjaxToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->access_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求平台 access_token
|
||||||
|
* @return void [type] [description]
|
||||||
|
*/
|
||||||
|
public function getAjaxToken()
|
||||||
|
{
|
||||||
|
$params = [
|
||||||
|
'client_id' => $this->config['client_id'],
|
||||||
|
'grant_type' => $this->config['grant_type'],
|
||||||
|
'client_secret' => $this->config['client_secret'],
|
||||||
|
'scope' => 'all',
|
||||||
|
];
|
||||||
|
|
||||||
|
$tokenUrl = $this->config['tokenUri'] . '?' . http_build_query($params);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$client = new Client();
|
||||||
|
|
||||||
|
$response = $client->request('GET', $tokenUrl);
|
||||||
|
|
||||||
|
$body = $response->getBody();
|
||||||
|
$content = $body->getContents();
|
||||||
|
$result = json_decode($content, true);
|
||||||
|
|
||||||
|
if ($this->error > 0) {
|
||||||
|
return new \Exception($this->message);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->data = $result['data'];
|
||||||
|
|
||||||
|
Cache::put('token_' . $this->config['grant_type'], $this->data['access_token'], $this->data['expires_in']);
|
||||||
|
|
||||||
|
$this->access_token = $this->data['access_token'];
|
||||||
|
$this->error = 0;
|
||||||
|
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
$this->error = 9999;
|
||||||
|
$this->message = $e->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,8 +132,8 @@ class Init
|
|||||||
$this->sign = $data['sign'];
|
$this->sign = $data['sign'];
|
||||||
} else {
|
} else {
|
||||||
$data = array_merge($data, [
|
$data = array_merge($data, [
|
||||||
'appId' => $this->appId,
|
'appId' => $this->config['client_id'],
|
||||||
'apiVersion' => $this->apiVersion,
|
'apiVersion' => $this->config['apiVersion'],
|
||||||
'timestamp' => $this->getMillisecond(),
|
'timestamp' => $this->getMillisecond(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -92,20 +184,6 @@ class Init
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 封装跳转链接
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2021/6/1 15:25
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUrl()
|
|
||||||
{
|
|
||||||
$params = $this->params;
|
|
||||||
$params['sign'] = $this->getSign();
|
|
||||||
|
|
||||||
return $this->url . http_build_query($this->params);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notes: 获取时间戳
|
* Notes: 获取时间戳
|
||||||
* @Author: 玄尘
|
* @Author: 玄尘
|
||||||
@@ -134,13 +212,16 @@ class Init
|
|||||||
throw new \Exception('获取校验数据失败,缺少数据.');
|
throw new \Exception('获取校验数据失败,缺少数据.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($params['sign'])) {
|
|
||||||
unset($params['sign']);
|
|
||||||
}
|
|
||||||
|
|
||||||
ksort($params);
|
ksort($params);
|
||||||
|
|
||||||
return http_build_query($params) . $this->appSecret;
|
$str = '';
|
||||||
|
foreach ($params as $key => $param) {
|
||||||
|
if ($param != '' || $param != null || $key != 'sign') {
|
||||||
|
$str .= $key . $param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str . $this->config['client_secret'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,24 +234,104 @@ class Init
|
|||||||
*/
|
*/
|
||||||
public function http($url, $query, $method = 'POST')
|
public function http($url, $query, $method = 'POST')
|
||||||
{
|
{
|
||||||
|
$this->getToken();
|
||||||
|
|
||||||
|
if (!$this->access_token) {
|
||||||
|
$this->error = 9999;
|
||||||
|
$this->message = '缺少 access_token';
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->url = $url . '?access_token=' . $this->access_token;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
$this->addLog($query);
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
];
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
$response = $client->request($method, $url, $query);
|
|
||||||
|
$response = $client->request($method, $this->url, [
|
||||||
|
'json' => $query,
|
||||||
|
'headers' => $headers,
|
||||||
|
]);
|
||||||
|
|
||||||
$body = $response->getBody();
|
$body = $response->getBody();
|
||||||
$content = $body->getContents();
|
$content = $body->getContents();
|
||||||
$result = json_decode($content, true);
|
$result = json_decode($content, true);
|
||||||
|
|
||||||
if ($result['ret'] > 0) {
|
$this->updateLog($result);
|
||||||
$retData = $result['msg'];
|
|
||||||
|
if ($result['code'] > 0) {
|
||||||
|
$this->error = $result['code'];
|
||||||
|
$this->message = $result['message'];
|
||||||
|
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$retData = $result['data'];
|
$this->data = $result['data'];
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retData;
|
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
|
$this->error = 9999;
|
||||||
|
$this->message = $e->getMessage();
|
||||||
|
$this->updateLog($e->getMessage());
|
||||||
|
|
||||||
return ['ret' => '99999', $e->getMessage()];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 插入日志
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/9 16:36
|
||||||
|
*/
|
||||||
|
public function addLog($query)
|
||||||
|
{
|
||||||
|
$this->log = WashcarLog::create([
|
||||||
|
'url' => $this->url,
|
||||||
|
'in_source' => $query,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 更新log
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/9 16:40
|
||||||
|
* @param $data
|
||||||
|
*/
|
||||||
|
public function updateLog($data)
|
||||||
|
{
|
||||||
|
$this->log->out_source = $data;
|
||||||
|
$this->log->status = $this->error == 0 ? WashcarLog::STATUS_SUCCESS : WashcarLog::STATUS_ERROR;
|
||||||
|
$this->log->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 返回
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:48
|
||||||
|
*/
|
||||||
|
public function getResponse()
|
||||||
|
{
|
||||||
|
$rt = microtime(true) - LARAVEL_START;
|
||||||
|
|
||||||
|
$header = [
|
||||||
|
'rt' => round($rt * 1000, 2) . 'ms',
|
||||||
|
'qps' => round(1 / $rt, 1),
|
||||||
|
'endMemory' => round(memory_get_usage() / 1024 / 1024, 2),
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'error' => $this->error,
|
||||||
|
'message' => $this->message,
|
||||||
|
'data' => $this->data,
|
||||||
|
'header' => $header,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/Action/UrlAction.php
Normal file
38
src/Action/UrlAction.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Action;
|
||||||
|
|
||||||
|
class UrlAction extends Init
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 跳转到下单url
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:11
|
||||||
|
*/
|
||||||
|
public function getOrderUrl()
|
||||||
|
{
|
||||||
|
$url = $this->config['baseUri'] . '/v2/h5/redirect/autoLogin/returnUrl';
|
||||||
|
|
||||||
|
$this->params = array_merge($this->params, [
|
||||||
|
'urlKey' => $this->config['urlKey'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$params = $this->getParams();
|
||||||
|
|
||||||
|
$this->http($url, $params);
|
||||||
|
|
||||||
|
return $this->getResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Notes: 获取优惠券详情地址
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:11
|
||||||
|
*/
|
||||||
|
public function getCouponInfoUrl()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
src/Models/Model.php
Normal file
21
src/Models/Model.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class Model extends \Illuminate\Database\Eloquent\Model
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
protected function serializeDate(\DateTimeInterface $date)
|
||||||
|
{
|
||||||
|
if (version_compare(app()->version(), '7.0.0') < 0) {
|
||||||
|
return parent::serializeDate($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $date->format(Carbon::DEFAULT_TO_STRING_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
31
src/Models/WashcarCoupon.php
Normal file
31
src/Models/WashcarCoupon.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use XuanChen\WoUnicom\Action\Order;
|
||||||
|
|
||||||
|
class WashcarCoupon extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'in_source' => 'json',
|
||||||
|
'out_source' => 'json',
|
||||||
|
];
|
||||||
|
|
||||||
|
const STATUS_INIT = 1;
|
||||||
|
const STATUS_SUCCESS = 2;
|
||||||
|
const STATUS_ERROR = 3;
|
||||||
|
|
||||||
|
const STATUS = [
|
||||||
|
self::STATUS_INIT => '初始',
|
||||||
|
self::STATUS_SUCCESS => '成功',
|
||||||
|
self::STATUS_ERROR => '失败',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function order()
|
||||||
|
{
|
||||||
|
return $this->morphTo();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
25
src/Models/WashcarLog.php
Normal file
25
src/Models/WashcarLog.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class WashcarLog extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'in_source' => 'json',
|
||||||
|
'out_source' => 'json',
|
||||||
|
];
|
||||||
|
|
||||||
|
const STATUS_INIT = 1;
|
||||||
|
const STATUS_SUCCESS = 2;
|
||||||
|
const STATUS_ERROR = 3;
|
||||||
|
|
||||||
|
const STATUS = [
|
||||||
|
self::STATUS_INIT => '初始',
|
||||||
|
self::STATUS_SUCCESS => '成功',
|
||||||
|
self::STATUS_ERROR => '失败',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\WashCar;
|
|
||||||
|
|
||||||
use XuanChen\WashCar\Action\BaseAction;
|
|
||||||
|
|
||||||
class PingAn
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 基础
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2021/6/1 15:44
|
|
||||||
*/
|
|
||||||
public function base()
|
|
||||||
{
|
|
||||||
return new BaseAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -14,11 +14,13 @@ class ServiceProvider extends LaravelServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->publishes([__DIR__ . '/../config/config.php' => config_path('pingan.php')]);
|
$this->publishes([__DIR__ . '/../config/config.php' => config_path('washcar.php')]);
|
||||||
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations/');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->app->bind('xuanchen.pingan_washcar', function ($app) {
|
$this->app->bind('xuanchen.washcar', function ($app) {
|
||||||
return new PingAn();
|
return new WashCar();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +30,7 @@ class ServiceProvider extends LaravelServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'pingan');
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'washcar');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/WashCar.php
Normal file
43
src/WashCar.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace XuanChen\WashCar;
|
||||||
|
|
||||||
|
use XuanChen\WashCar\Action\BaseAction;
|
||||||
|
use XuanChen\WashCar\Action\CouponAction;
|
||||||
|
use XuanChen\WashCar\Action\UrlAction;
|
||||||
|
|
||||||
|
class WashCar
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 基础
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/1 15:44
|
||||||
|
*/
|
||||||
|
public function base()
|
||||||
|
{
|
||||||
|
return new BaseAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 获取url
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 11:34
|
||||||
|
* @return \XuanChen\WashCar\Action\UrlAction
|
||||||
|
*/
|
||||||
|
public function url()
|
||||||
|
{
|
||||||
|
return new UrlAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notes: 优惠券
|
||||||
|
* @Author: 玄尘
|
||||||
|
* @Date : 2021/6/4 14:25
|
||||||
|
*/
|
||||||
|
public function coupon()
|
||||||
|
{
|
||||||
|
return new CouponAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user