流量池
This commit is contained in:
parent
a90b0f11d4
commit
6f71277e9a
@ -69,7 +69,17 @@ class FlowPoolMonthSync extends Command
|
|||||||
];
|
];
|
||||||
}, $items);
|
}, $items);
|
||||||
|
|
||||||
$array = array_merge($array, $items);
|
$items = array_groupBy($items, 'sim');
|
||||||
|
|
||||||
|
foreach ($items as $sim => $group) {
|
||||||
|
if (count($group) > 1) {
|
||||||
|
$temp = $group[0];
|
||||||
|
$temp['kilobyte'] = array_sum(array_pluck($group, 'kilobyte'));
|
||||||
|
$items[$sim] = [$temp];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$array = array_merge($array, array_collapse($items));
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::transaction(function () use ($array) {
|
DB::transaction(function () use ($array) {
|
||||||
|
@ -10,12 +10,15 @@ use App\Exceptions\NotExistException;
|
|||||||
use App\Models\Virtual\FlowPoolMonth;
|
use App\Models\Virtual\FlowPoolMonth;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use App\Exceptions\NotAllowedException;
|
use App\Exceptions\NotAllowedException;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use App\Exceptions\InvalidArgumentException;
|
||||||
use App\Domains\Export\Services\ExportService;
|
use App\Domains\Export\Services\ExportService;
|
||||||
|
use App\Domains\Export\Services\ImportService;
|
||||||
use App\Domains\Virtual\Exports\FlowPoolExport;
|
use App\Domains\Virtual\Exports\FlowPoolExport;
|
||||||
|
|
||||||
use App\Domains\Virtual\Services\PackageService;
|
use App\Domains\Virtual\Services\PackageService;
|
||||||
use App\Domains\Virtual\Services\ProductService;
|
use App\Domains\Virtual\Services\ProductService;
|
||||||
use App\Domains\Virtual\Services\FlowPoolService;
|
use App\Domains\Virtual\Services\FlowPoolService;
|
||||||
|
|
||||||
use App\Domains\Virtual\Repositories\FlowPoolRepository;
|
use App\Domains\Virtual\Repositories\FlowPoolRepository;
|
||||||
use App\Domains\Virtual\Exports\FlowPoolExportDetailExport;
|
use App\Domains\Virtual\Exports\FlowPoolExportDetailExport;
|
||||||
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
|
||||||
@ -287,4 +290,78 @@ class FlowPoolController extends Controller
|
|||||||
|
|
||||||
return res($url, '导出成功', 201);
|
return res($url, '导出成功', 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入流量卡数据.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
public function importFlows()
|
||||||
|
{
|
||||||
|
$file = $this->request->file('file');
|
||||||
|
$data = ImportService::load($file, ['month', 'pool_id', 'sim', 'kilobyte']);
|
||||||
|
|
||||||
|
Validator::validate($data, [
|
||||||
|
'*.month' => ['required'],
|
||||||
|
'*.pool_id' => ['required'],
|
||||||
|
'*.sim' => ['required'],
|
||||||
|
'*.kilobyte' => ['required'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$flowPools = app(FlowPoolRepository::class)->withConditions(['id' => array_unique(array_pluck($data, 'pool_id'))])->get()->keyBy('id')->toArray();
|
||||||
|
|
||||||
|
$simPackage = [];
|
||||||
|
|
||||||
|
foreach (array_chunk($data, 1000) as $value) {
|
||||||
|
$cards = app(OrderCardPartitionRepository::class)->select(['sim', 'package_id'])->withConditions([
|
||||||
|
'type' => 0,
|
||||||
|
'sim' => array_pluck($value, 'sim'),
|
||||||
|
])->get()->pluck('package_id', 'sim')->toArray();
|
||||||
|
|
||||||
|
foreach ($cards as $sim => $package_id) {
|
||||||
|
$simPackage[$sim] = $package_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data as &$item) {
|
||||||
|
if (!isset($simPackage[$item['sim']])) {
|
||||||
|
throw new NotExistException('卡不在VD上 #:' . $item['sim']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$package_id = $simPackage[$item['sim']];
|
||||||
|
|
||||||
|
$pool = $flowPools[$item['pool_id']];
|
||||||
|
|
||||||
|
if (!in_array($package_id, $pool['package_ids'])) {
|
||||||
|
throw new InvalidArgumentException("卡不属于流量池 {$item['pool_id']} #: {$item['sim']}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$item['package_id'] = $simPackage[$item['sim']];
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::transaction(function () use ($data) {
|
||||||
|
$monthGroupBy = array_groupBy($data, 'month');
|
||||||
|
|
||||||
|
foreach ($monthGroupBy as $month => $values) {
|
||||||
|
$table = FlowPoolService::checkTable($month);
|
||||||
|
$simGroupBy = array_groupBy($values, 'sim');
|
||||||
|
|
||||||
|
foreach ($simGroupBy as $sim => $group) {
|
||||||
|
if (count($group) > 1) {
|
||||||
|
$temp = $group[0];
|
||||||
|
$temp['kilobyte'] = array_sum(array_pluck($group, 'kilobyte'));
|
||||||
|
$simGroupBy[$sim] = [$temp];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$values = array_collapse($simGroupBy);
|
||||||
|
|
||||||
|
foreach (array_chunk($values, 1000) as $news) {
|
||||||
|
app(FlowPoolMonth::class)->setTable($table)->upsert($news, ['sim', 'month']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return res(true, '导入成功');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,4 +78,5 @@ $router->group(['prefix' => 'virtual', 'as' => 'virtual', 'middleware' => ['admi
|
|||||||
$router->post('/flow-pools/destroy', ['as' => 'flow-pools.destroy', 'uses' => 'FlowPoolController@destroy']);
|
$router->post('/flow-pools/destroy', ['as' => 'flow-pools.destroy', 'uses' => 'FlowPoolController@destroy']);
|
||||||
$router->post('/flow-pools/setting', ['as' => 'flow-pools.setting', 'uses' => 'FlowPoolController@setting']);
|
$router->post('/flow-pools/setting', ['as' => 'flow-pools.setting', 'uses' => 'FlowPoolController@setting']);
|
||||||
$router->addRoute(['GET', 'POST'], '/flow-pools/flows', ['as' => 'flow-pools.flows', 'uses' => 'FlowPoolController@flows']);
|
$router->addRoute(['GET', 'POST'], '/flow-pools/flows', ['as' => 'flow-pools.flows', 'uses' => 'FlowPoolController@flows']);
|
||||||
|
$router->post('/flow-pools/import-flows', ['as' => 'flow-pools.import-flows', 'uses' => 'FlowPoolController@importFlows']);
|
||||||
});
|
});
|
||||||
|
@ -118,3 +118,22 @@ export function getFlows(data) {
|
|||||||
export function postFlows(data) {
|
export function postFlows(data) {
|
||||||
return service.post('api/virtual/flow-pools/flows', data);
|
return service.post('api/virtual/flow-pools/flows', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [import 属性导入]
|
||||||
|
* @param {[type]} data [description]
|
||||||
|
* @return {[type]} [description]
|
||||||
|
*/
|
||||||
|
export function importFlows(file) {
|
||||||
|
let config = {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let params = new FormData();
|
||||||
|
|
||||||
|
params.append('file', file);
|
||||||
|
|
||||||
|
return service.post('api/virtual/flow-pools/import-flows', params, config);
|
||||||
|
}
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
<div class="handle-item">
|
<div class="handle-item">
|
||||||
<Button @click="exportExcel" icon="md-download">导出</Button>
|
<Button @click="exportExcel" icon="md-download">导出</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="handle-item">
|
||||||
|
<Button @click="importModel = true" type="warning">导入月流量数据</Button>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -125,6 +129,24 @@
|
|||||||
:month="moment(options.month).format('YYYY-MM')"
|
:month="moment(options.month).format('YYYY-MM')"
|
||||||
@add-success="index(list_data.current_page)"
|
@add-success="index(list_data.current_page)"
|
||||||
></ui-flows>
|
></ui-flows>
|
||||||
|
|
||||||
|
<Modal v-model="importModel" title="导入流量数据">
|
||||||
|
<ui-loading :show="page_loading.show"></ui-loading>
|
||||||
|
|
||||||
|
<Upload :before-upload="importFlows" action="/" :format="['xls','xlsx','csv']" class="f-l">
|
||||||
|
<Button type="primary" ghost>导入</Button>
|
||||||
|
</Upload>
|
||||||
|
|
||||||
|
<a
|
||||||
|
:href="CONFIG.url + 'storage/templates/import-flows.xls'"
|
||||||
|
download="导入流量数据模板.xls"
|
||||||
|
class="fz-12 lh-32 umar-l10"
|
||||||
|
>下载导入模板</a>
|
||||||
|
|
||||||
|
<footer class="ta-c" slot="footer">
|
||||||
|
<Button @click="importModel = false" class="w-80 umar-r5" ghost type="primary">取消</Button>
|
||||||
|
</footer>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ export default {
|
|||||||
search: {
|
search: {
|
||||||
show: true
|
show: true
|
||||||
},
|
},
|
||||||
|
importModel: false,
|
||||||
table_titles: [{
|
table_titles: [{
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
key: 'id',
|
key: 'id',
|
||||||
@ -384,6 +385,20 @@ export default {
|
|||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.isShowLoading(false);
|
this.isShowLoading(false);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
importFlows(file) {
|
||||||
|
this.isShowLoading(true);
|
||||||
|
API.importFlows(file).then(res => {
|
||||||
|
if (res.code === 0) {
|
||||||
|
this.request();
|
||||||
|
this.$Message.success(res.message);
|
||||||
|
this.importModel = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.isShowLoading(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
1
public/js/app.63b37964.js
Normal file
1
public/js/app.63b37964.js
Normal file
File diff suppressed because one or more lines are too long
14
public/js/chunk-4443c580.754ef273.js
Normal file
14
public/js/chunk-4443c580.754ef273.js
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-4443c580.c09b5b64.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/js/chunk-00ae0766.d130b440.js rel=prefetch><link href=/js/chunk-07a274ec.55e1b3b0.js rel=prefetch><link href=/js/chunk-4443c580.99320ef2.js rel=prefetch><link href=/js/chunk-996b1e80.92847c4e.js rel=prefetch><link href=/css/app.8e379248.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.2d02cf26.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.8e379248.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.2d02cf26.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-4443c580.c09b5b64.css rel=prefetch><link href=/css/chunk-996b1e80.5cadf3d0.css rel=prefetch><link href=/js/chunk-00ae0766.d130b440.js rel=prefetch><link href=/js/chunk-07a274ec.55e1b3b0.js rel=prefetch><link href=/js/chunk-4443c580.754ef273.js rel=prefetch><link href=/js/chunk-996b1e80.92847c4e.js rel=prefetch><link href=/css/app.8e379248.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.63b37964.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.8e379248.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.63b37964.js></script></body></html>
|
BIN
storage/app/public/templates/import-flows.xls
Normal file
BIN
storage/app/public/templates/import-flows.xls
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user