Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b3a3601da | |||
| 61e8d24f3e | |||
| add71f3d4c | |||
| 711940ecce | |||
| 563db90d6b |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xuanchen/washcar",
|
||||
"description": "平安sdk",
|
||||
"description": "洗车券",
|
||||
"license": "MIT",
|
||||
"homepage": "http://git.yuzhankeji.cn/xuanchen/PingAnWashCar.git",
|
||||
"authors": [
|
||||
|
||||
@@ -17,7 +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', ''),//免登陆跳转
|
||||
'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=heilongjiang#/car-ticketInfo?ticketCode={{ticketCode}}&isShowHead=1&accessToken={{accessToken}}',
|
||||
],
|
||||
|
||||
/**
|
||||
@@ -30,7 +32,10 @@ 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', ''),//免登陆跳转
|
||||
//首页购买页
|
||||
'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=heilongjiang#/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');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace XuanChen\WashCar\Action;
|
||||
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponLog;
|
||||
|
||||
class CouponAction extends Init
|
||||
{
|
||||
|
||||
@@ -12,17 +15,39 @@ class CouponAction extends Init
|
||||
*/
|
||||
public function getOrderUrl()
|
||||
{
|
||||
$url = $this->config['baseUri'] . '/v2/h5/redirect/autoLogin/returnUrl';
|
||||
$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();
|
||||
return app('xuanchen.washcar')->base()
|
||||
->setParams([
|
||||
'phone' => $this->params['phone'],
|
||||
'url' => $callback_url,
|
||||
])
|
||||
->getUnLoginUrl();
|
||||
}
|
||||
|
||||
$this->http($url, $params);
|
||||
/**
|
||||
* 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();
|
||||
|
||||
return $this->getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,4 +116,73 @@ class CouponAction extends Init
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +71,8 @@ class Init
|
||||
} else {
|
||||
$this->getAjaxToken();
|
||||
}
|
||||
|
||||
return $this->access_token;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,11 +4,9 @@ namespace XuanChen\WashCar\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class WashcarLog extends \Illuminate\Database\Eloquent\Model
|
||||
class WashcarLog extends Model
|
||||
{
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $casts = [
|
||||
'in_source' => 'json',
|
||||
'out_source' => 'json',
|
||||
@@ -24,13 +22,4 @@ class WashcarLog extends \Illuminate\Database\Eloquent\Model
|
||||
self::STATUS_ERROR => '失败',
|
||||
];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user