Skip to content

Commit

Permalink
statistic - bubble showing
Browse files Browse the repository at this point in the history
1. finish - but the chat is not good for this statistic
  • Loading branch information
taoyu65 committed Dec 9, 2016
1 parent 12f697c commit 19e506d
Show file tree
Hide file tree
Showing 8 changed files with 279 additions and 278 deletions.
385 changes: 113 additions & 272 deletions .idea/workspace.xml

Large diffs are not rendered by default.

33 changes: 32 additions & 1 deletion app/Http/Controllers/statisticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,40 @@ private function profits($year, $refresh, $type)
}
}

private function getCustomerProfits($year, $refresh)
public function allItem($refresh = 'dfsa')
{
$path = Config::get($this->configFileName.'.statistic.profitsPath.allItem');
if ($refresh === 'refresh') { //if refresh
$profits = $this->getAllItem();
file_put_contents(public_path($path), $profits);
}else{
$profits = file_get_contents($path);
if(!$profits || empty($profits)){
$profits = $this->getAllItem();
file_put_contents(public_path($path), $profits);
}
}
return view('statisticAllItem', ['dataSet' => $profits]);
}

private function getAllItem()
{
$dataSet = [];
$customers = DB::table('customs')->get();
foreach ($customers as $customer) {
$items = DB::table('items')
->join('carts', 'items.carts_id' , '=', 'carts.id')
->join('customs', 'customs.id', '=', 'carts.customs_id')
->where('customs.id', $customer->id)->get();
$xyr = [];
foreach ($items as $item) {
array_push($xyr, array('x' => (int)$item->costPrice, 'y' => (int)$item->sellPrice, 'r' => (int)$item->itemProfit));
}
if(count($xyr) > 0)
$dataSet[$customer->customName] = $xyr;
}
//dd($dataSet);
return json_encode($dataSet);
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
Route::get('firstpage', 'ItemController@firstPage');
#statistics
Route::get('statistics/{x}/{y}/{refresh?}', 'statisticController@index');
Route::get('statisticsAllItem/{refresh?}', 'statisticController@allItem');
#customs
Route::get('showcustomwindow', 'CustomController@showWindow');
Route::post('addcustom', 'CustomController@add');
Expand Down
1 change: 1 addition & 0 deletions config/ccbuy.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@
'customer2016' => 'json/customer2016.json',
'customer2017' => 'json/customer2017.json',
'customerAll' => 'json/customerAll.json',
'allItem' => 'json/allItem.json',
],
'profitMonth' => 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec',
'profitAll' => '2016,2017,2018',
Expand Down
2 changes: 1 addition & 1 deletion public/json/profit2016.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
63.58,60.00,,21.98,70,7.70,3.30,99.00,42.00,43,461.85,45.32
63.58,60.00,,21.98,70,7.70,3.30,99.00,42.00,43,823.85,45.32
1 change: 0 additions & 1 deletion public/json/profitAll.json

This file was deleted.

6 changes: 3 additions & 3 deletions resources/views/statistic.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<div class="line-middle" style="padding-top: 10px">
<div class="xl2">
<button class="btn btn-success btn130Width" type="button">
<button class="btn btn-success btn130Width" type="button" onclick="javascript:window.location.href='{{url('statisticsAllItem')}}'">
{{trans('statistic.items')}} <span class="badge">{{trans('statistic.all')}}</span>
</button>
</div>
Expand Down Expand Up @@ -89,8 +89,8 @@
var g = GetRandomNum(0, 250).toString();
var b = GetRandomNum(0, 250).toString();
var a = Math.random().toFixed(1).toString();
color.push('rgba('+r+', '+b+', '+b+', 0.5)');
borderColor.push('rgba('+r+', '+b+', '+b+', 1)');
color.push('rgba('+r+', '+g+', '+b+', 0.5)');
borderColor.push('rgba('+r+', '+g+', '+b+', 1)');
}
var ctx = $("#myChart");
Expand Down
128 changes: 128 additions & 0 deletions resources/views/statisticAllItem.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@

