public static function is_allowed($permission = 'default', $site_id = 0, $type = NULL) { $verify = true; $site_ids = role::get_site_ids($type); //超级管理员root不需要检查权限 zhu modify if (role::is_root()) { $verify = true; } else { if ($site_id > 0 && !in_array($site_id, $site_ids)) { $verify = false; } $acl = Session::instance()->get(self::$acl_tag); if ($acl) { $acl = unserialize($acl); } else { $acl = self::acl_init(); } $manager = role::get_manager(); $verify = $acl->is_allowed($manager["username"], $permission); } //验证操作 if ($verify) { return $site_ids; } else { if (request::is_ajax()) { $return_struct = array('status' => 0, 'code' => 501, 'msg' => Kohana::lang('o_global.access_denied'), 'content' => array()); die(json_encode($return_struct)); } else { $referrer = tool::referrer_url(); remind::set('权限不足', $referrer, 'error'); } } }
/** * 构造方法 */ public function __construct() { $package_name = substr(dirname(__FILE__), strlen(APPPATH . 'controllers/')); empty($package_name) && ($package_name = 'default'); $this->package_name = $package_name; $this->class_name = strtolower(substr(__CLASS__, 0, strpos(__CLASS__, '_'))); $this->phprpc_server = Kohana::config('phprpc.remote.statking.host'); $this->site_ids = role::get_site_ids(); $this->site_id = site::id(); parent::__construct(); if ($this->is_ajax_request() == TRUE) { $this->template = new View('layout/default_json'); } }
public function delete_all() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented.', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); //* 实现功能后屏蔽此异常抛出 */ //throw new MyRuntimeException('Not Implemented',501); //* 权限验证,数据验证,逻辑验证 ==根据业务逻辑定制== */ $site_ids = role::get_site_ids(); if (empty($site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } if (empty($request_data['product_id']) or empty($request_data['relation_ids'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } //* 权限验证 ==根据业务逻辑定制== */ $product_service = ProductService::get_instance(); $product_relation_service = Product_relationService::get_instance(); $product = $product_service->get($request_data['product_id']); if (!in_array($product['site_id'], $site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } $relation_ids = array(); $query_struct = array('where' => array('product_id' => $product, 'relation_product_id' => explode('-', $request_data['relation_ids']))); foreach (Product_relationService::get_instance()->query_assoc($query_struct) as $relation) { $relation_ids[$relation['relation_product_id']] = TRUE; } ORM::factory('product_relation')->where('product_id', $request_data['product_id'])->in('relation_product_id', array_keys($relation_ids))->delete_all(); ProductService::get_instance()->set($product['id'], array('update_timestamp' => time())); //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $relation_ids; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 404); // html 输出 $this->template = new View('layout/empty_html'); //$this->template->manager_data = $this->manager; //* 模板输出 */ //$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->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 { //$return_struct['action']['type']= 'close'; // 当前应用为弹出窗口所以定义失败后续动作为关闭窗口 $this->template = new View('layout/default_html'); $this->template->return_struct = $return_struct; $content = new View('info2'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
/** * 获取可以绑定的货品 * * @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); } }
public function delete() { $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); } $template_id = intval($request_data['template_id']); $template = Product_templateService::get_instance()->index(array('where' => array('id' => $template_id))); if (!empty($template)) { if ($template[0]['site_id'] == $query_site_id) { ORM::factory('product_template')->where('id', $template_id)->delete_all(); } else { throw new MyRuntimeException('没有权限删除该商品模板!', 403); } } else { throw new MyRuntimeException('该模板不存在,或者已被删除!', 403); } //* 补充&修改返回结构体 */ //* 补充&修改返回结构体 ==根据业务逻辑定制== */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = '商品模板已经成功删除!'; $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; } } }
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; } } }
public function index() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { $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); } $site_id = site::id(); if ($site_id <= 0 && !in_array($site_id, $site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.select_site'), 400); } //获取站点的统计ID $site_detail = Mysite::instance($site_id)->detail(); $statking_id = $site_detail['statking_id']; $site_name = Mysite::instance($site_id)->get('domain'); //$statking_id = 100097; require_once Kohana::find_file('vendor', 'phprpc/phprpc_client', TRUE); $client = new PHPRPC_Client($this->phprpc_server); $date_today = date('Y-m-d'); //今日数据 $phprpc_statking_key = Kohana::config('phprpc.remote.statking.api_key'); $args = array($statking_id, strtotime($date_today . $this->time_offset)); $sign = md5(json_encode($args) . $phprpc_statking_key); $today = $client->get_data_pv_ip_by_time($statking_id, strtotime($date_today . $this->time_offset), $sign); //昨日数据 $phprpc_statking_key = Kohana::config('phprpc.remote.statking.api_key'); $args = array($statking_id, strtotime(date('Y-m-d', time() - 86400) . $this->time_offset)); $sign = md5(json_encode($args) . $phprpc_statking_key); $yesterday = $client->get_data_pv_ip_by_time($statking_id, strtotime(date('Y-m-d', time() - 86400) . $this->time_offset), $sign); //24小时流量 $now_hour = intval(date('H')); $hours = array(); $ps1 = $ps2 = $ct = $chart_data = ''; $pv_max = $ip_min = 0; for ($i = $now_hour + 1; $i <= 23; $i++) { $hours[]['h'] = $i; $hours[]['v'] = $yesterday['hours'][$i]; $ct == '' ? $ct .= $i : ($ct .= ',' . $i); $ps1 == '' ? $ps1 .= $yesterday['hours'][$i]['pv'] : ($ps1 .= ',' . $yesterday['hours'][$i]['pv']); $ps2 == '' ? $ps2 .= $yesterday['hours'][$i]['ip_count'] : ($ps2 .= ',' . $yesterday['hours'][$i]['ip_count']); $chart_data .= "{$i};{$yesterday['hours'][$i]['pv']};{$yesterday['hours'][$i]['ip_count']}\n"; if ($yesterday['hours'][$i]['pv'] > $pv_max) { $pv_max = $yesterday['hours'][$i]['pv']; } $ip_min == 0 ? $ip_min = $yesterday['hours'][$i]['ip_count'] : ''; if ($yesterday['hours'][$i]['ip_count'] < $ip_min) { $ip_min = $yesterday['hours'][$i]['ip_count']; } } for ($i = 0; $i <= $now_hour; $i++) { $hours[]['h'] = $i; $hours[]['v'] = $today['hours'][$i]; $ct == '' ? $ct .= $i : ($ct .= ',' . $i); $ps1 == '' ? $ps1 .= $today['hours'][$i]['pv'] : ($ps1 .= ',' . $today['hours'][$i]['pv']); $ps2 == '' ? $ps2 .= $today['hours'][$i]['ip_count'] : ($ps2 .= ',' . $today['hours'][$i]['ip_count']); $chart_data .= "{$i};{$today['hours'][$i]['pv']};{$today['hours'][$i]['ip_count']}\n"; if ($today['hours'][$i]['pv'] > $pv_max) { $pv_max = $today['hours'][$i]['pv']; } $ip_min == 0 ? $ip_min = $today['hours'][$i]['ip_count'] : ''; if ($today['hours'][$i]['ip_count'] < $ip_min) { $ip_min = $today['hours'][$i]['ip_count']; } } if ($pv_max == $ip_min) { $pv_max = $ip_min + 10; } $src1 = "/sitestat/chart?type=lc&w=800&h=300&ma={$pv_max}&mi={$ip_min}&r=10&t=pv-ip&ct={$ct}&sp=30&g=2&ps1={$ps1}&ps2={$ps2}&clr1=255,0,0&clr2=0,255,0"; $src2 = "/sitestat/chart?type=bg&w=800&h=300&ma={$pv_max}&mi={$ip_min}&r=10&t=pv-ip&ct={$ct}&sp=30&g=2&ps1={$ps1}&ps2={$ps2}&clr1=255,0,0&clr2=0,255,0"; $flash1 = "<embed width=\"800\" height=\"400\" flashvars=\"path=/amline/&settings_file=/amline/chart_settings/pv_ip.xml&chart_data={$chart_data}\" wmode=\"transparent\" quality=\"high\" bgcolor=\"#FFFFFF\" name=\"img_src1\" id=\"img_src1\" style=\"\" src=\"/amline/amline.swf\" type=\"application/x-shockwave-flash\">"; $flash2 = "<embed width=\"800\" height=\"400\" flashvars=\"path=/amline/&settings_file=/amline/chart_settings/pv_ip.xml&chart_data={$chart_data}&preloader_color=#999999\" quality=\"high\" bgcolor=\"#FFFFFF\" name=\"img_src2\" id=\"img_src2\" style=\"display:none\" src=\"/amline/amcolumn.swf\" type=\"application/x-shockwave-flash\">"; //站点概况 $phprpc_statking_key = Kohana::config('phprpc.remote.statking.api_key'); $args = array($statking_id); $sign = md5(json_encode($args) . $phprpc_statking_key); $overview = $client->get_data_pv_ip_by_one_site($statking_id, $sign); //来路域名 $phprpc_statking_key = Kohana::config('phprpc.remote.statking.api_key'); $args = array($statking_id, strtotime($date_today . $this->time_offset), strtotime($date_today . $this->time_offset)); $sign = md5(json_encode($args) . $phprpc_statking_key); $domains_all = $client->get_data_domain_by_time_range($statking_id, strtotime($date_today . $this->time_offset), strtotime($date_today . $this->time_offset), 0, 1, 10, $sign); $domains = $domains_all['data']; //受访页面 $phprpc_statking_key = Kohana::config('phprpc.remote.statking.api_key'); $args = array($statking_id, strtotime($date_today . $this->time_offset), strtotime($date_today . $this->time_offset)); $sign = md5(json_encode($args) . $phprpc_statking_key); $pages_all = $client->get_data_page_by_time_range($statking_id, strtotime($date_today . $this->time_offset), strtotime($date_today . $this->time_offset), 0, 1, 10, $sign); $pages = $pages_all['data']; //地区分布 $phprpc_statking_key = Kohana::config('phprpc.remote.statking.api_key'); $args = array($statking_id, strtotime($date_today . $this->time_offset), strtotime($date_today . $this->time_offset)); $sign = md5(json_encode($args) . $phprpc_statking_key); $areas_all = $client->get_data_country_by_time_range($statking_id, strtotime($date_today . $this->time_offset), strtotime($date_today . $this->time_offset), 0, 1, 10, $sign); $areas = $areas_all['data']; $ps = $pts = ''; $chart_data = "[title];[value]\n"; for ($i = 1; $i < count($areas); $i++) { $ps .= $ps == '' ? $areas[$i]['pv'] : ',' . $areas[$i]['pv']; $pts .= $pts == '' ? $areas[$i]['name'] : ',' . $areas[$i]['name']; $chart_data .= "{$areas[$i]['name']};{$areas[$i]['pv']}\n"; } $chart_data = urlencode($chart_data); $src3 = "/sitestat/chart?type=pc&w=400&h=200&ps={$ps}&pts={$pts}"; $flash3 = "<embed width=\"800\" height=\"400\" flashvars=\"path=/amline/&settings_file=/amline/chart_settings/pie.xml&chart_data={$chart_data}\" quality=\"high\" bgcolor=\"#FFFFFF\" name=\"amline\" id=\"amline\" style=\"\" src=\"/amline/ampie.swf\" type=\"application/x-shockwave-flash\">"; $content = new View($this->package_name . '/' . $this->class_name . '/' . 'index'); $this->template->content = $content; $this->template->content->site_name = $site_name; $this->template->content->sitestat_left = new View($this->package_name . '/sitestat_left'); $this->template->content->sitestat_left->overview = 1; $this->template->content->today_pv_ip = $today['day']; $this->template->content->yesterday_pv_ip = $yesterday['day']; $this->template->content->average = $overview['average']; $this->template->content->highest = $overview['highest']; $this->template->content->total = $overview['total']; $this->template->content->src1 = $src1; $this->template->content->src2 = $src2; $this->template->content->src3 = $src3; $this->template->content->flash1 = $flash1; $this->template->content->flash2 = $flash2; $this->template->content->flash3 = $flash3; $this->template->content->domains = $domains; $this->template->content->pages = $pages; } 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 classifies() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); //* 实现功能后屏蔽此异常抛出 */ //throw new MyRuntimeException('Not Implemented',501); //* 权限验证 */ $site_ids = role::get_site_ids(); if (empty($site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } if (empty($request_data['site_id']) or !in_array($request_data['site_id'], $site_ids)) { throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403); } $classifies = ClassifyService::get_instance()->query_assoc(array('where' => array('site_id' => $request_data['site_id']), 'orderby' => array('id' => 'ASC'))); $html = '<option value="-1">通用商品类型</option>'; foreach ($classifies as $classify) { $html .= '<option value="' . $classify['id'] . '">' . htmlspecialchars($classify['name']) . '</option>'; } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = $html; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { throw new MyRuntimeException('Not Implemented'); // html 输出 //* 模板输出 */ $content = new View($this->package . '/' . $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->return_struct = $return_struct; //:: 当前应用专用数据 $this->template->content->site_id = $site_id; $this->template->content->sites = $sites; $this->template->content->categorys_tree = $categorys_tree; } // 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 select() { $site_id_list = role::check('affiliate'); $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 { $query_site_id = $site_ids; //throw new MyRuntimeException(Kohana::lang('o_global.select_site'), 400); } $site_name = Mysite::instance($this->site_id)->get('domain'); //页数 $page = isset($request_data['page']) && intval($request_data['page']) >= 1 ? intval($request_data['page']) : 1; //联盟id $affiliate_id = isset($request_data['affiliate_id']) && intval($request_data['affiliate_id']) >= 1 ? intval($request_data['affiliate_id']) : 0; //起始时间 $time_f = isset($request_data['time_f']) ? $request_data['time_f'] : date('Y-m-d', time() - 86400 * 365 * 5); $time_f = $time_f == '' ? date('Y-m-d', time() - 86400 * 365 * 5) : $time_f; //结束时间 $time_t = isset($request_data['time_t']) ? $request_data['time_t'] : date('Y-m-d'); $time_t = $time_t == '' ? date('Y-m-d') : $time_t; //获取联盟的订单 $where = array('site_id' => $query_site_id, 'order_time >' => date('Y-m-d H:i:s', strtotime($time_f . ' 00:00:00')), 'order_time <' => date('Y-m-d H:i:s', strtotime($time_t . ' 23:59:59'))); if ($affiliate_id > 0) { $where['affiliate_id'] = $affiliate_id; } $query_struct = array('where' => $where, 'limit' => array('page' => $page, 'per_page' => 20)); $orders = Affiliate_orderService::get_instance()->index($query_struct); $orders_count = Affiliate_orderService::get_instance()->count($query_struct); $this->pagination = new Pagination(array('total_items' => $orders_count, 'items_per_page' => 20)); $affiliates = AffiliateService::get_instance()->index(array('where' => array('mark' => 1))); for ($i = 0; $i < count($affiliates); $i++) { if ($affiliates[$i]['id'] == $affiliate_id) { $affiliates[$i]['selected'] = 1; } else { $affiliates[$i]['selected'] = 0; } } $content = new View($this->package_name . '/' . $this->class_name . '/' . __FUNCTION__); $this->template->content = $content; $this->template->content->site_name = $site_name; $this->template->content->orders = $orders; $this->template->content->pagination = $this->pagination; $this->template->content->time_f = $time_f; $this->template->content->time_t = $time_t; $this->template->content->affiliates = $affiliates; } 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; } } }