Exemple #1
0
 /**
  * 显示编辑商品表单
  */
 public function edit()
 {
     // 初始化返回结构体
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         // 初始化返回数据
         $return_data = array();
         // 收集请求数据
         $request_data = $this->input->get();
         if (empty($request_data['id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400);
         }
         $product = BLL_Product::get($request_data['id']);
         if (empty($product['id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400);
         }
         // 分类列表默认关联第一个
         $categorys_tree = CategoryService::get_instance()->get_tree("<option value=\\\"\$id\\\" \$selected>\$spacer\$title</option>", $product['category_id']);
         $categories = CategoryService::get_instance()->query_assoc(array());
         $categories = tree::get_tree_array($categories);
         $classifies = ClassifyService::get_instance()->index(array('orderby' => array('id' => 'ASC')));
         $classify_content['features'] = $this->load_features($product['classify_id'], $product['fetuoptrs']);
         $classify_content['brands'] = $this->load_brands($product['classify_id'], $product['brand_id']);
         // 处理商品类型特定的模板区块
         $ptype_layout = NULL;
         switch ($product['type']) {
             case ProductService::PRODUCT_TYPE_ASSEMBLY:
                 throw new MyRuntimeException('Coming soon ...', 400);
                 //暂时不支持组合商品
                 $ptype_layout = new View($this->package_name . '/' . $this->class_name . '/assembly/layout');
                 break;
             case ProductService::PRODUCT_TYPE_CONFIGURABLE:
                 $ptype_layout = new View($this->package_name . '/' . $this->class_name . '/configurable/layout');
                 break;
             case ProductService::PRODUCT_TYPE_GOODS:
             default:
                 $ptype_layout = new View($this->package_name . '/' . $this->class_name . '/simple/layout');
                 break;
         }
         $ptype_layout->product = $product;
         $return_struct['content'] = array('product' => $product);
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View($this->package_name . '/' . $this->class_name . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
             $this->template->content->categorys_tree = $categorys_tree;
             $this->template->content->categories = $categories;
             $this->template->content->classifies = $classifies;
             $this->template->content->classify_content = $classify_content;
             $this->template->content->ptype_layout = $ptype_layout;
             $this->template->content->listurl = isset($request_data['listurl']) ? $request_data['listurl'] : '';
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }
Exemple #2
0
 function get_category_data()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //$profiler = new Profiler;
         //* 初始化返回数据 */
         $return_data = array('classify' => array(), 'brand_list' => array(), 'attribute_list' => array(), 'feature_list' => array());
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         //必须为ajax请求
         if (!$this->is_ajax_request()) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         //数据验证
         if (!isset($request_data['category_id']) || !is_numeric($request_data['category_id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.input_error'), 404);
         }
         if ($request_data['category_id'] == 0) {
             //当前站点品牌
             $return_data['brand_list'] = BrandService::get_instance()->get_brands();
             //当前站点规格
             $return_data['attribute_list'] = AttributeService::get_instance()->get_attribute_spec_options();
             //当前站点品牌
             $return_data['feature_list'] = AttributeService::get_instance()->get_attribute_feature_options();
         } else {
             // 调用底层服务
             $category_service = CategoryService::get_instance();
             $classify_service = ClassifyService::get_instance();
             //获取数据
             $category = $category_service->get($request_data['category_id']);
             if ($category['classify_id']) {
                 $return_data['classify'] = $classify_service->get($category['classify_id']);
                 //获取关联品牌数组
                 $return_data['brand_list'] = $classify_service->get_brands_by_classify_id($category['classify_id']);
                 //获取关联规格及规格项数组
                 $return_data['attribute_list'] = $classify_service->get_attribute_options_by_classify_id($category['classify_id'], AttributeService::ATTRIBUTE_SPEC);
                 //获取关联特性及特性值数组
                 $return_data['feature_list'] = $classify_service->get_attribute_options_by_classify_id($category['classify_id'], AttributeService::ATTRIBUTE_FEATURE);
             }
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         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;
         }
     }
 }
Exemple #3
0
 protected function parse_titlebar($l)
 {
     $this->titlebar = array();
     foreach ($l as $i => $item) {
         $item = trim($item);
         $position = strpos($item, ':');
         if ($position !== FALSE) {
             $type = trim(substr($item, 0, $position));
             $value = trim(substr($item, $position + 1));
             switch ($type) {
                 case '类型':
                     if (empty($value)) {
                         $this->set_error(new MyRuntimeException('商品类型名称不可为空'));
                     }
                     if ($value == ClassifyService::DEFAULT_CLASSIFY_NAME) {
                         $this->classify_id = 0;
                         $this->classify_name = ClassifyService::DEFAULT_CLASSIFY_NAME;
                         $this->attributes = array();
                         $this->features = array();
                         $this->arguments = array();
                     } else {
                         $classify = ClassifyService::get_instance()->query_row(array('where' => array('name' => $value)));
                         if (empty($classify)) {
                             $this->set_error(new MyRuntimeException(sprintf('未找到名称为 "%s" 的商品类型', $value)));
                         }
                         $this->classify_id = $classify['id'];
                         $this->classify_name = $classify['name'];
                         if (!empty($classify['argument_relation_struct'])) {
                             $this->arguments = json_decode($classify['argument_relation_struct'], TRUE);
                         }
                         try {
                             $this->attributes = array();
                             foreach ((array) ClassifyService::get_instance()->get_attribute_options_by_classify_id($classify['id'], 1) as $item) {
                                 $this->attributes[] = $item;
                             }
                         } catch (MyRuntimeException $ex) {
                             $this->set_error($ex);
                         }
                         try {
                             $this->features = ClassifyService::get_instance()->get_attribute_options_by_classify_id($classify['id'], 0);
                         } catch (MyRuntimeException $ex) {
                             $this->set_error($ex);
                         }
                     }
                     break;
                 case '字段':
                     $value = strtoupper($value);
                     if (isset($this->columns[$value])) {
                         $this->titlebar[$this->columns[$value]] = $i;
                     } else {
                         $this->set_error(new MyRuntimeException(sprintf('未找到名称为 "%s" 的字段', $value)));
                     }
                     break;
                 case '规格':
                     $this->titlebar['attributes'] = $i;
                     break;
                 case '特性':
                     if ($this->classify_id > 0) {
                         if (!isset($this->titlebar['features'])) {
                             $this->titlebar['features'] = array();
                         }
                         $fsearch = FALSE;
                         foreach ($this->features as $feature) {
                             if (strtoupper($feature['name_manage']) === strtoupper($value)) {
                                 $this->titlebar['features'][$feature['id']] = $i;
                                 $fsearch = TRUE;
                                 break;
                             }
                         }
                         if ($fsearch === FALSE) {
                             $this->set_error(new MyRuntimeException(sprintf('商品类型 "%s" 下未关联名称为 "%s" 的特性', $this->classify_name, $value)));
                         }
                     } else {
                         $this->set_error(new MyRuntimeException(sprintf('"%s" 下不进行任何特性关联,却意外的找到了名称为 "%s" 的特性', ClassifyService::DEFAULT_CLASSIFY_NAME, $value)));
                     }
                     break;
                 case '参数':
                     if ($this->classify_id > 0) {
                         if (!isset($this->titlebar['arguments'])) {
                             $this->titlebar['arguments'] = array();
                         }
                         if (strpos($value, '->')) {
                             $value = explode('->', $value);
                             $value[0] = trim($value[0]);
                             $value[1] = trim($value[1]);
                             $gsearch = FALSE;
                             foreach ($this->arguments as $argument_group) {
                                 if ($argument_group['name'] === $value[0]) {
                                     $gsearch = TRUE;
                                     break;
                                 }
                             }
                             if ($gsearch === TRUE) {
                                 $asearch = FALSE;
                                 foreach ($argument_group['items'] as $argument) {
                                     if ($argument['name'] === $value[1]) {
                                         $this->titlebar['arguments'][$argument_group['name'] . '->' . $argument['name']] = $i;
                                         $asearch = TRUE;
                                         break;
                                     }
                                 }
                                 if ($asearch === FALSE) {
                                     $this->set_error(new MyRuntimeException(sprintf('参数组 "%s" 下未找到名称为 "%s" 的参数', $argument_group['name_manage'], $value[1])));
                                 }
                             } else {
                                 $this->set_error(new MyRuntimeException(sprintf('商品类型 "%s" 下未找到名称为 "%s" 的特性组', $this->classify_name, $value[0])));
                             }
                         } else {
                             $this->set_error(new MyRuntimeException(sprintf('错误的参数关联格式:"%s",参数组名称与参数名称之间使用 "->" 符号分割', $value)));
                         }
                     } else {
                         $this->set_error(new MyRuntimeException(sprintf('商品分类 "%s" 下不进行任何参数关联,却意外的找到了名称为 "%s" 的参数', ClassifyService::DEFAULT_CLASSIFY_NAME, $value)));
                     }
                     break;
             }
         } elseif ($item !== '') {
             $this->set_error(new MyRuntimeException(sprintf('标题解析失败:"%s"', $item)));
         }
     }
 }
Exemple #4
0
 public function product_as_template()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array('assoc' => NULL, 'count' => 0);
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         $site_ids = role::get_site_ids();
         if (empty($site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         $in_site_id = site::id();
         if (isset($request_data['site_id']) and $request_data['site_id'] === '0') {
             unset($request_data['site_id']);
         }
         if (isset($request_data['site_id']) and !in_array($request_data['site_id'], $site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         if ($in_site_id > 0) {
             $query_site_id = $in_site_id;
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.select_site'), 400);
         }
         $product = BLL_Product::get($request_data['product_id']);
         $classify = ClassifyService::get_instance()->index(array('where' => array('site_id' => $query_site_id, 'id' => $product['classify_id'])));
         $product['classify_name'] = isset($classify[0]['name']) ? $classify[0]['name'] : '通用商品类型';
         $category = CategoryService::get_instance()->index(array('where' => array('site_id' => $query_site_id, 'id' => $product['category_id'])));
         $product['category_name'] = isset($category[0]['name']) ? $category[0]['name'] : '通用商品分类';
         $brand = BrandService::get_instance()->index(array('where' => array('site_id' => $query_site_id, 'id' => $product['brand_id'])));
         $product['brand_name'] = isset($brand[0]['name']) ? $brand[0]['name'] : '通用商品分类';
         if (!empty($product['fetuoptrs'])) {
             $string = '';
             $arr = BLL_Product_Feature::get_clsfeturs($product['classify_id']);
             foreach ($product['fetuoptrs'] as $key => $value) {
                 $string .= $arr[$key]['name_manage'] . ':' . $arr[$key]['options'][$value]['name_manage'] . '&nbsp;&nbsp;&nbsp;';
             }
             if ($string != '') {
                 $product['fetuoptrs_v'] = $string;
             }
         } else {
             $product['fetuoptrs_v'] = '没有设置商品特性';
         }
         if ($product['site_id'] != $query_site_id) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         if (Product_templateService::get_instance()->is_template_exist($query_site_id)) {
             $template = Product_templateService::get_instance()->get_template_by_site($query_site_id);
             $classify = ClassifyService::get_instance()->index(array('where' => array('site_id' => $query_site_id, 'id' => $template['classify_id'])));
             $template['classify_name'] = isset($classify[0]['name']) ? $classify[0]['name'] : '通用商品类型';
             $category = CategoryService::get_instance()->index(array('where' => array('site_id' => $query_site_id, 'id' => $template['category_id'])));
             $template['category_name'] = isset($category[0]['name']) ? $category[0]['name'] : '通用商品分类';
             $brand = BrandService::get_instance()->index(array('where' => array('site_id' => $query_site_id, 'id' => $template['brand_id'])));
             $template['brand_name'] = isset($brand[0]['name']) ? $brand[0]['name'] : '无';
             $template['fetuoptrs'] = json_decode($template['product_featureoption_relation_struct']);
             if (!empty($template['fetuoptrs'])) {
                 $string = '';
                 $arr = BLL_Product_Feature::get_clsfeturs($template['classify_id']);
                 foreach ($template['fetuoptrs']->items as $key => $value) {
                     if (isset($arr[$key])) {
                         $string .= $arr[$key]['name_manage'] . ':' . $arr[$key]['options'][$value]['name_manage'] . '&nbsp;&nbsp;&nbsp;';
                     }
                 }
                 if ($string != '') {
                     $template['fetuoptrs_v'] = $string;
                 }
             } else {
                 $template['fetuoptrs_v'] = '没有设置商品特性';
             }
         } else {
             $template = array();
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             $this->template = new View('layout/commonblank_html');
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View($this->package_name . '/' . $this->class_name . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->product = $product;
             $this->template->content->template = $template;
             //:: 当前应用专用数据
             $this->template->content->title = Kohana::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         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;
         }
     }
 }
Exemple #5
0
 public function edit()
 {
     role::check('product_category_edit');
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array('action' => 'post');
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         //数据验证
         if (!isset($request_data['id']) || !is_numeric($request_data['id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.input_error'), 404);
         }
         $category_service = CategoryService::get_instance();
         $category = $category_service->get($request_data['id']);
         //返回数据
         //$category['pic_url'] = AttributeService::get_attach_url($category['pic_attach_id'], 't');
         $category['pic_url'] = AttService::get_instance($this->img_dir_name)->get_img_url($category['pic_attach_id']);
         $return_data['data'] = $category;
         //uri_name处理
         $route = Myroute::instance()->get();
         $route_type = $route['type'];
         $category_route = $route['category'];
         $category_suffix = $route['category_suffix'];
         if ($route_type == 0) {
             // 0: none  get category and product with id
             $category_permalink = $category_route . '/' . $category['id'];
         } else {
             if ($route_type == 1) {
                 // 1: get  product with {product}/permalink
                 $category_permalink = $category_route . '/';
             } else {
                 if ($route_type == 2 || $route_type == 4) {
                     // 2: get category and product with {category_permalink}  and {category+permalink}/{product_permalink}
                     $category_permalink = '';
                 } else {
                     if ($route_type == 3) {
                         // 3: get category and prdouct with {category_permalink1}/.../{category_permalinkn} and {category_permalink1}/.../{category_permalinkn}/{product_permalink}
                         $parents = $category_service->get_parents_by_category_id($category['id']);
                         $category_permalink = '';
                         $i = 1;
                         foreach ($parents as $val) {
                             if ($i != 1) {
                                 $category_permalink = urlencode($val['uri_name']) . '/' . $category_permalink;
                             }
                             $i++;
                         }
                     }
                 }
             }
         }
         //当前站点分类
         $categories = $category_service->get_categories();
         $child_ids = $category_service->get_childrens_by_category_id($category['id']);
         $parent_data = $category_service->get_parents_by_category_id($category['id']);
         $parent_is_show = isset($parent_data[1]) ? $parent_data[1]['is_show'] : 1;
         //去掉子分类和自己
         foreach ($categories as $key => $val) {
             if (in_array($val['id'], $child_ids) || $val['id'] == $category['id']) {
                 unset($categories[$key]);
             }
         }
         $str = '<option value={$id} {$selected}>{$spacer}{$title}</option>';
         //$return_data['category_list'] = $category_service->get_tree_by_site_id($request_data['site_id'], '<option value={$id} {$selected}>{$spacer}{$title}</option>',$category['pid']);
         $return_data['category_list'] = tree::get_tree($categories, $str, 0, $category['pid']);
         //当前站点类型
         $classify = ClassifyService::get_instance()->get_classifies();
         $return_data['classify_list'] = '';
         foreach ($classify as $val) {
             $selected = $category['classify_id'] == $val['id'] ? 'selected' : '';
             $return_data['classify_list'] .= '<option value=' . $val['id'] . ' ' . $selected . '>--' . $val['name'] . '--</option>';
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             //* 模板输出 */
             $content = new View($this->package . '/' . $this->class_name . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
             //:: 当前应用专用数据
             $this->template->content->has_child = count($child_ids);
             $this->template->content->parent_is_show = $parent_is_show;
             $this->template->content->route_type = $route_type;
             $this->template->content->category_suffix = $category_suffix;
             $this->template->content->category_permalink = $category_permalink;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex(&$ex, $return_struct, $request_data);
     }
 }
Exemple #6
0
 public function validate()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array('assoc' => NULL, 'count' => 0);
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         $site_ids = role::get_site_ids();
         if (empty($site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         if (empty($request_data['classify_id'])) {
             throw new MyRuntimeException('请首先选择商品类型', 403);
         }
         if (empty($request_data['merges'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         $classify = ClassifyService::get_instance()->get($request_data['classify_id']);
         $features = BLL_Product_Feature::get_clsfeturs($classify['id']);
         if (empty($features) or empty($request_data['mfids']) or !is_array($request_data['mfids'])) {
             throw new MyRuntimeException('未找到任何可供合并的特性', 403);
         }
         foreach ($request_data['mfids'] as $mfid) {
             if (!isset($features[$mfid])) {
                 throw new MyRuntimeException('所设置的合并特性未找到', 403);
             }
         }
         $merges = array();
         $fetuoptrs = array();
         foreach ($request_data['merges'] as $index => $merge) {
             if (isset($merge['id']) and isset($merge['sku'])) {
                 try {
                     $merges[$index] = BLL_Product::get($merge['id']);
                 } catch (MyRuntimeException $ex) {
                     throw new MyRuntimeException(sprintf('参与合并的商品 #%s 未找到', $index), 403);
                 }
                 if ($merges[$index]['classify_id'] != $classify['id']) {
                     throw new MyRuntimeException(sprintf('参与合并的商品 #%s 不属于商品类型 “%s”', $index, $classify['name']));
                 }
                 // 验证合并商品的SKU
                 if (BLL_Product::sku_exists($classify['site_id'], $merge['sku'], $merges[$index]['id'])) {
                     throw new MyRuntimeException(sprintf('参与合并的商品 #%s 与其他商品的SKU重复', $index), 403);
                 }
                 // 验证是否包含要合并的特性值
                 if (empty($merges[$index]['fetuoptrs'])) {
                     $merges[$index]['fetuoptrs'] = array();
                 }
                 $fetuoptr = array();
                 foreach ($request_data['mfids'] as $mfid) {
                     if (!isset($merges[$index]['fetuoptrs'][$mfid])) {
                         throw new MyRuntimeException(sprintf('参与合并的商品 #%s 未设置特性 "%s" 的值', $index, $features[$mfid]['name_manage']));
                     }
                     if (!isset($fetuoptr)) {
                         $fetuoptrs[$index] = array();
                     }
                     $fetuoptr[$mfid] = $merges[$index]['fetuoptrs'][$mfid];
                 }
                 foreach ($fetuoptrs as $k => $item) {
                     if ($item == $fetuoptr) {
                         throw new MyRuntimeException(sprintf('参与合并的商品 #%s 特性设置与商品 #%s 相同', $index, $k), 403);
                     }
                 }
                 $fetuoptrs[$index] = $fetuoptr;
             } else {
                 throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
             }
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             //* html 输出 ==根据业务逻辑定制== */
             $this->template = new View('layout/commonfix_html');
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View($this->package_name . '/product/merge/list');
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             $this->template->content->request_struct = $request_struct_current;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
             //:: 当前应用专用数据
             $this->template->content->title = Kohana::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         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;
         }
     }
 }
Exemple #7
0
 public function get_titlebar($classify_id)
 {
     try {
         if ($classify_id == 0) {
             $classify_name = ClassifyService::DEFAULT_CLASSIFY_NAME;
             $attributes = array();
             $features = array();
         } else {
             $classify = ClassifyService::get_instance()->get($classify_id);
             $classify_name = $classify['name'];
             $attributes = ClassifyService::get_instance()->get_attribute_options_by_classify_id($classify_id, AttributeService::ATTRIBUTE_SPEC);
             $features = ClassifyService::get_instance()->get_attribute_options_by_classify_id($classify_id, AttributeService::ATTRIBUTE_FEATURE);
         }
         $titlebar = array();
         $titlebar[] = '类型:' . $classify_name;
         $titlebar[] = '字段:分类';
         $titlebar[] = '字段:商品SKU';
         $titlebar[] = '字段:货品SKU';
         $titlebar[] = '字段:管理名称';
         $titlebar[] = '字段:商品名称';
         $titlebar[] = '字段:所属品牌';
         $titlebar[] = '字段:上下架';
         $titlebar[] = '字段:价格';
         $titlebar[] = '字段:市场价格';
         $titlebar[] = '字段:商品图片';
         if ($attributes) {
             $titlebar[] = '规格:';
         } else {
             $attribute_names = '';
             foreach ($attributes as $attribute) {
                 if (!empty($attribute_names)) {
                     $attribute_names .= '|';
                 }
                 $attribute_names .= $attribute['name'];
             }
             $titlebar[] = '规格:' . $attribute_names;
         }
         $titlebar[] = '字段:简介';
         $titlebar[] = '字段:详细描述';
         $titlebar[] = '字段:成本价格';
         $titlebar[] = '字段:库存';
         $titlebar[] = '字段:重量';
         $titlebar[] = '字段:META标题';
         $titlebar[] = '字段:META关键字';
         $titlebar[] = '字段:META描述';
         foreach ($features as $feature) {
             $titlebar[] = '特性:' . $feature['name'];
         }
         if (isset($classify) and !empty($classify['argument_relation_struct'])) {
             $classify['argument_relation_struct'] = json_decode($classify['argument_relation_struct'], TRUE);
             foreach ($classify['argument_relation_struct'] as $argument_group) {
                 $argument_name = '参数:' . $argument_group['name'];
                 foreach ((array) $argument_group['items'] as $argument) {
                     $titlebar[] = $argument_name . '->' . $argument['name'];
                 }
             }
             $this->arguments = $classify['argument_relation_struct'];
         }
         $this->attributes = $attributes;
         $this->features = $features;
         return $titlebar;
     } catch (MyRuntimeException $ex) {
         throw new MyRuntimeException(sprintf('创建标题栏失败:%s', $ex->getMessage()));
     }
 }
Exemple #8
0
 /**
  * 通过商品类型ID获取商品类型所关联的商品参数
  *
  * @param integer $classify_id
  * @return array
  */
 public static function get_clsargurs($classify_id)
 {
     $arguments = array();
     if ($classify_id > 0) {
         try {
             $classify = ClassifyService::get_instance()->get($classify_id);
             $arguments = json_decode($classify['argument_relation_struct'], TRUE);
             $arguments or $arguments = array();
         } catch (MyRuntimeException $ex) {
             return $arguments;
         }
     }
     return $arguments;
 }
Exemple #9
0
 /**
  * 获取商品列表
  *
  * @param array $query_struct
  * @return array
  */
 public static function index($query_struct)
 {
     $products = ProductService::get_instance()->index($query_struct);
     if (isset($query_struct['where']['sku'])) {
         $add_struct = array('where' => array());
         $add_struct['where']['sku'] = $query_struct['where']['sku'];
         if (isset($query_struct['where']['on_sale'])) {
             $add_struct['where']['on_sale'] = $query_struct['where']['on_sale'];
         }
         if (!empty($add_struct['where'])) {
             $goods = ProductService::get_instance()->index($add_struct);
             if (!empty($goods)) {
                 $add_ids = array();
                 $pdt_ids = array();
                 foreach ($products as $product) {
                     $pdt_ids[$product['id']] = TRUE;
                 }
                 foreach ($goods as $good) {
                     if (!isset($pdt_ids[$good['product_id']])) {
                         $add_ids[] = $good['product_id'];
                         $pdt_ids[$good['product_id']] = TRUE;
                     }
                 }
                 if (!empty($add_ids)) {
                     $add_pdts = ProductService::get_instance()->index(array('where' => array('id' => $add_ids)));
                     foreach ($add_pdts as $product) {
                         $products[] = $product;
                     }
                 }
             }
         }
     }
     $category_ids = array();
     $classify_ids = array();
     $brand_ids = array();
     foreach ($products as $product) {
         $product['category_id'] > 0 and $category_ids[$product['category_id']] = TRUE;
         $product['classify_id'] > 0 and $classify_ids[$product['classify_id']] = TRUE;
         $product['brand_id'] > 0 and $brand_ids[$product['brand_id']] = TRUE;
     }
     $category_ids = array_keys($category_ids);
     $classify_ids = array_keys($classify_ids);
     $brand_ids = array_keys($brand_ids);
     $categorys = array();
     if (!empty($category_ids)) {
         foreach (CategoryService::get_instance()->index(array('where' => array('id' => $category_ids))) as $category) {
             $categorys[$category['id']] = $category;
         }
     }
     $classifys = array();
     if (!empty($classify_ids)) {
         foreach (ClassifyService::get_instance()->index(array('where' => array('id' => $classify_ids))) as $classify) {
             $classifys[$classify['id']] = $classify;
         }
     }
     $brands = array();
     if (!empty($brand_ids)) {
         foreach (BrandService::get_instance()->index(array('where' => array('id' => $brand_ids))) as $brand) {
             $brands[$brand['id']] = $brand;
         }
     }
     foreach ($products as $index => $product) {
         $product = coding::decode_product($product);
         isset($categorys[$product['category_id']]) and $product['category'] = $categorys[$product['category_id']];
         isset($classifys[$product['classify_id']]) and $product['classify'] = $classifys[$product['classify_id']];
         isset($brands[$product['brand_id']]) and $product['brand'] = $brands[$product['brand_id']];
         $product['name_manage'] || ($product['name_manage'] = $product['title']);
         $product['category_name'] = isset($product['category']['title_manage']) ? $product['category']['title_manage'] : '';
         $products[$index] = $product;
     }
     return array('assoc' => $products, 'count' => ProductService::get_instance()->count($query_struct));
 }
Exemple #10
0
 public function classifies()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //$profiler = new Profiler;
         //* 初始化返回数据 */
         $return_data = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         //* 实现功能后屏蔽此异常抛出 */
         //throw new MyRuntimeException('Not Implemented',501);
         //* 权限验证 */
         $site_ids = role::get_site_ids();
         if (empty($site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         if (empty($request_data['site_id']) or !in_array($request_data['site_id'], $site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         $classifies = ClassifyService::get_instance()->query_assoc(array('where' => array('site_id' => $request_data['site_id']), 'orderby' => array('id' => 'ASC')));
         $html = '<option value="-1">通用商品类型</option>';
         foreach ($classifies as $classify) {
             $html .= '<option value="' . $classify['id'] . '">' . htmlspecialchars($classify['name']) . '</option>';
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $html;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             throw new MyRuntimeException('Not Implemented');
             // html 输出
             //* 模板输出 */
             $content = new View($this->package . '/' . $this->class_name . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
             //:: 当前应用专用数据
             $this->template->content->site_id = $site_id;
             $this->template->content->sites = $sites;
             $this->template->content->categorys_tree = $categorys_tree;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         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;
         }
     }
 }
Exemple #11
0
 function get_site_data()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //$profiler = new Profiler;
         //* 初始化返回数据 */
         $return_data = array('brand_list' => NULL, 'attribute_list' => NULL, 'feature_list' => NULL);
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         //* 实现功能后屏蔽此异常抛出 */
         //throw new MyRuntimeException('Not Implemented',501);
         //必须为ajax请求
         if (!$this->is_ajax_request()) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         //* 权限验证 */
         $site_id_list = role::check('product_classify', 0, 0);
         if (empty($site_id_list)) {
             throw new MyRuntimeException('Access Denied', 403);
         }
         if (isset($request_data['site_id']) && is_numeric($request_data['site_id'])) {
             if (!in_array($request_data['site_id'], $site_id_list)) {
                 throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
             }
         }
         //数据验证
         if (!isset($request_data['site_id']) || !is_numeric($request_data['site_id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         // 调用底层服务
         $classify_service = ClassifyService::get_instance();
         //请求站点品牌列表
         $brands = BrandService::get_instance()->get_brands_by_site_id($request_data['site_id']);
         foreach ($brands as $val) {
             $return_data['brand_list'] .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>';
         }
         //请求站点规格列表
         $attributes = AttributeService::get_instance()->get_attributes_by_site_id($request_data['site_id']);
         foreach ($attributes as $val) {
             $return_data['attribute_list'] .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>';
         }
         //请求站点规格列表
         $features = FeatureService::get_instance()->get_features_by_site_id($request_data['site_id']);
         foreach ($features as $val) {
             $return_data['feature_list'] .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>';
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             //* 模板输出 */
             $content = new View($this->package . '/' . $this->class_name . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         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;
         }
     }
 }