阶段性更新

This commit is contained in:
2020-10-13 08:49:57 +08:00
parent 7cfd45bf99
commit d8cd8ae9a6
21 changed files with 420 additions and 423 deletions

View File

@@ -10,6 +10,7 @@ use RuLong\Identity\Models\Identity;
class IdentityController extends AdminController class IdentityController extends AdminController
{ {
protected $title = '用户身份配置'; protected $title = '用户身份配置';
protected function grid() protected function grid()
@@ -47,6 +48,7 @@ class IdentityController extends AdminController
$grid->column('remark', '说明'); $grid->column('remark', '说明');
$grid->column('updated_at', '修改时间'); $grid->column('updated_at', '修改时间');
return $grid; return $grid;
} }

View File

@@ -41,6 +41,10 @@ class IndexController extends AdminController
$filter->column(1 / 2, function ($filter) { $filter->column(1 / 2, function ($filter) {
$filter->equal('msg_txn_code', '交易类型')->select(config('unionpay.type')); $filter->equal('msg_txn_code', '交易类型')->select(config('unionpay.type'));
}); });
$filter->column(1 / 2, function ($filter) {
$filter->equal('req_serial_no', '流水号');
$filter->equal('orig_req_serial_no', '原流水号');
});
}); });
$grid->column('id', '#ID#'); $grid->column('id', '#ID#');
@@ -53,6 +57,9 @@ class IndexController extends AdminController
$grid->column('mkt_code', '券码'); $grid->column('mkt_code', '券码');
$grid->column('msg_sys_sn', '平台流水号'); $grid->column('msg_sys_sn', '平台流水号');
$grid->column('req_serial_no', '查询流水号'); $grid->column('req_serial_no', '查询流水号');
$grid->column('status', '状态')
->using(UnionpayLog::STATUS)
->label();
// $grid->column('请求参数')->display(function ($title, $column) { // $grid->column('请求参数')->display(function ($title, $column) {
// return '点击展开'; // return '点击展开';

View File

@@ -143,12 +143,15 @@ class IndexController extends AdminController
$grid->column('分润规则')->display(function ($title, $column) { $grid->column('分润规则')->display(function ($title, $column) {
return '点击展开'; return '点击展开';
})->modal(function ($model) { })->modal(function ($model) {
if ($model->code) { if ($model->code) {
$codes = $model->code->map(function ($code) { $codes = $model->code->map(function ($code) {
return $code->only(['name', 'code', 'profit']); return $code->only(['name', 'code', 'profit']);
}); });
return new Table(['名称', '规则项', '分润金额(元)'], $codes->toArray()); $table = new Table(['名称', '规则项', '分润金额(元)'], $codes->toArray());
return trim($table->render(), '"');
} }
}); });

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Admin\Renderable\User;
use App\Models\User;
use Encore\Admin\Widgets\Table;
use Illuminate\Contracts\Support\Renderable;
class Rule implements Renderable
{
public function render($key = null)
{
$user = User::find($key);
$codes = $user->code->map(function ($code) {
return $code->only(['name', 'code', 'profit']);
});
$table = new Table(['名称', '规则项', '分润金额(元)'], $codes->toArray());
return $table->render();
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Admin\Renderable\User;
use App\Models\User;
use Encore\Admin\Widgets\Table;
use Illuminate\Contracts\Support\Renderable;
class ServerKey implements Renderable
{
public function render($key = null)
{
$user = User::find($key);
$data = [
[
'服务秘钥', $user->server_key ?? '---',
],
[
'DES3秘钥', $user->des3key ?? '---',
],
];
$table = new Table(['名称', '参数'], $data);
return $table->render();
die();
}
}

View File

@@ -1,45 +0,0 @@
<?php
/**
* Author: sai
* Date: 2020/1/15
* Time: 14:31
*/
namespace App\Exceptions;
class ApiUnionpayException extends \Exception
{
const ERROR_CODE = 1001;
const ERROR_MSG = 'ApiUnionpayException';
private $data = [];
/**
* BusinessException constructor.
* @param string $message
* @param string $code
* @param array $data
*/
public function __construct($data = [])
{
$this->data = $data;
}
/**
* @return array
*/
public function getData()
{
return $this->data;
}
/**
* 异常输出
*/
public function render($request)
{
return response()->json($this->getData(), 200);
}
}

View File

@@ -13,7 +13,6 @@ class Handler extends ExceptionHandler
* @var array * @var array
*/ */
protected $dontReport = [ protected $dontReport = [
ApiException::class,
]; ];
/** /**
@@ -32,7 +31,6 @@ class Handler extends ExceptionHandler
*/ */
public function report(Exception $exception) public function report(Exception $exception)
{ {
info($exception->getMessage());
parent::report($exception); parent::report($exception);
} }

View File

@@ -6,6 +6,7 @@ use App\Events\ConponCallback;
use App\Models\ActivityCouponLog; use App\Models\ActivityCouponLog;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use RuntimeException;
class ConponCallbackListener implements ShouldQueue class ConponCallbackListener implements ShouldQueue
{ {
@@ -55,6 +56,7 @@ class ConponCallbackListener implements ShouldQueue
$data['remark'] = '接口错误'; $data['remark'] = '接口错误';
$error = true; $error = true;
} }
ActivityCouponLog::create($data); ActivityCouponLog::create($data);
if ($error) { if ($error) {

View File

@@ -64,4 +64,26 @@ class ActivityCoupon extends Model
return $this->canRedemption(); return $this->canRedemption();
} }
/**
* Notes: 是否可以撤销
* @Author: 玄尘
* @Date : 2020/10/12 11:57
* @return bool
*/
public function canReversal()
{
return $this->status == self::STATUS_USED;
}
/**
* Notes: 撤销
* @Author: 玄尘
* @Date : 2020/10/12 13:56
*/
public function reversal()
{
$this->status = self::STATUS_INIT;
$this->save();
}
} }

