Browse Source

Merge remote-tracking branch 'origin/develop' into develop

develop
李可松 4 years ago
parent
commit
5398ea2db7
  1. 20
      app/AdminAgent/Controllers/HomeController.php
  2. 13
      app/AdminAgent/Metrics/Examples/Dashboard.php
  3. 152
      app/AdminAgent/Metrics/Examples/NewDevices.php
  4. 189
      app/AdminAgent/Metrics/Examples/NewUsers.php
  5. 160
      app/AdminAgent/Metrics/Examples/OrderExamples.php
  6. 179
      app/AdminAgent/Metrics/Examples/SalesExamples.php
  7. 78
      app/Common/DataTime.php
  8. 6
      app/Http/Controllers/Api/UserController.php
  9. 2
      config/database.php
  10. 43
      resources/views/admin/pages/agent-home.blade.php

20
app/AdminAgent/Controllers/HomeController.php

@ -4,7 +4,7 @@ namespace App\AdminAgent\Controllers;
use App\AdminAgent\Metrics\Examples; use App\AdminAgent\Metrics\Examples;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Dcat\Admin\Http\Controllers\Dashboard;
use Dcat\Admin\Admin;
use Dcat\Admin\Layout\Column; use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content; use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row; use Dcat\Admin\Layout\Row;
@ -13,13 +13,23 @@ class HomeController extends Controller
{ {
public function index(Content $content) public function index(Content $content)
{ {
Admin::style(
<<<CSS
.col-sm-10.d-flex{
display: inline-block !important;
}
.col-sm-9.d-flex{
display: inline-block !important;
}
CSS
);
return $content return $content
->header('仪表盘')
->header('代理商后台')
->description('数据详情') ->description('数据详情')
->body(function (Row $row) { ->body(function (Row $row) {
$row->column(6, function (Column $column) { $row->column(6, function (Column $column) {
$column->row(Dashboard::title());
$column->row(new Examples\Tickets());
$column->row(Examples\Dashboard::title());
$column->row(new Examples\OrderExamples());
}); });
$row->column(6, function (Column $column) { $row->column(6, function (Column $column) {
@ -28,7 +38,7 @@ class HomeController extends Controller
$row->column(6, new Examples\NewDevices()); $row->column(6, new Examples\NewDevices());
}); });
$column->row(new Examples\Sessions());
$column->row(new Examples\SalesExamples());
$column->row(new Examples\ProductOrders()); $column->row(new Examples\ProductOrders());
}); });
}); });

13
app/AdminAgent/Metrics/Examples/Dashboard.php

@ -0,0 +1,13 @@
<?php
namespace App\AdminAgent\Metrics\Examples;
use Dcat\Admin\Admin;
class Dashboard
{
public static function title()
{
return view('admin::pages.agent-home', ['admin' => Admin::user()]);
}
}

152
app/AdminAgent/Metrics/Examples/NewDevices.php

