コード例 #1
0
 static function change_quantity_and_calculators_price_query($quantity, $print_details_obj, $YPriceParam)
 {
     global $mysqli;
     $level = isset($print_details_obj->level) ? $print_details_obj->level : 'full';
     $query = "SELECT*FROM `" . BASE__CALCULATORS_PRICE_TABLES_TBL . "` WHERE `print_type_id` = '" . $print_details_obj->print_id . "' AND `level` = '" . $level . "'  ORDER by id, param_val";
     //echo $query;
     $result = $mysqli->query($query) or die($mysqli->error);
     /**/
     if ($result->num_rows > 0) {
         $priceIn_tblXindex = 0;
         while ($row = $result->fetch_assoc()) {
             //print_r($row);
             if ($row['param_val'] == 0) {
                 // здесь мы определяем в какой диапазон входит новое количество
                 for ($i = 1; isset($row[$i]); $i++) {
                     // если оно меньше минимального тиража
                     //if($row[$i] > $quantity) break;
                     if ($row['price_type'] == 'in') {
                         if ($quantity < $row[1]) {
                             $newIn_Xindex = 1;
                             $lackOfQuantInPrice = true;
                             $minQuantInPrice = $row[1];
                         } else {
                             if ($row[$i] > 0 && $quantity >= $row[$i]) {
                                 $newIn_Xindex = $i;
                             }
                         }
                         if ($row[$i] > 0) {
                             $in_limit = $row[$i];
                             $in_limitIndex = $i;
                         }
                     }
                     if ($row['price_type'] == 'out') {
                         if ($quantity < $row[1]) {
                             $newOut_Xindex = 1;
                             $lackOfQuantOutPrice = true;
                             $minQuantOutPrice = $row[1];
                         } else {
                             if ($quantity >= $row[$i] && $row[$i] > 0) {
                                 $newOut_Xindex = $i;
                             }
                         }
                         if ($row[$i] > 0) {
                             $out_limit = $row[$i];
                             $out_limitIndex = $i;
                         }
                     }
                 }
             }
             // определяем новые входящие и исходящие цены
             if ($row['price_type'] == 'in' && $row['param_val'] == $YPriceParam) {
                 $new_priceIn = $row[$newIn_Xindex];
             }
             if ($row['price_type'] == 'out' && $row['param_val'] == $YPriceParam) {
                 $new_priceOut = $row[$newOut_Xindex];
             }
         }
         $out = array("price_in" => $new_priceIn, "price_out" => $new_priceOut);
         // если тираж был меньше минимального значения в прайсе пересчитываем цены
         if (isset($lackOfQuantIntPrice) && $lackOfQuantInPrice == true) {
             $out['price_in'] = $new_priceIn * $minQuantInPrice / $quantity;
             self::$lackOfQuantity = true;
             self::$lackOfQuantityDetails[] = array('minQuantity' => (int) $minQuantInPrice, 'print_type' => $print_details_obj->print_type);
         }
         if (isset($lackOfQuantOutPrice) && $lackOfQuantOutPrice == true) {
             $out['price_out'] = $new_priceOut * $minQuantOutPrice / $quantity;
             self::$lackOfQuantity = true;
             self::$lackOfQuantityDetails[] = array('minQuantity' => (int) $minQuantOutPrice, 'print_type' => $print_details_obj->print_type);
         }
         //echo $newIn_Xindex .' - '. $in_limitIndex;  echo "\r" ;
         //echo $newOut_Xindex .' - '. $out_limitIndex;
         // если полученная цена оказалась равна 0 то значит стоимость не указана
         if ((double) $out['price_in'] == 0 || (double) $out['price_out'] == 0) {
             // если это последние ряды прайс значит это лимит
             if ($newIn_Xindex == $in_limitIndex) {
                 self::$outOfLimit = true;
                 self::$outOfLimitDetails[] = array('limitValue' => (int) $in_limit, 'print_type' => $print_details_obj->print_type);
             } elseif ($newOut_Xindex == $out_limitIndex) {
                 self::$outOfLimit = true;
                 self::$outOfLimitDetails[] = array('limitValue' => (int) $out_limit, 'print_type' => $print_details_obj->print_type);
             } else {
                 //иначе это индивидуальный расчет cancelCalculator
                 if (!self::$outOfLimit) {
                     self::$needIndividCalculation = true;
                     self::$needIndividCalculationDetails[] = array('print_type' => $print_details_obj->print_type);
                 }
             }
         }
         // echo "\r \$YPriceParam - ".$YPriceParam."\r In".$newIn_Xindex.' '.$new_priceIn; echo "\r Out".$newOut_Xindex.' '.$new_priceOut."\r";
         return $out;
     }
 }