Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current none :
/
var
/
www
/
html
/
tpid-aden
/
api
/
app
/
Helpers
/
Or
Select Your none :
Upload File :
New :
File
Dir
/var/www/html/tpid-aden/api/app/Helpers/AutoCRM.php
<?php namespace App\Helpers; use Mail; use App\Models\User; use App\Models\Mitra; use App\Mail\BasicMail; use App\Mail\ReceiptMail; use App\Mail\ReceiptMailPo; use App\Mail\ReceiptMailPaid; use App\Mail\MailTagihan; use App\Models\CustomerCode; use App\Models\CodeForgotPin; use App\Mail\MailWithAttachment; use App\Models\Autocrm as Getcrm; class AutoCRM { /** * Kirim auto CRM basic * * @param String $type * @param String $email * @param Enum $user_type (mitra || user) awas kalo beda * @return Boolean */ public static function sendAutoCRM($type, $email, $user_type, $variable=null, $file=null){ try { $get_crm = Getcrm::where('type', $type)->first(); if (!empty($get_crm) && !empty($email)) { // jika toogle emailnya true if ($get_crm->toggle_email) { // replace text jika ada yang mengandung % $data['subject'] = strpos($get_crm->email_subject, '%') ? self::textReplace($get_crm->email_subject, $email, $user_type, $variable) : $get_crm->email_subject; $data['content'] = strpos($get_crm->email_content, '%') ? self::textReplace($get_crm->email_content, $email, $user_type, $variable) : $get_crm->email_content; if($file == null) { Mail::to($email)->send(new BasicMail($data)); } else { //Gunakan Jika email berisi Attachment, variable file adalah path ke storage Mail::to($email)->send(new MailWithAttachment($data, $file)); } } // jika toogle forward true if ($get_crm->toggle_forward == 1) { $data['subject'] = strpos($get_crm->forward_subject, '%') ? self::textReplace($get_crm->forward_subject, $email, $user_type, $variable) : $get_crm->forward_subject; $data['content'] = strpos($get_crm->forward_content, '%') ? self::textReplace($get_crm->forward_content, $email, $user_type, $variable) : $get_crm->forward_content; // kirim email ke service email yang sudah dibuat if($file == null) { Mail::to($get_crm->forward_address)->send(new BasicMail($data)); } else { Mail::to($get_crm->forward_address)->send(new MailWithAttachment($data, $file)); } } return true; throw new Exception("error #CRM0321", 400); } throw new Exception("error #CRM0322", 400); } catch (\Throwable $th) { return false; } } /** * replace text jika terdapat conten yang terdapat % % * * @param String $string * @param String $email * @param Enum $user_type (mitra || user) awas kalo beda * @return String */ protected static function textReplace($string, $email, $user_type, $variable=null){ // return $string; // select user berdasarkan user typenya if ($user_type == "mitra") { $user = Mitra::where('email', $email)->first(); }else{ $user = User::where('email', $email)->first(); } // replace text berdasarkan keywordnya if (strpos($string, '%name%')) { $string = str_replace("%name%", $variable['name'] ?? $user->name ?? '-', $string); } if (strpos($string, '%email%')) { $string = str_replace("%email%", $variable['email'] ?? $user->email ?? '-', $string); } if (strpos($string, '%code%')) { $code = CustomerCode::where('user_id', $user->id)->where('user_type', $user_type)->orderBy('id', 'desc')->first()['code']; $string = str_replace("%code%", $variable['code'] ?? $code ?? '-', $string); } if (strpos($string, '%note%')) { $string = str_replace("%note%", $variable['note'] ?? '-', $string); } if (strpos($string, '%body%')) { $string = str_replace("%body%",$variable['body'] ?? '-', $string); } if (strpos($string, '%store%')) { $string = str_replace("%store%",$variable['store'] ?? '-', $string); } if (strpos($string, '%order%')) { $string = str_replace("%order%",$variable['order'] ?? '-', $string); } if(strpos($string, '%enquiry%')) { $string = str_replace("%enquiry%", $variable['enquiry'] ?? '-', $string); } if(strpos($string, '%store_name%')) { $string = str_replace("%store_name%", $variable['store_name'] ?? '-', $string); } if(strpos($string, '%do_number%')) { $string = str_replace("%do_number%", $variable['do_number'] ?? '-', $string); } if(strpos($string, '%pa_number%')) { $string = str_replace("%pa_number%", $variable['pa_number'] ?? '-', $string); } if(strpos($string, '%total_amount%')) { $string = str_replace("%total_amount%", $variable['total_amount'] ?? '-', $string); } return $string; } public static function sendReceiptOrder($transaction, $file){ try { Mail::to($transaction['mitra_store']['mitra']['email'])->send(new ReceiptMail($transaction, $file)); return true; } catch (\Throwable $th) { return false; } } public static function sendReceiptPreOrder($transaction, $file) { try { Mail::to($transaction['mitra_store']['mitra']['email'])->send(new ReceiptMailPo($transaction, $file)); return true; } catch (\Throwable $th) { return false; } } public static function sendReceiptPaid($transaction, $file) { try { Mail::to($transaction['mitra_store']['mitra']['email'])->send(new ReceiptMailPaid($transaction, $file)); return true; } catch (\Throwable $th) { return false; } } public static function sendReceipt($email, $file, $transaction, $store, $notif){ try { $subject = "Menunggu Pembayaran ".$transaction['order_id']; return Mail::to($email)->send(new MailTagihan($subject, $file, $transaction, $store, $notif)); return true; } catch (\Throwable $th) { return false; } } }