/**
  * 获取要安装的联盟的信息
  *
  * @param int $affiliate_id
  * @param int $site_id
  * @return unknown
  */
 public function get_affiliate_install($affiliate_id, $site_id)
 {
     $site_affiliate = Site_affiliateService::get_instance()->index(array('where' => array('affiliate_id' => $affiliate_id, 'site_id' => $site_id, 'mark' => 1)));
     if (empty($site_affiliate)) {
         $affiliate = $this->query_row(array('where' => array('id' => $affiliate_id, 'mark' => 1)));
         if (empty($affiliate)) {
             throw new MyRuntimeException('', 403);
         } else {
             $affiliate['form_string'] = $this->get_form_string($affiliate['name']);
             return $affiliate;
         }
     } else {
         throw new MyRuntimeException('该联盟已经安装,不能重复安装!', 403);
     }
 }
Exemple #2
0
 /**
  * 设置联盟的cookie,标记最新的联盟
  *
  * @param int $site_id 站点ID
  * @param string $affiliate_name 联盟名称
  * @param int $log 是否记录联盟带来的流量
  * @return unknown
  */
 public function set_cookie($site_id, $affiliate_name = 'clixgalore', $log = 1)
 {
     //检查联盟是否安装,并获取联盟的信息
     $affiliate = Site_affiliateService::get_instance()->query_row(array('where' => array('affiliate_name' => $affiliate_name, 'site_id' => $site_id, 'mark' => 1)));
     if (empty($affiliate)) {
         return '<!-- the affiliate ' . $affiliate_name . ' is not exist, or it was been uninstalled. -->';
     }
     //如果需要记录联盟的流量,则将相关内容插入数据库
     if ($log == 1) {
         $query_struct = array('affiliate_id' => $affiliate['affiliate_id'], 'affiliate_name' => $affiliate_name, 'site_id' => $site_id, 'site_name' => $_SERVER['HTTP_HOST'], 'visit_url' => $_SERVER['REQUEST_URI'], 'visit_time' => date('Y-m-d H:i:s'));
         $orm_instance = ORM::factory('affiliate_visit');
         $data = $orm_instance->as_array();
         foreach ($query_struct as $key => $val) {
             array_key_exists($key, $data) && ($orm_instance->{$key} = $val);
         }
         $orm_instance->save();
     }
     //设置联盟的cookie
     setcookie('affiliateSource', 'clixgalore', time() + intval($affiliate['cookie_day']) * 86400);
     return '<!-- cookie affiliateSource was been set-->';
 }
Exemple #3
0
 /**
  * 设置联盟的cookie,标记最新的联盟
  *
  * @param int $site_id 站点ID
  * @param string $affiliate_name 联盟名称
  * @param int $log 是否记录联盟带来的流量
  * @return unknown
  */
 function set_cookie($site_id, $affiliate_name = 'earnmoney', $log = 1)
 {
     $affiliate = Site_affiliateService::get_instance()->query_row(array('where' => array('affiliate_name' => $affiliate_name, 'site_id' => $site_id, 'mark' => 1)));
     if (empty($affiliate)) {
         return '<!-- affiliate ' . $affiliate_name . ' is not exist,or been uninstalled -->';
     }
     if ($log == 1) {
         $query_struct = array('affiliate_id' => $affiliate['affiliate_id'], 'affiliate_name' => $affiliate_name, 'site_id' => $site_id, 'site_name' => $_SERVER['HTTP_HOST'], 'visit_url' => $_SERVER['REQUEST_URI'], 'visit_time' => date('Y-m-d H:i:s'));
         $orm_instance = ORM::factory('affiliate_visit');
         $data = $orm_instance->as_array();
         foreach ($query_struct as $key => $val) {
             array_key_exists($key, $data) && ($orm_instance->{$key} = $val);
         }
         $orm_instance->save();
     }
     if (isset($_GET['param'])) {
         $params = $_GET['param'];
         $strDecode = self::uriDecode($params);
         $aryParams = explode('|', $strDecode);
         if ('nid' == $aryParams[0] && 'uid' == $aryParams[2] && 'resource' == $aryParams[4] && 'url' == $aryParams[6]) {
             setcookie('affiliateSource', 'earnmoney', time() + intval($affiliate['cookie_day']) * 86400);
             setcookie('earnmoney_params', $params, time() + intval($affiliate['cookie_day']) * 86400);
             return '<!-- cookie affiliateSource was been set -->';
         } else {
             return '<!-- params format wrong -->';
         }
     } else {
         return '<!-- no params -->';
     }
 }
Exemple #4
0
 /**
  * 对编辑网站联盟和安装网站联盟信息的处理
  *
  */
 public function post()
 {
     $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 {
             throw new MyRuntimeException(Kohana::lang('o_global.select_site'), 400);
         }
         if (!isset($_POST['install_affiliate'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         $affiliate_id = intval($_POST['affiliate_id']);
         $pdata = isset($_POST['pdata']) ? $_POST['pdata'] : array();
         $send_type = intval($_POST['send_type']);
         $cookie_day = intval($_POST['cookie_day']);
         $currency = $_POST['currency_use'] == 'default' ? 'default' : $_POST['currency'];
         Site_affiliateService::get_instance()->update_site_affiliate($query_site_id, $affiliate_id, $pdata, $send_type, $cookie_day, $currency);
         //* 补充&修改返回结构体 */
         //* 补充&修改返回结构体 ==根据业务逻辑定制== */
         $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;
         }
     }
 }