TCheckinManagementController.php 3.8KB

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