'ok', 'err' => ''); try { if (empty($_POST) || empty($_POST["pa"])) throw new \Exception("parameter empty"); foreach ($_POST as $k => $v) { $$k = htmlspecialchars(stripslashes(trim($v))); } if (empty($pa)) throw new \Exception("parameter empty[2]"); $opt = ""; if (strpos($pa, ",")) list($id, $opt) = explode(",", $pa); else $id = $pa; $person2weight_arr = [ "6" => "450", "8" => "550", "9" => "600", "10" => "700", "11" => "750", "12" => "800", "13" => "900", "15" => "1000", "17" => "1150", "20" => "1350", "24" => "1600"]; $mi_arr = []; $i = $weight = 0; $sql = "select note, item_qty, item_weight, item_op, item_spec from pricereview_item where mid = '$id' and item_group = 'A' order by item_no"; $res = mysqli_query($link, $sql); while ($row = mysqli_fetch_row($res)) { list($etype, $persons, $floors, $speed) = explode(",", $row[0]); $item_qty = $row[1]; // 數量 $item_weight = $row[2]; // 載重 $item_op = $row[3]; // 開門方式 $item_spec = $row[4]; // 電梯規格 $sql2 = "select o.*, r.* from elevator_mi_option o, elevator_quotation_rule r "; $sql2 .= "where o.quotation_no = r.quotation_no and o.elevator_type = '$etype' "; $sql2 .= "and ($item_weight between o.min_weight and o.max_weight) "; $sql2 .= "and ($floors between o.min_floors and o.max_floors) "; $sql2 .= "and ($speed between o.min_speed and o.max_speed) "; if ($etype == "MAQ100" || $etype == "MAP100") { $sql2 .= "and (o.model_no = '$persons') "; } $res_e = mysqli_query($link, $sql2); if ($row_e = mysqli_fetch_assoc($res_e)) { // 基准采购成本+±1停材料费+设计费+出口费用 $part1 = $row_e["purchase_cost"]+($floors-$row_e["base_floor"])*$row_e["material_plus"]+$row_e["design"]*$row_e["design_hour"]+$row_e["export_fee"]; // 利潤 $profit = round($part1*$row_e["profit"]+$row_e["equip_profit"], 0); // 設備 $equipment_ntd = round(($part1+$profit)*$row_e["equipment"], 0); // 報關+運輸 $customs = round($equipment_ntd*$row_e["shipping"], 0)+$row_e["customs_shipping"]; // 安裝基價 $install_base = $row_e["install_price"]+$row_e["trial_price"]+$row_e["install_coef"]*$row_e["install_plus"]+$row_e["trial_coef"]*$row_e["trial_plus"]; // 安裝成本 $install_price = round($install_base+($row_e["install_plus"]+$row_e["trial_plus"])*($floors-$row_e["base_floor"]), 0); // 起吊+木箱+耗材 $woods = $row_e["crane"]+$row_e["wooden_box"]+$row_e["consume"]+$row_e["consumables"]; // MI $mi = $equipment_ntd+$customs+$row_e["unloading"]+$row_e["transport_site"]+$install_price+$row_e["free1y"]+$woods+$row_e["option_price"]; /* $install_price = $row_e["install_price"] + $row_e["install_plus"]*($floors - $row_e["min_floors"]); // 安裝 $trial_price = $row_e["trial_price"] + $row_e["trial_plus"]*($floors - $row_e["min_floors"]); // 試車 $extra_fee = round($row_e["install_price"]*$row_e["extra_rate"], 0); // 預抓配合工程 // 安裝成本 $install_cost_total = $install_price + $trial_price + $extra_fee + $row_e["crane"] + $row_e["wooden_box"] + $row_e["consume"] + $row_e["consumables"]; // 設計費 $design_fee = $row_e["design"]*$row_e["design_hour"]; // 利潤 if (strpos($row_e["profit"], ".") !== false) { $profit_amt = round(($row_e["purchase_cost"] + ($floors - $row_e["base_floor"])*$row_e["material_plus"] + $design_fee + $row_e["export_fee"])*$row_e["profit"], 0); } else $profit_amt = $row_e["profit"]; // 報價 $quotation = $row_e["purchase_cost"] + ($floors - $row_e["base_floor"])*$row_e["material_plus"] + $design_fee + $row_e["export_fee"] + $profit_amt; // 設備折合台幣 $equipment_ntd = round($quotation*$row_e["equipment"], 0); // 報關+運輸費 if (strpos($row_e["shipping"], ".") !== false) { $shipping_fee = round($equipment_ntd*$row_e["shipping"], 0); } else $shipping_fee = $row_e["shipping"]; // MI $mi = $equipment_ntd + $shipping_fee + $row_e["unloading"] + $row_e["transport_site"] + $install_cost_total + $row_e["free1y"] + $row_e["option_price"] + $row_e["weight_price"]; */ // 拆梯價格 $dismantle_fee = $polishing_fee = 0; if ($opt == "R") { $sql3 = "select item_spec, item_qty, note from pricereview_item where mid = '$id' and item_group = 'C'"; $res_i = mysqli_query($link, $sql3); while ($row_i = mysqli_fetch_assoc($res_i)) { $sql4 = "select min_floors, price, price_plus from dismantle_mi_option where spec = '".$row_i["item_spec"]."' "; $sql4 .= "and ($floors between min_floors and max_floors) "; $sql4 .= "and version_date = '2023-09-04'"; $res_d = mysqli_query($link, $sql4); if ($row_d = mysqli_fetch_assoc($res_d)) { $dismantle_fee += ($row_d["price"] + $row_d["price_plus"]*($floors - $row_d["min_floors"]))*$row_i["item_qty"]; $polishing_fee += 3000*$row_i["note"]; } mysqli_free_result($res_d); } mysqli_free_result($res_i); } // Option價格 $oparr = []; $option_fee = $j = 0; $sql3 = "select id, price_id, item_spec, item_qty from pricereview_item "; $sql3 .= "where mid = '$id' and item_group = 'B' and option_relate_spec like '%".$item_spec."%' order by item_no"; $res_b = mysqli_query($link, $sql3); while ($row_b = mysqli_fetch_assoc($res_b)) { $sql4 = "select o.base_floor, o.base_floor_plus, o.price, r.equipment from option_mi o, elevator_quotation_rule r "; $sql4 .= "where o.quotation_no = r.quotation_no and o.option_price_id = ".$row_b["price_id"]." "; $sql4 .= "and ($item_weight between o.min_weight and o.max_weight) and o.open_kind = '$item_op'"; $res_om = mysqli_query($link, $sql4); $row_om = mysqli_fetch_assoc($res_om); $plus = ($floors > $row_om["base_floor"]) ? ($floors - $row_om["base_floor"])*$row_om["base_floor_plus"] : 0; // 特例 if ($row_b["price_id"] == "256" && ($floors < $row_om["base_floor"])) $row_om["price"] = 9815; if ($row_b["price_id"] == "266" && $floors >= 20) $plus += 44.8; // 15层,14.6元/层(19层内,跳20层再追加44.8元) $option_amt = round(0+($row_om["price"]+$plus)*$row_b["item_qty"]*$row_om["equipment"], 0); $option_fee += $option_amt; // option總金額 $oparr[$j][0] = $row_b["item_spec"]; $oparr[$j][1] = $option_amt; $j++; mysqli_free_result($res_om); } mysqli_free_result($res_b); $mi_arr[$i][0] = $mi*$item_qty + $dismantle_fee + $polishing_fee + $option_fee; /* $mi_arr[$i][1] = $row_e["purchase_cost"]; $mi_arr[$i][2] = $row_e["material_plus"]; $mi_arr[$i][3] = $design_fee; $mi_arr[$i][4] = $row_e["export_fee"]; $mi_arr[$i][5] = $profit_amt; $mi_arr[$i][6] = $quotation; */ $mi_arr[$i][1] = 0+$equipment_ntd; $mi_arr[$i][2] = 0+$customs; $mi_arr[$i][3] = 0+$row_e["unloading"]; $mi_arr[$i][4] = 0+$row_e["transport_site"]; $mi_arr[$i][5] = 0+$install_price; $mi_arr[$i][6] = 0+$row_e["free1y"]; $mi_arr[$i][7] = 0+$woods; $mi_arr[$i][8] = $row_e["equipment"]; $mi_arr[$i][9] = 0+$row_e["option_price"]; $mi_arr[$i][10] = 0+$dismantle_fee; $mi_arr[$i][11] = 0+$polishing_fee; $mi_arr[$i][12] = $mi_arr[$i][1]+$mi_arr[$i][2]+$mi_arr[$i][3]+$mi_arr[$i][4]+$mi_arr[$i][5]+$mi_arr[$i][6]+$mi_arr[$i][7]+$mi_arr[$i][9]+$mi_arr[$i][10]+$mi_arr[$i][11]; $mi_arr[$i][13] = $option_fee; $mi_arr[$i][14] = $oparr; $i++; } mysqli_free_result($res_e); } mysqli_free_result($res); $rarr["content"] = $mi_arr; }catch(\Exception $e) { $rarr['st'] = 'err'; $rarr['err'] = $e->getMessage(); } echo json_encode($rarr, JSON_UNESCAPED_UNICODE); exit; ?>