- Rejected
+ 已完成
{$rejected}
diff --git a/app/AdminAgent/Metrics/Examples/SalesExamples.php b/app/AdminAgent/Metrics/Examples/SalesExamples.php
index 6097141..665a1ea 100644
--- a/app/AdminAgent/Metrics/Examples/SalesExamples.php
+++ b/app/AdminAgent/Metrics/Examples/SalesExamples.php
@@ -57,7 +57,7 @@ class SalesExamples extends Bar
->select('*')
->addSelect(DB::raw('count(id) as count_id'))
->where([
- //'status' => OrderStatus::SUCCESS,
+ 'status' => OrderStatus::SUCCESS,
'agent_id' => Admin::user()->id,
])
->orderByDesc('count_id')
@@ -77,7 +77,7 @@ class SalesExamples extends Bar
$count = Order::query()
->where([
- //'status' => OrderStatus::SUCCESS,
+ 'status' => OrderStatus::SUCCESS,
'agent_id' => Admin::user()->id,
])
->count();
@@ -103,7 +103,7 @@ class SalesExamples extends Bar
return $this->chart([
'series' => [[
- 'name' => '出库数量',
+ 'name' => '销量',
'data' => $data
]],
'chart' => [
diff --git a/app/AdminSupplier/Controllers/HomeController.php b/app/AdminSupplier/Controllers/HomeController.php
index eef3f9f..28528bc 100644
--- a/app/AdminSupplier/Controllers/HomeController.php
+++ b/app/AdminSupplier/Controllers/HomeController.php
@@ -4,7 +4,7 @@ namespace App\AdminSupplier\Controllers;
use App\AdminSupplier\Metrics\Examples;
use App\Http\Controllers\Controller;
-use Dcat\Admin\Http\Controllers\Dashboard;
+use Dcat\Admin\Admin;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
@@ -13,13 +13,23 @@ class HomeController extends Controller
{
public function index(Content $content)
{
+ Admin::style(
+ <<
header('仪表盘')
->description('数据详情')
->body(function (Row $row) {
$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) {
@@ -28,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());
});
});
diff --git a/app/AdminSupplier/Metrics/Examples/Dashboard.php b/app/AdminSupplier/Metrics/Examples/Dashboard.php
new file mode 100755
index 0000000..c44f44f
--- /dev/null
+++ b/app/AdminSupplier/Metrics/Examples/Dashboard.php
@@ -0,0 +1,13 @@
+ Admin::user()]);
+ }
+}
diff --git a/app/AdminSupplier/Metrics/Examples/NewDevices.php b/app/AdminSupplier/Metrics/Examples/NewDevices.php
index db46e56..e5e45fc 100644
--- a/app/AdminSupplier/Metrics/Examples/NewDevices.php
+++ b/app/AdminSupplier/Metrics/Examples/NewDevices.php
@@ -2,86 +2,107 @@
namespace App\AdminSupplier\Metrics\Examples;
+use App\Common\AgentType;
+use App\Common\ProductStatus;
+use App\Models\Agent as AgentModel;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Donut;
class NewDevices extends Donut
{
- protected $labels = ['Desktop', 'Mobile'];
+ protected $labels = [];
- /**
- * 初始化卡片内容
- */
- protected function init()
- {
- parent::init();
+ /**
+ * 初始化卡片内容
+ */
+ protected function init()
+ {
+ parent::init();
+ $this->labels = array_values(AgentType::array());
+ $color = Admin::color();
+ $colors = [$color->primary(), $color->alpha('blue2', 0.5),Admin::color()->yellow()];
- $color = Admin::color();
- $colors = [$color->primary(), $color->alpha('blue2', 0.5)];
+ $this->title('代理商类型');;
+ $this->chartLabels($this->labels);
+ // 设置图表颜色
+ $this->chartColors($colors);
+ }
- $this->title('New Devices');
- $this->subTitle('Last 30 days');
- $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()
+ {
+ $agent = AgentModel::whereHas('agentProduct', function($query) {
+ //只统计在售产品的代理商
+ return $query->where('status', ProductStatus::ON_SALE)
+ ->whereHas('product', function ($query) {
+ return $query->where(['supplier_id' => Admin::user()->id, 'status' => ProductStatus::ON_SALE]);
+ });
+ });
+ $agent = $agent->pluck('type');
+ $operator = $supplier = $cluster = 0;
+ foreach ($agent as $v) {
+ if ($v == AgentType::OPERATOR) {
+ $operator++;
+ } elseif ($v == AgentType::SUPPLIER) {
+ $supplier++;
+ } elseif($v == AgentType::CLUSTER) {
+ $cluster++;
+ }
+ }
+ $this->withContent($operator, $supplier, $cluster);
- /**
- * 写入数据.
- *
- * @return void
- */
- public function fill()
- {
- $this->withContent(44.9, 28.6);
+ // 图表数据
+ $this->withChart([$operator,$supplier, $cluster]);
+ }
- // 图表数据
- $this->withChart([44.9, 28.6]);
- }
+ /**
+ * 设置图表数据.
+ *
+ * @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(
- <<content(
+ <<
{$this->labels[0]}
@@ -94,7 +115,13 @@ class NewDevices extends Donut
{$mobile}
+
+
+ {$this->labels[2]}
+
+
{$unkonw}
+
HTML
- );
- }
+ );
+ }
}
diff --git a/app/AdminSupplier/Metrics/Examples/NewUsers.php b/app/AdminSupplier/Metrics/Examples/NewUsers.php
index 817d047..a95d474 100644
--- a/app/AdminSupplier/Metrics/Examples/NewUsers.php
+++ b/app/AdminSupplier/Metrics/Examples/NewUsers.php
@@ -2,107 +2,116 @@
namespace App\AdminSupplier\Metrics\Examples;
+use App\Common\DataTime;
+use App\Models\OrderProductItem;
+use App\Models\User;
+use Carbon\Carbon;
+use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Metrics\Line;
use Illuminate\Http\Request;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\DB;
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)
+ {
+ $order = OrderProductItem::query()
+ ->where('supplier_id',Admin::user()->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,]);
- }
- }
+ switch ($request->get('option')) {
+ case 'day':
+ $order->whereDate('created_at', Carbon::today());
+ break;
+ case 'week':
+ $time = DataTime::beginAndEnd('week');
+ $order->whereBetween('created_at', $time);
+ break;
+ case 'month':
+ $order->whereMonth('created_at', Carbon::now()->month);
+ break;
+ case 'year':
+ $order->whereYear('created_at', Carbon::now()->year);
+ break;
+ default:
+ $time = DataTime::beginAndEnd('week');
+ $order->whereBetween('created_at', $time);
+ }
+ $countOrder = clone $order;
+ $count = $order->sum('price');
+ $this->withContent($count);
- /**
- * 设置图表数据.
- *
- * @param array $data
- *
- * @return $this
- */
- public function withChart(array $data)
- {
- return $this->chart([
- 'series' => [
- [
- 'name' => $this->title,
- 'data' => $data,
- ],
- ],
- ]);
- }
+ $countOrder = $countOrder->select('*')
+ ->addSelect(DB::raw("sum(price) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"))
+ ->limit(30)
+ ->groupBy('statistics_time')
+ ->get()
+ ->toArray();
+ // 图表数据
+ $this->chartLabels(Arr::pluck($countOrder, 'statistics_time'));
+ $this->withChart(Arr::pluck($countOrder, 'sum_price'));
+ }
- /**
- * 设置卡片内容.
- *
- * @param string $content
- *
- * @return $this
- */
- public function withContent($content)
- {
- return $this->content(
- <<chart([
+ 'series' => [
+ [
+ 'name' => $this->title,
+ 'data' => $data,
+ ],
+ ],
+ ]);
+ }
+
+ /**
+ * 设置卡片内容.
+ *
+ * @param string $content
+ *
+ * @return $this
+ */
+ public function withContent($content)
+ {
+ return $this->content(
+ <<
{$content}
{$this->title}
HTML
- );
- }
+ );
+ }
}
diff --git a/app/AdminSupplier/Metrics/Examples/OrderExamples.php b/app/AdminSupplier/Metrics/Examples/OrderExamples.php
new file mode 100644
index 0000000..71626ce
--- /dev/null
+++ b/app/AdminSupplier/Metrics/Examples/OrderExamples.php
@@ -0,0 +1,168 @@
+title('订单统计');
+ $this->height(400);
+ $this->chartHeight(300);
+ }
+
+ /**
+ * 处理请求
+ *
+ * @param Request $request
+ *
+ * @return mixed|void
+ */
+ public function handle(Request $request)
+ {
+ //总订单数
+ $count = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->count();
+ // 卡片内容
+ $this->withContent($count);
+ // 卡片底部
+ //今日订单
+ $countToday = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereDate('created_at',Carbon::today())->count();
+ $countYesterday = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereDate('created_at',Carbon::yesterday())->count();
+ $price = OrderProductItem::query()
+ ->where('supplier_id',Admin::user()->id)
+ ->whereHas('order',function ($query) {
+ $query->where('status',OrderStatus::SUCCESS);
+ })
+ ->whereDate('created_at',Carbon::today())
+ ->sum('price');
+ $this->withFooter($countToday, $countYesterday, $price);
+ $order = OrderProductItem::query()
+ ->select('*')
+ ->addSelect(DB::raw("COUNT(id) as count_id,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"))
+ ->where('supplier_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(
+ <<
+