PHP交易流水按照日、周、月汇总统计
所属分类:PHP之旅 | 最后更新于:2020-12-09 15:46:37 | 阅读次数:208

PHP交易流水统计,可以分页,日、周、月三种统计,不限时间

参数 说明
page
limit 条数
type 统计类型(day、week、month)
/** * 流水 * @param $where * @return array */ public static function trans($where) { $res = []; $n = $where['page'] * $where['limit']; for ($i = $n - $where['limit']; $i<$n; $i++) { $tmp = []; switch ($where['type']) { case 'day': $beginTime = mktime(0,0,0,date("m"),date("d") - $i,date("Y")); $endTime = mktime(0,0,0,date("m"),date("d")+1 - $i,date("Y"))-1; $tmp['dat'] = date("Y-m-d",$beginTime); break; case 'week': $beginTime = mktime(0,0,0,date('m'),date('d') - date('w') + 1 - 7 * $i, date('Y')); $endTime = mktime(23,59,59,date('m'),date('d') - date('w') + 7 - 7 * $i, date('Y')); $tmp['dat'] = date("Y-m-d",$beginTime) . " - " . date("Y-m-d",$endTime); break; case 'month': $beginTime = mktime(0,0,0, date('m') - $i,1, date('Y')); $endTime = mktime(0,0,0, date('m') - $i + 1, 1, date('Y'))-1; $tmp['dat'] = date("Y-m",$beginTime); break; } $tmp['money'] = self::collectModel([$beginTime,$endTime],isset($where['store_id']) ? $where['store_id'] : 0)->sum("payamount"); $tmp['count'] = self::collectModel([$beginTime,$endTime],isset($where['store_id']) ? $where['store_id'] : 0)->count(); $res[] = $tmp; } return $res; }

PHP获取今天、昨天、前三天、本周、上周、本月、上个月、上个季度、本季度、本年时间戳、上一年时间戳

文章作者:cfn
本文链接:
500字剩余