前端路由

This commit is contained in:
邓皓元 2019-01-07 14:09:14 +08:00
parent 1c89ced7fd
commit 3cc1811c70
17 changed files with 165 additions and 76 deletions

View File

@ -3,17 +3,20 @@ namespace App\Domains\Stats\Http\Controllers;
use App\Core\Controller;
use Illuminate\Http\Request;
use App\Domains\Stats\Services\OrderService;
class CompanyReportController extends Controller
class OrderController extends Controller
{
protected $request;
protected $orderService;
/**
* 构造函数,自动注入.
*/
public function __construct(Request $request)
public function __construct(Request $request, OrderService $orderService)
{
$this->request = $request;
$this->orderService = $orderService;
}
/**
@ -21,9 +24,14 @@ class CompanyReportController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function index()
public function index($type)
{
//
$conditions = $this->request->all();
$conditions['type'] = $type;
$res = $this->OrderService->index($conditions);
return res($res, '订单统计', 201);
}

View File

@ -6,4 +6,7 @@ $router->group(['prefix' => 'stats', 'as' => 'stats', 'middleware' => ['adminAut
$router->get('/company-count', ['as' => 'company-count.index', 'uses' => 'CompanyCountController@index']);
$router->get('/company-count/export', ['as' => 'company-count.export', 'uses' => 'CompanyCountController@export']);
// 订单统计
$router->get('/order/{type}', ['as' => 'order.index', 'uses' => 'OrderController@index']);
});

View File

@ -43,17 +43,19 @@ class OrderService extends Service
*
* @return void
*/
public function index(array $conditions = [])
public function index($type, array $conditions = [])
{
$conditions['type'] = $type;
$conditions['source'] = 1;
$companies = $this->companyRepository->withTrashed()->get()->pluck('name', 'id')->toArray();
$packages = $this->packageRepository->withTrashed()->get()->pluck('name', 'id')->toArray();
$select = [
'id',
DB::raw("string_agg(DISTINCT id, ',') as id"),
'company_id',
'package_id',
'product_id',
'unit_price',
'pay_channel',
DB::raw('SUM(counts) as counts'),
@ -88,8 +90,7 @@ class OrderService extends Service
$companies = $this->companyRepository->withTrashed()->get()->pluck('name', 'id')->toArray();
$packages = $this->packageRepository->withTrashed()->get()->pluck('name', 'id')->toArray();
$repository->withConditons()
$repository->withConditions($conditions)->applyConditions()->paginate($conditions['limit']);
$select = [
'id',

View File

@ -34,7 +34,6 @@ class OrderController extends Controller
$conditions = $this->request->all();
$conditions['limit'] = $this->request->get('limit', 20);
$conditions['source'] = 0;
$conditions['type'] = 0;
$orders = $this->orderService->paginate($conditions);

View File

@ -101,7 +101,7 @@ class PermissionSeeder extends Seeder
'open' => 3,
'children' => [
[
'name' => 'virtual.packages.index', 'title' => '基础套餐', 'path' => '/packages?type=0', 'icon' => 'ios-cube', 'type' => 0, 'open' => 3,
'name' => 'virtual.packages.index', 'title' => '基础套餐', 'path' => '/packages/0', 'icon' => 'ios-cube', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.packages.create', 'title' => '创建', 'description' => 'create', 'type' => 1],
['name' => 'virtual.packages.update', 'title' => '编辑', 'description' => 'update', 'type' => 1],
@ -135,7 +135,7 @@ class PermissionSeeder extends Seeder
'open' => 3,
'children' => [
[
'name' => 'virtual.orders.index', 'title' => '销售订单', 'path' => '/orders?type=0', 'icon' => 'logo-yen', 'type' => 0, 'open' => 3,
'name' => 'virtual.orders.index', 'title' => '销售订单', 'path' => '/orders/0', 'icon' => 'logo-yen', 'type' => 0, 'open' => 3,
'children' => [
['name' => 'virtual.orders.show', 'title' => '查看', 'description' => 'show', 'type' => 1],
['name' => 'virtual.orders.create', 'title' => '创建', 'description' => 'create', 'type' => 1],

View File

@ -1,9 +1,7 @@
import {
mapGetters
} from 'vuex';
import {
objectDot
} from 'service/util';
import { objectDot } from 'service/util';
import default_head from 'images/head.png';
export default {

View File

@ -20,8 +20,8 @@ const routes = [
{ path: '/companies', name: 'Companies', component: load('virtual/companies/index'), meta: { title: '企业管理' } },
{ path: '/company/accounts', name: 'CompanyAccounts', component: load('virtual/company_accounts/index'), meta: { title: '账号管理' } },
{ path: '/products', name: 'Products', component: load('virtual/products/index'), meta: { title: '定价管理' } },
{ path: '/orders', name: 'Orders', component: load('virtual/orders/index'), meta: { title: '订单列表' } },
{ path: '/packages', name: 'Packages', component: load('virtual/packages/index'), meta: { title: '套餐管理' } },
{ path: '/orders/:type', name: 'Orders', component: load('virtual/orders/index'), meta: { title: '订单列表' } },
{ path: '/packages/:type', name: 'Packages', component: load('virtual/packages/index'), meta: { title: '套餐管理' } },
{ path: '/cards', name: 'Cards', component: load('virtual/cards/index'), meta: { title: '客户列表' } },
{ path: '/exports', name: 'StatsExports', component: load('exports/index'), meta: { title: '导出记录' } },
{ path: '/stats/company-count', name: 'StatsCompanyCount', component: load('stats/company-count/index'), meta: { title: '企业统计' } }

View File

@ -136,3 +136,16 @@ export function objectDot(object, prepend = '') {
return results;
}
/**
* 合计数组对象
* @param {Array}} array
* @param {String} key
*/
export function sumBy(array, key) {
return array.map((item) => {
return item[key];
}).reduce((acc, cur) => {
return acc + cur;
});
};

View File

@ -51,11 +51,37 @@
</div>
<div class="page-list-wrap">
<Table :columns="table_titles" :data="list_data ? list_data.data : []"></Table>
<Table :columns="columns" :data="data" :height="page.limit > 12 ? 610 : ''" ref="table" stripe>
<template class="table-footer" slot="footer">
<colgroup class="table-footer-colgroup"></colgroup>
<thead class="ivu-table">
<tr>
<th><div class="ivu-table-cell">总计</div></th>
<th><div class="ivu-table-cell"></div></th>
<th><div class="ivu-table-cell">{{stats.total}}</div></th>
<th><div class="ivu-table-cell">{{stats.counts}}</div></th>
<th><div class="ivu-table-cell">{{stats.renewed_counts}}</div></th>
<th><div class="ivu-table-cell">{{stats.valid_counts}}</div></th>
<th v-if="page.limit > 12" rowspan="1"></th>
</tr>
</thead>
</template>
</Table>
</div>
<div class="page-turn-wrap" v-if="list_data">
<Page :current="Number(list_data.current_page)" :page-size="Number(list_data.per_page)" :total="Number(list_data.total)" @on-change="index" show-elevator show-total></Page>
<div class="page-turn-wrap">
<Page
:current="Number(page.page)"
:page-size="Number(page.limit)"
:page-size-opts="[10, 20, 100, Infinity]"
:total="Number(page.total)"
@on-change="changePage"
@on-page-size-change="changeLimit"
show-elevator
show-sizer
show-total
></Page>
</div>
</div>
</template>

View File

@ -1,50 +1,60 @@
import { sumBy } from 'service/util';
export default {
name: 'StatsCompanyCount',
data() {
return {
search: {
show: false
},
options: {
name: null,
time: null
},
list_data: null,
search: {
show: false
data: [],
list: [],
stats: {},
page: {
total: 0,
limit: 10,
page: 1
},
table_titles: [{
title: '企业ID',
key: 'id',
width: 80
},
{
title: '企业名称',
key: 'name'
},
{
title: '总用户数',
key: 'total',
width: 120
},
{
title: '新增用户数',
key: 'counts',
width: 120
},
{
title: '续费用户数',
key: 'renewed_counts',
width: 120
},
{
title: '服务期内用户数',
key: 'valid_counts',
width: 200
}
columns: [
{
title: '企业ID',
key: 'id',
width: 80
},
{
title: '企业名称',
key: 'name'
},
{
title: '总用户数',
key: 'total',
width: 120
},
{
title: '新增用户数',
key: 'counts',
width: 120
},
{
title: '续费用户数',
key: 'renewed_counts',
width: 120
},
{
title: '服务期内用户数',
key: 'valid_counts',
width: 200
}
]
};
},
created() {
this.index(1);
window.t = this;
this.index();
console.log(this.$refs.table);
},
methods: {
/**
@ -52,7 +62,7 @@ export default {
* @param {Number} page [description]
* @return {[type]} [description]
*/
index(page = 1) {
index() {
let options = Object.assign({
orderBy: 'id',
sortedBy: 'asc'
@ -60,7 +70,7 @@ export default {
this.options);
let params = this.searchDataHandle({}, {
page
limit: 0
}, options);
this.isShowLoading(true);
@ -70,7 +80,9 @@ export default {
}).then(res => {
this.isShowLoading(false);
if (res.code == 0) {
this.list_data = res.data;
this.list = res.data;
this.page.total = this.list.length;
this.changePage(1);
}
}).catch(() => {
this.isShowLoading(false);
@ -82,14 +94,14 @@ export default {
* @return {[type]} [description]
*/
request() {
const result = this.list_data;
let page = result.current_page;
let page = this.page.page;
if (this.list_data.data.length == 1) {
page = this.returnPage(result.total, result.current_page, result.per_page);
if (this.data.length == 1) {
page = this.returnPage(this.page.total, this.page.page, this.page.limit);
}
this.index(page);
this.index();
this.changePage(page);
},
resetSearch() {
@ -97,7 +109,30 @@ export default {
this.options[k] = null;
}
this.index(1);
this.index();
},
changeLimit(limit) {
this.page.limit = limit;
this.changePage(1);
},
changePage(page) {
this.page.page = page;
this.data = this.list.slice((page - 1) * this.page.limit, page * this.page.limit);
this.stats = {
total: sumBy(this.list, 'total'),
counts: sumBy(this.list, 'counts'),
renewed_counts: sumBy(this.list, 'renewed_counts'),
valid_counts: sumBy(this.list, 'valid_counts')
};
this.$nextTick(() => {
setTimeout(() => {
let html = $('.ivu-table-header colgroup').html();
console.log(html);
$('.table-footer-colgroup').html(html);
}, 10);
});
},
exportExcel() {
@ -114,7 +149,9 @@ export default {
this.isShowLoading(true);
service.get('api/stats/company-count/export', { params }).then((res) => {
service.get('api/stats/company-count/export', {
params
}).then((res) => {
if (res.code === 0) {
this.downloadFile(res.data);
}

View File

@ -9,12 +9,13 @@ export default {
data() {
return {
params: {
'sn': null,
'company_name': null,
'package_name': null,
'order_status': null,
'carrier_operator': null,
'time': []
type: 0,
sn: null,
company_name: null,
package_name: null,
order_status: null,
carrier_operator: null,
time: []
},
list_data: null,
editObj: {
@ -493,6 +494,8 @@ export default {
* @return {[type]} [description]
*/
index(page = 1) {
this.params.type = Number(this.$route.params.type);
console.log(this.params);
let data = this.searchDataHandle({}, { page }, this.params);
this.isShowLoading(true);
API.index(data).then(res => {

View File

@ -163,7 +163,7 @@ export default {
};
},
created() {
this.type = Number(this.$route.query.type);
this.type = Number(this.$route.params.type);
this.index(1);
},
methods: {
@ -173,11 +173,6 @@ export default {
* @return {[type]} [description]
*/
index(page = 1) {
if (typeof (this.type) === 'undefined') {
this.$Message.error('非法请求');
return;
}
let data = this.searchDataHandle(this.params, { page }, { 'type': this.type, 'trashed': this.trashed, 'orderBy': 'id', 'sortedBy': 'asc' });
this.isShowLoading(true);
API.index(data).then(res => {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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-7b30bdf4.a0bc7fe7.css rel=prefetch><link href=/js/chunk-00ae0766.158e4a52.js rel=prefetch><link href=/js/chunk-7b30bdf4.bc2c69b8.js rel=prefetch><link href=/css/app.36043160.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.07f32dff.js rel=preload as=script><link href=/js/chunk-vendors.02a4e5bc.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.36043160.css rel=stylesheet></head><body><noscript><strong>很抱歉如果没有启用JavaScript程序不能正常工作若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.02a4e5bc.js></script><script src=/js/app.07f32dff.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-7b30bdf4.a0bc7fe7.css rel=prefetch><link href=/js/chunk-00ae0766.158e4a52.js rel=prefetch><link href=/js/chunk-7b30bdf4.568cb339.js rel=prefetch><link href=/css/app.36043160.css rel=preload as=style><link href=/css/chunk-vendors.3c3b2e85.css rel=preload as=style><link href=/js/app.5b8146e0.js rel=preload as=script><link href=/js/chunk-vendors.02a4e5bc.js rel=preload as=script><link href=/css/chunk-vendors.3c3b2e85.css rel=stylesheet><link href=/css/app.36043160.css rel=stylesheet></head><body><noscript><strong>很抱歉如果没有启用JavaScript程序不能正常工作若要继续使用请启用它。</strong></noscript><div id=app></div><script src=/js/chunk-vendors.02a4e5bc.js></script><script src=/js/app.5b8146e0.js></script></body></html>