123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
-
- namespace App\Http\Controllers\Backend\DataManagement;
-
- use Illuminate\Http\Request;
- use App\Http\Services\Backend\DataManagement\InfoManagementService;
- use App\Http\Controllers\Controller;
- use App\Http\Services\CheckParamService;
-
- class InfoManagementController extends Controller
- {
-
- // 相關私有服務層調用器宣告
- private $infoManagementSv;
- private $checkParamSv;
-
- public function __construct()
- {
- // 建構服務層調用器
- $this->infoManagementSv = new InfoManagementService();
- $this->checkParamSv = new CheckParamService();
- // 時區調整
- date_default_timezone_set("Asia/Taipei");
- }
-
- public function index(Request $request)
- {
- // 渲染
- return view('admin.DataManagement.InfoManagement');
- }
-
- public function grid(Request $request)
- {
- // 取得參數
- $param = $_GET;
- if ($param == null) exit();
- $draw = $param["draw"]; //客戶端傳來的查詢次數,無條件回傳用以核對
- $orderColumn = $param["order"][0]["column"] + 1; //前端從 0 開始送,但 mysql 從 1 開始算
- $orderDir = $param["order"][0]["dir"];
- $start = $param["start"]; // 頁碼
- $length = $param["length"]; // 一頁多大
- $searchValue = $param["search"]["value"];
- //客製化搜尋欄位
- $sDate = explode("\n", $param["columns"][1]["search"]["value"]);
- $sDateStart = $sDate[0] ?? null;
- $sDateFinal = $sDate[1] ?? null;
- // 驗證
- if ($sDateStart == "") $sDateStart = "1900-01-01";
- if ($sDateFinal == "") $sDateFinal = "2050-12-31";
- //資料庫
- $recordsTotal = 0;
- $result = $this->infoManagementSv->getInfos(
- $recordsTotal,
- $orderColumn,
- $orderDir,
- $start,
- $length,
- $searchValue,
- $sDateStart,
- $sDateFinal
- );
- // 整理返回資料
- $data = array();
- for ($i = 0; $i < count($result); $i++) {
- $data[] = array(
- //一般資料
- $result[ $i ]["id"],
- $result[ $i ]["image_uri"],
- $result[ $i ]["nickname"],
- $result[ $i ]["memo"],
- $result[ $i ]["hash"],
- $result[ $i ]["name"],
- $result[ $i ]["tel"],
- $result[ $i ]["email"],
- $result[ $i ]["zone"],
- $result[ $i ]["cdate"],
- );
- }
- $json = array(
- "draw" => $draw,
- "recordsTotal" => $recordsTotal,
- "recordsFiltered" => $recordsTotal, //其實還是填入所有筆數,本次筆數可從陣列取得
- "data" => $data,
- );
-
- // 返回
- return json_decode(json_encode($json, JSON_NUMERIC_CHECK), true);
- }
-
- public function export(Request $request)
- {
- // 取得參數
- $param = $_POST;
- if ($param == null) exit();
- // 驗證
- if ($param['sDateStart'] == "") $param['sDateStart'] = "1900-01-01";
- if ($param['sDateFinal'] == "") $param['sDateFinal'] = "2050-12-31";
- // 製作
- $title = [
- 'ID',
- '圖片網址',
- '暱稱',
- '留言',
- '標籤',
- '姓名',
- '電話',
- '信箱',
- '地區',
- '媒體參數1',
- '媒體參數2',
- '媒體參數3',
- '時間',
- 'IP',
- ];
- $result = $this->infoManagementSv->getExportInfo($param);
- $this->infoManagementSv->downloadExcel($title, $result, date("YmdHis") . '-REPORT');
- }
-
- }
|