Beispiel #1
0
/**
 * 取得订单应该发放的红包
 * @param   int     $order_id   订单id
 * @return  array
 */
function order_bonus($order_id)
{
    /* 查询按商品发的红包 */
    $day = getdate();
    $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
    $sql = "SELECT b.type_id, b.type_money, SUM(o.goods_number) AS number " . "FROM " . $GLOBALS['ecs']->table('order_goods') . " AS o, " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('bonus_type') . " AS b " . " WHERE o.order_id = '{$order_id}' " . " AND o.is_gift = 0 " . " AND o.goods_id = g.goods_id " . " AND g.bonus_type_id = b.type_id " . " AND b.send_type = '" . SEND_BY_GOODS . "' " . " AND b.send_start_date <= '{$today}' " . " AND b.send_end_date >= '{$today}' " . " GROUP BY b.type_id ";
    $list = $GLOBALS['db']->getAll($sql);
    /* 查询定单中非赠品总金额 */
    $amount = order_amount($order_id, false);
    /* 查询订单日期 */
    $sql = "SELECT add_time " . " FROM " . $GLOBALS['ecs']->table('order_info') . " WHERE order_id = '{$order_id}' LIMIT 1";
    $order_time = $GLOBALS['db']->getOne($sql);
    /* 查询按订单发的红包 */
    $sql = "SELECT type_id, type_money, IFNULL(FLOOR('{$amount}' / min_amount), 1) AS number " . "FROM " . $GLOBALS['ecs']->table('bonus_type') . "WHERE send_type = '" . SEND_BY_ORDER . "' " . "AND send_start_date <= '{$order_time}' " . "AND send_end_date >= '{$order_time}' ";
    $list = array_merge($list, $GLOBALS['db']->getAll($sql));
    return $list;
}
/**
 *
 * @access  public
 * @param   int         $user_id         用户ID
 * @param   int         $num             列表显示条数
 * @param   int         $start           显示起始位置
 *
 * @return  array       $arr             红保列表
 */
function get_user_bouns_list($user_id, $num = 10, $start = 0)
{
    $sql = "SELECT u.bonus_sn, u.order_id, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date " . " FROM " . $GLOBALS['ecs']->table('user_bonus') . " AS u ," . $GLOBALS['ecs']->table('bonus_type') . " AS b" . " WHERE u.bonus_type_id = b.type_id AND u.user_id = '" . $user_id . "'";
    $res = $GLOBALS['db']->selectLimit($sql, $num, $start);
    $arr = array();
    $day = getdate();
    $cur_date = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        /* 先判断是否被使用,然后判断是否开始或过期 */
        if (empty($row['order_id'])) {
            /* 没有被使用 */
            if ($row['use_start_date'] > $cur_date) {
                $row['status'] = L('not_start');
            } else {
                if ($row['use_end_date'] < $cur_date) {
                    $row['status'] = L('overdue');
                } else {
                    $row['status'] = L('not_use');
                }
            }
        } else {
            $row['status'] = '<a href="user.php?act=order_detail&order_id=' . $row['order_id'] . '" >' . L('had_use') . '</a>';
        }
        $row['use_startdate'] = local_date(C('date_format'), $row['use_start_date']);
        $row['use_enddate'] = local_date(C('date_format'), $row['use_end_date']);
        $arr[] = $row;
    }
    return $arr;
}
Beispiel #3
0
 /**
  *
  * @access  public
  * @param   int         $user_id         用户ID
  * @param   int         $num             列表显示条数
  * @param   int         $start           显示起始位置
  *
  * @return  array       $arr             红保列表
  */
 function get_user_bouns_list($user_id, $num = 10, $start = 0)
 {
     $sql = "SELECT u.bonus_sn, u.order_id, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date " . " FROM " . $this->pre . "user_bonus AS u ," . $this->pre . "bonus_type AS b" . " WHERE u.bonus_type_id = b.type_id AND u.user_id = '" . $user_id . "' LIMIT {$start} , {$num}";
     $res = $this->query($sql);
     $arr = array();
     $day = getdate();
     $cur_date = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
     foreach ($res as $row) {
         /* 先判断是否被使用,然后判断是否开始或过期 */
         if (empty($row['order_id'])) {
             /* 没有被使用 */
             if ($row['use_start_date'] > $cur_date) {
                 $row['status'] = L('not_start');
             } else {
                 if ($row['use_end_date'] < $cur_date) {
                     $row['status'] = L('overdue');
                 } else {
                     $row['status'] = L('not_use');
                 }
             }
         } else {
             $url = url('user/order_detail', array('order_id' => $row['order_id']));
             $row['status'] = '<a href="' . $url . '" >' . L('had_use') . '</a>';
         }
         $row['use_startdate'] = local_date(C('date_format'), $row['use_start_date']);
         $row['use_enddate'] = local_date(C('date_format'), $row['use_end_date']);
         $arr[] = $row;
     }
     return $arr;
 }