@ -2,86 +2,98 @@
namespace App\AdminAgent\Metrics\Examples; namespace App\AdminAgent\Metrics\Examples;
use App\Models\User;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Donut; use Dcat\Admin\Widgets\Metrics\Donut;
use Illuminate\Support\Arr;
class NewDevices extends Donut class NewDevices extends Donut
{ {
protected $labels = ['Desktop', 'Mobile'];
protected $labels = ['男性', '女性', '未知'];
/**
* 初始化卡片内容
*/
protected function init()
{
parent::init();
/**
* 初始化卡片内容
*/
protected function init()
{
parent::init();
$color = Admin::color();
$colors = [$color->primary(), $color->alpha('blue2', 0.5)];
$color = Admin::color();
$colors = [$color->primary(), $color->alpha('blue2', 0.5)];
$this->title('New Devices');
$this->subTitle('Last 30 days');
$this->chartLabels($this->labels);
// 设置图表颜色
$this->chartColors($colors);
}
$this->title('用户性别');;
$this->chartLabels($this->labels);
// 设置图表颜色
$this->chartColors($colors);
}
/**
* 渲染模板
*
* @return string
*/
public function render()
{
$this->fill();
/**
* 渲染模板
*
* @return string
*/
public function render()
{
$this->fill();
return parent::render();
}
return parent::render();
}
/**
* 写入数据.
*
* @return void
*/
public function fill()
{
$this->withContent(44.9, 28.6);
/**
* 写入数据.
*
* @return void
*/
public function fill()
{
$gender = User::query()->where('agent_id', Admin::user()->id)->pluck('gender');
$man = $woman = $unkonw = 0;
foreach ($gender as $v) {
if ($v == 1) {
$man++;
} elseif ($v == 2) {
$woman++;
} else {
$unkonw++;
}
}
$this->withContent($man, $woman, $unkonw);
// 图表数据
$this->withChart([44.9, 28.6]);
}
// 图表数据
$this->withChart([$man,$woman, $unkonw]);
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
return $this->chart([
'series' => $data
]);
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
return $this->chart([
'series' => $data
]);
}
/**
* 设置卡片头部内容.
*
* @param mixed $desktop
* @param mixed $mobile
*
* @return $this
*/
protected function withContent($desktop, $mobile)
{
$blue = Admin::color()->alpha('blue2', 0.5);
/**
* 设置卡片头部内容.
*
* @param mixed $desktop
* @param mixed $mobile
*
* @return $this
*/
protected function withContent($desktop, $mobile, $unkonw)
{
$blue = Admin::color()->alpha('blue2', 0.5);
$yellow = Admin::color()->yellow();
$style = 'margin-bottom: 8px';
$labelWidth = 120;
$style = 'margin-bottom: 8px';
$labelWidth = 120;
return $this->content(
<<<HTML
return $this->content(
<<<HTML
<div class="d-flex pl-1 pr-1 pt-1" style="{$style}"> <div class="d-flex pl-1 pr-1 pt-1" style="{$style}">
<div style="width: {$labelWidth}px"> <div style="width: {$labelWidth}px">
<i class="fa fa-circle text-primary"></i> {$this->labels[0]} <i class="fa fa-circle text-primary"></i> {$this->labels[0]}
@ -94,7 +106,13 @@ class NewDevices extends Donut
</div> </div>
<div>{$mobile}</div> <div>{$mobile}</div>
</div> </div>
<div class="d-flex pl-1 pr-1" style="{$style}">
<div style="width: {$labelWidth}px">
<i class="fa fa-circle" style="color: $yellow"></i> {$this->labels[2]}
</div>
<div>{$unkonw}</div>
</div>
HTML HTML
);
}
);
}
} }

189
app/AdminAgent/Metrics/Examples/NewUsers.php

@ -2,107 +2,118 @@
namespace App\AdminAgent\Metrics\Examples; namespace App\AdminAgent\Metrics\Examples;
use App\Common\DataTime;
use App\Models\User;
use Carbon\Carbon;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Line; use Dcat\Admin\Widgets\Metrics\Line;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
class NewUsers extends Line class NewUsers extends Line
{ {
/**
* 初始化卡片内容
*
* @return void
*/
protected function init()
{
parent::init();
/**
* 初始化卡片内容
*
* @return void
*/
protected function init()
{
parent::init();
$this->title('New Users');
$this->dropdown([
'7' => 'Last 7 Days',
'28' => 'Last 28 Days',
'30' => 'Last Month',
'365' => 'Last Year',
]);
}
$this->title('新增用户');
$this->dropdown([
//'day' => '本日',
'week' => '本周',
'month' => '本月',
//'year' => '今年',
]);
}
/**
* 处理请求
*
* @param Request $request
*
* @return mixed|void
*/
public function handle(Request $request)
{
$generator = function ($len, $min = 10, $max = 300) {
for ($i = 0; $i <= $len; $i++) {
yield mt_rand($min, $max);
}
};
/**
* 处理请求
*
* @param Request $request
*
* @return mixed|void
*/
public function handle(Request $request)
{
$count = User::query()->where('agent_id', Admin::user()->id);
$user = User::query()
->select('*')
->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"));
switch ($request->get('option')) {
case 'day':
$count->whereDate('created_at', Carbon::today());
$user->whereDate('created_at', Carbon::today());
break;
case 'week':
$time = DataTime::beginAndEnd('week');
$count->whereBetween('created_at', $time);
$user->whereBetween('created_at', $time);
break;
case 'month':
$count->whereMonth('created_at', Carbon::now()->month);
$user->whereMonth('created_at', Carbon::now()->month);
break;
case 'year':
$count->whereYear('created_at', Carbon::now()->year);
$user->whereYear('created_at', Carbon::now()->year);
break;
default:
$time = DataTime::beginAndEnd('week');
$count->whereBetween('created_at', $time);
$user->whereBetween('created_at', $time);
}
$user = $user->where('agent_id', Admin::user()->id)
->limit(30)
->groupBy('statistics_time')
->get()
->toArray();
$count = $count->count();
$this->withContent($count);
// 图表数据
$this->chartLabels(Arr::pluck($user, 'statistics_time'));
$this->withChart(Arr::pluck($user, 'count_id'));
}
switch ($request->get('option')) {
case '365':
// 卡片内容
$this->withContent(mt_rand(1000, 5000).'k');
// 图表数据
$this->withChart(collect($generator(30))->toArray());
break;
case '30':
// 卡片内容
$this->withContent(mt_rand(400, 1000).'k');
// 图表数据
$this->withChart(collect($generator(30))->toArray());
break;
case '28':
// 卡片内容
$this->withContent(mt_rand(400, 1000).'k');
// 图表数据
$this->withChart(collect($generator(28))->toArray());
break;
case '7':
default:
// 卡片内容
$this->withContent('89.2k');
// 图表数据
$this->withChart([28, 40, 36, 52, 38, 60, 55,]);
}
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
return $this->chart([
'series' => [
[
'name' => $this->title,
'data' => $data,
],
],
]);
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart(array $data)
{
return $this->chart([
'series' => [
[
'name' => $this->title,
'data' => $data,
],
],
]);
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px"> <div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2> <h2 class="ml-1 font-lg-1">{$content}</h2>
<span class="mb-0 mr-1 text-80">{$this->title}</span> <span class="mb-0 mr-1 text-80">{$this->title}</span>
</div> </div>
HTML HTML
);
}
);
}
} }

