function get_stat_list() { // Obtaion to the statistics list $filter = array(); $condition = $where = "WHERE 1"; if (empty($_REQUEST['city'])) { $city = array_keys($_SESSION['city_arr']); $condition .= " AND city='{$city['0']}'"; $where .= " AND city='{$city['0']}'"; // $condition .= " AND city" . db_create_in(array_keys($_SESSION['city_arr'])); // 灵活选择城市的搜索方法 } else { $condition .= " AND city='" . intval($_REQUEST['city']) . "'"; $where .= " AND city='" . intval($_REQUEST['city']) . "'"; } $filter['bdate'] = empty($_REQUEST['bdate']) ? date('Y-m-d') : trim($_REQUEST['bdate']); $filter['turn'] = empty($_REQUEST['turn']) ? '' : intval($_REQUEST['turn']); if ($filter['bdate']) { $condition .= " AND bdate='" . $filter['bdate'] . "'"; } $sql = "SELECT COUNT(*) FROM cake_stat {$condition}"; $count = $GLOBALS['db_read']->getOne($sql); if ($count) { if ($filter['bdate']) { $where .= " AND bdate='" . $filter['bdate'] . "'"; } $query = "SELECT COUNT(*) FROM cake_stat {$where}"; $filter['record_count'] = $GLOBALS['db_read']->getOne($query); $filter = page_and_size($filter); $total = $GLOBALS['db_read']->getAll("SELECT goods_attr,goods_sum FROM cake_stat {$where}"); foreach ($total as $val) { $list['weight_total'] += $val[goods_sum] * floatval($val['goods_attr']); $list['num_total'] += $val['goods_sum']; } $limit = "LIMIT " . $filter['start'] . "," . $filter['page_size']; $sql = "SELECT id,city,bdate,goods_id,goods_attr,goods_sum,flag FROM cake_stat {$where} {$limit}"; $goods = $GLOBALS['db_read']->getAll($sql); foreach ($goods as $key => $val) { $list['stat'][$key]['city'] = $filter['city']; $list['stat'][$key]['goods_id'] = $val['goods_id']; $list['stat'][$key]['goods_name'] = get_goods_name($val['goods_id']); $list['stat'][$key]['bdate'] = $filter['bdate']; $list['stat'][$key]['goods_attr'] = empty($val['goods_attr']) ? '0.25' : floatval($val['goods_attr']); $list['stat'][$key]['goods_sum'] = $val['goods_sum']; $list['stat'][$key]['order_group'] = $val['order_group']; } } else { $term = "WHERE 1 AND b.order_status='1' AND c.goods_price>40"; if (empty($_REQUEST['city'])) { // $term .= " AND b.country" . db_create_in(array_keys($_SESSION['city_arr'])); // 灵活选择城市的搜索方法 foreach (array_keys($_SESSION['city_arr']) as $val) { if (isset($val) && $val == '441') { $term .= " AND b.country='441'"; } elseif (isset($val) && $val == '442') { $term .= " AND b.country='442'"; } } } else { $term .= " AND b.country IN ('" . intval($_REQUEST['city']) . "')"; $filter['city'] = intval($_REQUEST['city']); } if ($filter['bdate']) { $term .= " AND b.best_time BETWEEN '" . $filter['bdate'] . " 00:00:00' AND '" . $filter['bdate'] . " 23:59:59'"; } if ($filter['turn']) { $term .= " AND d.turn='" . $filter['turn'] . "'"; } if (!empty($filter['turn'])) { $join = "LEFT JOIN order_dispatch AS d ON d.order_id=b.order_id"; } $query = "SELECT COUNT(*) FROM order_genid AS a \r\n\t\t\tLEFT JOIN ecs_order_info AS b ON b.order_id=a.order_id \r\n\t\t\tLEFT JOIN ecs_order_goods AS c ON c.order_id=b.order_id " . $join . " {$term}"; $filter['record_count'] = $GLOBALS['db_read']->getOne($query); $filter = page_and_size($filter); $limit = "LIMIT " . $filter['start'] . "," . $filter['page_size']; $sql = "SELECT b.best_time,c.goods_id,c.goods_attr,SUM(c.goods_number) AS gnum,GROUP_CONCAT(c.order_id) AS order_group \r\n\t\t\tFROM order_genid AS a \r\n\t\t\tLEFT JOIN ecs_order_info AS b ON b.order_id=a.order_id \r\n\t\t\tLEFT JOIN ecs_order_goods AS c ON c.order_id=b.order_id " . $join . " {$term} \r\n\t\t\tGROUP BY c.goods_id,c.goods_attr ASC"; $goods = $GLOBALS['db_read']->getAll($sql); foreach ($goods as $key => $val) { $list['stat'][$key]['city'] = $filter['city']; $list['stat'][$key]['goods_id'] = $val['goods_id']; $list['stat'][$key]['goods_name'] = get_goods_name($val['goods_id']); $list['stat'][$key]['bdate'] = $filter['bdate']; $list['stat'][$key]['goods_attr'] = empty($val['goods_attr']) ? '0.25' : floatval($val['goods_attr']); $list['stat'][$key]['goods_sum'] = $val['gnum']; $list['stat'][$key]['order_group'] = $val['order_group']; $list['weight_total'] += $val['gnum'] * floatval($val['goods_attr']); $list['num_total'] += $val['gnum']; if (!empty($_REQUEST['city'])) { if ($filter['bdate'] < date('Y-m-d')) { $GLOBALS['db_write']->autoExecute('cake_stat', $list['stat'][$key], 'INSERT'); } } } } return array('list' => $list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count'], 'sql' => $sql); }
function get_stat_list() { // Obtaion to the statistics list $result = get_filter(); if ($result === false) { $filter = array(); $city_group = $_SESSION['city_group']; $where = "WHERE 1 "; $bdate = date('Y-m-d', strtotime(date('Y-m-d')) - 3600 * 24 * 2); $sdate = date('Y-m-d', strtotime(date('Y-m-d')) - 3600 * 24 * 1); $filter['turn'] = empty($_REQUEST['turn']) ? '' : intval($_REQUEST['turn']); $filter['bdate'] = empty($_REQUEST['bdate']) ? $bdate : trim($_REQUEST['bdate']); $filter['sdate'] = empty($_REQUEST['sdate']) ? $sdate : trim($_REQUEST['sdate']); $filter['order_sn'] = empty($_REQUEST['order_sn']) ? '' : trim($_REQUEST['order_sn']); $filter['print_sn'] = empty($_REQUEST['print_sn']) ? '' : trim($_REQUEST['print_sn']); $filter['stan'] = empty($_REQUEST['city']) ? $_SESSION['city_arr'] : intval($_REQUEST['city']); $join = ""; if (!empty($filter['turn'])) { $join .= " LEFT JOIN order_dispatch AS d ON d.order_id=b.order_id"; } if (!empty($filter['print_sn'])) { $join .= " LEFT JOIN print_log_x AS p ON p.order_id=b.order_id"; } $term = "WHERE 1 AND b.order_status='1' AND c.goods_price>40"; if ($filter['bdate'] && $filter['sdate']) { $term .= " and b.best_time>='" . $filter['bdate'] . " 00:00:00' AND b.best_time<='" . $filter['sdate'] . " 23:59:59'"; } if ($filter['turn']) { $term .= " AND d.turn='" . $filter['turn'] . "'"; } if ($filter['print_sn']) { $term .= " and p.print_sn='" . $filter['print_sn'] . "'and p.city_group=" . $city_group; } if ($filter['order_sn']) { $term .= " and b.order_sn like '%" . $filter['order_sn'] . "'"; } $query = "select count(*) from \r\n\t\t\t(SELECT b.best_time,c.goods_id,c.goods_attr,SUM(c.goods_number) AS gnum,GROUP_CONCAT(c.order_id) AS order_group \r\n\t\t\tFROM order_genid AS a \r\n\t\t\tLEFT JOIN ecs_order_info AS b ON b.order_id=a.order_id \r\n\t\t\tLEFT JOIN ecs_order_goods AS c ON c.order_id=b.order_id " . $join . " {$term} \r\n\t\t\tGROUP BY c.goods_id,c.goods_attr )as a "; $filter['record_count'] = $GLOBALS['db_read']->getOne($query); $filter = page_and_size($filter); $limit = "LIMIT " . $filter['start'] . "," . $filter['page_size']; $sql = "SELECT b.best_time,c.goods_id,c.goods_attr,SUM(c.goods_number) AS gnum,GROUP_CONCAT(c.order_id) AS order_group \r\n\t\t\tFROM order_genid AS a \r\n\t\t\tLEFT JOIN ecs_order_info AS b ON b.order_id=a.order_id \r\n\t\t\tLEFT JOIN ecs_order_goods AS c ON c.order_id=b.order_id " . $join . " {$term} \r\n\t\t\tGROUP BY c.goods_id,c.goods_attr ASC " . $limit; //print_r($sql);exit; $goods = $GLOBALS['db_read']->getAll($sql); foreach ($goods as $key => $val) { $list['stat'][$key]['goods_id'] = $val['goods_id']; $list['stat'][$key]['goods_name'] = get_goods_name($val['goods_id']); $list['stat'][$key]['bdate'] = $filter['bdate']; $list['stat'][$key]['goods_attr'] = empty($val['goods_attr']) ? '0.25' : floatval($val['goods_attr']); $list['stat'][$key]['goods_sum'] = $val['gnum']; $list['stat'][$key]['order_group'] = $val['order_group']; $list['weight_total'] += $val['gnum'] * floatval($val['goods_attr']); $list['num_total'] += $val['gnum']; set_filter($filter, $sql); } } else { $sql = $result['sql']; $filter = $result['filter']; } return array('list' => $list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count'], 'sql' => $sql); }