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'] . ' '; } 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'] . ' '; } } 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; } } }
/** * 加载商品特性模板 * * @param array $features * @param array $relation * @return string */ protected function load_features($classify_id, $relation = array()) { $template = new View($this->package_name . '/' . $this->class_name . '/plugins/classify/feature'); $template->features = BLL_Product_Feature::get_clsfeturs($classify_id); $template->relation = $relation; return trim((string) $template); }
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; } } }