日期和时间戳相互转换
$time = time();//当前时间 格式为时间戳
$date = date('Y-m-d H:i:s',$time);//日期格式
$unix = strtotime($date);//时间戳格式
或者可以直接在渲染的页面上进行转换
//控制器代码
$time = time();
$this->assign('time',$time);
//html代码
<div>{$v.time|date="Y-m-d H:i:s"}</div>
按每月统计数据信息
控制器代码
//user_order 用户订单表
//sciencename 景区名称
//price 金额
//create_time 创建时间
//status 状态
$income = Db::name('user_order')
->field("sciencename,SUM(`price`) as total,FROM_UNIXTIME(create_time,'%Y- %m') as months")
->where('status',2)
->group('sciencename,months')
->select();//订单表中当天各个景区的收入
$this->assign('income',$income);
html代码
<table >
<thead>
<td>景区名称</td>
<td>收益金额</td>
<td>日期</td>
</thead>
<tbody>
{foreach $income as $v}
<tr>
<td>{$v.sciencename}</td>
<td>¥{$v.total}</td>
<td>{$v.months}</td>
</tr>
{/foreach}
<tbody>
</table>
效果图:
这样可以统计到每个景区每个月的总收益了
大家根据自己的需求自行修改