Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. app/RegisterApplication.php
  2.  
  3. <?php
  4.  
  5. namespace App;
  6.  
  7. class RegisterApplication extends \Eloquent
  8. {
  9.  
  10. protected $table = 'register_applications';
  11.  
  12. protected $fillable = [
  13. 'id','name', 'email', 'mobile','rule','rule_marketing','rule_sms','active_code','active','activated_at','freshdesk_message','created_at','updated_at', 'external_id'
  14. ];
  15.  
  16.  
  17. protected static function boot()
  18. {
  19. parent::boot();
  20. }
  21.  
  22. public function sendFreshdeskEmail(){
  23. $update_arr = [];
  24. try{
  25. $custom_fiels = [];
  26.  
  27. if ($this->rule == 1){
  28. $custom_fiels['regulamin_zaakceptowany'] = true;
  29. }
  30. if ($this->rule_marketing == 1){
  31. $custom_fiels['zgoda_handlowa'] = true;
  32. }
  33. if ($this->rule_sms == 1){
  34. $custom_fiels['zgoda_sms'] = true;
  35. }
  36. // $card_code = Code::where('user_id',$this->id)->first();
  37. // if($card_code){
  38. // $custom_fiels['bussines_link_card'] = $card_code->code;
  39. // }
  40. $existing_contacts = \Freshdesk::contacts()->all(['email' => $this->email]);
  41. if (count($existing_contacts) && isset($existing_contacts[0]['id'])){
  42. \Freshdesk::contacts()->update($existing_contacts[0]['id'],[
  43. 'name' => $this->name,
  44. 'mobile' => $this->mobile,
  45. 'custom_fields' => $custom_fiels
  46. ]);
  47. $update_arr = [
  48. 'freshdesk_message' => 'OK',
  49. 'external_id' => (string)$existing_contacts[0]['id']
  50. ];
  51. if ($existing_contacts[0]['active']!=true){
  52. \Freshdesk::contacts()->sendInvite($existing_contacts[0]['id']);
  53. $info = 'Twoje dane zostały zaktualizowane, sprawdź swój email niebawem powinien przyjść e-mail aktywujący konto.';
  54. }else{
  55. $info = 'Twoje dane zostały pomyślnie zaktualizowane.';
  56. }
  57. } else {
  58. $contact = \Freshdesk::contacts()->create([
  59. 'email' => $this->email,
  60. 'name' => $this->name,
  61. 'mobile' => $this->mobile,
  62. 'custom_fields' => $custom_fiels
  63. ]);
  64. if (isset($contact['id'])) {
  65. $update_arr = [
  66. 'freshdesk_message' => 'OK',
  67. 'external_id' => (string)$contact['id']
  68. ];
  69. // \Freshdesk::contacts()->sendInvite($contact['id']);
  70. }
  71. $info = 'Dziękujemy za rejestrację, sprawdź swój email niebawem powinien przyjść e-mail aktywujący konto.';
  72. }
  73. }catch (\Exception $e){
  74. \Log::error($e);
  75. $update_arr =[
  76. 'freshdesk_message' => 'ERROR'
  77. ];
  78. $info = 'Dziękujemy za rejestrację, sprawdź swój email niebawem powinien przyjść e-mail aktywujący konto.';
  79. }
  80.  
  81. if (count($update_arr)) {
  82. $this->update($update_arr);
  83. }
  84. return $info;
  85. }
  86.  
  87. public function sendActivatedConfirmEmail(){
  88. $email = $this->email;
  89. $name = $this->name;
  90. if ($this->active != 1) {
  91. \Mail::send('mails.application_activated', [
  92.  
  93. ], function ($message) use ($email, $name) {
  94. $message->to($email, $name)
  95. ->subject('Aktywowano konto askhenry.pl');
  96. });
  97. }
  98. }
  99.  
  100. public function activate(){
  101. $registerApplication = $this;
  102. if ($registerApplication && is_null($registerApplication->active)) {
  103. $update_arr = [];
  104. try {
  105. $contact = \Freshdesk::contacts()->view($registerApplication->external_id);
  106. if (isset($contact['active']) && $contact['active'] == true) {
  107. $update_arr = [
  108. 'active' => 1,
  109. 'activated_at' => date('Y-m-d H:i:s'),
  110. 'freshdesk_message' => 'OK'
  111. ];
  112. $registerApplication->update($update_arr);
  113. $registerApplication->sendActivatedConfirmEmail();
  114. }
  115. } catch (\Exception $e) {
  116. \Log::error($e);
  117. $update_arr = [
  118. 'freshdesk_message' => 'ERROR'
  119. ];
  120. }
  121. $registerApplication->update($update_arr);
  122. }
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement