这里是 计算时间区间内每周的开始日期和结束日期; http://www.siyueweb.cn/index.php?c=show&id=69442 文章详情:
要统计订单销售金额的周 走势折线图,实现办法如下:
public function ocoin_income_proid_data($proids, $format = 'YmW')
{
$data = [];
$series1 = [];
foreach($proids as $time){
$t = date( $format , strtotime($time['s'] ));
$data[$t] = ['value' => 0, 'label' => $time['s'] ];
$s = $this->ocoin_income( $time['s'], $time['e'] );
$series1[] = $s['income'] ?? 0 ;
}
return [
'xaixs_data' => array_column( array_values($data), 'label'),
'legend_data'=> ['充值收益'],
'series' => [
['name' => '充值收益', 'type'=> 'bar', 'data'=> $series1 ],
]
];
}
下面是统计开始日期到结束日期的 总金额方法:
public function ocoin_income( $start, $end, $iscount = true )
{
$where = [['is_pay','=',1],['is_refund','=','0'],['is_cancel','=',0]];
$orm = OcoinThaliOrder::where( $where )->field('SUM(pay_money) as income')
->whereTime('create_time', 'between', [$start, date('Y-m-d 23:59:59', strtotime( $end))] ) ;
if( $iscount ) {
$orm = OcoinThaliOrder::where( $where )->field('SUM(pay_money) as income')
->whereTime('create_time', 'between', [$start, date('Y-m-d 23:59:59', strtotime( $end))] ) ;
return $orm->find();
}else{
$orm = OcoinThaliOrder::where( $where )->field(' pay_money as income, create_time ' )
->whereTime('create_time', 'between', [$start, date('Y-m-d 23:59:59', strtotime( $end))] ) ;
return $orm->select();
}
}
通过
count_weeks
函数,计算出 例如 2024年03月01日 到 2024年 05月 06日 的 proids 区间;
在通过方法
ocoin_income_proid_data
计算出折线图数据;
好了,本文内容全部结束,感谢您的阅读,希望能帮助到您;