完善石化包
This commit is contained in:
@@ -46,7 +46,8 @@
|
|||||||
"RuLong\\Bonus\\": "packages/bonus/src/",
|
"RuLong\\Bonus\\": "packages/bonus/src/",
|
||||||
"RuLong\\Identity\\": "packages/identity/src/",
|
"RuLong\\Identity\\": "packages/identity/src/",
|
||||||
"XuanChen\\Coupon\\": "packages/coupon/src/",
|
"XuanChen\\Coupon\\": "packages/coupon/src/",
|
||||||
"XuanChen\\UnionPay\\": "packages/unionpay/src/"
|
"XuanChen\\UnionPay\\": "packages/unionpay/src/",
|
||||||
|
"XuanChen\\Sinopec\\": "packages/sinopec/src/"
|
||||||
},
|
},
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"database/seeds",
|
"database/seeds",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xuanchen/coupon",
|
"name": "xuanchen/sinopec",
|
||||||
"description": "卡券相关",
|
"description": "中石化相关",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@@ -14,13 +14,13 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"XuanChen\\Coupon": "src/"
|
"XuanChen\\Sinopec": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"laravel": {
|
"laravel": {
|
||||||
"providers": [
|
"providers": [
|
||||||
"XuanChen\\Coupon\\ServiceProvider"
|
"XuanChen\\Sinopec\\ServiceProvider"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action;
|
|
||||||
|
|
||||||
use XuanChen\Coupon\Action\pingan\Query;
|
|
||||||
use XuanChen\Coupon\Action\pingan\Verification;
|
|
||||||
use XuanChen\Coupon\Contracts\CouponContracts;
|
|
||||||
|
|
||||||
class PinganAction extends Init implements CouponContracts
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 核销执行入口
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/6/29 14:49
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
return (new Verification)->setCode($this->redemptionCode)
|
|
||||||
->setUser($this->user)
|
|
||||||
->setOutletId($this->outletId)
|
|
||||||
->setTotal($this->total)
|
|
||||||
->setOrderId($this->orderid)
|
|
||||||
->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 查询卡券详情
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/6/29 15:15
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function detail()
|
|
||||||
{
|
|
||||||
$info = (new Query)->setOutletId($this->outletId)
|
|
||||||
->setCode($this->redemptionCode)
|
|
||||||
->start();
|
|
||||||
|
|
||||||
return $info;
|
|
||||||
}
|
|
||||||
|
|
||||||
//发券
|
|
||||||
function grant()
|
|
||||||
{
|
|
||||||
return '没这个接口';
|
|
||||||
}
|
|
||||||
|
|
||||||
//作废
|
|
||||||
function destroy()
|
|
||||||
{
|
|
||||||
return '没这个接口';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action;
|
|
||||||
|
|
||||||
use XuanChen\Coupon\Action\ysd\YsdDestroy;
|
|
||||||
use XuanChen\Coupon\Action\ysd\YsdGrant;
|
|
||||||
use XuanChen\Coupon\Action\ysd\YsdQuery;
|
|
||||||
use XuanChen\Coupon\Action\ysd\YsdVerification;
|
|
||||||
use XuanChen\Coupon\Contracts\CouponContracts;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class YsdAction 自有卡券核销
|
|
||||||
* @Author : 玄尘
|
|
||||||
* @Date : 2020/7/21 9:41
|
|
||||||
* @package XuanChen\Coupon\Action
|
|
||||||
*/
|
|
||||||
class YsdAction extends Init implements CouponContracts
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 发券
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/7/21 10:08
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function grant()
|
|
||||||
{
|
|
||||||
return (new YsdGrant)->setActivityId($this->activityId)
|
|
||||||
->setOutletId($this->outletId)
|
|
||||||
->setMobile($this->mobile)
|
|
||||||
->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 查询卡券详情
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/6/29 15:15
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function detail()
|
|
||||||
{
|
|
||||||
$query_coupon = (new YsdQuery)->setOutletId($this->outletId)
|
|
||||||
->setCode($this->redemptionCode)
|
|
||||||
->start();
|
|
||||||
|
|
||||||
if (!is_string($query_coupon)) {
|
|
||||||
return [
|
|
||||||
'name' => $query_coupon->activity->title,
|
|
||||||
'code' => $query_coupon->code,
|
|
||||||
'full' => $query_coupon->full,
|
|
||||||
'price' => $query_coupon->price,
|
|
||||||
'status' => $query_coupon->status,
|
|
||||||
'used_at' => (string)$query_coupon->used_at,
|
|
||||||
'startTime' => (string)$query_coupon->start_at,
|
|
||||||
'endTime' => (string)$query_coupon->end_at,
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query_coupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 作废
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/7/21 11:32
|
|
||||||
*/
|
|
||||||
public function destroy()
|
|
||||||
{
|
|
||||||
return $res = (new YsdDestroy)->setCode($this->redemptionCode)
|
|
||||||
->setOutletId($this->outletId)
|
|
||||||
->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 核销执行入口
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/6/29 14:49
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
return $res = (new YsdVerification)->setCode($this->redemptionCode)
|
|
||||||
->setUser($this->user)
|
|
||||||
->setOutletId($this->outletId)
|
|
||||||
->setTotal($this->total)
|
|
||||||
->setOrderId($this->orderid)
|
|
||||||
->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\pingan;
|
|
||||||
|
|
||||||
use App\Models\PinganToken;
|
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use GuzzleHttp\Exception\RequestException;
|
|
||||||
use XuanChen\Coupon\Action\Init;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 超市购物券
|
|
||||||
*/
|
|
||||||
class PingAnInit extends Init
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $this_type;
|
|
||||||
|
|
||||||
protected $baseUri;
|
|
||||||
|
|
||||||
protected $tokenUri;
|
|
||||||
|
|
||||||
protected $client_id;
|
|
||||||
|
|
||||||
protected $grant_type;
|
|
||||||
|
|
||||||
protected $client_secret;
|
|
||||||
|
|
||||||
protected $access_token;
|
|
||||||
|
|
||||||
protected $userName;
|
|
||||||
|
|
||||||
protected $error;
|
|
||||||
|
|
||||||
protected $aes_code; //aes 密钥
|
|
||||||
|
|
||||||
protected $log;//日志
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->this_type = config('pingan.this_type');
|
|
||||||
$pingan = config('pingan.' . $this->this_type);
|
|
||||||
|
|
||||||
$this->baseUri = $pingan['Uri'];
|
|
||||||
$this->tokenUri = $pingan['tokenUri'];
|
|
||||||
$this->client_id = $pingan['client_id'];
|
|
||||||
$this->grant_type = $pingan['grant_type'];
|
|
||||||
$this->userName = $pingan['userName'];
|
|
||||||
$this->client_secret = $pingan['client_secret'];
|
|
||||||
$this->aes_code = $pingan['AES_CODE'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取access_token
|
|
||||||
* @return void [type] [description]
|
|
||||||
*/
|
|
||||||
public function getToken()
|
|
||||||
{
|
|
||||||
//从数据库里找token
|
|
||||||
$token = PinganToken::where('type', $this->this_type)->orderBy('id', 'desc')->first();
|
|
||||||
|
|
||||||
if ($token) {
|
|
||||||
$access_token = $token->access_token;
|
|
||||||
$expires_in = $token->expires_in;
|
|
||||||
$get_token_time = $token->get_token_time;
|
|
||||||
$diffMinutes = $get_token_time->diffInMinutes(now(), false);
|
|
||||||
if ($diffMinutes < $expires_in) {
|
|
||||||
$this->access_token = $access_token;
|
|
||||||
} else {
|
|
||||||
$this->getAjaxToken();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$this->getAjaxToken();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取毫秒级别的时间戳
|
|
||||||
*/
|
|
||||||
public function getMsecTime()
|
|
||||||
{
|
|
||||||
[$msec, $sec] = explode(' ', microtime());
|
|
||||||
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
|
|
||||||
$msectime = explode('.', $msectime);
|
|
||||||
|
|
||||||
return $msectime[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求平台 access_token
|
|
||||||
* @return void [type] [description]
|
|
||||||
*/
|
|
||||||
public function getAjaxToken()
|
|
||||||
{
|
|
||||||
$params = [
|
|
||||||
'client_id' => $this->client_id,
|
|
||||||
'grant_type' => $this->grant_type,
|
|
||||||
'client_secret' => $this->client_secret,
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
|
||||||
$log = $this->createLog($this->tokenUri, 'POST', $params, 'pingan');
|
|
||||||
|
|
||||||
$client = new Client();
|
|
||||||
$response = $client->request('POST', $this->tokenUri, [
|
|
||||||
'form_params' => $params,
|
|
||||||
]);
|
|
||||||
$body = $response->getBody();
|
|
||||||
$content = $body->getContents();
|
|
||||||
$result = json_decode($content, true);
|
|
||||||
|
|
||||||
$this->updateLog($log, $result); //更新日志
|
|
||||||
|
|
||||||
if ($result['ret'] > 0) {
|
|
||||||
$this->error = $result['msg'];
|
|
||||||
} else {
|
|
||||||
$data = $result['data'];
|
|
||||||
PinganToken::create([
|
|
||||||
'type' => $this->this_type,
|
|
||||||
'access_token' => $data['access_token'],
|
|
||||||
'expires_in' => $data['expires_in'],
|
|
||||||
'get_token_time' => now(),
|
|
||||||
]);
|
|
||||||
$this->access_token = $data['access_token'];
|
|
||||||
$this->error = '';
|
|
||||||
}
|
|
||||||
} catch (RequestException $e) {
|
|
||||||
$this->error = $e->getMessage();
|
|
||||||
$this->updateLog($log, [$this->error]); //更新日志
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用获取数据接口
|
|
||||||
* @param [type] $url 请求地址
|
|
||||||
* @param array $query 传递参数
|
|
||||||
* @param array $json 需要传的json数据
|
|
||||||
* @param string $method 方式
|
|
||||||
* @return array|mixed [type] [description]
|
|
||||||
*/
|
|
||||||
public function getPingAnData($url, $query = [], $json = [], $method = 'POST')
|
|
||||||
{
|
|
||||||
$this->getToken();
|
|
||||||
|
|
||||||
if ($this->error) {
|
|
||||||
return $this->error;
|
|
||||||
}
|
|
||||||
|
|
||||||
$postData = [
|
|
||||||
'query' => array_merge([
|
|
||||||
'access_token' => $this->access_token,
|
|
||||||
'request_id' => $this->getMsecTime(),
|
|
||||||
'userName' => $this->userName,
|
|
||||||
], $query),
|
|
||||||
'json' => $json,
|
|
||||||
'headers' => [
|
|
||||||
'Content-Type' => 'application/json;charset=utf-8',
|
|
||||||
'accept' => 'application/json;charset=utf-8',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$log = $this->createLog($url, $method, $postData, 'pingan'); //日志
|
|
||||||
|
|
||||||
try {
|
|
||||||
$client = new Client();
|
|
||||||
$response = $client->request($method, $url, $postData);
|
|
||||||
$body = $response->getBody();
|
|
||||||
$content = $body->getContents();
|
|
||||||
$result = json_decode($content, true);
|
|
||||||
|
|
||||||
if ($result['ret'] > 0) {
|
|
||||||
$retData = $result['msg'];
|
|
||||||
} else {
|
|
||||||
$retData = $result['data'];
|
|
||||||
}
|
|
||||||
$this->updateLog($log, $retData);//更新日志
|
|
||||||
|
|
||||||
return $retData;
|
|
||||||
} catch (RequestException $e) {
|
|
||||||
$this->updateLog($log, [$e->getMessage()]);//更新日志
|
|
||||||
|
|
||||||
return ['ret' => '99999', $e->getMessage()];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//加密
|
|
||||||
public function encrypt($str)
|
|
||||||
{
|
|
||||||
if (is_array($str)) {
|
|
||||||
$str = json_encode($str);
|
|
||||||
}
|
|
||||||
$data = openssl_encrypt($str, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
|
||||||
|
|
||||||
return base64_encode($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
//解密
|
|
||||||
public function decrypt($str)
|
|
||||||
{
|
|
||||||
$encrypted = base64_decode($str);
|
|
||||||
|
|
||||||
return openssl_decrypt($encrypted, 'aes-128-ecb', $this->aes_code, OPENSSL_RAW_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\pingan;
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
|
|
||||||
class Query extends PingAnInit
|
|
||||||
{
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
|
|
||||||
try {
|
|
||||||
//查询网点是否存在
|
|
||||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
|
||||||
|
|
||||||
if (!$outlet) {
|
|
||||||
throw new \Exception('网点编号错误,未查询到网点信息');
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = $this->baseUri . 'partner/v2/coupondetail';
|
|
||||||
$params = [
|
|
||||||
'redemptionCode' => $this->redemptionCode,
|
|
||||||
'outletNo' => $outlet->PaOutletId,
|
|
||||||
'thirdOutletNo' => $outlet->outlet_id,
|
|
||||||
];
|
|
||||||
|
|
||||||
$res = $this->getPingAnData($url, $params);
|
|
||||||
|
|
||||||
if (!is_array($res)) {
|
|
||||||
throw new \Exception($res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($res['code'] != 200) {
|
|
||||||
throw new \Exception($res['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return collect($res['data']);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,298 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\pingan;
|
|
||||||
|
|
||||||
use App\Models\Coupon;
|
|
||||||
use App\Models\User;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
class Verification extends PingAnInit
|
|
||||||
{
|
|
||||||
|
|
||||||
public $ticket;
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
//检查是否已经核销过
|
|
||||||
$res = $this->HasCheck();
|
|
||||||
if ($res !== false) {
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
//查询卡券信息
|
|
||||||
$this->query_coupon = (new Query)->setOutletId($this->outletId)
|
|
||||||
->setCode($this->redemptionCode)
|
|
||||||
->start();
|
|
||||||
if (is_string($this->query_coupon)) {
|
|
||||||
return $this->query_coupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
//校验卡券
|
|
||||||
$ticket = $this->checkCoupon();
|
|
||||||
if (!is_array($ticket)) {
|
|
||||||
return $ticket;
|
|
||||||
}
|
|
||||||
|
|
||||||
//检查可核销次数
|
|
||||||
$ret = $this->CheckCount();
|
|
||||||
if ($ret !== true) {
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
//增加核销记录
|
|
||||||
$coupon = $this->AddCoupon();
|
|
||||||
if (is_string($coupon)) {
|
|
||||||
return $coupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$params = [
|
|
||||||
'couponNo' => $coupon->redemptionCode,
|
|
||||||
'partnerOrderId' => date('ymdHis') . sprintf("%0" . strlen(999999) . "d", mt_rand(0, 999999)),
|
|
||||||
'outletId' => $coupon->PaOutletId,
|
|
||||||
'productId' => $coupon->productId,
|
|
||||||
'timestamp' => $this->getMsecTime(),
|
|
||||||
];
|
|
||||||
|
|
||||||
$url = $this->baseUri . 'partner/redemption';
|
|
||||||
$str = $this->encrypt($params);
|
|
||||||
$res = $this->getPingAnData($url, [], ['data' => $str]);
|
|
||||||
|
|
||||||
if (!is_array($res)) {
|
|
||||||
$coupon->remark = $res;
|
|
||||||
$coupon->status = 3;
|
|
||||||
$coupon->save();
|
|
||||||
throw new \Exception($res);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($res['code'] != 200) {
|
|
||||||
$coupon->remark = $res['code'] . '--' . $res['message'];
|
|
||||||
$coupon->status = 3;
|
|
||||||
$coupon->save();
|
|
||||||
throw new \Exception($res['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = $res['data'];
|
|
||||||
|
|
||||||
$coupon->remark = $data['message'];
|
|
||||||
$coupon->status = ($data['status'] == 1) ? 2 : 3;
|
|
||||||
$coupon->save();
|
|
||||||
|
|
||||||
//返回的数据
|
|
||||||
$resdata = [
|
|
||||||
'price' => $coupon->price,
|
|
||||||
'name' => $coupon->couponName,
|
|
||||||
'total' => $coupon->total,
|
|
||||||
];
|
|
||||||
|
|
||||||
//核销成功 执行分润
|
|
||||||
$coupon->profit();
|
|
||||||
|
|
||||||
return $resdata;
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$coupon->status = 3;
|
|
||||||
$coupon->remark = '核销失败 ' . $e->getMessage();
|
|
||||||
$coupon->save();
|
|
||||||
|
|
||||||
return $coupon->remark;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 如可核销记录
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/7/21 15:03
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function AddCoupon()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$couponData = [
|
|
||||||
'user_id' => $this->user->id,
|
|
||||||
'type' => Coupon::TYPE_PINGAN,
|
|
||||||
'outletId' => $this->outletId,
|
|
||||||
'orderid' => $this->orderid,
|
|
||||||
'PaOutletId' => $this->queryData['PaOutletId'],
|
|
||||||
'redemptionCode' => $this->redemptionCode,
|
|
||||||
'productId' => $this->queryData['productId'],
|
|
||||||
'thirdPartyGoodsId' => $this->queryData['thirdPartyGoodsId'],
|
|
||||||
'couponName' => $this->query_coupon['couponName'],
|
|
||||||
'price' => $this->ticket['price'],
|
|
||||||
'total' => $this->total,
|
|
||||||
'profit' => $this->ticket['profit'],
|
|
||||||
'status' => 0,
|
|
||||||
'startTime' => $this->query_coupon['startTime'],
|
|
||||||
'endTime' => $this->query_coupon['endTime'],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $coupon = Coupon::create($couponData);
|
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 检查卡券信息
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/6/29 16:40
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function checkCoupon()
|
|
||||||
{
|
|
||||||
|
|
||||||
//检查卡券是否已被核销
|
|
||||||
if ($this->query_coupon['status'] > 0) {
|
|
||||||
if (isset(config('pingan.coupon_status')[$this->query_coupon['status']])) {
|
|
||||||
return '核销失败,平安券' . config('pingan.coupon_status')[$this->query_coupon['status']];
|
|
||||||
}
|
|
||||||
|
|
||||||
return '核销失败,平安券不可用。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$startTime = Carbon::parse($this->query_coupon['startTime']);
|
|
||||||
$endTime = Carbon::parse($this->query_coupon['endTime']);
|
|
||||||
$now = now();
|
|
||||||
|
|
||||||
if ($startTime->gt($now)) {
|
|
||||||
return '核销失败,平安券未开始使用。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($now->gt($endTime)) {
|
|
||||||
return '核销失败,平安券已过期。';
|
|
||||||
}
|
|
||||||
|
|
||||||
//查找适配的商品id 和 网点id
|
|
||||||
$pinganData = $this->getPinganProduct();
|
|
||||||
|
|
||||||
if (is_string($pinganData)) {
|
|
||||||
return $pinganData;
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取相关优惠信息
|
|
||||||
return $this->checkCode();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验平安券编号
|
|
||||||
* @return array|string [type] [description]
|
|
||||||
*/
|
|
||||||
public function checkCode()
|
|
||||||
{
|
|
||||||
$code = $this->user->code->where('code', $this->queryData['thirdPartyGoodsId'])->first();
|
|
||||||
if (!$code) {
|
|
||||||
return "核销失败,未找到此项平安券规则,请联系管理人员检查渠道配置。";
|
|
||||||
}
|
|
||||||
|
|
||||||
$ticket = explode('-', $this->queryData['thirdPartyGoodsId']);
|
|
||||||
|
|
||||||
if (!is_array($ticket) || count($ticket) != 3) {
|
|
||||||
return "核销失败,平安券规则格式不正确。";
|
|
||||||
}
|
|
||||||
|
|
||||||
$full = $ticket[1]; //full100
|
|
||||||
$price = $ticket[2];
|
|
||||||
preg_match('/\d+/', $full, $result);
|
|
||||||
|
|
||||||
if (empty($result) || !is_array($result)) {
|
|
||||||
return "核销失败,平安券规则格式不正确。";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_numeric($this->total)) {
|
|
||||||
return "核销失败,订单金额必须是数字";
|
|
||||||
}
|
|
||||||
if ($result[0] > $this->total) {
|
|
||||||
return '核销失败,订单金额不足,平安券不可使用。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->ticket = [
|
|
||||||
'total' => $result[0],
|
|
||||||
'price' => $price,
|
|
||||||
'profit' => $code->profit,
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->ticket;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查找平安商品id
|
|
||||||
* @author 玄尘 2020-04-04
|
|
||||||
* @return array|string [type] [description]
|
|
||||||
*/
|
|
||||||
public function getPinganProduct()
|
|
||||||
{
|
|
||||||
//查询网点是否存在
|
|
||||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
|
||||||
|
|
||||||
if (!$outlet) {
|
|
||||||
return '核销失败,网点编号错误,未查询到网点信息';
|
|
||||||
}
|
|
||||||
|
|
||||||
$PaOutletId = $outlet->PaOutletId;
|
|
||||||
$outlet_id = $outlet->outlet_id;
|
|
||||||
$profitOfferItemVersion = $this->query_coupon['profitOfferItemVersion'];
|
|
||||||
|
|
||||||
if (!$PaOutletId && $profitOfferItemVersion != 1) {
|
|
||||||
return '核销失败,参数错误,渠道信息缺少平安网点id';
|
|
||||||
}
|
|
||||||
|
|
||||||
$productItemList = $this->query_coupon['productItemList'];
|
|
||||||
|
|
||||||
if (!is_array($productItemList) || !is_array($productItemList[0])) {
|
|
||||||
return '核销失败,平安券数据有误,可能是未配置网点。';
|
|
||||||
}
|
|
||||||
|
|
||||||
//循环查找
|
|
||||||
$first = '';
|
|
||||||
foreach ($productItemList as $key => $item) {
|
|
||||||
$productId = $item['productId'];
|
|
||||||
$thirdPartyGoodsId = $item['thirdPartyGoodsId'];
|
|
||||||
$outletList = $item['outletList'];
|
|
||||||
if (!is_array($outletList) || !is_array($outletList[0])) {
|
|
||||||
return '核销失败,网点信息有误!请检查平安券配置信息。';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$outletList = collect($outletList);
|
|
||||||
//判断是新版还是旧版
|
|
||||||
if ($profitOfferItemVersion) {
|
|
||||||
//新版通过第三方查询
|
|
||||||
$first = $outletList->firstWhere('thirdOutletNo', $outlet_id);
|
|
||||||
|
|
||||||
if ($first) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//旧版通过平安网点查询
|
|
||||||
$first = $outletList->firstWhere('outletNo', $PaOutletId);
|
|
||||||
if ($first) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$first) {
|
|
||||||
return '核销失败,未找到可用网点信息。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$thirdPartyGoodsId) {
|
|
||||||
return '核销失败,平安券编号规则有误。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$productId) {
|
|
||||||
return '核销失败,未查询到平安券商品id。';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->queryData = [
|
|
||||||
'thirdPartyGoodsId' => $thirdPartyGoodsId,
|
|
||||||
'productId' => $productId,
|
|
||||||
'PaOutletId' => $first['outletNo'],
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\sinopec;
|
namespace XuanChen\Sinopec\Action\sinopec;
|
||||||
|
|
||||||
use XuanChen\Coupon\Contracts\CheckCouponContracts;
|
use XuanChen\Sinopec\Contracts\CheckCouponContracts;
|
||||||
|
|
||||||
class ZhyCreate implements CheckCouponContracts
|
class ZhyCreate implements CheckCouponContracts
|
||||||
{
|
{
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
@@ -28,8 +29,8 @@ class ZhyCreate implements CheckCouponContracts
|
|||||||
"voucherRuleName" => "ceshi2",
|
"voucherRuleName" => "ceshi2",
|
||||||
"voucherSource" => "S01",
|
"voucherSource" => "S01",
|
||||||
"voucherStartTime" => "2019-12-13",
|
"voucherStartTime" => "2019-12-13",
|
||||||
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME"
|
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME",
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
"limitFrequency" => "",
|
"limitFrequency" => "",
|
||||||
"mabIsRefund" => "",
|
"mabIsRefund" => "",
|
||||||
@@ -53,8 +54,8 @@ class ZhyCreate implements CheckCouponContracts
|
|||||||
"ruleCode" => "$01-VC-1573468710381900",
|
"ruleCode" => "$01-VC-1573468710381900",
|
||||||
"ruleDetail" => "123123",
|
"ruleDetail" => "123123",
|
||||||
"ruleName" => "ceshi2",
|
"ruleName" => "ceshi2",
|
||||||
"voucherType" => "C01"
|
"voucherType" => "C01",
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
"tradLimit" => [
|
"tradLimit" => [
|
||||||
[
|
[
|
||||||
@@ -67,9 +68,9 @@ class ZhyCreate implements CheckCouponContracts
|
|||||||
"operator" => "",
|
"operator" => "",
|
||||||
"startValue" => "",
|
"startValue" => "",
|
||||||
"tradingUnit" => "",
|
"tradingUnit" => "",
|
||||||
"transactionType" => ""
|
"transactionType" => "",
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\sinopec;
|
namespace XuanChen\Sinopec\Action\sinopec;
|
||||||
|
|
||||||
use XuanChen\Coupon\Contracts\CheckCouponContracts;
|
use XuanChen\Sinopec\Contracts\CheckCouponContracts;
|
||||||
|
|
||||||
class ZhyQuery implements CheckCouponContracts
|
class ZhyQuery implements CheckCouponContracts
|
||||||
{
|
{
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
public function start()
|
public function start()
|
||||||
@@ -28,8 +29,8 @@ class ZhyQuery implements CheckCouponContracts
|
|||||||
"voucherRuleName" => "ceshi2",
|
"voucherRuleName" => "ceshi2",
|
||||||
"voucherSource" => "S01",
|
"voucherSource" => "S01",
|
||||||
"voucherStartTime" => "2019-12-13",
|
"voucherStartTime" => "2019-12-13",
|
||||||
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME"
|
"voucherStartTime_type" => "VOUCHER_START_TIME_TYPE_ABSOLUTE_EFFECTIVE_TIME",
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
"limitFrequency" => "",
|
"limitFrequency" => "",
|
||||||
"mabIsRefund" => "",
|
"mabIsRefund" => "",
|
||||||
@@ -53,8 +54,8 @@ class ZhyQuery implements CheckCouponContracts
|
|||||||
"ruleCode" => "$01-VC-1573468710381900",
|
"ruleCode" => "$01-VC-1573468710381900",
|
||||||
"ruleDetail" => "123123",
|
"ruleDetail" => "123123",
|
||||||
"ruleName" => "ceshi2",
|
"ruleName" => "ceshi2",
|
||||||
"voucherType" => "C01"
|
"voucherType" => "C01",
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
"tradLimit" => [
|
"tradLimit" => [
|
||||||
[
|
[
|
||||||
@@ -67,9 +68,9 @@ class ZhyQuery implements CheckCouponContracts
|
|||||||
"operator" => "",
|
"operator" => "",
|
||||||
"startValue" => "",
|
"startValue" => "",
|
||||||
"tradingUnit" => "",
|
"tradingUnit" => "",
|
||||||
"transactionType" => ""
|
"transactionType" => "",
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\ysd;
|
|
||||||
|
|
||||||
use App\Events\ConponCallback;
|
|
||||||
use App\Models\ActivityCoupon;
|
|
||||||
use App\Models\User;
|
|
||||||
use XuanChen\Coupon\Action\Init;
|
|
||||||
|
|
||||||
class YsdDestroy extends Init
|
|
||||||
{
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
if ($this->redemptionCode) {
|
|
||||||
try {
|
|
||||||
if (!$this->outletId) {
|
|
||||||
throw new \Exception('缺少网点id');
|
|
||||||
}
|
|
||||||
|
|
||||||
$info = ActivityCoupon::where('code', $this->redemptionCode)->first();
|
|
||||||
|
|
||||||
if (!$info) {
|
|
||||||
throw new \Exception('未查询到卡券信息');
|
|
||||||
}
|
|
||||||
|
|
||||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
|
||||||
|
|
||||||
if (empty($outlet)) {
|
|
||||||
return '作废失败,未查询到此网点信息。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$grants = $info->activity->grants()->pluck('user_id');
|
|
||||||
if ($grants->isEmpty()) {
|
|
||||||
return '作废失败,此活动还没有配置可发券渠道,请联系相关人员进行配置。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($outlet->parent_id, $grants->toArray())) {
|
|
||||||
return '作废失败,您没有权限作废此优惠券。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$info->canDestroy()) {
|
|
||||||
throw new \Exception('作废失败,' . $info->status_text . '不能操作');
|
|
||||||
}
|
|
||||||
|
|
||||||
$info->status = ActivityCoupon::STATUS_CLOSE;
|
|
||||||
$info->save();
|
|
||||||
|
|
||||||
event(new ConponCallback($info));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return '未获取到券码。';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\ysd;
|
|
||||||
|
|
||||||
use App\Models\Activity;
|
|
||||||
use App\Models\User;
|
|
||||||
use XuanChen\Coupon\Action\Init;
|
|
||||||
|
|
||||||
class YsdGrant extends Init
|
|
||||||
{
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
|
|
||||||
$activity = Activity::where('code', $this->activityId)->first();
|
|
||||||
if (!$activity) {
|
|
||||||
return '发券失败,没有找到这个活动。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$activity->status) {
|
|
||||||
return '发券失败,活动已经关闭。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$outlet = User::where('outlet_id', $this->outletId)->first();
|
|
||||||
if (!$outlet) {
|
|
||||||
return '发券失败,未查询到此网点信息。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$grants = $activity->grants()->pluck('user_id');
|
|
||||||
if ($grants->isEmpty()) {
|
|
||||||
return '发券失败,此活动还没有配置可发券渠道,请联系相关人员进行配置。';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($outlet->parent_id, $grants->toArray())) {
|
|
||||||
return '发券失败,您没有权限发此类优惠券。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$coupon = $activity->grant($this->mobile, $this->outletId);
|
|
||||||
|
|
||||||
if (!is_string($coupon)) {
|
|
||||||
return [
|
|
||||||
'name' => $activity->title,
|
|
||||||
'code' => $coupon->code,
|
|
||||||
'full' => $coupon->full,
|
|
||||||
'price' => $coupon->price,
|
|
||||||
'startTime' => $coupon->start_at->format('Y-m-d H:i:s'),
|
|
||||||
'endTime' => $coupon->end_at->format('Y-m-d H:i:s'),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $coupon;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\ysd;
|
|
||||||
|
|
||||||
use App\Models\ActivityCoupon;
|
|
||||||
use App\Models\User;
|
|
||||||
use XuanChen\Coupon\Action\Init;
|
|
||||||
|
|
||||||
class YsdQuery extends Init
|
|
||||||
{
|
|
||||||
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$info = User::where('outlet_id', $this->outletId)->first();
|
|
||||||
|
|
||||||
if (!$info) {
|
|
||||||
throw new \Exception('网点编号错误,未查询到网点信息');
|
|
||||||
}
|
|
||||||
|
|
||||||
$coupon = ActivityCoupon::where('code', $this->redemptionCode)->first();
|
|
||||||
|
|
||||||
if (!$coupon) {
|
|
||||||
throw new \Exception('卡券编号错误,未查询到卡券信息');
|
|
||||||
}
|
|
||||||
|
|
||||||
$activity = $coupon->activity;
|
|
||||||
if (!$activity) {
|
|
||||||
throw new \Exception('操作失败,未查到活动信息');
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取所有可核销渠道
|
|
||||||
$verifications = $activity->verifications()->pluck('user_id');
|
|
||||||
|
|
||||||
if ($verifications->isEmpty()) {
|
|
||||||
throw new \Exception('操作失败,此活动还没有配置可核券渠道,请联系相关人员进行配置。');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($info->parent_id, $verifications->toArray())) {
|
|
||||||
throw new \Exception('操作失败,您没有权限查询此卡券信息。');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $coupon;
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,195 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Action\ysd;
|
|
||||||
|
|
||||||
use App\Events\ConponCallback;
|
|
||||||
use App\Models\ActivityCoupon;
|
|
||||||
use App\Models\Coupon;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use XuanChen\Coupon\Action\Init;
|
|
||||||
|
|
||||||
class YsdVerification extends Init
|
|
||||||
{
|
|
||||||
|
|
||||||
public $ticket;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 核销具体流程
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/7/29 13:12
|
|
||||||
* @return array|string
|
|
||||||
*/
|
|
||||||
public function start()
|
|
||||||
{
|
|
||||||
//检查是否已经核销过
|
|
||||||
$res = $this->HasCheck();
|
|
||||||
if ($res !== false) {
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
//查询卡券信息 返回model 返回string 说明报错
|
|
||||||
$this->query_coupon = (new YsdQuery)->setOutletId($this->outletId)
|
|
||||||
->setCode($this->redemptionCode)
|
|
||||||
->start();
|
|
||||||
|
|
||||||
if (is_string($this->query_coupon)) {
|
|
||||||
return $this->query_coupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
//检查可核销次数,100元为1次。
|
|
||||||
if ($this->query_coupon->activity && $this->query_coupon->activity->need_check) {
|
|
||||||
$ret = $this->CheckCount();
|
|
||||||
if ($ret !== true) {
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//校验卡券
|
|
||||||
$ticket = $this->checkCoupon();
|
|
||||||
if (!is_array($ticket)) {
|
|
||||||
return $ticket;
|
|
||||||
}
|
|
||||||
|
|
||||||
//增加核销记录
|
|
||||||
$coupon = $this->AddCoupon();
|
|
||||||
if (is_string($coupon)) {
|
|
||||||
return $coupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$this->query_coupon->status = ActivityCoupon::STATUS_USED;
|
|
||||||
$this->query_coupon->used_at = now();
|
|
||||||
$this->query_coupon->save();
|
|
||||||
|
|
||||||
$this->coupon->status = 2;
|
|
||||||
$this->coupon->remark = '核销成功';
|
|
||||||
$this->coupon->save();
|
|
||||||
//返回的数据
|
|
||||||
$resdata = [
|
|
||||||
'name' => $this->coupon->couponName,
|
|
||||||
'total' => $this->coupon->total,
|
|
||||||
'price' => $this->coupon->price,
|
|
||||||
];
|
|
||||||
//核销成功 执行分润
|
|
||||||
$this->coupon->profit();
|
|
||||||
DB::commit();
|
|
||||||
|
|
||||||
event(new ConponCallback($this->query_coupon));
|
|
||||||
|
|
||||||
return $resdata;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
DB::rollback();
|
|
||||||
|
|
||||||
$this->coupon->status = 3;
|
|
||||||
$this->coupon->remark = '核销失败 ' . $e->getMessage();
|
|
||||||
$this->coupon->save();
|
|
||||||
|
|
||||||
return $this->coupon->remark;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 检查卡券信息
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/6/29 16:40
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function checkCoupon()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!$this->query_coupon->canRedemption()) {
|
|
||||||
return '核销失败,优惠券不可核销';
|
|
||||||
}
|
|
||||||
|
|
||||||
$now = now();
|
|
||||||
|
|
||||||
if ($this->query_coupon->start_at->gt($now)) {
|
|
||||||
return '核销失败,卡券未到可用时间。请在' . $this->query_coupon->start_at->format('Y-m-d H:i:s') . '后使用';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($now->gt($this->query_coupon->end_at)) {
|
|
||||||
return '核销失败,卡券已过期。';
|
|
||||||
}
|
|
||||||
|
|
||||||
$rule_code = $this->query_coupon->activity->rule->code;
|
|
||||||
$code = $this->user->code->where('code', $rule_code)->first();
|
|
||||||
|
|
||||||
if (!$code) {
|
|
||||||
return "核销失败,您没有权限使用此卡券优惠活动。";
|
|
||||||
}
|
|
||||||
|
|
||||||
$ticket = explode('-', $rule_code);
|
|
||||||
if (!is_array($ticket) || count($ticket) != 3) {
|
|
||||||
return "核销失败,卡券规则格式不正确";
|
|
||||||
}
|
|
||||||
|
|
||||||
$full = $ticket[1]; //full100
|
|
||||||
$price = $ticket[2];
|
|
||||||
// preg_match('/(\d{3}(\.\d+)?)/is', $full, $match);
|
|
||||||
preg_match('/\d+/', $full, $match);
|
|
||||||
|
|
||||||
if (!is_array($match)) {
|
|
||||||
return "核销失败,卡券规则格式不正确。";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_numeric($this->total)) {
|
|
||||||
return "核销失败,订单金额必须是数字";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($match[0] > $this->total) {
|
|
||||||
return '核销失败,订单金额不足。';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->ticket = [
|
|
||||||
'total' => $match[0],
|
|
||||||
'price' => $price,
|
|
||||||
'profit' => $code->profit,
|
|
||||||
];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Notes: 如可核销记录
|
|
||||||
* @Author: 玄尘
|
|
||||||
* @Date : 2020/7/21 15:03
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function AddCoupon()
|
|
||||||
{
|
|
||||||
DB::beginTransaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$couponData = [
|
|
||||||
'user_id' => $this->user->id,
|
|
||||||
'type' => Coupon::TYPE_YSD,
|
|
||||||
'outletId' => $this->outletId,
|
|
||||||
'orderid' => $this->orderid,
|
|
||||||
'PaOutletId' => '',
|
|
||||||
'redemptionCode' => $this->redemptionCode,
|
|
||||||
'thirdPartyGoodsId' => $this->query_coupon->activity->rule->code,
|
|
||||||
'couponName' => $this->query_coupon->activity->title,
|
|
||||||
'price' => $this->ticket['price'],
|
|
||||||
'total' => $this->total,
|
|
||||||
'profit' => $this->ticket['profit'],
|
|
||||||
'status' => $this->query_coupon->status,
|
|
||||||
'startTime' => $this->query_coupon->start_at,
|
|
||||||
'endTime' => $this->query_coupon->end_at,
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->coupon = Coupon::create($couponData);
|
|
||||||
|
|
||||||
DB::commit();
|
|
||||||
|
|
||||||
return $this->coupon;
|
|
||||||
} catch (Exception $e) {
|
|
||||||
DB::rollback();
|
|
||||||
|
|
||||||
return $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Contracts;
|
namespace XuanChen\Sinopec\Contracts;
|
||||||
|
|
||||||
interface CheckCouponContracts
|
interface CheckCouponContracts
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Contracts;
|
namespace XuanChen\Sinopec\Contracts;
|
||||||
|
|
||||||
interface CouponContracts
|
interface CouponContracts
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon;
|
namespace XuanChen\Sinopec;
|
||||||
|
|
||||||
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ class ServiceProvider extends LaravelServiceProvider
|
|||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->publishes([__DIR__ . '/../config/xuanchen_coupon.php' => config_path('xuanchen_coupon.php')]);
|
$this->publishes([__DIR__ . '/../config/sinopec.php' => config_path('sinopec.php')]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ class ServiceProvider extends LaravelServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$this->mergeConfigFrom(__DIR__ . '/../config/xuanchen_coupon.php', 'xuanchen_coupon');
|
$this->mergeConfigFrom(__DIR__ . '/../config/sinopec.php', 'sinopec');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon;
|
namespace XuanChen\Sinopec;
|
||||||
|
|
||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\DB;
|
|||||||
/**
|
/**
|
||||||
* 自有卡券系统
|
* 自有卡券系统
|
||||||
*/
|
*/
|
||||||
class Coupon
|
class Sinopec
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Traits;
|
namespace XuanChen\Sinopec\Traits;
|
||||||
|
|
||||||
use App\Models\Log as LogModel;
|
use App\Models\Log as LogModel;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace XuanChen\Coupon\Traits;
|
namespace XuanChen\Sinopec\Traits;
|
||||||
|
|
||||||
trait SetParams
|
trait SetParams
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user