Exemple #1
0
<?php

/**
 * Created by PhpStorm.
 * User: hssh_win8.1
 * Date: 2015/10/4
 * Time: 20:40
 * file: cateadd.php  栏目添加
 */
require_once './common/include.php';
$mu = new ModelUser('bl_cate');
$sql = 'select * from bl_cate where 1 order by cate_id ';
$res = $mu->getAll($sql);
// 无限极分类 返回 一维数组
$catelist = ToolsInfClassify::ClassifyForOne($res);
require ROOT . 'view/admin/templates/cateadd.html';
 * Date: 2015/10/5
 * Time: 17:55
 * file: cateedithandle.php  编辑栏目信息的处理函数
 */
require_once './common/include.php';
//print_r($_POST);
$cate_id = $_POST['cate_id'] + 0;
$cate_name = $_POST['cate_name'];
$cate_desc = $_POST['cate_desc'];
$newparent_id = $_POST['parent_id'] + 0;
// 实例化数据库
$mu = new ModelUser('bl_cate');
// 判断新的父栏目是否在子栏目中 如果是的话 就返回错误
$field = array('cate_id', 'parent_id');
$res = $mu->select($field, 'is_delete=0 order by cate_id');
$allChildId = ToolsInfClassify::ChildrenId($res, $cate_id);
// 父栏目选取错误
if (in_array($newparent_id, $allChildId) || $newparent_id == $cate_id) {
    echo '2';
    return;
}
// 改变父栏目
$arr = array('parent_id' => $newparent_id, 'cate_name' => $cate_name, 'cate_desc' => $cate_desc);
$res = $mu->update($arr, 'cate_id=' . $cate_id);
//echo $res;
if ($res != 1) {
    // 编辑失败
    echo '1';
    return;
} else {
    // 编辑成功
Exemple #3
0
$navlist = ToolsInfClassify::FamilyTree($ALLCATE, $cate_id);
//print_r($navlist);
// 获得子栏目
$cur_catelist = ToolsInfClassify::ClassifyForMul($ALLCATE, $cate_id);
if (!$cur_catelist) {
    // 没有子栏目 取父栏目的子栏目
    $parent_id = ToolsInfClassify::FamilyTree($ALLCATE, $cate_id)[1]['cate_id'];
    $cur_catelist = ToolsInfClassify::ClassifyForMul($ALLCATE, $parent_id);
}
//print_r($cur_catelist);die();
// 本周热销
$hotlist = $mg->select(array('goods_id', 'goods_name', 'goods_price', 'goods_img'), 'is_hot order by sale_total desc limit 0,3');
// 本周新品
$newlist = $mg->select(array('goods_id', 'goods_name', 'goods_price', 'goods_img'), 'is_new order by sale_total desc limit 0,3');
// 或的该栏目下的所有商品
$allCateId = ToolsInfClassify::ChildrenId($ALLCATE, $cate_id);
array_unshift($allCateId, $cate_id);
// 分页显示
$list_per_page = 16;
// 每页显示的条数
$sql = 'select count(*) from bl_goods where cate_id in (' . implode(',', $allCateId) . ')';
$list_total = $mg->getOne($sql);
// 显示的总条数
$page_total = ceil($list_total / $list_per_page);
// 总页数
// 获得当前显示的页
if (!isset($_GET['page']) || intval($_GET['page']) < 1) {
    $page = 1;
} else {
    if (intval($_GET['page']) > $page_total) {
        $page = $page_total;
$mu = new ModelUser('bl_cate');
//判断操作类型 query为查询要删除的栏目是否存在子栏目 delete为软删除
$type = $_POST['type'];
$cate_id = $_POST['cate_id'] + 0;
// 查询
if ($type == 'query') {
    $sql = "select count(c2.cate_id) from bl_cate as c1 left join bl_cate as c2 on c1.cate_id=c2.parent_id where c1.cate_id=" . $cate_id;
    $res = $mu->getOne($sql);
    echo $res;
    return;
} else {
    if ($type == 'delete') {
        // 把要删除的栏目中所有的子栏目找出 把要删除的id全部放在allid中
        $sql = "select * from bl_cate";
        $res = $mu->getAll($sql);
        $childrenid = ToolsInfClassify::ChildrenId($res, $cate_id);
        $allid = array_merge(array($cate_id), $childrenid);
        $arr = array('is_delete' => 1);
        $where = 'cate_id in(' . implode(',', $allid) . ')';
        $res = $mu->update($arr, $where);
        if ($res != count($allid)) {
            // 删除失败
            echo '1';
            return;
        } else {
            // 删除成功
            echo '0';
            return;
        }
    }
}
Exemple #5
0
<?php

/**
 * Created by PhpStorm.
 * User: hssh_win8.1
 * Date: 2015/10/7
 * Time: 14:08
 * file: front/goods.php  前端的商品页
 */
require_once './common/include.php';
// 获得商品信息
$goods_id = isset($_GET['goods_id']) ? $_GET['goods_id'] : 12;
$sql = "select * from bl_goods where goods_id=" . $goods_id;
$goodsinfo = $mg->getRow($sql);
if (!$goodsinfo) {
    header('location: ' . 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/index.php');
}
// 获得导航条的参数
$navlist = ToolsInfClassify::FamilyTree($ALLCATE, $goodsinfo['cate_id']);
// 本周热销
$hotlist = $mg->select(array('goods_id', 'goods_name', 'goods_price', 'goods_img'), 'is_hot order by sale_total desc limit 0,3');
// 本周新品
$newlist = $mg->select(array('goods_id', 'goods_name', 'goods_price', 'goods_img'), 'is_new order by sale_total desc limit 0,3');
require ROOT . 'view/front/goods.html';
Exemple #6
0
 * Date: 2015/10/4
 * Time: 12:01
 * file: /front/index.php  前台首页
 */
require_once './common/include.php';
$res = ToolsInfClassify::ClassifyForMul($ALLCATE);
$catelist = $res[0]['child'];
//print_r($catelist);
// 获得商品 查询两次数据库 bl_cate一次 goods_id一次 两次的结果合并再无限极分类
// 获得前5栏目的cate_id及子栏目cate_id
$allCateId = array_slice($catelist, 0, 5);
$allCateId = array_get_by_key($allCateId, 'cate_id');
// 获得这些cate_id的所有商品
$sql = "select c.cate_id,c.cate_name,c.parent_id from bl_cate as c where c.cate_id in (" . implode(',', $allCateId) . ')';
$res1 = $mc->getAll($sql);
$sql = "select g.goods_id, g.goods_name, g.cate_id as parent_id, g.cate_id_temp as cate_id, g.goods_img, g.goods_price from bl_goods as g where g.cate_id in (" . implode(',', $allCateId) . ')';
$res2 = $mg->getAll($sql);
// 无限极分类整合成(cate_id的)一维数组
$alllist = ToolsInfClassify::ClassifyForMul(array_merge($res1, $res2), 1);
require ROOT . 'view/front/index.html';
/************************function***********************************************************************/
// 返回cate_id的值
function array_get_by_key(array $array, $string)
{
    if (!trim($string)) {
        return false;
    }
    //    preg_match_all("/\"$string\";\w{1}:(?:\d+:|)(.*?);/", serialize($array), $res);
    preg_match_all("/\"{$string}\";\\w{1}:\\d+:\"(\\d+)\"(.*?);/", serialize($array), $res);
    return $res[1];
}