From eb2d173ea716b15a48a3f8c1c38e5f95d69933bc Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sun, 21 Jun 2020 19:14:30 +0800 Subject: [PATCH] Add email and customer signature to complete call in rider api #424 --- src/Entity/JOExtra.php | 16 ++++++++ .../RiderAPIHandler/CMBRiderAPIHandler.php | 37 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/Entity/JOExtra.php b/src/Entity/JOExtra.php index cefc6434..4784c629 100644 --- a/src/Entity/JOExtra.php +++ b/src/Entity/JOExtra.php @@ -59,6 +59,12 @@ class JOExtra */ protected $after_other_images; + /** + * @ORM\Column(type="string", nullable=true) + */ + protected $cust_signature; + + public function __construct() { $this->before_other_images = new ArrayCollection(); @@ -181,4 +187,14 @@ class JOExtra return $this; } + public function setCustomerSignature($sig_file) + { + $this->cust_signature($sig_file); + return $this; + } + + public function getCustomerSignature() + { + return $this->cust_signature; + } } diff --git a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php index 2755a804..6f7b646a 100644 --- a/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/CMBRiderAPIHandler.php @@ -1394,6 +1394,17 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + // set customer signature + $jo_extra = $jo->getJOExtra(); + $sig_file = $this->handleFileUpload($req, 'signature'); + if ($sig_file) + $jo_extra->setCustomerSignature($sig_file); + + // set email + $cust_email = $req->request->get('customer_email', ''); + $jo->addMeta('customer_email', $cust_email); + + /* // set jo status to fulfilled $jo->setStatus(JOStatus::FULFILLED); @@ -1517,6 +1528,32 @@ class CMBRiderAPIHandler implements RiderAPIHandlerInterface return $data; } + protected function handleFileUpload($req, $name) + { + $file = $req->files->get($name); + if (empty($file)) + return false; + + $orig_filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME); + + // generate prefix to assure uniqueness + $prefix = uniqid() . '_'; + $new_filename = $prefix . $orig_filename . '.' . $file->guessClientExtension(); + + // move to our upload dir + $dest = $this->upload_dir; + try + { + $file->move($dest, $new_filename); + } + catch (FileException $e) + { + return false; + } + + return $new_filename; + } + public function uploadArrivePhotos(Request $req) { $required_params = [