TPlayerManagementController.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace App\Http\Controllers\Backend\DataManagement;
  3. use Illuminate\Http\Request;
  4. use App\Http\Services\Backend\DataManagement\TPlayerManagementService;
  5. use App\Http\Controllers\Controller;
  6. use App\Http\Services\ConstDef\GeneralConst;
  7. use App\Http\Services\CheckParamService;
  8. class TPlayerManagementController extends Controller
  9. {
  10. // 相關私有服務層調用器宣告
  11. private $tplayerManagementSv;
  12. private $checkParamSv;
  13. public function __construct()
  14. {
  15. // 建構服務層調用器
  16. $this->tplayerManagementSv = new TPlayerManagementService();
  17. $this->checkParamSv = new CheckParamService();
  18. // 時區調整
  19. date_default_timezone_set("Asia/Taipei");
  20. }
  21. public function index(Request $request)
  22. {
  23. // 渲染
  24. return view('admin.DataManagement.TPlayerManagement');
  25. }
  26. public function grid(Request $request)
  27. {
  28. // 取得參數
  29. $param = $_GET;
  30. if ($param == null) exit();
  31. $draw = $param["draw"]; //客戶端傳來的查詢次數,無條件回傳用以核對
  32. $orderColumn = $param["order"][0]["column"] + 1; //前端從 0 開始送,但 mysql 從 1 開始算
  33. $orderDir = $param["order"][0]["dir"];
  34. $start = $param["start"]; // 頁碼
  35. $length = $param["length"]; // 一頁多大
  36. $searchValue = $param["search"]["value"];
  37. //客製化搜尋欄位
  38. $lineId = $param["columns"][1]["search"]["value"];
  39. // $userName = $param["columns"][2]["search"]["value"];
  40. $createDate = explode("\n", $param["columns"][2]["search"]["value"]);
  41. $createDateStart = $createDate[0] ?? null;
  42. $createDateFinal = $createDate[1] ?? null;
  43. // 驗證
  44. if ($lineId != filter_var($lineId, FILTER_SANITIZE_SPECIAL_CHARS)) $lineId = "___CANNOT_FIND_STRING___";
  45. if (!$this->checkParamSv->LenMToN($lineId, 0, 50)) $lineId = "___CANNOT_FIND_STRING___";
  46. // if ($userName != filter_var($userName, FILTER_SANITIZE_SPECIAL_CHARS)) $userName = "___CANNOT_FIND_STRING___";
  47. // if (!$this->checkParamSv->LenMToN($userName, 0, 100)) $userName = "___CANNOT_FIND_STRING___";
  48. if ($createDateStart == "") $createDateStart = "1900-01-01";
  49. if ($createDateFinal == "") $createDateFinal = "2050-12-31";
  50. if (!$this->checkParamSv->validateDate($createDateStart, 'Y-m-d')) $createDateStart = "1900-01-01";
  51. if (!$this->checkParamSv->validateDate($createDateFinal, 'Y-m-d')) $createDateFinal = "2050-12-31";
  52. //資料庫
  53. $recordsTotal = 0;
  54. $result = $this->tplayerManagementSv->getTPlayers(
  55. $recordsTotal,
  56. $orderColumn,
  57. $orderDir,
  58. $start,
  59. $length,
  60. $searchValue,
  61. $lineId,
  62. // $userName,
  63. $createDateStart,
  64. $createDateFinal
  65. );
  66. // 整理返回資料
  67. $data = array();
  68. for ($i = 0; $i < count($result); $i++) {
  69. $data[] = array(
  70. //一般資料
  71. $result[ $i ]["id"],
  72. $result[ $i ]["lineId"],
  73. // $result[ $i ]["userName"],
  74. // $result[ $i ]["userPhoto"],
  75. $result[ $i ]["gp"],
  76. $result[ $i ]["jgg"],
  77. $result[ $i ]["cdate"],
  78. $result[ $i ]["mdate"],
  79. );
  80. }
  81. $json = array(
  82. "draw" => $draw,
  83. "recordsTotal" => $recordsTotal,
  84. "recordsFiltered" => $recordsTotal, //其實還是填入所有筆數,本次筆數可從陣列取得
  85. "data" => $data,
  86. );
  87. // 返回
  88. return json_decode(json_encode($json, JSON_NUMERIC_CHECK), true);
  89. }
  90. public function export(Request $request)
  91. {
  92. // 取得參數
  93. $param = $_POST;
  94. if ($param == null) exit();
  95. // 驗證
  96. if ($param['lineId'] != filter_var($param['lineId'], FILTER_SANITIZE_SPECIAL_CHARS)) $param['lineId'] = "___CANNOT_FIND_STRING___";
  97. if (!$this->checkParamSv->LenMToN($param['lineId'], 0, 50)) $param['lineId'] = "___CANNOT_FIND_STRING___";
  98. // if ($param['userName'] != filter_var($param['userName'], FILTER_SANITIZE_SPECIAL_CHARS)) $param['userName'] = "___CANNOT_FIND_STRING___";
  99. // if (!$this->checkParamSv->LenMToN($param['userName'], 0, 100)) $param['userName'] = "___CANNOT_FIND_STRING___";
  100. if ($param['createDateStart'] == "") $param['createDateStart'] = "1900-01-01";
  101. if ($param['createDateFinal'] == "") $param['createDateFinal'] = "2050-12-31";
  102. if (!$this->checkParamSv->validateDate($param['createDateStart'], 'Y-m-d')) $param['createDateStart'] = "1900-01-01";
  103. if (!$this->checkParamSv->validateDate($param['createDateFinal'], 'Y-m-d')) $param['createDateFinal'] = "2050-12-31";
  104. // 製作
  105. $title = [
  106. 'ID',
  107. '玩家 LINE ID',
  108. // '玩家名稱',
  109. '當前吉點',
  110. '九宮格狀態',
  111. '加入時間',
  112. '修改時間',
  113. ];
  114. $tplayers = $this->tplayerManagementSv->getExports($param);
  115. $this->tplayerManagementSv->downloadExcel($title, $tplayers, date("YmdHis") . '-TPLAYER-REPORT');
  116. }
  117. public function jggclear(Request $request)
  118. {
  119. $this->tplayerManagementSv->jggclear($request->user()->id);
  120. return json_decode(json_encode([], JSON_NUMERIC_CHECK), true);
  121. }
  122. public function gpclear(Request $request)
  123. {
  124. $this->tplayerManagementSv->gpclear($request->user()->id);
  125. return json_decode(json_encode([], JSON_NUMERIC_CHECK), true);
  126. }
  127. }