Beispiel #4
0
 $order['total_weight'] = $weight_price['formated_weight'];
 /* 参数赋值:订单 */
 $smarty->assign('order', $order);
 /* 取得用户信息 */
 if ($order['user_id'] > 0) {
     /* 用户等级 */
     if ($user['user_rank'] > 0) {
         $where = " WHERE rank_id = '{$user['user_rank']}' ";
     } else {
         $where = " WHERE min_points <= " . intval($user['rank_points']) . " ORDER BY min_points DESC ";
     }
     $sql = "SELECT rank_name FROM " . $ecs->table('user_rank') . $where;
     $user['rank_name'] = $db->getOne($sql);
     // 用户红包数量
     $day = getdate();
     $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
     $sql = "SELECT COUNT(*) " . "FROM " . $ecs->table('bonus_type') . " AS bt, " . $ecs->table('user_bonus') . " AS ub " . "WHERE bt.type_id = ub.bonus_type_id " . "AND ub.user_id = '{$order['user_id']}' " . "AND ub.order_id = 0 " . "AND bt.use_start_date <= '{$today}' " . "AND bt.use_end_date >= '{$today}'";
     $user['bonus_count'] = $db->getOne($sql);
     $smarty->assign('user', $user);
     // 地址信息
     $sql = "SELECT * FROM " . $ecs->table('user_address') . " WHERE user_id = '{$order['user_id']}'";
     $smarty->assign('address_list', $db->getAll($sql));
 }
 /* 取得订单商品及货品 */
 $goods_list = array();
 $goods_attr = array();
 $sql = "SELECT o.*, IF(o.product_id > 0, p.product_number, g.goods_number) AS storage, o.goods_attr, g.suppliers_id, IFNULL(b.brand_name, '') AS brand_name, p.product_sn\n            FROM " . $ecs->table('order_goods') . " AS o\n                LEFT JOIN " . $ecs->table('products') . " AS p\n                    ON p.product_id = o.product_id\n                LEFT JOIN " . $ecs->table('goods') . " AS g\n                    ON o.goods_id = g.goods_id\n                LEFT JOIN " . $ecs->table('brand') . " AS b\n                    ON g.brand_id = b.brand_id\n            WHERE o.order_id = '{$order['order_id']}'";
 $res = $db->query($sql);
 while ($row = $db->fetchRow($res)) {
     /* 虚拟商品支持 */
     if ($row['is_real'] == 0) {
Beispiel #5
0
<?php

/**
 * ECSHOP 注册短信
 * ============================================================================
 * 版权所有 2005-2011 上海商派网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.ecshop.com;
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用;不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liuhui $
 * $Id: sms_url.php 16654 2009-09-09 10:29:24Z liuhui $
 */
$url = '';
if (isset($GLOBALS['_CFG']['certificate_id'])) {
    if ($GLOBALS['_CFG']['certificate_id'] == '') {
        $certi_id = 'error';
    } else {
        $certi_id = $GLOBALS['_CFG']['certificate_id'];
    }
    $sess_id = $GLOBALS['sess']->get_session_id();
    $auth = local_mktime();
    //代码修改  By www.68ecshop.com
    $ac = md5($certi_id . 'SHOPEX_SMS' . $auth);
    $url = 'http://service.shopex.cn/sms/index.php?certificate_id=' . $certi_id . '&sess_id=' . $sess_id . '&auth=' . $auth . '&ac=' . $ac;
}
Beispiel #6
0
/**
 * 获得商品的货品列表
 *
 * @access  public
 * @params  integer $goods_id
 * @params  string  $conditions
 * @return  array
 */
function product_list($goods_id, $conditions = '')
{
    /* 过滤条件 */
    $param_str = '-' . $goods_id;
    $result = get_filter($param_str);
    if ($result === false) {
        $day = getdate();
        $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
        $filter['goods_id'] = $goods_id;
        $filter['keyword'] = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']);
        $filter['stock_warning'] = empty($_REQUEST['stock_warning']) ? 0 : intval($_REQUEST['stock_warning']);
        if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1) {
            $filter['keyword'] = json_str_iconv($filter['keyword']);
        }
        $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'product_id' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
        $filter['extension_code'] = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);
        $filter['page_count'] = isset($filter['page_count']) ? $filter['page_count'] : 1;
        $where = '';
        /* 库存警告 */
        if ($filter['stock_warning']) {
            $where .= ' AND goods_number <= warn_number ';
        }
        /* 关键字 */
        if (!empty($filter['keyword'])) {
            $where .= " AND (product_sn LIKE '%" . $filter['keyword'] . "%')";
        }
        $where .= $conditions;
        /* 记录总数 */
        $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('products') . " AS p WHERE goods_id = {$goods_id} {$where}";
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);
        $sql = "SELECT product_id, goods_id, goods_attr, product_sn, product_number\n                FROM " . $GLOBALS['ecs']->table('products') . " AS g\n                WHERE goods_id = {$goods_id} {$where}\n                ORDER BY {$filter['sort_by']} {$filter['sort_order']}";
        $filter['keyword'] = stripslashes($filter['keyword']);
        //set_filter($filter, $sql, $param_str);
    } else {
        $sql = $result['sql'];
        $filter = $result['filter'];
    }
    $row = $GLOBALS['db']->getAll($sql);
    /* 处理规格属性 */
    $goods_attr = product_goods_attr_list($goods_id);
    foreach ($row as $key => $value) {
        $_goods_attr_array = explode('|', $value['goods_attr']);
        if (is_array($_goods_attr_array)) {
            $_temp = '';
            foreach ($_goods_attr_array as $_goods_attr_value) {
                $_temp[] = $goods_attr[$_goods_attr_value];
            }
            $row[$key]['goods_attr'] = $_temp;
        }
    }
    return array('product' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}
