CheckinManagementController.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Http\Controllers\Backend\DataManagement;
  3. use Illuminate\Http\Request;
  4. use App\Http\Services\Backend\DataManagement\CheckinManagementService;
  5. use App\Http\Services\Backend\DataManagement\CheckinTmpManagementService;
  6. use App\Http\Services\Backend\DataManagement\SettingManagementService;
  7. use App\Http\Controllers\Controller;
  8. use App\Http\Services\ConstDef\GeneralConst;
  9. use App\Http\Services\CheckParamService;
  10. use Redirect;
  11. class CheckinManagementController extends Controller
  12. {
  13. // 相關私有服務層調用器宣告
  14. private $checkinManagementSv;
  15. private $checkParamSv;
  16. public function __construct()
  17. {
  18. // 建構服務層調用器
  19. $this->checkinManagementSv = ((new SettingManagementService())->getSetting()['GAME_AUDIT_SWITCH'] == 'false') ? new CheckinManagementService() : new CheckinTmpManagementService();
  20. $this->checkParamSv = new CheckParamService();
  21. // 時區調整
  22. date_default_timezone_set("Asia/Taipei");
  23. }
  24. public function index()
  25. {
  26. // 渲染
  27. return view('admin.DataManagement.CheckinManagement');
  28. }
  29. public function grid()
  30. {
  31. // 取得參數
  32. $param = $_GET;
  33. if ($param == null) exit();
  34. $draw = $param["draw"]; //客戶端傳來的查詢次數,無條件回傳用以核對
  35. $orderColumn = $param["order"][0]["column"] + 1; //前端從 0 開始送,但 mysql 從 1 開始算
  36. $orderDir = $param["order"][0]["dir"];
  37. $start = $param["start"]; // 頁碼
  38. $length = $param["length"]; // 一頁多大
  39. $searchValue = $param["search"]["value"];
  40. //客製化搜尋欄位
  41. // 驗證
  42. //資料庫
  43. $recordsTotal = 0;
  44. $result = $this->checkinManagementSv->getCheckins(
  45. $recordsTotal,
  46. $orderColumn,
  47. $orderDir,
  48. $start,
  49. $length,
  50. $searchValue
  51. );
  52. // 整理返回資料
  53. $data = array();
  54. for ($i = 0; $i < count($result); $i++) {
  55. $data[] = array(
  56. //一般資料
  57. $result[ $i ]["id"],
  58. $result[ $i ]["day"],
  59. $result[ $i ]["gp"],
  60. $result[ $i ]["cdate"],
  61. $result[ $i ]["mdate"],
  62. $result[ $i ]["oid"],
  63. );
  64. }
  65. $json = array(
  66. "draw" => $draw,
  67. "recordsTotal" => $recordsTotal,
  68. "recordsFiltered" => $recordsTotal, //其實還是填入所有筆數,本次筆數可從陣列取得
  69. "data" => $data,
  70. );
  71. // 返回
  72. return json_decode(json_encode($json, JSON_NUMERIC_CHECK), true);
  73. }
  74. public function create()
  75. {
  76. // 渲染
  77. return view('admin.DataManagement.CheckinManagementEdit', [
  78. 'operdata' => "",
  79. ]);
  80. }
  81. public function edit($id)
  82. {
  83. // 取得參數與驗證
  84. // 服務層取得資料(以及實現各種業務上的邏輯)
  85. $checkin = $this->checkinManagementSv->getCheckinById($id);
  86. // 渲染
  87. return view('admin.DataManagement.CheckinManagementEdit', [
  88. 'operdata' => $checkin,
  89. ]);
  90. }
  91. public function store(Request $request)
  92. {
  93. // 取得參數與驗證
  94. $mode = $request->mode;
  95. $id = ($request->mode == 'insert') ? '' : $request->id;
  96. $day = $request->day;
  97. $gp = $request->gp;
  98. // 服務層設置(以及實現各種業務上的邏輯)
  99. if ($mode == "insert") {
  100. // 新增模式
  101. $id = $this->checkinManagementSv->insertCheckin($day, $gp, $request->user()->id);
  102. } else {
  103. // 編輯模式
  104. $this->checkinManagementSv->modifyCheckin($id, $day, $gp, $request->user()->id);
  105. }
  106. // 跳轉
  107. return redirect('/backend/dataManagement/checkinManagement/edit/' . $id);
  108. }
  109. }