Browse Source

首页

develop
lemon 4 years ago
parent
commit
f1302bccd0
  1. 8
      app/AdminAgent/Controllers/HomeController.php
  2. 152
      app/AdminAgent/Metrics/Examples/NewDevices.php
  3. 179
      app/AdminAgent/Metrics/Examples/SalesExamples.php
  4. 6
      app/Http/Controllers/Api/UserController.php

8
app/AdminAgent/Controllers/HomeController.php

@ -18,7 +18,11 @@ class HomeController extends Controller
.col-sm-10.d-flex{
display: inline-block !important;
}
CSS );
.col-sm-9.d-flex{
display: inline-block !important;
}
CSS
);
return $content
->header('代理商后台')
->description('数据详情')
@ -34,7 +38,7 @@ class HomeController extends Controller
$row->column(6, new Examples\NewDevices());
});
$column->row(new Examples\Sessions());
$column->row(new Examples\SalesExamples());
$column->row(new Examples\ProductOrders());
});
});

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

@ -2,86 +2,98 @@
namespace App\AdminAgent\Metrics\Examples;
use App\Models\User;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Donut;
use Illuminate\Support\Arr;
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 style="width: {$labelWidth}px">
<i class="fa fa-circle text-primary"></i> {$this->labels[0]}
@ -94,7 +106,13 @@ class NewDevices extends Donut
</div>
<div>{$mobile}</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
);
}
);
}
}

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
);
}
}

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

@ -60,6 +60,12 @@ class UserController extends Controller
if (!empty($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();
} catch (\Exception | DecryptException $e) {
return $this->error($e->getMessage());

Loading…
Cancel
Save