Beispiel #7
0
function insert_id_rebate($supplier_id)
{
    $sql = "select supplier_rebate_paytime from " . $GLOBALS['ecs']->table('supplier') . " where supplier_id='{$supplier_id}'";
    $supplier_rebate_paytime = $GLOBALS['db']->getOne($sql);
    $sql = "select rebate_paytime_start, rebate_paytime_end from " . $GLOBALS['ecs']->table('supplier_rebate') . " where supplier_id= '{$supplier_id}' and is_pay_ok=0 order by rebate_id DESC LIMIT 0,1";
    $row = $GLOBALS['db']->getRow($sql);
    if (!$row['rebate_paytime_start']) {
        $rebate_paytime_start = local_mktime(0, 0, 0, local_date('m'), local_date('d'), local_date('Y'));
    }
    if (!$row['rebate_paytime_end']) {
        switch ($supplier_rebate_paytime) {
            case '1':
                $rebate_paytime_end = local_strtotime("this Sunday") + 24 * 60 * 60 - 1;
                break;
            case '2':
                $rebate_paytime_end = local_mktime(23, 59, 59, local_date("m"), local_date("t"), local_date("Y"));
                break;
            case '3':
                if (local_date("m") == '1' || local_date("m") == '2' || local_date("m") == '3') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 3, 31, local_date("Y"));
                } elseif (local_date("m") == '4' || local_date("m") == '5' || local_date("m") == '6') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 6, 30, local_date("Y"));
                } elseif (local_date("m") == '7' || local_date("m") == '8' || local_date("m") == '9') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 9, 30, local_date("Y"));
                } elseif (local_date("m") == '10' || local_date("m") == '11' || local_date("m") == '12') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 12, 31, local_date("Y"));
                }
                break;
            case '4':
                $rebate_paytime_end = local_mktime(23, 59, 59, 12, 31, local_date("Y"));
                break;
        }
    }
    if ($row['rebate_paytime_start'] && $row['rebate_paytime_end']) {
        $rebate_paytime_start = $row['rebate_paytime_end'] + 1;
        switch ($supplier_rebate_paytime) {
            case '1':
                $rebate_paytime_end = $row['rebate_paytime_end'] + 24 * 60 * 60 * 7;
                break;
            case '2':
                $rebate_paytime_end = local_mktime(23, 59, 59, local_date("m", $rebate_paytime_start), local_date("t", $rebate_paytime_start), local_date("Y", $rebate_paytime_start));
                break;
            case '3':
                if (local_date("m", $rebate_paytime_start) == '1' || local_date("m") == '2' || local_date("m") == '3') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 3, 31, local_date("Y"));
                } elseif (local_date("m") == '4' || local_date("m") == '5' || local_date("m") == '6') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 6, 30, local_date("Y"));
                } elseif (local_date("m") == '7' || local_date("m") == '8' || local_date("m") == '9') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 9, 30, local_date("Y"));
                } elseif (local_date("m") == '10' || local_date("m") == '11' || local_date("m") == '12') {
                    $rebate_paytime_end = local_mktime(23, 59, 59, 12, 31, local_date("Y"));
                }
                break;
            case '4':
                $rebate_paytime_end = local_mktime(23, 59, 59, 12, 31, local_date("Y"));
                break;
        }
    }
    $sql = "insert into " . $GLOBALS['ecs']->table('supplier_rebate') . "(rebate_paytime_start, rebate_paytime_end, supplier_id) value('{$rebate_paytime_start}', '{$rebate_paytime_end}', '{$supplier_id}') ";
    $GLOBALS['db']->query($sql);
}
Beispiel #8
0
        $query_type = $_GET['query_type'];
        $start_time = $_GET['start_time'];
        $end_time = $_GET['end_time'];
    }
} else {
    if (isset($_POST['query_by_year'])) {
        /* 年走势 */
        $query_type = 'year';
        $start_time = local_mktime(0, 0, 0, 1, 1, intval($_POST['year_beginYear']));
        $end_time = local_mktime(23, 59, 59, 12, 31, intval($_POST['year_endYear']));
    } else {
        /* 月走势 */
        $query_type = 'month';
        $start_time = local_mktime(0, 0, 0, intval($_POST['month_beginMonth']), 1, intval($_POST['month_beginYear']));
        $end_time = local_mktime(23, 59, 59, intval($_POST['month_endMonth']), 1, intval($_POST['month_endYear']));
        $end_time = local_mktime(23, 59, 59, intval($_POST['month_endMonth']), date('t', $end_time), intval($_POST['month_endYear']));
    }
}
/* 分组统计订单数和销售额:已发货时间为准 */
$format = $query_type == 'year' ? '%Y' : '%Y-%m';
$sql = "SELECT DATE_FORMAT(FROM_UNIXTIME(shipping_time), '{$format}') AS period, COUNT(*) AS order_count, " . "SUM(goods_amount + shipping_fee + insure_fee + pay_fee + pack_fee + card_fee - discount) AS order_amount " . "FROM " . $ecs->table('order_info') . " WHERE (order_status = '" . OS_CONFIRMED . "' OR order_status >= '" . OS_SPLITED . "')" . " AND (pay_status = '" . PS_PAYED . "' OR pay_status = '" . PS_PAYING . "') " . " AND (shipping_status = '" . SS_SHIPPED . "' OR shipping_status = '" . SS_RECEIVED . "') " . " AND shipping_time >= '{$start_time}' AND shipping_time <= '{$end_time}'" . " GROUP BY period ";
$data_list = $db->getAll($sql);
/*------------------------------------------------------ */
//-- 显示统计信息
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list') {
    /* 赋值查询时间段 */
    $smarty->assign('start_time', local_date('Y-m-d', $start_time));
    $smarty->assign('end_time', local_date('Y-m-d', $end_time));
    /* 赋值统计数据 */
    $xml = "<chart caption='' xAxisName='%s' showValues='0' decimals='0' formatNumberScale='0'>%s</chart>";
