阶段性提交代码

This commit is contained in:
2020-10-10 14:57:22 +08:00
parent c909b9b1ed
commit 7cfd45bf99
14 changed files with 540 additions and 211 deletions

View File

@@ -41,7 +41,7 @@ class IndexController extends AdminController
$users = User::whereHas('identity', function ($query) {
$query->where('identity_id', 1);
})->get()->pluck('nickname', 'id');
$filter->equal('user_id', '渠道')->select($users);
$filter->equal('thirdPartyGoodsId', '优惠政策')->select(ActivityRule::pluck('title', 'code'));
});

View File

@@ -0,0 +1,94 @@
<?php
namespace App\Admin\Controllers\Unionpay;
use App\Admin\Actions\User\Callback;
use App\Admin\Actions\User\Profit;
use App\Admin\Actions\User\ReCode;
use App\Admin\Actions\User\RefD3Key;
use App\Admin\Exporters\UsersExport;
use App\Models\Area;
use App\Models\UnionpayLog;
use App\Models\User;
use Auth;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Table;
use Illuminate\Http\Request;
use RuLong\Identity\Models\Identity;
class IndexController extends AdminController
{
protected $title = '银联操作日志';
/**
* Notes:
* @Author: <C.Jason>
* @Date : 2019/9/18 14:50
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new UnionpayLog);
$grid->disableActions();
$grid->model()->orderBy('id', 'desc');
$grid->filter(function ($filter) {
$filter->column(1 / 2, function ($filter) {
$filter->equal('msg_txn_code', '交易类型')->select(config('unionpay.type'));
});
});
$grid->column('id', '#ID#');
$grid->column('msg_txn_code', '交易类型')
->using(config('unionpay.type'))
->label();
$grid->column('msg_crrltn_id', '消息关联号');
$grid->column('msg_time', '报文日期');
$grid->column('mkt_code', '券码');
$grid->column('msg_sys_sn', '平台流水号');
$grid->column('req_serial_no', '查询流水号');
// $grid->column('请求参数')->display(function ($title, $column) {
// return '点击展开';
// })->modal(function ($model) {
// $in_source = $this->in_source;
// if (is_array($in_source) && count($in_source) > 1) {
// foreach ($in_source as $key => $item) {
// dump($this->id);
// $title[] = $key;
// $data[] = $item;
// }
//
// return new Table($title, $data);
// }
// });
$grid->column('请求参数')->display(function () {
$in_source = $this->in_source;
return $in_source;
})->hide();
$grid->column('返回信息')->display(function () {
$out_source = $this->out_source;
return $out_source;
})->hide();
$grid->column('created_at', '注册时间');
$grid->disableExport(false);
$grid->export(function ($export) {
$export->filename($this->title . date("YmdHis"));
});
return $grid;
}
}

View File

@@ -55,4 +55,7 @@ Route::group([
$router->resource('activitycoupons', 'Activity\CouponController');
$router->resource('activitycouponlogs', 'Activity\LogController');
//银联日志
$router->resource('unionpays', 'Unionpay\IndexController');
});

View File

@@ -1,54 +1,98 @@
<?php
namespace App\Api\Controllers;
use Illuminate\Http\Request;
use XuanChen\UnionPay\UnionPay;
use Response;
class UnionPayController extends Controller
{
public function index()
{
$user_ext_info = [
'mobile_no' => '15663876870',
'user_code' => '1',
'user_code_type' => '8521475DDDeeee',
'dev_id' => '1',
];
dd(json_encode($user_ext_info));
$str = 'msg_type=00&msg_txn_code=002100&msg_crrltn_id=12345678901234567890123456789000&msg_flg=0&msg_sender=01&msg_time=20130318162412&msg_sys_sn=12345678900987654321&msg_ver=0.1&mchnt_no=8981231234567890&term_no=12345678&shop_no=086123456123456789&req_serial_no=12345678900987654321&orig_req_serial_no=12345678900987654321&enc_card_no=123123123123123123123sdfadqerqr&acq_term_sn=123456&refer_no=123456789012&sett_date=20130318&txn_date=20130318&txn_time=162850&orig_amt=10000&discount_amt=2000&pay_amt=8000&pay_mode=1';
parse_str($str, $arr_str);
$action = new UnionPay($arr_str);
$sign = $action->getSign();
$action->sign = $sign;
$res = $action->checkSign(true);
dump($sign);
dump($res);
}
/**
* Notes: 银联接口
* @Author: 玄尘
* @Date : 2020/9/28 16:31
* @param Request $request
* @return mixed
*/
public function query(Request $request)
{
$inputs = $request->all();
$sign = $inputs['sign'];
unset($inputs['sign']);
$action = new UnionPay($inputs, $sign);
$action->start();
$action->updateOutData();
return $action->respond();
}
}
<?php
namespace App\Api\Controllers;
use App\Exceptions\ApiException;
use Illuminate\Http\Request;
use XuanChen\UnionPay\UnionPay;
class UnionPayController extends Controller
{
public function index(Request $request)
{
$action = new UnionPay($request->all());
// $sign = $action->getSign(false);
$sign = 'd8e5bf46d0d9f1da702170c2e141d85cf3ca785106886dbfedb3310ee9ce2ca3f18a2e6c179ec9908fc4f41d05df463634106918bdbefc63b8f199c7d2f3b0d45510b4dd6ccdf4549e11a8551a5098b14c01fdaa5840a4608f462fdafdc14b8f2a35471da315d8245a4ef6281b6e04bd22d5a266500a6caf6e5203202c37111d';
$action->sign = $sign;
$res = $action->checkSign(false, false);
dump('签名: ' . $sign);
$res_str = ($res === true) ? '成功' : '失败';
dump('验签结果:' . $res_str);
dd($action);
}
//签名
public function toSign($sign_data)
{
//签名字段
// $sign_data['msg_type'] = $array['msg_type'];
// $sign_data['msg_txn_code'] = $array['msg_txn_code'];
// $sign_data['msg_crrltn_id'] = $array['msg_crrltn_id'];
// $sign_data['msg_flg'] = $array['msg_flg'];
// $sign_data['msg_sender'] = $array['msg_sender'];
// $sign_data['msg_time'] = $array['msg_time'];
// $sign_data['msg_sys_sn'] = $array['msg_sys_sn'];
// $sign_data['msg_ver'] = $array['msg_ver'];
// if (isset($array['msg_rsp_code'])) {
// $sign_data['msg_rsp_code'] = $array['msg_rsp_code'];
// }
// if (isset($array['msg_rsp_desc'])) {
// $sign_data['msg_rsp_desc'] = $array['msg_rsp_desc'];
// }
//将字段名按字母表顺序排序
ksort($sign_data);
//将post的数据utf-8编码
$str_data = utf8_encode(http_build_query($sign_data));
//获取私钥资源ID
$private = config('unionpay.check.self.private');
if (!file_exists($private)) {
throw new \Exception('缺少私钥文件');
}
$private_key = file_get_contents($private);
$pkeyid = openssl_get_privatekey($private_key);
//签名赋值sign
if (openssl_sign($str_data, $sign, $pkeyid)) {
$sign_data = bin2hex($sign);
} else {
$sign_data = '';
}
//释放ssl资源
openssl_free_key($pkeyid);
return $sign_data;
}
/**
* Notes: 银联接口
* @Author: 玄尘
* @Date : 2020/9/28 16:31
* @param Request $request
* @return mixed
*/
public function query(Request $request)
{
$inputs = $request->all();
$sign = $inputs['sign'];
unset($inputs['sign']);
$action = new UnionPay($inputs, $sign);
// $action->addLog();
$action->start();
// $action->updateLog();
return $action->respond();
}
}

View File

@@ -0,0 +1,45 @@
<?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

@@ -7,18 +7,17 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
ApiException::class,
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
@@ -28,24 +27,24 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* @param \Exception $exception
* @param \Exception $exception
* @return void
*/
public function report(Exception $exception)
{
info($exception->getMessage());
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @param \Illuminate\Http\Request $request
* @param \Exception $exception
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}

View File

@@ -88,6 +88,24 @@ class Coupon extends Model
}
}
/**
* Notes: 撤销分润
* @Author: 玄尘
* @Date : 2020/10/9 14:07
*/
public function reprofit()
{
if ($this->profit > 1) {
return $this->user->account->rule('refreeze', -$this->profit, false, [
'coupon_id' => $this->id,
'redemptionCode' => $this->redemptionCode,
]);
} else {
return '不需要操作';
}
}
/**
* 打款
* @author 玄尘 2020-03-13

View File

@@ -10,4 +10,9 @@ class UnionpayLog extends Model
'out_source' => 'array',
];
public function coupon()
{
return $this->hasOne(Coupon::class, 'redemptionCode', 'mkt_code');
}
}