Exemplo n.º 1
0
 /**
  * @brief 商品添加中图片上传的方法
  */
 static function goods_img_upload()
 {
     //获得配置文件中的数据
     $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;
     //调用文件上传类
     $photoObj = new PhotoUpload();
     $photoObj->setThumb($show_thumb_width, $show_thumb_height, 'show');
     $photoObj->setThumb($list_thumb_width, $list_thumb_height, 'list');
     $photo = $photoObj->run();
     //判断上传是否成功,如果float=1则成功
     if ($photo['Filedata']['flag'] == 1) {
         $list = $photo['Filedata']['thumb']['list'];
         $list = strrchr($list, '/');
         $id = substr($list, 1, strpos($list, '_') - 1);
         $show = $photo['Filedata']['thumb']['show'];
         $img = $photo['Filedata']['img'];
         echo IUrl::creatUrl() . $show . '|' . $show . '|' . $img . '|' . $id . '|' . $photo['Filedata']['thumb']['list'] . '|' . '_' . $show_thumb_width . '_' . $show_thumb_height;
         exit;
     } else {
         echo '0';
         exit;
     }
 }
Exemplo n.º 2
0
 function user_ico_upload()
 {
     $result = array('isError' => true);
     if (isset($_FILES['attach']['name']) && $_FILES['attach']['name'] != '') {
         $photoObj = new PhotoUpload();
         $photo = $photoObj->run();
         if ($photo['attach']['img']) {
             $user_id = $this->user['user_id'];
             $user_obj = new IModel('user');
             $dataArray = array('head_ico' => $photo['attach']['img']);
             $user_obj->setData($dataArray);
             $where = 'id = ' . $user_id;
             $isSuss = $user_obj->update($where);
             if ($isSuss !== false) {
                 $result['isError'] = false;
                 $result['data'] = IUrl::creatUrl() . $photo['attach']['img'];
                 ISafe::set('head_ico', $dataArray['head_ico']);
             } else {
                 $result['message'] = '上传失败';
             }
         } else {
             $result['message'] = '上传失败';
         }
     } else {
         $result['message'] = '请选择图片';
     }
     echo '<script type="text/javascript">parent.callback_user_ico(' . JSON::encode($result) . ');</script>';
 }
Exemplo n.º 3
0
 /**
  * @brief 保存品牌
  */
 function brand_save()
 {
     $brand_id = IFilter::act(IReq::get('brand_id'), 'int');
     $name = IFilter::act(IReq::get('name'));
     $sort = IFilter::act(IReq::get('sort'), 'int');
     $url = IFilter::act(IReq::get('url'));
     $description = IFilter::act(IReq::get('description'), 'text');
     $tb_brand = new IModel('brand');
     $brand = array('name' => $name, 'sort' => $sort, 'url' => $url, 'description' => $description);
     if (isset($_FILES['logo']['name']) && $_FILES['logo']['name'] != '') {
         $uploadObj = new PhotoUpload();
         $uploadObj->setIterance(false);
         $photoInfo = $uploadObj->run();
         if (isset($photoInfo['logo']['img']) && file_exists($photoInfo['logo']['img'])) {
             $brand['logo'] = $photoInfo['logo']['img'];
         }
     }
     $tb_brand->setData($brand);
     if ($brand_id) {
         $where = "id=" . $brand_id;
         $tb_brand->update($where);
     } else {
         $tb_brand->add();
     }
     $this->brand_list();
 }
Exemplo n.º 4
0
 /**
  * @brief 商品添加中图片上传的方法
  */
 public function goods_img_upload()
 {
     //获得配置文件中的数据
     $config = new Config("site_config");
     //调用文件上传类
     $photoObj = new PhotoUpload();
     $photo = current($photoObj->run());
     //判断上传是否成功,如果float=1则成功
     if ($photo['flag'] == 1) {
         $result = array('flag' => 1, 'img' => $photo['img']);
     } else {
         $result = array('flag' => $photo['flag']);
     }
     echo JSON::encode($result);
 }
Exemplo n.º 5
0
 public static function get($image_url, $width = 100, $height = 100)
 {
     $ext = strrchr($image_url, '.');
     $end = intval("-" . strlen($ext));
     $real_url = substr($image_url, 0, $end) . "_{$width}_{$height}" . $ext;
     if (file_exists($real_url)) {
         return IUrl::creatUrl("") . $real_url;
     }
     return IUrl::creatUrl("") . PhotoUpload::thumb($image_url, $width, $height, "_{$width}_{$height}");
 }
