增加导入平安结算订单
This commit is contained in:
115
app/Admin/Actions/Coupon/SettleCoupon.php
Normal file
115
app/Admin/Actions/Coupon/SettleCoupon.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Coupon;
|
||||
|
||||
use App\Admin\Imports\SettleCouponImport;
|
||||
use Encore\Admin\Actions\Action;
|
||||
use Encore\Admin\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class SettleCoupon extends Action
|
||||
{
|
||||
public $name = '结算数据';
|
||||
|
||||
protected $selector = '.check-coupon';
|
||||
|
||||
public function handle(Request $request): \Encore\Admin\Actions\Response
|
||||
{
|
||||
try {
|
||||
Excel::import(new SettleCouponImport(), request()->file('file'));
|
||||
} catch (\Exception $exception) {
|
||||
return $this->response()->swal()->error($exception->getMessage());
|
||||
}
|
||||
|
||||
return $this->response()->swal()->success('上传成功')->refresh();
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$this->file('file', '请选择文件')
|
||||
->options([
|
||||
'showPreview' => false,
|
||||
'allowedFileExtensions' => ['xlsx', 'xls', 'csv'],
|
||||
'showUpload' => true,
|
||||
])
|
||||
->required();
|
||||
|
||||
}
|
||||
|
||||
public function html(): string
|
||||
{
|
||||
return <<<HTML
|
||||
<a class="btn btn-sm btn-default import-action check-coupon">导入已结算数据</a>
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传等待
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function handleActionPromise(): string
|
||||
{
|
||||
$resolve = <<<SCRIPT
|
||||
var actionResolverss = function (data) {
|
||||
$('.modal-footer').show()
|
||||
$('.tips').remove()
|
||||
var response = data[0];
|
||||
var target = data[1];
|
||||
|
||||
if (typeof response !== 'object') {
|
||||
return $.admin.swal({type: 'error', title: 'Oops!'});
|
||||
}
|
||||
|
||||
var then = function (then) {
|
||||
if (then.action == 'refresh') {
|
||||
$.admin.reload();
|
||||
}
|
||||
|
||||
if (then.action == 'download') {
|
||||
window.open(then.value, '_blank');
|
||||
}
|
||||
|
||||
if (then.action == 'redirect') {
|
||||
$.admin.redirect(then.value);
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof response.html === 'string') {
|
||||
target.html(response.html);
|
||||
}
|
||||
|
||||
if (typeof response.swal === 'object') {
|
||||
$.admin.swal(response.swal);
|
||||
}
|
||||
|
||||
if (typeof response.toastr === 'object') {
|
||||
$.admin.toastr[response.toastr.type](response.toastr.content, '', response.toastr.options);
|
||||
}
|
||||
|
||||
if (response.then) {
|
||||
then(response.then);
|
||||
}
|
||||
};
|
||||
|
||||
var actionCatcherss = function (request) {
|
||||
$('.modal-footer').show()
|
||||
$('.tips').remove()
|
||||
|
||||
if (request && typeof request.responseJSON === 'object') {
|
||||
$.admin.toastr.error(request.responseJSON.message, '', {positionClass:"toast-bottom-center", timeOut: 10000}).css("width","500px")
|
||||
}
|
||||
};
|
||||
SCRIPT;
|
||||
|
||||
Admin::script($resolve);
|
||||
|
||||
return <<<SCRIPT
|
||||
$('.modal-footer').hide()
|
||||
let html = `<div class='tips' style='color: red;font-size: 18px;'>导入时间取决于数据量,请耐心等待结果不要关闭窗口!<img src="data:image/gif;base64,R0lGODlhEAAQAPQAAP///1VVVfr6+np6eqysrFhYWG5ubuPj48TExGNjY6Ojo5iYmOzs7Lq6utjY2ISEhI6OjgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAAFUCAgjmRpnqUwFGwhKoRgqq2YFMaRGjWA8AbZiIBbjQQ8AmmFUJEQhQGJhaKOrCksgEla+KIkYvC6SJKQOISoNSYdeIk1ayA8ExTyeR3F749CACH5BAkKAAAALAAAAAAQABAAAAVoICCKR9KMaCoaxeCoqEAkRX3AwMHWxQIIjJSAZWgUEgzBwCBAEQpMwIDwY1FHgwJCtOW2UDWYIDyqNVVkUbYr6CK+o2eUMKgWrqKhj0FrEM8jQQALPFA3MAc8CQSAMA5ZBjgqDQmHIyEAIfkECQoAAAAsAAAAABAAEAAABWAgII4j85Ao2hRIKgrEUBQJLaSHMe8zgQo6Q8sxS7RIhILhBkgumCTZsXkACBC+0cwF2GoLLoFXREDcDlkAojBICRaFLDCOQtQKjmsQSubtDFU/NXcDBHwkaw1cKQ8MiyEAIfkECQoAAAAsAAAAABAAEAAABVIgII5kaZ6AIJQCMRTFQKiDQx4GrBfGa4uCnAEhQuRgPwCBtwK+kCNFgjh6QlFYgGO7baJ2CxIioSDpwqNggWCGDVVGphly3BkOpXDrKfNm/4AhACH5BAkKAAAALAAAAAAQABAAAAVgICCOZGmeqEAMRTEQwskYbV0Yx7kYSIzQhtgoBxCKBDQCIOcoLBimRiFhSABYU5gIgW01pLUBYkRItAYAqrlhYiwKjiWAcDMWY8QjsCf4DewiBzQ2N1AmKlgvgCiMjSQhACH5BAkKAAAALAAAAAAQABAAAAVfICCOZGmeqEgUxUAIpkA0AMKyxkEiSZEIsJqhYAg+boUFSTAkiBiNHks3sg1ILAfBiS10gyqCg0UaFBCkwy3RYKiIYMAC+RAxiQgYsJdAjw5DN2gILzEEZgVcKYuMJiEAOwAAAAAAAAAAAA=="><\/div>`
|
||||
$('.modal-header').append(html)
|
||||
process.then(actionResolverss).catch(actionCatcherss);
|
||||
SCRIPT;
|
||||
}
|
||||
}
|
||||
55
app/Admin/Controllers/Coupon/PaCouponController.php
Normal file
55
app/Admin/Controllers/Coupon/PaCouponController.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Coupon;
|
||||
|
||||
use App\Admin\Actions\Coupon\SettleCoupon;
|
||||
use App\Models\ActivityRule;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponPaCheck;
|
||||
use App\Models\User;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class PaCouponController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '未找到数据';
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
*
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2019/9/18 14:50
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new CouponPaCheck());
|
||||
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableBatchActions();
|
||||
$grid->disableActions();
|
||||
|
||||
|
||||
$grid->model()->latest();
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->equal('pa_order_id', '平安主订单号');
|
||||
});
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
|
||||
$grid->column('pa_order_id', '平安主订单号');
|
||||
|
||||
$grid->disableExport(false);
|
||||
|
||||
$grid->export(function ($export) {
|
||||
$export->filename($this->title.date("YmdHis"));
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
}
|
||||
148
app/Admin/Controllers/Coupon/SettleCouponController.php
Normal file
148
app/Admin/Controllers/Coupon/SettleCouponController.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Controllers\Coupon;
|
||||
|
||||
use App\Admin\Actions\Coupon\SettleCoupon;
|
||||
use App\Models\ActivityRule;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\User;
|
||||
use Encore\Admin\Controllers\AdminController;
|
||||
use Encore\Admin\Grid;
|
||||
|
||||
class SettleCouponController extends AdminController
|
||||
{
|
||||
|
||||
protected $title = '平安核销全列表';
|
||||
|
||||
/**
|
||||
* Notes:
|
||||
*
|
||||
* @Author: <C.Jason>
|
||||
* @Date : 2019/9/18 14:50
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid(): Grid
|
||||
{
|
||||
$grid = new Grid(new Coupon);
|
||||
|
||||
$grid->disableCreateButton();
|
||||
$grid->disableBatchActions();
|
||||
$grid->disableActions();
|
||||
|
||||
$grid->tools(function (Grid\Tools $tools) {
|
||||
$tools->append(new SettleCoupon());//上传等待校验数据
|
||||
});
|
||||
|
||||
$grid->model()
|
||||
->where('type', 1)
|
||||
->with(['outlet.province', 'outlet.city', 'outlet.district', 'user', 'user.info'])
|
||||
->whereIn('status', [2])
|
||||
->orderBy('id', 'desc');
|
||||
|
||||
$grid->filter(function ($filter) {
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->between('created_at', '核销时间')->datetime();
|
||||
$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'));
|
||||
$filter->like('couponName', '优惠政策名');
|
||||
});
|
||||
$filter->column(1 / 2, function ($filter) {
|
||||
$filter->like('redemptionCode', '卡券编号');
|
||||
$filter->where(function ($query) {
|
||||
$query->whereHas('outlet', function ($query) {
|
||||
$query->whereHas('info', function ($query) {
|
||||
$query->where('nickname', 'like', "%{$this->input}%");
|
||||
});
|
||||
});
|
||||
}, '网点名称');
|
||||
|
||||
$filter->like('pa_order_id', '平安主订单号');
|
||||
$filter->equal('is_settle', '是否结算')->select(Coupon::SETTLES);
|
||||
});
|
||||
});
|
||||
|
||||
$grid->column('id', '#ID#');
|
||||
$grid->column('渠道')->display(function () {
|
||||
return $this->user->nickname;
|
||||
});
|
||||
$grid->column('type', '类型')
|
||||
->using(Coupon::TYPES)
|
||||
->label([
|
||||
'1' => 'info',
|
||||
'2' => 'success',
|
||||
]);
|
||||
|
||||
$grid->column('网点名称/编号')->display(function () {
|
||||
return $this->outlet ? $this->outlet->nickname : $this->outletId;
|
||||
});
|
||||
|
||||
$grid->column('redemptionCode', '卡券编号');
|
||||
$grid->column('couponName', '优惠政策');
|
||||
$grid->column('price', '核销金额');
|
||||
$grid->column('total', '订单金额');
|
||||
$grid->column('orderid', '订单id');
|
||||
$grid->column('pa_order_id', '平安主订单号');
|
||||
$grid->column('pa_sub_order_id', '平安子订单号')->hide();
|
||||
$grid->column('is_settle', '是否结算')->bool();
|
||||
|
||||
$grid->column('资金通道结算')->display(function () {
|
||||
$profit = $this->status == 2 ? $this->profit : '0.00';
|
||||
|
||||
return '<span style="color:red">'.$profit.'</span>';
|
||||
});
|
||||
$grid->column('startTime', '起始时间')->hide();
|
||||
$grid->column('endTime', '到期时间')->hide();
|
||||
$grid->column('created_at', '核销时间');
|
||||
$grid->column('省')->display(function () {
|
||||
return ($this->outlet && $this->outlet->province) ? $this->outlet->province->name : '';
|
||||
});
|
||||
|
||||
$grid->column('市')->display(function () {
|
||||
return ($this->outlet && $this->outlet->province) ? $this->outlet->city->name : '';
|
||||
});
|
||||
|
||||
$grid->column('区')->display(function () {
|
||||
return ($this->outlet && $this->outlet->province) ? $this->outlet->district->name : '';
|
||||
});
|
||||
|
||||
$grid->footer(function ($query) {
|
||||
$total = $query->count();
|
||||
$success = $query->where('status', 2)->count();
|
||||
$faield = $total - $success;
|
||||
|
||||
return '<label class="label label-success">全部:'.$total.'张</label> '
|
||||
.'<label class="label label-success">成功:'.$success.'张</label> '
|
||||
.'<label class="label label-success">失败:'.$faield.'张</label> '
|
||||
.'<label class="label label-success">核销金额:'.$query->sum('price').'元</label> '
|
||||
.'<label class="label label-success">资金通道结算:'.$query->sum('profit').'元</label> '
|
||||
.'<label class="label label-success">打款金额:'.$query->where('is_profit', 1)
|
||||
->sum('profit').'元</label> ';
|
||||
});
|
||||
$grid->disableExport(false);
|
||||
|
||||
$grid->export(function ($export) {
|
||||
$export->column('type', function ($value, $original) {
|
||||
return strip_tags($value);
|
||||
});
|
||||
$export->column('redemptionCode', function ($value, $original) {
|
||||
return $value."\t";
|
||||
});
|
||||
|
||||
$export->column('orderid', function ($value, $original) {
|
||||
return $value."\t";
|
||||
});
|
||||
|
||||
$export->column('资金通道结算', function ($value, $original) {
|
||||
return strip_tags($value);
|
||||
});
|
||||
$export->filename($this->title.date("YmdHis"));
|
||||
});
|
||||
|
||||
return $grid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class IndexController extends AdminController
|
||||
* @Date : 2019/9/18 14:50
|
||||
* @return Grid
|
||||
*/
|
||||
protected function grid()
|
||||
protected function grid(): Grid
|
||||
{
|
||||
$user = Auth::guard('admin')->user();
|
||||
|
||||
|
||||
83
app/Admin/Imports/SettleCouponImport.php
Normal file
83
app/Admin/Imports/SettleCouponImport.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Admin\Imports;
|
||||
|
||||
use App\Models\Coupon;
|
||||
use App\Models\CouponPaCheck;
|
||||
use Maatwebsite\Excel\Concerns\Importable;
|
||||
use Maatwebsite\Excel\Concerns\SkipsErrors;
|
||||
use Maatwebsite\Excel\Concerns\ToModel;
|
||||
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
||||
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
||||
use Maatwebsite\Excel\Concerns\WithStartRow;
|
||||
|
||||
|
||||
class SettleCouponImport implements ToModel, WithStartRow, WithChunkReading, WithBatchInserts
|
||||
{
|
||||
|
||||
use Importable, SkipsErrors;
|
||||
|
||||
public $chunk = 5000;
|
||||
|
||||
/**
|
||||
* @param array $row
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function model(array $row)
|
||||
{
|
||||
try {
|
||||
$order_id = trim($row[0]);
|
||||
$exists = Coupon::query()->where('pa_order_id', $order_id)->exists();
|
||||
if (! $exists) {
|
||||
CouponPaCheck::create([
|
||||
'pa_order_id' => $order_id
|
||||
]);
|
||||
} else {
|
||||
Coupon::query()->where('pa_order_id', $order_id)->update([
|
||||
'is_settle' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 从第几行开始处理数据 就是不处理标题
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function startRow(): int
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 批量导入1000条
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/11/23 13:40
|
||||
* @return int
|
||||
*/
|
||||
public function chunkSize(): int
|
||||
{
|
||||
return $this->chunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 以1000条数据基准切割数据
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date : 2020/11/23 13:41
|
||||
* @return int
|
||||
*/
|
||||
public function batchSize(): int
|
||||
{
|
||||
return $this->chunk;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -37,6 +37,8 @@ Route::group([
|
||||
*/
|
||||
$router->resource('logs', 'Log\IndexController');
|
||||
$router->resource('coupons', 'Coupon\IndexController'); //平安卡券
|
||||
$router->resource('settle_coupons', 'Coupon\SettleCouponController'); //平安结算数据
|
||||
$router->resource('pa_coupons', 'Coupon\PaCouponController'); //平安未找到数据
|
||||
$router->resource('wos', 'Wo\IndexController'); //沃钱包业务
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user