gameManagementDb = new GameGpRatio();
$this->syslogManagementDb = new Syslog();
}
public function getGames(
&$cnt = 0,
$orderColumn,
$orderDir,
$start,
$length,
$searchValue
)
{
$games = $this->gameManagementDb
->select([
'id',
\DB::raw("CONCAT('', IFNULL(ratio_tmp, ''), '', '
', IFNULL(ratio, '')) as ratio"),
\DB::raw("CONCAT(IFNULL(gp_tmp, ''), '
', IFNULL(gp, '')) as gp"),
'cdate',
'mdate',
\DB::raw("(select name from users where id=gameGpRatio.oid) as oid"),
]);
// 過濾搜尋條件
// 取總筆數
$cnt = $games->count();
// 排序
$games = $games
->orderByRaw((int)$orderColumn . ' ' . $orderDir);
// 彙整
// 分頁
$games = $games
->skip($start)->take($length);
// 實際取資料
$games = $games
->get()
->toArray();
// 整理返回值並返回
return $games;
}
public function getGameById($id)
{
// 取得參數
// 調用資料庫(或者其他業務邏輯)
$games = $this->gameManagementDb->select([
'id',
\DB::raw("ratio_tmp as ratio"),
\DB::raw("gp_tmp as gp"),
'cdate',
'mdate',
\DB::raw("(select name from users where id=gameGpRatio.oid) as oid"),
])
->where('id', $id)
->first()
->toArray();
// 整理返回值並返回
return $games;
}
public function insertGame($ratio, $gp, $oid)
{
// 取得參數
$data = [
'ratio' . '_tmp' => $ratio,
'gp' . '_tmp' => $gp,
'cdate' => date('Y-m-d H:i:s'),
'mdate' => date('Y-m-d H:i:s'),
'oid' => $oid,
];
// 調用資料庫(或者其他業務邏輯)
$this->gameManagementDb
->insert($data);
$id = \DB::getPdo()->lastInsertId();
// syslog
$this->syslogManagementDb
->insert([
'type' => GeneralConst::LOG_ADMIN,
'func' => __FUNCTION__,
'k' => $oid,
'memoIn' => json_encode(['data' => $data], JSON_UNESCAPED_UNICODE),
'memoOut' => json_encode(['id' => $id], JSON_UNESCAPED_UNICODE),
'cdate' => date("Y-m-d H:i:s"),
]);
// 整理返回值並返回
return $id;
}
public function modifyGame($id, $ratio, $gp, $oid)
{
// 取得參數
$data = [
'ratio' . '_tmp' => $ratio,
'gp' . '_tmp' => $gp,
'mdate' => date('Y-m-d H:i:s'),
'oid' => $oid,
];
// 調用資料庫(或者其他業務邏輯)
$res = $this->gameManagementDb
->where('id', $id)
->update($data);
$rc = \DB::select("SELECT ROW_COUNT() AS rc;");
$rc = $rc[0]->rc;
// syslog
$this->syslogManagementDb
->insert([
'type' => GeneralConst::LOG_ADMIN,
'func' => __FUNCTION__,
'k' => $oid,
'memoIn' => json_encode(['id' => $id, 'data' => $data], JSON_UNESCAPED_UNICODE),
'memoOut' => json_encode(['rc' => $rc], JSON_UNESCAPED_UNICODE),
'cdate' => date("Y-m-d H:i:s"),
]);
// 整理返回值並返回
return $res;
}
}