Example #1
0
 /**
  * @brief ��������ͼ
  * @param string $imgSrc ͼƬ·��
  * @param int $width ͼƬ���
  * @param int $height ͼƬ�߶�
  * @return string WEBͼƬ·������
  */
 public static function get($imgSrc, $width = 100, $height = 100)
 {
     if ($imgSrc == '') {
         return '';
     }
     //��Ʒ����ʵ��·��
     $sourcePath = IWeb::$app->getBasePath() . $imgSrc;
     //����ͼ�ļ���
     $preThumb = "{$width}_{$height}_";
     $thumbFileName = $preThumb . basename($imgSrc);
     //����ͼĿ¼
     $thumbDir = self::getThumbDir() . dirname($imgSrc) . "/";
     $webThumbDir = self::$thumbDir . dirname($imgSrc) . "/";
     if (is_file($thumbDir . $thumbFileName) == false && is_file($sourcePath)) {
         IImage::thumb($sourcePath, $width, $height, $preThumb, $thumbDir);
     }
     return $webThumbDir . $thumbFileName;
 }
Example #2
0
 /**
  * @brief 生成$fileName文件的缩略图,位置与$fileName相同
  * @param string  $fileName 要生成缩略图的目标文件
  * @param int     $width    缩略图宽度
  * @param int     $height   缩略图高度
  * @param string  $extName  缩略图文件名附加值
  * @param string  $saveDir  缩略图存储目录
  */
 public static function thumb($fileName, $width, $height, $extName = '_thumb', $saveDir = '')
 {
     return IImage::thumb($fileName, $width, $height, $extName, $saveDir);
 }
