function get_user_orderinfo($is_pagination = true) { global $db, $ecs, $start_date, $end_date; $filter['start_date'] = empty($_REQUEST['start_date']) ? $start_date : local_strtotime($_REQUEST['start_date']); $filter['end_date'] = empty($_REQUEST['end_date']) ? $end_date : local_strtotime($_REQUEST['end_date']); $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'order_num' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $where = "WHERE u.user_id = o.user_id " . "AND u.user_id > 0 " . order_query_sql('finished', 'o.'); if ($filter['start_date']) { $where .= " AND o.add_time >= '" . $filter['start_date'] . "'"; } if ($filter['end_date']) { $where .= " AND o.add_time <= '" . $filter['end_date'] . "'"; } $sql = "SELECT count(distinct(u.user_id)) FROM " . $ecs->table('users') . " AS u, " . $ecs->table('order_info') . " AS o " . $where; $filter['record_count'] = $GLOBALS['db']->getOne($sql); /* 分页大小 */ $filter = page_and_size($filter); /* 计算订单各种费用之和的语句 */ $total_fee = " SUM(" . order_amount_field() . ") AS turnover "; $sql = "SELECT u.user_id, u.user_name, COUNT(*) AS order_num, " . $total_fee . "FROM " . $ecs->table('users') . " AS u, " . $ecs->table('order_info') . " AS o " . $where . " GROUP BY u.user_id" . " ORDER BY " . $filter['sort_by'] . " " . $filter['sort_order']; if ($is_pagination) { $sql .= " LIMIT " . $filter['start'] . ', ' . $filter['page_size']; } $user_orderinfo = array(); $res = $db->query($sql); while ($items = $db->fetchRow($res)) { $items['turnover'] = price_format($items['turnover']); $user_orderinfo[] = $items; } $arr = array('user_orderinfo' => $user_orderinfo, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
/** * 取得访问和购买次数统计数据 * * @param int $cat_id 分类编号 * @param int $brand_id 品牌编号 * @param int $show_num 显示个数 * @return array $click_sold_info 访问购买比例数据 */ function click_sold_info($cat_id, $brand_id, $show_num) { global $db, $ecs; $where = " WHERE o.order_id = og.order_id AND g.goods_id = og.goods_id " . order_query_sql('finished', 'o.'); $limit = " LIMIT " . $show_num; if ($cat_id > 0) { $where .= " AND " . get_children($cat_id); } if ($brand_id > 0) { $where .= " AND g.brand_id = '{$brand_id}' "; } $click_sold_info = array(); $sql = "SELECT og.goods_id, g.goods_sn, g.goods_name, g.click_count, COUNT(og.goods_id) AS sold_times " . " FROM " . $ecs->table('goods') . " AS g, " . $ecs->table('order_goods') . " AS og, " . $ecs->table('order_info') . " AS o " . $where . " GROUP BY og.goods_id ORDER BY g.click_count DESC " . $limit; $res = $db->query($sql); while ($item = $db->fetchRow($res)) { if ($item['click_count'] <= 0) { $item['scale'] = 0; } else { /* 每一百个点击的订单比率 */ $item['scale'] = sprintf("%0.2f", $item['sold_times'] / $item['click_count'] * 100) . '%'; } $click_sold_info[] = $item; } return $click_sold_info; }
/** * 取得销售排行数据信息 * @param bool $is_pagination 是否分页 * @return array 销售排行数据 */ function get_sales_order($is_pagination = true) { $filter['start_date'] = empty($_REQUEST['start_date']) ? '' : local_strtotime($_REQUEST['start_date']); $filter['end_date'] = empty($_REQUEST['end_date']) ? '' : local_strtotime($_REQUEST['end_date']); $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'goods_num' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $where = " WHERE og.order_id = oi.order_id " . order_query_sql('finished', 'oi.'); if ($filter['start_date']) { $where .= " AND oi.add_time >= '" . $filter['start_date'] . "'"; } if ($filter['end_date']) { $where .= " AND oi.add_time <= '" . $filter['end_date'] . "'"; } $sql = "SELECT COUNT(distinct(og.goods_id)) FROM " . $GLOBALS['ecs']->table('order_info') . ' AS oi,' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . $where; $filter['record_count'] = $GLOBALS['db']->getOne($sql); /* 分页大小 */ $filter = page_and_size($filter); $sql = "SELECT og.goods_id, og.goods_sn, og.goods_name, oi.order_status, " . "SUM(og.goods_number) AS goods_num, SUM(og.goods_number * og.goods_price) AS turnover " . "FROM " . $GLOBALS['ecs']->table('order_goods') . " AS og, " . $GLOBALS['ecs']->table('order_info') . " AS oi " . $where . " GROUP BY og.goods_id " . ' ORDER BY ' . $filter['sort_by'] . ' ' . $filter['sort_order']; if ($is_pagination) { $sql .= " LIMIT " . $filter['start'] . ', ' . $filter['page_size']; } $sales_order_data = $GLOBALS['db']->getAll($sql); foreach ($sales_order_data as $key => $item) { $sales_order_data[$key]['wvera_price'] = price_format($item['goods_num'] ? $item['turnover'] / $item['goods_num'] : 0); $sales_order_data[$key]['short_name'] = sub_str($item['goods_name'], 30, true); $sales_order_data[$key]['turnover'] = price_format($item['turnover']); $sales_order_data[$key]['taxis'] = $key + 1; } $arr = array('sales_order_data' => $sales_order_data, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
/** * 查询历史记录 * * @access public * @params integer $id * @params integer $page * @return array */ function assign_sale_history($id, $page = 1) { $where_saled = order_query_sql($type = 'finished'); $sql = 'select COUNT(goods_id) FROM ' . $GLOBALS['ecs']->table('order_goods') . ' as g,' . $GLOBALS['ecs']->table('users') . ' as u, ' . $GLOBALS['ecs']->table('order_info') . ' as f where u.user_id = f.user_id and g.order_id = f.order_id ' . $where_saled . 'and g.goods_id=' . $id . ' order by f.pay_time desc'; $count = $GLOBALS['db']->getOne($sql); $size = !empty($GLOBALS['_CFG']['comments_number']) ? $GLOBALS['_CFG']['comments_number'] : 10; $page_count = $count > 0 ? intval(ceil($count / $size)) : 1; $sql = 'select u.user_name, g.goods_price, g.goods_number, f.pay_time,g.goods_attr FROM ' . $GLOBALS['ecs']->table('order_goods') . ' as g,' . $GLOBALS['ecs']->table('users') . ' as u, ' . $GLOBALS['ecs']->table('order_info') . ' as f where u.user_id = f.user_id and g.order_id = f.order_id ' . $where_saled . 'and g.goods_id=' . $id . ' order by f.pay_time desc'; $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $sale_historys = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $tmp_consignee = utf8Substr($row['user_name'], 0, 1); $tmp_consignee .= "<span style='color:#999'>**</span>"; $tmp_consignee .= utf8Substr($row['user_name'], mb_strlen($row['user_name'], 'utf8') - 1, 1); $row['consignee'] = $tmp_consignee; $sale_history = array(); $sale_history['consignee'] = $row['consignee']; $sale_history['pay_fee'] = $row['goods_price']; $sale_history['goods_number'] = $row['goods_number']; $sale_history['pay_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['pay_time']); $sale_history['goods_attr'] = $row['goods_attr']; $sale_historys[] = $sale_history; } /* 分页样式 */ $pager = getBoughtPage(array('currPage' => $page, 'size' => $size, 'count' => $count, 'page_count' => $page_count, 'id' => $id)); $cmt = array('sale_historys' => $sale_historys, 'pager' => $pager); return $cmt; }
function getsales_history($goods_id) { $where_saled = order_query_sql($type = 'finished'); $sql = 'select u.user_name, g.goods_price, g.goods_number, f.pay_time,g.goods_attr FROM ' . $GLOBALS['ecs']->table('order_goods') . ' as g,' . $GLOBALS['ecs']->table('users') . ' as u, ' . $GLOBALS['ecs']->table('order_info') . ' as f where u.user_id = f.user_id and g.order_id = f.order_id ' . $where_saled . 'and g.goods_id=' . $goods_id . ' order by f.pay_time desc'; $res = $GLOBALS['db']->getAll($sql); $sales_history = array(); foreach ($res as $idx => $row) { $tmp_consignee = utf8Substr($row['user_name'], 0, 1); $tmp_consignee .= "<span style='color:#999'>**</span>"; $tmp_consignee .= utf8Substr($row['user_name'], mb_strlen($row['user_name'], 'utf8') - 1, 1); $row['consignee'] = $tmp_consignee; $sales_history[$idx]['consignee'] = $row['consignee']; $sales_history[$idx]['pay_fee'] = $row['goods_price']; $sales_history[$idx]['goods_number'] = $row['goods_number']; $sales_history[$idx]['pay_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['pay_time']); $sales_history[$idx]['goods_attr'] = $row['goods_attr']; } global $smarty; $smarty->assign('count_sale_history', count($sales_history)); return $sales_history; }
/** * 获取订单列表信息 * * @access public * @param * * @return void */ function order_list() { $result = get_filter(); if ($result === false) { /* 过滤信息 */ $filter['order_sn'] = empty($_REQUEST['order_sn']) ? '' : trim($_REQUEST['order_sn']); if (!empty($_GET['is_ajax']) && $_GET['is_ajax'] == 1) { $_REQUEST['consignee'] = json_str_iconv($_REQUEST['consignee']); //$_REQUEST['address'] = json_str_iconv($_REQUEST['address']); } $filter['consignee'] = empty($_REQUEST['consignee']) ? '' : trim($_REQUEST['consignee']); $filter['email'] = empty($_REQUEST['email']) ? '' : trim($_REQUEST['email']); $filter['address'] = empty($_REQUEST['address']) ? '' : trim($_REQUEST['address']); $filter['zipcode'] = empty($_REQUEST['zipcode']) ? '' : trim($_REQUEST['zipcode']); $filter['tel'] = empty($_REQUEST['tel']) ? '' : trim($_REQUEST['tel']); $filter['mobile'] = empty($_REQUEST['mobile']) ? 0 : intval($_REQUEST['mobile']); $filter['country'] = empty($_REQUEST['country']) ? 0 : intval($_REQUEST['country']); $filter['province'] = empty($_REQUEST['province']) ? 0 : intval($_REQUEST['province']); $filter['city'] = empty($_REQUEST['city']) ? 0 : intval($_REQUEST['city']); $filter['district'] = empty($_REQUEST['district']) ? 0 : intval($_REQUEST['district']); $filter['shipping_id'] = empty($_REQUEST['shipping_id']) ? 0 : intval($_REQUEST['shipping_id']); $filter['pay_id'] = empty($_REQUEST['pay_id']) ? 0 : intval($_REQUEST['pay_id']); $filter['order_status'] = isset($_REQUEST['order_status']) ? intval($_REQUEST['order_status']) : -1; $filter['shipping_status'] = isset($_REQUEST['shipping_status']) ? intval($_REQUEST['shipping_status']) : -1; $filter['pay_status'] = isset($_REQUEST['pay_status']) ? intval($_REQUEST['pay_status']) : -1; $filter['user_id'] = empty($_REQUEST['user_id']) ? 0 : intval($_REQUEST['user_id']); $filter['user_name'] = empty($_REQUEST['user_name']) ? '' : trim($_REQUEST['user_name']); $filter['composite_status'] = isset($_REQUEST['composite_status']) ? intval($_REQUEST['composite_status']) : -1; $filter['group_buy_id'] = isset($_REQUEST['group_buy_id']) ? intval($_REQUEST['group_buy_id']) : 0; $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'add_time' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $filter['start_time'] = empty($_REQUEST['start_time']) ? '' : (strpos($_REQUEST['start_time'], '-') > 0 ? local_strtotime($_REQUEST['start_time']) : $_REQUEST['start_time']); $filter['end_time'] = empty($_REQUEST['end_time']) ? '' : (strpos($_REQUEST['end_time'], '-') > 0 ? local_strtotime($_REQUEST['end_time']) : $_REQUEST['end_time']); $where = 'WHERE 1 '; if ($filter['order_sn']) { $where .= " AND o.order_sn LIKE '%" . mysql_like_quote($filter['order_sn']) . "%'"; } if ($filter['consignee']) { $where .= " AND o.consignee LIKE '%" . mysql_like_quote($filter['consignee']) . "%'"; } if ($filter['email']) { $where .= " AND o.email LIKE '%" . mysql_like_quote($filter['email']) . "%'"; } if ($filter['address']) { $where .= " AND o.address LIKE '%" . mysql_like_quote($filter['address']) . "%'"; } if ($filter['zipcode']) { $where .= " AND o.zipcode LIKE '%" . mysql_like_quote($filter['zipcode']) . "%'"; } if ($filter['tel']) { $where .= " AND o.tel LIKE '%" . mysql_like_quote($filter['tel']) . "%'"; } if ($filter['mobile']) { $where .= " AND o.mobile LIKE '%" . mysql_like_quote($filter['mobile']) . "%'"; } if ($filter['country']) { $where .= " AND o.country = '{$filter['country']}'"; } if ($filter['province']) { $where .= " AND o.province = '{$filter['province']}'"; } if ($filter['city']) { $where .= " AND o.city = '{$filter['city']}'"; } if ($filter['district']) { $where .= " AND o.district = '{$filter['district']}'"; } if ($filter['shipping_id']) { $where .= " AND o.shipping_id = '{$filter['shipping_id']}'"; } if ($filter['pay_id']) { $where .= " AND o.pay_id = '{$filter['pay_id']}'"; } if ($filter['order_status'] != -1) { $where .= " AND o.order_status = '{$filter['order_status']}'"; } if ($filter['shipping_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['shipping_status']}'"; } if ($filter['pay_status'] != -1) { $where .= " AND o.pay_status = '{$filter['pay_status']}'"; } if ($filter['user_id']) { $where .= " AND o.user_id = '{$filter['user_id']}'"; } if ($filter['user_name']) { $where .= " AND u.user_name LIKE '%" . mysql_like_quote($filter['user_name']) . "%'"; } if ($filter['start_time']) { $where .= " AND o.add_time >= '{$filter['start_time']}'"; } if ($filter['end_time']) { $where .= " AND o.add_time <= '{$filter['end_time']}'"; } //综合状态 switch ($filter['composite_status']) { case CS_AWAIT_PAY: $where .= order_query_sql('await_pay'); break; case CS_AWAIT_SHIP: $where .= order_query_sql('await_ship'); break; case CS_FINISHED: $where .= order_query_sql('finished'); break; case PS_PAYING: if ($filter['composite_status'] != -1) { $where .= " AND o.pay_status = '{$filter['composite_status']}' "; } break; case OS_SHIPPED_PART: if ($filter['composite_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['composite_status']}'-2 "; } break; default: if ($filter['composite_status'] != -1) { $where .= " AND o.order_status = '{$filter['composite_status']}' "; } } /* 团购订单 */ if ($filter['group_buy_id']) { $where .= " AND o.extension_code = 'group_buy' AND o.extension_id = '{$filter['group_buy_id']}' "; } /* 如果管理员属于某个办事处,只列出这个办事处管辖的订单 */ $sql = "SELECT agency_id FROM " . $GLOBALS['ecs']->table('admin_user') . " WHERE user_id = '{$_SESSION['admin_id']}'"; $agency_id = $GLOBALS['db']->getOne($sql); if ($agency_id > 0) { $where .= " AND o.agency_id = '{$agency_id}' "; } /* 分页大小 */ $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']); if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) { $filter['page_size'] = intval($_REQUEST['page_size']); } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) { $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']); } else { $filter['page_size'] = 15; } /* 记录总数 */ if ($filter['user_name']) { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o ," . $GLOBALS['ecs']->table('users') . " AS u " . $where; } else { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . $where; } $filter['record_count'] = $GLOBALS['db']->getOne($sql); $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1; /* 查询 */ $sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer " . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; foreach (array('order_sn', 'consignee', 'email', 'address', 'zipcode', 'tel', 'user_name') as $val) { $filter[$val] = stripslashes($filter[$val]); } set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $row = $GLOBALS['db']->getAll($sql); /* 格式话数据 */ foreach ($row as $key => $value) { $row[$key]['formated_order_amount'] = price_format($value['order_amount']); $row[$key]['formated_money_paid'] = price_format($value['money_paid']); $row[$key]['formated_total_fee'] = price_format($value['total_fee']); $row[$key]['short_order_time'] = local_date('m-d H:i', $value['add_time']); if ($value['order_status'] == OS_INVALID || $value['order_status'] == OS_CANCELED) { /* 如果该订单为无效或取消则显示删除链接 */ $row[$key]['can_remove'] = 1; } else { $row[$key]['can_remove'] = 0; } } $arr = array('orders' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
function action_order_list() { $user = $GLOBALS['user']; $_CFG = $GLOBALS['_CFG']; $_LANG = $GLOBALS['_LANG']; $smarty = $GLOBALS['smarty']; $db = $GLOBALS['db']; $ecs = $GLOBALS['ecs']; $user_id = $_SESSION['user_id']; $action = $GLOBALS['action']; include_once ROOT_PATH . 'includes/lib_transaction.php'; include_once ROOT_PATH . 'includes/lib_transaction_1.php'; include_once ROOT_PATH . 'includes/lib_payment.php'; include_once ROOT_PATH . 'includes/lib_order.php'; include_once ROOT_PATH . 'includes/lib_clips.php'; $ex_where = " and user_id={$user_id}"; /* 已完成的订单 */ $order_count['finished'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE 1 {$ex_where} " . order_query_sql('finished')); $status['finished'] = CS_FINISHED; /* 待发货的订单: */ $order_count['await_ship'] = $db->GetOne('SELECT COUNT(*)' . ' FROM ' . $ecs->table('order_info') . " WHERE 1 {$ex_where} " . order_query_sql('await_ship')); $status['await_ship'] = CS_AWAIT_SHIP; /* 待付款的订单: */ $order_count['await_pay'] = $db->GetOne('SELECT COUNT(*)' . ' FROM ' . $ecs->table('order_info') . " WHERE 1 {$ex_where} " . order_query_sql('await_pay')); $status['await_pay'] = CS_AWAIT_PAY; /* “未确认”的订单 */ $order_count['unconfirmed'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE 1 {$ex_where} " . order_query_sql('unconfirmed')); $status['unconfirmed'] = OS_UNCONFIRMED; // $today_start = mktime(0,0,0,date('m'),date('d'),date('Y')); $order_count['stats'] = $db->getRow('SELECT COUNT(*) AS oCount, IFNULL(SUM(order_amount), 0) AS oAmount' . ' FROM ' . $ecs->table('order_info')); $smarty->assign('order_count', $order_count); $smarty->assign('status', $status); $composite_status = isset($_REQUEST['composite_status']) ? intval($_REQUEST['composite_status']) : -1; $where = ''; switch ($composite_status) { case CS_AWAIT_PAY: $where .= order_query_sql('await_pay'); break; case CS_AWAIT_SHIP: $where .= order_query_sql('await_ship'); break; case CS_FINISHED: $where .= order_query_sql('finished'); break; default: if ($composite_status != -1) { $where .= " AND o.order_status = '{$composite_status}' "; } } $page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1; $record_count = $db->getOne("SELECT COUNT(*) FROM " . $ecs->table('order_info') . " WHERE user_id = '{$user_id}'"); $pager = get_pager('user.php', array('act' => $action, 'composite_status' => $composite_status), $record_count, $page, 5); $orders = get_user_orders_1($user_id, $pager['size'], $pager['start'], $where); foreach ($orders as $k_kuaidi => $v_kuaidi) { // 同城快递 if ($v_kuaidi['shipping_name_2'] == "同城快递") { $kos_order_id = $db->getOne("select order_id from " . $ecs->table('kuaidi_order') . " where order_sn='" . $v_kuaidi['invoice_no'] . "'"); $sql = "select * from " . $ecs->table('kuaidi_order_status') . " where order_id='" . $kos_order_id . "' order by status_id desc"; $res_status = $db->query($sql); $have_shipping_info = 0; $shipping_info = ""; while ($row_status = $db->fetchRow($res_status)) { if ($row_status['status_display'] == 1) { switch ($row_status['status_id']) { case 1: $shipping_info .= "您提交了订单,请等待确认。 (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; case 2: $shipping_info .= "您的快件已经确认,等待快递员揽收。 (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; case 3: $postman_id = $db->getOne("select postman_id from " . $ecs->table('kuaidi_order') . " where order_sn='" . $orders[$k_kuaidi]['invoice_no'] . "'"); $postman_info = $db->getRow("select postman_name, mobile from " . $ecs->table('postman') . " where postman_id=" . $postman_id); $shipping_info .= "您的快件正在派送,快递员:" . $postman_info['postman_name'] . ",电话:" . $postman_info['mobile'] . " (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; case 4: $shipping_info .= "您的快件已经签收。 (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; case 5: $shipping_info .= "您的快件已被拒收。 (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; case 6: $shipping_info .= "您拒收的快件已被退回。 (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; case 7: $shipping_info .= "您的快件已经取消。 (" . local_date('Y-m-d H:i:s', $row_status['status_time']) . ")"; break; } $shipping_info .= "<br>"; if ($row_status['status_id'] >= 1) { $have_shipping_info++; } } } if ($have_shipping_info) { $orders[$k_kuaidi]['result_content'] = $shipping_info; } else { $orders[$k_kuaidi]['result_content'] = '抱歉,暂时还没有该运单的物流信息哦!'; } } } $merge = get_user_merge($user_id); $smarty->assign('merge', $merge); $smarty->assign('pager', $pager); $smarty->assign('orders', $orders); $smarty->display('user_transaction.dwt'); }
/* 待发货的订单: */ $order['await_ship'] = $db->GetOne('SELECT COUNT(*)'. ' FROM ' .$ecs->table('order_info') . " WHERE 1 " . order_query_sql('await_ship')); $status['await_ship'] = CS_AWAIT_SHIP; /* 待付款的订单: */ $order['await_pay'] = $db->GetOne('SELECT COUNT(*)'. ' FROM ' .$ecs->table('order_info') . " WHERE 1 " . order_query_sql('await_pay')); $status['await_pay'] = CS_AWAIT_PAY; /* "未确认"的订单 */ $order['unconfirmed'] = $db->GetOne('SELECT COUNT(*) FROM ' .$ecs->table('order_info'). " WHERE 1 " . order_query_sql('unconfirmed')); $status['unconfirmed'] = OS_UNCONFIRMED; /* "部分发货"的订单 */ $order['shipped_part'] = $db->GetOne('SELECT COUNT(*) FROM ' .$ecs->table('order_info'). " WHERE shipping_status=" .SS_SHIPPED_PART); $status['shipped_part'] = OS_SHIPPED_PART; // $today_start = mktime(0,0,0,date('m'),date('d'),date('Y')); $order['stats'] = $db->getRow('SELECT COUNT(*) AS oCount, IFNULL(SUM(order_amount), 0) AS oAmount' . ' FROM ' .$ecs->table('order_info')); $smarty->assign('order', $order); $smarty->assign('status', $status); /* 商品信息 */
/** * 获取用户可以和并的订单数组 * * @access public * @param int $user_id 用户ID * * @return array $merge 可合并订单数组 */ function get_user_merge($user_id) { $sql = "SELECT order_sn FROM " . $this->pre . "order_info WHERE user_id = '{$user_id}' " . order_query_sql('unprocessed') . "AND extension_code = '' " . " ORDER BY add_time DESC"; $list = $this->query($sql); $merge = array(); foreach ($list as $key => $value) { $merge[$value['order_sn']] = $value['order_sn']; } return $merge; }
/** * 获取订单列表信息 * * @access public * @param * * @return void */ function order_list() { $result = get_filter(); if ($result === false) { /* 过滤信息 */ /* 代码增加_start By morestock_morecity */ $filter['sid'] = empty($_REQUEST['sid']) ? '0' : intval($_REQUEST['sid']); $filter['ssid'] = empty($_REQUEST['ssid']) ? '0' : intval($_REQUEST['ssid']); /* 代码增加_end By morestock_morecity */ $filter['order_sn'] = empty($_REQUEST['order_sn']) ? '' : trim($_REQUEST['order_sn']); if (!empty($_GET['is_ajax']) && $_GET['is_ajax'] == 1) { $_REQUEST['consignee'] = json_str_iconv($_REQUEST['consignee']); //$_REQUEST['address'] = json_str_iconv($_REQUEST['address']); } $filter['consignee'] = empty($_REQUEST['consignee']) ? '' : trim($_REQUEST['consignee']); $filter['email'] = empty($_REQUEST['email']) ? '' : trim($_REQUEST['email']); $filter['address'] = empty($_REQUEST['address']) ? '' : trim($_REQUEST['address']); $filter['zipcode'] = empty($_REQUEST['zipcode']) ? '' : trim($_REQUEST['zipcode']); $filter['tel'] = empty($_REQUEST['tel']) ? '' : trim($_REQUEST['tel']); $filter['mobile'] = empty($_REQUEST['mobile']) ? 0 : intval($_REQUEST['mobile']); $filter['country'] = empty($_REQUEST['country']) ? 0 : intval($_REQUEST['country']); $filter['province'] = empty($_REQUEST['province']) ? 0 : intval($_REQUEST['province']); $filter['city'] = empty($_REQUEST['city']) ? 0 : intval($_REQUEST['city']); $filter['district'] = empty($_REQUEST['district']) ? 0 : intval($_REQUEST['district']); $filter['shipping_id'] = empty($_REQUEST['shipping_id']) ? 0 : intval($_REQUEST['shipping_id']); $filter['pay_id'] = empty($_REQUEST['pay_id']) ? 0 : intval($_REQUEST['pay_id']); $filter['order_status'] = isset($_REQUEST['order_status']) ? intval($_REQUEST['order_status']) : -1; $filter['shipping_status'] = isset($_REQUEST['shipping_status']) ? intval($_REQUEST['shipping_status']) : -1; $filter['pay_status'] = isset($_REQUEST['pay_status']) ? intval($_REQUEST['pay_status']) : -1; $filter['user_id'] = empty($_REQUEST['user_id']) ? 0 : intval($_REQUEST['user_id']); $filter['user_name'] = empty($_REQUEST['user_name']) ? '' : trim($_REQUEST['user_name']); $filter['composite_status'] = isset($_REQUEST['composite_status']) ? intval($_REQUEST['composite_status']) : -1; $filter['group_buy_id'] = isset($_REQUEST['group_buy_id']) ? intval($_REQUEST['group_buy_id']) : 0; $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'add_time' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $filter['start_time'] = empty($_REQUEST['start_time']) ? '' : (strpos($_REQUEST['start_time'], '-') > 0 ? local_strtotime($_REQUEST['start_time']) : $_REQUEST['start_time']); $filter['end_time'] = empty($_REQUEST['end_time']) ? '' : (strpos($_REQUEST['end_time'], '-') > 0 ? local_strtotime($_REQUEST['end_time']) : $_REQUEST['end_time']); /* 代码增加_start By www.ecshop68.com */ $filter['order_type'] = isset($_REQUEST['order_type']) ? intval($_REQUEST['order_type']) : 0; /* 代码增加_end By www.ecshop68.com */ $filter['supp'] = isset($_REQUEST['supp']) && !empty($_REQUEST['supp']) && intval($_REQUEST['supp']) > 0 ? intval($_REQUEST['supp']) : 0; $filter['suppid'] = isset($_REQUEST['suppid']) && !empty($_REQUEST['suppid']) && intval($_REQUEST['suppid']) > 0 ? intval($_REQUEST['suppid']) : 0; //$where = 'WHERE 1 '; $where = $filter['supp'] > 0 ? 'WHERE o.supplier_id > 0' : 'WHERE o.supplier_id = 0'; //morestock_morecity if ($filter['suppid']) { //$where .= " AND o.supplier_id = ".$filter['suppid']; $where = 'WHERE o.supplier_id = ' . $filter['suppid']; //morestock_morecity } //判断是否是查询过来的 if (isset($_REQUEST['search']) && $_REQUEST['search']) { $where = "where 1"; $search = false; } else { $search = true; } /* 代码增加_start By morestock_morecity */ if ($filter['ssid']) { $where .= " AND o.sub_id like '%|" . $filter['ssid'] . "|%' "; } else { if ($filter['sid']) { $where .= " AND o.store_id = '" . $filter['sid'] . "' "; } } //获取当前管理员负责的store_id列表 if ($filter['supp'] == 0 && $search) { //如果是查看自己的订单,就获取仓库列表 $storeid_list = ""; if ($_SESSION['action_list'] == 'all') { //自营超级管理员,可以查看所有 $sql2 = "select store_id from " . $GLOBALS['ecs']->table('store_main') . " where supplier_id=0 and parent_id > 0"; $res2 = $GLOBALS['db']->query($sql2); while ($row2 = $GLOBALS['db']->fetchRow($res2)) { $storeid_list .= $storeid_list ? " or " : ""; $storeid_list .= " sub_id like '%|" . $row2['store_id'] . "|%' "; } } else { $sql1 = "select store_id from " . $GLOBALS['ecs']->table('store_adminer') . " where supplier_id=0 and admin_id = " . $_SESSION['admin_id']; $res1 = $GLOBALS['db']->query($sql1); while ($row1 = $GLOBALS['db']->fetchRow($res1)) { $storeid_list .= $storeid_list ? " or " : ""; $storeid_list .= " sub_id like '%|" . $row1['store_id'] . "|%' "; $sql2 = "select store_id from " . $GLOBALS['ecs']->table('store_main') . " where supplier_id=0 and parent_id = '{$row1['store_id']}' "; $res2 = $GLOBALS['db']->query($sql2); while ($row2 = $GLOBALS['db']->fetchRow($res2)) { $storeid_list .= $storeid_list ? " or " : ""; $storeid_list .= " sub_id like '%|" . $row2['store_id'] . "|%' "; } } } if ($storeid_list) { $where .= " AND ({$storeid_list}) "; } } /* 代码增加_end By morestock_morecity */ if ($filter['order_sn']) { $where .= " AND o.order_sn LIKE '%" . mysql_like_quote($filter['order_sn']) . "%'"; } if ($filter['consignee']) { $where .= " AND o.consignee LIKE '%" . mysql_like_quote($filter['consignee']) . "%'"; } if ($filter['email']) { $where .= " AND o.email LIKE '%" . mysql_like_quote($filter['email']) . "%'"; } if ($filter['address']) { $where .= " AND o.address LIKE '%" . mysql_like_quote($filter['address']) . "%'"; } if ($filter['zipcode']) { $where .= " AND o.zipcode LIKE '%" . mysql_like_quote($filter['zipcode']) . "%'"; } if ($filter['tel']) { $where .= " AND o.tel LIKE '%" . mysql_like_quote($filter['tel']) . "%'"; } if ($filter['mobile']) { $where .= " AND o.mobile LIKE '%" . mysql_like_quote($filter['mobile']) . "%'"; } if ($filter['country']) { $where .= " AND o.country = '{$filter['country']}'"; } if ($filter['province']) { $where .= " AND o.province = '{$filter['province']}'"; } if ($filter['city']) { $where .= " AND o.city = '{$filter['city']}'"; } if ($filter['district']) { $where .= " AND o.district = '{$filter['district']}'"; } if ($filter['shipping_id']) { $where .= " AND o.shipping_id = '{$filter['shipping_id']}'"; } if ($filter['pay_id']) { $where .= " AND o.pay_id = '{$filter['pay_id']}'"; } if ($filter['order_status'] != -1) { $where .= " AND o.order_status = '{$filter['order_status']}'"; } if ($filter['shipping_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['shipping_status']}'"; } if ($filter['pay_status'] != -1) { $where .= " AND o.pay_status = '{$filter['pay_status']}'"; } if ($filter['user_id']) { $where .= " AND o.user_id = '{$filter['user_id']}'"; } if ($filter['user_name']) { $where .= " AND u.user_name LIKE '%" . mysql_like_quote($filter['user_name']) . "%'"; } if ($filter['start_time']) { $where .= " AND o.add_time >= '{$filter['start_time']}'"; } if ($filter['end_time']) { $where .= " AND o.add_time <= '{$filter['end_time']}'"; } /* 代码增加_start By www.ecshop68.com */ switch ($filter['order_type']) { case 1: $where .= " AND o.is_pickup = 0"; break; case 2: $where .= " AND o.is_pickup > 0"; break; } /* 代码增加_end By www.ecshop68.com */ //综合状态 switch ($filter['composite_status']) { case CS_AWAIT_PAY: $where .= order_query_sql('await_pay'); break; case CS_AWAIT_SHIP: $where .= order_query_sql('await_ship'); break; case CS_FINISHED: $where .= order_query_sql('finished'); break; case PS_PAYING: if ($filter['composite_status'] != -1) { $where .= " AND o.pay_status = '{$filter['composite_status']}' "; } break; case OS_SHIPPED_PART: if ($filter['composite_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['composite_status']}'-2 "; } break; default: if ($filter['composite_status'] != -1) { $where .= " AND o.order_status = '{$filter['composite_status']}' "; } } /* 团购订单 */ if ($filter['group_buy_id']) { $where .= " AND o.extension_code = 'group_buy' AND o.extension_id = '{$filter['group_buy_id']}' "; } /* 如果管理员属于某个办事处,只列出这个办事处管辖的订单 */ $sql = "SELECT agency_id FROM " . $GLOBALS['ecs']->table('admin_user') . " WHERE user_id = '{$_SESSION['admin_id']}'"; $agency_id = $GLOBALS['db']->getOne($sql); if ($agency_id > 0) { $where .= " AND o.agency_id = '{$agency_id}' "; } /* 分页大小 */ $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']); if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) { $filter['page_size'] = intval($_REQUEST['page_size']); } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) { $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']); } else { $filter['page_size'] = 15; } /* 记录总数 */ if ($filter['user_name']) { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o ," . $GLOBALS['ecs']->table('users') . " AS u " . $where; } else { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . $where; } $filter['record_count'] = $GLOBALS['db']->getOne($sql); $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1; /* 查询 */ if ($filter['supp']) { $sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer,supplier_name,o.froms,is_pickup " . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('supplier') . " AS s ON s.supplier_id=o.supplier_id " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; } else { $sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer, o.froms , is_pickup " . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; } foreach (array('order_sn', 'consignee', 'email', 'address', 'zipcode', 'tel', 'user_name') as $val) { $filter[$val] = stripslashes($filter[$val]); } set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $row = $GLOBALS['db']->getAll($sql); /* 格式话数据 */ foreach ($row as $key => $value) { $row[$key]['formated_order_amount'] = price_format($value['order_amount']); $row[$key]['formated_money_paid'] = price_format($value['money_paid']); $row[$key]['formated_total_fee'] = price_format($value['total_fee']); $row[$key]['short_order_time'] = local_date('m-d H:i', $value['add_time']); if ($value['order_status'] == OS_INVALID || $value['order_status'] == OS_CANCELED) { /* 如果该订单为无效或取消则显示删除链接 */ $row[$key]['can_remove'] = 1; } else { $row[$key]['can_remove'] = 0; } $tuihuan_info = $GLOBALS['db']->getOne("select order_sn from " . $GLOBALS['ecs']->table('back_order') . " where order_sn = '" . $row[$key]['order_sn'] . "' AND status_back < 6"); if (!empty($tuihuan_info)) { $row[$key]['tuihuan'] = 1; } } $arr = array('orders' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
$rows['order_num'] = $db->getOne($sql2); /* 当前广告所产生的已完成的有效订单 */ $sql3 = "SELECT COUNT(order_id) FROM " . $ecs->table('order_info') . " WHERE from_ad = '{$rows['ad_id']}'" . " AND referer = '{$rows['referer']}' " . order_query_sql('finished'); $rows['order_confirm'] = $db->getOne($sql3); $ads_stats[] = $rows; } $smarty->assign('ads_stats', $ads_stats); /* 站外JS投放商品的统计数据 */ $goods_stats = array(); $goods_sql = "SELECT from_ad, referer, clicks FROM " . $ecs->table('adsense') . " WHERE from_ad = '-1' ORDER by referer DESC"; $goods_res = $db->query($goods_sql); while ($rows2 = $db->fetchRow($goods_res)) { /* 获取当前广告所产生的订单总数 */ $rows2['order_num'] = $db->getOne("SELECT COUNT(order_id) FROM " . $ecs->table('order_info') . " WHERE referer='{$rows2['referer']}'"); /* 当前广告所产生的已完成的有效订单 */ $sql = "SELECT COUNT(order_id) FROM " . $ecs->table('order_info') . " WHERE referer='{$rows2['referer']}'" . order_query_sql('finished'); $rows2['order_confirm'] = $db->getOne($sql); $rows2['ad_name'] = $_LANG['adsense_js_goods']; $goods_stats[] = $rows2; } if ($_REQUEST['act'] == 'download') { header("Content-type: application/vnd.ms-excel; charset=utf-8"); header("Content-Disposition: attachment; filename=ad_statistics.xls"); $data = "{$_LANG['adsense_name']}\t{$_LANG['cleck_referer']}\t{$_LANG['click_count']}\t{$_LANG['confirm_order']}\t{$_LANG['gen_order_amount']}\n"; $res = array_merge($goods_stats, $ads_stats); foreach ($res as $row) { $data .= "{$row['ad_name']}\t{$row['referer']}\t{$row['clicks']}\t{$row['order_confirm']}\t{$row['order_num']}\n"; } echo ecs_iconv(EC_CHARSET, 'GB2312', $data); exit; }
$froms_series[0]['data'] = $froms_data; $froms_options['tooltip'] = $froms_tooltip; $froms_options['legend'] = $froms_legend; $froms_options['toolbox'] = $froms_toolbox; $froms_options['calculabe'] = $froms_calculable; $froms_options['series'] = $froms_series; $smarty->assign('froms_option', json_encode($froms_options)); //当月每日订单数统计 $orders_tooltip = array('trigger' => 'axis'); $orders_legend = array('data' => array()); $orders_toolbox = array('show' => true, 'x' => 'right', 'feature' => array('magicType' => array('show' => true, 'type' => array('line', 'bar')), 'restore' => array('show' => true), 'saveAsImage' => array('show' => true))); $orders_calculable = true; $orders_xAxis = array('type' => 'category', 'boundryGap' => false, 'data' => array()); $orders_yAxis = array('type' => 'value', 'axisLabel' => array('formatter' => '{value}个')); $orders_series = array(array('name' => '订单个数', 'type' => 'line', 'data' => array(), 'markPoint' => array('data' => array(array('type' => 'max', 'name' => '最大值'), array('type' => 'min', 'name' => '最小值'))), 'markLine' => array('data' => array(array('type' => 'average', 'name' => '平均值'))))); $result = $db->query('SELECT DATE_FORMAT(FROM_UNIXTIME(`confirm_time`),"%d") AS day,COUNT(*) AS count,SUM(money_paid) AS money FROM ' . $ecs->table('order_info') . ' WHERE `confirm_time` BETWEEN ' . $month_start . ' AND ' . $month_end . ' ' . order_query_sql('finished') . ' AND supplier_id=' . $_SESSION['supplier_id'] . ' GROUP BY day ORDER BY day ASC '); while ($row = mysql_fetch_assoc($result)) { $orders_series_data[intval($row['day'])] = intval($row['count']); $sales_series_data[intval($row['day'])] = floatval($row['money']); } for ($i = 1; $i <= date('d'); $i++) { if (empty($orders_series_data[$i])) { $orders_series_data[$i] = 0; $sales_series_data[$i] = 0; } $orders_xAxis_data[] = $i; $sales_xAxis_data[] = $i; } $orders_xAxis['data'] = $orders_xAxis_data; ksort($orders_series_data); $orders_series[0]['data'] = array_values($orders_series_data);
$sql = "SELECT COUNT(*) FROM " . $ecs->table("users"); $res = $db->getCol($sql); $user_num = $res[0]; /* 计算订单各种费用之和的语句 */ $total_fee = " SUM(" . order_amount_field() . ") AS turnover "; /* 有过订单的会员数 */ $sql = 'SELECT COUNT(DISTINCT user_id) FROM ' . $ecs->table('order_info') . " WHERE user_id > 0 " . order_query_sql('finished'); $have_order_usernum = $db->getOne($sql); /* 会员订单总数和订单总购物额 */ $user_all_order = array(); $sql = "SELECT COUNT(*) AS order_num, " . $total_fee . "FROM " . $ecs->table('order_info') . " WHERE user_id > 0 " . order_query_sql('finished'); $user_all_order = $db->getRow($sql); $user_all_order['turnover'] = floatval($user_all_order['turnover']); /* 匿名会员订单总数和总购物额 */ $guest_all_order = array(); $sql = "SELECT COUNT(*) AS order_num, " . $total_fee . "FROM " . $ecs->table('order_info') . " WHERE user_id = 0 " . order_query_sql('finished'); $guest_all_order = $db->getRow($sql); /* 匿名会员平均订单额: 购物总额/订单数 */ $guest_order_amount = $guest_all_order['order_num'] > 0 ? floatval($guest_all_order['turnover'] / $guest_all_order['order_num']) : '0.00'; $_GET['flag'] = isset($_GET['flag']) ? 'download' : ''; if ($_GET['flag'] == 'download') { $filename = ecs_iconv(EC_CHARSET, 'GB2312', $_LANG['guest_statistics']); header("Content-type: application/vnd.ms-excel; charset=utf-8"); header("Content-Disposition: attachment; filename={$filename}.xls"); /* 生成会员购买率 */ $data = $_LANG['percent_buy_member'] . "\t\n"; $data .= $_LANG['member_count'] . "\t" . $_LANG['order_member_count'] . "\t" . $_LANG['member_order_count'] . "\t" . $_LANG['percent_buy_member'] . "\n"; $data .= $user_num . "\t" . $have_order_usernum . "\t" . $user_all_order['order_num'] . "\t" . sprintf("%0.2f", ($user_num > 0 ? $have_order_usernum / $user_num : 0) * 100) . "\n\n"; /* 每会员平均订单数及购物额 */ $data .= $_LANG['order_turnover_peruser'] . "\t\n"; $data .= $_LANG['member_sum'] . "\t" . $_LANG['average_member_order'] . "\t" . $_LANG['member_order_sum'] . "\n";
$sql = 'SELECT COUNT(*) FROM ' . $ecs->table('users'); $res = $db->getCol($sql); $user_num = $res[0]; /* 计算订单各种费用之和的语句 */ $total_fee = ' SUM(' . order_amount_field() . ') AS turnover '; /* 有过订单的会员数 */ $sql = 'SELECT COUNT(DISTINCT user_id) FROM ' . $ecs->table('order_info') . ' WHERE user_id > 0 ' . order_query_sql('finished'); $have_order_usernum = $db->getOne($sql); /* 会员订单总数和订单总购物额 */ $user_all_order = array(); $sql = 'SELECT COUNT(*) AS order_num, ' . $total_fee . 'FROM ' . $ecs->table('order_info') . ' WHERE user_id > 0 ' . order_query_sql('finished'); $user_all_order = $db->getRow($sql); $user_all_order['turnover'] = floatval($user_all_order['turnover']); /* 匿名会员订单总数和总购物额 */ $guest_all_order = array(); $sql = 'SELECT COUNT(*) AS order_num, ' . $total_fee . 'FROM ' . $ecs->table('order_info') . ' WHERE user_id = 0 ' . order_query_sql('finished'); $guest_all_order = $db->getRow($sql); /* 匿名会员平均订单额: 购物总额/订单数 */ $guest_order_amount = $guest_all_order['order_num'] > 0 ? floatval($guest_all_order['turnover'] / $guest_all_order['order_num']) : '0.00'; $_GET['flag'] = isset($_GET['flag']) ? 'download' : ''; if ($_GET['flag'] == 'download') { $filename = ecs_iconv(EC_CHARSET, 'GB2312', $_LANG['guest_statistics']); header('Content-type: application/vnd.ms-excel; charset=GB2312'); header("Content-Disposition: attachment; filename={$filename}.xls"); /* 生成会员购买率 */ $data = $_LANG['percent_buy_member'] . "\t\n"; $data .= $_LANG['member_count'] . "\t" . $_LANG['order_member_count'] . "\t" . $_LANG['member_order_count'] . "\t" . $_LANG['percent_buy_member'] . "\n"; $data .= $user_num . "\t" . $have_order_usernum . "\t" . $user_all_order['order_num'] . "\t" . sprintf('%0.2f', ($user_num > 0 ? $have_order_usernum / $user_num : 0) * 100) . "\n\n"; /* 每会员平均订单数及购物额 */ $data .= $_LANG['order_turnover_peruser'] . "\t\n"; $data .= $_LANG['member_sum'] . "\t" . $_LANG['average_member_order'] . "\t" . $_LANG['member_order_sum'] . "\n";
/** * 获取用户中心默认页面所需的数据 * @access public * @param int $user_id 用户ID * @return array $info 默认页面所需资料数组 */ public function get_user_default($user_id) { $sql = "SELECT pay_points, user_money, credit_line, last_login, is_validated,user_rank FROM " . $this->pre . "users WHERE user_id = '{$user_id}'"; $row = $this->row($sql); $info = array(); $info['username'] = stripslashes($_SESSION['user_name']); $info['shop_name'] = C('shop_name'); $info['integral'] = $row['pay_points'] . C('integral_name'); /* 增加是否开启会员邮件验证开关 */ $info['is_validate'] = C('member_email_validate') && !$row['is_validated'] ? 0 : 1; $info['credit_line'] = $row['credit_line']; $info['formated_credit_line'] = price_format($info['credit_line'], false); //新增获取用户头像,昵称 $u_row = ''; if (class_exists('WechatController')) { if (method_exists('WechatController', 'get_avatar')) { $u_row = call_user_func(array('WechatController', 'get_avatar'), $user_id); } } if ($u_row) { $info['nickname'] = $u_row['nickname']; $info['headimgurl'] = $u_row['headimgurl']; } else { $info['nickname'] = $info['username']; $info['headimgurl'] = __PUBLIC__ . '/images/get_avatar.png'; } //如果$_SESSION中时间无效说明用户是第一次登录。取当前登录时间。 $last_time = !isset($_SESSION['last_time']) ? $row['last_login'] : $_SESSION['last_time']; if ($last_time == 0) { $_SESSION['last_time'] = $last_time = gmtime(); } $info['last_time'] = local_date(C('time_format'), $last_time); $info['surplus'] = price_format($row['user_money'], false); $this->table = 'order_info'; $condition = "user_id = '" . $user_id . "' AND add_time > '" . local_strtotime('-1 months') . "'"; $info['order_count'] = $this->count($condition); $condition = "user_id = '" . $user_id . "' AND shipping_time > '" . $last_time . "'" . order_query_sql('shipped'); $info['shipped_order'] = $this->select($condition, 'order_id, order_sn'); $info['user_rank'] = $row['user_rank']; return $info; }
function _wap_await_pay_count() { global $db, $ecs; $await_pay = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('order_info') . ' WHERE 1 ' . order_query_sql('await_pay') . ' AND supplier_id=' . $_SESSION['supplier_id']); return $await_pay; }
/** * 获取订单列表信息 * * @access public * @param * * @return void */ function order_list() { $result = get_filter(); if ($result === false) { /* 过滤信息 */ $filter['order_sn'] = empty($_REQUEST['order_sn']) ? '' : trim($_REQUEST['order_sn']); if (!empty($_GET['is_ajax']) && $_GET['is_ajax'] == 1) { $_REQUEST['consignee'] = json_str_iconv($_REQUEST['consignee']); //$_REQUEST['address'] = json_str_iconv($_REQUEST['address']); } /*add by hg for date 2014-04-23 获取代理商id begin*/ $filter['admin_agency_id'] = !empty($_REQUEST['admin_agency_id']) ? $_REQUEST['admin_agency_id'] : 0; /*end*/ /*add by ccx for date 2014-11-12 获取支付类型payment_method*/ $filter['payment_method'] = empty($_REQUEST['payment_method']) ? '' : trim($_REQUEST['payment_method']); /*end*/ $filter['start_date'] = empty($_REQUEST['start_date']) ? local_strtotime('-7 days') : $_REQUEST['start_date']; $filter['end_date'] = empty($_REQUEST['end_date']) ? local_strtotime('today') : $_REQUEST['end_date']; if (strpos($filter['start_date'], '-') !== false) { $filter['start_date'] = local_strtotime($filter['start_date']); $filter['end_date'] = local_strtotime($filter['end_date']); } //dump(date('Y-m-d H-i-s',$filter['end_date'])); $filter['consignee'] = empty($_REQUEST['consignee']) ? '' : trim($_REQUEST['consignee']); $filter['email'] = empty($_REQUEST['email']) ? '' : trim($_REQUEST['email']); $filter['address'] = empty($_REQUEST['address']) ? '' : trim($_REQUEST['address']); $filter['zipcode'] = empty($_REQUEST['zipcode']) ? '' : trim($_REQUEST['zipcode']); $filter['tel'] = empty($_REQUEST['tel']) ? '' : trim($_REQUEST['tel']); $filter['mobile'] = empty($_REQUEST['mobile']) ? 0 : intval($_REQUEST['mobile']); $filter['country'] = empty($_REQUEST['country']) ? 0 : intval($_REQUEST['country']); $filter['province'] = empty($_REQUEST['province']) ? 0 : intval($_REQUEST['province']); $filter['city'] = empty($_REQUEST['city']) ? 0 : intval($_REQUEST['city']); $filter['district'] = empty($_REQUEST['district']) ? 0 : intval($_REQUEST['district']); $filter['shipping_id'] = empty($_REQUEST['shipping_id']) ? 0 : intval($_REQUEST['shipping_id']); $filter['pay_id'] = empty($_REQUEST['pay_id']) ? 0 : intval($_REQUEST['pay_id']); $filter['order_status'] = isset($_REQUEST['order_status']) ? intval($_REQUEST['order_status']) : -1; $filter['shipping_status'] = isset($_REQUEST['shipping_status']) ? intval($_REQUEST['shipping_status']) : -1; $filter['pay_status'] = isset($_REQUEST['pay_status']) ? intval($_REQUEST['pay_status']) : -1; $filter['user_id'] = empty($_REQUEST['user_id']) ? 0 : intval($_REQUEST['user_id']); $filter['user_name'] = empty($_REQUEST['user_name']) ? '' : trim($_REQUEST['user_name']); $filter['composite_status'] = isset($_REQUEST['composite_status']) ? intval($_REQUEST['composite_status']) : -1; $filter['group_buy_id'] = isset($_REQUEST['group_buy_id']) ? intval($_REQUEST['group_buy_id']) : 0; $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'add_time' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $filter['start_time'] = empty($_REQUEST['start_time']) ? '' : (strpos($_REQUEST['start_time'], '-') > 0 ? local_strtotime($_REQUEST['start_time']) : $_REQUEST['start_time']); $filter['end_time'] = empty($_REQUEST['end_time']) ? '' : (strpos($_REQUEST['end_time'], '-') > 0 ? local_strtotime($_REQUEST['end_time']) : $_REQUEST['end_time']); $where = 'WHERE 1 '; /*add by hg for date 2014-04-22 只显示代理商本身所属订单 begin*/ $where .= agency_where(); /*end*/ if ($filter['order_sn']) { $where .= " AND o.order_sn LIKE '%" . mysql_like_quote($filter['order_sn']) . "%'"; } if ($filter['consignee']) { $where .= " AND o.consignee LIKE '%" . mysql_like_quote($filter['consignee']) . "%'"; } if ($filter['email']) { $where .= " AND o.email LIKE '%" . mysql_like_quote($filter['email']) . "%'"; } if ($filter['address']) { $where .= " AND o.address LIKE '%" . mysql_like_quote($filter['address']) . "%'"; } if ($filter['zipcode']) { $where .= " AND o.zipcode LIKE '%" . mysql_like_quote($filter['zipcode']) . "%'"; } if ($filter['tel']) { $where .= " AND o.tel LIKE '%" . mysql_like_quote($filter['tel']) . "%'"; } if ($filter['mobile']) { $where .= " AND o.mobile LIKE '%" . mysql_like_quote($filter['mobile']) . "%'"; } if ($filter['country']) { $where .= " AND o.country = '{$filter['country']}'"; } if ($filter['province']) { $where .= " AND o.province = '{$filter['province']}'"; } if ($filter['city']) { $where .= " AND o.city = '{$filter['city']}'"; } if ($filter['district']) { $where .= " AND o.district = '{$filter['district']}'"; } if ($filter['shipping_id']) { $where .= " AND o.shipping_id = '{$filter['shipping_id']}'"; } if ($filter['pay_id']) { $where .= " AND o.pay_id = '{$filter['pay_id']}'"; } /* ccx 2014-11-12 增加了对支付类型的搜索功能*/ if ($filter['payment_method']) { //$where .= " AND o.pay_id = '$filter[payment_method]'"; if ($filter['payment_method'] == 3) { $where .= " AND ( o.pay_id !=1 AND o.pay_id !=2 AND o.pay_id !=0)"; } elseif ($filter['payment_method'] == 1) { $where .= " AND o.pay_id = 1"; } elseif ($filter['payment_method'] == 2) { $where .= " AND o.pay_id = 2"; } } if ($filter['order_status'] != -1) { $where .= " AND o.order_status = '{$filter['order_status']}'"; } if ($filter['shipping_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['shipping_status']}'"; } if ($filter['pay_status'] != -1) { $where .= " AND o.pay_status = '{$filter['pay_status']}'"; } if ($filter['user_id']) { $where .= " AND o.user_id = '{$filter['user_id']}'"; } if ($filter['user_name']) { $where .= " AND u.user_name LIKE '%" . mysql_like_quote($filter['user_name']) . "%'"; } if ($filter['start_time']) { $where .= " AND o.add_time >= '{$filter['start_time']}'"; } if ($filter['end_time']) { $where .= " AND o.add_time <= '{$filter['end_time']}'"; } $where .= " AND o.add_time >= '" . $filter['start_date'] . "' AND o.add_time < '" . ($filter['end_date'] + 86400) . "'"; /*add by hg for date 2014-04-23 根据代理商筛选 begin*/ if (if_agency()) { if (!empty($filter['admin_agency_id'])) { if ($filter['admin_agency_id'] != '-') { $where .= " AND o.admin_agency_id = {$filter['admin_agency_id']}"; } else { $GLOBALS['smarty']->assign('show_agency', true); //查询整站订单 } } else { $where .= " AND o.admin_agency_id = 0"; } } /*end*/ //综合状态 switch ($filter['composite_status']) { case CS_AWAIT_PAY: $where .= order_query_sql('await_pay'); break; case CS_AWAIT_SHIP: $where .= order_query_sql('await_ship'); break; case CS_FINISHED: $where .= order_query_sql('finished'); break; case PS_PAYING: if ($filter['composite_status'] != -1) { $where .= " AND o.pay_status = '{$filter['composite_status']}' "; } break; case OS_SHIPPED_PART: if ($filter['composite_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['composite_status']}'-2 "; } break; default: if ($filter['composite_status'] != -1) { $where .= " AND o.order_status = '{$filter['composite_status']}' "; } } /* 团购订单 */ if ($filter['group_buy_id']) { $where .= " AND o.extension_code = 'group_buy' AND o.extension_id = '{$filter['group_buy_id']}' "; } /* 如果管理员属于某个办事处,只列出这个办事处管辖的订单 */ $sql = "SELECT agency_id FROM " . $GLOBALS['ecs']->table('admin_user') . " WHERE user_id = '{$_SESSION['admin_id']}'"; $agency_id = $GLOBALS['db']->getOne($sql); if ($agency_id > 0) { $where .= " AND o.agency_id = '{$agency_id}' "; } /* 分页大小 */ $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']); if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) { $filter['page_size'] = intval($_REQUEST['page_size']); } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) { $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']); } else { $filter['page_size'] = 15; } /* 记录总数 */ if ($filter['user_name']) { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o ," . $GLOBALS['ecs']->table('users') . " AS u " . $where; } else { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . $where; } $filter['record_count'] = $GLOBALS['db']->getOne($sql); $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1; /* 查询 */ $sql = "SELECT o.order_id, o.order_sn,o.add_time, o.order_status, o.shipping_status, " . "o.order_amount, o.money_paid,IFNULL(a.user_name, '主站') AS admin_user," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer " . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id LEFT JOIN " . $GLOBALS['ecs']->table('admin_user') . " as a ON a.agency_user_id=o.admin_agency_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; foreach (array('order_sn', 'consignee', 'email', 'address', 'zipcode', 'tel', 'user_name') as $val) { $filter[$val] = stripslashes($filter[$val]); } set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $row = $GLOBALS['db']->getAll($sql); /* 格式话数据 */ foreach ($row as $key => $value) { $row[$key]['formated_order_amount'] = price_format($value['order_amount']); $row[$key]['formated_money_paid'] = price_format($value['money_paid']); $row[$key]['formated_total_fee'] = price_format($value['total_fee']); $row[$key]['short_order_time'] = local_date('m-d H:i', $value['add_time']); if ($value['order_status'] == OS_INVALID || $value['order_status'] == OS_CANCELED) { /* 如果该订单为无效或取消则显示删除链接 */ $row[$key]['can_remove'] = 1; } else { $row[$key]['can_remove'] = 0; } /*ccx 2014-12-14 对已经抽奖过的订单,提示该订单不能进行退货和退款 开始 */ $sql_luck = "SELECT id FROM " . $GLOBALS['ecs']->table('lucky_draw') . " WHERE order_sn = '" . $value['order_sn'] . "'"; $lucky_draw = $GLOBALS['db']->getOne($sql_luck); $row[$key]['lucky_draw'] = $lucky_draw; /*ccx 2014-12-14 对已经抽奖过的订单,提示该订单不能进行退货和退款 结束 */ } /*统计总金额和应付金额 by hg for 2014-06-10*/ $overall_order_amount = overall_order_amount($sql); $GLOBALS['smarty']->assign('overall_formated_total_fee', price_format($overall_order_amount['overall_formated_total_fee'])); $GLOBALS['smarty']->assign('overall_formated_order_amount', price_format($overall_order_amount['overall_formated_order_amount'])); $GLOBALS['smarty']->assign('start_date', local_date('Y-m-d', $filter['start_date'])); $GLOBALS['smarty']->assign('end_date', local_date('Y-m-d', $filter['end_date'])); $filter['start_date'] = local_date('Y-m-d', $filter['start_date']); $filter['end_date'] = local_date('Y-m-d', $filter['end_date']); $arr = array('orders' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
/** * 获取用户中心默认页面所需的数据 * * @access public * @param int $user_id 用户ID * * @return array $info 默认页面所需资料数组 */ function get_user_default($user_id) { $user_bonus = get_user_bonus(); $paystatus = PS_PAYED; $sql = "SELECT pay_points, user_money, head_img, credit_line, last_login, is_validated, phonestatus, emailstatus, idcardstatus, bangcardstatus FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '{$user_id}'"; $row = $GLOBALS['db']->getRow($sql); $info = array(); $info['username'] = stripslashes($_SESSION['user_name']); $info['shop_name'] = $GLOBALS['_CFG']['shop_name']; $info['integral'] = $row['pay_points'] . $GLOBALS['_CFG']['integral_name']; $info['phonestatus'] = $row['phonestatus']; $info['emailstatus'] = $row['emailstatus']; $info['idcardstatus'] = $row['idcardstatus']; $info['bangcardstatus'] = $row['bangcardstatus']; $info['user_head_img'] = empty($row['head_img']) ? '0' : $row['head_img']; /* 增加是否开启会员邮件验证开关 */ $info['is_validate'] = $GLOBALS['_CFG']['member_email_validate'] && !$row['is_validated'] ? 0 : 1; $info['credit_line'] = $row['credit_line']; $info['formated_credit_line'] = price_format($info['credit_line'], false); //如果$_SESSION中时间无效说明用户是第一次登录。取当前登录时间。 $last_time = !isset($_SESSION['last_time']) ? $row['last_login'] : $_SESSION['last_time']; if ($last_time == 0) { $_SESSION['last_time'] = $last_time = gmtime(); } $info['last_time'] = local_date($GLOBALS['_CFG']['time_format'], $last_time); $info['surplus'] = price_format($row['user_money'], false); $info['frozen'] = price_format($row['frozen_money'], false); $info['bonus'] = sprintf($GLOBALS['_LANG']['user_bonus_info'], $user_bonus['bonus_count'], price_format($user_bonus['bonus_value'], false)); $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_goods') . " WHERE user_id = '" . $user_id . "' AND add_time > '" . local_strtotime('-1 months') . "'"; $info['order_count'] = $GLOBALS['db']->getOne($sql); /* 理财资产*/ $sqlsum = "SELECT SUM(invest_price) FROM " . $GLOBALS['ecs']->table('order_goods') . " where pay_status =" . $paystatus . " and user_id =" . $user_id; $info['order_sum'] = $GLOBALS['db']->getOne($sqlsum); $info['order_sum'] = empty($info['order_sum']) ? '0.00' : $info['order_sum']; /* 借款负债*/ //$sqlborrow = "SELECT SUM(borrow_num) FROM ".$GLOBALS['ecs']->table('user_borrow')." where borrow_status = 1 and user_id =".$user_id; //$info['borrow_sum'] = $GLOBALS['db']->getOne($sqlborrow); //$info['borrow_sum'] = empty($info['borrow_sum'])?'0.00':$info['borrow_sum']; /* 账户净资产*/ $info['account_sum'] = $info['order_sum'] - $info['borrow_sum'] + $info['surplus']; $info['account_sum'] = empty($info['account_sum']) ? '0.00' : $info['account_sum']; include_once ROOT_PATH . 'includes/lib_order.php'; $sql = "SELECT order_id, order_sn " . " FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE user_id = '" . $user_id . "' AND shipping_time > '" . $last_time . "'" . order_query_sql('shipped'); $info['shipped_order'] = $GLOBALS['db']->getAll($sql); return $info; }
$res = array('error' => 0, 'new_orders' => 0, 'new_paid' => 0); $_REQUEST['username'] = urlencode(serialize(json_str_iconv($_REQUEST['username']))); /* 检查密码是否正确 */ $sql = "SELECT COUNT(*) ". " FROM " . $ecs->table('admin_user') . " WHERE user_name = '" . trim($_REQUEST['username']). "' AND password = '******'password'])) . "'"; if ($db->getOne($sql)) { /* 新订单 */ $sql = 'SELECT COUNT(*) FROM ' . $ecs->table('order_info'). " WHERE order_status = " . OS_UNCONFIRMED; $res['new_orders'] = $db->getOne($sql); /* 待发货的订单: */ $sql = 'SELECT COUNT(*)'. ' FROM ' .$ecs->table('order_info') . " WHERE 1 ". order_query_sql('await_ship'); $res['new_paid'] = $db->getOne($sql); } else { $res['error'] = 1; } $val = $json->encode($res); die($val); ?>
/** * 取得销售排行数据信息 * @param bool $is_pagination 是否分页 * @return array 销售排行数据 */ function get_sales_order($is_pagination = true) { $filter['start_date'] = empty($_REQUEST['start_date']) ? '' : local_strtotime($_REQUEST['start_date']); $filter['end_date'] = empty($_REQUEST['end_date']) ? '' : local_strtotime($_REQUEST['end_date']); $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'goods_num' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); /*add by hg for date 2014-04-23 获取代理商信息 begin*/ $admin_agency_id = !empty($_REQUEST['admin_agency_id']) ? $_REQUEST['admin_agency_id'] : '0'; $res = agency_list(); $agency_list = array('-' => '全站销售排行'); foreach ($res as $re_k => $res_v) { $agency_list[$re_k] = $res_v; } $GLOBALS['smarty']->assign('agency_list', $agency_list); $GLOBALS['smarty']->assign('admin_agency_id', $admin_agency_id); $action_list = if_agency() ? 'all' : ''; $GLOBALS['smarty']->assign('all', $action_list); /*end*/ /*add by hg for date 2014-04-22 加入代理商条件*/ $agency_where = agency_where(); if (!empty($agency_where)) { $whereArr = explode(' ', $agency_where); $sale_where = $whereArr[0] . $whereArr[1] . ' oi.' . $whereArr[2] . $whereArr[3] . $whereArr[4]; } /*end*/ $where = " WHERE og.order_id = oi.order_id " . order_query_sql('finished', 'oi.'); if ($filter['start_date']) { $where .= " AND oi.add_time >= '" . $filter['start_date'] . "'"; } if ($filter['end_date']) { $where .= " AND oi.add_time <= '" . $filter['end_date'] . "'"; } /*add by hg for date 2014-04-23 根据代理商筛选 begin*/ if (!empty($admin_agency_id) && if_agency()) { if ($admin_agency_id != '-') { $where .= " AND oi.admin_agency_id = '{$admin_agency_id}' "; } } elseif (if_agency()) { $where .= " AND oi.admin_agency_id = '0' "; } /*end*/ $sql = "SELECT COUNT(distinct(og.goods_id)) FROM " . $GLOBALS['ecs']->table('order_info') . ' AS oi,' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . $where; $filter['record_count'] = $GLOBALS['db']->getOne($sql); /* 分页大小 */ $filter = page_and_size($filter); $sql = "SELECT og.goods_id, og.goods_sn, og.goods_name, oi.order_status, " . "SUM(og.goods_number) AS goods_num, SUM(og.goods_number * og.goods_price) AS turnover " . "FROM " . $GLOBALS['ecs']->table('order_goods') . " AS og, " . $GLOBALS['ecs']->table('order_info') . " AS oi " . $where . $sale_where . " GROUP BY og.goods_id " . ' ORDER BY ' . $filter['sort_by'] . ' ' . $filter['sort_order']; if ($is_pagination) { $sql .= " LIMIT " . $filter['start'] . ', ' . $filter['page_size']; } $sales_order_data = $GLOBALS['db']->getAll($sql); foreach ($sales_order_data as $key => $item) { $sales_order_data[$key]['wvera_price'] = price_format($item['goods_num'] ? $item['turnover'] / $item['goods_num'] : 0); $sales_order_data[$key]['short_name'] = sub_str($item['goods_name'], 30, true); $sales_order_data[$key]['turnover'] = price_format($item['turnover']); $sales_order_data[$key]['taxis'] = $key + 1; } $arr = array('sales_order_data' => $sales_order_data, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
/** * 取得订单概况数据(包括订单的几种状态) * @param $start_date 开始查询的日期 * @param $end_date 查询的结束日期 * @return $order_info 订单概况数据 */ function get_orderinfo($start_date, $end_date) { $order_info = array(); /* 未确认订单数 */ $sql = 'SELECT COUNT(*) AS unconfirmed_num FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_status = '" . OS_UNCONFIRMED . "' AND add_time >= '{$start_date}'" . " AND add_time < '" . ($end_date + 86400) . "'"; $order_info['unconfirmed_num'] = $GLOBALS['db']->getOne($sql); /* 已确认订单数 */ $sql = 'SELECT COUNT(*) AS confirmed_num FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_status = '" . OS_CONFIRMED . "' AND shipping_status NOT " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . " AND pay_status NOT" . db_create_in(array(PS_PAYED, PS_PAYING)) . " AND add_time >= '{$start_date}'" . " AND add_time < '" . ($end_date + 86400) . "'"; $order_info['confirmed_num'] = $GLOBALS['db']->getOne($sql); /* 已成交订单数 */ $sql = 'SELECT COUNT(*) AS succeed_num FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE 1 " . order_query_sql('finished') . " AND add_time >= '{$start_date}' AND add_time < '" . ($end_date + 86400) . "'"; $order_info['succeed_num'] = $GLOBALS['db']->getOne($sql); /* 无效或已取消订单数 */ $sql = "SELECT COUNT(*) AS invalid_num FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_status > '" . OS_CONFIRMED . "'" . " AND add_time >= '{$start_date}' AND add_time < '" . ($end_date + 86400) . "'"; $order_info['invalid_num'] = $GLOBALS['db']->getOne($sql); return $order_info; }
/** * 获取订单列表信息 * * @access public * @param * * @return void */ function order_list() { $result = get_filter(); if ($result === false) { /* 过滤信息 */ $filter['order_sn'] = empty($_REQUEST['order_sn']) ? '' : trim($_REQUEST['order_sn']); if (!empty($_GET['is_ajax']) && $_GET['is_ajax'] == 1) { $_REQUEST['consignee'] = json_str_iconv($_REQUEST['consignee']); //$_REQUEST['address'] = json_str_iconv($_REQUEST['address']); } $filter['consignee'] = empty($_REQUEST['consignee']) ? '' : trim($_REQUEST['consignee']); $filter['composite_status'] = isset($_REQUEST['composite_status']) ? intval($_REQUEST['composite_status']) : -1; $filter['start_time'] = empty($_REQUEST['start_time']) ? '' : (strpos($_REQUEST['start_time'], '-') > 0 ? local_strtotime($_REQUEST['start_time']) : $_REQUEST['start_time']); $filter['end_time'] = empty($_REQUEST['end_time']) ? '' : (strpos($_REQUEST['end_time'], '-') > 0 ? local_strtotime($_REQUEST['end_time']) : $_REQUEST['end_time']); $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'add_time' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $filter['rebateid'] = isset($_REQUEST['rebateid']) && !empty($_REQUEST['rebateid']) && intval($_REQUEST['rebateid']) > 0 ? intval($_REQUEST['rebateid']) : 0; $filter['isreb'] = !isset($_REQUEST['isreb']) ? 1 : intval($_REQUEST['isreb']); ishavereb($filter['rebateid']); //$where = 'WHERE 1 '; $where = $filter['rebateid'] > 0 ? 'WHERE o.rebate_id = ' . $filter['rebateid'] : 'WHERE 1'; $where .= " AND o.rebate_ispay = " . $filter['isreb']; if ($filter['order_sn']) { $where .= " AND o.order_sn LIKE '%" . mysql_like_quote($filter['order_sn']) . "%'"; } if ($filter['consignee']) { $where .= " AND o.consignee LIKE '%" . mysql_like_quote($filter['consignee']) . "%'"; } //综合状态 switch ($filter['composite_status']) { case CS_AWAIT_PAY: $where .= order_query_sql('await_pay'); break; case CS_AWAIT_SHIP: $where .= order_query_sql('await_ship'); break; case CS_FINISHED: $where .= order_query_sql('finished'); break; case PS_PAYING: if ($filter['composite_status'] != -1) { $where .= " AND o.pay_status = '{$filter['composite_status']}' "; } break; case OS_SHIPPED_PART: if ($filter['composite_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['composite_status']}'-2 "; } break; default: if ($filter['composite_status'] != -1) { $where .= " AND o.order_status = '{$filter['composite_status']}' "; } } /* 分页大小 */ $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']); if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) { $filter['page_size'] = intval($_REQUEST['page_size']); } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) { $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']); } else { $filter['page_size'] = 15; } /* 记录总数 */ $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . $where; $filter['record_count'] = $GLOBALS['db']->getOne($sql); $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1; /* 查询 */ $sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, o.shipping_time, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer " . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; //echo $sql; foreach (array('order_sn', 'consignee', 'email', 'address', 'zipcode', 'tel', 'user_name') as $val) { $filter[$val] = stripslashes($filter[$val]); } set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $row = $GLOBALS['db']->getAll($sql); /* 格式话数据 */ foreach ($row as $key => $value) { $is_order = $is_shipping = $is_pay = 0; $row[$key]['formated_order_amount'] = price_format($value['order_amount']); $row[$key]['formated_money_paid'] = price_format($value['money_paid']); $row[$key]['formated_total_fee'] = price_format($value['total_fee']); $row[$key]['short_order_time'] = local_date('m-d H:i', $value['add_time']); $row[$key]['is_rebeat'] = 0; if ($value['order_status'] == OS_INVALID || $value['order_status'] == OS_CANCELED) { /* 如果该订单为无效或取消则显示删除链接 */ $row[$key]['can_remove'] = 1; } else { $row[$key]['can_remove'] = 0; } //订单状态 if ($value['order_status'] == OS_CONFIRMED || $value['order_status'] == OS_SPLITED) { $is_order = 1; } //配送状态 if ($value['shipping_status'] == SS_SHIPPED || $value['shipping_status'] == SS_RECEIVED) { $is_shipping = 1; } //支付状态 if ($value['pay_status'] == PS_PAYED) { $is_pay = 1; } if ($is_order && $is_shipping && $is_pay) { $row[$key]['is_rebeat'] = 1; $cha = getdatecha($value['shipping_time']); $row[$key]['datas'] = $GLOBALS['_CFG']['tuihuan_days_qianshou'] - $cha; } } $arr = array('orders' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
* ============================================================================ * 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。 * 网站地址: http://www.ecshop.com; * ---------------------------------------------------------------------------- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和 * 使用;不允许对程序代码以任何形式任何目的的再发布。 * ============================================================================ * $Author: liuhui $ * $Id: checkorder.php 17200 2010-10-14 03:02:27Z liuhui $ */ define('IN_ECS', true); require './init.php'; require_once ROOT_PATH . 'includes/lib_order.php'; require_once '../includes/cls_json.php'; $json = new JSON(); $res = array('error' => 0, 'new_orders' => 0, 'new_paid' => 0); $_REQUEST['username'] = urlencode(serialize(json_str_iconv($_REQUEST['username']))); /* 检查密码是否正确 */ $sql = "SELECT COUNT(*) " . " FROM " . $ecs->table('admin_user') . " WHERE user_name = '" . trim($_REQUEST['username']) . "' AND password = '******'password'])) . "'"; if ($db->getOne($sql)) { /* 新订单 */ $sql = 'SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE order_status = " . OS_UNCONFIRMED; $res['new_orders'] = $db->getOne($sql); /* 待发货的订单: */ $sql = 'SELECT COUNT(*)' . ' FROM ' . $ecs->table('order_info') . " WHERE 1 " . order_query_sql('await_ship'); $res['new_paid'] = $db->getOne($sql); } else { $res['error'] = 1; } $val = $json->encode($res); die($val);
/** * 取得销售明细数据信息 * @param bool $is_pagination 是否分页 * @return array 销售明细数据 */ function get_sale_list($is_pagination = true) { /* 时间参数 */ $filter['start_date'] = empty($_REQUEST['start_date']) ? local_strtotime('-7 days') : local_strtotime($_REQUEST['start_date']); $filter['end_date'] = empty($_REQUEST['end_date']) ? local_strtotime('today') : local_strtotime($_REQUEST['end_date']); /* 查询数据的条件 */ $where = " WHERE og.order_id = oi.order_id" . order_query_sql('finished', 'oi.') . " AND oi.add_time >= '" . $filter['start_date'] . "' AND oi.add_time < '" . ($filter['end_date'] + 86400) . "'"; $sql = "SELECT COUNT(og.goods_id) FROM " . $GLOBALS['ecs']->table('order_info') . ' AS oi,' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' . $where; $filter['record_count'] = $GLOBALS['db']->getOne($sql); /* 分页大小 */ $filter = page_and_size($filter); $sql = 'SELECT og.goods_id, og.goods_sn, og.goods_name, og.goods_number AS goods_num, og.goods_price ' . 'AS sales_price, oi.add_time AS sales_time, oi.order_id, oi.order_sn ' . "FROM " . $GLOBALS['ecs']->table('order_goods') . " AS og, " . $GLOBALS['ecs']->table('order_info') . " AS oi " . $where . " ORDER BY sales_time DESC, goods_num DESC"; if ($is_pagination) { $sql .= " LIMIT " . $filter['start'] . ', ' . $filter['page_size']; } $sale_list_data = $GLOBALS['db']->getAll($sql); foreach ($sale_list_data as $key => $item) { $sale_list_data[$key]['sales_price'] = price_format($sale_list_data[$key]['sales_price']); $sale_list_data[$key]['sales_time'] = local_date($GLOBALS['_CFG']['time_format'], $sale_list_data[$key]['sales_time']); } $arr = array('sale_list_data' => $sale_list_data, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
/** * 获取用户中心默认页面所需的数据. * * @param int $user_id 用户ID * * @return array $info 默认页面所需资料数组 */ function get_user_default($user_id) { $user_bonus = get_user_bonus(); $sql = 'SELECT pay_points, user_money, credit_line, last_login, is_validated FROM ' . $GLOBALS['ecs']->table('users') . " WHERE user_id = '{$user_id}'"; $row = $GLOBALS['db']->getRow($sql); $info = array(); $info['username'] = stripslashes($_SESSION['user_name']); $info['shop_name'] = $GLOBALS['_CFG']['shop_name']; $info['integral'] = $row['pay_points'] . $GLOBALS['_CFG']['integral_name']; /* 增加是否开启会员邮件验证开关 */ $info['is_validate'] = $GLOBALS['_CFG']['member_email_validate'] && !$row['is_validated'] ? 0 : 1; $info['credit_line'] = $row['credit_line']; $info['formated_credit_line'] = price_format($info['credit_line'], false); //如果$_SESSION中时间无效说明用户是第一次登录。取当前登录时间。 $last_time = !isset($_SESSION['last_time']) ? $row['last_login'] : $_SESSION['last_time']; if ($last_time == 0) { $_SESSION['last_time'] = $last_time = gmtime(); } $info['last_time'] = local_date($GLOBALS['_CFG']['time_format'], $last_time); $info['surplus'] = price_format($row['user_money'], false); $info['bonus'] = sprintf($GLOBALS['_LANG']['user_bonus_info'], $user_bonus['bonus_count'], price_format($user_bonus['bonus_value'], false)); $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE user_id = '" . $user_id . "' AND add_time > '" . local_strtotime('-1 months') . "'"; $info['order_count'] = $GLOBALS['db']->getOne($sql); include_once ROOT_PATH . 'includes/lib_order.php'; $sql = 'SELECT order_id, order_sn ' . ' FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE user_id = '" . $user_id . "' AND shipping_time > '" . $last_time . "'" . order_query_sql('shipped'); $info['shipped_order'] = $GLOBALS['db']->getAll($sql); return $info; }
/** * 取得访问和购买次数统计数据 * * @param int $cat_id 分类编号 * @param int $brand_id 品牌编号 * @param int $show_num 显示个数 * @return array $click_sold_info 访问购买比例数据 */ function click_sold_info($cat_id, $brand_id, $show_num, $admin_agency_id) { global $db, $ecs; /*add by hg for date 2014-04-22 加入代理商条件*/ $agency_where = agency_where(); if (!empty($agency_where)) { $whereArr = explode(' ', $agency_where); $sale_where = $whereArr[0] . $whereArr[1] . ' o.' . $whereArr[2] . $whereArr[3] . $whereArr[4]; } /*end*/ $where = " WHERE o.order_id = og.order_id AND g.goods_id = og.goods_id " . order_query_sql('finished', 'o.'); $limit = " LIMIT " . $show_num; if ($cat_id > 0) { $where .= " AND " . get_children($cat_id); } if ($brand_id > 0) { $where .= " AND g.brand_id = '{$brand_id}' "; } /*add by hg for date 2014-04-23 根据代理商筛选 begin*/ if (!empty($admin_agency_id) && if_agency()) { if ($admin_agency_id != '-') { $where .= " AND o.admin_agency_id = '{$admin_agency_id}' "; } } elseif (if_agency()) { $where .= " AND o.admin_agency_id = '0' "; } /*end*/ $click_sold_info = array(); $sql = "SELECT og.goods_id, g.goods_sn, g.goods_name, g.click_count, COUNT(og.goods_id) AS sold_times " . " FROM " . $ecs->table('goods') . " AS g, " . $ecs->table('order_goods') . " AS og, " . $ecs->table('order_info') . " AS o " . $where . $sale_where . " GROUP BY og.goods_id ORDER BY g.click_count DESC " . $limit; $res = $db->query($sql); while ($item = $db->fetchRow($res)) { if ($item['click_count'] <= 0) { $item['scale'] = 0; } else { /* 每一百个点击的订单比率 */ $item['scale'] = sprintf("%0.2f", $item['sold_times'] / $item['click_count'] * 100) . '%'; } $click_sold_info[] = $item; } return $click_sold_info; }
$sql = 'SELECT message_id, sender_id, receiver_id, sent_time, readed, deleted, title, message, user_name ' . 'FROM ' . $ecs->table('admin_message') . ' AS a, ' . $ecs->table('admin_user') . ' AS b ' . "WHERE a.sender_id = b.user_id AND a.receiver_id = '{$_SESSION['admin_id']}' AND " . "a.readed = 0 AND deleted = 0 ORDER BY a.sent_time DESC"; $admin_msg = $db->GetAll($sql); $smarty->assign('admin_msg', $admin_msg); /* 取得支持货到付款和不支持货到付款的支付方式 */ $ids = get_pay_ids(); /* 已完成的订单 */ $order['finished'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE 1 " . order_query_sql('finished')); $status['finished'] = CS_FINISHED; /* 待发货的订单: */ $order['await_ship'] = $db->GetOne('SELECT COUNT(*)' . ' FROM ' . $ecs->table('order_info') . " WHERE 1 " . order_query_sql('await_ship')); $status['await_ship'] = CS_AWAIT_SHIP; /* 待付款的订单: */ $order['await_pay'] = $db->GetOne('SELECT COUNT(*)' . ' FROM ' . $ecs->table('order_info') . " WHERE 1 " . order_query_sql('await_pay')); $status['await_pay'] = CS_AWAIT_PAY; /* “未确认”的订单 */ $order['unconfirmed'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE 1 " . order_query_sql('unconfirmed')); $status['unconfirmed'] = OS_UNCONFIRMED; $order['stats'] = $db->getRow('SELECT COUNT(*) AS oCount, IFNULL(SUM(order_amount), 0) AS oAmount' . ' FROM ' . $ecs->table('order_info')); $smarty->assign('order', $order); $smarty->assign('status', $status); /* 商品信息 */ $goods['total'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_alone_sale = 1 AND is_real = 1'); $virtual_card['total'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_alone_sale = 1 AND is_real=0 AND extension_code=\'virtual_card\''); $goods['new'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_new = 1 AND is_real = 1'); $virtual_card['new'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_new = 1 AND is_real=0 AND extension_code=\'virtual_card\''); $goods['best'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_best = 1 AND is_real = 1'); $virtual_card['best'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_best = 1 AND is_real=0 AND extension_code=\'virtual_card\''); $goods['hot'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_hot = 1 AND is_real = 1'); $virtual_card['hot'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND is_hot = 1 AND is_real=0 AND extension_code=\'virtual_card\''); $time = gmtime(); $goods['promote'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('goods') . ' WHERE is_delete = 0 AND promote_price>0' . " AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}' AND is_real = 1");
$status['await_pay'] = CS_AWAIT_PAY; //待确认订单 $sql = 'SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE supplier_id=0 " . order_query_sql('unconfirmed'); $order['unconfirmed'] = $db->getOne($sql); $status['unconfirmed'] = OS_UNCONFIRMED; //部分发货的订单 $order['shipped_part'] = $db->GetOne('SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE supplier_id=0 AND shipping_status=" . SS_SHIPPED_PART); $status['shipped_part'] = OS_SHIPPED_PART; //退款申请 $order['new_repay'] = $db->getOne('SELECT COUNT(*) FROM ' . $ecs->table('back_order') . ' WHERE status_back=5 AND back_type=4 AND supplier_id=0'); //退货申请 $order['returns'] = $db->getOne('SELECT COUNT(*) FROM ' . $ecs->table('back_order') . ' WHERE status_back=5 AND back_type=1 AND supplier_id=0'); //缺货登记 $order['booking_goods'] = $db->getOne('SELECT COUNT(*) FROM ' . $ecs->table('booking_goods') . ' AS bg LEFT JOIN ' . $ecs->table('goods') . ' AS g ON bg.goods_id=g.goods_id WHERE g.supplier_id=0 AND is_dispose=0'); //成交订单数 $sql = 'SELECT COUNT(*) FROM ' . $ecs->table('order_info') . " WHERE supplier_id=0 " . order_query_sql('finished'); $order['finished'] = $db->GetOne($sql); $status['finished'] = CS_FINISHED; $smarty->assign('order', $order); $smarty->assign('status', $status); //每月数据统计 //当月订单来源统计 $froms_tooltip = array('trigger' => 'item', 'formatter' => '{a} <br/>{b} : {c} ({d}%)'); $froms_legend = array('orient' => 'vertical', 'x' => 'left', 'y' => '20', 'data' => array()); $froms_toolbox = array('show' => true, 'feature' => array('magicType' => array('show' => true, 'type' => array('pie', 'funnel')), 'restore' => array('show' => true), 'saveAsImage' => array('show' => true))); $froms_calculable = true; $froms_series = array(array('type' => 'pie', 'radius' => '55%', 'center' => array('50%', '60%'))); $froms_data = array(); $froms_options = array(); $sql = 'SELECT `froms`, count(*) AS `count` FROM ' . $ecs->table('order_info') . ' WHERE `confirm_time` BETWEEN ' . $month_start . ' AND ' . $month_end . ' AND supplier_id=0 GROUP BY `froms` ORDER BY `count` DESC'; $result = $db->query($sql);
/** * 获取用户可以和并的订单数组 * * @access public * @param int $user_id 用户ID * * @return array $merge 可合并订单数组 */ function get_user_merge($user_id) { include_once ROOT_PATH . 'includes/lib_order.php'; $sql = "SELECT order_sn FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE user_id = '{$user_id}' " . order_query_sql('unprocessed') . "AND extension_code = '' " . " ORDER BY add_time DESC"; $list = $GLOBALS['db']->GetCol($sql); $merge = array(); foreach ($list as $val) { $merge[$val] = $val; } return $merge; }
/** * 获取订单列表信息 * * @access public * @param * * @return void */ function order_list() { $result = get_filter(); if ($result === false) { /* 过滤信息 */ $filter['order_sn'] = empty($_REQUEST['order_sn']) ? '' : trim($_REQUEST['order_sn']); if (!empty($_GET['is_ajax']) && $_GET['is_ajax'] == 1) { $_REQUEST['consignee'] = json_str_iconv($_REQUEST['consignee']); //$_REQUEST['address'] = json_str_iconv($_REQUEST['address']); } $filter['consignee'] = empty($_REQUEST['consignee']) ? '' : trim($_REQUEST['consignee']); $filter['email'] = empty($_REQUEST['email']) ? '' : trim($_REQUEST['email']); $filter['address'] = empty($_REQUEST['address']) ? '' : trim($_REQUEST['address']); $filter['zipcode'] = empty($_REQUEST['zipcode']) ? '' : trim($_REQUEST['zipcode']); $filter['tel'] = empty($_REQUEST['tel']) ? '' : trim($_REQUEST['tel']); $filter['mobile'] = empty($_REQUEST['mobile']) ? 0 : intval($_REQUEST['mobile']); $filter['country'] = empty($_REQUEST['country']) ? 0 : intval($_REQUEST['country']); $filter['province'] = empty($_REQUEST['province']) ? 0 : intval($_REQUEST['province']); $filter['city'] = empty($_REQUEST['city']) ? 0 : intval($_REQUEST['city']); $filter['district'] = empty($_REQUEST['district']) ? 0 : intval($_REQUEST['district']); $filter['shipping_id'] = empty($_REQUEST['shipping_id']) ? 0 : intval($_REQUEST['shipping_id']); $filter['pay_id'] = empty($_REQUEST['pay_id']) ? 0 : intval($_REQUEST['pay_id']); $filter['order_status'] = isset($_REQUEST['order_status']) ? intval($_REQUEST['order_status']) : -1; $filter['shipping_status'] = isset($_REQUEST['shipping_status']) ? intval($_REQUEST['shipping_status']) : -1; $filter['pay_status'] = isset($_REQUEST['pay_status']) ? intval($_REQUEST['pay_status']) : -1; $filter['user_id'] = empty($_REQUEST['user_id']) ? 0 : intval($_REQUEST['user_id']); $filter['user_name'] = empty($_REQUEST['user_name']) ? '' : trim($_REQUEST['user_name']); $filter['composite_status'] = isset($_REQUEST['composite_status']) ? intval($_REQUEST['composite_status']) : -1; $filter['group_buy_id'] = isset($_REQUEST['group_buy_id']) ? intval($_REQUEST['group_buy_id']) : 0; $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'add_time' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $filter['start_time'] = empty($_REQUEST['start_time']) ? '' : (strpos($_REQUEST['start_time'], '-') > 0 ? local_strtotime($_REQUEST['start_time']) : $_REQUEST['start_time']); $filter['end_time'] = empty($_REQUEST['end_time']) ? '' : (strpos($_REQUEST['end_time'], '-') > 0 ? local_strtotime($_REQUEST['end_time']) : $_REQUEST['end_time']); /* 代码增加_start By www.ecshop68.com */ $filter['order_type'] = isset($_REQUEST['order_type']) ? intval($_REQUEST['order_type']) : 0; /* 代码增加_end By www.ecshop68.com */ $filter['supp'] = isset($_REQUEST['supp']) && !empty($_REQUEST['supp']) && intval($_REQUEST['supp']) > 0 ? intval($_REQUEST['supp']) : 0; $filter['suppid'] = isset($_REQUEST['suppid']) && !empty($_REQUEST['suppid']) && intval($_REQUEST['suppid']) > 0 ? intval($_REQUEST['suppid']) : 0; /*增值税发票_添加_START_www.68ecshop.com*/ $filter['inv_status'] = empty($_REQUEST['inv_status']) ? '' : trim($_REQUEST['inv_status']); $filter['inv_type'] = empty($_REQUEST['inv_type']) ? '' : trim($_REQUEST['inv_type']); $filter['vat_inv_consignee_name'] = empty($_REQUEST['vat_inv_consignee_name']) ? '' : trim($_REQUEST['vat_inv_consignee_name']); $filter['vat_inv_consignee_phone'] = empty($_REQUEST['vat_inv_consignee_phone']) ? '' : trim($_REQUEST['vat_inv_consignee_phone']); $filter['add_time'] = empty($_REQUEST['add_time']) ? '' : (strpos($_REQUEST['add_time'], '-') > 0 ? local_strtotime($_REQUEST['add_time']) : $_REQUEST['add_time']); if (!empty($filter['add_time'])) { $filter['start_time'] = $filter['add_time']; $filter['end_time'] = $filter['add_time'] + '86400'; } /*增值税发票_添加_END_www.68ecshop.com*/ //$where = 'WHERE 1 '; $where = $filter['supp'] > 0 ? 'WHERE o.supplier_id > 0' : 'WHERE o.supplier_id = 0'; if ($filter['suppid']) { //$where .= " AND o.supplier_id = ".$filter['suppid']; $where = 'WHERE o.supplier_id = ' . $filter['suppid']; } if ($filter['order_sn']) { $where .= " AND o.order_sn LIKE '%" . mysql_like_quote($filter['order_sn']) . "%'"; } if ($filter['consignee']) { $where .= " AND o.consignee LIKE '%" . mysql_like_quote($filter['consignee']) . "%'"; } if ($filter['email']) { $where .= " AND o.email LIKE '%" . mysql_like_quote($filter['email']) . "%'"; } if ($filter['address']) { $where .= " AND o.address LIKE '%" . mysql_like_quote($filter['address']) . "%'"; } if ($filter['zipcode']) { $where .= " AND o.zipcode LIKE '%" . mysql_like_quote($filter['zipcode']) . "%'"; } if ($filter['tel']) { $where .= " AND o.tel LIKE '%" . mysql_like_quote($filter['tel']) . "%'"; } if ($filter['mobile']) { $where .= " AND o.mobile LIKE '%" . mysql_like_quote($filter['mobile']) . "%'"; } if ($filter['country']) { $where .= " AND o.country = '{$filter['country']}'"; } if ($filter['province']) { $where .= " AND o.province = '{$filter['province']}'"; } if ($filter['city']) { $where .= " AND o.city = '{$filter['city']}'"; } if ($filter['district']) { $where .= " AND o.district = '{$filter['district']}'"; } if ($filter['shipping_id']) { $where .= " AND o.shipping_id = '{$filter['shipping_id']}'"; } if ($filter['pay_id']) { $where .= " AND o.pay_id = '{$filter['pay_id']}'"; } if ($filter['order_status'] != -1) { $where .= " AND o.order_status = '{$filter['order_status']}'"; } if ($filter['shipping_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['shipping_status']}'"; } if ($filter['pay_status'] != -1) { $where .= " AND o.pay_status = '{$filter['pay_status']}'"; } if ($filter['user_id']) { $where .= " AND o.user_id = '{$filter['user_id']}'"; } if ($filter['user_name']) { $where .= " AND u.user_name LIKE '%" . mysql_like_quote($filter['user_name']) . "%'"; } if ($filter['start_time']) { $where .= " AND o.add_time >= '{$filter['start_time']}'"; } if ($filter['end_time']) { $where .= " AND o.add_time <= '{$filter['end_time']}'"; } /*增值税发票_添加_START_www.68ecshop.com*/ if ($filter['inv_status']) { $where .= " AND o.inv_status = '{$filter['inv_status']}'"; } if ($filter['inv_type']) { $where .= " AND o.inv_type = '{$filter['inv_type']}'"; } if ($filter['vat_inv_consignee_name']) { $where .= " AND o.inv_consignee_name = '{$filter['vat_inv_consignee_name']}'"; } if ($filter['vat_inv_consignee_phone']) { $where .= " AND o.inv_consignee_phone = '{$filter['vat_inv_consignee_phone']}'"; } if ($_REQUEST['act'] == 'invoice_list' || isset($_REQUEST['act_detail']) && $_REQUEST['act_detail'] == 'invoice_query') { $where .= " AND o.inv_type != ''"; } /* 普通订单不显示虚拟团购订单 添加_START_www.68ecshop.com*/ $where .= " AND o.extension_code != 'virtual_good'"; /* 普通订单不显示虚拟团购订单 添加_END_www.68ecshop.com*/ /*增值税发票_添加_END_www.68ecshop.com*/ /* 代码增加_start By www.ecshop68.com */ switch ($filter['order_type']) { case 1: $where .= " AND o.is_pickup = 0"; break; case 2: $where .= " AND o.is_pickup > 0"; break; } /* 代码增加_end By www.ecshop68.com */ //综合状态 switch ($filter['composite_status']) { case CS_AWAIT_PAY: $where .= order_query_sql('await_pay'); break; case CS_AWAIT_SHIP: $where .= order_query_sql('await_ship'); break; case CS_FINISHED: $where .= order_query_sql('finished'); break; case PS_PAYING: if ($filter['composite_status'] != -1) { $where .= " AND o.pay_status = '{$filter['composite_status']}' "; } break; case OS_SHIPPED_PART: if ($filter['composite_status'] != -1) { $where .= " AND o.shipping_status = '{$filter['composite_status']}'-2 "; } break; default: if ($filter['composite_status'] != -1) { $where .= " AND o.order_status = '{$filter['composite_status']}' "; } } /* 团购订单 */ if ($filter['group_buy_id']) { $where .= " AND o.extension_code = '" . GROUP_BUY_CODE . "' AND o.extension_id = '{$filter['group_buy_id']}' "; } /* 预售订单 */ if ($filter['pre_sale_id']) { $where .= " AND o.extension_code = '" . PRE_SALE_CODE . "' AND o.extension_id = '{$filter['pre_sale_id']}' "; } /* 如果管理员属于某个办事处,只列出这个办事处管辖的订单 */ $sql = "SELECT agency_id FROM " . $GLOBALS['ecs']->table('admin_user') . " WHERE user_id = '{$_SESSION['admin_id']}'"; $agency_id = $GLOBALS['db']->getOne($sql); if ($agency_id > 0) { $where .= " AND o.agency_id = '{$agency_id}' "; } /* 分页大小 */ $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']); if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) { $filter['page_size'] = intval($_REQUEST['page_size']); } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) { $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']); } else { $filter['page_size'] = 15; } /* 记录总数 */ if ($filter['user_name']) { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o ," . $GLOBALS['ecs']->table('users') . " AS u " . $where; } else { $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . $where; } $filter['record_count'] = $GLOBALS['db']->getOne($sql); $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1; /* 查询 */ if ($filter['supp']) { $sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer,supplier_name,o.froms,is_pickup " . ',o.mobile,o.inv_payee,o.inv_content,o.inv_type,o.vat_inv_company_name' . ',o.vat_inv_taxpayer_id,o.vat_inv_registration_address,o.vat_inv_registration_phone' . ',o.vat_inv_deposit_bank,o.vat_inv_bank_account' . ',o.inv_consignee_name,o.inv_consignee_phone,o.inv_consignee_country' . ',o.inv_consignee_province,o.inv_consignee_city,o.inv_consignee_district' . ',o.inv_consignee_address,o.inv_status,o.inv_payee_type,o.inv_money' . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('supplier') . " AS s ON s.supplier_id=o.supplier_id " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; } else { $sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," . "o.pay_status, o.consignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " . "(" . order_amount_field('o.') . ") AS total_fee, " . "IFNULL(u.user_name, '" . $GLOBALS['_LANG']['anonymous'] . "') AS buyer, o.froms , is_pickup " . ',o.mobile,o.inv_payee,o.inv_content,o.inv_type,o.vat_inv_company_name' . ',o.vat_inv_taxpayer_id,o.vat_inv_registration_address,o.vat_inv_registration_phone' . ',o.vat_inv_deposit_bank,o.vat_inv_bank_account' . ',o.inv_consignee_name,o.inv_consignee_phone,o.inv_consignee_country' . ',o.inv_consignee_province,o.inv_consignee_city,o.inv_consignee_district' . ',o.inv_consignee_address,o.inv_status,o.inv_payee_type,o.inv_money' . " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " . " LEFT JOIN " . $GLOBALS['ecs']->table('users') . " AS u ON u.user_id=o.user_id " . $where . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}"; } //echo $sql; foreach (array('order_sn', 'consignee', 'email', 'address', 'zipcode', 'tel', 'user_name') as $val) { $filter[$val] = stripslashes($filter[$val]); } set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $row = $GLOBALS['db']->getAll($sql); /* 格式话数据 */ foreach ($row as $key => $value) { $row[$key]['formated_order_amount'] = price_format($value['order_amount']); $row[$key]['formated_money_paid'] = price_format($value['money_paid']); $row[$key]['formated_total_fee'] = price_format($value['total_fee']); $row[$key]['short_order_time'] = local_date('m-d H:i', $value['add_time']); /*增值税发票_添加_START_www.68ecshop.com*/ $row[$key]['formatted_add_time'] = local_date('Y-m-d H:i', $value['add_time']); $row[$key]['formatted_inv_money'] = price_format($value['inv_money']); /*增值税发票_添加_END_www.68ecshop.com*/ if ($value['order_status'] == OS_INVALID || $value['order_status'] == OS_CANCELED) { /* 如果该订单为无效或取消则显示删除链接 */ $row[$key]['can_remove'] = 1; } else { $row[$key]['can_remove'] = 0; } $tuihuan_info = $GLOBALS['db']->getOne("select order_sn from " . $GLOBALS['ecs']->table('back_order') . " where order_sn = '" . $row[$key]['order_sn'] . "' AND status_back < 6"); if (!empty($tuihuan_info)) { $row[$key]['tuihuan'] = 1; } } $arr = array('orders' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); /*增值税发票_添加_START_www.68ecshop.com*/ if ($filter['inv_type']) { global $smarty; $smarty->assign('inv_type', $filter['inv_type']); } /*增值税发票_添加_END_www.68ecshop.com*/ return $arr; }