SignupManagementService.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Services\Backend\DataManagement;
  3. use App\Http\Services\ConstDef\GeneralConst;
  4. use App\Models\SignupData;
  5. use DB;
  6. use Log;
  7. use PhpOffice\PhpSpreadsheet\IOFactory;
  8. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  9. class SignupManagementService
  10. {
  11. // 相關私有 model 調用器宣告
  12. private $signupDb;
  13. public function __construct()
  14. {
  15. // 建構 model 調用器
  16. $this->signupDb=new SignupData();
  17. }
  18. public function getList(&$cnt = 0, $orderColumn, $orderDir, $start, $length, $searchValue, $keyword)
  19. {
  20. // 調用資料庫(或者其他業務邏輯)
  21. $res = $this->signupDb
  22. ->select('*');
  23. if ($keyword != ""){
  24. $res->where('firstName', $keyword)
  25. ->orWhere('lastName', $keyword)
  26. ->orWhere('companyName', $keyword)
  27. ->orWhere('companyEmail', $keyword)
  28. ->orWhere('backupEmail', $keyword)
  29. ->orWhere('phoneNumber', $keyword)
  30. ->orWhere('country', $keyword)
  31. ->orWhere('trackNo', $keyword)
  32. ->orWhere('typeOfIndustry', $keyword)
  33. ->orWhere('typeOfJob', $keyword)
  34. ->orWhere('jobTitle', $keyword);
  35. }
  36. // 取總筆數
  37. $cnt = $res->count();
  38. // 排序
  39. $res = $res
  40. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  41. // 分頁
  42. $res = $res
  43. ->skip($start)->take($length);
  44. // 實際取資料
  45. $result = $res
  46. ->get()
  47. ->toArray();
  48. // 整理返回值並返回
  49. return $result;
  50. }
  51. public function getExportList($keyword)
  52. {
  53. $res = $this->signupDb
  54. ->select('*');
  55. if ($keyword != ""){
  56. $res->where('firstName', $keyword)
  57. ->orWhere('lastName', $keyword)
  58. ->orWhere('companyName', $keyword)
  59. ->orWhere('companyEmail', $keyword)
  60. ->orWhere('backupEmail', $keyword)
  61. ->orWhere('phoneNumber', $keyword)
  62. ->orWhere('country', $keyword)
  63. ->orWhere('trackNo', $keyword)
  64. ->orWhere('typeOfIndustry', $keyword)
  65. ->orWhere('typeOfJob', $keyword)
  66. ->orWhere('jobTitle', $keyword);
  67. }
  68. $res = $this->signupDb
  69. ->get()
  70. ->toArray();
  71. // 整理返回值並返回
  72. return $res;
  73. }
  74. }