SignupManagementService.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, $createDateStart, $createDateFinal)
  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. $res->where('createDate', '>', $createDateStart)
  37. ->where('createDate', '<', $createDateFinal);
  38. // 取總筆數
  39. $cnt = $res->count();
  40. // 排序
  41. $res = $res
  42. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  43. // 分頁
  44. $res = $res
  45. ->skip($start)->take($length);
  46. // 實際取資料
  47. $result = $res
  48. ->get()
  49. ->toArray();
  50. // 整理返回值並返回
  51. return $result;
  52. }
  53. public function getExportList($keyword)
  54. {
  55. $res = $this->signupDb
  56. ->select('*');
  57. if ($keyword != ""){
  58. $res->where('firstName', $keyword)
  59. ->orWhere('lastName', $keyword)
  60. ->orWhere('companyName', $keyword)
  61. ->orWhere('companyEmail', $keyword)
  62. ->orWhere('backupEmail', $keyword)
  63. ->orWhere('phoneNumber', $keyword)
  64. ->orWhere('country', $keyword)
  65. ->orWhere('trackNo', $keyword)
  66. ->orWhere('typeOfIndustry', $keyword)
  67. ->orWhere('typeOfJob', $keyword)
  68. ->orWhere('jobTitle', $keyword);
  69. }
  70. $res = $this->signupDb
  71. ->get()
  72. ->toArray();
  73. // 整理返回值並返回
  74. return $res;
  75. }
  76. }