Пример #1
0
     }
 } else {
     die('Error in asins of aws_asin');
 }
 $upc = $row['upc'];
 if (!empty($row['amazon_quantity']) or !is_null($row['amazon_quantity'])) {
     $quantity = $row['amazon_quantity'];
 } else {
     die("Quantity Null");
 }
 if (trim($price_formula) == "001") {
     $ebay_price = price_basic_profit_percetage($amazon_price, $profit_percentage);
 } elseif (trim($price_formula) == "002") {
     $ebay_price = price_basic_amount_profit($amazon_price, $profit_percentage);
 } elseif (trim($price_formula) == "003") {
     $ebay_price = price_formula_profit_percentage($amazon_price, $profit_percentage);
 } elseif (trim($price_formula) == "004") {
     $ebay_price = price_basic_amount_profit($amazon_price, $profit_percentage);
 } else {
     die('Something Gone Wrong on Profit Calculation');
 }
 $profit_ratio = $profit_percentage;
 $in_amazon = true;
 $prime = $row['prime'];
 $ratio = $row['profit_ratio'];
 if ($prime == 'Yes' && $ratio < 2) {
     $ebay_price = $amazon_price * (1 + $ratio) / 0.87;
 } else {
     if ($prime == 'Yes' && $ratio >= 2) {
         $ebay_price = ($amazon_price + $ratio) / 0.87;
     }
 function insert_into__scrape_aliexpress($data)
 {
     require_once 'redirect.php';
     require_once 'profit_calculation.php';
     $active_user = $_SESSION['user_id'];
     $sql_ebay_config = "SELECT \n                            max_quantity,\n                            price_formula,\n                            profit_percentage\n         FROM   ebay_config \n         WHERE \n                user_id={$active_user}";
     $rs_config = mysql_query($sql_ebay_config) or die('Something Wrong...!');
     if (mysql_num_rows($rs_config) != 1) {
         die('Someting Wrong..!');
     }
     $row_config = mysql_fetch_assoc($rs_config);
     $max_quantity = $row_config['max_quantity'];
     $price_formula = $row_config['price_formula'];
     $profit_percentage = $row_config['profit_percentage'];
     $asin = $data['itemid'];
     //$title=str_replace("'","\'",$data['title']);
     $title = addslashes($data['title']);
     $title = str_replace("&#x27;", "\\'", $title);
     $description = str_replace("'", "\\'", $data['description']);
     $features = str_replace("'", "\\'", $data['features']);
     $j = 0;
     while ($data['pictures' . $j] != "") {
         $pictures[] = $data['pictures' . $j];
         $j++;
     }
     $thumbpictures = "";
     if (count($pictures) > 0) {
         $thumbpictures = implode(',', $pictures);
     }
     //echo $pictures;die;
     $image = $data['imageurl'];
     $price = $data['price'];
     $offer_price = explode('-', trim($price));
     $offer_price = number_format((double) $offer_price[0], 2, '.', '');
     $prime = $data['prime'];
     // $brand=$data['brand'];
     $aliexpress_quantity = $data['quantity'];
     $currency_code = "USD";
     $aws_asin_insert_sql = "INSERT INTO aws_asin(UserId,asin,title,description,\n                                                    features,large_image_url,thumb_img,\n                                                    prime,offer_price,\n                                                    currency_code,quantity,processed) \n                                                    \n                                VALUES \n                                                    ({$active_user},'{$asin}','" . $title . "','{$description}',\n                                                     '{$features}','{$image}','{$thumbpictures}',\n                                                     '{$prime}','{$offer_price}',\n                                                     '{$currency_code}',{$aliexpress_quantity},2)";
     // echo  $aws_asin_insert_sql;die;
     $asins_table_update_sql = "UPDATE asins_table SET processed=1 WHERE asins='{$asin}' AND UserID = {$active_user}";
     mysql_query($aws_asin_insert_sql) and mysql_query($asins_table_update_sql) or die(mysql_error());
     $sql_success = "SELECT asin FROM aws_asin WHERE asin='{$asin}' AND UserID='{$active_user}'";
     $rs_sucess = mysql_query($sql_success) or die(mysql_error());
     //
     if (mysql_num_rows($rs_sucess)) {
         $offer_price = str_replace(array('$' . ','), '', $offer_price);
         $offer_price = floatval($offer_price);
         $ebay_select_sql = "SELECT asins FROM ebay_asin WHERE asins='{$asin}' AND UserID='{$active_user}'";
         $ebay_asin_result = mysql_query($ebay_select_sql) or die(mysql_error());
         if (!mysql_num_rows($ebay_asin_result)) {
             //
             if ($offer_price == 'Not Available' or !isset($offer_price)) {
                 $offer_price = $list_price;
             }
             //
             $temp_title = str_replace(',', ' ', $title);
             $title_words = explode(' ', $temp_title);
             $new_title = trim("New ");
             foreach ($title_words as $title_word) {
                 $title_word = trim($title_word);
                 if ($title_word == '' || empty($title_word)) {
                     continue;
                 }
                 if (strlen($new_title) + strlen($title_word) >= 80) {
                     break;
                 }
                 if (trim($new_title) != '') {
                     $new_title .= " " . $title_word;
                 }
             }
             // New Title got...
             //
             if (trim($price_formula) == "001") {
                 $ebay_price = price_basic_profit_percetage($offer_price, $profit_percentage);
             } elseif (trim($price_formula) == "002") {
                 $ebay_price = price_basic_amount_profit($offer_price, $profit_percentage);
             } elseif (trim($price_formula) == "003") {
                 $ebay_price = price_formula_profit_percentage($offer_price, $profit_percentage);
             } elseif (trim($price_formula) == "004") {
                 $ebay_price = price_basic_amount_profit($offer_price, $profit_percentage);
             } else {
                 die('Something Gone Wrong on Profit Calculation');
             }
             // $profit_ratio = round(bcsub(bcdiv($ebay_price, $offer_price, 8), 1, 8),2);
             $profit_ratio = $profit_percentage;
             //$temp_price = bcadd(bcmul($offer_price, 100), bcmul($offer_price, 25));
             //$ebay_price = bcadd(bcmul($temp_price, 0.01, 4), 0.01, 2);
             //
             //$title=addslashes($data['title']);
             //$title=str_replace("&#x27;","\'",$title);
             //
             $insert_ebay_asin_sql = "INSERT INTO ebay_asin(\n                                                 UserID,asins,ebay_title,prefix,\n                                                 ebay_price,amazon_price,\n                                                 handling_time,shipping_option,return_option,profit_percent,\n                                                 profit_ratio,amazon_quantity,max_quantity\n                                                 ) \n                            \n                                                VALUES (\n                                                {$active_user},'{$asin}','{$new_title}','New ',\n                                                 {$ebay_price}, {$offer_price} ,\n                                                 1,'free','ReturnsAccepted',{$profit_percentage},\n                                                 {$profit_ratio},{$aliexpress_quantity},{$max_quantity}\n                        )";
             mysql_query($insert_ebay_asin_sql) or die(mysql_error());
         }
         $this->no_inserted_asins++;
     }
 }