Exemplo n.º 1
0
 public function _merge_order($to_merge_order_id, $data)
 {
     $transaction_id = $data['transaction_id'];
     $to_merge_order = $this->order_model->get_order($to_merge_order_id);
     $currency = $data['currency'];
     $gross = $data['gross'];
     $fee = $data['fee'];
     $shippingamt = $data['shippingamt'];
     $item_title_str = $data['item_title_str'];
     $item_id_str = $data['item_id_str'];
     $sku_str = $data['sku_str'];
     $qty_str = $data['qty_str'];
     $to_merged_item_ids = explode(',', $to_merge_order->item_id_str);
     $transaction_ids = array();
     foreach ($to_merged_item_ids as $item_id) {
         $transaction_ids[] = $to_merge_order->transaction_id;
     }
     $item_ids = explode(',', $item_id_str);
     foreach ($item_ids as $item_id) {
         $transaction_ids[] = $transaction_id;
     }
     // starting merging
     if ($to_merge_order->currency == $currency) {
         $new_gross = $to_merge_order->gross + $gross;
         $new_fee = $to_merge_order->fee + $fee;
         $new_shippingamt = $to_merge_order->shippingamt + $shippingamt;
     } else {
         $tmp_rmb = calc_currency($currency, $gross);
         $new_gross = $to_merge_order->gross + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb));
         $tmp_rmb = calc_currency($currency, $fee);
         $new_fee = $to_merge_order->fee + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb));
         $tmp_rmb = calc_currency($currency, $shippingamt);
         $new_shippingamt = $to_merge_order->shippingamt + price(to_foreigh_currency($to_merge_order->currency, $tmp_rmb));
     }
     $new_net = $new_gross - $new_fee;
     $new_title = $to_merge_order->item_title_str . ITEM_TITLE_SEP . $item_title_str;
     $new_id = $to_merge_order->item_id_str . ',' . $item_id_str;
     $new_sku_str = $to_merge_order->sku_str . ',' . $sku_str;
     $new_amount = $to_merge_order->qty_str . ',' . $qty_str;
     $sys_remark = $to_merge_order->sys_remark . ', ' . sprintf(lang('merge_log'), get_current_time(), $transaction_id);
     $data = array('gross' => $new_gross, 'fee' => $new_fee, 'net' => $new_net, 'item_title_str' => $new_title, 'item_id_str' => $new_id, 'sku_str' => $new_sku_str, 'qty_str' => $new_amount, 'sys_remark' => $sys_remark, 'is_merged' => 1, 'shippingamt' => $new_shippingamt);
     $sku_price = 0;
     $sku_weight = 0;
     $tmp_i = 0;
     $tmp_skus = explode(',', $new_sku_str);
     $tmp_qties = explode(',', $new_amount);
     foreach ($tmp_skus as $tmp_sku) {
         $tmp_qty = $tmp_qties[$tmp_i];
         $product = $this->product_model->fetch_product_by_sku($tmp_sku);
         $sku_price += $product->price * $tmp_qty;
         $sku_weight += $product->total_weight * $tmp_qty;
         $tmp_i++;
     }
     $order_data = array('item_id_str' => $new_id, 'gross' => $new_gross, 'net' => $new_net, 'currency' => $currency, 'transaction_ids' => $transaction_ids, 'shipping_code' => $to_merge_order->is_register, 'price' => $sku_price, 'shipping_weight' => $sku_weight, 'country' => $to_merge_order->country);
     $profit = $this->_calculate_profit_rate($order_data);
     $data['profit_rate'] = $profit['profit_rate'];
     $data['shipping_cost'] = $profit['shipping_cost'];
     $data['product_cost_all'] = $profit['product_cost'];
     $data['trade_fee'] = $profit['trade_fee'];
     $data['listing_fee'] = $profit['listing_fee'];
     // order role
     $order_role = $this->_get_order_role($data['sku_str'], $to_merge_order->to_email);
     $data['stock_user_id'] = $order_role['stock_user_id'];
     $data['purchaser_id_str'] = $order_role['purchaser_id_str'];
     $data['developer_id'] = $order_role['developer_id'];
     $data['saler_id'] = $order_role['saler_id'];
     $data['tester_id'] = $order_role['tester_id'];
     // promote shipping code from P to PT if in need.
     if ($to_merge_order->is_register == 'P' || 1 == 1) {
         $args = array('gross_usd' => to_usd($currency, $new_gross));
         //$tmp_shipping_code = regular_shipping_code($args);
         $item_info = array('item_qties' => explode(',', $new_amount), 'item_codes' => explode(',', $new_sku_str), 'item_ids' => explode(',', $new_id), 'ship_to_country' => $to_merge_order->country, 'gross' => $new_gross, 'gross_usd' => $this->order_model->to_usd($currency, $new_gross));
         $tmp_shipping_code = get_register($item_info, '', $currency, array($transaction_id, $to_merge_order->transaction_id));
         if ($to_merge_order->is_register != $tmp_shipping_code) {
             $data['is_register'] = $tmp_shipping_code;
             $data['item_no'] = change_item_register($to_merge_order->item_no, $to_merge_order->is_register, $tmp_shipping_code);
         }
     }
     $this->order_model->update_order_information($to_merge_order_id, $data);
     $this->paypal_model->save_merged_list(array('order_id' => $to_merge_order_id, 'transaction_id' => $transaction_id, 'item_title_str' => $item_title_str, 'item_id_str' => $item_id_str, 'buyer_id' => $to_merge_order->buyer_id, 'buyer_name' => $to_merge_order->name));
     return TRUE;
 }
