public function fetch_order_infos($begin_time, $end_time, $status_ids)
 {
     $begin_time = to_utc_format($begin_time);
     $end_time = to_utc_format($end_time);
     $limit = 4000;
     $start = 0;
     $sql = "order_status:({$status_ids['0']} OR {$status_ids['1']})";
     $sql .= " AND input_datetime:[{$begin_time} TO {$end_time}]";
     $this->solr_query->setQuery($sql);
     $this->solr_query->setFacetSort(SolrQuery::FACET_SORT_COUNT);
     $this->solr_query->setFacet(TRUE);
     $this->solr_query->setRows($limit);
     $this->solr_query->addField('skus');
     $this->solr_query->addField('qties');
     $this->solr_query->addField('gross');
     $this->solr_query->addField('net');
     $this->solr_query->addField('currency');
     $this->solr_query->setFacetOffset(0);
     $datas = array();
     $i = 1;
     do {
         $this->solr_query->setStart($start);
         $updateResponse = $this->solr_client->query($this->solr_query);
         $response_array = $updateResponse->getResponse();
         if ($i > 1) {
             $datas = array_merge($datas, $response_array->response->docs);
         } else {
             $datas = $response_array->response->docs;
         }
         $num = $response_array->response->numFound;
         $start += 4000;
         $i++;
     } while ($start < $response_array->response->numFound);
     return $datas;
 }
 public function by_ship_confirm_user()
 {
     $this->set_2column('sidebar_statistics_order');
     $input_user = NULL;
     if (!$this->input->is_post()) {
         $begin_time = date("Y-m-d H:i:s", strtotime('-1 month'));
         $end_time = date("Y-m-d H:i:s");
     } else {
         $begin_time = $this->input->post('begin_time');
         $end_time = $this->input->post('end_time');
         $input_user = $this->input->post('input_user');
     }
     $begin_time = to_utc_format($begin_time);
     $end_time = to_utc_format($end_time);
     $input_users = $this->order_model->fetch_input_user();
     $ship_users = $this->order_model->fetch_ship_confirm_user();
     foreach ($ship_users as $users) {
         if (empty($users->ship_confirm_user)) {
             continue;
         }
         $ship_user_arr[] = $users->ship_confirm_user;
     }
     $status_id = fetch_status_id('order_status', 'received_partial_refunded');
     $currencies = array('RMB', 'USD', 'AUD', 'GBP', 'EUR');
     foreach ($currencies as $currency) {
         $return_infos = $this->solr_statistics_model->fetch_return_info_by_ship_confirm_user($currency, $status_id, $begin_time, $end_time, $input_user);
         $return_datas = empty($return_infos->facets->ship_confirm_user) ? NULL : $return_infos->facets->ship_confirm_user;
         $return_all_count = empty($return_infos->count) ? 0 : $return_infos->count;
         $return_all_cost[$currency] = empty($return_infos->sum) ? 0 : $return_infos->sum;
         foreach ($ship_user_arr as $ship_user) {
             if (!empty($return_datas->{$ship_user}->count)) {
                 $tmp_count = $return_datas->{$ship_user}->count;
             } else {
                 $tmp_count = 0;
             }
             if (isset($return_count[$ship_user])) {
                 $return_count[$ship_user] += $tmp_count;
             } else {
                 $return_count[$ship_user] = $tmp_count;
             }
             if (empty($return_datas->{$ship_user}->sum)) {
                 $return_cost[$ship_user][$currency] = 0;
             } else {
                 $return_cost[$ship_user][$currency] = price($return_datas->{$ship_user}->sum);
             }
             if (isset($return_to_rmb[$ship_user])) {
                 $return_to_rmb[$ship_user] += $return_cost[$ship_user][$currency] * $this->cur_rates[$currency];
             } else {
                 $return_to_rmb[$ship_user] = $return_cost[$ship_user][$currency];
             }
         }
     }
     foreach ($currencies as $currency) {
         $total_infos = $this->solr_statistics_model->fetch_total_info_by_ship_confirm_user($currency, $begin_time, $end_time, $input_user);
         $total_datas = empty($total_infos->facets->ship_confirm_user) ? NULL : $total_infos->facets->ship_confirm_user;
         $total_all_count = empty($total_infos->count) ? 0 : $total_infos->count;
         $total_all_cost[$currency] = empty($total_infos->sum) ? 0 : $total_infos->sum;
         foreach ($ship_user_arr as $ship_user) {
             if (!empty($total_datas->{$ship_user}->count)) {
                 $tmp_count = $total_datas->{$ship_user}->count;
             } else {
                 $tmp_count = 0;
             }
             if (isset($total_count[$ship_user])) {
                 $total_count[$ship_user] += $tmp_count;
             } else {
                 $total_count[$ship_user] = $tmp_count;
             }
             if (empty($total_datas->{$ship_user}->sum)) {
                 $total_cost[$ship_user][$currency] = 0;
             } else {
                 $total_cost[$ship_user][$currency] = price($total_datas->{$ship_user}->sum);
             }
             if (isset($total_to_rmb[$ship_user])) {
                 $total_to_rmb[$ship_user] += $total_cost[$ship_user][$currency] * $this->cur_rates[$currency];
             } else {
                 $total_to_rmb[$ship_user] = $total_cost[$ship_user][$currency];
             }
         }
     }
     foreach ($ship_user_arr as $ship_user) {
         if ($total_count[$ship_user] == 0) {
             $return_count_rate[$ship_user] = 0;
         } else {
             $return_count_rate[$ship_user] = price($return_count[$ship_user] / $total_count[$ship_user], '4');
         }
         if ($total_to_rmb[$ship_user] == 0) {
             $return_cost_rate[$ship_user] = 0;
         } else {
             $return_cost_rate[$ship_user] = price($return_to_rmb[$ship_user] / $total_to_rmb[$ship_user], '4');
         }
     }
     arsort($return_count);
     foreach ($return_count as $key => $vl) {
         $return_count[$key] = $vl;
     }
     foreach ($return_count as $key => $vl) {
         foreach ($ship_user_arr as $ship_user) {
             if ($key == $ship_user) {
                 $ship_user_arrs[] = $key;
             }
         }
     }
     $data = array('input_users' => $input_users, 'current_user' => $input_user, 'begin_time' => $begin_time, 'end_time' => $end_time, 'return_count' => $return_count, 'total_count' => $total_count, 'return_count_rate' => $return_count_rate, 'return_cost' => $return_cost, 'total_cost' => $total_cost, 'return_cost_rate' => $return_cost_rate, 'currencies' => $currencies, 'ship_users' => $ship_user_arrs);
     $this->template->write_view('content', 'order/receive_partial_refunded/by_ship_confirm_user', $data);
     $this->template->add_js('static/js/sorttable.js');
     $this->template->render();
 }
