//近七日付款金额统计 order_type 类型 5 8 9 11
public function data()
{
date_default_timezone_set('PRC');
// 近七天 第一天第一一秒 2019-11-03 00:00:00
$startToday = mktime(-144, 0, 0, date('m'), date('d'), date('Y'));
//近七日 第1-7天 11-03 0点到 12.59
$d1 = $this->countTime('-120', '0', '-1');
$d2 = $this->countTime('-96', '0', '-1');
$d3 = $this->countTime('-72', '0', '-1');
$d4 = $this->countTime('-48', '0', '-1');
$d5 = $this->countTime('-24', '0', '-1');
$d6 = $this->countTime('0', '0', '-1');
$d7 = $this->countTime('24', '0', '-1');
//结果 组成array
$money = [];
$money[] = $this->info($startToday, $d1);
$money[] = $this->info($d1, $d2);
$money[] = $this->info($d2, $d3);
$money[] = $this->info($d3, $d4);
$money[] = $this->info($d4, $d5);
$money[] = $this->info($d5, $d6);
$money[] = $this->info($d6, $d7);
$date = [];
$date[] = date('m-d', $d1);
$date[] = date('m-d', $d2);
$date[] = date('m-d', $d3);
$date[] = date('m-d', $d4);
$date[] = date('m-d', $d5);
$date[] = date('m-d', $d6);
$date[] = date('m-d', $d7);
return [$money, $date];
}
// 传的是 时间戳 不是 2019-11-09 23:59:59 时间戳更精确
public function info($a, $b)
{
return Db::table('ec_shop_order')
->where('order_type', 'in', '5,8,9,11')
->whereTime('ctime', 'between', [$a, $b])
->sum('order_money');
}
//计算时间 近七日 第一天 11-03 0点到 12.59
public function countTime($h, $m, $s)
{
return mktime($h, $m, $s, date('m'), date('d'), date('Y'));
}
php时间的计算
最新推荐文章于 2021-03-26 03:19:31 发布