Exemplo n.º 6
0
 /**
  * @brief Éú³ÉËõÂÔͼ
  * @param string $image_url ͼƬ·¾¶
  * @param int $width ͼƬ¿í¶È
  * @param int $height ͼƬ¸ß¶È
  */
 public static function get($image_url, $width = 100, $height = 100)
 {
     if ($image_url == '') {
         return '';
     }
     $fileExt = IFile::getFileSuffix($image_url);
     $extName = "_{$width}_{$height}";
     $thumbFileName = str_replace('.' . $fileExt, $extName . '.' . $fileExt, $image_url);
     if (is_file(IWeb::$app->getRuntimePath() . $thumbFileName) == false) {
         PhotoUpload::thumb($image_url, $width, $height, "_{$width}_{$height}", IWeb::$app->getRuntimePath() . dirname($image_url));
     }
     return 'runtime/' . IWeb::$app->controller->theme . '/' . $thumbFileName;
 }
Exemplo n.º 7
0
 /**
  * 用户在编辑器里上传图片
  */
 public function upload_img_from_editor()
 {
     $checkRight = new checkRights($this);
     $checkRight->checkAdminRights();
     $photoUpload = new PhotoUpload();
     $photoUpload->setIterance(false);
     $re = $photoUpload->run();
     if (isset($re['imgFile']['flag']) && $re['imgFile']['flag'] == 1) {
         $filePath = IUrl::creatUrl() . $re['imgFile']['dir'] . $re['imgFile']['name'];
         echo JSON::encode(array('error' => 0, 'url' => $filePath));
         exit;
     } else {
         $this->alert("上传失败");
     }
 }
Exemplo n.º 8
0
 function regiment_edit_act()
 {
     $id = IFilter::act(IReq::get('id'), 'int');
     $goodsId = IFilter::act(IReq::get('goods_id'), 'int');
     $dataArray = array('id' => $id, 'title' => IFilter::act(IReq::get('title', 'post')), 'start_time' => IFilter::act(IReq::get('start_time', 'post')), 'end_time' => IFilter::act(IReq::get('end_time', 'post')), 'is_close' => 1, 'intro' => IFilter::act(IReq::get('intro', 'post')), 'goods_id' => $goodsId, 'store_nums' => IFilter::act(IReq::get('store_nums', 'post')), 'limit_min_count' => IFilter::act(IReq::get('limit_min_count', 'post'), 'int'), 'limit_max_count' => IFilter::act(IReq::get('limit_max_count', 'post'), 'int'), 'regiment_price' => IFilter::act(IReq::get('regiment_price', 'post')));
     if ($goodsId) {
         $goodsObj = new IModel('goods');
         $where = 'id = ' . $goodsId . ' and seller_id = ' . $this->seller['seller_id'];
         $goodsRow = $goodsObj->getObj($where);
         //商品信息不存在
         if (!$goodsRow) {
             $this->regimentRow = $dataArray;
             $this->redirect('regiment_edit', false);
             Util::showMessage('请选择商户自己的商品');
         }
         //处理上传图片
         if (isset($_FILES['img']['name']) && $_FILES['img']['name'] != '') {
             $uploadObj = new PhotoUpload();
             $photoInfo = $uploadObj->run();
             $dataArray['img'] = $photoInfo['img']['img'];
         } else {
             $dataArray['img'] = $goodsRow['img'];
         }
         $dataArray['sell_price'] = $goodsRow['sell_price'];
     } else {
         $this->regimentRow = $dataArray;
         $this->redirect('regiment_edit', false);
         Util::showMessage('请选择要关联的商品');
     }
     $regimentObj = new IModel('regiment');
     $regimentObj->setData($dataArray);
     if ($id) {
         $where = 'id = ' . $id;
         $regimentObj->update($where);
     } else {
         $regimentObj->add();
     }
     $this->redirect('regiment_list');
 }
Exemplo n.º 9
0
 function save_conf()
 {
     //错误信息
     $message = null;
     $form_index = IReq::get('form_index');
     switch ($form_index) {
         case "base_conf":
             if (isset($_FILES['logo']['name']) && $_FILES['logo']['name'] != '') {
                 $uploadObj = new PhotoUpload('image');
                 $uploadObj->setIterance(false);
                 $photoInfo = $uploadObj->run();
                 if (!isset($photoInfo['logo']['img']) || !file_exists($photoInfo['logo']['img'])) {
                     $message = 'logo图片上传失败';
                 } else {
                     unlink('image/logo.gif');
                     rename($photoInfo['logo']['img'], 'image/logo.gif');
                 }
             }
             break;
         case "index_slide":
             $config_slide = array();
             if (isset($_POST['slide_name'])) {
                 foreach ($_POST['slide_name'] as $key => $value) {
                     $config_slide[$key]['name'] = $value;
                     $config_slide[$key]['url'] = $_POST['slide_url'][$key];
                     $config_slide[$key]['img'] = $_POST['slide_img'][$key];
                 }
             }
             if (isset($_FILES['slide_pic'])) {
                 $uploadObj = new PhotoUpload();
                 $uploadObj->setIterance(false);
                 $slideInfo = $uploadObj->run();
                 if (isset($slideInfo['slide_pic']['flag'])) {
                     $slideInfo['slide_pic'] = array($slideInfo['slide_pic']);
                 }
                 if (isset($slideInfo['slide_pic'])) {
                     foreach ($slideInfo['slide_pic'] as $key => $value) {
                         if ($value['flag'] == 1) {
                             $config_slide[$key]['img'] = $value['img'];
                         }
                     }
                 }
             }
             $_POST = array('index_slide' => serialize($config_slide));
             break;
         case "guide_conf":
             $guideName = IFilter::act(IReq::get('guide_name'));
             $guideLink = IFilter::act(IReq::get('guide_link'));
             $data = array();
             $guideObj = new IModel('guide');
             if (!empty($guideName)) {
                 foreach ($guideName as $key => $val) {
                     if (!empty($val) && !empty($guideLink[$key])) {
                         $data[$key]['name'] = $val;
                         $data[$key]['link'] = $guideLink[$key];
                     }
                 }
             }
             //清空导航栏
             $guideObj->del('all');
             if (!empty($data)) {
                 //插入数据
                 foreach ($data as $order => $rs) {
                     $dataArray = array('order' => $order, 'name' => $rs['name'], 'link' => $rs['link']);
                     $guideObj->setData($dataArray);
                     $guideObj->add();
                 }
                 //跳转方法
                 $this->conf_base($form_index);
             }
             break;
         case "shopping_conf":
             break;
         case "show_conf":
             if (isset($_POST['auto_finish']) && $_POST['auto_finish'] == "") {
                 $_POST['auto_finish'] == "0";
             }
             break;
         case "image_conf":
             break;
         case "mail_conf":
             break;
         case "system_conf":
             break;
     }
     //获取输入的数据
     $inputArray = $_POST;
     if ($message == null) {
         if ($form_index == 'system_conf') {
             //写入的配置文件
             $configFile = IWeb::$app->config['basePath'] . 'config/config.php';
             config::edit($configFile, $inputArray);
         } else {
             $siteObj = new Config('site_config');
             $siteObj->write($inputArray);
         }
         //跳转方法
         $this->conf_base($form_index);
     } else {
         $inputArray['form_index'] = $form_index;
         $this->confRow = $inputArray;
         $this->redirect('conf_base', false);
         Util::showMessage($message);
     }
 }
Exemplo n.º 10
0
 /**
  * @brief 商户的增加动作
  */
 public function seller_reg()
 {
     $seller_name = IFilter::act(IReq::get('seller_name'));
     $email = IFilter::act(IReq::get('email'));
     $password = IFilter::act(IReq::get('password'));
     $repassword = IFilter::act(IReq::get('repassword'));
     $truename = IFilter::act(IReq::get('true_name'));
     $phone = IFilter::act(IReq::get('phone'));
     $mobile = IFilter::act(IReq::get('mobile'));
     $province = IFilter::act(IReq::get('province'), 'int');
     $city = IFilter::act(IReq::get('city'), 'int');
     $area = IFilter::act(IReq::get('area'), 'int');
     $address = IFilter::act(IReq::get('address'));
     $home_url = IFilter::act(IReq::get('home_url'));
     if ($password == '') {
         $errorMsg = '请输入密码!';
     }
     if ($password != $repassword) {
         $errorMsg = '两次输入的密码不一致!';
     }
     //创建商家操作类
     $sellerDB = new IModel("seller");
     if ($sellerDB->getObj("seller_name = '{$seller_name}'")) {
         $errorMsg = "登录用户名重复";
     } else {
         if ($sellerDB->getObj("true_name = '{$truename}'")) {
             $errorMsg = "商户真实全称重复";
         }
     }
     //操作失败表单回填
     if (isset($errorMsg)) {
         $this->sellerRow = $_POST;
         $this->redirect('seller', false);
         Util::showMessage($errorMsg);
     }
     //待更新的数据
     $sellerRow = array('true_name' => $truename, 'phone' => $phone, 'mobile' => $mobile, 'email' => $email, 'address' => $address, 'province' => $province, 'city' => $city, 'area' => $area, 'home_url' => $home_url, 'is_lock' => 1);
     //商户资质上传
     if (isset($_FILES['paper_img']['name']) && $_FILES['paper_img']['name']) {
         $uploadObj = new PhotoUpload();
         $uploadObj->setIterance(false);
         $photoInfo = $uploadObj->run();
         if (isset($photoInfo['paper_img']['img']) && file_exists($photoInfo['paper_img']['img'])) {
             $sellerRow['paper_img'] = $photoInfo['paper_img']['img'];
         }
     }
     $sellerRow['seller_name'] = $seller_name;
     $sellerRow['password'] = md5($password);
     $sellerRow['create_time'] = ITime::getDateTime();
     $sellerDB->setData($sellerRow);
     $sellerDB->add();
     //短信通知商城平台
     $siteConfig = new Config('site_config');
     if ($siteConfig->mobile) {
         $content = smsTemplate::sellerReg(array('{true_name}' => $truename));
         $result = Hsms::send($mobile, $content);
     }
     $this->redirect('/site/success?message=' . urlencode("申请成功!请耐心等待管理员的审核"));
 }
Exemplo n.º 11
0
 public function expresswaybill_upload()
 {
     $result = array('isError' => true);
     if (isset($_FILES['attach']['name']) && $_FILES['attach']['name'] != '') {
         $photoObj = new PhotoUpload();
         $photo = $photoObj->run();
         $result['isError'] = false;
         $result['data'] = $photo['attach']['img'];
     } else {
         $result['message'] = '请选择图片';
     }
     echo '<script type="text/javascript">parent.photoUpload_callback(' . JSON::encode($result) . ');</script>';
 }
Exemplo n.º 12
0
 /**
  * @brief 商户的增加动作
  */
 public function seller_add()
 {
     $seller_id = IFilter::act(IReq::get('id'), 'int');
     $seller_name = IFilter::act(IReq::get('seller_name'));
     $email = IFilter::act(IReq::get('email'));
     $password = IFilter::act(IReq::get('password'));
     $repassword = IFilter::act(IReq::get('repassword'));
     $truename = IFilter::act(IReq::get('true_name'));
     $phone = IFilter::act(IReq::get('phone'));
     $mobile = IFilter::act(IReq::get('mobile'));
     $province = IFilter::act(IReq::get('province'), 'int');
     $city = IFilter::act(IReq::get('city'), 'int');
     $area = IFilter::act(IReq::get('area'), 'int');
     $cash = IFilter::act(IReq::get('cash'), 'float');
     $is_vip = IFilter::act(IReq::get('is_vip'), 'int');
     $is_lock = IFilter::act(IReq::get('is_lock'), 'int');
     $address = IFilter::act(IReq::get('address'));
     $account = IFilter::act(IReq::get('account'));
     $server_num = IFilter::act(IReq::get('server_num'));
     $home_url = IFilter::act(IReq::get('home_url'));
     $sort = IFilter::act(IReq::get('sort'), 'int');
     if (!$seller_id && $password == '') {
         $errorMsg = '请输入密码!';
     }
     if ($password != $repassword) {
         $errorMsg = '两次输入的密码不一致!';
     }
     //创建商家操作类
     $sellerDB = new IModel("seller");
     if ($sellerDB->getObj("seller_name = '{$seller_name}' and id != {$seller_id}")) {
         $errorMsg = "登录用户名重复";
     } else {
         if ($sellerDB->getObj("true_name = '{$truename}' and id != {$seller_id}")) {
             $errorMsg = "商户真实全程重复";
         }
     }
     //操作失败表单回填
     if (isset($errorMsg)) {
         $this->sellerRow = $_POST;
         $this->redirect('seller_edit', false);
         Util::showMessage($errorMsg);
     }
     //待更新的数据
     $sellerRow = array('true_name' => $truename, 'account' => $account, 'phone' => $phone, 'mobile' => $mobile, 'email' => $email, 'address' => $address, 'is_vip' => $is_vip, 'is_lock' => $is_lock, 'cash' => $cash, 'province' => $province, 'city' => $city, 'area' => $area, 'server_num' => $server_num, 'home_url' => $home_url, 'sort' => $sort);
     //商户资质上传
     if (isset($_FILES['paper_img']['name']) && $_FILES['paper_img']['name']) {
         $uploadObj = new PhotoUpload();
         $uploadObj->setIterance(false);
         $photoInfo = $uploadObj->run();
         if (isset($photoInfo['paper_img']['img']) && file_exists($photoInfo['paper_img']['img'])) {
             $sellerRow['paper_img'] = $photoInfo['paper_img']['img'];
         }
     }
     //添加新会员
     if (!$seller_id) {
         $sellerRow['seller_name'] = $seller_name;
         $sellerRow['password'] = md5($password);
         $sellerRow['create_time'] = ITime::getDateTime();
         $sellerDB->setData($sellerRow);
         $sellerDB->add();
     } else {
         //修改密码
         if ($password) {
             $sellerRow['password'] = md5($password);
         }
         $sellerDB->setData($sellerRow);
         $sellerDB->update("id = " . $seller_id);
     }
     $this->redirect('seller_list');
 }
Exemplo n.º 13
0
 /**
  * @brief 把采集的结果插入到商城系统中
  * @param array $collectResult 采集后的结果集
  * array( 'goods_no' => '商品编号','up_time' => '上架时间','weight' => '重量','unit' => '计量单位','name' => '商品名字','price' => '商品价格','marketprice' => '市场价格','img' => array(商品图片),'content' => '商品详情';
  */
 private static function insert($collectResult)
 {
     //实例化对象
     $catObj = new IModel('category');
     $catExtObj = new IModel('category_extend');
     $attrObj = new IModel('attribute');
     $goodsObj = new IModel('goods');
     $goodsAttrObj = new IModel('goods_attribute');
     $photoObj = new IModel('goods_photo');
     $photoRelObj = new IModel('goods_photo_relation');
     //处理商品数据
     foreach ($collectResult as $key => $val) {
         //商品添加
         $goodsObj->setData(array('name' => $val['name'], 'sell_price' => $val['price'], 'market_price' => $val['marketprice'], 'goods_no' => $val['goods_no'], 'up_time' => $val['up_time'], 'content' => $val['content'], 'store_nums' => 100, 'weight' => $val['weight'], 'unit' => $val['unit'], 'create_time' => date('Y-m-d H:i:s'), 'seller_id' => self::$seller_id));
         $goods_id = $goodsObj->add();
         //商品图片拷贝
         if (isset($val['img']) && $val['img']) {
             foreach ($val['img'] as $img) {
                 $md5Val = md5_file($img);
                 $photoData = $photoObj->getObj('id = "' . $md5Val . '"');
                 //如果图库中没有图片数据就要拷贝
                 if (!$photoData) {
                     $destFile = PhotoUpload::hashDir() . '/' . basename($img);
                     $copyResult = IFile::copy($img, IWeb::$app->getBasePath() . "/" . $destFile);
                     if ($copyResult) {
                         $photoObj->setData(array('id' => $md5Val, 'img' => $destFile));
                         $photoObj->add();
                     }
                 }
                 //商品图片关联
                 $photoRelObj->setData(array('goods_id' => $goods_id, 'photo_id' => $md5Val));
                 $photoRelObj->add();
             }
             $imgVal = isset($destFile) ? $destFile : $photoData['img'];
             $goodsObj->setData(array('img' => $imgVal));
             $goodsObj->update('id = ' . $goods_id);
         }
         //商品与商品分类关联
         if (self::$category) {
             foreach (self::$category as $catId) {
                 $catExtObj->setData(array('goods_id' => $goods_id, 'category_id' => $catId));
                 $catExtObj->add();
             }
         }
     }
     return array('result' => 'success');
 }
Exemplo n.º 14
0
 function save_conf()
 {
     if (!$_POST) {
         $this->redirect('conf_base');
     }
     //错误信息
     $form_index = IReq::get('form_index');
     switch ($form_index) {
         case "base_conf":
             break;
         case "site_footer_conf":
             $_POST['site_footer_code'] = preg_replace('![\\r\\n]+!', "", $_POST['site_footer_code']);
             break;
         case "index_slide":
             $config_slide = array();
             if (isset($_POST['slide_name'])) {
                 foreach ($_POST['slide_name'] as $key => $value) {
                     $config_slide[$key]['name'] = $value;
                     $config_slide[$key]['url'] = $_POST['slide_url'][$key];
                     $config_slide[$key]['img'] = $_POST['slide_img'][$key];
                 }
             }
             if (isset($_FILES['slide_pic'])) {
                 $uploadObj = new PhotoUpload();
                 $uploadObj->setIterance(false);
                 $slideInfo = $uploadObj->run();
                 if (isset($slideInfo['slide_pic']['flag'])) {
                     $slideInfo['slide_pic'] = array($slideInfo['slide_pic']);
                 }
                 if (isset($slideInfo['slide_pic'])) {
                     foreach ($slideInfo['slide_pic'] as $key => $value) {
                         if ($value['flag'] == 1) {
                             $config_slide[$key]['img'] = $value['img'];
                         }
                     }
                 }
             }
             $_POST = array('index_slide' => serialize($config_slide));
             break;
             //导航写入数据库,不需要记录配置文件
         //导航写入数据库,不需要记录配置文件
         case "guide_conf":
             $guideName = IFilter::act(IReq::get('guide_name'));
             $guideLink = IFilter::act(IReq::get('guide_link'));
             $data = array();
             $guideObj = new IModel('guide');
             if (!empty($guideName)) {
                 foreach ($guideName as $key => $val) {
                     if (!empty($val) && !empty($guideLink[$key])) {
                         $data[$key]['name'] = $val;
                         $data[$key]['link'] = $guideLink[$key];
                     }
                 }
             }
             //清空导航栏
             $guideObj->del('all');
             if ($data) {
                 //插入数据
                 foreach ($data as $order => $rs) {
                     $dataArray = array('order' => $order, 'name' => $rs['name'], 'link' => $rs['link']);
                     $guideObj->setData($dataArray);
                     $guideObj->add();
                 }
                 //跳转方法
                 $this->redirect('conf_base', false);
                 exit;
             }
             break;
         case "other_conf":
             if (isset($_POST['auto_finish']) && $_POST['auto_finish'] == "") {
                 $_POST['auto_finish'] == "0";
             }
             break;
         case "mail_conf":
             break;
         case "system_conf":
             break;
         case "service_online":
             $serviceName = IFilter::act(IReq::get('service_name'));
             $serviceQQ = IFilter::act(IReq::get('service_qq'));
             $data = array();
             foreach ($serviceName as $key => $val) {
                 $data[] = array('name' => $serviceName[$key], 'qq' => $serviceQQ[$key]);
             }
             $_POST = array('service_online' => serialize($data));
             break;
     }
     //获取输入的数据
     $this->confRow = $inputArray = $_POST;
     if ($form_index == 'system_conf') {
         //写入的配置文件
         $configFile = IWeb::$app->getBasePath() . 'config/config.php';
         Config::edit($configFile, $inputArray);
     } else {
         $siteObj = new Config('site_config');
         $siteObj->write($inputArray);
     }
     $this->redirect('conf_base', false);
 }
Exemplo n.º 15
0
 /**
  * @brief 开始运行
  */
 public static function run()
 {
     set_time_limit(0);
     ini_set("max_execution_time", 0);
     $csvType = IReq::get('csvType');
     $category = IFilter::act(IReq::get('category'), 'int');
     $pluginDir = IWeb::$app->getBasePath() . 'plugins/csvPacketHelper/';
     if (!file_exists($pluginDir)) {
         die('此功能仅供授权版本使用,请您购买商业授权');
     }
     if (!class_exists('ZipArchive')) {
         die('服务器环境中没有安装zip扩展,无法使用此功能');
     }
     if (extension_loaded('mbstring') == false) {
         die('服务器环境中没有安装mbstring扩展,无法使用此功能');
     }
     //处理上传
     $uploadInstance = new IUpload(9999999, array('zip'));
     $uploadCsvDir = 'runtime/cvs/' . date('YmdHis');
     $uploadInstance->setDir($uploadCsvDir);
     $result = $uploadInstance->execute();
     if (!isset($result['csvPacket'])) {
         die('请上传指定大小的csv数据包');
     }
     if (($packetData = current($result['csvPacket'])) && $packetData['flag'] != 1) {
         $message = $uploadInstance->errorMessage($packetData['flag']);
         die($message);
     }
     $zipPath = $packetData['fileSrc'];
     $zipDir = dirname($zipPath);
     $imageDir = IWeb::$app->config['upload'] . '/' . date('Y/m/d');
     file_exists($imageDir) ? '' : IFile::mkdir($imageDir);
     //解压缩包
     $zipObject = new ZipArchive();
     $zipObject->open($zipPath);
     $isExtract = $zipObject->extractTo($zipDir);
     $zipObject->close();
     if ($isExtract == false) {
         $message = '解压缩到目录' . $zipDir . '失败!';
         die($message);
     }
     //实例化商品
     $goodsObject = new IModel('goods');
     $photoRelationDB = new IModel('goods_photo_relation');
     $photoDB = new IModel('goods_photo');
     $cateExtendDB = new IModel('category_extend');
     //获得配置文件中的数据
     $config = new Config("site_config");
     $dirHandle = opendir($zipDir);
     while ($fileName = readdir($dirHandle)) {
         if (strpos($fileName, '.csv') !== false) {
             //创建解析对象
             switch ($csvType) {
                 case "taobao":
                     include_once $pluginDir . 'taoBaoPacketHelper.php';
                     $helperInstance = new taoBaoPacketHelper($zipDir . '/' . $fileName, $imageDir);
                     $titleToCols = taoBaoTitleToColsMapping::$mapping;
                     break;
                 default:
                     $message = "请选择csv数据包的格式";
                     die($message);
             }
             //从csv中解析数据
             $collectData = $helperInstance->collect();
             //插入商品表
             foreach ($collectData as $key => $val) {
                 $collectImage = isset($val[$titleToCols['img']]) ? $val[$titleToCols['img']] : '';
                 //有图片处理
                 if ($collectImage) {
                     //图片拷贝
                     $_FILES = array();
                     foreach ($collectImage as $image) {
                         foreach ($image as $from => $to) {
                             if (!is_file($from)) {
                                 continue;
                             }
                             IFile::xcopy($from, $to);
                             //构造$_FILES全局数组
                             $_FILES[] = array('size' => 100, 'tmp_name' => $to, 'name' => basename($to), 'error' => 0);
                         }
                     }
                     //调用文件上传类
                     $photoObj = new PhotoUpload();
                     $uploadImg = $photoObj->run(true);
                     $showImg = current($uploadImg);
                 }
                 //处理商品详情图片
                 $toDir = IUrl::creatUrl() . dirname($to);
                 $goodsContent = preg_replace("|src=\".*?(?=/contentPic/)|", "src=\"{$toDir}", trim($val[$titleToCols['content']], "'\""));
                 $insertData = array('name' => IFilter::act(trim($val[$titleToCols['name']], '"\'')), 'goods_no' => goods_class::createGoodsNo(), 'sell_price' => IFilter::act($val[$titleToCols['sell_price']], 'float'), 'market_price' => IFilter::act($val[$titleToCols['sell_price']], 'float'), 'up_time' => ITime::getDateTime(), 'create_time' => ITime::getDateTime(), 'store_nums' => IFilter::act($val[$titleToCols['store_nums']], 'int'), 'content' => IFilter::addSlash($goodsContent), 'img' => isset($showImg['img']) ? $showImg['img'] : '', 'seller_id' => self::$seller_id);
                 $goodsObject->setData($insertData);
                 $goods_id = $goodsObject->add();
                 //处理商品分类
                 if ($category) {
                     foreach ($category as $catId) {
                         $cateExtendDB->setData(array('goods_id' => $goods_id, 'category_id' => $catId));
                         $cateExtendDB->add();
                     }
                 }
                 //处理商品图片
                 if ($uploadImg) {
                     $imgArray = array();
                     foreach ($uploadImg as $temp) {
                         if (isset($temp['img']) && $temp['img']) {
                             $imgArray[] = $temp['img'];
                         }
                     }
                     if ($imgArray) {
                         $photoData = $photoDB->query('img in ("' . join('","', $imgArray) . '")', 'id');
                         if ($photoData) {
                             foreach ($photoData as $item) {
                                 $photoRelationDB->setData(array('goods_id' => $goods_id, 'photo_id' => $item['id']));
                                 $photoRelationDB->add();
                             }
                         }
                     }
                 }
             }
         }
     }
     //清理csv文件数据
     IFile::rmdir($uploadCsvDir, true);
     die('<script type="text/javascript">parent.artDialogCallback();</script>');
 }
Exemplo n.º 16
0
 /**
  * @brief 运行采集功能
  */
 public static function run()
 {
     set_time_limit(0);
     ini_set("max_execution_time", "0");
     $collect_name = IFilter::act(IReq::get('collect_name'));
     $url = IFilter::act(IReq::get('url'));
     $pluginDir = IWeb::$app->getBasePath() . 'plugins/collect/';
     switch ($collect_name) {
         //京东商城数据采集器
         case 'jd':
             include_once $pluginDir . 'jd_collect.php';
             $collectorObject = new jd_collect();
             break;
         default:
             die('<script type="text/javascript">parent.artDialogCallback("没有找到采集器");</script>');
     }
     $collectorObject->readListPage($url);
     $goodsData = $collectorObject->collect();
     //实例化对象
     $catObj = new IModel('category');
     $catExtObj = new IModel('category_extend');
     $attrObj = new IModel('attribute');
     $goodsObj = new IModel('goods');
     $goodsAttrObj = new IModel('goods_attribute');
     $photoObj = new IModel('goods_photo');
     $photoRelObj = new IModel('goods_photo_relation');
     $modelObj = new IModel('model');
     $productsObj = new IModel('products');
     //信息入库
     if (isset($goodsData['cat']) && $goodsData['cat']) {
         $model_id = 0;
         $attrMap = array();
         if (isset($goodsData['attr']) && $goodsData['attr']) {
             $modelName = end($goodsData['cat']);
             //1,模型存在情况-直接读取
             if ($modelRow = $modelObj->getObj('name = "' . $modelName . '"')) {
                 $model_id = $modelRow['id'];
                 $attrList = $attrObj->query('model_id = ' . $model_id);
                 foreach ($attrList as $key => $val) {
                     $attrMap[$val['name']] = $val['id'];
                 }
             } else {
                 //创建模型
                 $modelObj->setData(array('name' => $modelName));
                 $model_id = $modelObj->add();
                 //创建模型属性
                 foreach ($goodsData['attr'] as $key => $val) {
                     $attrObj->setData(array('model_id' => $model_id, 'type' => 2, 'name' => $key, 'value' => $val, 'search' => 1));
                     $newAttrId = $attrObj->add();
                     $attrMap[$key] = $newAttrId;
                 }
             }
         }
         //分类添加
         $parentId = 0;
         $catPath = array();
         foreach ($goodsData['cat'] as $key => $val) {
             if ($catRow = $catObj->getObj('name = "' . $val . '"')) {
                 $catPath[] = $parentId = $catRow['id'];
             } else {
                 $catObj->setData(array('name' => $val, 'parent_id' => $parentId, 'model_id' => $model_id));
                 $parentId = $catObj->add();
                 $catPath[] = $parentId;
             }
         }
         //处理商品数据
         foreach ($goodsData['item'] as $key => $val) {
             //商品添加
             $goodsObj->setData(array('name' => $val['name'], 'sell_price' => $val['price'], 'market_price' => $val['price'], 'model_id' => $model_id, 'goods_no' => $val['goods_no'], 'up_time' => $val['up_time'], 'content' => IFilter::act($val['content'], 'text'), 'store_nums' => 100, 'weight' => $val['weight'], 'unit' => $val['unit'], 'create_time' => date('Y-m-d H:i:s')));
             $goods_id = $goodsObj->add();
             //商品图片拷贝
             if (isset($val['img']) && $val['img']) {
                 foreach ($val['img'] as $img) {
                     $md5Val = md5_file($img);
                     $photoData = $photoObj->getObj('id = "' . $md5Val . '"');
                     if (!$photoData) {
                         $destFile = PhotoUpload::hashDir() . '/' . basename($img);
                         if (IFile::copy($img, $destFile)) {
                             $photoObj->setData(array('id' => $md5Val, 'img' => $destFile));
                             $photoObj->add();
                         }
                     }
                     //商品图片关联
                     $photoRelObj->setData(array('goods_id' => $goods_id, 'photo_id' => $md5Val));
                     $photoRelObj->add();
                 }
                 $imgVal = isset($destFile) ? $destFile : $photoData['img'];
                 $goodsObj->setData(array('img' => $imgVal));
                 $goodsObj->update('id = ' . $goods_id);
             }
             //商品与商品分类关联
             if ($catPath) {
                 foreach ($catPath as $catId) {
                     $catExtObj->setData(array('goods_id' => $goods_id, 'category_id' => $catId));
                     $catExtObj->add();
                 }
             }
             //商品与属性关联
             if (isset($val['attr']) && $val['attr']) {
                 foreach ($val['attr'] as $attrName => $attrVal) {
                     if (isset($attrMap[$attrName])) {
                         $attrArray = explode(',', $attrVal);
                         foreach ($attrArray as $k => $v) {
                             $goodsAttrObj->setData(array('goods_id' => $goods_id, 'attribute_id' => $attrMap[$attrName], 'attribute_value' => $v, 'model_id' => $model_id));
                             $goodsAttrObj->add();
                         }
                     }
                 }
             }
         }
         die('<script type="text/javascript">parent.artDialogCallback();</script>');
     } else {
         die('<script type="text/javascript">parent.artDialogCallback("采集信息不存在");</script>');
     }
 }