/** * 更新联盟信息 * * @param int $site_id * @param int $affiliate_id * @param array $pdata * @param int $send_type * @param int $cookie_day * @param string $currency */ public function update_site_affiliate($site_id, $affiliate_id, $pdata, $send_type, $cookie_day = 30, $currency = 'default') { $affiliate = AffiliateService::get_instance()->query_row(array('where' => array('id' => $affiliate_id, 'mark' => 1))); $site_affiliate = $this->query_row(array('where' => array('affiliate_id' => $affiliate_id, 'site_id' => $site_id))); $cookie_day = $cookie_day < 1 ? 30 : $cookie_day; if (empty($site_affiliate)) { $add_arr = array('site_id' => $site_id, 'affiliate_id' => $affiliate_id, 'affiliate_name' => $affiliate['name'], 'prm_value' => json_encode($pdata), 'send_type' => $send_type, 'cookie_day' => $cookie_day, 'currency' => $currency); $this->add($add_arr); } else { $update_arr = array('id' => $site_affiliate['id'], 'site_id' => $site_id, 'affiliate_id' => $affiliate_id, 'affiliate_name' => $affiliate['name'], 'prm_value' => json_encode($pdata), 'send_type' => $send_type, 'cookie_day' => $cookie_day, 'currency' => $currency, 'mark' => 1); $this->update($update_arr); } }
/** * 对网站联盟订单的查询处理 * */ 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; } } }