/** * 保存联盟订单 * * @param array $order * @param array $affiliate * @return string */ public function save_affiliate_order($order, $affiliate) { //计算IP $f = intval($order['ip'] / (256 * 256 * 256)); $f_r = $order['ip'] - 256 * 256 * 256 * $f; $s = intval($f_r / (256 * 256)); $s_r = $f_r - 256 * 256 * $s; $t = intval($s_r / 256); $t_r = $s_r - 256 * $t; $ip = "{$f}.{$s}.{$t}.{$t_r}"; /* 联盟订单记录 start */ $query_struct = array('affiliate_id' => $affiliate['affiliate_id'], 'affiliate_name' => $affiliate['affiliate_name'], 'site_id' => $order['site_id'], 'site_name' => $_SERVER['HTTP_HOST'], 'order_num' => $order['order_num'], 'order_amount' => $order['total_product'], 'currency' => $order['currency'], 'order_time' => $order['date_add'], 'user_ip' => $ip, 'user_country' => $order['billing_country']); //判断订单是否有记录防止重复发送 $arr = Affiliate_orderService::get_instance()->query_row(array('where' => array('order_num' => $order['order_num']))); if (!empty($arr)) { return '<!-- this order has been recorded before -->'; } $orm_instance = ORM::factory('affiliate_order'); $data = $orm_instance->as_array(); foreach ($query_struct as $key => $val) { array_key_exists($key, $data) && ($orm_instance->{$key} = $val); } $orm_instance->save(); return 1; }
/** * 对网站联盟订单的查询处理 * */ 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; } } }