Beispiel #9
0
function get_user_bouns_list2($user_id)
{
    $sql = "SELECT u.bonus_sn, u.order_id,u.used_time,b.is_share, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date " . " FROM " . $GLOBALS['hhs']->table('user_bonus') . " AS u ," . $GLOBALS['hhs']->table('bonus_type') . " AS b" . " WHERE u.bonus_type_id = b.type_id AND u.user_id = '" . $user_id . "'";
    $res = $GLOBALS['db']->getAll($sql);
    $arr = array();
    $day = getdate();
    $cur_date = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
    $cur_date_start = local_mktime(0, 0, 0, $day['mon'], $day['mday'], $day['year']);
    foreach ($res as $row) {
        /* 先判断是否被使用,然后判断是否开始或过期 */
        if (empty($row['order_id'])) {
            /* 没有被使用 */
            if ($row['use_start_date'] > $cur_date) {
                $row['status'] = $GLOBALS['_LANG']['not_start'];
            } else {
                if ($row['use_end_date'] < $cur_date) {
                    $row['status'] = $GLOBALS['_LANG']['overdue'];
                } else {
                    $row['status'] = $GLOBALS['_LANG']['not_use'];
                }
            }
        } else {
            $row['status'] = '<a href="user.php?act=order_detail&order_id=' . $row['order_id'] . '" >' . $GLOBALS['_LANG']['had_use'] . '</a>';
        }
        $row['use_startdate'] = local_date($GLOBALS['_CFG']['date_format'], $row['use_start_date']);
        $row['use_enddate'] = local_date($GLOBALS['_CFG']['date_format'], $row['use_end_date']);
        //归类存放 1 使用中 2 可使用 3已使用 4 未激活 5 已过期
        if (!empty($row['order_id'])) {
            //已使用分为 1 使用中 2 已使用
            $row['used_date'] = local_date($GLOBALS['_CFG']['date_format'], $row['used_time']);
            //使用中
            $sql = "select order_status,pay_status from " . $GLOBALS['hhs']->table('order_info') . " where order_id=" . $row['order_id'];
            $order = $GLOBALS['db']->getRow($sql);
            if ($order['pay_status'] == 2) {
                //已使用
                $arr['used'][] = $row;
            } else {
                $total_fee = " (o.goods_amount - o.discount + o.tax + o.shipping_fee + o.insure_fee + o.pay_fee + o.pack_fee + o.card_fee) AS total_fee ";
                $sql = "select g.goods_name,g.goods_thumb," . $total_fee . " from " . $GLOBALS['hhs']->table('order_info') . " as o left join " . $GLOBALS['hhs']->table('order_goods') . " as og on o.order_id=og.order_id left join " . $GLOBALS['hhs']->table('goods') . " as g on og.goods_id=g.goods_id where o.order_id=" . $row['order_id'];
                $goods = $GLOBALS['db']->getRow($sql);
                $row['goods'] = $goods;
                $arr['using'][] = $row;
                //使用中
            }
        } else {
            //未使用 ——> 1 可使用 2 未激活 3 已过期
            if ($row['use_start_date'] > $cur_date) {
                $arr['not_start'][] = $row;
                //未开始未激活
            } else {
                if ($row['use_end_date'] < $cur_date) {
                    $arr['overdue'][] = $row;
                    //已过期
                } else {
                    $arr['ok'][] = $row;
                }
            }
        }
    }
    return $arr;
}
Beispiel #10
0
/**
 *
 * @access  public
 * @param   int         $user_id         用户ID
 * @param   int         $num             列表显示条数
 * @param   int         $start           显示起始位置
 * @param   int         $suppid          店铺id
 * @return  array       $arr             红保列表
 */
