Example #1
0
 /**
  * 设定菜单的排序
  */
 public function set_order()
 {
     //初始化返回数组
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     $request_data = $this->input->get();
     $id = isset($request_data['id']) ? $request_data['id'] : '';
     $order = isset($request_data['order']) ? $request_data['order'] : '';
     /* 验证是否可以操作 */
     if (!role::verify('product_filter', site::id(), 0)) {
         $return_struct['msg'] = Kohana::lang('o_global.permission_enough');
         exit(json_encode($return_struct));
     }
     if (empty($id) || empty($order) && $order != 0) {
         $return_struct['msg'] = Kohana::lang('o_global.bad_request');
         exit(json_encode($return_struct));
     }
     if (!is_numeric($order) || $order < 0) {
         $return_struct['msg'] = Kohana::lang('o_global.position_rule');
         exit(json_encode($return_struct));
     }
     $aliasfilter_service = Alias_filterService::get_instance();
     $aliasfilter_service->set($id, array('order' => $order));
     $return_struct = array('status' => 1, 'code' => 200, 'msg' => Kohana::lang('o_global.position_success'), 'content' => array('order' => $order));
     exit(json_encode($return_struct));
 }
Example #2
0
 /**
  * 根据 category_id 删除分类
  * @param $category_id  int
  * @return void 
  * @throws MyRuntimeException
  */
 public function delete_category_by_category_id($category_id)
 {
     try {
         $category = $this->get($category_id);
         if ($this->get_childrens_by_category_id($category_id)) {
             throw new MyRuntimeException('有子分类不能删除', 500);
         }
         if ($this->get_products_by_category_id($category_id)) {
             throw new MyRuntimeException('分类下有商品不能删除', 500);
         }
         $query_struct = array('where' => array('category_id' => $category_id));
         if (Alias_filterService::get_instance()->count($query_struct)) {
             throw new MyRuntimeException('有相关联的虚拟分类不能删除', 500);
         }
         if (!empty($category['pic_attach_id'])) {
             $this->delete_pic($category['pic_attach_id']);
         }
         $this->remove($category_id);
         $this->update_categories();
     } catch (MyRuntimeException $ex) {
         throw $ex;
     }
 }