SmsUtility.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Utility;
  3. use App\Models\SmsTemplate;
  4. use App\Models\User;
  5. class SmsUtility
  6. {
  7. public static function phone_number_verification($user = '')
  8. {
  9. $sms_template = SmsTemplate::where('identifier','phone_number_verification')->first();
  10. $sms_body = $sms_template->sms_body;
  11. $sms_body = str_replace('[[code]]', $user->verification_code, $sms_body);
  12. $sms_body = str_replace('[[site_name]]', env('APP_NAME'), $sms_body);
  13. $template_id = $sms_template->template_id;
  14. try {
  15. sendSMS($user->phone, env('APP_NAME'), $sms_body, $template_id);
  16. } catch (\Exception $e) {
  17. }
  18. }
  19. public static function password_reset($user = '')
  20. {
  21. $sms_template = SmsTemplate::where('identifier','password_reset')->first();
  22. $sms_body = $sms_template->sms_body;
  23. $sms_body = str_replace('[[code]]', $user->verification_code, $sms_body);
  24. $template_id = $sms_template->template_id;
  25. try {
  26. sendSMS($user->phone, env('APP_NAME'), $sms_body, $template_id);
  27. } catch (\Exception $e) {
  28. }
  29. }
  30. public static function order_placement($phone='', $order='')
  31. {
  32. $sms_template = SmsTemplate::where('identifier','order_placement')->first();
  33. $sms_body = $sms_template->sms_body;
  34. $sms_body = str_replace('[[order_code]]', $order->code, $sms_body);
  35. $template_id = $sms_template->template_id;
  36. try {
  37. sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
  38. } catch (\Exception $e) {
  39. }
  40. }
  41. public static function delivery_status_change($phone='', $order)
  42. {
  43. $sms_template = SmsTemplate::where('identifier','delivery_status_change')->first();
  44. $sms_body = $sms_template->sms_body;
  45. $delivery_status = translate(ucfirst(str_replace('_', ' ', $order->delivery_status)));
  46. $sms_body = str_replace('[[delivery_status]]', $delivery_status, $sms_body);
  47. $sms_body = str_replace('[[order_code]]', $order->code, $sms_body);
  48. $template_id = $sms_template->template_id;
  49. try {
  50. sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
  51. } catch (\Exception $e) {
  52. }
  53. }
  54. public static function payment_status_change($phone='', $order='')
  55. {
  56. $sms_template = SmsTemplate::where('identifier','payment_status_change')->first();
  57. $sms_body = $sms_template->sms_body;
  58. $sms_body = str_replace('[[payment_status]]', $order->payment_status, $sms_body);
  59. $sms_body = str_replace('[[order_code]]', $order->code, $sms_body);
  60. $template_id = $sms_template->template_id;
  61. try {
  62. sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
  63. } catch (\Exception $e) {
  64. }
  65. }
  66. public static function assign_delivery_boy($phone='', $code='')
  67. {
  68. $sms_template = SmsTemplate::where('identifier','assign_delivery_boy')->first();
  69. $sms_body = $sms_template->sms_body;
  70. $sms_body = str_replace('[[order_code]]', $code, $sms_body);
  71. $template_id = $sms_template->template_id;
  72. try {
  73. sendSMS($phone, env('APP_NAME'), $sms_body, $template_id);
  74. } catch (\Exception $e) {
  75. }
  76. }
  77. }
  78. ?>