View File

@@ -37,6 +37,9 @@ class Coupon extends Model
case 4: case 4:
return '已分润'; return '已分润';
break; break;
case 5:
return '已撤销';
break;
default: default:
return '未知状态'; return '未知状态';
break; break;
@@ -88,6 +91,27 @@ class Coupon extends Model
} }
} }
/**
* Notes: 撤销
* @Author: 玄尘
* @Date : 2020/10/12 13:56
*/
public function reversal()
{
$this->status = 5;
$this->remark = '撤销成功';
$this->save();
if ($this->profit > 0) {
return $this->user->account->rule('refreeze', -$this->profit, false, [
'coupon_id' => $this->id,
'redemptionCode' => $this->redemptionCode,
]);
} else {
return '不需要操作';
}
}
/** /**
* Notes: 撤销分润 * Notes: 撤销分润
* @Author: 玄尘 * @Author: 玄尘

View File

@@ -10,6 +10,13 @@ class UnionpayLog extends Model
'out_source' => 'array', 'out_source' => 'array',
]; ];
const STATUS_SUCCESS = 1;
const STATUS_ERROR = 0;
const STATUS = [
self::STATUS_SUCCESS => '成功',
self::STATUS_ERROR => '失败',
];
public function coupon() public function coupon()
{ {
return $this->hasOne(Coupon::class, 'redemptionCode', 'mkt_code'); return $this->hasOne(Coupon::class, 'redemptionCode', 'mkt_code');

View File

@@ -41,13 +41,19 @@ class PinganAction extends Init implements CouponContracts
} }
//发券 //发券
function grant() public function grant()
{ {
return '没这个接口'; return '没这个接口';
} }
//作废 //作废
function destroy() public function destroy()
{
return '没这个接口';
}
//撤销
public function reversal()
{ {
return '没这个接口'; return '没这个接口';
} }

View File

@@ -5,6 +5,7 @@ namespace XuanChen\Coupon\Action;
use XuanChen\Coupon\Action\ysd\YsdDestroy; use XuanChen\Coupon\Action\ysd\YsdDestroy;
use XuanChen\Coupon\Action\ysd\YsdGrant; use XuanChen\Coupon\Action\ysd\YsdGrant;
use XuanChen\Coupon\Action\ysd\YsdQuery; use XuanChen\Coupon\Action\ysd\YsdQuery;
use XuanChen\Coupon\Action\ysd\YsdReversal;
use XuanChen\Coupon\Action\ysd\YsdVerification; use XuanChen\Coupon\Action\ysd\YsdVerification;
use XuanChen\Coupon\Contracts\CouponContracts; use XuanChen\Coupon\Contracts\CouponContracts;
@@ -88,4 +89,17 @@ class YsdAction extends Init implements CouponContracts
->start(); ->start();
} }
/**
* Notes: 撤销
* @Author: 玄尘
* @Date : 2020/10/12 11:55
* @return array|string
*/
public function reversal()
{
return $res = (new YsdReversal)->setCode($this->redemptionCode)
->setOutletId($this->outletId)
->start();
}
} }