160
app/AdminAgent/Metrics/Examples/OrderExamples.php

@ -0,0 +1,160 @@
<?php
namespace App\AdminAgent\Metrics\Examples;
use App\Models\Order;
use Carbon\Carbon;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\RadialBar;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
class OrderExamples extends RadialBar
{
/**
* 初始化卡片内容
*/
protected function init()
{
parent::init();
$this->title('订单统计');
$this->height(400);
$this->chartHeight(300);
}
/**
* 处理请求
*
* @param Request $request
*
* @return mixed|void
*/
public function handle(Request $request)
{
//总订单数
$count = Order::query()->where('agent_id',Admin::user()->id)->count();
// 卡片内容
$this->withContent($count);
// 卡片底部
//今日订单
$countToday = Order::query()->where('agent_id',Admin::user()->id)->whereDate('created_at',Carbon::today())->count();
$countYesterday = Order::query()->where('agent_id',Admin::user()->id)->whereDate('created_at',Carbon::yesterday())->count();
$price = Order::query()->where('agent_id',Admin::user()->id)->whereDate('created_at',Carbon::today())->sum('price');
$this->withFooter($countToday, $countYesterday, $price);
$order = Order::query()
->select('*')
->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"))
->where('agent_id',Admin::user()->id)
->limit(30)
->orderBy('created_at', 'asc')
->groupBy('statistics_time')
->get()
->toArray();
$categories = Arr::pluck($order,'statistics_time');
// 图表数据
$data = Arr::pluck($order,'count_id');
$this->withChart($data,$categories);
}
/**
* 设置图表数据.
*
* @param int $data
*
* @return $this
*/
public function withChart(array $data,array $categories)
{
return $this->chart([
'series' => [
[
'name' => '订单量',
'data' => $data
]
],
'chart' => [
'type' => 'line',
'zoom' => [
'enabled' => false
],
'toolbar' => [
'show' => false
],
],
'colors' => [
Admin::color()->green(),
],
'dataLabels' => [
'enabled' => false
],
'stroke' => [
'curve' => 'smooth'
],
'legend' => [
'position' =>'top',
//'horizontalAlign' => 'right'
],
'fill' => [
'opacity' => 1,
'type' => 'solid',
],
'xaxis' => [
'categories' => $categories,
]
]);
}
/**
* 卡片内容
*
* @param string $content
*
* @return $this
*/
public function withContent($content)
{
return $this->content(
<<<HTML
<div class="d-flex flex-column flex-wrap text-left p-1">
<h1 class="font-lg-2 mt-2 mb-0">{$content}</h1>
<small>总订单数</small>
</div>
HTML
);
}
/**
* 卡片底部内容.
*
* @param string $new
* @param string $open
* @param string $response
*
* @return $this
*/
public function withFooter($new, $open, $response)
{
return $this->footer(
<<<HTML
<div class="d-flex justify-content-between p-1" style="padding-top: 0!important;">
<div class="text-center">
<p>今日订单</p>
<span class="font-lg-1">{$new}</span>
</div>
<div class="text-center">
<p>昨日订单</p>
<span class="font-lg-1">{$open}</span>
</div>
<div class="text-center">
<p>今日成交()</p>
<span class="font-lg-1">{$response}</span>
</div>
</div>
HTML
);
}
}