@extends('layouts.foot')
@section('content')
<style>
.btn130Width{
width:130px;text-align: left;
}
</style>
<div class="line">
<div class="xl3">
<button class="btn btn-primary btn130Width" type="button" onclick="javascript:window.location.href='{{url('statistics/2016/profits')}}'">
{{trans('statistic.profits')}} <span class="badge">2016</span>
</button>
</div>
<div class="xl3">
<button class="btn btn-primary btn130Width" type="button" onclick="javascript:window.location.href='{{url('statistics/2017/profits')}}'">
{{trans('statistic.profits')}} <span class="badge">2017</span>
</button>
</div>
<div class="xl3">
<button class="btn btn-primary btn130Width" type="button" onclick="javascript:window.location.href='{{url('statistics/All/profits')}}'">
{{trans('statistic.profits')}} <span class="badge">{{trans('statistic.all')}}</span>
</button>
</div>
</div>
<div class="line" style="padding-top: 10px">
<div class="xl3">
<button class="btn btn-warning btn130Width" type="button" onclick="javascript:window.location.href='{{url('statistics/2016/customer')}}'">
{{trans('statistic.customer')}} <span class="badge">2016</span>
</button>
</div>
<div class="xl3">
<button class="btn btn-warning btn130Width" type="button" onclick="javascript:window.location.href='{{url('statistics/2017/customer')}}'">
{{trans('statistic.customer')}} <span class="badge">2017</span>
</button>
</div>
<div class="xl3">
<button class="btn btn-warning btn130Width" type="button" onclick="javascript:window.location.href='{{url('statistics/All/customer')}}'">
{{trans('statistic.customer')}} <span class="badge">{{trans('statistic.all')}}</span>
</button>
</div>
</div>

<div class="line-middle" style="padding-top: 10px">
<div class="xl2">
<button class="btn btn-success btn130Width" type="button" onclick="javascript:window.location.href='{{url('statisticsAllItem')}}'">
{{trans('statistic.items')}} <span class="badge">{{trans('statistic.all')}}</span>
</button>
</div>
</div>

<script type="text/javascript" src='{{url("js/Chart.min.js")}}'></script>
<canvas id="myChart" width="600" height="300"></canvas>
<script>
var color = [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)',
'rgba(199,21,133, 1)',
'rgba(95,158,160, 1)',
'rgba(85,107,47, 1)',
'rgba(0,255,0, 1)',
'rgba(165,42,42, 1)',
'rgba(105,105,105, 1)',
];
var returnData = '{!! $dataSet !!}';
var jsonData = eval('(' + returnData + ')');
var arr = [];
var i = 0;
for(var label in jsonData){
i++;
if(i > 12) {
var r = GetRandomNum(0, 250).toString();
var g = GetRandomNum(0, 250).toString();
var b = GetRandomNum(0, 250).toString();
color.push('rgba('+r+', '+g+', '+b+', 0.8)');
}
var json = {
label: label,
data: jsonData[label],
backgroundColor: color[i],
//hoverBackgroundColor: "#FF6384",
};
arr.push(json);
}
var bubbleChartData = {
datasets: arr
};
window.onload = function() {
var ctx = document.getElementById("myChart").getContext("2d");
window.myChart = new Chart(ctx, {
type: 'bubble',
data: bubbleChartData,
options: {
responsive: true,
title:{
display:true,
text:'Chart.js Bubble Chart'
},
tooltips: {
mode: 'point'
}
}
});
};
//get refresh page
function refresh() {
var url = document.URL;
url = url.replace('/refresh', '');
url += '/refresh';
window.location.href = url;
}
//get random number
function GetRandomNum(Min,Max)
{
var Range = Max - Min;
var Rand = Math.random();
return(Min + Math.round(Rand * Range));
}
</script>

<button type="button" class="btn btn-default btn-lg btn-block" onclick="refresh();"><strong>{{trans('statistic.refresh')}}</strong></button>
@endsection

0 comments on commit 19e506d

Please sign in to comment.