Exemplo n.º 2
0
 public function auto_outstock($stock_code)
 {
     if (strpos($_SERVER['SCRIPT_FILENAME'], 'auto_abroad_outstock.php') === FALSE) {
         exit;
     }
     $this->auto_stock_check($stock_code);
     switch ($stock_code) {
         case 'uk':
             $stock_codes = array('UK');
             $stock_count = 'uk_stock_count';
             $shipping_codes = $this->shipping_code_model->cky_fetch_all_shipping_codes($stock_codes);
             break;
         case 'de':
             $stock_codes = array('DE');
             $stock_count = 'de_stock_count';
             $shipping_codes = $this->shipping_code_model->cky_fetch_all_shipping_codes($stock_codes);
             break;
         case 'au':
             $stock_codes = array('AU');
             $stock_count = 'au_stock_count';
             $shipping_codes = $this->shipping_code_model->cky_fetch_all_shipping_codes($stock_codes);
             break;
         case 'yb':
             $stock_codes = array('YB');
             $stock_count = 'yb_stock_count';
             $shipping_codes = $this->shipping_code_model->cky_fetch_all_shipping_codes($stock_codes);
             break;
         default:
             return;
     }
     $order_status = array('wait_for_shipping_label');
     $order_result = $this->fetch_orders($order_status, $shipping_codes);
     $order_count = count($order_result);
     $order_sign = '';
     if ($order_count) {
         $data = array();
         $data['Sign'] = '';
         $data['StorageCode'] = strtoupper($stock_code);
         $data['Remark'] = '';
         $result = $this->cky_order->outstore_add($data);
         if ($result) {
             if ($result['status']) {
                 $order_sign = $result['order_sign'];
             } else {
                 echo $result['message'], "\n";
                 die('');
             }
         } else {
             die('Error!');
         }
     } else {
         return;
     }
     $submited_orders = array();
     $shipping_confirmation = fetch_status_id('order_status', 'wait_for_shipping_confirmation');
     $customer_confirmation = fetch_status_id('order_status', 'wait_for_confirmation');
     $countries = array('Russia' => 'Russian Federation', 'Croatia' => 'Croatia, Republic of');
     foreach ($order_result as $row) {
         $oid = $row->oid;
         $country = isset($countries[$row->country]) ? $countries[$row->country] : $row->country;
         /* united kingdom should use PTE. */
         $save_is_register = $row->is_register;
         $row->is_register = $this->_change_shipping_type($row->country, $row->is_register);
         /* should change item no if shipping code changes */
         if ($save_is_register != $row->is_register) {
             $row->item_no = change_item_register($row->item_no, $save_is_register, $row->is_register);
         }
         $shipping_code_obj = $this->shipping_code_model->fetch_name_by_shipping_code($row->is_register);
         $shipping_name = $shipping_code_obj->taobao_company_code;
         $service = empty($shipping_code_obj->is_tracking) ? '' : 'Tracking';
         $zip_code = empty($row->zip_code) ? 0 : $row->zip_code;
         if (!cky_check_shipping_support($row->is_register, $row->country)) {
             $order_data = array('descript' => $row->descript . '  ' . lang('abroad_not_support_please_correct'), 'order_status' => $customer_confirmation, 'sys_remark' => $row->sys_remark . ',' . sprintf(lang('cky_back_to_customer_confirmation_remark'), get_current_time(), 'script'));
             $this->order_model->update_order_information($oid, $order_data);
             continue;
         }
         /*
          * check if there is more than one sku.
          */
         if (strpos($row->sku_str, ',') === FALSE) {
             $data = array();
             $data['Title'] = $row->sku_str;
             $data['Quantity'] = $row->qty_str;
             $data['TransactionID'] = $oid;
             $data['Consignee'] = $row->name;
             $data['AddressLine1'] = $row->address_line_1;
             $data['AddressLine2'] = $row->address_line_2;
             $data['Phone'] = $row->contact_phone_number;
             $data['City'] = $row->town_city;
             $data['Province'] = $row->state_province;
             $data['Country'] = $country;
             $data['PostCode'] = $zip_code;
             $data['Shipping'] = $shipping_name;
             $data['Service'] = $service;
             $data['Remark'] = '';
             $data['OrderNo'] = $order_sign;
             $result = $this->cky_order->outstore_product_add($data);
             if ($result && $result['status']) {
                 echo $oid, " is submited\n";
                 $submited_orders[] = $row;
             } else {
                 echo $oid, "  ";
                 var_dump($result);
             }
         } else {
             $skus = explode(',', $row->sku_str);
             $qties = explode(',', $row->qty_str);
             $titles = explode(ITEM_TITLE_SEP, $row->item_title_str);
             $sku_not_allowed = FALSE;
             foreach ($titles as $title) {
                 if (!cky_get_shipping_code($title, $row->input_user)) {
                     $sku_not_allowed = TRUE;
                     echo $title, " is not allowed \n";
                     break;
                 }
             }
             if ($sku_not_allowed) {
                 $order_data = array('order_status' => $customer_confirmation, 'descript' => $row->descript . '  ' . lang('abroad_not_support_please_correct'), 'sys_remark' => $row->sys_remark . ',' . sprintf(lang('cky_back_to_customer_confirmation_remark'), get_current_time(), 'script'));
                 $this->order_model->update_order_information($oid, $order_data);
                 continue;
             }
             $data_package = array();
             $data_package['TransactionID'] = $oid;
             $data_package['Consignee'] = $row->name;
             $data_package['AddressLine1'] = $row->address_line_1;
             $data_package['AddressLine2'] = $row->address_line_2;
             $data_package['Phone'] = $row->contact_phone_number;
             $data_package['City'] = $row->town_city;
             $data_package['Province'] = $row->state_province;
             $data_package['Country'] = $country;
             $data_package['PostCode'] = $zip_code;
             $data_package['Shipping'] = $shipping_name;
             $data_package['Service'] = $service;
             $data_package['Remark'] = '';
             $data_package['OrderNo'] = $order_sign;
             $result = $this->cky_order->outstore_package_add($data_package);
             if ($result && $result['status']) {
                 $package_sign = $result['order_sign'];
                 $products = array();
                 $i = 0;
                 foreach ($skus as $sku) {
                     $products[] = array('Title' => $sku, 'Quantity' => $qties[$i]);
                     $i++;
                 }
                 $result = $this->cky_order->outstore_package_product_add($products, $package_sign, $order_sign);
                 if ($result && $result['status']) {
                     echo $oid, " is submited\n";
                     $submited_orders[] = $row;
                 } else {
                     var_dump($result);
                 }
             } else {
                 var_dump($result);
             }
         }
     }
     $result = FALSE;
     if (count($submited_orders)) {
         $result = $this->cky_order->outstore_submit(array('OrderNo' => $order_sign));
     }
     // update order status to wait for shipping.
     if ($result && $result['status']) {
         foreach ($submited_orders as $row) {
             $oid = $row->oid;
             $skus = explode(',', $row->sku_str);
             $qties = explode(',', $row->qty_str);
             $sku_count = count($skus);
             $shipping_weight = 0;
             for ($i = 0; $i < $sku_count; $i++) {
                 $sku = $skus[$i];
                 $qty = $qties[$i];
                 $temp_product = $this->product_model->fetch_product_by_sku($sku, "{$stock_count}, total_weight");
                 $temp_stock_count = $temp_product->{$stock_count};
                 $data = array($stock_count => $temp_stock_count - $qty);
                 $this->product_model->update_product_by_sku($sku, $data);
                 $shipping_weight += $temp_product->total_weight * $qty;
             }
             $order_data = array('order_status' => $shipping_confirmation, 'ship_weight' => $shipping_weight, 'sys_remark' => $row->sys_remark . ',' . sprintf(lang('cky_wait_for_shipping_remark'), get_current_time(), 'script'), 'is_register' => $row->is_register, 'item_no' => $row->item_no);
             echo "{$oid}, start updating order information\n";
             $this->order_model->update_order_information($oid, $order_data);
         }
         echo $oid, ", {$order_sign} start saving outstock, \n";
         $this->abroad_stock_model->save_outstock($order_sign);
     } else {
         echo 'Ending....', "\n";
         var_dump($result);
     }
 }
