TrackManagementService.php 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace App\Http\Services\Backend\DataManagement;
  3. use App\Http\Services\ConstDef\GeneralConst;
  4. use App\Models\TrackData;
  5. use DB;
  6. use Log;
  7. use PhpOffice\PhpSpreadsheet\IOFactory;
  8. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  9. class TrackManagementService
  10. {
  11. // 相關私有 model 調用器宣告
  12. private $signupDb;
  13. public function __construct()
  14. {
  15. // 建構 model 調用器
  16. $this->trackDataDb = new TrackData();
  17. }
  18. public function getList(&$cnt = 0, $orderColumn, $orderDir, $start, $length, $searchValue, $keyword)
  19. {
  20. // 調用資料庫(或者其他業務邏輯)
  21. $res = $this->trackDataDb
  22. ->select('*')
  23. ->where('trackNo', 'like', '%'.$keyword.'%')
  24. ->orWhere('trackTitle', 'like', '%'.$keyword.'%');
  25. // 取總筆數
  26. $cnt = $res->count();
  27. // 排序
  28. $res = $res
  29. ->orderByRaw((int)$orderColumn . ' ' . $orderDir);
  30. // 分頁
  31. $res = $res
  32. ->skip($start)->take($length);
  33. // 實際取資料
  34. $result = $res
  35. ->get()
  36. ->toArray();
  37. // 整理返回值並返回
  38. return $result;
  39. }
  40. public function getReferral()
  41. {
  42. $res=$this->referralDB->select(["id","name","referral"])->get();
  43. if(!empty($res))
  44. {
  45. $res=$res->toArray();
  46. }
  47. return $res;
  48. }
  49. public function getTrackDataById($id)
  50. {
  51. $res=$this->trackDataDb
  52. ->select('*')
  53. ->where("id",$id)
  54. ->first();
  55. if(!empty($res))
  56. {
  57. $res=$res->toArray();
  58. }
  59. return $res;
  60. }
  61. public function getReferralByReferral($referral)
  62. {
  63. return $this->referralDB->where('referral', $referral)->first();
  64. }
  65. public function modifyReferral($id,$name,$referral,$richmenuId,$orlCode=0)
  66. {
  67. $res=$this->referralDB->where("id",$id)->update(["name"=>$name,"richmenuId"=>$richmenuId,"orlCode"=>$orlCode]);
  68. return $res;
  69. }
  70. public function modifyReferralPicsee($id,$picseeCode,$picseeUrl,$qRCode)
  71. {
  72. $res=$this->referralDB->where("id",$id)->update(["picseeCode"=>$picseeCode,"shortUrl"=>$picseeUrl,"qRCode"=>$qRCode]);
  73. return $res;
  74. }
  75. public function modifyPicseeCntAndTime($id,$picseeCnt,$last_call)
  76. {
  77. $res=$this->referralDB->where("id",$id)->update(["picseeCnt"=>$picseeCnt,"last_call"=>$last_call]);
  78. return $res;
  79. }
  80. public function insert($trackNo, $trackTitle, $trackLimit)
  81. {
  82. $this->trackDataDb
  83. ->insert([
  84. 'trackNo' => $trackNo,
  85. 'trackTitle' => $trackTitle,
  86. 'trackLimit' => $trackLimit,
  87. 'createDate' => date("Y-m-d H:i:s"),
  88. ]);
  89. return ;
  90. }
  91. public function store($id, $trackNo, $trackTitle, $trackLimit)
  92. {
  93. $this->trackDataDb
  94. ->where('id', $id)
  95. ->update([
  96. 'trackNo' => $trackNo,
  97. 'trackTitle' => $trackTitle,
  98. 'trackLimit' => $trackLimit,
  99. 'updateDate' => date("Y-m-d H:i:s"),
  100. ]);
  101. return $id;
  102. }
  103. public function deleteDataById($id)
  104. {
  105. // 取得參數
  106. // 調用資料庫(或者其他業務邏輯)
  107. $res = $this->trackDataDb
  108. ->where('id', $id)
  109. ->delete();
  110. // 整理返回值並返回
  111. return $res;
  112. }
  113. public function getExportList($keyword)
  114. {
  115. $res = $this->signupDb
  116. ->select('*')
  117. // 過濾搜尋條件
  118. ->where('firstName', $keyword)
  119. ->orWhere('lastName', $keyword)
  120. ->orWhere('companyName', $keyword)
  121. ->orWhere('companyEmail', $keyword)
  122. ->orWhere('backupEmail', $keyword)
  123. ->orWhere('phoneNumber', $keyword)
  124. ->orWhere('country', $keyword)
  125. ->orWhere('trackNo', $keyword)
  126. // ->orWhere('registeredSession', $keyword)
  127. // ->orWhere('lunchOptions', $keyword)
  128. ->orWhere('typeOfIndustry', $keyword)
  129. ->orWhere('typeOfJob', $keyword)
  130. ->orWhere('jobTitle', $keyword)
  131. ->get()
  132. ->toArray();
  133. // 整理返回值並返回
  134. return $res;
  135. }
  136. }