【发布时间】:2014-12-25 04:46:28
【问题描述】:
作为 Laravel 的新手,我对日期格式化程序和刀片模板有些疑问。
我写了一个以正确方式执行的查询, 以下是我的 Eloquent SQL 查询。
public function orderbyweek()
{
$orderbyweek = DB::table('sales_flat_order_items as s')
->leftJoin('sales_flat_orders as w', 'w.entity_id','=','s.order_id')
->select(array(DB::Raw('sum(s.amount_refunded) as amount_refunded'),
DB::Raw('sum(s.row_total) as row_total'),
DB::Raw('sum(s.discount_amount) as discount_amount'),
DB::Raw('sum(s.tax_amount) as tax_amount'),
DB::Raw('sum(s.qty_ordered) as qty_ordered'),
DB::Raw('sum(w.subtotal) as subtotal'),
DB::Raw('WEEK(w.created_at) week'),
DB::Raw('sum(w.total_invoiced) as total_invoiced'),
DB::Raw('sum(w.shipping_amount) as shipping_amount')
))
->where('qty_canceled','=','0')
->where('status','!=','canceled')
->groupBy('week')
->orderBy('w.created_at')
->get();
return View::make('sales_flat_orders.orderbyweek', compact('orderbyweek'));
}
这向我显示了我想要一周的表格,间隔为 7 天。 那么在我的模板中我需要做什么?如何为此添加日期格式化程序?我在这里做了一些事情:
<table width="100%">
<thead>
<th>DATE</th>
</thead>
@foreach($orderbyweek as $s)
<tr>
<td>{{date("d F, Y",strtotime($s->week))}}</td>
</tr>
@endforeach
</table>
我执行了如下的 sql 查询:
select sum(s.amount_refunded) as amount_refunded, sum(s.row_total) as row_total, sum(s.discount_amount) as discount_amount, sum(s.tax_amount) as tax_amount, sum(s.qty_ordered) as qty_ordered, sum(w.subtotal) as subtotal, WEEK(w.created_at) week, sum(w.total_invoiced) as total_invoiced, sum(w.shipping_amount) as shipping_amount from `sales_flat_order_items` as `s` left join `sales_flat_orders` as `w` on `w`.`entity_id` = `s`.`order_id` where `qty_canceled` = '0' and `status` != 'canceled' group by `week` order by `s`.`created_at` asc
我哪里错了?
我得到了 ordebydate,orderbyyear 也是。但不是按周排序
请帮帮我。
【问题讨论】:
标签: php sql laravel laravel-4 eloquent