导出
This commit is contained in:
parent
53cad92a23
commit
15592ed2bd
|
|
@ -48,55 +48,69 @@ class Auditorder extends Backend
|
||||||
/**
|
/**
|
||||||
* 查看
|
* 查看
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index($getArray = false, $page = 0, $input_limit = 0)
|
||||||
{
|
{
|
||||||
//当前是否为关联查询
|
//当前是否为关联查询
|
||||||
$this->relationSearch = true;
|
$this->relationSearch = true;
|
||||||
//设置过滤方法
|
//设置过滤方法
|
||||||
$this->request->filter(['strip_tags', 'trim']);
|
$this->request->filter(['strip_tags', 'trim']);
|
||||||
if ($this->request->isAjax()) {
|
|
||||||
//如果发送的来源是Selectpage,则转发到Selectpage
|
|
||||||
if ($this->request->request('keyField')) {
|
|
||||||
return $this->selectpage();
|
|
||||||
}
|
|
||||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
||||||
|
|
||||||
|
|
||||||
$list = $this->model
|
if (false === $this->request->isAjax() && $getArray == false) {
|
||||||
->scope('tab',Order::TAB_AUDIT)
|
$res = $this->getSource();
|
||||||
->alias('order')
|
$this->view->assign("sources", $res);
|
||||||
->with([
|
return $this->view->fetch();
|
||||||
'user' => function ($q) {
|
|
||||||
$q->field('id,nickname');
|
|
||||||
},'workerman','auditadmin' => function ($q) {
|
|
||||||
$q->field('id,nickname');
|
|
||||||
}, 'source' => [
|
|
||||||
'parent' => function ($q) {
|
|
||||||
$q->field('id,title');
|
|
||||||
}
|
|
||||||
]])
|
|
||||||
->where($where)
|
|
||||||
->order($sort, $order)
|
|
||||||
->paginate($limit);
|
|
||||||
|
|
||||||
foreach ($list as $item) {
|
|
||||||
if (isset($item->getRelation('source')->parent->title)){
|
|
||||||
$item->source_total_name = '【' . $item->getRelation('source')->parent->title . '】' . ($item->getRelation('source')->title??'');
|
|
||||||
}else{
|
|
||||||
$item->source_total_name = ($item->getRelation('source')->title??'');
|
|
||||||
}
|
|
||||||
unset($item->source);
|
|
||||||
}
|
|
||||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
|
||||||
|
|
||||||
return json($result);
|
|
||||||
}
|
}
|
||||||
$res = $this->getSource();
|
|
||||||
$this->view->assign("sources", $res);
|
|
||||||
return $this->view->fetch();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
//如果发送的来源是Selectpage,则转发到Selectpage
|
||||||
|
if ($this->request->request('keyField')) {
|
||||||
|
return $this->selectpage();
|
||||||
|
}
|
||||||
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||||
|
|
||||||
|
|
||||||
|
$build = $this->model
|
||||||
|
->scope('tab', Order::TAB_AUDIT)
|
||||||
|
->alias('order')
|
||||||
|
->with([
|
||||||
|
'user' => function ($q) {
|
||||||
|
$q->field('id,nickname');
|
||||||
|
}, 'workerman', 'auditadmin' => function ($q) {
|
||||||
|
$q->field('id,nickname');
|
||||||
|
}, 'source' => [
|
||||||
|
'parent' => function ($q) {
|
||||||
|
$q->field('id,title');
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
->where($where)
|
||||||
|
->order($sort, $order);
|
||||||
|
|
||||||
|
|
||||||
|
if ($getArray) {
|
||||||
|
$list = $build->paginate([
|
||||||
|
'list_rows' => $input_limit,
|
||||||
|
'page' => $page
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$list = $build->paginate($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($list as $item) {
|
||||||
|
if (isset($item->getRelation('source')->parent->title)) {
|
||||||
|
$item->source_total_name = '【' . $item->getRelation('source')->parent->title . '】' . ($item->getRelation('source')->title ?? '');
|
||||||
|
} else {
|
||||||
|
$item->source_total_name = ($item->getRelation('source')->title ?? '');
|
||||||
|
}
|
||||||
|
unset($item->source);
|
||||||
|
}
|
||||||
|
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||||
|
|
||||||
|
return json($result);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
|
|
@ -108,12 +122,12 @@ class Auditorder extends Backend
|
||||||
*/
|
*/
|
||||||
public function edit($ids = null)
|
public function edit($ids = null)
|
||||||
{
|
{
|
||||||
$row = $this->model->get($ids,['dispatch']);
|
$row = $this->model->get($ids, ['dispatch']);
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
$this->error(__('No Results were found'));
|
$this->error(__('No Results were found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($row ->status != Order::STATUS_AUDITING){
|
if ($row->status != Order::STATUS_AUDITING) {
|
||||||
$this->error('订单状态不可审核');
|
$this->error('订单状态不可审核');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,10 +136,10 @@ class Auditorder extends Backend
|
||||||
$this->error(__('You have no permission'));
|
$this->error(__('You have no permission'));
|
||||||
}
|
}
|
||||||
if (false === $this->request->isPost()) {
|
if (false === $this->request->isPost()) {
|
||||||
$order = Order::where('id',$ids)->find();
|
$order = Order::where('id', $ids)->find();
|
||||||
$this->view->assign('row', $row);
|
$this->view->assign('row', $row);
|
||||||
$worker = Worker::withTrashed()->where('id', $order->worker_id)->find();
|
$worker = Worker::withTrashed()->where('id', $order->worker_id)->find();
|
||||||
$this->view->assign('worker',$worker);
|
$this->view->assign('worker', $worker);
|
||||||
$this->view->assign('cdnurl', config('upload.cdnurl'));
|
$this->view->assign('cdnurl', config('upload.cdnurl'));
|
||||||
return $this->view->fetch();
|
return $this->view->fetch();
|
||||||
}
|
}
|
||||||
|
|
@ -148,9 +162,9 @@ class Auditorder extends Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
$txt = '审核通过';
|
$txt = '审核通过';
|
||||||
if($audit_status){
|
if ($audit_status) {
|
||||||
$params['status'] = Order::STATUS_FINISHED;
|
$params['status'] = Order::STATUS_FINISHED;
|
||||||
}else{
|
} else {
|
||||||
$params['status'] = Order::STATUS_CHECKONCE;
|
$params['status'] = Order::STATUS_CHECKONCE;
|
||||||
$txt = '审核未通过';
|
$txt = '审核未通过';
|
||||||
}
|
}
|
||||||
|
|
@ -163,16 +177,16 @@ class Auditorder extends Backend
|
||||||
$hookParams['order'] = $row;
|
$hookParams['order'] = $row;
|
||||||
$hookParams['role'] = 1;
|
$hookParams['role'] = 1;
|
||||||
$hookParams['auth'] = $this->auth;
|
$hookParams['auth'] = $this->auth;
|
||||||
$hookParams['remark'] = $txt.',审核备注:'.$params['audit_remark'];
|
$hookParams['remark'] = $txt . ',审核备注:' . $params['audit_remark'];
|
||||||
Hook::listen('order_change',$hookParams);
|
Hook::listen('order_change', $hookParams);
|
||||||
|
|
||||||
if($params['status'] == Order::STATUS_CHECKONCE){
|
if ($params['status'] == Order::STATUS_CHECKONCE) {
|
||||||
//未通过审核,通知派单员,重新配置
|
//未通过审核,通知派单员,重新配置
|
||||||
Message::create([
|
Message::create([
|
||||||
'to_id' => $row->dispatch_admin_id,
|
'to_id' => $row->dispatch_admin_id,
|
||||||
'type' => 1,
|
'type' => 1,
|
||||||
'title' => '订单结算审核未通过',
|
'title' => '订单结算审核未通过',
|
||||||
'content' => '【订单结算未通过】订单编号:'.$row->order_no.',审核备注:'.$params['audit_remark'].',审核人:'.$this->auth->nickname
|
'content' => '【订单结算未通过】订单编号:' . $row->order_no . ',审核备注:' . $params['audit_remark'] . ',审核人:' . $this->auth->nickname
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,4 +202,42 @@ class Auditorder extends Backend
|
||||||
$this->success();
|
$this->success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function export()
|
||||||
|
{
|
||||||
|
$columns = json_decode($this->request->get('columns', ''), true);
|
||||||
|
if (!$columns) {
|
||||||
|
$sample = $this->index(true, 1, 1)->getData();
|
||||||
|
|
||||||
|
if (!isset($sample['rows'][0])) {
|
||||||
|
return json(['code' => 0, 'msg' => '无数据可导出']);
|
||||||
|
}
|
||||||
|
$columns = [];
|
||||||
|
foreach ($sample['rows'][0] as $key => $value) {
|
||||||
|
$columns[] = ['field' => $key, 'title' => $key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$generator = function () use ($columns) {
|
||||||
|
$limit = 1000;
|
||||||
|
$page = 1;
|
||||||
|
$order = new \app\admin\model\Order();
|
||||||
|
do {
|
||||||
|
$result = $this->index(true, $page, $limit);
|
||||||
|
$rows = $result->getData()['rows'] ?? [];
|
||||||
|
if (!$rows) break;
|
||||||
|
|
||||||
|
foreach ($rows as $item) {
|
||||||
|
$item->status = $order->getStatusList()[$item->status] ?? '';
|
||||||
|
$item->amount_images = $this->dealImages($item->amount_images);
|
||||||
|
$item->workerman->images = $this->dealImages($item->workerman->images);
|
||||||
|
yield $item->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
$page++;
|
||||||
|
} while (count($rows) === $limit);
|
||||||
|
};
|
||||||
|
|
||||||
|
$this->streamCsv($columns, $generator(), '订单导出_' . date('Ymd_His') . '.csv');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@
|
||||||
<div class="widget-body no-padding">
|
<div class="widget-body no-padding">
|
||||||
<div id="toolbar" class="toolbar">
|
<div id="toolbar" class="toolbar">
|
||||||
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
|
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
|
||||||
|
<a href="javascript:;" class="btn btn-success btn-export" id="btn-export">
|
||||||
|
<i class="fa fa-download"></i> 导出
|
||||||
|
</a>
|
||||||
<!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('orders/auditorder/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
|
<!-- <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('orders/auditorder/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
|
||||||
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('orders/auditorder/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
|
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('orders/auditorder/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
|
||||||
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('orders/auditorder/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
|
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('orders/auditorder/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
|
||||||
|
|
|
||||||
|
|
@ -784,7 +784,6 @@ class Backend extends Controller
|
||||||
|
|
||||||
$fields = array_column($columns, 'field');
|
$fields = array_column($columns, 'field');
|
||||||
$titles = array_column($columns, 'title');
|
$titles = array_column($columns, 'title');
|
||||||
|
|
||||||
// 写入表头
|
// 写入表头
|
||||||
fputcsv($output, $titles);
|
fputcsv($output, $titles);
|
||||||
|
|
||||||
|
|
@ -818,4 +817,18 @@ class Backend extends Controller
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function dealImages($image_str)
|
||||||
|
{
|
||||||
|
if (empty($image_str)){
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$images = explode(',', $image_str);
|
||||||
|
$url = '';
|
||||||
|
foreach ($images as $img) {
|
||||||
|
if (empty($img)) continue;
|
||||||
|
$url .= cdnurl($img) . ',';
|
||||||
|
}
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||||
sortOrder: 'desc',
|
sortOrder: 'desc',
|
||||||
fixedColumns: true,
|
fixedColumns: true,
|
||||||
fixedRightNumber: 1,
|
fixedRightNumber: 1,
|
||||||
|
showExport: false,
|
||||||
columns: [
|
columns: [
|
||||||
[
|
[
|
||||||
// {checkbox: true},
|
// {checkbox: true},
|
||||||
|
|
@ -132,6 +133,31 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#btn-export').on('click', function () {
|
||||||
|
var options = $("#table").bootstrapTable('getOptions');
|
||||||
|
|
||||||
|
// 提取列信息(不含 checkbox)
|
||||||
|
var columns = [];
|
||||||
|
$.each(options.columns[0], function (i, item) {
|
||||||
|
if (item.field && !item.checkbox && !item.visible === false) {
|
||||||
|
columns.push({
|
||||||
|
field: item.field,
|
||||||
|
title: item.title
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var params = {
|
||||||
|
columns: JSON.stringify(columns),
|
||||||
|
filter: options.queryParams({}).filter || {},
|
||||||
|
op: options.queryParams({}).op || {},
|
||||||
|
sort: options.sortName,
|
||||||
|
order: options.sortOrder
|
||||||
|
};
|
||||||
|
// console.log($.param(params))
|
||||||
|
var url = '/admin/orders/auditorder/export?' + $.param(params);
|
||||||
|
window.open(url); // 发起文件下载
|
||||||
|
});
|
||||||
// 为表格绑定事件
|
// 为表格绑定事件
|
||||||
Table.api.bindevent(table);
|
Table.api.bindevent(table);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user