Exemplo n.º 3
0
 public function make_batch_confirmed()
 {
     $order_count = $this->input->post('order_count');
     if ($order_count < 1) {
         echo $this->create_json(0, lang('ok'));
         return;
     }
     $user_name = $this->get_current_user_name();
     for ($i = 0; $i < $order_count; $i++) {
         $order_id = $this->input->post('order_id_' . $i);
         $item_id_string = trim(trim($this->input->post('item_id_string_' . $i)), ',');
         $sku_string = trim(trim($this->input->post('sku_string_' . $i)), ',');
         $qty_string = trim(trim($this->input->post('qty_string_' . $i)), ',');
         $phone = trim($this->input->post('phone_' . $i));
         $shipping_way = trim($this->input->post('shipping_way_' . $i));
         $note = trim($this->input->post('note_' . $i));
         $item = $this->order_model->get_order_item($order_id);
         if (strtoupper($item->country) != 'UNITED STATES' && $shipping_way == 'EUB') {
             echo $this->create_json(0, "NOT UNITED STATES,Don't Use EUB");
             return;
         }
         // double check the order status.
         if ($item->order_status != $this->order_statuses['wait_for_confirmation'] && $item->order_status != $this->order_statuses['holded']) {
             continue;
         }
         $new_item_no = change_item_register($item->item_no, $item->is_register, $shipping_way);
         $this->merge_items($item_id_string, $sku_string, $qty_string);
         $remark = $this->order_model->get_sys_remark($order_id);
         $remark .= sprintf(lang('batch_confirm_order_remark'), date('Y-m-d H:i:s'), $user_name);
         $skus = explode(',', $sku_string);
         $sku_not_exists = FALSE;
         foreach ($skus as $sku) {
             if (!$this->product_model->fetch_product_id(strtoupper($sku))) {
                 $sku_not_exists = TRUE;
                 break;
             }
         }
         if ($sku_not_exists) {
             continue;
         }
         $data = array('item_id_str' => $item_id_string, 'sku_str' => $sku_string, 'qty_str' => $qty_string, 'contact_phone_number' => $phone, 'is_register' => $shipping_way, 'item_no' => $new_item_no, 'descript' => $note, 'note' => $note, 'order_status' => $this->order_statuses['wait_for_purchase'], 'check_user' => $user_name, 'check_date' => date('Y-m-d H:i:s'), 'bursary_check_user' => $user_name, 'bursary_check_date' => date('Y-m-d H:i:s'), 'sys_remark' => $remark);
         try {
             $phone_requred = $this->order_model->fetch_contact_phone_requred($shipping_way);
             if ($phone_requred and $phone == null) {
                 echo $this->create_json(0, lang('phone_requred'));
                 continue;
             }
             // eub can't be used twice
             if ($shipping_way == 'H' && $this->order_model->check_epacket_exists($item->id, $item->transaction_id)) {
                 echo $this->create_json(0, lang('epacket_cannot_be_used_twice'));
                 continue;
             }
             $this->order_model->update_order_information($order_id, $data);
             if ($sku_string != $item->sku_str or $qty_string != $item->qty_str or $shipping_way != $item->is_register) {
                 // auto verify order before print label
                 $this->events->trigger('verify_order_before_print_label', array('order_id' => $order_id));
             }
         } catch (Exception $e) {
             echo lang('error_msg');
             $this->ajax_failed();
         }
     }
     echo $this->create_json(1, lang('ok'));
 }
 public function give_order_back_to_shipping()
 {
     $order_id = $this->input->post('order_id');
     $is_register = $this->input->post('is_register');
     $shipping_remark = $this->input->post('shipping_remark');
     $track_number = $this->input->post('track_number');
     $weight = $this->input->post('weight');
     $item = $this->order_model->get_order_item($order_id);
     $new_item_no = change_item_register($item->item_no, $item->is_register, $is_register);
     $sys_remark = $item->sys_remark . ',' . sprintf(lang('feedback_to_shipping_remark'), get_current_time(), get_current_login_name());
     $data = array('is_register' => $is_register, 'item_no' => $new_item_no, 'ship_weight' => '', 'track_number' => strtoupper($track_number), 'order_status' => $this->order_statuses['wait_for_shipping_confirmation'], 'descript' => $shipping_remark, 'sys_remark' => $sys_remark);
     try {
         $user_name = get_current_login_name();
         $type_extra = $user_name . '/' . date('Y-m-d H:i:s');
         $this->product_model->update_product_stock_count_by_order_id($order_id, 'label_instock', $type_extra, FALSE);
         $this->order_model->update_order_information($order_id, $data);
     } catch (Exception $e) {
         echo lang('error_msg');
         $this->ajax_failed();
     }
 }
