public function set_on_sale() { $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['product_id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } if (!isset($request_data['status']) or !in_array($request_data['status'], array('0', '1'))) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } //* 逻辑验证 ==根据业务逻辑定制== */ BLL_Product::set_on_sale($request_data['product_id'], $request_data['status']); //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $request_data['status']; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { // 仅允许AJAX调用 //throw new MyRuntimeException('Not Implemented',501); //* 模板输出 */ $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; } // end of request type determine } catch (MyRuntimeException $ex) { $this->_ex($ex, $return_struct, $request_data); } }