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);
         }
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['content'] = $product;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }
Exemple #2
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();
         if (empty($request_data['product_id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         if (empty($request_data['goods']) or !is_array($request_data['goods'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         try {
             $product = BLL_Product::get($request_data['product_id']);
         } catch (MyRuntimeException $ex) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         foreach ($request_data['goods'] as $index => $good) {
             if (isset($good['sku'])) {
                 empty($good['id']) and $good['id'] = 0;
                 if (BLL_Product_Type_Assembly::good_sku_exists($good['sku'], $good['id'])) {
                     throw new MyRuntimeException(sprintf(Kohana::lang('o_product.good_sku_has_exists'), $index), 403);
                 }
             } 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->return_struct = $return_struct;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }
Exemple #3
0
 /**
  * 使用商品模板创建一个新的商品
  * 
  * @return array
  */
 public static function get($site_id, $type = 0)
 {
     if (Product_templateService::get_instance()->is_template_exist($site_id)) {
         $template = Product_templateService::get_instance()->get_template_by_site($site_id);
         unset($template['id']);
         unset($template['create_timestamp']);
         unset($template['update_timestamp']);
         unset($template['descriptions']);
         $product = $template;
         $product['type'] = $type;
         $product['sku'] = strtoupper(uniqid());
     } else {
         $product = array('site_id' => $site_id, 'status' => 0, 'sku' => strtoupper(uniqid()), 'category_id' => 0, 'on_sale' => 1, 'type' => $type);
     }
     $product_id = ProductService::get_instance()->add($product);
     return BLL_Product::get($product_id);
 }
Exemple #4
0
 /**
  * 获取可以绑定的货品
  *
  * @author gehaifeng
  */
 public function get_goods_not_binded()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         //* 权限验证 ==根据业务逻辑定制== */
         $site_id_list = role::get_site_ids();
         if (empty($request_data['site_id']) || empty($request_data['product_id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
         }
         if (!in_array($request_data['site_id'], $site_id_list)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         //ajax请求处理
         if (isset($request_data['is_ajax']) && $request_data['is_ajax'] == 1) {
             if (isset($request_data['select_classify'])) {
                 $classify_id = intval($request_data['select_classify']);
             }
         }
         $page = isset($request_data['page']) ? intval($request_data['page']) : 1;
         $per_page = 10;
         //获取货品信息,判断是否有提交查询,选择不同的操作
         if (isset($request_data['select_type']) && $request_data['select_key'] != '') {
             $product = BLL_Product_Type_Binding::get_goods_nb_by_select($request_data, $page, $per_page);
         } else {
             $product = BLL_Product::get($request_data['product_id'], $page, $per_page);
         }
         $return_data = array();
         $this->pagination = new Pagination(array('total_items' => isset($product['goods_nb_count']) ? $product['goods_nb_count'] : 0, 'items_per_page' => $per_page));
         //* 补充&修改返回结构体 */
         $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 . '/binding/goods_nb_show');
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->product = $product;
             $this->template->content->request_data = $request_data;
             $this->template->content->pagination = $this->pagination;
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }
Exemple #5
0
 public function set()
 {
     $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();
         if (empty($request_data)) {
             $request_data = array_merge($_GET, $_POST);
         }
         $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 = ProductService::get_instance()->get($request_data['product_id']);
         $product = BLL_Product::get($request_data['product_id']);
         if ($product['site_id'] != $query_site_id) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         BLL_Pdttpl::set_product_template($request_data, $product);
         //* 补充&修改返回结构体 */
         //* 补充&修改返回结构体 ==根据业务逻辑定制== */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = Kohana::lang('o_product.edit_product_success');
         $return_struct['content'] = $return_data;
         $return_struct['action'] = array('type' => 'location', 'url' => !empty($request_data['listurl']) ? url::base() . $request_data['listurl'] : url::base() . $this->package_name . '/' . $this->class_name . '/' . 'index');
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             //* 变量绑定 */
             $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->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 #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;
         }
     }
 }