1、\app\adminapi\controller\v1\export\ExportExcel.php
use app\services\water\OrderServices;
public function waterOrder(OrderServices $services)
{
$where = $this->request->getMore([
['status', ''],
['real_name', ''],
['data', '', '', 'time'],
['field_key', ''],
]);
$data = $services->searchList($where, true, false);
return app('json')->success($this->service->waterOrder($data['list'] ?? []));
}
2、\app\adminapi\route\export.php
Route::get('waterOrder', 'v1.export.ExportExcel/waterOrder')->option(['real_name' => '提水订单导出']);
3、\app\dao\water\WaterOrderDao.php
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'], $with=[])
{
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return $this->search($where)->field($field)->with(array_merge(['user'], $with))->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
$query->page($page, $limit);
})
->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($where, $realName, $fieldKey) {
$query->whereLike(trim($fieldKey), '%' . trim($realName) . '%');
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->whereLike('order_id|real_name', '%' . $where['real_name'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
});
})
->when(!$page && $limit, function ($query) use ($limit) {
$query->page($limit);
})->order('add_time DESC,id DESC')->select()->toArray();
}
public function getCount(array $where)
{
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
return $this->search($where)->with(['user'])
->when($realName && $fieldKey && in_array($fieldKey, $this->withField), function ($query) use ($where, $realName, $fieldKey) {
$query->whereLike(trim($fieldKey), '%' . trim($realName) . '%');
})->when($realName && !$fieldKey, function ($query) use ($where) {
$query->whereLike('order_id|real_name', '%' . $where['real_name'] . '%')->whereOr('uid', 'in', function ($q) use ($where) {
$q->name('user')->whereLike('nickname|uid|phone', '%' . $where['real_name'] . '%')->field(['uid'])->select();
});
})->count();
}
4、\app\services\export\ExportServices.php
public function waterOrder($data = [])
{
$export = [];
if (!empty($data)) {
foreach ($data as $index => $item) {
$export[] = [
$item['id'],
$item['nickname'],
$item['total_num'],
$item['real_name'],
$item['user_phone'],
$item['user_address'],
$item['status']==1?'已完成':'待发货',
$item['delivery_name'],
$item['delivery_id'],
$item['add_time'],
];
}
}
$header = ['', 'id', '用户昵称', '提水数量', '收货人姓名', '收货人电话', '收货地址', '状态', '快递公司', '快递单号', '创建时间'];
$title = ['提水订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())];
$filename = '提水订单导出_' . date('YmdHis', time());
$suffix = 'xlsx';
$is_save = true;
return $this->export($header, $title, $export, $filename, $suffix, $is_save);
}
5、\app\services\water\OrderServices.php
use think\facade\Config;
public function searchList(array $where, bool $isStock = false, $is_page = true)
{
$data = $this->getProductList($where, $isStock, $is_page);
foreach ($data['list'] as &$item) {
}
return $data;
}
public function getProductList(array $where, bool $isStock = true, $is_page = true)
{
$prefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
if ($isStock) {
$field = [
'*',
];
} else {
$field = ['*'];
}
[$page, $limit] = $this->getPageValue($is_page);
$list = $this->dao->getSearchList($where, $page, $limit, $field);
$count = $this->dao->getCount($where);
return compact('count', 'list');
}
\src\api\water.js
export function orderExportApi (data) {
return request({
url: `export/waterOrder`,
method: 'get',
params: data
})
}
\src\pages\water\order\index.vue
<Row type="flex">
<Col v-bind="grid">
<Button
v-auth="['export-storeProduct']"
class="export"
icon="ios-share-outline"
@click="exports"
>导出</Button
>
</Col>
</Row>
import { orderListApi, setShowApi, treeListApi, deliveryApi, orderExportApi } from '@/api/water'
exports() {
let formValidate = this.artFrom;
let data = {
status: formValidate.status,
real_name: formValidate.real_name,
data: formValidate.data,
field_key: formValidate.field_key,
};
orderExportApi(data).then((res) => {
this.$Message.success(res.msg);
location.href = res.data[0];
}).catch((res) => {
this.$Message.error(res.msg);
});
},
|