Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TeamController.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace App\Http\Controllers\v3\Dealer;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use LynX39\LaraPdfMerger\Facades\PdfMerger;
  7. use Carbon\Carbon;
  8. use Validator;
  9. use Hash;
  10. use App\SiteSetting;
  11. use App\LatestModel\Staff;
  12. use App\LatestModel\StaffDetail;
  13. use App\LatestModel\Module\Form;
  14. use App\LatestModel\Module\Subscriber;
  15. use App\LatestModel\Module\WorkOrder;
  16. use App\LatestModel\Module\PackageDetail;
  17. use App\LatestModel\Module\Company;
  18. use App\LatestModel\Module\Coverage;
  19. use App\LatestModel\Module\Product;
  20. use App\LatestModel\Module\Docket;
  21. class TeamController extends Controller
  22. {
  23. function viewTeamList()
  24. {
  25. $id = Auth::guard('dealer')->id();
  26. $user = Staff::with('StaffDetail')->find($id);
  27. $site = SiteSetting::first();
  28. return view('v3.main-dealer.team.sales_list',compact('user','site'));
  29. }
  30. public function viewStaffForm()
  31. {
  32. $id = Auth::guard('dealer')->id();
  33. $user = Staff::with('StaffDetail')->find($id);
  34. $site = SiteSetting::first();
  35. return view('v3.main-dealer.team.add_new_staff', compact('user','site'));
  36. }
  37. public function encryptPassword($action, $string) {
  38. $output = false;
  39. $encrypt_method = "AES-256-CBC";
  40. $secret_key = '28472B4B6250655368566D5970337336';
  41. $secret_iv = md5(md5($string)); //'This is my secret iv';
  42. // hash
  43. $key = hash('sha256', $secret_key);
  44. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  45. if ( $action == 'encrypt' ) {
  46. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  47. $output = base64_encode($output);
  48. } else if( $action == 'decrypt' ) {
  49. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  50. }
  51. return $output;
  52. }
  53. public function requestAddSales(Request $request){
  54. $validator = Validator::make($request->all(), [
  55. 'password' => 'min:6|confirmed',
  56. ]);
  57. if ($validator->fails()) {
  58. return redirect()->back()->withInput()->withErrors($validator);
  59. }
  60. $encrP = $this->encryptPassword('encrypt', $request->password);
  61. $encrP2 = Hash::make($request->get('password'));
  62. $company = Company::where('_id',$request->vendor)->first();
  63. if(!empty($company)){
  64. $exist = Staff::with('StaffDetail')->where('email',$request->email)->where('roles_access','Sales')->first();
  65. if(empty($exist)){
  66. $sl = Staff::create([
  67. 'email' => $request->email,
  68. 'password' => $encrP,
  69. 'password2' => $encrP2,
  70. 'roles_access' => 'Sales',
  71. 'company_id' => $request->vendor,
  72. 'last_login_at' => '',
  73. 'last_login_ip'=> '',
  74. 'company_id' => $request->vendor,
  75. 'authorized' => false,
  76. 'token_firebase' => '',
  77. ]);
  78. $sdl = new StaffDetail();
  79. $sdl->name = $request->name;
  80. $sdl->ic = $request->ic;
  81. $sdl->email = $request->email;
  82. $sdl->phone = $request->phone;
  83. $sdl->company_id = $request->vendor;
  84. $sdl->color = $company->color;
  85. $sdl->position = 'Sales';
  86. $sdl->password = $encrP;
  87. $sdl->password2 = $encrP2;
  88. $sdl->user_pic = 'uploads/profile/user.png';
  89. $company->staff()->save($sl);
  90. $company->save();
  91. $sl->staffdetail()->save($sdl);
  92. return redirect()->back()->with('success_msg', '<strong>Success!</strong> add <strong>'.$request->get('aname').'</strong> as new sales');
  93. }else {
  94. return redirect()->back()->withInput()->with('error_msg', 'Staff sales with '.$request->email.' already exist!');
  95. }
  96. }else {
  97. return redirect()->back()->withInput()->with('error_msg', 'Record company not found!');
  98. }
  99. }
  100. public function editStaffDetail($_id)
  101. {
  102. $id = Auth::guard('dealer')->id();
  103. $user = Staff::with('StaffDetail')->find($id);
  104. $site = SiteSetting::first();
  105. $staff = Staff::with('StaffDetail')->where('_id', $_id)->first();
  106. $current_company = Company::where('_id',$user->company_id)->first();
  107. return view('v3.main-dealer.team.edit_staff_detail',compact('user','site','staff','current_company'));
  108. }
  109. public function requestEditStaff(Request $request){
  110. $exist = Staff::with('StaffDetail')->where('_id',$request->_id)->first();
  111. if(empty($exist)){
  112. return redirect()->back()->withInput()->withErrors('staff not found');
  113. }else {
  114. $exist->email = $request->email;
  115. $exist->save();
  116. $exist->StaffDetail->name = $request->name;
  117. $exist->StaffDetail->ic = $request->ic;
  118. $exist->StaffDetail->email = $request->email;
  119. $exist->StaffDetail->phone = $request->phone;
  120. $exist->StaffDetail->save();
  121. return redirect()->back()->with('success_msg', '<strong>Success!</strong> update detail staff <strong>'.$request->get('name').'</strong>');
  122. }
  123. }
  124. }