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.
132 lines
5.2 KiB
132 lines
5.2 KiB
<?php
|
|
|
|
|
|
namespace App\Admin\Common;
|
|
|
|
|
|
use App\Models\ImsCjdcOrderMain;
|
|
|
|
class Order
|
|
{
|
|
/**
|
|
* 查询结果
|
|
* @param $params
|
|
* @param $option
|
|
* @return int
|
|
*/
|
|
public static function getOrderData($params,$option)
|
|
{
|
|
//如果市场id存在
|
|
$buildData = self::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) = self::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) = self::beginAndEnd($option);
|
|
//>>2.构建数据模型
|
|
$buildData = $buildData->whereBetween('created_at',[$beginTime,$endTime]);
|
|
}
|
|
}
|
|
if ($params['data_type']=='count_user'){
|
|
$result = $buildData
|
|
->groupBy('lanzu_order_main.user_id')
|
|
->pluck('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 static 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"));
|
|
|
|
//当前日期
|
|
$sdefaultDate = date("Y-m-d");
|
|
//$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
|
|
$first=1;
|
|
//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
|
|
$w=date('w',strtotime($sdefaultDate));
|
|
//获取本周开始日期,如果$w是0,则表示周日,减去 6 天
|
|
$beginTime=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
|
|
//本周结束日期
|
|
$start = date('Y-m-d',$beginTime);
|
|
$endTime=strtotime("$start +6 days")+86399;
|
|
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 static function buildData()
|
|
{
|
|
$build = ImsCjdcOrderMain
|
|
::whereIn('state', [3, 4, 5, 10])
|
|
->where('type',1);
|
|
return $build;
|
|
}
|
|
}
|