View File

@@ -0,0 +1,69 @@
<?php
namespace XuanChen\Coupon\Action\ysd;
use App\Events\ConponCallback;
use App\Models\ActivityCoupon;
use App\Models\Coupon;
use App\Models\User;
use XuanChen\Coupon\Action\Init;
class YsdReversal extends Init
{
public function start()
{
if ($this->redemptionCode) {
try {
if (!$this->outletId) {
throw new \Exception('缺少网点id');
}
$activityCoupon = ActivityCoupon::where('code', $this->redemptionCode)->first();
if (!$activityCoupon) {
throw new \Exception('未查询到卡券信息');
}
if (!$activityCoupon->canReversal()) {
throw new \Exception('操作失败,卡券当前状态不能操作');
}
$outlet = User::where('outlet_id', $this->outletId)->first();
if (empty($outlet)) {
return '操作失败,未查询到此网点信息。';
}
$grants = $activityCoupon->activity->grants()->pluck('user_id');
if ($grants->isEmpty()) {
return '操作失败,此活动还没有配置可发券渠道,请联系相关人员进行配置。';
}
if (!in_array($outlet->parent_id, $grants->toArray())) {
return '操作失败,您没有权限作废此优惠券。';
}
$coupon = Coupon::where('redemptionCode', $this->redemptionCode)
->where('status', 2)
->first();
if ($activityCoupon && $coupon) {
//撤销
$activityCoupon->reversal();
//撤销
$coupon->reversal();
}
event(new ConponCallback($activityCoupon));
return true;
} catch (\Exception $e) {
return $e->getMessage();
}
} else {
return '未获取到券码。';
}
}
}

View File

@@ -89,7 +89,8 @@ class Coupon
{ {
$rules = config('xuanchen_coupon.rules'); $rules = config('xuanchen_coupon.rules');
if (!$rules) { if (!$rules) {
return '系统出错,未找到配置文件'; throw new \Exception('系统出错,未找到配置文件');
} }
$model = ''; $model = '';
@@ -141,4 +142,28 @@ class Coupon
} }
/**
* Notes: 冲正 撤销 已经核销的改为未核销状态
* @Author: 玄尘
* @Date : 2020/10/12 11:54
* @param $redemptionCode
* @param $outletId
* @return string
*/
public static function Reversal($redemptionCode, $outletId)
{
try {
$model = self::getModelByCode($redemptionCode);
if (is_string($model)) {
return $model;
}
return $model->setCode($redemptionCode)
->setOutletId($outletId)
->reversal();
} catch (\Exception $e) {
return $e->getMessage();
}
}
} }

View File

@@ -2,49 +2,41 @@
namespace XuanChen\UnionPay\Action; namespace XuanChen\UnionPay\Action;
use App\Models\ActivityCoupon; use XuanChen\Coupon\Coupon;
use App\Models\User;
class Query class Query
{ {
public $outlet_id;
public $params;
public $outdata;
public function start() public function start()
{ {
try { try {
$info = User::where('outlet_id', $this->outletId)->first(); $res = Coupon::Query($this->params['mkt_code'], $this->outlet_id);
if (!$info) { if (is_array($res)) {
throw new \Exception('网点编号错误,未查询到网点信息'); $this->outdata['pos_display'] = $res['name'];
$this->outdata['discount'] = $res['price'] * 100;
$this->outdata['actual_amt'] = (int)bcsub($this->params['amount'], $res['price'] * 100);
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $res;
} }
$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) { } catch (\Exception $e) {
return $e->getMessage(); $this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $e->getMessage();
} }
} }
public function back()
{
return $this->outdata;
}
} }