179
app/AdminAgent/Metrics/Examples/SalesExamples.php

@ -0,0 +1,179 @@
<?php
namespace App\AdminAgent\Metrics\Examples;
use App\Common\OrderStatus;
use App\Models\Order;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Bar;
use Illuminate\Support\Facades\DB;
class SalesExamples extends Bar
{
protected $labels = [];
protected $colors;
/**
* 初始化卡片内容
*/
protected function init()
{
parent::init();
$color = Admin::color();
$this->colors = [$color->green(), $color->red(), $color->yellow(), $color->orange1(), $color->dark90(), $color->dark70(), $color->custom()];
$this->contentWidth(3, 9);
$this->title('销售排行');
//$this->chartPullRight = false;
//$this->subTitle('Last 30 days');
$this->height = 280;
$this->chartHeight = 250;
// 设置图表颜色
$this->chartColors($this->colors);
}
/**
* 渲染模板
*
* @return string
*/
public function render()
{
$this->fill();
return parent::render();
}
/**
* 写入数据.
*
* @return void
*/
public function fill()
{
$warehouse = Order::query()
->with('agentProduct')
->select('*')
->addSelect(DB::raw('count(id) as count_id'))
->where([
//'status' => OrderStatus::SUCCESS,
'agent_id' => Admin::user()->id,
])
->orderByDesc('count_id')
->groupBy('agent_product_id')
->limit(5)
->get();
//$warehouse = [];
$data = $categories = [];
foreach ($warehouse as $v) {
array_push($this->labels, $v->title);
array_push($data, $v->count_id);
$categories[] = [$v->title];
}
$this->withChart($data, $categories);
//$this->chartLabels($this->labels);
$count = Order::query()
->where([
//'status' => OrderStatus::SUCCESS,
'agent_id' => Admin::user()->id,
])
->count();
//$count = 0;
if ($count > 0) {
array_unshift($data, $count);
array_unshift($this->labels, '总销售量');
$color = Admin::color();
array_unshift($this->colors, $color->primary());
}
$this->withContent($data);
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public function withChart($data, $categories)
{
return $this->chart([
'series' => [[
'name' => '出库数量',
'data' => $data
]],
'chart' => [
//'width' => '180%',
'type' => 'bar',
'events' => [
],
'toolbar' => ['show' => false],
],
'colors' => $this->colors,
'plotOptions' => [
'bar' => [
//'columnWidth' => '45%',
'distributed' => true,
]
],
'dataLabels' => [
'enabled' => false
],
'legend' => [
'show' => false
],
'xaxis' => [
'categories' =>
$categories
,
'labels' => [
'show' => false,
'style' => [
'colors' => $this->colors,
'fontSize' => '12px'
]
],
],
'yaxis' => [
'show' => false
],
'tooltip' => [
'x' => ['show' => true],
],
]);
}
/**
* 设置卡片头部内容.
*
* @param mixed $desktop
* @param mixed $mobile
*
* @return $this
*/
protected function withContent($data)
{
$content = '';
foreach ($data as $k => $v) {
$content .= '
<div class="d-flex pl-1 mt-2">
<div style="width:100%;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
<i class="fa fa-circle" style="color:' . $this->colors[$k] . '"></i> ' . $this->labels[$k] . '
<div style="display:inline-block">' . $v . '</div>
</div>
</div>
';
}
return $this->content(
<<<HTML
$content
HTML
);
}
}

78
app/Common/DataTime.php

@ -0,0 +1,78 @@
<?php
namespace App\Common;
class DataTime
{
/**
* 处理时间为空时的时间显示格式
* @param $time
* @return string
*/
public static function format($time)
{
if (is_numeric($time)&&$time>0) {
return date('Y-m-d H:i', $time);
} elseif (empty($time) || $time->format('Y-m-d') == '1970-01-01') {
return '-';
}
return $time->format('Y-m-d H:i');
}
/**
* 查询时间范围
* @param $option
* @return array
*/
public static function beginAndEnd($option)
{
$t = time();
switch ($option) {
case 'today':
$beginTime = date('Y-m-d H:i:s', mktime(0, 0, 0, date("m", $t), date("d", $t), date("Y", $t)));
$endTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1);
break;
case 'yesterday':
$beginTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), date('d') - 1, date('Y')));
$endTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), date('d'), date('Y')) - 1);
break;
case '7day':
$beginTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), date('d') - 7, date('Y')));
$endTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1);
break;
case 'week':
$timestamp = mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y'));
$beginTime = date('Y-m-d H:i:s', $timestamp);
//本周结束日期
$timestamp = mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y'));
$endTime= date('Y-m-d H:i:s',$timestamp);
break;
case 'last_week':
$beginTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date("m"), date("d") - date("w") + 1 - 7, date("Y")));
$endTime = date('Y-m-d H:i:s',mktime(23, 59, 59, date("m"), date("d") - date("w") + 7 - 7, date("Y")));
break;
case 'month':
$beginTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m'), 1, date('Y')));
$endTime = date('Y-m-d H:i:s',mktime(23, 59, 59, date('m'), date('t'), date('Y')));
break;
case 'last_month':
$beginTime = date('Y-m-d H:i:s',mktime(0, 0, 0, date('m') - 1, 1, date('Y')));
$endTime = date('Y-m-d H:i:s',strtotime(date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), 0, date("Y")))));
break;
default:
$searchTime = request()->input('created_at');
if ($searchTime){
$beginTime = date('Y-m-d H:i:s',strtotime($searchTime['start']));
$endTime = date('Y-m-d H:i:s',strtotime($searchTime['end']));
}else{
$beginTime = 0;
$endTime = 999999999999;
}
break;
}
return [$beginTime,$endTime];
}
}

