public function proccess_calculating($suggest_price = NULL) { // don't calculate, just show the form if ($this->input->post('init')) { $eshop_code = $this->input->post('eshop_code'); if ($eshop_code) { $currency_code = $this->fee_price_model->fetch_eshop_currency_code($eshop_code); } else { $currency_code = 'USD'; } $data = array('suggest_price' => 0, 'buyer_shipping_cost' => 0, 'list_fee' => 0, 'trade_fee' => 0, 'pay_fee' => 0, 'shipping_cost' => 0, 'shipping_type_name' => 0, 'other_cost' => 0, 'total_cost' => 0, 'total_profit' => 0, 'total_profit_rate' => 0, 'currency_code' => $currency_code, 'default_currency_code' => DEFAULT_CURRENCY_CODE); return $this->load->view('sale/price/calculate_price_result', $data); } $product_count = $this->input->post('product_count'); $total_price = 0; $total_weight = 0; $total_profit = 0; $max_length = 0; $max_width = 0; $total_height = 0; for ($i = 0; $i < $product_count; $i++) { $sku = trim($this->input->post('sku_' . $i)); $product = $this->product_model->fetch_product_by_sku($sku); if (!$product) { echo $this->create_json(0, sprintf(lang('product_sku_doesnot_exists_with_sku'), $sku)); return; } $qty = trim($this->input->post('qty_' . $i)); if (!is_numeric($qty) || $qty <= 0) { echo $this->create_json(0, lang('qty_not_natural')); return; } $weight = trim($this->input->post('weight_' . $i)); if (!numeric($weight) || $weight <= 0) { echo $this->create_json(0, lang('weight_format_error')); return; } $price = trim($this->input->post('price_' . $i)); if (!numeric($price) || $price <= 0) { echo $this->create_json(0, lang('price_format_error')); return; } $profit = trim($this->input->post('profit_' . $i)); if (!numeric($profit) || $profit <= 0 || $profit >= 1) { echo $this->create_json(0, lang('profit_format_error')); return; } $length = trim($this->input->post('length_' . $i)); if ($length > $max_length) { $max_length = $length; } $width = trim($this->input->post('width_' . $i)); if ($width > $max_width) { $max_width = $width; } $height = trim($this->input->post('height_' . $i)); $total_height += $height; $total_price += $price * $qty; $total_weight += $weight * $qty; $total_profit += $profit; } $balance_profit = $total_profit / $product_count; $pay_option = $this->input->post('pay_option'); $pay_discount = $this->input->post('pay_discount'); $eshop_code = $this->input->post('eshop_code'); $sale_mode = $this->input->post('sale_mode'); $eshop_list_count = $this->input->post('eshop_list_count'); $shipping_type = $this->input->post('shipping_type'); $shipping_country = $this->input->post('shipping_country'); if (empty($shipping_country)) { $shipping_country = DEFAULT_SHIPPING_COUNTRY; } $buyer_shipping_cost = $this->input->post('buyer_shipping_cost'); $other_cost = $this->input->post('other_cost'); $eshop_category = $this->input->post('eshop_category'); if (!is_numeric($eshop_list_count) || $eshop_list_count <= 0) { echo $this->create_json(0, lang('eshop_list_count_format_error')); return; } if (!numeric($buyer_shipping_cost) || $buyer_shipping_cost < 0) { echo $this->create_json(0, lang('buyer_shipping_cost_format_error')); return; } if (!numeric($other_cost)) { echo $this->create_json(0, lang('other_cost_format_error')); return; } $eshop_list_fee_multiply = 1; if ($sale_mode == 'auction') { $bid_rate = $this->input->post('bid_rate'); $eshop_list_fee_multiply = 1 + (100 - $bid_rate) / $bid_rate; } $input = array('eshop_code' => $eshop_code, 'buyer_shipping_cost' => $buyer_shipping_cost, 'shipping_type' => $shipping_type, 'shipping_country' => $shipping_country, 'total_weight' => $total_weight, 'sale_mode' => $sale_mode, 'eshop_category' => $eshop_category, 'suggest_price' => $suggest_price, 'key' => $key, 'total_price' => $total_price, 'balance_profit' => $balance_profit, 'eshop_list_count' => $eshop_list_count, 'eshop_list_fee_multiply' => $eshop_list_fee_multiply, 'pay_option' => $pay_option, 'pay_discount' => $pay_discount, 'other_cost' => $other_cost, 'max_length' => $max_length, 'max_width' => $max_width, 'total_height' => $total_height); $data = price_profit_rate($input); if (!is_array($data)) { echo $this->create_json(0, $data); return; } $this->load->view('sale/price/calculate_price_result', $data); }
private function is_profit_good($transaction_details) { $gross = $transaction_details['AMT']; $fee = isset($transaction_details['FEEAMT']) ? $transaction_details['FEEAMT'] : 0; $currency = $transaction_details['CURRENCYCODE']; $gross_rmb = price(calc_currency($currency, $gross)); $fee_rmb = price(calc_currency($currency, $fee)); $skus = $this->item_info['item_codes']; $qties = $this->item_info['item_qties']; $item_ids = $this->item_info['item_ids']; $product_cost = 0; $shipping_weight = 0; $other_cost = 0.65; $paypal_transaction_id = array($transaction_details['TRANSACTIONID']); $shipping_type = get_register($this->item_info, $this->user, $currency, $paypal_transaction_id); $country_name_en = $transaction_details['SHIPTOCOUNTRYNAME']; if (isset($this->country_names[$country_name_en])) { $country_name_cn = $this->country_names[$country_name_en]; } else { $country_name_cn = get_country_name_cn($country_name_en); $this->country_names[$country_name_en] = $country_name_cn; } $sale_mode = 'buy_now'; // check sale mode foreach ($item_ids as $item_id) { $item = $this->ebay_model->fetch_ebay_item_by_item_id($item_id); if (isset($item->listing_type)) { $sale_mode = $item->listing_type; break; } } if ($sale_mode == 'buy_now') { $eshop_list_fee_multiply = 1; $eshop_list_count = 100; } else { $bid_rate = 30; $eshop_list_fee_multiply = 1 + (100 - $bid_rate) / $bid_rate; $eshop_list_count = 1; } $i = 0; foreach ($skus as $sku) { $qty = $qties[$i]; $product = $this->product_model->fetch_product_by_sku($sku); $product_cost += $product->price * $qty; $shipping_weight += $product->total_weight * $qty; $i++; } $eshop_codes = array('USD' => 'ebay-USA', 'AUD' => 'ebay-AU', 'GBP' => 'ebay-UK', 'EUR' => 'ebay-FR'); $input = array('eshop_code' => $eshop_codes[$currency], 'buyer_shipping_cost' => 0, 'shipping_type' => $shipping_type, 'shipping_country' => $country_name_cn, 'total_weight' => $shipping_weight, 'sale_mode' => $sale_mode, 'eshop_category' => 0, 'suggest_price' => $gross, 'key' => TRUE, 'total_price' => $product_cost, 'balance_profit' => 0.3, 'eshop_list_count' => $eshop_list_count, 'eshop_list_fee_multiply' => $eshop_list_fee_multiply, 'pay_option' => 0, 'pay_discount' => 0, 'other_cost' => $other_cost, 'paypal_cost' => $fee); $data = price_profit_rate($input); if (!is_array($data)) { $this->user_note = lang('not_profit_rate_note'); return FALSE; } $profit_rate = price($data['total_profit_rate']); $this->profit_rate = $profit_rate; $this->sale_mode = $sale_mode; $this->user_note = ''; if ($profit_rate < 0) { if ($sale_mode == 'buy_now' or $profit_rate < -0.3) { $product_cost = $data['product_cost']; $shipping_cost = $data['shipping_cost']; $trade_fee_rmb = price($data['trade_fee']); $list_fee_rmb = price($data['list_fee']); $this->user_note = sprintf(lang('wait_for_confirmation_user_note'), $profit_rate, $gross_rmb, $fee_rmb, $trade_fee_rmb, $list_fee_rmb, $product_cost, $shipping_cost, $other_cost); return FALSE; } } return TRUE; }