Example #3
0
 public function fetch_order_count_by_input_date($begin_time, $end_time)
 {
     $begin_time = to_utc_format($begin_time);
     $end_time = to_utc_format($end_time);
     $where = array('input_date >= ' => $begin_time, 'input_date <= ' => $end_time);
     return $this->count('order_list', $where);
 }
Example #4
0
 public function in_store_case($id = null, $case_no = null)
 {
     /**
      * 当点击继续加箱的时候进入。
      */
     if ($id && $case_no) {
         list($list_info, $boxes_info, $products_info) = $this->in_store_list_all_detail($id);
         $data_for_view = array('list_id' => $id, 'case_no' => $case_no, 'list_info' => $list_info, 'boxes_info' => $boxes_info, 'products_info' => $products_info);
         $this->load->view('stock/abroad_stock/in_store_case_page', $data_for_view);
         return;
     }
     /**
      * 当点击上一步的时候进入。
      */
     if ($id && $case_no == 0) {
         $case_obj = $this->abroad_stock_model->fetch_case_info_by_id($id);
         list($list_info, $boxes_info, $products_info) = $this->in_store_list_all_detail($case_obj->list_id);
         $data = array('list_id' => $case_obj->list_id, 'list_info' => $list_info, 'boxes_info' => $boxes_info, 'products_info' => $products_info, 'case_obj' => $case_obj, 'page_status' => 'close_case_back_button');
         $this->load->view('stock/abroad_stock/in_store_case_page', $data);
         return;
     }
     $rules = array(array('field' => 'log_type', 'label' => lang('log_type'), 'rules' => 'trim|required'), array('field' => 'storage_code', 'label' => lang('storage_code'), 'rules' => 'trim|required'), array('field' => 'arrive_time', 'label' => lang('arrive_time'), 'rules' => 'trim|required'), array('field' => 'locale', 'label' => lang('locale'), 'rules' => 'trim|required'), array('field' => 'is_collect', 'label' => lang('is_collect'), 'rules' => 'trim|required'), array('field' => 'collect_time', 'label' => lang('collect_time'), 'rules' => 'trim|required'), array('field' => 'collect_address', 'label' => lang('collect_address'), 'rules' => 'trim|required'), array('field' => 'collect_contact', 'label' => lang('collect_contact'), 'rules' => 'trim|required'), array('field' => 'collect_phone', 'label' => lang('collect_phone'), 'rules' => 'trim|required'));
     $this->form_validation->set_rules($rules);
     if ($this->form_validation->run() == FALSE) {
         $error = validation_errors();
         echo $this->create_json(0, $error);
         return;
     }
     $log_type = trim($this->input->post('log_type'));
     $storage_code = trim($this->input->post('storage_code'));
     $arrive_time = substr(trim($this->input->post('arrive_time')), 0, 10);
     $locale = trim($this->input->post('locale'));
     $remark = trim($this->input->post('abroad_stock_remark'));
     $is_collect = trim($this->input->post('is_collect'));
     $collect_time = to_utc_format(trim($this->input->post('collect_time')));
     $collect_address = trim($this->input->post('collect_address'));
     $collect_contact = trim($this->input->post('collect_contact'));
     $collect_phone = trim($this->input->post('collect_phone'));
     $data_to_database = array('log_type' => $log_type, 'storage_code' => $storage_code, 'arrive_time' => $arrive_time, 'locale' => $locale, 'remark' => $remark, 'is_collect' => $is_collect, 'collect_time' => $collect_time, 'collect_address' => $collect_address, 'collect_contact' => $collect_contact, 'collect_phone' => $collect_phone, 'status' => 0, 'creator' => get_current_login_name());
     try {
         $list_id = $this->input->post('list_id');
         if ($list_id > 0) {
             $this->abroad_stock_model->update('cky_in_store_list', array('id' => $list_id), $data_to_database);
         } else {
             $list_id = $this->abroad_stock_model->save_in_store_apply($data_to_database);
         }
         list($list_info, $boxes_info, $products_info) = $this->in_store_list_all_detail($list_id);
         $data_for_view = array('list_id' => $list_id, 'list_info' => $list_info, 'boxes_info' => $boxes_info, 'products_info' => $products_info);
         $this->load->view('stock/abroad_stock/in_store_case_page', $data_for_view);
         return;
     } catch (Exception $e) {
         echo lang('error_msg');
         $this->ajax_failed();
     }
 }
 private function _process_import_order($order_table, $order_id, $start_time, $end_time, $limit, $offset)
 {
     $total = $this->solr_order_model->fetch_order_count_by_updated($order_table, $start_time, $end_time);
     $successful = TRUE;
     $options = array('hostname' => SOLR_SERVER_HOSTNAME, 'port' => SOLR_SERVER_PORT);
     echo 'table: ' . $order_table, "\n";
     echo 'total: ' . $total, "\n";
     do {
         echo 'off set: ' . $offset, "\n";
         $orders = $this->solr_order_model->fetch_orders_by_updated($order_table, $start_time, $end_time, $limit, $offset);
         $docs = array();
         foreach ($orders as $order) {
             $client = new SolrClient($options);
             $doc = new SolrInputDocument();
             $doc->addField('id', $order_table . ':' . $order->{$order_id});
             $skus = explode(',', $order->sku_str);
             foreach ($skus as $sku) {
                 $doc->addField('skus', $sku);
             }
             $doc->addField('list_datetime', $order->list_date . 'T' . $order->list_time . "Z");
             $doc->addField('buyer_name', $order->name);
             $doc->addField('buyer_id', $order->buyer_id);
             $doc->addField('list_type', $order->list_type);
             $doc->addField('payment_status', $order->payment_status);
             $doc->addField('subject', $order->subject);
             $doc->addField('currency', $order->currency);
             $doc->addField('gross', make_number($order->gross, 0));
             $doc->addField('fee', make_number($order->fee, 0));
             $doc->addField('net', make_number($order->net, 0));
             $doc->addField('time_zone', $order->time_zone);
             $doc->addField('note', $order->note);
             $doc->addField('buyer_email', $order->from_email);
             $doc->addField('company_email', $order->to_email);
             $doc->addField('transaction_id', $order->transaction_id);
             $doc->addField('payment_type', $order->payment_type);
             $doc->addField('shipping_address', $order->shipping_address);
             $doc->addField('address_status', $order->address_status);
             $item_titles = explode_item_title($order->item_title_str);
             foreach ($item_titles as $item_title) {
                 $doc->addField('item_titles', $item_title);
             }
             $item_ids = explode(',', $order->item_id_str);
             foreach ($item_ids as $item_id) {
                 $doc->addField('item_ids', $item_id);
             }
             $doc->addField('item_url', $order->item_url);
             $doc->addField('closing_date', $order->closing_date);
             $doc->addField('invoice_number', $order->invoice_number);
             $doc->addField('address_line_1', $order->address_line_1);
             $doc->addField('address_line_2', $order->address_line_2);
             $doc->addField('town_city', $order->town_city);
             $doc->addField('state_province', $order->state_province);
             $doc->addField('country', $order->country);
             $doc->addField('zip_code', $order->zip_code);
             $doc->addField('contact_phone_number', $order->contact_phone_number);
             $doc->addField('income_type', $order->income_type);
             $qties = explode(',', $order->qty_str);
             foreach ($qties as $qty) {
                 //$doc->addField('qties', make_number($qty));
             }
             $doc->addField('description', $order->descript);
             $doc->addField('input_datetime', to_utc_format($order->input_date));
             $doc->addField('input_user', $order->input_user);
             $doc->addField('order_status', make_number($order->order_status));
             $doc->addField('check_date', to_utc_format($order->check_date));
             $doc->addField('check_user', $order->check_user);
             $doc->addField('print_label_date', to_utc_format($order->print_label_date));
             $doc->addField('label_content', $order->label_content);
             $doc->addField('item_no', $order->item_no);
             $doc->addField('print_label_user', $order->print_label_user);
             $doc->addField('ship_confirm_date', to_utc_format($order->ship_confirm_date));
             $doc->addField('ship_confirm_user', $order->ship_confirm_user);
             $doc->addField('ship_weight', make_number($order->ship_weight, 0));
             $doc->addField('ship_remark', $order->ship_remark);
             $doc->addField('track_number', $order->track_number);
             $doc->addField('shipping_code', $order->is_register, 0);
             $doc->addField('cost', make_number($order->cost, 0));
             $doc->addField('cost_date', to_utc_format($order->cost_date));
             $doc->addField('cost_user', $order->cost_user);
             $product_costs = explode(',', trim($order->product_cost, ','));
             foreach ($product_costs as $product_cost) {
                 $doc->addField('product_costs', make_number($product_cost, 0));
             }
             $doc->addField('product_total_cost', $order->product_cost_all);
             $doc->addField('shipping_cost', make_number($order->shipping_cost, 0));
             $doc->addField('return_date', to_utc_format($order->return_date));
             $doc->addField('return_remark', $order->return_remark);
             $doc->addField('return_user', $order->return_user);
             $doc->addField('return_why', $order->return_why);
             $doc->addField('return_order', $order->return_order);
             $doc->addField('return_cost', make_number($order->return_cost, 0));
             $doc->addField('sys_remark', $order->sys_remark);
             $doc->addField('order_receive_date', $order->order_receive_date);
             $doc->addField('email_status', $order->email_status);
             $doc->addField('stock_user_id', make_number($order->stock_user_id));
             $doc->addField('saler_id', make_number($order->saler_id));
             $purchaser_ids = explode(',', $order->purchaser_id_str);
             foreach ($purchaser_ids as $purchaser_id) {
                 $doc->addField('purchaser_ids', make_number($purchaser_id));
             }
             $developer_ids = explode(',', $order->developer_id);
             foreach ($developer_ids as $developer_id) {
                 $doc->addField('developer_ids', make_number($developer_id));
             }
             $doc->addField('trade_fee', make_number($order->trade_fee, 0));
             $doc->addField('listing_fee', make_number($order->listing_fee, 0));
             $doc->addField('profit_rate', make_number($order->profit_rate, 0));
             $doc->addField('refund_verify_status', $order->refund_verify_status);
             $doc->addField('refund_verify_type', $order->refund_verify_type);
             $doc->addField('refund_verify_content', $order->refund_verify_content);
             $refund_duties = explode(',', $order->refund_duty);
             foreach ($refund_duties as $refund_duty) {
                 $doc->addField('refund_duties', $refund_duty);
             }
             $refund_skus = explode(',', $order->refund_sku_str);
             foreach ($refund_skus as $refund_sku) {
                 $doc->addField('refund_skus', $refund_sku);
             }
             $docs[] = $doc;
         }
         try {
             if (!empty($docs)) {
                 $response = $client->addDocuments($docs);
                 $client->commit();
             }
         } catch (SolrException $e) {
             $successful = FALSE;
             var_dump($e);
             break;
         }
         $offset += $limit;
     } while ($offset < $total);
     return $successful;
 }
    public function fetch_field_count($field, $begin_time, $end_time, $duty_user = NULL)
    {
        $begin_time = to_utc_format($begin_time);
        $end_time = to_utc_format($end_time);
        $total_counts = 1000000;
        $query = <<<QUERY
input_datetime:[{$begin_time} TO {$end_time}]
QUERY;
        if ($duty_user !== NULL) {
            $query .= " AND refund_duties:{$duty_user}";
        }
        $this->solr_query->setQuery($query);
        $this->solr_query->setFacet(TRUE);
        $this->solr_query->setFacetSort(SolrQuery::FACET_SORT_COUNT);
        $this->solr_query->setFacetOffset('0');
        $this->solr_query->setFacetLimit($total_counts);
        $this->solr_query->addField($field);
        $this->solr_query->addFacetField($field);
        $this->solr_query->setFacetMinCount(1);
        $updateResponse = $this->solr_client->query($this->solr_query);
        $response_array = $updateResponse->getResponse();
        return array('facet' => $response_array->facet_counts->facet_fields->{$field}, 'query' => $response_array->response);
    }
