/** * 显示商品列表 */ public function index() { $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(); $request_data['status'] = isset($request_data['status']) ? (int) $request_data['status'] : 0; $struct = product::get_struct($request_data); $query_struct_current = $struct['query']; $query_struct_current['where']['type'] = array(ProductService::PRODUCT_TYPE_GOODS, ProductService::PRODUCT_TYPE_CONFIGURABLE, ProductService::PRODUCT_TYPE_ASSEMBLY); $request_struct_current = $struct['request']; // 每页条目数 controller_tool::request_per_page($query_struct_current, $request_data); $return_data = BLL_Product::index($query_struct_current); // 模板输出 分页 $this->pagination = new Pagination(array('total_items' => $return_data['count'], 'items_per_page' => $query_struct_current['limit']['per_page'])); $query_struct_current['limit']['page'] = $this->pagination->current_page; //* 如果是ajax请求缩减返回的字段 ==根据业务逻辑定制== */ if ($this->is_ajax_request()) { $requestkeys = array('id', 'category_id', 'title', 'store', 'on_sale', 'price', 'sku'); array_walk($return_data['assoc'], 'util::simplify_return_array', $requestkeys); } //* 补充&修改返回结构体 */ $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->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->request_struct = $request_struct_current; $this->template->content->query_struct = $query_struct_current; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } // end of request type determine } catch (MyRuntimeException $ex) { $this->_ex($ex, $return_struct, $request_data); } }
public function index() { $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); } $struct = product::get_struct($request_data, $query_site_id); $query_struct_current = $struct['query']; $request_struct_current = $struct['request']; $query_struct_current['limit']['per_page'] = 1; $return_data = BLL_Product::index($query_struct_current); $products = $return_data['assoc']; $content = new View($this->package_name . '/' . $this->class_name . '/' . __FUNCTION__); $this->template->content = $content; $this->template->content->products = $products; } 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; } } }
public function search_product() { role::check('promotion_promotion'); // 收集请求数据 $request_data = $this->input->get(); $request_data['stype'] = $request_data['type']; $request_data['on_sale'] = 1; $request_data['per_page'] = 6; $struct = product::get_struct($request_data); $query_struct_current = $struct['query']; $request_struct_current = $struct['request']; $request_data['keyword'] && ($query_struct_current['like'][$request_data['stype']] = $request_data['keyword']); $return_data = BLL_Product::index($query_struct_current); $returnData['content'] = $return_data['assoc']; $returnData['page'] = isset($request_struct_current['page']) ? $request_struct_current['page'] : 1; $returnData['count'] = ceil($return_data['count'] / $request_struct_current['per_page']); echo json_encode($returnData); exit; }
public function index() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); //* 初始化返回数据 */ $return_data = array('assoc' => NULL, 'count' => 0); $search_value = isset($request_data['keyword']) ? $request_data['keyword'] : array(); $category_list = array(); $brand_list = array(); $product_ids = array(); $relation_product_ids = array(); $product_id = $request_data['product_id']; $product_service = ProductService::get_instance(); $product = $product_service->get($product_id); $product_id = $product['id']; if (!$product_id > 0) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } else { $struct = product::get_struct($request_data); $query_struct_current = $struct['query']; $request_struct_current = $struct['request']; if ($product['type'] == ProductService::PRODUCT_TYPE_CONFIGURABLE || $product['type'] == ProductService::PRODUCT_TYPE_ASSEMBLY) { $product_id_array = Product_assemblyService::get_instance()->get_good_id_array($product_id); $product_id_array[] = $product_id; } else { $product_id_array = array($product_id); } $query_struct_current['not_in']['id'] = $product_id_array; try { $return_data = BLL_Product::index($query_struct_current); if (!empty($return_data['assoc'])) { // 获取该商品列表中涉及到的分类以及品牌ID $category_ids = array(); $brand_ids = array(); foreach ($return_data['assoc'] as $product) { if ($product['category_id'] != 0) { $category_ids[$product['category_id']] = TRUE; } if ($product['brand_id'] != 0) { $brand_ids[$product['brand_id']] = TRUE; } $product_ids[] = $product['id']; } $query_struct = array('where' => array('product_id' => $product_id)); foreach (Product_relationService::get_instance()->query_assoc($query_struct) as $relation) { if (in_array($relation['relation_product_id'], $product_ids)) { $relation_product_ids[] = $relation['relation_product_id']; } } // 获取分类列表 if (!empty($category_ids)) { $query_struct = array('where' => array('id' => array_keys($category_ids))); $categorys = CategoryService::get_instance()->query_assoc($query_struct); foreach ($categorys as $category) { $category_list[$category['id']] = $category['title_manage'] ? $category['title_manage'] : $category['title']; } } // 获取品牌列表 if (!empty($brand_ids)) { $query_struct = array('where' => array('id' => array_keys($brand_ids))); $brands = BrandService::get_instance()->query_assoc($query_struct); foreach ($brands as $brand) { $brand_list[$brand['id']] = $brand['name']; } } } // 模板输出 分页 $this->pagination = new Pagination(array('total_items' => $return_data['count'], 'items_per_page' => $query_struct_current['limit']['per_page'])); } catch (MyRuntimeException $ex) { //* ==根据业务逻辑定制== */ //FIXME 根据service层的异常做一些对应处理并抛出用户友好的异常Message throw $ex; } } //* 如果是ajax请求缩减返回的字段 ==根据业务逻辑定制== */ if ($this->is_ajax_request()) { $requestkeys = array('id', 'category_id', 'title', 'uri_name', 'store', 'on_sale', 'price', 'sku'); array_walk($return_data['assoc'], 'util::simplify_return_array', $requestkeys); } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $return_data; //exit("<div id=\"do_debug\" style=\"clear:both;display:;\"><pre>\n".var_export($return_struct,TRUE)."\n</pre></div>"); //* 请求类型 */ 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 . '/' . $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->request_struct = $request_struct_current; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; //:: 当前应用专用数据 $this->template->content->title = Kohana::config('site.name'); //$this->template->content->site_list = Mysite::instance()->select_list($site_ids); $this->template->content->category_list = $category_list; $this->template->content->brand_list = $brand_list; $this->template->content->product_id = $product_id; $this->template->content->product_ids = $product_ids; $this->template->content->relation_ids = $relation_product_ids; $this->template->content->keyword = $search_value; } // end of request type determine } catch (MyRuntimeException $ex) { $this->template = new View('layout/commonfix_html'); $this->_ex($ex, $return_struct, $request_data); } }
public function index() { $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(); $struct = product::get_struct($request_data); $query_struct_current = $struct['query']; $request_struct_current = $struct['request']; /* 初始化默认查询结构体 ==根据业务逻辑定制== */ $request_struct_default = array('type' => NULL, 'keyword' => NULL); /* 初始化请求结构体 */ $request_struct_current = array(); /* 设置合并默认请求结构数据到当前请求结构体 */ $request_struct_current = array_merge($request_struct_current, $request_struct_default); /* 初始化默认查询结构体 ==根据业务逻辑定制== */ $query_struct_default = array('where' => array('type' => ProductService::PRODUCT_TYPE_GOODS, 'on_sale' => 1, 'store >' => 0), 'like' => array(), 'orderby' => array('id' => 'DESC'), 'limit' => array('per_page' => Kohana::config('my.items_per_page'), 'page' => 1)); /* 初始化当前查询结构体 */ $query_struct_current = array(); /* 设置合并默认查询条件到当前查询结构体 */ $query_struct_current = array_merge($query_struct_current, $query_struct_default); /* 当前支持的查询业务逻辑 ==根据业务逻辑定制== */ if (isset($request_data['type']) && isset($request_data['keyword']) && !empty($request_data['keyword'])) { switch ($request_data['type']) { case 'sku': $query_struct_current['like'][$request_data['type']] = trim($request_data['keyword']); $request_struct_current['keyword'] = $query_struct_current['like'][$request_data['type']]; /* $query_struct_current['where'][$request_data['type']] = trim($request_data['keyword']); $request_struct_current['keyword'] = $query_struct_current['where'][$request_data['type']]; */ break; case 'title': $query_struct_current['like'][$request_data['type']] = trim($request_data['keyword']); $request_struct_current['keyword'] = $query_struct_current['like'][$request_data['type']]; /* $query_struct_current['where'][$request_data['type']] = trim($request_data['keyword']); $request_struct_current['keyword'] = $query_struct_current['where'][$request_data['type']]; */ break; } $request_struct_current['type'] = $request_data['type']; } /* 当前支持的排序业务逻辑 */ if (isset($request_data['order']) && !empty($request_data['order'])) { /* 如果查询请求中包含了排序条件则覆盖当前的默认排序请求*/ $query_struct_current['orderby'] = array(); //FIXME 目前排序请求采用的是key和value合在一起减少请求参数,以后如果有必要可以分开 if (is_array($request_data['order'])) { foreach ($request_data['order'] as $order_string) { $order_field = substr($order_string, 0, -1); /*预设0为ASC,1为DESC*/ $order_sort = intval(substr($order_string, -1, 1)); $query_struct_current['orderby'][$order_field] = $order_sort == 0 ? 'ASC' : 'DESC'; } } else { $order_string = trim($request_data['order']); $order_field = substr($order_string, 0, -1); /* 预设0为ASC,1为DESC*/ $order_sort = intval(substr($order_string, -1, 1)); $query_struct_current['orderby'][$order_field] = $order_sort == 0 ? 'ASC' : 'DESC'; } } /* * 回写$request_struct_current 的 order状态 用于页面调用时判断显示状态, * 回写的原因是因为有些默认初始的orderby请求并非在第一次请求时就由_GET得到的,而是在内部设置的。 */ if (isset($query_struct_current['orderby']) && !empty($query_struct_current['orderby'])) { $request_struct_current['order'] = array(); if (count($query_struct_current['orderby']) == 1) { // 单条 foreach ($query_struct_current['orderby'] as $ord_field => $ord_sort) { $request_struct_current['order'] = $ord_field . ($ord_sort == 'ASC' ? 0 : 1); } } else { // 多条 foreach ($query_struct_current['orderby'] as $ord_field => $ord_sort) { $request_struct_current['order'][] = $ord_field . ($ord_sort == 'ASC' ? 0 : 1); } } } //设定默认分页 $preset_perpages = Kohana::config('my.items_per_pages'); if (isset($request_data['per_page']) && !empty($request_data['per_page'])) { $query_struct_current['limit']['per_page'] = $request_data['per_page']; } $request_struct_current['per_page'] = $query_struct_current['limit']['per_page']; if (isset($request_data['page']) && !empty($request_data['page']) && is_numeric($request_data['page']) && $request_data['page'] > 0) { $query_struct_current['limit']['page'] = $request_data['page']; } $request_struct_current['page'] = $query_struct_current['limit']['page']; try { /* 调用后端服务获取数据 */ $good_service = ProductService::get_instance(); $return_data['assoc'] = $good_service->index($query_struct_current); $return_data['count'] = $good_service->count($query_struct_current); /* 模板输出 分页*/ $this->pagination = new Pagination(array('total_items' => $return_data['count'], 'items_per_page' => $query_struct_current['limit']['per_page'])); } catch (MyRuntimeException $ex) { /* ==根据业务逻辑定制== */ //FIXME 根据service层的异常做一些对应处理并抛出用户友好的异常Message throw $ex; } /* 如果是ajax请求缩减返回的字段 ==根据业务逻辑定制== */ if ($this->is_ajax_request()) { $requestkeys = array('id', 'title', 'uri_name', 'store', 'on_sale', 'goods_price', 'sku'); array_walk($return_data['assoc'], 'util::simplify_return_array', $requestkeys); } /* 补充&修改返回结构体 */ $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 . '/' . $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->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; } } }
public function add_products() { role::check('product_auction'); $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); $experience = $this->input->get('experience', 0); $relation_query_struct = array('where' => array('status!=' => 2, 'experience' => $experience), 'orderby' => array('id' => 'DESC')); //$relations = Product_auctionService::get_instance()->index($relation_query_struct); $product_ids = array(); //foreach ($relations as $relation){ //$product_ids[] = $relation['product_id']; //} $struct = product::get_struct($request_data); $query_struct_current = $struct['query']; $request_struct_current = $struct['request']; $query_struct_current['where']['type'] = ProductService::PRODUCT_TYPE_GOODS; //* 调用后端服务获取数据 */ $product_service = ProductService::get_instance(); $return_data['assoc'] = $product_service->index($query_struct_current); $return_data['count'] = $product_service->count($query_struct_current); // 初始化分类列表 $category_list = array(); // 初始化品牌列表 $brand_list = array(); if (!empty($return_data['assoc'])) { // 获取该商品列表中涉及到的分类以及品牌ID $category_ids = array(); $brand_ids = array(); foreach ($return_data['assoc'] as $product) { if ($product['category_id'] != 0) { $category_ids[$product['category_id']] = TRUE; } if ($product['brand_id'] != 0) { $brand_ids[$product['brand_id']] = TRUE; } } // 获取分类列表 if (!empty($category_ids)) { $query_struct = array('where' => array('id' => array_keys($category_ids))); $categorys = CategoryService::get_instance()->query_assoc($query_struct); foreach ($categorys as $category) { $category_list[$category['id']] = $category['title_manage']; } } // 获取品牌列表 if (!empty($brand_ids)) { $query_struct = array('where' => array('id' => array_keys($brand_ids))); $brands = BrandService::get_instance()->query_assoc($query_struct); foreach ($brands as $brand) { $brand_list[$brand['id']] = $brand['name']; } } } // 模板输出 分页 $this->pagination = new Pagination(array('total_items' => $return_data['count'], 'items_per_page' => $query_struct_current['limit']['per_page'])); //* 如果是ajax请求缩减返回的字段 ==根据业务逻辑定制== */ if ($this->is_ajax_request()) { $requestkeys = array('id', 'category_id', 'title', 'uri_name', 'store', 'on_sale', 'goods_price', 'sku'); array_walk($return_data['assoc'], 'util::simplify_return_array', $requestkeys); } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $return_data; //exit("<div id=\"do_debug\" style=\"clear:both;display:;\"><pre>\n".var_export($return_struct,TRUE)."\n</pre></div>"); //* 请求类型 */ 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('product/auction/add_products', array('experience' => $experience)); //* 变量绑定 */ $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; //:: 当前应用专用数据 $this->template->content->title = Kohana::config('site.name'); $this->template->content->product_ids = $product_ids; $this->template->content->category_list = $category_list; $this->template->content->brand_list = $brand_list; } // end of request type determine } catch (MyRuntimeException $ex) { $this->_ex($ex, $return_struct, $request_data); } }
public function index() { $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']) or !isset($request_data['site_id']) or !in_array($request_data['site_id'], $site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $struct = product::get_struct($request_data, $request_data['site_id']); $query_struct_current = $struct['query']; $request_struct_current = $struct['request']; $query_struct_current['where']['status'] = 1; $query_struct_current['where']['type'] = 0; $query_struct_current['where']['classify_id'] = $request_data['classify_id']; $query_struct_current['where']['goods_attributeoption_relation_struct_default'] = array('', '{"items":[]}'); // 每页条目数 controller_tool::request_per_page($query_struct_current, $request_data); try { $return_data = BLL_Product::index($query_struct_current); foreach ($return_data['assoc'] as $index => $product) { $product['pictures'] = BLL_Product_Picture::get($product['id']); $product['picrels'] = array_keys($product['pictures']); $return_data['assoc'][$index] = $product; } // 模板输出 分页 $this->pagination = new Pagination(array('total_items' => $return_data['count'], 'items_per_page' => $query_struct_current['limit']['per_page'])); $query_struct_current['limit']['page'] = $this->pagination->current_page; } catch (MyRuntimeException $ex) { //* ==根据业务逻辑定制== */ //FIXME 根据service层的异常做一些对应处理并抛出用户友好的异常Message throw $ex; } //* 如果是ajax请求缩减返回的字段 ==根据业务逻辑定制== */ if ($this->is_ajax_request()) { $requestkeys = array('id', 'site_id', 'category_id', 'title', 'uri_name', 'store', 'on_sale', 'goods_price', 'sku'); array_walk($return_data['assoc'], 'util::simplify_return_array', $requestkeys); } //* 补充&修改返回结构体 */ $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->query_struct = $query_struct_current; $this->template->content->site_id = $request_data['site_id']; $this->template->content->classify_id = $request_data['classify_id']; //* 返回结构体绑定 */ $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; } } }