Example #1
0
function F_get_goods_catelist($first = true)
{
    //	$catelist=F(md5('sys_category_goods_tree'));
    //	if(empty($catelist)){
    //		$catelist=get_cate_list(0,false,'goods');
    //		F(md5('sys_category_goods_tree'),$catelist);
    //	}
    //	if(!$first)unset($catelist[0]);
    //	return $catelist;
    return F_get_cate_list(true, 'goods');
}
 function createthumb()
 {
     if (IS_POST) {
         $info = array('status' => 2, 'info' => '', 'url' => '');
         $arccatid = I('post.article_catid');
         $catid = I('post.category_d');
         //查询是否有没有处理完的图片
         $thumbpath = F('thumbpath');
         if (empty($thumbpath)) {
             //开始查询要处理的图片数据
             $temarr = array();
             $map['pic'] = array('neq', 0);
             if ($arccatid != 0) {
                 $map['category_id'] = $arccatid;
             }
             $list = M('Article')->where($map)->field('pic')->select();
             foreach ($list as $val) {
                 $temarr[] = $val['pic'];
             }
             if ($catid != 0) {
                 $map['category_id'] = $catid;
             }
             $list = M('goods')->where($map)->field('pic,xc')->select();
             foreach ($list as $val) {
                 $temarr[] = $val['pic'];
                 //拆分相册
                 $xcarr = explode('|', $val['xc']);
                 foreach ($xcarr as $val) {
                     $temarr[] = $val;
                 }
             }
             //把查到的数量保存到缓存中
             F('thumbpath', $temarr);
             $thumbpath = $temarr;
         }
         //开始生成图片
         $jishu = 0;
         //处理的总数量
         $sucstr = '';
         //成功字符串
         $failjishu = 0;
         //失败的数量
         $failstr = '';
         //错误字符串
         $num = count($thumbpath);
         $num = $num > 50 ? 50 : $num;
         //一次只处理50个数据
         $i = 0;
         for ($i; $i < $num; $i++) {
             if (count($thumbpath) > 0) {
                 $spath = get_picture($thumbpath[$i], 'path');
                 $thupath = str_replace('image/', 'image/thumb/', $spath);
                 $spath = path_a($spath);
                 $dpath = str_replace('image/', 'image/thumb/', $spath);
                 if (file_exists($spath)) {
                     //源文件存在
                     if (file_exists($dpath)) {
                         unlink($dpath);
                     }
                     $result = create_thumb($spath, $dpath, C('THUMB_WIDTH'), C('THUMB_HEIGHT'));
                     if ($result === true) {
                         M('Picture')->where("id={$thumbpath[$i]}")->save(array('thumbpath' => $thupath));
                         $jishu++;
                         $sucstr .= $spath . '->' . $dpath . '<br>';
                     } else {
                         $failjishu++;
                         $failstr .= $spath . '->' . $dpath . '<br>';
                     }
                 } else {
                     $failjishu++;
                     $failstr .= '<span style="color:red;">' . $spath . "此路径文件丢失数据库id为{$thumbpath[$i]}请联系管理员自行处理</span><br>";
                 }
                 unset($thumbpath[$i]);
             }
         }
         $tishistr = '全部完成';
         if (count($thumbpath) <= 0) {
             $info['status'] = 1;
         } else {
             $tishistr = '还剩' . count($thumbpath) . '个。继续生成中......';
         }
         F('thumbpath', array_values($thumbpath));
         $info['info'] = "成功生成{$jishu}个缩略图,失败{$failjishu}个,{$failstr},{$tishistr}";
         $this->ajaxreturn($info);
         exit;
     } else {
         //文章分类树
         $catelist = F('sys_category_tree');
         if (empty($catelist)) {
             $catelist = F_get_cate_list(true, 'article');
             F('sys_category_tree', $catelist);
         }
         $catelist[0] = '全部分类';
         $field = array(array('field' => 'arccat_catid', 'name' => 'arccat_catid', 'type' => 'select', 'title' => '文章分类', 'note' => '', 'extra' => $catelist, 'is_show' => 3));
         $this->assign('fieldarr1', $field);
         $this->display();
     }
 }