Example #7
0
 public function push_rules($sql, $key, $to = FALSE, $exclude = FALSE)
 {
     if ($to) {
         if ($exclude == FALSE) {
             $value_from = $this->input->post($key . "_from");
             $value_to = $this->input->post($key . "_to");
             if (!empty($value_from) && !empty($value_to)) {
                 if ($key == "input_datetime" || $key == "ship_confirm_date" || $key == 'cost_date') {
                     $value_from = to_utc_format($value_from);
                     $value_to = to_utc_format($value_to);
                 }
                 if ($sql != '') {
                     $sql = " AND ";
                     $sql .= "{$key}:[{$value_from} TO {$value_to}]";
                 } else {
                     $sql = "{$key}:[{$value_from} TO {$value_to}]";
                 }
             } else {
                 if (empty($value_from) && !empty($value_to)) {
                     if ($key == "input_datetime" || $key == "ship_confirm_date" || $key == "cost_date") {
                         $value_to = to_utc_format($value_to);
                     }
                     if ($sql != '') {
                         $sql = " AND ";
                         $sql .= "{$key}:[ * TO {$value_to}]";
                     } else {
                         $sql = "{$key}:[ * TO {$value_to}]";
                     }
                 } else {
                     if (empty($value_to) && !empty($value_from)) {
                         if ($key == "input_datetime" || $key == "ship_confirm_date" || $key == 'cost_date') {
                             $value_from = to_utc_format($value_from);
                         }
                         if ($sql != '') {
                             $sql = " AND ";
                             $sql .= "{$key}:[ {$value_from} TO * ]";
                         } else {
                             $sql = "{$key}:[ {$value_from} TO * ]";
                         }
                     } else {
                         if (empty($value_from) && empty($value_to)) {
                             $sql = '';
                         }
                     }
                 }
             }
         } else {
             $value_from = $this->input->post($key . "_from");
             $value_to = $this->input->post($key . "_to");
             $key_solr = substr($key, 0, -2);
             if (!empty($value_from) && !empty($value_to)) {
                 if ($key == "input_datetime_b" || $key == "ship_confirm_date_b" || $key == 'cost_date_b') {
                     $value_from = to_utc_format($value_from);
                     $value_to = to_utc_format($value_to);
                 }
                 if ($sql != '') {
                     $sql = " AND ";
                     $sql .= "-{$key_solr}:[{$value_from} TO {$value_to}]";
                 } else {
                     $sql = "-{$key_solr}:[{$value_from} TO {$value_to}]";
                 }
             } else {
                 if (empty($value_from) && !empty($value_to)) {
                     if ($key == "input_datetime_b" || $key == "ship_confirm_date_b" || $key == "cost_date_b") {
                         $value_to = to_utc_format($value_to);
                     }
                     if ($sql != '') {
                         $sql = " AND ";
                         $sql .= "-{$key_solr}:[ * TO {$value_to}]";
                     } else {
                         $sql = "-{$key_solr}:[ * TO {$value_to}]";
                     }
                 } else {
                     if (empty($value_to) && !empty($value_from)) {
                         if ($key == "input_datetime_b" || $key == "ship_confirm_date_b" || $key == 'cost_date_b') {
                             $value_from = to_utc_format($value_from);
                         }
                         if ($sql != '') {
                             $sql = " AND ";
                             $sql .= "-{$key_solr}:[ {$value_from} TO * ]";
                         } else {
                             $sql = "-{$key_solr}:[ {$value_from} TO * ]";
                         }
                     } else {
                         if (empty($value_from) && empty($value_to)) {
                             $sql = '';
                         }
                     }
                 }
             }
         }
     } else {
         if ($exclude == FALSE) {
             $value = $this->input->post($key);
             if (!empty($value)) {
                 if ($sql != '') {
                     $sql = " AND ";
                     if ($key == 'item_titles' || $key == 'item_no') {
                         $sql .= "{$key}:*{$value}*";
                     } else {
                         $sql .= "{$key}:\"{$value}\"";
                     }
                 } else {
                     if ($key == 'item_titles' || $key == 'item_no') {
                         $sql = "{$key}:*{$value}*";
                     } else {
                         $sql = "{$key}:\"{$value}\"";
                     }
                 }
             } else {
                 $sql = '';
             }
         } else {
             $value = $this->input->post($key);
             $key_solr = substr($key, 0, -2);
             if (!empty($value)) {
                 if ($sql != '') {
                     $sql = " AND ";
                     if ($key == 'item_titles' || $key == 'item_no') {
                         $sql .= "-{$key_solr}:*{$value}*";
                     } else {
                         $sql .= "-{$key_solr}:\"{$value}\"";
                     }
                 } else {
                     if ($key == 'item_titles' || $key == 'item_no') {
                         $sql = "-{$key_solr}:*{$value}*";
                     } else {
                         $sql = "-{$key_solr}:\"{$value}\"";
                     }
                 }
             } else {
                 $sql = '';
             }
         }
     }
     return $sql;
 }