修改bug

This commit is contained in:
2020-08-24 08:35:19 +08:00
parent 0230bb0144
commit da9d0d258f
2 changed files with 334 additions and 334 deletions

View File

@@ -36,12 +36,12 @@ class IndexController extends AdminController
]); ]);
$filter->between('created_at', '核销时间')->datetime(); $filter->between('created_at', '核销时间')->datetime();
$users = User::query() $users = User::query()
->whereHas('identity', function ($query) { ->whereHas('identity', function ($query) {
$query->where('identity_id', 1); $query->where('identity_id', 1);
}) })
->where('type', 'pingan') ->where('type', 'pingan')
->get() ->get()
->pluck('nickname', 'id'); ->pluck('nickname', 'id');
$filter->equal('user_id', '渠道')->select($users); $filter->equal('user_id', '渠道')->select($users);
$filter->equal('thirdPartyGoodsId', '优惠政策')->select(ActivityRule::pluck('title', 'code')); $filter->equal('thirdPartyGoodsId', '优惠政策')->select(ActivityRule::pluck('title', 'code'));
}); });
@@ -64,11 +64,11 @@ class IndexController extends AdminController
return $this->user->nickname; return $this->user->nickname;
}); });
$grid->column('type', '类型') $grid->column('type', '类型')
->using(Coupon::TYPES) ->using(Coupon::TYPES)
->label([ ->label([
'1' => 'info', '1' => 'info',
'2' => 'success', '2' => 'success',
]); ]);
$grid->column('网点名称/编号')->display(function () { $grid->column('网点名称/编号')->display(function () {
return $this->outlet ? $this->outlet->nickname : $this->outletId; return $this->outlet ? $this->outlet->nickname : $this->outletId;
@@ -118,13 +118,13 @@ class IndexController extends AdminController
$pass = collect($pass); $pass = collect($pass);
return '<label class="label label-success">全部:' . $all->count() . '张</label>&nbsp;&nbsp;' return '<label class="label label-success">全部:' . $all->count() . '张</label>&nbsp;&nbsp;'
. '<label class="label label-success">成功:' . $pass->count() . '张</label>&nbsp;&nbsp;' . '<label class="label label-success">成功:' . $pass->count() . '张</label>&nbsp;&nbsp;'
. '<label class="label label-success">失败:' . $all->where('status', 3) . '<label class="label label-success">失败:' . $all->where('status', 3)
->count() . '张</label>&nbsp;&nbsp;' ->count() . '张</label>&nbsp;&nbsp;'
. '<label class="label label-success">核销金额:' . $pass->sum('price') . '元</label>&nbsp;&nbsp;' . '<label class="label label-success">核销金额:' . $pass->sum('price') . '元</label>&nbsp;&nbsp;'
. '<label class="label label-success">资金通道结算:' . $pass->sum('profit') . '元</label>&nbsp;&nbsp;' . '<label class="label label-success">资金通道结算:' . $pass->sum('profit') . '元</label>&nbsp;&nbsp;'
. '<label class="label label-success">打款金额:' . $pass->where('is_profit', 1) . '<label class="label label-success">打款金额:' . $pass->where('is_profit', 1)
->sum('profit') . '元</label>&nbsp;&nbsp;'; ->sum('profit') . '元</label>&nbsp;&nbsp;';
}); });
$grid->disableExport(false); $grid->disableExport(false);
@@ -162,30 +162,30 @@ class IndexController extends AdminController
$form->decimal('recommend', '推荐人佣金')->required()->default(0); $form->decimal('recommend', '推荐人佣金')->required()->default(0);
$form->number('hots', '热度/亲密度')->required()->default('1'); $form->number('hots', '热度/亲密度')->required()->default('1');
$form->text('times', '显示时间') $form->text('times', '显示时间')
->default('200') ->default('200')
->required() ->required()
->help('礼物显示时间,毫秒'); ->help('礼物显示时间,毫秒');
$form->textarea('description', '礼物说明'); $form->textarea('description', '礼物说明');
$form->image('cover', '封面') $form->image('cover', '封面')
->rules(function ($form) { ->rules(function ($form) {
if ($form->model()->cover != '') { if ($form->model()->cover != '') {
return 'nullable|image'; return 'nullable|image';
} else { } else {
return 'required'; return 'required';
} }
}) })
->move('images/' . date('Y/m/d')) ->move('images/' . date('Y/m/d'))
->removable() ->removable()
->uniqueName(); ->uniqueName();
$form->switch('status', '状态')->default(1); $form->switch('status', '状态')->default(1);
$form->decimal('sort', '排序')->default(0)->help('序号越大越靠前'); $form->decimal('sort', '排序')->default(0)->help('序号越大越靠前');
$form->saving(function ($form) { $form->saving(function ($form) {
$sum = (int) $form->pv + (int) $form->bonus + (int) $form->recommend; $sum = (int)$form->pv + (int)$form->bonus + (int)$form->recommend;
if ((int) $sum > $form->price) { if ((int)$sum > $form->price) {
admin_warning('配置错误', 'PV+佣金+推荐人佣金不能超过礼物价值'); admin_warning('配置错误', 'PV+佣金+推荐人佣金不能超过礼物价值');
throw new \Exception('配置错误,PV+佣金+推荐人佣金不能超过礼物价值'); throw new \Exception('配置错误,PV+佣金+推荐人佣金不能超过礼物价值');
} }

View File

@@ -1,301 +1,301 @@
<?php <?php
namespace XuanChen\Coupon\Action\pingan; namespace XuanChen\Coupon\Action\pingan;
use App\Models\Coupon; use App\Models\Coupon;
use App\Models\User; use App\Models\User;
use Carbon\Carbon; use Carbon\Carbon;
class Verification extends PingAnInit class Verification extends PingAnInit
{ {
public $ticket; public $ticket;
//查询到的卡券规则和商品id //查询到的卡券规则和商品id
public $queryData; public $queryData;
public function start() public function start()
{ {
//检查是否已经核销过 //检查是否已经核销过
$res = $this->HasCheck(); $res = $this->HasCheck();
if ($res !== false) { if ($res !== false) {
return $res; return $res;
} }
//检查可核销次数 //检查可核销次数
$ret = $this->CheckCount(); $ret = $this->CheckCount();
if ($ret !== true) { if ($ret !== true) {
return $ret; return $ret;
} }
//查询卡券信息 //查询卡券信息
$this->query_coupon = (new Query)->setOutletId($this->outletId) $this->query_coupon = (new Query)->setOutletId($this->outletId)
->setCode($this->redemptionCode) ->setCode($this->redemptionCode)
->start(); ->start();
if (is_string($this->query_coupon)) { if (is_string($this->query_coupon)) {
return $this->query_coupon; return $this->query_coupon;
} }
//校验卡券 //校验卡券
$ticket = $this->checkCoupon(); $ticket = $this->checkCoupon();
if (!is_array($ticket)) { if (!is_array($ticket)) {
return $ticket; return $ticket;
} }
//增加核销记录 //增加核销记录
$coupon = $this->AddCoupon(); $coupon = $this->AddCoupon();
if (is_string($coupon)) { if (is_string($coupon)) {
return $coupon; return $coupon;
} }
try { try {
$params = [ $params = [
'couponNo' => $coupon->redemptionCode, 'couponNo' => $coupon->redemptionCode,
'partnerOrderId' => date('ymdHis') . sprintf("%0" . strlen(999999) . "d", mt_rand(0, 999999)), 'partnerOrderId' => date('ymdHis') . sprintf("%0" . strlen(999999) . "d", mt_rand(0, 999999)),
'outletId' => $coupon->PaOutletId, 'outletId' => $coupon->PaOutletId,
'productId' => $coupon->productId, 'productId' => $coupon->productId,
'timestamp' => $this->getMsecTime(), 'timestamp' => $this->getMsecTime(),
]; ];
$url = $this->baseUri . 'partner/redemption'; $url = $this->baseUri . 'partner/redemption';
$str = $this->encrypt($params); $str = $this->encrypt($params);
$res = $this->getPingAnData($url, [], ['data' => $str]); $res = $this->getPingAnData($url, [], ['data' => $str]);
if (!is_array($res)) { if (!is_array($res)) {
$coupon->remark = $res; $coupon->remark = $res;
$coupon->status = 3; $coupon->status = 3;
$coupon->save(); $coupon->save();
throw new \Exception($res); throw new \Exception($res);
} }
if ($res['code'] != 200) { if ($res['code'] != 200) {
$coupon->remark = $res['code'] . '--' . $res['message']; $coupon->remark = $res['code'] . '--' . $res['message'];
$coupon->status = 3; $coupon->status = 3;
$coupon->save(); $coupon->save();
throw new \Exception($res['message']); throw new \Exception($res['message']);
} }
$data = $res['data']; $data = $res['data'];
$coupon->remark = $data['message']; $coupon->remark = $data['message'];
$coupon->status = ($data['status'] == 1) ? 2 : 3; $coupon->status = ($data['status'] == 1) ? 2 : 3;
$coupon->save(); $coupon->save();
//返回的数据 //返回的数据
$resdata = [ $resdata = [
'price' => $coupon->price, 'price' => $coupon->price,
'name' => $coupon->couponName, 'name' => $coupon->couponName,
'total' => $coupon->total, 'total' => $coupon->total,
]; ];
//核销成功 执行分润 //核销成功 执行分润
$coupon->profit(); $coupon->profit();
return $resdata; return $resdata;
} catch (Exception $e) { } catch (Exception $e) {
$coupon->status = 3; $coupon->status = 3;
$coupon->remark = '核销失败 ' . $e->getMessage(); $coupon->remark = '核销失败 ' . $e->getMessage();
$coupon->save(); $coupon->save();
return $coupon->remark; return $coupon->remark;
} }
} }
/** /**
* Notes: 如可核销记录 * Notes: 如可核销记录
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/7/21 15:03 * @Date : 2020/7/21 15:03
* @return string * @return string
*/ */
public function AddCoupon() public function AddCoupon()
{ {
try { try {
$couponData = [ $couponData = [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'type' => Coupon::TYPE_PINGAN, 'type' => Coupon::TYPE_PINGAN,
'outletId' => $this->outletId, 'outletId' => $this->outletId,
'orderid' => $this->orderid, 'orderid' => $this->orderid,
'PaOutletId' => $this->queryData['PaOutletId'], 'PaOutletId' => $this->queryData['PaOutletId'],
'redemptionCode' => $this->redemptionCode, 'redemptionCode' => $this->redemptionCode,
'productId' => $this->queryData['productId'], 'productId' => $this->queryData['productId'],
'thirdPartyGoodsId' => $this->queryData['thirdPartyGoodsId'], 'thirdPartyGoodsId' => $this->queryData['thirdPartyGoodsId'],
'couponName' => $this->query_coupon['couponName'], 'couponName' => $this->query_coupon['couponName'],
'price' => $this->ticket['price'], 'price' => $this->ticket['price'],
'total' => $this->total, 'total' => $this->total,
'profit' => $this->ticket['profit'], 'profit' => $this->ticket['profit'],
'status' => 0, 'status' => 0,
'startTime' => $this->query_coupon['startTime'], 'startTime' => $this->query_coupon['startTime'],
'endTime' => $this->query_coupon['endTime'], 'endTime' => $this->query_coupon['endTime'],
]; ];
return $coupon = Coupon::create($couponData); return $coupon = Coupon::create($couponData);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
} }
/** /**
* Notes: 检查卡券信息 * Notes: 检查卡券信息
* @Author: 玄尘 * @Author: 玄尘
* @Date : 2020/6/29 16:40 * @Date : 2020/6/29 16:40
* @return string * @return string
*/ */
public function checkCoupon() public function checkCoupon()
{ {
//检查卡券是否已被核销 //检查卡券是否已被核销
if ($this->query_coupon['status'] > 0) { if ($this->query_coupon['status'] > 0) {
if (isset(config('pingan.coupon_status')[$this->query_coupon['status']])) { if (isset(config('pingan.coupon_status')[$this->query_coupon['status']])) {
return '核销失败,平安券' . config('pingan.coupon_status')[$this->query_coupon['status']]; return '核销失败,平安券' . config('pingan.coupon_status')[$this->query_coupon['status']];
} }
return '核销失败,平安券不可用。'; return '核销失败,平安券不可用。';
} }
$startTime = Carbon::parse($this->query_coupon['startTime']); $startTime = Carbon::parse($this->query_coupon['startTime']);
$endTime = Carbon::parse($this->query_coupon['endTime']); $endTime = Carbon::parse($this->query_coupon['endTime']);
$now = now(); $now = now();
if ($startTime->gt($now)) { if ($startTime->gt($now)) {
return '核销失败,平安券未开始使用。'; return '核销失败,平安券未开始使用。';
} }
if ($now->gt($endTime)) { if ($now->gt($endTime)) {
return '核销失败,平安券已过期。'; return '核销失败,平安券已过期。';
} }
//查找适配的商品id 和 网点id //查找适配的商品id 和 网点id
$pinganData = $this->getPinganProduct(); $pinganData = $this->getPinganProduct();
if (is_string($pinganData)) { if (is_string($pinganData)) {
return $pinganData; return $pinganData;
} }
//获取相关优惠信息 //获取相关优惠信息
return $this->checkCode(); return $this->checkCode();
} }
/** /**
* 校验平安券编号 * 校验平安券编号
* @return array|string [type] [description] * @return array|string [type] [description]
*/ */
public function checkCode() public function checkCode()
{ {
$code = $this->user->code->where('code', $this->queryData['thirdPartyGoodsId'])->first(); $code = $this->user->code->where('code', $this->queryData['thirdPartyGoodsId'])->first();
if (!$code) { if (!$code) {
return "核销失败,未找到此项平安券规则,请联系管理人员检查渠道配置。"; return "核销失败,未找到此项平安券规则,请联系管理人员检查渠道配置。";
} }
$ticket = explode('-', $this->queryData['thirdPartyGoodsId']); $ticket = explode('-', $this->queryData['thirdPartyGoodsId']);
if (!is_array($ticket) || count($ticket) != 3) { if (!is_array($ticket) || count($ticket) != 3) {
return "核销失败,平安券规则格式不正确。"; return "核销失败,平安券规则格式不正确。";
} }
$full = $ticket[1]; //full100 $full = $ticket[1]; //full100
$price = $ticket[2]; $price = $ticket[2];
preg_match('/\d+/', $full, $result); preg_match('/\d+/', $full, $result);
if (empty($result) || !is_array($result)) { if (empty($result) || !is_array($result)) {
return "核销失败,平安券规则格式不正确。"; return "核销失败,平安券规则格式不正确。";
} }
if (!is_numeric($this->total)) { if (!is_numeric($this->total)) {
return "核销失败,订单金额必须是数字"; return "核销失败,订单金额必须是数字";
} }
if ($result[0] > $this->total) { if ($result[0] > $this->total) {
return '核销失败,订单金额不足,平安券不可使用。'; return '核销失败,订单金额不足,平安券不可使用。';
} }
$this->ticket = [ $this->ticket = [
'total' => $result[0], 'total' => $result[0],
'price' => $price, 'price' => $price,
'profit' => $code->profit, 'profit' => $code->profit,
]; ];
return $this->ticket; return $this->ticket;
} }
/** /**
* 查找平安商品id * 查找平安商品id
* @author 玄尘 2020-04-04 * @author 玄尘 2020-04-04
* @return array|string [type] [description] * @return array|string [type] [description]
*/ */
public function getPinganProduct() public function getPinganProduct()
{ {
//查询网点是否存在 //查询网点是否存在
$outlet = User::where('outlet_id', $this->outletId)->first(); $outlet = User::where('outlet_id', $this->outletId)->first();
if (!$outlet) { if (!$outlet) {
return '核销失败,网点编号错误,未查询到网点信息'; return '核销失败,网点编号错误,未查询到网点信息';
} }
$PaOutletId = $outlet->PaOutletId; $PaOutletId = $outlet->PaOutletId;
$outlet_id = $outlet->outlet_id; $outlet_id = $outlet->outlet_id;
$profitOfferItemVersion = $this->query_coupon['profitOfferItemVersion']; $profitOfferItemVersion = $this->query_coupon['profitOfferItemVersion'];
if (!$PaOutletId && $profitOfferItemVersion != 1) { if (!$PaOutletId && $profitOfferItemVersion != 1) {
return '核销失败参数错误渠道信息缺少平安网点id'; return '核销失败参数错误渠道信息缺少平安网点id';
} }
$productItemList = $this->query_coupon['productItemList']; $productItemList = $this->query_coupon['productItemList'];
if (!is_array($productItemList) || !is_array($productItemList[0])) { if (!is_array($productItemList) || !is_array($productItemList[0])) {
return '核销失败,平安券数据有误,可能是未配置网点。'; return '核销失败,平安券数据有误,可能是未配置网点。';
} }
//循环查找 //循环查找
$first = ''; $first = '';
foreach ($productItemList as $key => $item) { foreach ($productItemList as $key => $item) {
$productId = $item['productId']; $productId = $item['productId'];
$thirdPartyGoodsId = $item['thirdPartyGoodsId']; $thirdPartyGoodsId = $item['thirdPartyGoodsId'];
$outletList = $item['outletList']; $outletList = $item['outletList'];
if (!is_array($outletList) || !is_array($outletList[0])) { if (!is_array($outletList) || !is_array($outletList[0])) {
return '核销失败,网点信息有误!请检查平安券配置信息。'; return '核销失败,网点信息有误!请检查平安券配置信息。';
break; break;
} }
$outletList = collect($outletList); $outletList = collect($outletList);
//判断是新版还是旧版 //判断是新版还是旧版
if ($profitOfferItemVersion) { if ($profitOfferItemVersion) {
//新版通过第三方查询 //新版通过第三方查询
$first = $outletList->firstWhere('thirdOutletNo', $outlet_id); $first = $outletList->firstWhere('thirdOutletNo', $outlet_id);
if ($first) { if ($first) {
break; break;
} }
} else { } else {
//旧版通过平安网点查询 //旧版通过平安网点查询
$first = $outletList->firstWhere('outletNo', $PaOutletId); $first = $outletList->firstWhere('outletNo', $PaOutletId);
if ($first) { if ($first) {
break; break;
} }
} }
} }
if (!$first) { if (!$first) {
return '核销失败,未找到可用网点信息。'; return '核销失败,未找到可用网点信息。';
} }
if (!$thirdPartyGoodsId) { if (!$thirdPartyGoodsId) {
return '核销失败,平安券编号规则有误。'; return '核销失败,平安券编号规则有误。';
} }
if (!$productId) { if (!$productId) {
return '核销失败未查询到平安券商品id。'; return '核销失败未查询到平安券商品id。';
} }
return $this->queryData = [ return $this->queryData = [
'thirdPartyGoodsId' => $thirdPartyGoodsId, 'thirdPartyGoodsId' => $thirdPartyGoodsId,
'productId' => $productId, 'productId' => $productId,
'PaOutletId' => $first['outletNo'], 'PaOutletId' => $first['outletNo'],
]; ];
} }
} }