View File

@@ -0,0 +1,58 @@
<?php
namespace XuanChen\UnionPay\Action;
use App\Models\ActivityCoupon;
use App\Models\UnionpayLog;
use App\Models\User;
use XuanChen\Coupon\Coupon;
class Redemption
{
public $outlet_id;
public $params;
public $outdata;
public $agent_id;
public function start()
{
//查询聚合信息
$query = UnionpayLog::where('req_serial_no', $this->params['orig_req_serial_no'])
->where('msg_txn_code', '002025')
->latest()
->first();
if (!$query) {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '销账失败,未查询到前置数据。';
} else {
$this->outdata['orig_amt'] = (int)$query->in_source['amount']; //订单金额 原始金额
$this->outdata['discount_amt'] = $query->out_source['discount']; //折扣金额
$this->outdata['pay_amt'] = $query->out_source['actual_amt']; //折扣后金额
//获取银联渠道
$user = User::find($this->agent_id);
if ($query) {
$coupon = Coupon::Redemption($user, $query->mkt_code, $this->params['orig_amt'] / 100, $this->outlet_id, '');
if (!is_array($coupon)) {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $coupon;
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '未查询到前置接口,获取券码失败。';
}
}
}
public function back()
{
return $this->outdata;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace XuanChen\UnionPay\Action;
use App\Models\UnionpayLog;
use XuanChen\Coupon\Coupon;
use App\Models\Coupon as CouponModel;
class Reversal
{
public $outlet_id;
public $params;
public $outdata;
public function start()
{
try {
//查询聚合信息
$info = UnionpayLog::where('req_serial_no', $this->params['orig_req_serial_no'])
->where('msg_txn_code', '002100')
->where('status', 1)
->latest()
->first();
if ($info) {
$query = UnionpayLog::where('req_serial_no', $info->orig_req_serial_no)
->where('msg_txn_code', '002025')
->where('status', 1)
->latest()
->first();
$coupon = CouponModel::where('redemptionCode', $query->mkt_code)
->where('status', 2)
->latest()
->first();
if ($query && $coupon) {
//优惠券核销成功
if ($coupon->status == 2) {
$res = Coupon::Reversal($coupon->redemptionCode, $this->outlet_id);
if ($res !== true) {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $res;
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '优惠券状态不对';
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '未查询到卡券信息。';
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '未查询到销账接口数据。';
}
} catch (\Exception $e) {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $e->getMessage();
}
}
public function back()
{
return $this->outdata;
}
}

View File

@@ -1,90 +0,0 @@
<?php
namespace XuanChen\Coupon\Action;
use XuanChen\UnionPay\Action\Destroy;
use XuanChen\UnionPay\Action\Query;
use XuanChen\UnionPay\Action\Verification;
use XuanChen\UnionPay\Contracts\CouponContracts;
/**
* Class 银联对接优惠券
* @Author : 玄尘
* @Date : 2020/9/28 14:02
* @package XuanChen\Coupon\Action
*/
class UnionPayAction 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();
}
}

View File

@@ -1,194 +0,0 @@
<?php
namespace XuanChen\UnionPay\Action;
use App\Events\ConponCallback;
use App\Models\ActivityCoupon;
use App\Models\Coupon;
use Illuminate\Support\Facades\DB;
class Verification
{
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();
}
}
}

View File

@@ -6,6 +6,9 @@ use App\Models\UnionpayLog;
use App\Models\User; use App\Models\User;
use XuanChen\UnionPay\Action\Init; use XuanChen\UnionPay\Action\Init;
use XuanChen\Coupon\Coupon; use XuanChen\Coupon\Coupon;
use XuanChen\UnionPay\Action\Query;
use XuanChen\UnionPay\Action\Redemption;
use XuanChen\UnionPay\Action\Reversal;
/** /**
* 银联入口 * 银联入口
@@ -71,69 +74,33 @@ class UnionPay extends Init
switch ($this->msg_txn_code) { switch ($this->msg_txn_code) {
//聚合营销优惠查询接口 //聚合营销优惠查询接口
case '002025': case '002025':
$res = Coupon::Query($this->params['mkt_code'], $this->outlet_id); $action = new Query();
if (is_array($res)) { $action->outlet_id = $this->outlet_id;
$this->outdata['pos_display'] = $res['name']; $action->params = $this->params;
$this->outdata['discount'] = $res['price'] * 100; $action->outdata = $this->outdata;
$this->outdata['actual_amt'] = (int)bcsub($this->params['amount'], $res['price'] * 100); $action->start();
} else { $this->outdata = $action->back();
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $res;
}
break; break;
//销账交易接口 //销账交易接口
case '002100': case '002100':
//查询聚合信息 $action = new Redemption();
$query = UnionpayLog::where('req_serial_no', $this->params['orig_req_serial_no']) $action->outlet_id = $this->outlet_id;
->where('msg_txn_code', '002025') $action->params = $this->params;
->latest() $action->outdata = $this->outdata;
->first(); $action->agent_id = $this->agent_id;
$action->start();
$this->outdata['orig_amt'] = $query->in_source['amount']; //订单金额 原始金额 $this->outdata = $action->back();
$this->outdata['discount_amt'] = $query->out_source['discount']; //折扣金额
$this->outdata['pay_amt'] = $query->out_source['actual_amt']; //折扣后金额
//获取银联渠道
$user = User::find($this->agent_id);
if ($query) {
$coupon = [];
$coupon = Coupon::Redemption($user, $query->mkt_code, $this->params['orig_amt'] / 100, $this->outlet_id, '');
if (!is_array($coupon)) {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $coupon;
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '未查询到前置接口,获取券码失败。';
}
break; break;
//冲正
case '002101': case '002101':
break; //撤销
case '002102': case '002102':
//查询聚合信息 $action = new Reversal();
$info = UnionpayLog::where('req_serial_no', $this->params['orig_req_serial_no']) $action->outlet_id = $this->outlet_id;
->where('msg_txn_code', '002025') $action->params = $this->params;
->latest() $action->outdata = $this->outdata;
->first(); $action->start();
$this->outdata = $action->back();
if ($info) {
if ($info->coupon) {
$ret = $info->coupon->reprofit();
if ($ret !== true) {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = $ret;
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '为查询到优惠券信息。';
}
} else {
$this->outdata['msg_rsp_code'] = '9999';
$this->outdata['msg_rsp_desc'] = '未查询到前置接口,获取券码失败。';
}
break; break;
default: default:
break; break;
@@ -202,6 +169,7 @@ class UnionPay extends Init
]; ];
switch ($this->msg_txn_code) { switch ($this->msg_txn_code) {
//查询
case '002025': case '002025':
$basics = array_merge($basics, [ $basics = array_merge($basics, [
"discount" => 0, "discount" => 0,
@@ -212,6 +180,7 @@ class UnionPay extends Init
"pos_mkt_ad" => config('unionpay.pos_receipt'), "pos_mkt_ad" => config('unionpay.pos_receipt'),
]); ]);
break; break;
//销账
case '002100': case '002100':
$basics = array_merge($basics, [ $basics = array_merge($basics, [
'msg_ver' => 0.1, 'msg_ver' => 0.1,
@@ -223,11 +192,12 @@ class UnionPay extends Init
'event_no' => '',//活动号 直接为空就可以 'event_no' => '',//活动号 直接为空就可以
]); ]);
break; break;
//冲正
case '002101': case '002101':
$basics = array_merge($basics, [ $basics = array_merge($basics, [
'msg_ver' => 0.1, 'msg_ver' => 0.1,
]); ]);
break; //撤销
case '002102': case '002102':
$basics = array_merge($basics, [ $basics = array_merge($basics, [
'msg_ver' => 0.1, 'msg_ver' => 0.1,