Commit cc169ef1 authored by gxx's avatar gxx

完成用户增长百分比显示在页面

parent cc2beae6
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/11/10
* Time: 16:14
*/
namespace App\Contracts;
interface StatisticsServiceContract
{
public function UserIncrease();
}
\ No newline at end of file
......@@ -195,7 +195,7 @@ class GroupController extends Controller
if($inviteResult){
return Message::makeSuccess('邀请成功!');
}else{
return Message::makeError('你邀请过了吧!');
return Message::makeError('ta 已经是你的人了,亲!');
}
}
......
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Contracts\StatisticsServiceContract;
use App\Models\Group;
use App\Models\Project;
use App\Models\User;
......@@ -11,6 +12,11 @@ use Illuminate\Http\Request;
class StatisticsController extends Controller
{
public function __construct(StatisticsServiceContract $statisticsHandel)
{
$this->mStatistics = $statisticsHandel;
}
// 今日新增用户
public function newUser()
......@@ -34,4 +40,12 @@ class StatisticsController extends Controller
}
// 用户增长
public function UserIncrease()
{
$date = $this->mStatistics->UserIncrease();
return $date;
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserInfo extends Model
{
//
}
<?php
namespace App\Providers;
use App\Services\StatisticsService;
use Illuminate\Support\ServiceProvider;
class StatisticsServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//绑定服务与接口关系
$this->app->singleton("App\Contracts\StatisticsServiceContract",function(){
return new StatisticsService();
});
}
}
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/11/10
* Time: 16:16
*/
namespace App\Services;
use App\Contracts\StatisticsServiceContract;
use App\Models\User;
use Carbon\Carbon;
class StatisticsService implements StatisticsServiceContract
{
public function UserIncrease()
{
$dtD = Carbon::now()->subDay();
$dtM = Carbon::now()->subMonth();
$dtW = Carbon::now()->subWeek();
$dayUsers = User::where('created_at','>',$dtD)->get();
$monthUsers = User::where('created_at','>',$dtM)->get();
$weekUsers = User::where('created_at','>',$dtW)->get();
$users = User::all()->count();
$day=0;
$week=0;
$month=0;
if (!$dayUsers->isEmpty()){
$day = count($dayUsers);
}
if (!$weekUsers->isEmpty()){
$week = count($weekUsers);
}
if (!$monthUsers->isEmpty()){
$month = count($monthUsers);
}
$day = round($day/$users*100,2);
$week = round($week/$users*100,2);
$month = round($month/$users*100,2);
$date = array($day.'%',$week.'%',$month.'%',$users);
return $date;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Aladin
* Date: 2017/9/27
* Time: 17:28
*/
namespace App\Util;
use Illuminate\Support\Facades\Storage;
class UploadPhoto
{
public function upload($head_icon)
{
// 获取上传文件的大小
$size = $head_icon->getSize();
if ($size > 2*1024*1024){
return back()->with('上传文件不能超过2M');
}
// 文件类型
$mimeType = $head_icon->getMimeType();
// 扩展文件名
$ext = $head_icon->getClientOriginalExtension();
// 判断是否通过HTTP POST 上传
$realPath = $head_icon->getRealPath();
if (!$realPath){
return '操作非法';
}
$today = date('Y-m-d');
$dir = storage_path().'\app\public\uploads\\'.$today;
if (!$dir){
mkdir($dir);
}
// 新文件名
$newFilename = uniqid().'.'.$ext;
if (Storage::disk('uploads')->put($today.'/'.$newFilename,file_get_contents($realPath))){
$head_icon = 'storage/'.$today.'/'.$newFilename;
return $head_icon;
}else{
return false;
}
}
}
\ No newline at end of file
......@@ -183,6 +183,7 @@ return [
App\Providers\ScheduleServiceProvider::class,
App\Providers\SMSServiceProvider::class,
App\Providers\UserServiceProvider::class,
App\Providers\StatisticsServiceProvider::class,
Zizaco\Entrust\EntrustServiceProvider::class,
......
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUserInfosTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_infos', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_infos');
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -67,5 +67,125 @@
<!-- ./col -->
</div>
<div>
{{--<div style="width: 728px;height: 200px;background-color: #f0f0f0;border: 1px solid #D2D6DE;float: right;">--}}
<div style="width: 815px;height: 200px;background-color: #f0f0f0;border: 1px solid #D2D6DE;float: right;">
<p style="margin-left: 265px;"> 新增用户占总用户百分比数据图</p>
<div style="width: 220px;height: 150px;float: left; margin-top:2px;margin-left: 15px; line-height: 150px;">
昨日新增用户数: <span style="font-family:'微软雅黑';font-size: 20px;color: #cb2027;" id="day"> </span>
</div>
<div style="float:left;width: 1px;height: 120px; background: #A3A3A3;margin-top: 21px;"></div>
<div style="width: 220px;height: 150px;float: left; margin-top: 2px;margin-left: 15px;line-height: 150px;">
一周内新增用户数:<span style="font-family:'微软雅黑';font-size: 20px;color: #cb2027;" id="week"> </span>
</div>
<div style="float:left;width: 1px;height: 120px; background: #A3A3A3;margin-top: 21px;"></div>
<div style="width: 220px;height: 150px;float: left; margin-top: 2px;margin-left: 15px;line-height: 150px;">
一月内新增用户数:<span style="font-family:'微软雅黑';font-size: 20px;color: #cb2027;" id="month"> </span>
</div>
<!-- 为ECharts准备一个具备大小(宽高)的Dom -->
</div>
<div id="main" style="width: 600px;height:400px;"></div>
</div>
<script src="{{url('js/jquery-3.2.1.min.js')}}"> </script>
<!-- 引入 echarts.js -->
<script src="{{'js/echarts.js'}}"></script>
<script>
$.ajax({
type:'get',
url:'{{route('statistics.UserIncrease')}}',
success:function(data){
$('#day').html(data[0]);
$('#week').html(data[1]);
$('#month').html(data[2]);
},
error:function(data){
console.log('错误');
}
});
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));
var optiona = {
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)"
},
legend: {
orient: 'vertical',
x: 'left',
data:['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
},
series: [
{
name:'访问来源',
type:'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
normal: {
show: false,
position: 'center'
},
emphasis: {
show: true,
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
labelLine: {
normal: {
show: false
}
},
data:[
{value:335, name:'直接访问'},
{value:310, name:'邮件营销'},
{value:234, name:'联盟广告'},
{value:135, name:'视频广告'},
{value:1548, name:'搜索引擎'}
]
}
]
};
myChart.setOption(optiona);
</script>
@endsection
\ No newline at end of file
......@@ -19,7 +19,7 @@
<label for="exampleInputFile">头像</label>
<p>
<img src="{{asset($result['head_icon'])}}" alt="" width="100px" height="80px" style="border-radius: 80%">
<img src="{{asset($result['head_icon'])}}" alt="" width="100px" height="20px" style="border-radius: 80%">
</p>
</div>
<div class="form-group">
......
......@@ -78,6 +78,20 @@ Route::group(['prefix'=> 'project'],function (){
});
// 统计
Route::group(['prefix'=> 'statistics'],function (){
Route::get('user_increase','StatisticsController@UserIncrease')->name('statistics.UserIncrease');
});
// 权限
Route::group(['prefix'=> 'auth'],function (){
Route::get('getAll','AuthController@getAll')->name('auth.getAll');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment