Пример #1
0
 /**
  * 设置商品的详细描述
  * 
  * @param array $product
  * @param array $descsections
  * @return boolean
  */
 public static function set(&$product)
 {
     $descids = array();
     $descsections = $product['descsections'];
     foreach (self::get($product['id']) as $descsection) {
         $descids[$descsection['id']] = TRUE;
     }
     if ($descsections) {
         foreach ($descsections as $descsection) {
             if (isset($descsection['id']) && isset($descids[$descsection['id']])) {
                 unset($descids[$descsection['id']]);
                 Product_detailService::get_instance()->update($descsection);
             } else {
                 unset($descsection['id']);
                 $descsection['product_id'] = $product['id'];
                 Product_detailService::get_instance()->create($descsection);
             }
         }
     }
     if (!empty($descids)) {
         ORM::factory('product_detail')->in('id', array_keys($descids))->delete_all();
     }
     //Cache::remove(self::$cache_key.$product['id']);
     return TRUE;
 }
Пример #2
0
 /**
  * 首页
  */
 public function index()
 {
     // 初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     try {
         /* 清空商品搜索表中的脏数据 */
         /* 初始化默认查询结构体 */
         $query_struct = array('where' => array(), 'like' => array(), 'orderby' => array(), 'limit' => array('per_page' => 100, 'page' => 1));
         /* 清理已经删除的产品 */
         do {
             $productsearches = ProductsearchService::get_instance()->query_assoc($query_struct);
             if (is_array($productsearches) && count($productsearches) > 0) {
                 foreach ($productsearches as $value) {
                     try {
                         $product = ProductService::get_instance()->get($value['product_id']);
                         if (!is_array($product) || $product['id'] < 1) {
                             ProductsearchService::get_instance()->delete_by_productsearch_id($value['id']);
                         }
                     } catch (MyRuntimeException $ex) {
                         Kohana::log('error', 'Productsearch error:' . $value['product_id'] . ' product not found.');
                     }
                 }
                 $query_struct['limit']['page']++;
             } else {
                 break;
             }
         } while (1);
         //更新产品内容到产品搜索快照  获取产品描述
         $query_struct = array('where' => array());
         $productdescsections = array();
         $descsections = Product_detailService::get_instance()->query_assoc($query_struct);
         if (!empty($descsections)) {
             foreach ($descsections as $val) {
                 if (!empty($productdescsections[$val['product_id']])) {
                     $productdescsections[$val['product_id']] .= ' ' . $val['content'];
                 } else {
                     $productdescsections[$val['product_id']] = $val['content'];
                 }
             }
         }
         /* 初始化默认查询结构体 */
         $query_struct = array('where' => array(), 'like' => array(), 'orderby' => array(), 'limit' => array('per_page' => 100, 'page' => 1));
         do {
             $products = ProductService::get_instance()->query_assoc($query_struct);
             if (is_array($products) && count($products) > 0) {
                 foreach ($products as $key => $value) {
                     $productsearch = ProductsearchService::get_instance()->get_by_product_id($value['id']);
                     $productsearch_data = array();
                     $productsearch_data['product_id'] = $value['id'];
                     $productsearch_data['category_id'] = $value['category_id'];
                     $productsearch_data['brand_id'] = $value['brand_id'];
                     $productsearch_data['title'] = $value['title'];
                     $productsearch_data['brief'] = $value['brief'];
                     if (!empty($productdescsections[$value['id']])) {
                         $productsearch_data['description'] = $productdescsections[$value['id']];
                     }
                     if ($productsearch['id'] > 0) {
                         ProductsearchService::get_instance()->set($productsearch['id'], $productsearch_data);
                     } else {
                         ProductsearchService::get_instance()->add($productsearch_data);
                     }
                 }
                 $query_struct['limit']['page']++;
             } else {
                 break;
             }
         } while (1);
         remind::set(Kohana::lang('o_global.set_success'), '/index/desktop', 'success');
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         if ($this->is_ajax_request()) {
             $this->template->content = $return_struct;
         } else {
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
     }
 }
Пример #3
0
 public function run($products)
 {
     $csv_array = array();
     if ($products) {
         $result = $this->format($products);
         foreach ($result as $classify_id => $products) {
             foreach ($products as $product) {
                 $csv_array[] = $this->get_titlebar($classify_id);
                 //dump($csv_array);
                 //foreach ($products as $product){
                 $product = coding::decode_product($product);
                 $desc = Product_detailService::get_instance()->get_by_product_id($product['id']);
                 $goods = ProductService::get_instance()->query_assoc(array('where' => array('product_id' => $product['id']), 'orderby' => array('default_goods' => 'DESC')));
                 if (!empty($this->arguments)) {
                     $arguments = Product_argumentService::get_instance()->query_row(array('where' => array('product_id' => $product['id'])));
                     $arguments = empty($arguments) ? array() : json_decode($arguments['arguments'], TRUE);
                 }
                 $has_goods = FALSE;
                 $default_good = array();
                 foreach ($goods as $good) {
                     if (!empty($good['attribute_struct']['items'])) {
                         $has_goods = TRUE;
                     }
                     if ($good['default_goods'] == 1) {
                         $default_good = $good;
                         break;
                     }
                 }
                 /*if ($default_good AND $goods)
                 		{
                 			$default_good = $goods[key($goods)];
                 		}*/
                 $p_row = array();
                 $p_row[] = '';
                 $p_row[] = '';
                 $p_row[] = $this->get_category_names($product['category_id']);
                 $p_row[] = $product['sku'];
                 $p_row[] = '';
                 $p_row[] = $product['name_manage'];
                 $p_row[] = $product['title'];
                 $p_row[] = $product['brand_id'] > 0 ? $this->get_brand_name($product['brand_id']) : '';
                 if (!$has_goods) {
                     $p_row[] = $product['on_sale'] == 1 ? 'Y' : 'N';
                     $p_row[] = $product['price'];
                     $p_row[] = $product['market_price'];
                 } else {
                     $p_row[] = '';
                     $p_row[] = '';
                     $p_row[] = '';
                 }
                 $p_row[] = '';
                 // 商品图片
                 /**
                  * 处理商品规格
                  */
                 if ($has_goods) {
                     /*$attribute_option_ids = $product['argumrs_struct_default']['items'];
                     		$same_attributes = TRUE;
                     		if (count($this->attributes) == count($attribute_option_ids))
                     		{
                     			foreach ($this->attributes as $attribute)
                     			{
                     				if (!isset($attribute_option_ids[$attribute['id']]))
                     				{
                     					$same_attributes = FALSE;
                     					break;
                     				}
                     			}
                     		} else {
                     			$same_attributes = FALSE;
                     		}
                     		if ($same_attributes == TRUE)
                     		{
                     			$attributes = $this->attributes;
                     			$p_row[] = '';
                     		} else {
                     			$attributes = AttributeService::get_instance()->get_attribute_options(array(
                     				'where' => array(
                     					'id' => array_keys($attribute_option_ids),
                     				),
                     				'orderby' => array(
                     					'id' => 'ASC',
                     				),
                     			));*/
                     $attribute_names = '';
                     foreach ($this->attributes as $attribute) {
                         if (!empty($attribute_names)) {
                             $attribute_names .= '|';
                         }
                         $attribute_names .= $attribute['name'];
                     }
                     $p_row[] = '规格:' . $attribute_names;
                     //}
                 } else {
                     $p_row[] = '';
                 }
                 $p_row[] = $product['brief'];
                 /**
                  * 处理商品的详细描述
                  */
                 if ($desc) {
                     $p_row[] = $desc['description'];
                 } else {
                     $p_row[] = '';
                 }
                 /**
                  * 处理商品的成本、库存、重量,当商品有规格时,在商品行不显示此三项信息
                  */
                 if (!$has_goods) {
                     $p_row[] = $product['cost'];
                     $p_row[] = $product['store'];
                     $p_row[] = empty($default_good) ? '0' : $default_good['weight'];
                 } else {
                     $p_row[] = '';
                     $p_row[] = '';
                     $p_row[] = '';
                 }
                 $p_row[] = $desc['meta_title'];
                 $p_row[] = $desc['meta_keywords'];
                 $p_row[] = $desc['meta_description'];
                 /**
                  * 处理货品与特性的关联
                  */
                 $feature_option_ids = empty($product['product_featureoption_relation_struct']['items']) ? array() : $product['product_featureoption_relation_struct']['items'];
                 foreach ($this->features as $feature) {
                     if (isset($feature_option_ids[$feature['id']])) {
                         $p_row[] = $feature['options'][$feature_option_ids[$feature['id']]]['name'];
                     } else {
                         $p_row[] = '';
                     }
                 }
                 foreach ($this->arguments as $argument_group) {
                     foreach ($argument_group['items'] as $argument) {
                         if (isset($arguments[$argument_group['name']]) and isset($arguments[$argument_group['name']][$argument['name']])) {
                             $p_row[] = $arguments[$argument_group['name']][$argument['name']];
                         } else {
                             $p_row[] = '';
                         }
                     }
                 }
                 $csv_array[] = $p_row;
                 /**
                  * 处理货品
                  */
                 if ($has_goods) {
                     foreach ($goods as $good) {
                         $is_err = FALSE;
                         $good = coding::decode_good($good);
                         $g_row = array();
                         $g_row[] = '';
                         $g_row[] = '';
                         $g_row[] = '';
                         $g_row[] = '';
                         $g_row[] = $good['sku'];
                         $g_row[] = '';
                         $g_row[] = $good['title'];
                         $g_row[] = '';
                         $g_row[] = $good['on_sale'] == 1 ? 'Y' : 'N';
                         $g_row[] = $good['price'];
                         $g_row[] = $good['market_price'];
                         $g_row[] = '';
                         $option_name = '';
                         foreach ($this->attributes as $attribute) {
                             if ($option_name != '') {
                                 $option_name .= '|';
                             }
                             if (!isset($good['argumrs_struct']['items'][$attribute['id']])) {
                                 $is_err = TRUE;
                                 log::write('product_import_data_error', print_r($product, true), __FILE__, __LINE__);
                             } else {
                                 $option_id = $good['argumrs_struct']['items'][$attribute['id']];
                                 $option_name .= $attribute['options'][$option_id]['name'];
                             }
                         }
                         $g_row[] = $option_name;
                         if ($is_err == TRUE) {
                             break;
                         }
                         $g_row[] = '';
                         $g_row[] = '';
                         $g_row[] = $good['cost'];
                         $g_row[] = $good['store'];
                         $g_row[] = $good['weight'];
                         $g_row[] = '';
                         $g_row[] = '';
                         $g_row[] = '';
                         foreach ($this->features as $feature) {
                             $g_row[] = '';
                         }
                         foreach ($this->arguments as $argument_group) {
                             foreach ($argument_group['items'] as $argument) {
                                 $g_row[] = '';
                             }
                         }
                         $csv_array[] = $g_row;
                     }
                 }
                 //}
             }
         }
     }
     return $csv_array;
 }
Пример #4
0
 /**
  * 更新商品SEO信息
  */
 public function index()
 {
     $site = Mysite::instance()->get();
     if ($_POST) {
         // 收集请求数据
         $domain = $this->input->post('domain');
         $category_id = $this->input->post('category_id');
         $is_children = $this->input->post('is_children');
         $meta_title = $this->input->post('meta_title');
         $meta_keywords = $this->input->post('meta_keywords');
         $meta_description = $this->input->post('meta_description');
         if (empty($domain) || $domain != $site['domain']) {
             remind::set(Kohana::lang('o_site.seo_domain_cannot_null'), 'site/seo_manage', 'error');
         }
         //分类ID数组
         $category_ids = array();
         //分类ID和名称的对应关系
         $category_names = array();
         //分类id不为空
         if ($category_id > 0) {
             $category = CategoryService::get_instance()->get($category_id);
             //先处理选择分类的信息
             $result = Seo_manageService::get_instance()->get_by_category_id($category_id);
             $set_data = array('category_id' => $category_id, 'is_children' => $is_children, 'meta_title' => $meta_title, 'meta_keywords' => $meta_keywords, 'meta_description' => $meta_description);
             if (isset($result) && $result['id'] > 0) {
                 $set_data['update_timestamp'] = date('Y-m-d H:i:s', time());
                 Seo_manageService::get_instance()->set($result['id'], $set_data);
             } else {
                 Seo_manageService::get_instance()->add($set_data);
             }
             //包含子分类
             if ($is_children == Seo_manageService::SEO_CATEGORY_IS_CHILDREN) {
                 //得到分类下的子分类
                 $childrens = CategoryService::get_instance()->get_childrens_by_category_id($category_id);
                 foreach ($childrens as $key => $value) {
                     //记录更新过的分类ID
                     $category_ids[] = $value;
                     $category_child = CategoryService::get_instance()->get($value);
                     $category_names[$value] = $category_child['title'];
                     //查看分类信息已经存在的SEO信息
                     $result_child = Seo_manageService::get_instance()->get_by_category_id($value);
                     $set_data = array('category_id' => $value, 'is_children' => Seo_manageService::SEO_CATEGORY_IS_CHILDREN, 'meta_title' => $meta_title, 'meta_keywords' => $meta_keywords, 'meta_description' => $meta_description);
                     if (isset($result_child) && $result_child['id'] > 0) {
                         $set_data['update_timestamp'] = date('Y-m-d H:i:s', time());
                         Seo_manageService::get_instance()->set($result_child['id'], $set_data);
                     } else {
                         Seo_manageService::get_instance()->add($set_data);
                     }
                 }
                 $category_ids[] = $category_id;
                 $category_names[$category_id] = $category['title'];
                 // 初始化默认查询条件[商品表]
                 $reqeust_query_struct = array('where' => array('category_id' => $category_ids));
             } else {
                 $category_names[$category_id] = $category['title'];
                 $reqeust_query_struct = array('where' => array('category_id' => $category_id));
             }
         } else {
             //没有选择分类,默认更新全部分类
             $result = Seo_manageService::get_instance()->get_by_category_id(Seo_manageService::SEO_CATEGORY_IS_NULL);
             $set_data = array('is_children' => Seo_manageService::SEO_CATEGORY_IS_CHILDREN, 'meta_title' => $meta_title, 'meta_keywords' => $meta_keywords, 'meta_description' => $meta_description);
             if (isset($result['id']) && $result['id'] > 0) {
                 $set_data['update_timestamp'] = date('Y-m-d H:i:s', time());
                 Seo_manageService::get_instance()->set($result['id'], $set_data);
             } else {
                 Seo_manageService::get_instance()->add($set_data);
             }
             //得到站点所有分类
             $categories = CategoryService::get_instance()->get_categories();
             foreach ($categories as $cate_key => $cate_value) {
                 if ($cate_value['id'] <= 0) {
                     continue;
                 }
                 $category_ids[] = $cate_value['id'];
                 $category_names[$cate_value['id']] = $cate_value['title'];
                 $result = Seo_manageService::get_instance()->get_by_category_id($cate_value['id']);
                 $set_data = array('category_id' => $cate_value['id'], 'is_children' => Seo_manageService::SEO_CATEGORY_IS_CHILDREN, 'meta_title' => $meta_title, 'meta_keywords' => $meta_keywords, 'meta_description' => $meta_description, 'update_timestamp' => date('Y-m-d H:i:s', time()));
                 if (isset($result['id']) && $result['id'] > 0) {
                     Seo_manageService::get_instance()->set($result['id'], $set_data);
                 } else {
                     $set_data['create_timestamp'] = date('Y-m-d H:i:s', time());
                     Seo_manageService::get_instance()->add($set_data);
                 }
             }
             $reqeust_query_struct = array('where' => array('category_id' => $category_ids));
         }
         //获得总数
         $count = ProductService::get_instance()->count($reqeust_query_struct);
         if ($count < 10000) {
             $products = ProductService::get_instance()->query_assoc($reqeust_query_struct);
             foreach ($products as $key => $value) {
                 $product_name = $value['title'];
                 $category_name = isset($category_names[$value['category_id']]) ? $category_names[$value['category_id']] : '';
                 $site_domain = $site['domain'];
                 $goods_price = isset($value['goods_price']) ? $value['goods_price'] : 0;
                 $title = str_replace('{product_name}', $product_name, $meta_title);
                 $keywords = str_replace('{product_name}', $product_name, $meta_keywords);
                 $description = str_replace('{product_name}', $product_name, $meta_description);
                 $title = str_replace('{category_name}', $category_name, $title);
                 $keywords = str_replace('{category_name}', $category_name, $keywords);
                 $description = str_replace('{category_name}', $category_name, $description);
                 $title = str_replace('{site_domain}', $site_domain, $title);
                 $keywords = str_replace('{site_domain}', $site_domain, $keywords);
                 $description = str_replace('{site_domain}', $site_domain, $description);
                 $title = str_replace('{price}', $goods_price, $title);
                 $keywords = str_replace('{price}', $goods_price, $keywords);
                 $description = str_replace('{price}', $goods_price, $description);
                 $data = array('meta_title' => $title, 'meta_keywords' => $keywords, 'meta_description' => $description);
                 Product_detailService::get_instance()->set_by_product_id($value['id'], $data);
             }
             remind::set(Kohana::lang('o_global.update_success'), 'site/seo_manage', 'success');
         } else {
             remind::set(Kohana::lang('o_site.product_request_check'), 'site/seo_manage');
         }
     }
     //没有选择分类,默认更新全部分类
     $data = Seo_manageService::get_instance()->get_by_category_id(Seo_manageService::SEO_CATEGORY_IS_NULL);
     // 分类列表默认关联第一个
     $categorys_tree = CategoryService::get_instance()->get_tree('<option value={$id} {$selected}>{$spacer}{$title}</option>');
     $this->template->content = new View("site/update_product_seo");
     $this->template->content->data = $data;
     $this->template->content->site = $site;
     $this->template->content->categorys_tree = $categorys_tree;
 }