function get_user_bouns_list($user_id, $num = 10, $start = 0, $suppid = -1)
{
    /* $sql = "SELECT u.bonus_sn,u.supplier_id, u.order_id, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date ".
       " FROM " .$GLOBALS['ecs']->table('user_bonus'). " AS u ,".
       $GLOBALS['ecs']->table('bonus_type'). " AS b".
       " WHERE u.bonus_type_id = b.type_id AND u.user_id = '" .$user_id. "'";*/
    $sql = "SELECT u.bonus_sn,u.supplier_id, u.order_id, b.type_name, b.type_money, b.min_goods_amount, b.use_start_date, b.use_end_date " . " FROM " . $GLOBALS['ecs']->table('user_bonus') . " AS u ," . $GLOBALS['ecs']->table('bonus_type') . " AS b" . " WHERE u.bonus_type_id = b.type_id AND u.user_id = '" . $user_id . "'";
    if ($suppid > -1) {
        $sql .= " AND u.supplier_id=" . intval($suppid);
    }
    $res = $GLOBALS['db']->selectLimit($sql, $num, $start);
    $arr = array();
    $day = getdate();
    $cur_date = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        /* 先判断是否被使用,然后判断是否开始或过期 */
        if (empty($row['order_id'])) {
            /* 没有被使用 */
            if ($row['use_start_date'] > $cur_date) {
                $row['status'] = $GLOBALS['_LANG']['not_start'];
            } else {
                if ($row['use_end_date'] < $cur_date) {
                    $row['status'] = $GLOBALS['_LANG']['overdue'];
                } else {
                    $row['status'] = $GLOBALS['_LANG']['not_use'];
                }
            }
        } else {
            $row['status'] = '<a href="user.php?act=order_detail&order_id=' . $row['order_id'] . '" >' . $GLOBALS['_LANG']['had_use'] . '</a>';
        }
        if ($row['supplier_id'] == '0') {
            $row['supplier_id'] = "自营商";
        } else {
            $supplierid = $row['supplier_id'];
            $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('supplier_shop_config') . "WHERE supplier_id = '{$supplierid}' AND code = 'shop_name'";
            $supp = $GLOBALS['db']->getRow($sql);
            $row['supplier_id'] = $supp['value'];
        }
        $row['use_startdate'] = local_date($GLOBALS['_CFG']['date_format'], $row['use_start_date']);
        $row['use_enddate'] = local_date($GLOBALS['_CFG']['date_format'], $row['use_end_date']);
        $arr[] = $row;
    }
    return $arr;
}
    /**
     * 取得当前用户应该得到的红包总额
     */
    function get_total_bonus() {
        $day = getdate();
        $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);

        /* 按商品发的红包 */
        $sql = "SELECT SUM(c.goods_number * t.type_money)" .
                " as count FROM " . $this->pre . "cart AS c, "
                . $this->pre . "bonus_type AS t, "
                . $this->pre . "goods AS g " .
                "WHERE c.session_id = '" . SESS_ID . "' " .
                "AND c.is_gift = 0 " .
                "AND c.goods_id = g.goods_id " .
                "AND g.bonus_type_id = t.type_id " .
                "AND t.send_type = '" . SEND_BY_GOODS . "' " .
                "AND t.send_start_date <= '$today' " .
                "AND t.send_end_date >= '$today' " .
                "AND c.rec_type = '" . CART_GENERAL_GOODS . "'";
        $res = $this->row($sql);
        $goods_total = floatval($res['count']);

        /* 取得购物车中非赠品总金额 */
        $sql = "SELECT SUM(goods_price * goods_number) " .
                " as count FROM " . $this->pre .
                "cart WHERE session_id = '" . SESS_ID . "' " .
                " AND is_gift = 0 " .
                " AND rec_type = '" . CART_GENERAL_GOODS . "'";
        $res = $this->row($sql);
        $amount = floatval($res['count']);

        /* 按订单发的红包 */
        $sql = "SELECT FLOOR('$amount' / min_amount) * type_money " .
                "as count FROM " . $this->pre .
                "bonus_type WHERE send_type = '" . SEND_BY_ORDER . "' " .
                " AND send_start_date <= '$today' " .
                "AND send_end_date >= '$today' " .
                "AND min_amount > 0 ";
        $res = $this->row($sql);
        $order_total = floatval($res['count']);

        return $goods_total + $order_total;
    }