Example #3
0
 /**
  *导入CSV文件
  * @param <文件路径> $name
  * @param <文件标示> $mark
  */
 function import($name, $mark)
 {
     $handle = fopen($name, 'r');
     $goods_col = array();
     $goods_col['1'] = 'name';
     $goods_col['2'] = 'goods_no';
     $goods_col['3'] = 'model_id';
     $goods_col['4'] = 'sell_price';
     $goods_col['5'] = 'market_price';
     $goods_col['6'] = 'cost_price';
     $goods_col['7'] = 'create_time';
     $goods_col['8'] = 'store_nums';
     $goods_col['9'] = 'img';
     $goods_col['10'] = 'is_del';
     $goods_col['11'] = 'content';
     $goods_col['12'] = 'keywords';
     $goods_col['13'] = 'description';
     $goods_col['14'] = 'tag_ids';
     $goods_col['15'] = 'weight';
     $goods_col['16'] = 'point';
     $goods_col['17'] = 'unit';
     $goods_col['18'] = 'brand_id';
     $goods_col['19'] = 'visit';
     $goods_col['20'] = 'favorite';
     $goods_col['21'] = 'sort';
     $goods_col['22'] = 'list_img';
     $goods_col['23'] = 'small_img';
     $goods_col['24'] = 'spec_array';
     $goods_col['25'] = 'exp';
     $gid = '';
     $products_id = '';
     $total = 0;
     //数据总条数
     $suce = 0;
     //成功的总条数
     $group = array();
     $product = array();
     $config = new Config("site_config");
     $config_info = $config->getInfo();
     $list_thumb_width = isset($config_info['list_thumb_width']) ? $config_info['list_thumb_width'] : 175;
     $list_thumb_height = isset($config_info['list_thumb_height']) ? $config_info['list_thumb_height'] : 175;
     $show_thumb_width = isset($config_info['show_thumb_width']) ? $config_info['show_thumb_width'] : 85;
     $show_thumb_height = isset($config_info['show_thumb_height']) ? $config_info['show_thumb_height'] : 85;
     while ($data = fgetcsv($handle)) {
         $total++;
         $arr = array();
         $num = count($data);
         //导入goods表
         for ($i = 0; $i < $num; $i++) {
             if ($i == $num) {
                 break;
             }
             if ($data[0] == '*cols*') {
                 break;
             }
             if ($data[0] == 'gid') {
                 if ($i > 0 && $i < 26) {
                     $arr[$goods_col[$i]] = $this->i($data[$i]);
                     if ($goods_col[$i] == 'spec_array' || $goods_col[$i] == 'content') {
                         $arr[$goods_col[$i]] = addslashes($arr[$goods_col[$i]]);
                     }
                 }
                 if ($i == 26) {
                     $goods_no = $data[2];
                     $obj_goods = new IQuery('goods');
                     $obj_goods->fields = 'id';
                     $obj_goods->where = "goods_no='{$goods_no}'";
                     $goods_info = $obj_goods->find();
                     if (file_exists($arr['img'])) {
                         $arr['list_img'] = IImage::thumb($arr['img'], $list_thumb_width, $list_thumb_height, '_' . $list_thumb_width . '_' . $list_thumb_height);
                         $arr['small_img'] = IImage::thumb($arr['img'], $show_thumb_width, $show_thumb_height, '_' . $show_thumb_width . '_' . $show_thumb_height);
                     }
                     if (count($goods_info) == 0 || empty($goods_no)) {
                         $tb_goods = new IModel('goods');
                         $tb_goods->setData($arr);
                         $gid = $tb_goods->add();
                         $suce++;
                         //如果新添加的,则处理图片
                     } else {
                         if ($mark == 1) {
                             //生成新的商品
                             $tb_goods = new IModel('goods');
                             $tb_goods->setData($arr);
                             $gid = $tb_goods->update('id=' . $goods_info[0]['id']);
                             $suce++;
                         } else {
                             $tb_goods = new IModel('goods');
                             $tb_goods->setData($arr);
                             $gid = $tb_goods->add();
                             $suce++;
                             //如果新添加的,则处理图片
                         }
                     }
                 }
                 //保存图片
                 if ($i == 29) {
                     if (!empty($data[$i])) {
                         $photo = explode(',', substr($data[$i], 0, -1));
                         foreach ($photo as $v) {
                             if (count($goods_info) == 0 || empty($goods_no) || $mark == 2) {
                                 if (file_exists(str_replace("'", "", $v))) {
                                     $md5 = md5_file(str_replace("'", "", $v));
                                     //照片图库表
                                     $tb_goods_photo = new IModel('goods_photo');
                                     $goods_photo = $tb_goods_photo->getObj("id='" . $md5 . "'");
                                     if (count($goods_photo) == 0) {
                                         $tb_goods_photo->setData(array('id' => $md5, 'img' => str_replace("'", "", $v)));
                                         $tb_goods_photo->add();
                                     }
                                     //商品照片的关联表
                                     $tb_goods_photo_relation = new IModel('goods_photo_relation');
                                     $tb_goods_photo_relation->setData(array('goods_id' => $gid, 'photo_id' => $md5));
                                     $tb_goods_photo_relation->add();
                                 }
                             }
                         }
                     }
                 }
                 //保存商品标签
                 if ($i == 30) {
                     if (!empty($data[$i])) {
                         $commend = explode(',', substr($data[$i], 0, -1));
                         foreach ($commend as $v) {
                             $tb_commend_goods = new IModel('commend_goods');
                             $tb_commend_goods->setData(array('goods_id' => $gid, 'commend_id' => $v));
                             $tb_commend_goods->add();
                         }
                     }
                 }
                 //会员组价格
                 if ($i == 31) {
                     if (!empty($data[$i])) {
                         $group = explode(';', substr($data[$i], 0, -1));
                         foreach ($group as $gva) {
                             $gprice = explode(',', $gva);
                             $tb_group_price = new IModel('group_price');
                             $tb_group_price->setData(array('goods_id' => $gid, 'products_id' => $gprice[0], 'group_id' => $gprice[1], 'price' => $gprice[2]));
                             $tb_group_price->add();
                         }
                     }
                 }
                 //商品扩展分类
                 if ($i == 32) {
                     if (!empty($data[$i])) {
                         $cate_extend = explode('|', substr($data[$i], 0, -1));
                         foreach ($cate_extend as $cva) {
                             $tb_cate_extend = new IModel('category_extend');
                             $tb_cate_extend->setData(array('goods_id' => $gid, 'category_id' => $cva));
                             $tb_cate_extend->add();
                         }
                     }
                 }
                 //商品属性
                 if ($i > 32) {
                     if (!empty($data[$i])) {
                         if (strstr($data[$i], '**a**')) {
                             $tb_goods_attribute = new IModel('goods_attribute');
                             $attr = explode('|', $data[$i]);
                             $tb_goods_attribute->setData(array('goods_id' => $gid, 'attribute_id' => str_replace('**a**', '', $attr[0]), 'attribute_value' => $this->i($data[$i + 1]), 'model_id' => $data[4]));
                             $tb_goods_attribute->add();
                         }
                         if (strstr($data[$i], '**s**')) {
                             $tb_goods_attribute = new IModel('goods_attribute');
                             $spec = explode('|', $data[$i]);
                             $tb_goods_attribute->setData(array('goods_id' => $gid, 'spec_id' => str_replace('**s**', '', $spec[0]), 'spec_value' => $this->i($data[$i + 1]), 'model_id' => $data[4]));
                             $tb_goods_attribute->add();
                         }
                     }
                 }
             }
         }
         //导入products表
         if ($data[0] == 'pid') {
             $arr = array('goods_id' => $gid, 'products_no' => $data[2], 'sell_price' => $data[5], 'market_price' => $data[6], 'store_nums' => $data[8], 'weight' => $data[15], 'spec_array' => $data[24], 'cost_price' => $data[27], 'spec_md5' => $data[28]);
             $tb_product = new IModel('products');
             $tb_product->setData($arr);
             $products_id = $tb_product->add();
             $product[$products_id] = $data[1];
             $suce++;
         }
     }
     fclose($handle);
     //修改用户组会员价的货品ID
     if (count($product) > 0) {
         foreach ($product as $keys => $value) {
             $tb_group_price = new IModel('group_price');
             $group_price_info = $tb_group_price->query('products_id=' . $value);
             if (count($group_price_info) > 0) {
                 foreach ($group_price_info as $va) {
                     $tb_group_price->setData(array('products_id' => $keys));
                     $tb_group_price->update('id=' . $va['id']);
                 }
             }
         }
     }
     if ($suce == 0) {
         return -1;
     }
     return $total - $suce - 1;
 }
Example #4
0
 /**
  * @brief 生成$fileName文件的缩略图,位置与$fileName相同
  * @param string  $fileName 要生成缩略图的目标文件
  * @param int     $width    缩略图宽度
  * @param int     $height   缩略图高度
  * @param string  $extName  缩略图文件名附加值
  */
 static function thumb($fileName, $width, $height, $extName = '_thumb')
 {
     return IImage::thumb($fileName, $width, $height, $extName);
 }