Exemplo n.º 5
0
 private function _merge_order($to_merged_id, $transaction_details)
 {
     $order_obj = $this->paypal_model->get_order_info_for_merge($to_merged_id);
     if (!$order_obj) {
         return $this->_waiting_comfirmed_order($transaction_details);
     }
     $gross = $order_obj->gross;
     $fee = $order_obj->fee;
     $shippingamt = $order_obj->shippingamt;
     $currency = $order_obj->currency;
     $item_title = $order_obj->item_title_str;
     $item_id = $order_obj->item_id_str;
     $sm_products_code = $order_obj->sku_str;
     $amount = $order_obj->qty_str;
     $item_no = $order_obj->item_no;
     $is_register = $order_obj->is_register;
     $item_info = array('item_titles' => array_merge(explode(ITEM_TITLE_SEP, $item_title), $this->item_info['item_titles']), 'item_ids' => array_merge(explode(',', $item_id), $this->item_info['item_ids']), 'item_codes' => array_merge(explode(',', $sm_products_code), $this->item_info['item_codes']), 'item_qties' => array_merge(explode(',', $amount), $this->item_info['item_qties']));
     $item_info = $this->_merge_duplicated_order($item_info);
     if ($currency == $transaction_details['CURRENCYCODE']) {
         $new_gross = $gross + $transaction_details['AMT'];
         $new_fee = $fee + $transaction_details['FEEAMT'];
         $new_shippingamt = $shippingamt + $transaction_details['SHIPPINGAMT'];
     } else {
         $tmp_rmb = calc_currency($transaction_details['CURRENCYCODE'], $transaction_details['AMT']);
         $new_gross = $gross + price(to_foreigh_currency($currency, $tmp_rmb));
         $tmp_rmb = calc_currency($transaction_details['CURRENCYCODE'], $transaction_details['FEEAMT']);
         $new_fee = $fee + price(to_foreigh_currency($currency, $tmp_rmb));
         $tmp_rmb = calc_currency($transaction_details['CURRENCYCODE'], $transaction_details['SHIPPINGAMT']);
         $new_shippingamt = $shippingamt + price(to_foreigh_currency($currency, $tmp_rmb));
     }
     echo "{$new_gross}, {$new_fee}, {$new_shippingamt}\n";
     echo "currency: {$currency}\n";
     echo "transaction_details: {$transaction_details['CURRENCYCODE']}\n";
     echo "gross: {$gross}, {$transaction_details['AMT']}\n";
     echo "fee: {$fee}, {$transaction_details['FEEAMT']}\n";
     echo "shippingamt: {$shippingamt}, {$transaction_details['SHIPPINGAMT']}\n";
     $paypal_transaction_id = array($transaction_details['TRANSACTIONID'], $order_obj->transaction_id);
     $new_net = $new_gross - $new_fee;
     $new_title = implode(ITEM_TITLE_SEP, $item_info['item_titles']);
     $new_id = implode(',', $item_info['item_ids']);
     $new_sm_products_code = implode(',', $item_info['item_codes']);
     $new_amount = implode(',', $item_info['item_qties']);
     $new_gross_usd = $this->order_model->to_usd($currency, $new_gross);
     $item_info['gross_usd'] = $new_gross_usd;
     $item_info['gross'] = $new_gross;
     $new_is_register = get_register($item_info, $this->user, $currency, $paypal_transaction_id);
     $new_item_no = change_item_register($item_no, $is_register, $new_is_register);
     $order_status = $this->order_statuses['wait_for_confirmation'];
     $data = array('transaction_id' => $transaction_details['TRANSACTIONID'], 'gross' => $new_gross, 'fee' => $new_fee, 'net' => $new_net, 'shippingamt' => $new_shippingamt, 'item_title_str' => $new_title, 'item_id_str' => $new_id, 'sku_str' => $new_sm_products_code, 'qty_str' => $new_amount, 'is_register' => $new_is_register, 'item_no' => $new_item_no, 'order_status' => $order_status);
     $sys_remark = $this->_create_sys_remark('merged_order', $transaction_details['TRANSACTIONID']);
     $this->paypal_model->merge_order($to_merged_id, $data, $sys_remark);
     $this->report['merged_order']++;
 }