6
app/Http/Controllers/Api/UserController.php

@ -60,6 +60,12 @@ class UserController extends Controller
if (!empty($decryptedData['purePhoneNumber'])) { if (!empty($decryptedData['purePhoneNumber'])) {
$user->mobile = $decryptedData['purePhoneNumber']; $user->mobile = $decryptedData['purePhoneNumber'];
} }
$user->unionid = $decryptedData['unionId'] ?? '';
$user->country = $decryptedData['country'] ?? '';
$user->province = $decryptedData['province'] ?? '';
$user->city = $decryptedData['city'] ?? '';
$user->gender = $decryptedData['gender'] ?? 0;
$user->language = $decryptedData['language'] ?? '';
$user->save(); $user->save();
} catch (\Exception | DecryptException $e) { } catch (\Exception | DecryptException $e) {
return $this->error($e->getMessage()); return $this->error($e->getMessage());

2
config/database.php

@ -56,7 +56,7 @@ return [
'collation' => 'utf8mb4_unicode_ci', 'collation' => 'utf8mb4_unicode_ci',
'prefix' => '', 'prefix' => '',
'prefix_indexes' => true, 'prefix_indexes' => true,
'strict' => true,
'strict' => false,
'engine' => null, 'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([ 'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),

43
resources/views/admin/pages/agent-home.blade.php

@ -0,0 +1,43 @@
<style>
.dashboard-title .links {
text-align: center;
margin-bottom: 2.5rem;
}
.dashboard-title .links > a {
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
color: #fff;
}
.dashboard-title h1 {
font-weight: 200;
font-size: 2.5rem;
}
.dashboard-title .avatar {
background: #fff;
border: 2px solid #fff;
width: 70px;
height: 70px;
}
</style>
<div class="dashboard-title card bg-primary">
<div class="card-body">
<div class="text-center ">
<img class="avatar img-circle shadow mt-1" src="{{config('filesystems.disks.oss.cdnDomain').'/'.$admin->avatar}}">
<div class="text-center mb-1">
<h1 class="mb-3 mt-2 text-white">{{$admin->name}}</h1>
<div class="links">
<a href="{{ admin_url('/auth/users') }}">用户管理</a>
<a href="{{ admin_url('/order/list') }}" id="doc-link">订单管理</a>
<a href="{{ admin_url('/advertising/list') }}" id="demo-link">广告管理</a>
<a href="{{ admin_url('/product/list') }}" id="demo-link">产品管理</a>
</div>
</div>
</div>
</div>
</div>
Loading…
Cancel
Save