1、\app\adminapi\controller\v1\export\ExportExcel.php
use app\services\water\OrderServices;
/**
* 提水订单导出
* @param StoreProductServices $services
* @return mixed
*/
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
/**
* 条件获取商品列表
* @param array $where
* @param int $page
* @param int $limit
* @param array|string[] $field
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'], $with=[])
{
// return [];
$realName = $where['real_name'] ?? '';
$fieldKey = $where['field_key'] ?? '';
$fieldKey = $fieldKey == 'all' ? '' : $fieldKey;
// var_dump($where);die("444444444444444444");
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();
}
/**
* 条件获取数量
* @param array $where
* @return int
*/
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
/**
* 提水订单导出
* @param $data 导出数据
*/
public function waterOrder($data = [])
{
$export = [];
if (!empty($data)) {
foreach ($data as $index => $item) {
$export[] = [
$item['id'],
// $item['nickname'].' | '.$item['use_uid'],
$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;
/**
* 获取选择的商品列表
* @param array $where
* @return array
*/
public function searchList(array $where, bool $isStock = false, $is_page = true)
{
// $store_stock = sys_config('store_stock');
// $where['store_stock'] = $store_stock > 0 ? $store_stock : 2;
$data = $this->getProductList($where, $isStock, $is_page);
foreach ($data['list'] as &$item) {
// $item['cate_name'] = implode(',', array_column($cateName, 'cate_name'));
// $item['give_integral'] = floatval($item['give_integral']);
// $item['price'] = floatval($item['price']);
// $item['vip_price'] = floatval($item['vip_price']);
// $item['ot_price'] = floatval($item['ot_price']);
// $item['postage'] = floatval($item['postage']);
// $item['cost'] = floatval($item['cost']);
// $item['is_product_type'] = 1;
}
// var_dump($data);die("3333333333333333333333");
return $data;
}
/**
* 后台获取商品列表展示
* @param array $where
* @return array
*/
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);
// var_dump($list);die("444444444444444444");
return compact('count', 'list');
}
\src\api\water.js
/**
* @description 商铺产品 -- 导出
*/
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);
});
},