Beispiel #12
0
/**
 * 取得用户当前可用红包
 * @param   int     $user_id        用户id
 * @param   float   $goods_amount   订单商品金额
 * @return  array   红包数组
 */
function zy_user_bonus($user_id, $goods_amount = 0)
{
    $day    = getdate();
    $today  = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);

    $sql = "SELECT t.type_id, t.type_name, t.type_money, b.bonus_id " .
            "FROM " . $GLOBALS['ecs']->table('bonus_type') . " AS t," .
                $GLOBALS['ecs']->table('user_bonus') . " AS b " .
            "WHERE t.type_id = b.bonus_type_id " .
            "AND t.use_start_date <= '$today' " .
            "AND t.use_end_date >= '$today' " .
            "AND t.min_goods_amount <= '$goods_amount' " .
            "AND b.user_id<>0 " .
            "AND b.user_id = '$user_id' " .
            "AND b.order_id = 0";
    return $GLOBALS['db']->getAll($sql);
}
/**
 * 获得商品列表
 *
 * @access  public
 * @params  integer $isdelete
 * @params  integer $real_goods
 * @return  array
 */
function goods_list($is_delete, $real_goods = 1)
{
    /* 过滤条件 */
    $param_str = '-' . $is_delete . '-' . $real_goods;
    $result = get_filter($param_str);
    if ($result === false) {
        $day = getdate();
        $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']);
        $filter['cat_id'] = empty($_REQUEST['cat_id']) ? 0 : intval($_REQUEST['cat_id']);
        $filter['intro_type'] = empty($_REQUEST['intro_type']) ? '' : trim($_REQUEST['intro_type']);
        $filter['is_promote'] = empty($_REQUEST['is_promote']) ? 0 : intval($_REQUEST['is_promote']);
        $filter['stock_warning'] = empty($_REQUEST['stock_warning']) ? 0 : intval($_REQUEST['stock_warning']);
        $filter['brand_id'] = empty($_REQUEST['brand_id']) ? 0 : intval($_REQUEST['brand_id']);
        $filter['keyword'] = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']);
        if ($_REQUEST['is_ajax'] == 1) {
            $filter['keyword'] = json_str_iconv($filter['keyword']);
        }
        $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'goods_id' : trim($_REQUEST['sort_by']);
        $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
        $filter['extension_code'] = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']);
        $filter['is_delete'] = $is_delete;
        $filter['real_goods'] = $real_goods;
        $where = $filter['cat_id'] > 0 ? " AND " . get_children($filter['cat_id']) : '';
        /* 推荐类型 */
        switch ($filter['intro_type']) {
            case 'is_best':
                $where .= " AND is_best=1";
                break;
            case 'is_hot':
                $where .= ' AND is_hot=1';
                break;
            case 'is_new':
                $where .= ' AND is_new=1';
                break;
            case 'is_promote':
                $where .= " AND is_promote = 1 AND promote_price > 0 AND promote_start_date <= '{$today}' AND promote_end_date >= '{$today}'";
                break;
            case 'all_type':
                $where .= " AND (is_best=1 OR is_hot=1 OR is_new=1 OR (is_promote = 1 AND promote_price > 0 AND promote_start_date <= '" . $today . "' AND promote_end_date >= '" . $today . "'))";
        }
        /* 库存警告 */
        if ($filter['stock_warning']) {
            $where .= ' AND goods_number <= warn_number ';
        }
        /* 品牌 */
        if ($filter['brand_id']) {
            $where .= " AND brand_id='{$filter['brand_id']}'";
        }
        /* 扩展 */
        if ($filter['extension_code']) {
            $where .= " AND extension_code='{$filter['extension_code']}'";
        }
        /* 关键字 */
        if (!empty($filter['keyword'])) {
            $where .= " AND (goods_sn LIKE '%" . mysql_like_quote($filter['keyword']) . "%' OR goods_name LIKE '%" . mysql_like_quote($filter['keyword']) . "%')";
        }
        if ($real_goods > -1) {
            $where .= " AND is_real='{$real_goods}'";
        }
        /* 记录总数 */
        $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods') . " AS g WHERE is_delete='{$is_delete}' {$where}";
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);
        /* 分页大小 */
        $filter = page_and_size($filter);
        $sql = "SELECT goods_id, goods_name, goods_sn, shop_price, is_on_sale, is_best, is_new, is_hot, sort_order, goods_number, integral, " . " (promote_price > 0 AND promote_start_date <= '{$today}' AND promote_end_date >= '{$today}') AS is_promote " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g WHERE is_delete='{$is_delete}' {$where}" . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . $filter['start'] . ",{$filter['page_size']}";
        $filter['keyword'] = stripslashes($filter['keyword']);
        set_filter($filter, $sql, $param_str);
    } else {
        $sql = $result['sql'];
        $filter = $result['filter'];
    }
    $row = $GLOBALS['db']->getAll($sql);
    return array('goods' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}