예제 #1
0
 /* 复制一份相册图片 */
 $img = $original_img;
 // 相册图片
 $pos = strpos(basename($img), '.');
 $newname = dirname($img) . '/' . $image->random_filename() . substr(basename($img), $pos);
 if (!copy('../' . $img, '../' . $newname)) {
     sys_msg('fail to copy file: ' . realpath('../' . $img), 1, array(), false);
 }
 $img = $newname;
 $gallery_img = $img;
 $gallery_thumb = $img;
 // 如果系统支持GD,缩放商品图片,且给商品图片和相册图片加水印
 if ($image->gd_version() > 0 && $image->check_img_function($_FILES['goods_img']['type'])) {
     // 如果设置大小不为0,缩放图片
     if ($_CFG['image_width'] != 0 || $_CFG['image_height'] != 0) {
         $goods_img = $image->make_thumb('../' . $goods_img, $GLOBALS['_CFG']['image_width'], $GLOBALS['_CFG']['image_height']);
         if ($goods_img === false) {
             sys_msg($image->error_msg(), 1, array(), false);
         }
     }
     $newname = dirname($img) . '/' . $image->random_filename() . substr(basename($img), $pos);
     if (!copy('../' . $img, '../' . $newname)) {
         sys_msg('fail to copy file: ' . realpath('../' . $img), 1, array(), false);
     }
     $gallery_img = $newname;
     // 加水印
     if (intval($_CFG['watermark_place']) > 0 && !empty($GLOBALS['_CFG']['watermark'])) {
         if ($image->add_watermark('../' . $goods_img, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']) === false) {
             sys_msg($image->error_msg(), 1, array(), false);
         }
         if ($image->add_watermark('../' . $gallery_img, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']) === false) {
예제 #2
0
파일: user.php 프로젝트: seanguo166/yinoos
function action_shaidan_save()
{
    $user = $GLOBALS['user'];
    $_CFG = $GLOBALS['_CFG'];
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    $user_id = $_SESSION['user_id'];
    include_once dirname(__FILE__) . '/includes/cls_image.php';
    $image = new cls_image($_CFG['bgcolor']);
    $rec_id = intval($_POST['rec_id']);
    $goods_id = intval($_POST['goods_id']);
    $title = trim($_POST['title']);
    $message = $_POST['message'];
    $add_time = gmtime();
    $status = $_CFG['shaidan_check'];
    $hide_username = intval($_POST['hide_username']);
    $sql = "INSERT INTO " . $ecs->table('shaidan') . "(rec_id, goods_id, user_id, title, message, add_time, status, hide_username)" . "VALUES ('{$rec_id}', '{$goods_id}', '{$user_id}', '{$title}', '{$message}', '{$add_time}', '{$status}', '{$hide_username}')";
    $db->query($sql);
    $shaidan_id = $db->insert_id();
    $db->query("UPDATE " . $ecs->table('order_goods') . " SET shaidan_state = 1 WHERE rec_id = '{$rec_id}'");
    // 处理图片
    $img_srcs = $_POST['img_srcs'];
    $img_names = $_POST['img_names'];
    if (is_array($img_srcs)) {
        foreach ($img_srcs as $i => $src) {
            $thumb = $image->make_thumb($src, 100, 100);
            $sql = "INSERT INTO " . $ecs->table('shaidan_img') . "(shaidan_id, `desc`, image, thumb)" . "VALUES ('{$shaidan_id}', '" . $img_names[$i] . "', '{$src}', '{$thumb}')";
            $db->query($sql);
        }
    }
    // 需要审核
    if ($status == 0) {
        $msg = '您的信息提交成功,需要管理员审核后才能显示!';
    } else {
        $info = $db->GetRow("SELECT * FROM " . $ecs->table('shaidan') . " WHERE shaidan_id='{$shaidan_id}'");
        // 该商品第几位晒单者
        $res = $db->getAll("SELECT shaidan_id FROM " . $ecs->table("shaidan") . " WHERE goods_id = '{$info['goods_id']}' ORDER BY add_time ASC");
        foreach ($res as $key => $value) {
            if ($shaidan_id == $value['shaidan_id']) {
                $weizhi = $key + 1;
            }
        }
        // 图片数量
        $imgnum = count($img_srcs);
        // 是否赠送积分
        if ($info['is_points'] == 0 && $weizhi <= $_CFG['shaidan_pre_num'] && $imgnum >= $_CFG['shaidan_img_num']) {
            $pay_points = $_CFG['shaidan_pay_points'];
            $db->query("UPDATE " . $ecs->table('shaidan') . " SET pay_points = '{$pay_points}', is_points = 1 WHERE shaidan_id = '{$shaidan_id}'");
            $db->query("INSERT INTO " . $ecs->table('account_log') . "(user_id, rank_points, pay_points, change_time, change_desc, change_type) " . "VALUES ('{$info['user_id']}', 0, '" . $pay_points . "', " . gmtime() . ", '晒单获得积分', '99')");
            $log = $db->getRow("SELECT SUM(rank_points) AS rank_points, SUM(pay_points) AS pay_points FROM " . $ecs->table("account_log") . " WHERE user_id = '{$info['user_id']}'");
            $db->query("UPDATE " . $ecs->table('users') . " SET rank_points = '" . $log['rank_points'] . "', pay_points = '" . $log['pay_points'] . "' WHERE user_id = '{$info['user_id']}'");
        }
        $msg = '您的信息提交成功!';
    }
    echo "<script>alert('{$msg}');self.location='user.php?act=my_comment';</script>";
    exit;
}
예제 #3
0
    $thumb_file_name = date("His") . rand(10000, 99999);
    $new_file_name = $thumb_file_name . '.' . $file_ext;
    //移动文件
    $file_path = $save_path . $new_file_name;
    if (move_uploaded_file($tmp_name, $file_path) === false) {
        alert("上传文件失败。");
    }
    @chmod($file_path, 0644);
    $file_url = $save_url . $new_file_name;
    $type = $_FILES['imgFile']['type'];
    $type1 = substr($type, 0, 5);
    //判断上传是否是图片
    if ($type1 == 'image') {
        require_once 'cls_image.php';
        $images = new cls_image();
        if ($filename = $images->make_thumb($file_path, 600, '', $save_path, $thumb_file_name)) {
            $file_url = $save_url . $filename;
        } else {
            alert($images->error_msg);
        }
    }
    header('Content-type: text/html; charset=UTF-8');
    $json = new Services_JSON();
    echo $json->encode(array('error' => 0, 'url' => $file_url));
    exit;
}
function alert($msg)
{
    header('Content-type: text/html; charset=UTF-8');
    $json = new Services_JSON();
    echo $json->encode(array('error' => 1, 'message' => $msg));
예제 #4
0
파일: lib_api.php 프로젝트: Ryan007/mybb
/**
 * 添加商品
 *
 * @param array $post
 */
function API_AddGoods($post)
{
    //debug_text();
    global $_CFG;
    /* 加载后台操作类与函数 */
    require_once ROOT_PATH . ADMIN_PATH . '/includes/lib_main.php';
    require_once ROOT_PATH . ADMIN_PATH . '/includes/lib_goods.php';
    require_once ROOT_PATH . 'includes/cls_image.php';
    /* 检查权限 */
    admin_privilege('goods_manage');
    $image = new cls_image($GLOBALS['_CFG']['bgcolor']);
    $code = empty($_POST['extension_code']) ? '' : trim($_POST['extension_code']);
    /* 插入还是更新的标识 */
    $is_insert = $_POST['act'] == 'insert';
    /* 如果是更新,先检查该商品是否存在,不存在,则退出。 */
    if (!$is_insert) {
        $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$_POST['goods_id']}' AND is_delete = 0";
        if ($GLOBALS['db']->getOne($sql) <= 0) {
            client_show_message(240);
            //货号重复
        }
    }
    /* 检查货号是否重复 */
    if ($_POST['goods_sn']) {
        $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_sn = '{$_POST['goods_sn']}' AND is_delete = 0 AND goods_id <> '{$_POST['goods_id']}'";
        if ($GLOBALS['db']->getOne($sql) > 0) {
            client_show_message(200);
            //货号重复
        }
    }
    /* 处理商品图片 */
    $goods_img = '';
    // 初始化商品图片
    $goods_thumb = '';
    // 初始化商品缩略图
    $original_img = '';
    // 初始化原始图片
    $old_original_img = '';
    // 初始化原始图片旧图
    $allow_file_type = array('jpg', 'jpeg', 'png', 'gif');
    if (!empty($_POST['goods_img']['Data'])) {
        if (!in_array($_POST['goods_img']['Type'], $allow_file_type)) {
            client_show_message(201);
        }
        if (client_check_image_size($_POST['goods_img']['Data']) === false) {
            client_show_message(202);
        }
        if ($_POST['goods_id'] > 0) {
            /* 删除原来的图片文件 */
            $sql = "SELECT goods_thumb, goods_img, original_img " . " FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$_POST['goods_id']}'";
            $row = $GLOBALS['db']->getRow($sql);
            if ($row['goods_thumb'] != '' && is_file(ROOT_PATH . '/' . $row['goods_thumb'])) {
                @unlink(ROOT_PATH . '/' . $row['goods_thumb']);
            }
            if ($row['goods_img'] != '' && is_file(ROOT_PATH . '/' . $row['goods_img'])) {
                @unlink(ROOT_PATH . '/' . $row['goods_img']);
            }
            if ($row['original_img'] != '' && is_file(ROOT_PATH . '/' . $row['original_img'])) {
                /* 先不处理,以防止程序中途出错停止 */
                //$old_original_img = $row['original_img']; //记录旧图路径
            }
        }
        $original_img = upload_image($_POST['goods_img']);
        // 原始图片
        if ($original_img === false) {
            client_show_message(210);
            // 写入商品图片出错
        }
        $goods_img = $original_img;
        // 商品图片
        /* 复制一份相册图片 */
        $img = $original_img;
        // 相册图片
        $pos = strpos(basename($img), '.');
        $newname = dirname($img) . '/' . random_filename() . substr(basename($img), $pos);
        if (!copy(ROOT_PATH . '/' . $img, ROOT_PATH . '/' . $newname)) {
            client_show_message(211);
            // 复制相册图片时出错
        }
        $img = $newname;
        $gallery_img = $img;
        $gallery_thumb = $img;
        /* 图片属性 */
        $img_property = $image->gd_version() > 0 ? getimagesize(ROOT_PATH . '/' . $goods_img) : array();
        // 如果系统支持GD,缩放商品图片,且给商品图片和相册图片加水印
        if ($image->gd_version() > 0 && $image->check_img_function($img_property[2])) {
            // 如果设置大小不为0,缩放图片
            if ($GLOBALS['_CFG']['image_width'] != 0 || $GLOBALS['_CFG']['image_height'] != 0) {
                $goods_img = $image->make_thumb(ROOT_PATH . '/' . $goods_img, $GLOBALS['_CFG']['image_width'], $GLOBALS['_CFG']['image_height']);
                if ($goods_img === false) {
                    client_show_message(212);
                }
            }
            // 加水印
            if (intval($GLOBALS['_CFG']['watermark_place']) > 0 && !empty($GLOBALS['_CFG']['watermark'])) {
                if ($image->add_watermark(ROOT_PATH . '/' . $goods_img, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']) === false) {
                    client_show_message(213);
                }
                $newname = dirname($img) . '/' . random_filename() . substr(basename($img), $pos);
                if (!copy(ROOT_PATH . '/' . $img, ROOT_PATH . '/' . $newname)) {
                    client_show_message(214);
                }
                $gallery_img = $newname;
                if ($image->add_watermark(ROOT_PATH . '/' . $gallery_img, '', $GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']) === false) {
                    client_show_message(213);
                }
            }
            // 相册缩略图
            if ($_CFG['thumb_width'] != 0 || $_CFG['thumb_height'] != 0) {
                $gallery_thumb = $image->make_thumb(ROOT_PATH . '/' . $img, $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']);
                if ($gallery_thumb === false) {
                    client_show_message(215);
                }
            }
        }
    }
    if (!empty($_POST['goods_thumb']['Data'])) {
        if (!in_array($_POST['goods_thumb']['Type'], $allow_file_type)) {
            client_show_message(203);
        }
        if (client_check_image_size($_POST['goods_thumb']['Data']) === false) {
            client_show_message(204);
        }
        $goods_thumb = upload_image($_POST['goods_thumb']);
        if ($goods_thumb === false) {
            client_show_message(217);
        }
    } else {
        // 未上传,如果自动选择生成,且上传了商品图片,生成所略图
        if (isset($_POST['auto_thumb']) && !empty($original_img)) {
            // 如果设置缩略图大小不为0,生成缩略图
            if ($_CFG['thumb_width'] != 0 || $_CFG['thumb_height'] != 0) {
                $goods_thumb = $image->make_thumb(ROOT_PATH . '/' . $original_img, $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']);
                if ($goods_thumb === false) {
                    client_show_message(218);
                }
            } else {
                $goods_thumb = $original_img;
            }
        }
    }
    /* 如果没有输入商品货号则自动生成一个商品货号 */
    if (empty($_POST['goods_sn'])) {
        $max_id = $is_insert ? $GLOBALS['db']->getOne("SELECT MAX(goods_id) + 1 FROM " . $GLOBALS['ecs']->table('goods')) : $_POST['goods_id'];
        $goods_sn = generate_goods_sn($max_id);
    } else {
        $goods_sn = $_POST['goods_sn'];
    }
    /* 处理商品数据 */
    $is_promote = isset($_POST['is_promote']) && $_POST['is_promote'] ? 1 : 0;
    $shop_price = !empty($_POST['shop_price']) ? $_POST['shop_price'] : 0;
    $market_price = !empty($_POST['market_price']) ? $_POST['market_price'] : $GLOBALS['_CFG']['market_price_rate'] * $shop_price;
    $promote_price = !empty($_POST['promote_price']) ? floatval($_POST['promote_price']) : 0;
    $promote_start_date = $is_promote && !empty($_POST['promote_start_date']) ? local_strtotime($_POST['promote_start_date']) : 0;
    $promote_end_date = $is_promote && !empty($_POST['promote_end_date']) ? local_strtotime($_POST['promote_end_date']) : 0;
    $goods_weight = !empty($_POST['goods_weight']) ? $_POST['goods_weight'] * $_POST['weight_unit'] : 0;
    $is_best = isset($_POST['is_best']) && $_POST['is_best'] ? 1 : 0;
    $is_new = isset($_POST['is_new']) && $_POST['is_new'] ? 1 : 0;
    $is_hot = isset($_POST['is_hot']) && $_POST['is_hot'] ? 1 : 0;
    $is_on_sale = isset($_POST['is_on_sale']) && $_POST['is_on_sale'] ? 1 : 0;
    $is_alone_sale = isset($_POST['is_alone_sale']) && $_POST['is_alone_sale'] ? 1 : 0;
    $goods_number = isset($_POST['goods_number']) ? $_POST['goods_number'] : 0;
    $warn_number = isset($_POST['warn_number']) ? $_POST['warn_number'] : 0;
    $goods_type = isset($_POST['goods_type']) ? $_POST['goods_type'] : 0;
    $goods_name_style = $_POST['goods_name_color'] . '+' . $_POST['goods_name_style'];
    $catgory_id = empty($_POST['cat_id']) ? '' : intval($_POST['cat_id']);
    $brand_id = empty($_POST['brand_id']) ? '' : intval($_POST['brand_id']);
    $new_brand_name = empty($_POST['new_brand_name']) ? '' : trim($_POST['new_brand_name']);
    $new_cat_name = empty($_POST['new_cat_name']) ? '' : trim($_POST['new_cat_name']);
    if ($catgory_id == '' && $new_cat_name != '') {
        if (cat_exists($new_cat_name, $_POST['parent_cat'])) {
            /* 同级别下不能有重复的分类名称 */
            client_show_message(219);
        }
    }
    if ($brand_id == '' && $new_brand_name != '') {
        if (brand_exists($new_brand_name)) {
            /* 同级别下不能有重复的品牌名称 */
            client_show_message(220);
        }
    }
    //处理快速添加分类
    if ($catgory_id == '' && $new_cat_name != '') {
        $sql = "INSERT INTO " . $GLOBALS['ecs']->table('category') . "(cat_name, parent_id, is_show)" . "VALUES ( '{$new_cat_name}', '{$_POST['parent_cat']}', 1)";
        $GLOBALS['db']->query($sql);
        $catgory_id = $GLOBALS['db']->insert_id();
    }
    //处理快速添加品牌
    if ($brand_id == '' && $new_brand_name != '') {
        $sql = "INSERT INTO " . $GLOBALS['ecs']->table('brand') . "(brand_name) " . "VALUES ('{$new_brand_name}')";
        $GLOBALS['db']->query($sql);
        $brand_id = $GLOBALS['db']->insert_id();
    }
    /* 处理商品详细描述 */
    $_POST['goods_desc'] = htmlspecialchars_decode($_POST['goods_desc']);
    /* 入库 */
    if ($is_insert) {
        if ($code == '') {
            $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods') . " (goods_name, goods_name_style, goods_sn, " . "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " . "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " . "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, " . "is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type)" . "VALUES ('{$_POST['goods_name']}', '{$goods_name_style}', '{$goods_sn}', '{$catgory_id}', " . "'{$brand_id}', '{$shop_price}', '{$market_price}', '{$is_promote}','{$promote_price}', " . "'{$promote_start_date}', '{$promote_end_date}', '{$goods_img}', '{$goods_thumb}', '{$original_img}', " . "'{$_POST['keywords']}', '{$_POST['goods_brief']}', '{$_POST['seller_note']}', '{$goods_weight}', '{$goods_number}'," . " '{$warn_number}', '{$_POST['integral']}', '" . intval($_POST['give_integral']) . "', '{$is_best}', '{$is_new}', '{$is_hot}', '{$is_on_sale}', '{$is_alone_sale}', " . " '{$_POST['goods_desc']}', '" . gmtime() . "', '" . gmtime() . "', '{$goods_type}')";
        } else {
            $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods') . " (goods_name, goods_name_style, goods_sn, " . "cat_id, brand_id, shop_price, market_price, is_promote, promote_price, " . "promote_start_date, promote_end_date, goods_img, goods_thumb, original_img, keywords, goods_brief, " . "seller_note, goods_weight, goods_number, warn_number, integral, give_integral, is_best, is_new, is_hot, is_real, " . "is_on_sale, is_alone_sale, goods_desc, add_time, last_update, goods_type, extension_code)" . "VALUES ('{$_POST['goods_name']}', '{$goods_name_style}', '{$goods_sn}', '{$catgory_id}', " . "'{$brand_id}', '{$shop_price}', '{$market_price}', '{$is_promote}', '{$promote_price}', " . "'{$promote_start_date}', '{$promote_end_date}', '{$goods_img}', '{$goods_thumb}', '{$original_img}', " . "'{$_POST['keywords']}', '{$_POST['goods_brief']}', '{$_POST['seller_note']}', '{$goods_weight}', '{$goods_number}'," . " '{$warn_number}', '{$_POST['integral']}', '" . intval($_POST['give_integral']) . "', '{$is_best}', '{$is_new}', '{$is_hot}', 0, '{$is_on_sale}', '{$is_alone_sale}', " . " '{$_POST['goods_desc']}', '" . gmtime() . "', '" . gmtime() . "', '{$goods_type}', '{$code}')";
        }
    } else {
        /* 将上传的新图片图片名改为原图片 */
        if ($goods_img && $row['goods_img']) {
            if (is_file(ROOT_PATH . $row['goods_img'])) {
                @unlink(ROOT_PATH . $row['goods_img']);
            }
            @rename(ROOT_PATH . $goods_img, ROOT_PATH . $row['goods_img']);
            if (is_file(ROOT_PATH . $row['original_img'])) {
                @unlink(ROOT_PATH . $row['original_img']);
            }
            @rename(ROOT_PATH . $original_img, ROOT_PATH . $row['original_img']);
        }
        if ($goods_thumb && $row['goods_thumb']) {
            if (is_file(ROOT_PATH . $row['goods_thumb'])) {
                @unlink(ROOT_PATH . $row['goods_thumb']);
            }
            @rename(ROOT_PATH . $goods_thumb, ROOT_PATH . $row['goods_thumb']);
        }
        $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET " . "goods_name = '{$_POST['goods_name']}', " . "goods_name_style = '{$goods_name_style}', " . "goods_sn = '{$goods_sn}', " . "cat_id = '{$catgory_id}', " . "brand_id = '{$brand_id}', " . "shop_price = '{$shop_price}', " . "market_price = '{$market_price}', " . "is_promote = '{$is_promote}', " . "promote_price = '{$promote_price}', " . "promote_start_date = '{$promote_start_date}', " . "promote_end_date = '{$promote_end_date}', ";
        /* 如果以前没上传过图片,需要更新数据库 */
        if ($goods_img && empty($row['goods_img'])) {
            $sql .= "goods_img = '{$goods_img}', original_img = '{$original_img}', ";
        }
        if (!empty($goods_thumb)) {
            $sql .= "goods_thumb = '{$goods_thumb}', ";
        }
        if ($code != '') {
            $sql .= "is_real=0, extension_code='{$code}', ";
        }
        $sql .= "keywords = '{$_POST['keywords']}', " . "goods_brief = '{$_POST['goods_brief']}', " . "seller_note = '{$_POST['seller_note']}', " . "goods_weight = '{$goods_weight}'," . "goods_number = '{$goods_number}', " . "warn_number = '{$warn_number}', " . "integral = '{$_POST['integral']}', " . "give_integral = '" . $_POST['give_integral'] . "', " . "is_best = '{$is_best}', " . "is_new = '{$is_new}', " . "is_hot = '{$is_hot}', " . "is_on_sale = '{$is_on_sale}', " . "is_alone_sale = '{$is_alone_sale}', " . "goods_desc = '{$_POST['goods_desc']}', " . "last_update = '" . gmtime() . "', " . "goods_type = '{$goods_type}' " . "WHERE goods_id = '{$_POST['goods_id']}' LIMIT 1";
    }
    $GLOBALS['db']->query($sql);
    /* 商品编号 */
    $goods_id = $is_insert ? $GLOBALS['db']->insert_id() : $_POST['goods_id'];
    /* 记录日志 */
    if ($is_insert) {
        admin_log($_POST['goods_name'], 'add', 'goods');
    } else {
        admin_log($_POST['goods_name'], 'edit', 'goods');
    }
    /* 处理属性 */
    if (isset($_POST['attr_id_list']) && isset($_POST['attr_value_list'])) {
        // 取得原有的属性值
        $goods_attr_list = array();
        $keywords_arr = explode(" ", $_POST['keywords']);
        $keywords_arr = array_flip($keywords_arr);
        if (isset($keywords_arr[''])) {
            unset($keywords_arr['']);
        }
        $sql = "SELECT attr_id, attr_index FROM " . $GLOBALS['ecs']->table('attribute') . " WHERE cat_id = '{$goods_type}' ";
        $attr_res = $GLOBALS['db']->query($sql);
        $attr_list = array();
        while ($row = $GLOBALS['db']->fetchRow($attr_res)) {
            $attr_list[$row['attr_id']] = $row['attr_index'];
        }
        $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id = '{$goods_id}' ";
        $res = $GLOBALS['db']->query($sql);
        while ($row = $GLOBALS['db']->fetchRow($res)) {
            $goods_attr_list[$row['attr_id']][$row['attr_value']] = array('sign' => 'delete', 'goods_attr_id' => $row['goods_attr_id']);
        }
        // 循环现有的,根据原有的做相应处理
        foreach ($_POST['attr_id_list'] as $key => $attr_id) {
            $attr_value = $_POST['attr_value_list'][$key];
            $attr_price = $_POST['attr_price_list'][$key];
            if (!empty($attr_value)) {
                if (isset($goods_attr_list[$attr_id][$attr_value])) {
                    // 如果原来有,标记为更新
                    $goods_attr_list[$attr_id][$attr_value]['sign'] = 'update';
                    $goods_attr_list[$attr_id][$attr_value]['attr_price'] = $attr_price;
                } else {
                    // 如果原来没有,标记为新增
                    $goods_attr_list[$attr_id][$attr_value]['sign'] = 'insert';
                    $goods_attr_list[$attr_id][$attr_value]['attr_price'] = $attr_price;
                }
                $val_arr = explode(' ', $attr_value);
                foreach ($val_arr as $k => $v) {
                    if (!isset($keywords_arr[$v]) && $attr_list[$attr_id] == "1") {
                        $keywords_arr[$v] = $v;
                    }
                }
            }
        }
        $keywords = join(' ', array_flip($keywords_arr));
        $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET keywords = '{$keywords}' WHERE goods_id = '{$goods_id}' LIMIT 1";
        $GLOBALS['db']->query($sql);
        /* 插入、更新、删除数据 */
        foreach ($goods_attr_list as $attr_id => $attr_value_list) {
            foreach ($attr_value_list as $attr_value => $info) {
                if ($info['sign'] == 'insert') {
                    $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_attr') . " (attr_id, goods_id, attr_value, attr_price)" . "VALUES ('{$attr_id}', '{$goods_id}', '{$attr_value}', '{$info['attr_price']}')";
                } elseif ($info['sign'] == 'update') {
                    $sql = "UPDATE " . $GLOBALS['ecs']->table('goods_attr') . " SET attr_price = '{$info['attr_price']}' WHERE goods_attr_id = '{$info['goods_attr_id']}' LIMIT 1";
                } else {
                    $sql = "DELETE FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_attr_id = '{$info['goods_attr_id']}' LIMIT 1";
                }
                $GLOBALS['db']->query($sql);
            }
        }
    }
    /* 处理会员价格 */
    if (isset($_POST['user_rank']) && isset($_POST['user_price'])) {
        handle_member_price($goods_id, $_POST['user_rank'], $_POST['user_price']);
    }
    /* 处理扩展分类 */
    if (isset($_POST['other_cat'])) {
        handle_other_cat($goods_id, array_unique($_POST['other_cat']));
    }
    if ($is_insert) {
        /* 处理关联商品 */
        handle_link_goods($goods_id);
        /* 处理组合商品 */
        handle_group_goods($goods_id);
        /* 处理关联文章 */
        handle_goods_article($goods_id);
    }
    /* 如果有图片,把商品图片加入图片相册 */
    if (isset($img)) {
        $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$gallery_img}', '', '{$gallery_thumb}', '{$img}')";
        $GLOBALS['db']->query($sql);
    }
    /* 处理相册图片
       handle_gallery_image($goods_id, $_FILES['img_url'], $_POST['img_desc']);
       */
    if (!empty($_POST['img_url'])) {
        foreach ($_POST['img_url'] as $key => $img_url) {
            if (!in_array($img_url['Type'], $allow_file_type)) {
                client_show_message(205);
            }
            if (client_check_image_size($img_url['Data']) === false) {
                client_show_message(206);
            }
            $img_original = upload_image($img_url);
            if ($img_original === false) {
                continue;
            }
            // 暂停生成缩略图
            /*
            $thumb_url = $image->make_thumb(ROOT_PATH . $img_original, $GLOBALS['_CFG']['thumb_width'],  $GLOBALS['_CFG']['thumb_height']);
            $thumb_url = is_string($thumb_url) ? $thumb_url : '';
            
            $img_url = $img_original;
            
            // 如果服务器支持GD 则添加水印
            if (gd_version() > 0)
            {
                $pos        = strpos(basename($img_original), '.');
                $newname    = dirname($img_original) . '/' . random_filename() . substr(basename($img_original), $pos);
                copy(ROOT_PATH . '/' . $img_original, ROOT_PATH . '/' . $newname);
                $img_url    = $newname;
            
                $image->add_watermark(ROOT_PATH . $img_url,'',$GLOBALS['_CFG']['watermark'], $GLOBALS['_CFG']['watermark_place'], $GLOBALS['_CFG']['watermark_alpha']);
            }
            */
            $img_url = $thumb_url = $img_original;
            $img_desc = $_POST['img_desc'][$key];
            $sql = "INSERT INTO " . $GLOBALS['ecs']->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original) " . "VALUES ('{$goods_id}', '{$img_url}', '{$img_desc}', '{$thumb_url}', '{$img_original}')";
            $GLOBALS['db']->query($sql);
        }
    }
    /* 编辑时处理相册图片描述 */
    if (!$is_insert && isset($_POST['old_img_desc'])) {
        foreach ($_POST['old_img_desc'] as $img_id => $img_desc) {
            $sql = "UPDATE " . $GLOBALS['ecs']->table('goods_gallery') . " SET img_desc = '{$img_desc}' WHERE img_id = '{$img_id}' LIMIT 1";
            $GLOBALS['db']->query($sql);
        }
    }
    /* 清空缓存 */
    clear_cache_files();
    /* 提示页面 */
    client_show_message(0, true, '', $goods_id);
}
예제 #5
0
$picSize = $_FILES['imgFile']['size'];
//图片尺寸
list($picWidth, $picHeight) = getimagesize($_FILES['imgFile']['tmp_name']);
//图片高宽
/* 通知详情的图片 */
if ($act == 'notice' || $act == 'intro' || $act == 'info' || $act == 'lifenav' || $act == 'redpacket') {
    $maxSize = 1 * 1024 * 1024;
    $dir_name .= $act;
    if ($picSize > $maxSize) {
        $msg['error'] = 1;
        $msg['message'] = '上传图片不能大于1M';
    } else {
        $cls_image = new cls_image('#ffffff', $dir_name);
        $upload = isset($_FILES['imgFile']) ? $_FILES['imgFile'] : '';
        $msg = $cls_image->upload_image($upload, $dir = '', $img_name = '');
        if ($msg['error'] == 0) {
            $msg['url'] = $msg['msg'];
            if ($picWidth > 640) {
                $msg['msg'] = substr($msg['msg'], 1);
                $msg['url'] = $cls_image->make_thumb($msg['msg'], $width = 640, $height = 0, $path = '', $pic = '');
                @unlink($msg['msg']);
                // 删除原图,只保留缩略图
            }
        } else {
            $msg['message'] = $msg['msg'];
        }
    }
}
$msg = $Json->encode($msg);
echo $msg;
exit;
예제 #6
0
 //代表图片上传
 if ($_FILES['logo']['size']) {
     $save['supplier_id'] = 0;
     //自营运营商
     include_once ROOT_PATH . 'includes/cls_image.php';
     $image = new cls_image($_CFG['bgcolor']);
     $logo_path .= $save['supplier_id'];
     $logo_name = "original" . $save['supplier_id'] . '_' . $favourable['act_id'] . substr($_FILES['logo']['name'], -4);
     $picinfo = $image->upload_image($_FILES['logo'], $logo_path, $logo_name);
     $parray = pathinfo($picinfo);
     if ($picinfo) {
         $create_pic_info = array('580x260' => array('width' => 580, 'height' => 260));
         foreach ($create_pic_info as $key => $val) {
             $path = ROOT_PATH . $parray['dirname'] . '/';
             $image->create_pic_name = "original" . $save['supplier_id'] . '_' . $favourable['act_id'] . "_" . $key;
             $pinfo = $image->make_thumb(ROOT_PATH . $picinfo, $val['width'], $val['height'], $path);
         }
         $save['logo'] = '/' . $pinfo;
     }
     $pic_sql = "update " . $ecs->table('favourable_activity') . " set logo='" . $save['logo'] . "' where act_id=" . $favourable['act_id'];
     $db->query($pic_sql);
 }
 /* 记日志 */
 if ($is_add) {
     admin_log($favourable['act_name'], 'add', 'favourable');
 } else {
     admin_log($favourable['act_name'], 'edit', 'favourable');
 }
 /* 清除缓存 */
 clear_cache_files();
 /* 提示信息 */
예제 #7
0
파일: user.php 프로젝트: naliduo/ecshop
         }
     }
 }
 //会员头像 by neo
 if (!empty($_FILES['avatar']['name'])) {
     /* 更新会员头像之前先删除旧的头像 */
     $sql = "SELECT avatar " . " FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '{$user_id}'";
     $row = $GLOBALS['db']->getRow($sql);
     if ($row['avatar'] != '') {
         @unlink($row['avatar']);
     }
     $img_name = $user_id . '.' . end(explode('.', $_FILES['avatar']['name']));
     $target = ROOT_PATH . DATA_DIR . '/avatar/';
     $original_img = $image->upload_image($_FILES['avatar'], 'avatar', $img_name);
     // 原始图片
     $avatar = $image->make_thumb($original_img, 55, 55, $target);
     if ($avatar === false) {
         show_message("图片保存出错!");
     }
 }
 $profile = array('user_id' => $user_id, 'email' => isset($_POST['email']) ? trim($_POST['email']) : '', 'sex' => isset($_POST['sex']) ? intval($_POST['sex']) : 0, 'birthday' => $birthday, 'avatar' => $avatar, 'other' => isset($other) ? $other : array());
 if (edit_profile($profile)) {
     show_message($_LANG['edit_profile_success'], $_LANG['profile_lnk'], 'user.php?act=profile', 'info');
 } else {
     if ($user->error == ERR_EMAIL_EXISTS) {
         $msg = sprintf($_LANG['email_exist'], $profile['email']);
     } else {
         $msg = $_LANG['edit_profile_failed'];
     }
     show_message($msg, '', '', 'info');
 }
예제 #8
0
function action_shaidan_save()
{
    $user = $GLOBALS['user'];
    $_CFG = $GLOBALS['_CFG'];
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    $user_id = $_SESSION['user_id'];
    include_once dirname(__FILE__) . '/includes/cls_image.php';
    $image = new cls_image($_CFG['bgcolor']);
    $rec_id = intval($_POST['rec_id']);
    $goods_id = intval($_POST['goods_id']);
    $title = trim($_POST['title']);
    $message = $_POST['message'];
    $add_time = gmtime();
    $status = $_CFG['shaidan_check'];
    $hide_username = intval($_POST['hide_username']);
    $sql = "INSERT INTO " . $ecs->table('shaidan') . "(rec_id, goods_id, user_id, title, message, add_time, status, hide_username)" . "VALUES ('{$rec_id}', '{$goods_id}', '{$user_id}', '{$title}', '{$message}', '{$add_time}', '{$status}', '{$hide_username}')";
    $db->query($sql);
    $shaidan_id = $db->insert_id();
    $db->query("UPDATE " . $ecs->table('order_goods') . " SET shaidan_state = 1 WHERE rec_id = '{$rec_id}'");
    // 处理图片
    $img_srcs[0] = $_FILES['img_srcs0'];
    $img_srcs[1] = $_FILES['img_srcs1'];
    $img_srcs[2] = $_FILES['img_srcs2'];
    $img_srcs[3] = $_FILES['img_srcs3'];
    include_once ROOT_PATH . 'includes/cls_image.php';
    $path_a = "images/image/" . date('Ym') . "/";
    $path = "./../" . $path_a;
    if (!file_exists($path)) {
        mkdir($path);
    }
    foreach ($img_srcs as $k => $v) {
        if (!empty($v["name"])) {
            $arr = explode(".", $v["name"]);
            $hz = $arr[count($arr) - 1];
            $v["name"] = time() . '_' . $k . '.' . $hz;
            if (file_exists($path . $v["name"])) {
                $msg = '该文件已经存在!';
            } else {
                if (move_uploaded_file($v["tmp_name"], $path . $v["name"])) {
                    ini_set("memory_limit", -1);
                    $thumb = $image->make_thumb($path . $v["name"], 100, 100);
                    $path_img = $path_a . $v["name"];
                    $sql = "INSERT INTO " . $ecs->table('shaidan_img') . "(shaidan_id, `desc`, image, thumb)" . "VALUES ('{$shaidan_id}', '" . $v["name"] . "', '{$path_img}', '{$thumb}')";
                    $db->query($sql);
                }
                //echo "存储路径: " . $path . $v["name"];
            }
        }
    }
    // 需要审核
    if ($status == 0) {
        $msg = '您的信息提交成功,需要管理员审核后才能显示!';
    } else {
        $info = $db->GetRow("SELECT * FROM " . $ecs->table('shaidan') . " WHERE shaidan_id='{$shaidan_id}'");
        // 该商品第几位晒单者
        $res = $db->getAll("SELECT shaidan_id FROM " . $ecs->table("shaidan") . " WHERE goods_id = '{$info['goods_id']}' ORDER BY add_time ASC");
        foreach ($res as $key => $value) {
            if ($shaidan_id == $value['shaidan_id']) {
                $weizhi = $key + 1;
            }
        }
        // 图片数量
        $imgnum = count($img_srcs);
        // 是否赠送积分
        if ($info['is_points'] == 0 && $weizhi <= $_CFG['shaidan_pre_num'] && $imgnum >= $_CFG['shaidan_img_num']) {
            $pay_points = $_CFG['shaidan_pay_points'];
            $db->query("UPDATE " . $ecs->table('shaidan') . " SET pay_points = '{$pay_points}', is_points = 1 WHERE shaidan_id = '{$shaidan_id}'");
            $db->query("INSERT INTO " . $ecs->table('account_log') . "(user_id, rank_points, pay_points, change_time, change_desc, change_type) " . "VALUES ('{$info['user_id']}', 0, '" . $pay_points . "', " . gmtime() . ", '晒单获得积分', '99')");
            $log = $db->getRow("SELECT SUM(rank_points) AS rank_points, SUM(pay_points) AS pay_points FROM " . $ecs->table("account_log") . " WHERE user_id = '{$info['user_id']}'");
            $db->query("UPDATE " . $ecs->table('users') . " SET rank_points = '" . $log['rank_points'] . "', pay_points = '" . $log['pay_points'] . "' WHERE user_id = '{$info['user_id']}'");
        }
        $msg = '您的信息提交成功!';
    }
    echo "<script>alert('{$msg}');self.location='user.php?act=my_comment';</script>";
    exit;
}
예제 #9
0
파일: user.php 프로젝트: tang7h/jzmall
 $i = 0;
 foreach ($single_img_url as $k => $v) {
     $front_cover = 0;
     if ($k == $cover) {
         $front_cover = 1;
     }
     $rand_name = gmtime() . sprintf("%03d", mt_rand(1, 999));
     $img_ext = substr($v, strrpos($v, '.'));
     $img_name = $goods_id . '_S_' . $rand_name;
     $img_path = $dir . '/' . $sub_dir . '/single_img/' . $img_name . $img_ext;
     if (!file_exists(ROOT_PATH . $dir . '/' . $sub_dir . '/single_img/')) {
         createFolder(ROOT_PATH . $dir . '/' . $sub_dir . '/single_img/');
         mkdir($path, 0777);
     }
     if (move_image_file_single(ROOT_PATH . $v, ROOT_PATH . $dir . '/' . $sub_dir . '/single_img/' . $img_name . $img_ext)) {
         $thumb_url = $image->make_thumb($img_path, $GLOBALS['_CFG']['thumb_width'], $GLOBALS['_CFG']['thumb_height']);
         $thumb_url = is_string($thumb_url) ? $thumb_url : '';
         $sql = "INSERT INTO " . $ecs->table('goods_gallery') . " (goods_id, img_url, img_desc, thumb_url, img_original, single_id, dis_id, front_cover) " . "VALUES ('0', '{$img_path}', '{$cont_desc[$i]}', '{$thumb_url}', '', '{$single_id}','0', '{$front_cover}')";
         $db->query($sql);
         $i++;
         // 				unlink(ROOT_PATH.$v);
     } else {
         show_message('-_-提交失败,请检查网络', $_LANG['back_page_up'], "user.php?act=single_sun&order_id={$order_id}&goods_id={$goods_id}", 'error');
     }
 }
 $sql = "UPDATE " . $ecs->table('order_goods') . " SET is_single = '1' WHERE order_id='{$order_id}' AND goods_id='{$goods_id}'";
 if ($db->query($sql)) {
     show_message($_LANG['single_success'], $_LANG['back_page_list'], 'user.php?act=single_list');
 } else {
     show_message($_LANG['single_error'], $_LANG['back_page_up'], "user.php?act=single_sun&order_id={$order_id}&goods_id={$goods_id}", 'error');
 }
예제 #10
0
             } elseif ($code == 'wap_logo') {
                 $ext = array_pop(explode('.', $file['name']));
                 $file_name = $file_var_list[$code]['store_dir'] . 'wap_logo.' . $ext;
                 if (file_exists($file_var_list[$code]['value'])) {
                     @unlink($file_var_list[$code]['value']);
                 }
             } else {
                 $file_name = $file_var_list[$code]['store_dir'] . $file['name'];
             }
             /* 判断是否上传成功 */
             if (move_upload_file($file['tmp_name'], $file_name)) {
                 if ($code == 'shop_logo') {
                     include_once ROOT_PATH . 'includes/cls_image.php';
                     $image = new cls_image($_CFG['bgcolor']);
                     $image->create_pic_name = 'logo_supplier' . $_SESSION['supplier_id'];
                     $file_name = '/' . $image->make_thumb($file_name, 360, 180, $to_path);
                 }
                 $sql = "UPDATE " . $ecs->table('supplier_shop_config') . " SET value = '{$file_name}' WHERE code = '{$code}' AND supplier_id=" . $_SESSION['supplier_id'];
                 $db->query($sql);
             } else {
                 sys_msg(sprintf($_LANG['msg_upload_failed'], $file['name'], $file_var_list[$code]['store_dir']));
             }
         }
     }
 }
 /* 处理发票类型及税率 */
 /*
 if (!empty($_POST['invoice_rate']))
 {
     foreach ($_POST['invoice_rate'] as $key => $rate)
     {
예제 #11
0
파일: souwu.php 프로젝트: dlpc/ecshop
/**
* 处理url图片
* @$img_url 图片地址
* @$mark  	是否处理缩略图 1不处理
**/
function get_img($img_url = '', $mark = '0')
{
    $cls_imageobj = new cls_image();
    if (strstr($img_url, 'http://')) {
        $data = file_get_contents($img_url);
        $dir = date('Ym');
        $filename = cls_image::random_filename();
        $imgDir = $cls_imageobj->images_dir . '/' . $dir . '/source_img/' . $filename . '.jpg';
        $dir = ROOT_PATH . $imgDir;
        $fp = @fopen($dir, "w");
        @fwrite($fp, $data);
        fclose($fp);
    } else {
        $imgDir = $img_url;
    }
    if ($mark == '0') {
        //处理缩略图
        $goods_thumb = '';
        $goods_img = '';
        $goods_thumb = $cls_imageobj->make_thumb('http://o2o.txd168.com/' . $imgDir, "170", '170');
        $goods_img = $cls_imageobj->make_thumb('http://o2o.txd168.com/' . $imgDir, "300", '300');
        return array('original_img' => $imgDir, 'goods_thumb' => $goods_thumb, 'goods_img' => $goods_img);
    } elseif ($mark == '1') {
        return $imgDir;
    }
}