导入导出
This commit is contained in:
parent
152a11b6cf
commit
c56eff0610
@ -26,6 +26,7 @@ abstract class AbstractExport implements WithEvents, WithTitle, ShouldAutoSize
|
||||
\App\Domains\Virtual\Exports\FlowPoolExportDetailExport::class => '流量池明细',
|
||||
\App\Domains\Virtual\Exports\OrderCardExport::class => '订单卡清单',
|
||||
\App\Domains\Virtual\Exports\OrderExport::class => '订单导出',
|
||||
\App\Domains\Virtual\Exports\PropertyExport::class => '属性导出',
|
||||
\App\Domains\Stats\Exports\CompanyCountExport::class => '企业统计',
|
||||
\App\Domains\Stats\Exports\OrderExport::class => '订单统计',
|
||||
\App\Domains\Stats\Exports\OrderDetailExport::class => '订单明细',
|
||||
|
108
app/Domains/Virtual/Exports/PropertyExport.php
Normal file
108
app/Domains/Virtual/Exports/PropertyExport.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Virtual\Exports;
|
||||
|
||||
use App\Core\AbstractExport;
|
||||
use Dipper\Excel\Concerns\WithRows;
|
||||
use Dipper\Excel\Concerns\WithHeadings;
|
||||
use Dipper\Excel\Concerns\FromCollection;
|
||||
use Dipper\Excel\Concerns\WithColumnFormatting;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
use App\Domains\Virtual\Services\PropertyService;
|
||||
use App\Domains\Virtual\Repositories\PropertySettingRepository;
|
||||
|
||||
class PropertyExport extends AbstractExport implements FromCollection, WithHeadings, WithRows, WithColumnFormatting
|
||||
{
|
||||
public $conditions;
|
||||
public $settings;
|
||||
|
||||
public function __construct(array $conditions = [])
|
||||
{
|
||||
$this->conditions = $conditions;
|
||||
$this->settings = app(PropertySettingRepository::class)->getAll();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
return app(PropertyService::class)->index($this->conditions);
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
$provinces = $this->settings['province'];
|
||||
|
||||
$headings = [
|
||||
'*企业ID',
|
||||
'企业名称',
|
||||
'*套餐ID',
|
||||
'套餐名称',
|
||||
'月流量',
|
||||
'销售数量',
|
||||
'*公司类型',
|
||||
'*产品类型',
|
||||
'套餐类型',
|
||||
'平台/API',
|
||||
'*车辆类型',
|
||||
'商用车分类',
|
||||
'*客户类型',
|
||||
];
|
||||
|
||||
foreach ($provinces as $province) {
|
||||
array_push($headings, $province);
|
||||
}
|
||||
|
||||
return $headings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $row
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function rows($rows)
|
||||
{
|
||||
$provinces = $this->settings['province'];
|
||||
|
||||
$array = [];
|
||||
|
||||
foreach ($rows as $key => $value) {
|
||||
$item = [
|
||||
$value['company_id'],
|
||||
$value['company_name'],
|
||||
$value['package_id'],
|
||||
$value['package_name'],
|
||||
strval($value['flows'] ?: 0),
|
||||
strval($value['counts']),
|
||||
$value['company'],
|
||||
$value['product'],
|
||||
$value['package'],
|
||||
$value['platform'],
|
||||
$value['vehicle'],
|
||||
$value['commercial_vehicle'],
|
||||
$value['customer'],
|
||||
];
|
||||
|
||||
foreach ($provinces as $province) {
|
||||
$item[$province] = strval($value['province'][$province] ?: 0);
|
||||
}
|
||||
|
||||
$array[] = $item;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'A' => NumberFormat::FORMAT_NUMBER,
|
||||
'C' => NumberFormat::FORMAT_NUMBER,
|
||||
'E' => NumberFormat::FORMAT_NUMBER,
|
||||
'F' => NumberFormat::FORMAT_NUMBER,
|
||||
];
|
||||
}
|
||||
}
|
@ -3,7 +3,12 @@ namespace App\Domains\Virtual\Http\Controllers;
|
||||
|
||||
use App\Core\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domains\Export\Services\ExportService;
|
||||
use App\Domains\Export\Services\ImportService;
|
||||
use App\Domains\Virtual\Exports\PropertyExport;
|
||||
use App\Domains\Virtual\Services\PropertyService;
|
||||
use App\Domains\Virtual\Repositories\PropertySettingRepository;
|
||||
use App\Exceptions\InvalidArgumentException;
|
||||
|
||||
class PropertyController extends Controller
|
||||
{
|
||||
@ -68,7 +73,16 @@ class PropertyController extends Controller
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
//
|
||||
$conditions = $this->request->all();
|
||||
|
||||
try {
|
||||
$export = new PropertyExport($conditions);
|
||||
$url = ExportService::store($export, 'public');
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return res($url, '导出成功', 201);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,6 +92,67 @@ class PropertyController extends Controller
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
//
|
||||
$file = $this->request->file('file');
|
||||
|
||||
$settings = app(PropertySettingRepository::class)->getAll();
|
||||
$provinces = $settings['province'];
|
||||
|
||||
$data = ImportService::load($file);
|
||||
|
||||
$array = [];
|
||||
|
||||
$errors = [];
|
||||
|
||||
$columns = [
|
||||
'company_id',
|
||||
'package_id',
|
||||
'product',
|
||||
'vehicle',
|
||||
'company',
|
||||
'customer',
|
||||
];
|
||||
|
||||
foreach ($data as $i => $item) {
|
||||
$row = $i + 1;
|
||||
|
||||
foreach ($item as $v => $value) {
|
||||
if (strpos($v, '*') !== false) {
|
||||
$item[trim($v, '*')] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($item['企业id']) || empty($item['套餐id'])) {
|
||||
throw new InvalidArgumentException("行 {$row} #:无效行");
|
||||
}
|
||||
|
||||
$value = [
|
||||
'company_id' => $item['企业id'],
|
||||
'package_id' => $item['套餐id'],
|
||||
'product' => $item['产品类型'],
|
||||
'vehicle' => $item['车辆类型'],
|
||||
'commercial_vehicle' => $item['商用车分类'],
|
||||
'company' => $item['公司类型'],
|
||||
'platform' => $item['平台/api'],
|
||||
'customer' => $item['客户类型'],
|
||||
];
|
||||
|
||||
foreach ($provinces as $province) {
|
||||
$value['province'][$province] = !empty($item[$province]) ? $item[$province] : 0;
|
||||
$value['province'][$province] = sprintf("%.2f", $value['province'][$province]);
|
||||
}
|
||||
|
||||
foreach ($columns as $column) {
|
||||
if (empty($value[$column])) {
|
||||
$filed = PropertyService::$property_types[$column];
|
||||
throw new InvalidArgumentException("行 {$row} #:字段 {$filed} 不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
$array[] = $value;
|
||||
}
|
||||
|
||||
$this->propertyService->store($array);
|
||||
|
||||
return res(null, '导入成功');
|
||||
}
|
||||
}
|
||||
|
@ -103,11 +103,6 @@ class PropertyService extends Service
|
||||
{
|
||||
$settings = $this->propertySettingRepository->getAll();
|
||||
|
||||
if (isset($values['product'])) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
if (!in_array($key, array_keys(self::$property_types))) {
|
||||
throw new NotExistException("分类{$key}不存在");
|
||||
|
@ -155,7 +155,8 @@ class PermissionSeeder extends Seeder
|
||||
'children' => [
|
||||
['name' => 'virtual.properties.create', 'title' => '设置', 'description' => 'create', 'type' => 1],
|
||||
['name' => 'virtual.properties.update', 'title' => '修改', 'description' => 'update', 'type' => 1],
|
||||
['name' => 'virtual.properties.output', 'title' => '导出', 'description' => 'output', 'type' => 1],
|
||||
['name' => 'virtual.properties.export', 'title' => '导出', 'description' => 'output', 'type' => 1],
|
||||
['name' => 'virtual.properties.import', 'title' => '导入', 'description' => 'input', 'type' => 1],
|
||||
],
|
||||
],
|
||||
],
|
||||
|
@ -58,6 +58,16 @@ export function exportExcel(data) {
|
||||
* @param {[type]} data [description]
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
export function importExcel(data) {
|
||||
return service.post('api/virtual/properties/import', data);
|
||||
export function importExcel(file) {
|
||||
let config = {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
};
|
||||
|
||||
let params = new FormData();
|
||||
|
||||
params.append('file', file);
|
||||
|
||||
return service.post('api/virtual/properties/import', params, config);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</li>
|
||||
<li class="f-r">
|
||||
<div class="handle-item lh-32">
|
||||
<div class="handle-item lh-32" v-has="'update'">
|
||||
<b class="umar-r10">编辑模式</b>
|
||||
<Switch v-model="editModel" size="large">
|
||||
<span slot="open">开</span>
|
||||
@ -37,7 +37,7 @@
|
||||
</div>
|
||||
|
||||
<div class="handle-item">
|
||||
<Button @click="index(1)" icon="md-refresh">刷新</Button>
|
||||
<Button @click="request()" icon="md-refresh">刷新</Button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@ -59,12 +59,22 @@
|
||||
<Option
|
||||
:key="index"
|
||||
:value="item.id"
|
||||
v-for="(item, index) in companies"
|
||||
v-for="(item, index) in packages"
|
||||
>{{ item.name }}</Option>
|
||||
</Select>
|
||||
</li>
|
||||
|
||||
<li class="f-r">
|
||||
<div class="handle-item">
|
||||
<Upload :before-upload="importExcel" action="/" :format="['xls','xlsx','csv']">
|
||||
<Button type="warning">导入</Button>
|
||||
</Upload>
|
||||
</div>
|
||||
|
||||
<div class="handle-item" v-has="'output'">
|
||||
<Button @click="exportExcel" type="warning">导出</Button>
|
||||
</div>
|
||||
|
||||
<div class="handle-item">
|
||||
<Button @click="index(1)" ghost type="primary">立即搜索</Button>
|
||||
</div>
|
||||
|
@ -6,19 +6,19 @@ export default {
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default () {
|
||||
default() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
isUpdate: {
|
||||
type: Boolean,
|
||||
default () {
|
||||
default() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
provinces: {
|
||||
type: Array,
|
||||
default () {
|
||||
default() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ export default {
|
||||
data: null
|
||||
},
|
||||
search: {
|
||||
show: false
|
||||
show: true
|
||||
},
|
||||
page: {
|
||||
total: 0,
|
||||
@ -277,6 +277,7 @@ export default {
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
request() {
|
||||
this.properties = [];
|
||||
this.index();
|
||||
},
|
||||
resetSearch() {
|
||||
@ -354,6 +355,48 @@ export default {
|
||||
this.properties[index] = data;
|
||||
this.changePage(this.page.page);
|
||||
this.updates[index] = this.properties[index];
|
||||
},
|
||||
exportExcel() {
|
||||
let params = {};
|
||||
|
||||
for (const key in this.params) {
|
||||
const element = this.params[key];
|
||||
|
||||
if (element !== '' && element !== undefined) {
|
||||
params[key] = element;
|
||||
}
|
||||
}
|
||||
|
||||
this.isShowLoading(true);
|
||||
|
||||
API.exportExcel(params).then(res => {
|
||||
if (res.code === 0) {
|
||||
if (res.data) {
|
||||
this.downloadFile(res.data);
|
||||
} else {
|
||||
this.$Modal.success({
|
||||
title: '提示',
|
||||
content: '当前导出数据量大,已进入后台队列导出模式,请稍后至导出列表查看下载。'
|
||||
});
|
||||
}
|
||||
}
|
||||
this.isShowLoading(false);
|
||||
}).catch(() => {
|
||||
this.isShowLoading(false);
|
||||
});
|
||||
},
|
||||
importExcel(file) {
|
||||
this.isShowLoading(true);
|
||||
API.importExcel(file).then(res => {
|
||||
if (res.code === 0) {
|
||||
this.request();
|
||||
this.$Message.success(res.message);
|
||||
}
|
||||
|
||||
this.isShowLoading(false);
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
2
public/js/app.53627ae3.js
Normal file
2
public/js/app.53627ae3.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/app.53627ae3.js.map
Normal file
1
public/js/app.53627ae3.js.map
Normal file
File diff suppressed because one or more lines are too long
2
public/js/app.a4f6ae07.js
Normal file
2
public/js/app.a4f6ae07.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/app.a4f6ae07.js.map
Normal file
1
public/js/app.a4f6ae07.js.map
Normal file
File diff suppressed because one or more lines are too long
2
public/js/app.b1d2578c.js
Normal file
2
public/js/app.b1d2578c.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/app.b1d2578c.js.map
Normal file
1
public/js/app.b1d2578c.js.map
Normal file
File diff suppressed because one or more lines are too long
15
public/js/chunk-f284e446.084c6108.js
Normal file
15
public/js/chunk-f284e446.084c6108.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/chunk-f284e446.084c6108.js.map
Normal file
1
public/js/chunk-f284e446.084c6108.js.map
Normal file
File diff suppressed because one or more lines are too long
15
public/js/chunk-f284e446.c033033f.js
Normal file
15
public/js/chunk-f284e446.c033033f.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/chunk-f284e446.c033033f.js.map
Normal file
1
public/js/chunk-f284e446.c033033f.js.map
Normal file
File diff suppressed because one or more lines are too long
15
public/js/chunk-f284e446.ee2db358.js
Normal file
15
public/js/chunk-f284e446.ee2db358.js
Normal file
File diff suppressed because one or more lines are too long
1
public/js/chunk-f284e446.ee2db358.js.map
Normal file
1
public/js/chunk-f284e446.ee2db358.js.map
Normal file
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/css/chunk-f284e446.60854bc0.css rel=prefetch><link href=/js/chunk-00ae0766.3874cd10.js rel=prefetch><link href=/js/chunk-07a274ec.c3ad5dec.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.js rel=prefetch><link href=/js/chunk-f284e446.8f131eda.js rel=prefetch><link href=/css/app.d71a8195.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.61a556c3.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.d71a8195.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.61a556c3.js></script></body></html>
|
||||
<!DOCTYPE html><html><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=\favicon.ico><script src=\config.js></script><title></title><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/css/chunk-f284e446.60854bc0.css rel=prefetch><link href=/js/chunk-00ae0766.3874cd10.js rel=prefetch><link href=/js/chunk-07a274ec.c3ad5dec.js rel=prefetch><link href=/js/chunk-996b1e80.d3b45e46.js rel=prefetch><link href=/js/chunk-f284e446.ee2db358.js rel=prefetch><link href=/css/app.d71a8195.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.a4f6ae07.js rel=preload as=script><link href=/js/chunk-vendors.ed6443e8.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.d71a8195.css rel=stylesheet></head><body><noscript><strong>很抱歉,如果没有启用JavaScript,程序不能正常工作,若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.ed6443e8.js></script><script src=/js/app.a4f6ae07.js></script></body></html>
|
Loading…
x
Reference in New Issue
Block a user