求代码帝啊

2016-07-07 15:03 来源:www.chinab4c.com 作者:ecshop专家

sale_general.php里面,我想把利润也弄进去。。。

利润=售价-成本价

已经在数据库里面的goods表跟ord_goods表加多一个字段

现在想把这个利润也弄进销售概况里面去~

无奈能力有限~~~

求代码帝帮忙~

/* 分组统计订单数和销售额:已发货时间为准 */
$format = ($query_type == 'year') ? '%Y' : '%Y-%m';
$sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(oi.shipping_time), '$format') AS period, COUNT(*) AS order_count, " .
"SUM(oi.goods_amount + oi.shipping_fee + oi.insure_fee + oi.pay_fee + oi.pack_fee + oi.card_fee - oi.discount) AS order_amount, " .
"og.order_id, og.goods_number AS goods_num, og.cost_price, og.goods_price, (og.goods_price-og.cost_price)*og.goods_number as gross_profit, oi.order_id ".
"FROM " . $ecs->table('order_info') ." AS oi, ".$ecs->table('order_goods')." AS og ".
" WHERE (order_status = '" . OS_CONFIRMED . "' OR order_status >= '" . OS_SPLITED . "')" .
" AND oi.order_id = og.order_id".
" AND (pay_status = '" . PS_PAYED . "' OR pay_status = '" . PS_PAYING . "') " .
" AND (shipping_status = '" . SS_SHIPPED . "' OR shipping_status = '" . SS_RECEIVED . "') " .
" AND shipping_time >= '$start_time' AND shipping_time <= '$end_time'" .
" GROUP BY period ";
这样做好像不行~~~


print_r ($data_list);

的结果

Array ( [0] => Array ( [period] => 2010-04 [order_count] => 4 [order_amount] => 8667.38 [order_id] => 24 [goods_num] => 1 [cost_price] => 0.00 [goods_price] => 16.39 [gross_profit] => 16.39 ) [1] => Array ( [period] => 2010-05 [order_count] => 13 [order_amount] => 2098.54 [order_id] => 43 [goods_num] => 1 [cost_price] => 20.00 [goods_price] => 39.00 [gross_profit] => 19.00 ) )

gross_profit是利润

明显只有统计一个订单 [order_id] => 24

回答:
没问题啊。你直接做减法.就可以了..

没问题啊。你直接做减法.就可以了..
netaxcess 发表于 2010-5-24 18:04



厄,不是直接做减法的问题~


是无法统计出一个年度,或者一个季度的利润

因为统计出来的只能是一个年度或者一个季度的里面某一个订单~~~就一个




SUM((og.goods_price-og.cost_price)*og.goods_number)

原来这样才行呢~~~