<?php
/* 快捷商城系统
 * 版本号：2.0
 * 官网：http://www.kjcms.cn
 * 2015-02-16
 */
class mod_report_shop extends inc_mod_mall {
	function get_list() {
		$starttime = fun_get::get("s_starttime");
		$endtime = fun_get::get("s_endtime");
		if(empty($starttime)) $starttime = date("Y-m-d");
		if(empty($endtime)) $endtime = date("Y-m-d 23:59:59");
		$obj_db = cls_obj::db();
		$total_price = $total_cost = $total_td = 0;
		$arr_list = $shop_id = array();
		$obj_result = $obj_db->select("select (sold_num*sold_price) as 'price',(sold_num*sold_goods_cost) as 'cost',sold_shop_id from " . cls_config::DB_PRE . "mall_goods_sold a inner join " . cls_config::DB_PRE . "mall_order b on a.sold_order_id=b.order_id where order_state=10 and sold_datetime>='" . $starttime . "' and sold_datetime<='" . $endtime . "' group by sold_shop_id");
		while($obj_rs = $obj_db->fetch_array($obj_result)) {
			$obj_rs['shop_name'] = '';
			$total_price += $obj_rs['price'];
			$total_cost += $obj_rs['cost'];
			$obj_rs['td'] = $obj_rs['price'] - $obj_rs['cost'];
			$arr_list[] = $obj_rs;
			$shop_id[] = $obj_rs['sold_shop_id'];
		}
		if(!empty($shop_id)) {
			$ids = implode("," , $shop_id);
			$obj_result = $obj_db->select("select shop_id,shop_name from " . cls_config::DB_PRE . "mall_shop where shop_id in(". $ids . ")");
			while($obj_rs = $obj_db->fetch_array($obj_result)) {
				$arr_shop['id_' . $obj_rs['shop_id']] = $obj_rs;
			}
			for($i = 0 ; $i < count($arr_list) ; $i++) {
				if(isset($arr_shop['id_' . $arr_list[$i]['sold_shop_id']])) $arr_list[$i]['shop_name'] = $arr_shop['id_' . $arr_list[$i]['sold_shop_id']]['shop_name'];
			}
		}
		return array('list' => $arr_list , 'total_price' => $total_price , 'total_cost' => $total_cost , 'td' => $total_price - $total_cost);
	}
}