完善石化包

This commit is contained in:
2020-10-09 09:54:33 +08:00
parent d0ae80aeff
commit c909b9b1ed
19 changed files with 35 additions and 1092 deletions

View File

@@ -0,0 +1,144 @@
<?php
namespace XuanChen\Sinopec;
use App\Models\Activity;
use App\Models\User;
use Illuminate\Support\Facades\DB;
/**
* 自有卡券系统
*/
class Sinopec
{
/**
* Notes: 发券接口
* @Author: 玄尘
* @Date : 2020/6/28 15:07
* @param $activityId 活动编号
* @param $outletId 网点编号
* @param $mobile 手机号
*/
public static function Grant($activityId, $outletId, $mobile)
{
$model = config('xuanchen_coupon.rules.ysd.model');
return (new $model)->setActivityId($activityId)
->setOutletId($outletId)
->setMobile($mobile)
->grant();
}
/**
* Notes: 查询接口
* @Author: 玄尘
* @Date : 2020/7/21 11:58
* @param $redemptionCode
*/
public static function Query($redemptionCode, $outletId)
{
if (!$redemptionCode) {
return '查询失败,未获取到券码';
}
$model = self::getModelByCode($redemptionCode);
if (is_string($model)) {
return $model;
}
return $model->setCode($redemptionCode)
->setOutletId($outletId)
->detail();
}
/**
* Notes: 卡券作废
* @Author: 玄尘
* @Date : 2020/9/2 16:54
* @param $redemptionCode
* @param $outletId
* @return string
*/
public static function Destroy($redemptionCode, $outletId)
{
try {
$model = self::getModelByCode($redemptionCode);
if (is_string($model)) {
return $model;
}
return $model->setCode($redemptionCode)
->setOutletId($outletId)
->destroy();
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* Notes: 根据券码 获取class
* @Author: 玄尘
* @Date : 2020/7/21 12:00
* @param $code
* @return string
*/
public static function getModelByCode($code)
{
$rules = config('xuanchen_coupon.rules');
if (!$rules) {
return '系统出错,未找到配置文件';
}
$model = '';
foreach ($rules as $rule) {
if (preg_match($rule['pattern'], $code, $matches)) {
$model = $rule['model'];
break;
}
}
if (!$model) {
throw new \Exception('卡券核销失败。未查到卡券所属');
}
return new $model;
}
/**
* Notes: description
* @Author: 玄尘
* @Date : 2020/8/21 13:33
* @param \App\Models\User $user 渠道
* @param string $redemptionCode 要核销的券码
* @param float $total 订单金额
* @param string $outletId 网点id
* @param string $orderid 订单id
* @return string
*/
public static function Redemption(User $user, string $redemptionCode, float $total, string $outletId, string $orderid = '')
{
try {
$model = self::getModelByCode($redemptionCode);
if (is_string($model)) {
return $model;
}
return $model->setUser($user)
->setCode($redemptionCode)
->setTotal($total)
->setOutletId($outletId)
->setOrderId($orderid)
->start();
} catch (\Exception $e) {
return $e->getMessage();
}
}
}