Added fields to POST /preorder

This commit is contained in:
Frank Schubert
2022-09-23 16:02:03 +02:00
parent 2db0249c1c
commit 2da58d36d3
8 changed files with 347 additions and 230 deletions
+13 -1
View File
@@ -32,11 +32,23 @@ class AddressdbApicontroller extends mfBaseApicontroller {
protected function findCity() {
$search = $this->db()->escape(trim($this->post['search']));
$city = $this->db()->escape(trim($this->post['city']));
$zip = $this->db()->escape(trim($this->post['zip']));
if($city) {
$search = $city;
}
if(!$search) {
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
}
$results = ADBGemeindeModel::search(['name%' => $search]);
$city_search = ['name%' => $search];
if($zip) {
$city_search['zip'] = $zip;
}
$results = ADBGemeindeModel::search($city_search);
$cities = [];
+84 -27
View File
@@ -36,11 +36,33 @@ class PreorderApicontroller extends mfBaseApicontroller {
return mfResponse::Forbidden();
}
$type = $this->post['type'];
$type = $this->post['preorderType'];
if($type != "interest" && $type != "provision" && $type != "order") {
return mfResponse::BadRequest(["message" => "Unknown type"]);
return mfResponse::BadRequest(["message" => "Invalid preorderType"]);
}
$connection_type = false;
switch($this->post['connectionType']) {
case "single-dwelling":
$connection_type = "single-dwelling";
break;
case "multi-dwelling":
$connection_type = "multi-dwelling";
break;
case "apartment-building":
$connection_type = "apartment-building";
break;
case "apartment":
$connection_type = "apartment";
break;
case "business":
$connection_type = "business";
break;
default:
return mfResponse::BadRequest(["message" => "Invalid connectionType"]);
}
if(!array_key_exists("address", $this->post)) {
return mfResponse::BadRequest(['message' => "address missing"]);
}
@@ -49,7 +71,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
return mfResponse::BadRequest(['message' => "customer data missing"]);
}
// check address
/*
* check address
*/
if(!property_exists($this->post['address'],"street") || !$this->post['address']->street ||
!property_exists($this->post['address'],"housenumber") || !$this->post['address']->housenumber ||
!property_exists($this->post['address'],"zip") || !$this->post['address']->zip ||
@@ -72,7 +96,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
}
}
// check customer
/*
* check customer
*/
$customer = $this->post['customer'];
if(!property_exists($customer,"firstname") || !$customer->firstname ||
@@ -84,9 +110,9 @@ class PreorderApicontroller extends mfBaseApicontroller {
return mfResponse::BadRequest(['message' => "Mandatory customer fields missing"]);
}
// search address in AddressDB
/*
* search address in AddressDB
*/
foreach($address_search as $field => $value) {
$where .= " AND `$field` = '$value'";
}
@@ -100,10 +126,10 @@ class PreorderApicontroller extends mfBaseApicontroller {
$address = $this->db()->fetch_object($res);
// search wohneinheit
/*
* search wohneinheit
*/
$unit = false;
if(count($unit_search)) {
foreach($unit_search as $field => $value) {
@@ -128,11 +154,15 @@ class PreorderApicontroller extends mfBaseApicontroller {
$unit = $this->db()->fetch_object($res);
}
}
//var_dump($unit);exit;
/*
* build fields
*/
$preorder_data = [];
$preorder_data['preordercampaign_id'] = $this->campaign->id;
$preorder_data['type'] = $type;
$preorder_data['connection_type'] = $connection_type;
$preorder_data['connection_count'] = (intval($this->post['connectionCount'])) ? intval($this->post['connectionCount']) : 1;
$preorder_data['submit_type'] = "api";
if($this->request_json) {
$preorder_data['submit_request'] = $this->request_json;
@@ -143,23 +173,52 @@ class PreorderApicontroller extends mfBaseApicontroller {
$preorder_data['adb_wohneinheit_id'] = $unit->wohneinheit_id;
}
if($this->post['acceptAgb'] === true) {
$preorder_data['accept_agb'] = 1;
}
if($this->post['acceptDsgvo'] === true) {
$preorder_data['accept_dsgvo'] = 1;
}
if($this->post['acceptMarketing'] === true) {
$preorder_data['accept_marketing'] = 1;
}
if($this->post['acceptWithdrawal'] === true) {
$preorder_data['accept_withdrawal'] = 1;
}
/*
* setup price
*/
$product = false;
if($type == "provision") {
$product = $this->campaign->setup_products['provision'][0];
if($product) {
$preorder_data['setup_product_id'] = $product->id;
$preorder_data['price_setup'] = $product->price_setup;
}
}
if($type == "order") {
$product = $this->campaign->setup_products['activation'][0];
if($product) {
$preorder_data['setup_product_id'] = $product->id;
$preorder_data['price_setup'] = $product->price_setup;
}
if($product) {
$preorder_data['setup_product_id'] = $product->id;
$preorder_data['price_setup'] = $product->price_setup;
if($connection_type == "multi-dwelling") {
if($preorder_data['connection_count'] == 2) {
$preorder_data['price_setup'] = round($product->price_setup * 2 - (($product->price_setup * 2) / 100) * TT_PREORDER_DISCOUNT_2);
}
if($connection_type == "multi-dwelling" && $preorder_data['connection_count'] == 3) {
$preorder_data['price_setup'] = round($product->price_setup * 3 - (($product->price_setup * 3) / 100) * TT_PREORDER_DISCOUNT_3);
}
}
if($connection_type == "apartment" && $type == "order") {
$preorder_data['price_setup'] = round($product->price_setup - (($product->price_setup) / 100) * TT_PREORDER_DISCOUNT_APART);
}
if($connection_type == "business") {
$preorder_data['price_setup'] = round($product->price_setup - (($product->price_setup) / 100) * TT_PREORDER_DISCOUNT_BUSINESS);
}
}
/*
* get customer data
*/
foreach(['company','uid','firstname','lastname','street','zip','city','phone','email'] as $key) {
if(property_exists($customer, $key)) {
$preorder_data[$key] = $customer->$key;
@@ -167,9 +226,12 @@ class PreorderApicontroller extends mfBaseApicontroller {
}
/*
* create preorder record
*/
$preorder = PreorderModel::create($preorder_data);
$preorder->createUcode();
//var_dump($preorder);exit;
$preorder_id = $preorder->save();
if(!$preorder_id || !$preorder->ucode) {
@@ -177,11 +239,6 @@ class PreorderApicontroller extends mfBaseApicontroller {
}
return mfResponse::Ok(["code" => $preorder->ucode]);
var_dump($preorder);exit;
var_dump($this->post);exit;
}
}