/** * 销售额月报表曲线 */ public function balance_line() { global_run(); $s_account_info = $GLOBALS["account_info"]; $supplier_id = intval($s_account_info['supplier_id']); if (empty($s_account_info)) { die("请先登录"); } $year = intval($_REQUEST['year']); $month = intval($_REQUEST['month']); $current_year = intval(to_date(NOW_TIME, "Y")); $current_month = intval(to_date(NOW_TIME, "m")); if ($year == 0) { $year = $current_year; } if ($month == 0) { $month = $current_month; } if ($month < 1) { $month = 1; } if ($month > 12) { $month = 12; } $days_list = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $days = $days_list[$month - 1]; if ($days == 28 && $year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) { $days = 29; } $stat_month = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT); //月份的key $stat_result = $GLOBALS['db']->getAll("select money,sale_money,refund_money,stat_time from " . DB_PREFIX . "supplier_statements where supplier_id = " . $supplier_id . " and stat_month = '" . $stat_month . "'"); $result = array(); $x_axis_labels = array(); //x轴标题 for ($i = 1; $i <= $days; $i++) { $x_axis_labels[] = $i . "日"; } $result['x_axis'] = array("labels" => array("labels" => $x_axis_labels)); //开始定义每个数据的线条元素 $max_value = 0; //营业额 $sale_money_values = array(); for ($i = 1; $i <= $days; $i++) { $stat_time = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($i, 2, "0", STR_PAD_LEFT); //天的key $data_row = array("value" => 0, "tip" => $stat_time . "营业额0元"); foreach ($stat_result as $k => $v) { if ($v['stat_time'] == $stat_time) { if ($v['sale_money'] > $max_value) { $max_value = $v['sale_money']; } $data_row = array("value" => floatval($v['sale_money']), "tip" => $stat_time . "营业额" . round($v['sale_money'], 2) . "元"); } } $sale_money_values[] = $data_row; } $sale_money_elements = array("type" => "line", "colour" => "#ff3300", "text" => "营业额", "width" => 2, "values" => $sale_money_values); //消费数 $money_values = array(); for ($i = 1; $i <= $days; $i++) { $stat_time = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($i, 2, "0", STR_PAD_LEFT); //天的key $data_row = array("value" => 0, "tip" => $stat_time . "消费0元"); foreach ($stat_result as $k => $v) { if ($v['stat_time'] == $stat_time) { if ($v['money'] > $max_value) { $max_value = $v['money']; } $data_row = array("value" => floatval($v['money']), "tip" => $stat_time . "消费" . round($v['money'], 2) . "元"); } } $money_values[] = $data_row; } $money_elements = array("type" => "line", "colour" => "#736AFF", "text" => "消费额", "width" => 2, "values" => $money_values); //退款数 $refund_money_values = array(); for ($i = 1; $i <= $days; $i++) { $stat_time = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT) . "-" . str_pad($i, 2, "0", STR_PAD_LEFT); //天的key $data_row = array("value" => 0, "tip" => $stat_time . "退款0元"); foreach ($stat_result as $k => $v) { if ($v['stat_time'] == $stat_time) { if ($v['refund_money'] > $max_value) { $max_value = $v['refund_money']; } $data_row = array("value" => floatval($v['refund_money']), "tip" => $stat_time . "退款" . round($v['refund_money'], 2) . "元"); } } $refund_money_values[] = $data_row; } $refund_money_elements = array("type" => "line", "colour" => "#008f47", "text" => "退款额", "width" => 2, "values" => $refund_money_values); $max_value = ofc_max($max_value); $result['y_axis'] = array("max" => floatval($max_value)); $result['elements'] = array($sale_money_elements, $money_elements, $refund_money_elements); $result['bg_colour'] = "#ffffff"; ajax_return($result); }
public function sale_month_line() { $year = intval($_REQUEST['year']); $month = intval($_REQUEST['month']); $current_year = intval(to_date(NOW_TIME, "Y")); $current_month = intval(to_date(NOW_TIME, "m")); if ($year == 0) { $year = $current_year; } if ($month == 0) { $month = $current_month; } $days_list = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $days = $days_list[$month - 1]; if ($days == 28 && $year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) { $days = 29; } $stat_month = $year . "-" . str_pad($month, 2, "0", STR_PAD_LEFT); //月数据 $x_labels = array(); //x轴的标题 for ($i = 1; $i <= $days; $i++) { $x_labels[] = $i . "日"; } $result['x_axis'] = array("labels" => array("labels" => $x_labels)); $sql = "select income_order,refund_money,verify_money,stat_time from " . DB_PREFIX . "statements where stat_month = '" . $stat_month . "'"; $stat_result = $GLOBALS['db']->getAll($sql); //开始定义每个数据的线条元素 $max_value = 0; //销售额线条元素 $sale_line_values = array(); for ($i = 1; $i <= $days; $i++) { $stat_time = $stat_month . "-" . str_pad($i, 2, "0", STR_PAD_LEFT); $data_row = array("value" => 0, "tip" => $stat_time . "营业额0元"); foreach ($stat_result as $row) { if ($row['stat_time'] == $stat_time) { if ($row['income_order'] > $max_value) { $max_value = $row['income_order']; } $data_row = array("value" => floatval($row['income_order']), "tip" => $stat_time . "营业额" . round($row['income_order'], 2) . "元"); } } $sale_line_values[] = $data_row; } $sale_line_element = array("type" => "line", "colour" => SALE_COLOR, "text" => "营业额", "width" => 2, "values" => $sale_line_values); //退款额线条元素 $refund_line_values = array(); for ($i = 1; $i <= $days; $i++) { $stat_time = $stat_month . "-" . str_pad($i, 2, "0", STR_PAD_LEFT); $data_row = array("value" => 0, "tip" => $stat_time . "退款额0元"); foreach ($stat_result as $row) { if ($row['stat_time'] == $stat_time) { if ($row['refund_money'] > $max_value) { $max_value = $row['refund_money']; } $data_row = array("value" => floatval($row['refund_money']), "tip" => $stat_time . "退款额" . round($row['refund_money'], 2) . "元"); } } $refund_line_values[] = $data_row; } $refund_line_element = array("type" => "line", "colour" => REFUND_COLOR, "text" => "退款额", "width" => 2, "values" => $refund_line_values); //消费额线条元素 $verify_line_values = array(); for ($i = 1; $i <= $days; $i++) { $stat_time = $stat_month . "-" . str_pad($i, 2, "0", STR_PAD_LEFT); $data_row = array("value" => 0, "tip" => $stat_time . "消费额0元"); foreach ($stat_result as $row) { if ($row['stat_time'] == $stat_time) { if ($row['verify_money'] > $max_value) { $max_value = $row['verify_money']; } $data_row = array("value" => floatval($row['verify_money']), "tip" => $stat_time . "消费额" . round($row['verify_money'], 2) . "元"); } } $verify_line_values[] = $data_row; } $verify_line_element = array("type" => "line", "colour" => VERIFY_COLOR, "text" => "消费额", "width" => 2, "values" => $verify_line_values); $max_value = ofc_max($max_value); $result['y_axis'] = array("max" => floatval($max_value)); $result['elements'] = array($sale_line_element, $refund_line_element, $verify_line_element); $result['bg_colour'] = "#ffffff"; ajax_return($result); }