You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
6.0 KiB
174 lines
6.0 KiB
<?php
|
|
|
|
namespace App\Admin\Metrics\Examples\Order;
|
|
|
|
|
|
use App\Models\ImsCjdcOrder;
|
|
use App\Models\ImsCjdcOrderMain;
|
|
use Dcat\Admin\Widgets\Metrics\Card;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OrderData extends Card
|
|
{
|
|
protected $params;
|
|
public function __construct($title=null,$data=[])
|
|
{
|
|
$this->params = $data;
|
|
parent::__construct($title, null);
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
parent::init(); // TODO: Change the autogenerated stub
|
|
$this->dropdown([
|
|
'1' => '今日',
|
|
'-1' => '昨日',
|
|
'7' => '最近7天',
|
|
'w' => '本周',
|
|
'lw' => '上周',
|
|
'30' => '本月',
|
|
'-30' => '上月'
|
|
]);
|
|
|
|
}
|
|
|
|
public function handle(Request $request)
|
|
{
|
|
$params = $request->get('params');//参数选项
|
|
$option = $request->get('option');//数据选项
|
|
//获取订单数据
|
|
$result = $this->getOrderData($params,$option);
|
|
$this->content($result);
|
|
}
|
|
|
|
/**
|
|
* 查询结果
|
|
* @param $params
|
|
* @param $option
|
|
* @return int
|
|
*/
|
|
public function getOrderData($params,$option)
|
|
{
|
|
//如果市场id存在
|
|
$buildData = $this->buildData();
|
|
if ($params['market_id']) {//是否存在市场id
|
|
if (is_array($params['market_id'])) {
|
|
$buildData = $buildData->whereIn('lanzu_order_main.market_id',$params['market_id']);
|
|
} else {
|
|
$buildData = $buildData->where('lanzu_order_main.market_id',$params['market_id']);
|
|
}
|
|
}
|
|
if ($params['user_type']=='lanzu_cs'||$params['user_type']=='lanzu_biz'){//社区角色
|
|
if ($params['condition']==1){//获取时间范围
|
|
list($beginTime,$endTime) = $this->beginAndEnd($option);
|
|
//>>2.构建数据模型
|
|
if ($params['user_ids']){
|
|
$buildData = $buildData->whereIn('lanzu_order_main.user_id',$params['user_ids']);
|
|
}else{
|
|
return 0;
|
|
}
|
|
$buildData = $buildData
|
|
->leftJoin('lanzu_user_relation_bind','lanzu_user_relation_bind.user_id','lanzu_order_main.user_id')
|
|
->whereRaw('lanzu_order_main.created_at > lanzu_user_relation_bind.created_at')
|
|
->whereBetween('lanzu_order_main.created_at',[$beginTime,$endTime]);
|
|
}
|
|
}elseif ($params['user_type']=='market_service'||$params['user_type']=='lanzu_mp'){//市场服务站角色 及服务商
|
|
if ($params['condition']==1){//获取时间范围
|
|
list($beginTime,$endTime) = $this->beginAndEnd($option);
|
|
//>>2.构建数据模型
|
|
$buildData = $buildData->whereBetween('created_at',[$beginTime,$endTime]);
|
|
}
|
|
}
|
|
if ($params['data_type']=='count_user'){
|
|
$result = $buildData->pluck('lanzu_order_main.user_id')
|
|
->groupBy('lanzu_order_main.user_id')
|
|
->toArray();
|
|
$result = count($result);
|
|
}elseif ($params['data_type']=='number'){
|
|
$result = $buildData->count();
|
|
}elseif ($params['data_type']=='amount'){
|
|
$result = $buildData->sum('money');
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 查询时间范围
|
|
* @param $option
|
|
* @return array
|
|
*/
|
|
public function beginAndEnd($option)
|
|
{
|
|
switch ($option) {
|
|
case '1':
|
|
$beginTime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
|
|
$endTime = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
|
|
break;
|
|
case '-1':
|
|
$beginTime = mktime(0, 0, 0, date('m'), date('d') - 1, date('Y'));
|
|
$endTime = mktime(0, 0, 0, date('m'), date('d'), date('Y')) - 1;
|
|
break;
|
|
case '7':
|
|
$beginTime = mktime(0, 0, 0, date('m'), date('d') - 7, date('Y'));
|
|
$endTime = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
|
|
break;
|
|
case 'w':
|
|
$beginTime = mktime(0, 0, 0, date("m"), date("d") - date("w") + 1, date("Y"));
|
|
$endTime = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y"));
|
|
break;
|
|
case 'lw':
|
|
$beginTime = mktime(0, 0, 0, date("m"), date("d") - date("w") + 1 - 7, date("Y"));
|
|
$endTime = mktime(23, 59, 59, date("m"), date("d") - date("w") + 7 - 7, date("Y"));
|
|
break;
|
|
case '30':
|
|
$beginTime = mktime(0, 0, 0, date('m'), 1, date('Y'));
|
|
$endTime = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
|
|
break;
|
|
case '-30':
|
|
$beginTime = mktime(0, 0, 0, date('m') - 1, 1, date('Y'));
|
|
$endTime = strtotime(date("Y-m-d H:i:s", mktime(23, 59, 59, date("m"), 0, date("Y"))));
|
|
break;
|
|
default:
|
|
$beginTime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
|
|
$endTime = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
|
|
break;
|
|
}
|
|
return [$beginTime,$endTime];
|
|
}
|
|
|
|
/**
|
|
* 构建数据模型
|
|
* @param $condition
|
|
* @return mixed
|
|
*/
|
|
public function buildData()
|
|
{
|
|
$build = ImsCjdcOrderMain
|
|
::whereIn('state', [3, 4, 5, 10])
|
|
->where('type',1);
|
|
return $build;
|
|
}
|
|
|
|
// 传递自定义参数到 handle 方法
|
|
public function parameters(): array
|
|
{
|
|
return [
|
|
'params'=>$this->params
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 渲染卡片内容
|
|
* @return string
|
|
*/
|
|
public function renderContent()
|
|
{
|
|
$content = parent::renderContent();
|
|
return <<<HTML
|
|
<div class="d-flex justify-content-between bg-primary align-items-center mt-1" style="margin-bottom: 2px">
|
|
<h2 class="ml-1 font-large-1">{$content}</h2>
|
|
</div>
|
|
HTML;
|
|
}
|
|
}
|