Пример #1
0
 /**
  * 配置站点的支付成功代码
  */
 public function pay_code()
 {
     // 初始化返回数据
     $return_data = array();
     //请求结构体
     $request_data = array();
     try {
         /* 管理员才能进行代码更新操作 */
         if ($this->manager_is_admin == 1) {
             $site = Mysite::instance($this->site_id)->get();
             $site_detail = Mysite::instance($this->site_id)->detail();
             //无站点ID非法操作
             if (!$site['id']) {
                 throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 401);
             }
             //更新pay_code信息
             if ($_POST) {
                 $pay_code = $this->input->post('pay_code');
                 if (empty($pay_code)) {
                     throw new MyRuntimeException(Kohana::lang('o_site.site_config_payment_success_cannot_submit'), 402);
                 }
                 //更新站点robots信息
                 $data = array();
                 $data['pay_code'] = $pay_code;
                 if (Mysite_detail::instance()->update_by_site_id($this->site_id, $data)) {
                     remind::set(Kohana::lang('o_global.update_success'), 'site/config/pay_code', 'success');
                 } else {
                     remind::set(Kohana::lang('o_global.update_error'), 'site/config/pay_code');
                 }
             }
             $pay_code = isset($site_detail['pay_code']) ? $site_detail['pay_code'] : '';
             $this->template->content = new View("site/pay_code");
             $this->template->content->pay_code = $pay_code;
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
     } 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 = new View('layout/empty_html');
             $this->template->content = $return_struct['msg'];
         } 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;
         }
     }
 }
Пример #2
0
 /**
  * 计算积分的值
  * @param $action_type
  * @param $value
  */
 public function calculate_score($action_type, $value)
 {
     //取得积分的公式
     $site_detail = Mysite_detail::instance()->get();
     $score_formula = $site_detail['user_score_formula'];
     empty($score_formula) && ($score_formula = self::$default_user_score_formula);
     // 计算积分
     $score_formula = str_replace($action_type, $value, $score_formula);
     $score_formula = preg_replace('/[a-zA-Z]/', 0, $score_formula);
     eval(" \$score = {$score_formula};");
     return $score;
 }
Пример #3
0
 public function build()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //$profiler = new Profiler;
         //* 初始化返回数据 */
         $return_data = array();
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->post();
         //* 实现功能后屏蔽此异常抛出 */
         //throw new MyRuntimeException('Not Implemented',501);
         //权限验证
         if ($this->site_id == 0) {
             throw new MyRuntimeException(Kohana::lang('o_global.select_site'), 400);
         }
         role::check('default', $this->site_id, 0);
         // 调用底层服务
         $sitemap_service = SitemapService::get_instance();
         //业务逻辑
         $xmlContent = '';
         $xmlContent .= '<?xml version="1.0" encoding="UTF-8"?>';
         $xmlContent .= '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
         //添加首页
         if (!empty($request_data['index']) && is_numeric($request_data['index'])) {
             $priority = number_format($request_data['index'], 1);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         $site_domain = Mysite::instance($this->site_id)->get('domain');
         $xmlContent .= sitemap::Render('http://' . $site_domain, 0, 'always', $priority);
         //添加分类页面
         $categories = $sitemap_service->get_category_page_by_site_id($this->site_id);
         if (!empty($request_data['category']) && is_numeric($request_data['category'])) {
             $priority = number_format($request_data['category'], 1);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         if (!empty($categories)) {
             foreach ($categories as $category) {
                 if (empty($request_data['exclude_category']) || !empty($request_data['exclude_category']) && !in_array($category['id'], $request_data['exclude_category'])) {
                     $xmlContent .= sitemap::Render(category::permalink($category['id']), 0, 'weekly', $priority);
                 }
             }
         }
         //添加商品页面
         if (!empty($request_data['product']) && is_numeric($request_data['product'])) {
             $priority = number_format($request_data['product'], 1);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         if (isset($request_data['on_sale'])) {
             $on_sale = intval($request_data['on_sale']);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         $products = $sitemap_service->get_product_page_by_site_id($this->site_id, $on_sale);
         if (!empty($request_data['exclude_product'])) {
             if (preg_match('/^([a-zA-Z0-9_]+,)*[a-zA-Z0-9_]+$/i', $request_data['exclude_product'])) {
                 $request_data['exclude_product'] = explode(',', $request_data['exclude_product']);
             } else {
                 throw new MyRuntimeException(Kohana::lang('o_site.product_id_format_check'), 404);
             }
         }
         if (!empty($products)) {
             foreach ($products as $product) {
                 if (empty($request_data['exclude_product'])) {
                     $xmlContent .= sitemap::Render(product::permalink($product['id']), $product['update_timestamp'], 'weekly', $priority);
                 } elseif (!empty($request_data['exclude_product']) && !in_array($product['sku'], $request_data['exclude_product'])) {
                     $xmlContent .= sitemap::Render(product::permalink($product['id']), $product['update_timestamp'], 'weekly', $priority);
                 }
             }
         }
         //添加促销页
         if (!empty($request_data['promotion']) && is_numeric($request_data['promotion'])) {
             $priority = number_format($request_data['promotion'], 1);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         $promotions = $sitemap_service->get_promotion_page_by_site_id($this->site_id);
         if (!empty($promotions)) {
             $route = Myroute::instance()->get();
             $action = $route['promotion'];
             foreach ($promotions as $promotion) {
                 $xmlContent .= sitemap::Render('http://' . $site_domain . '/' . $action . '/' . $promotion['id'], time(), 'weekly', $priority);
             }
         }
         //添加文案页
         if (!empty($request_data['doc']) && is_numeric($request_data['doc'])) {
             $priority = number_format($request_data['doc'], 1);
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 404);
         }
         $docs = $sitemap_service->get_doc_page_by_site_id($this->site_id);
         if (!empty($docs)) {
             foreach ($docs as $doc) {
                 $lastmod = strtotime($doc['updated']);
                 $xmlContent .= sitemap::Render('http://' . $site_domain . '/' . $doc['permalink'], $lastmod, 'weekly', $priority);
             }
         }
         $xmlContent .= '</urlset>';
         $data['sitemap'] = $xmlContent;
         if (!Mysite_detail::instance()->update_by_site_id($this->site_id, $data)) {
             throw new MyRuntimeException(Kohana::lang('o_site.sitemap_error_handle'), 500);
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '操作成功';
         $return_struct['content'] = $return_data;
         $return_struct['action'] = array('type' => 'location', 'url' => url::base() . 'site/sitemap');
         //* 请求类型 */
         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->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
         // 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;
         }
     }
 }
Пример #4
0
 public function edit_formula()
 {
     role::check('user_level');
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => '');
     try {
         //收集数据
         tool::filter_strip_tags($_POST);
         $request_data = $this->input->post();
         $validation = Validation::factory($request_data)->pre_filter('trim')->add_rules('user_score_formula', 'required', 'length[1,255]');
         if ($validation->validate() == FALSE) {
             $return_struct['content']['errors'] = $validation->errors();
             throw new MyRuntimeException(Kohana::lang('o_global.input_error'), 400);
         }
         //调用底层服务
         $site_detail_service = Mysite_detail::instance();
         //储存数据
         $data['user_score_formula'] = $request_data['user_score_formula'];
         //判断是否为默认的
         $site_detail_service->update_by_site_id($this->site_id, $data);
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = kohana::lang('o_global.update_success');
         $return_struct['content'] = $request_data;
         $return_struct['action'] = array('type' => 'location', 'url' => url::base() . 'user/' . $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->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
         }
         // 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;
         }
     }
 }