roundManagementDb = new Round();
$this->syslogManagementDb = new Syslog();
}
public function getRounds(
&$cnt = 0,
$orderColumn,
$orderDir,
$start,
$length,
$searchValue
)
{
// 選欄位
$activeStr = '';
foreach (GeneralConst::$activeMap as $k => $v) {
$activeStr .= ' when \'' . $k . '\' then \'' . $v . '\'';
}
$rounds = $this->roundManagementDb
->select([
'id',
\DB::raw("CONCAT('', roundName, '') as roundName"),
\DB::raw("CONCAT(IFNULL(dateBegin_tmp, ''), '
', IFNULL(dateBegin, '')) as dateBegin"),
\DB::raw("CONCAT(IFNULL(dateFinal_tmp, ''), '
', IFNULL(dateFinal, '')) as dateFinal"),
\DB::raw("CONCAT(IFNULL(redeemExtra_tmp, ''), '
', IFNULL(redeemExtra, '')) as redeemExtra"),
\DB::raw("(case active $activeStr end) as active"),
'cdate',
'mdate',
\DB::raw("(select name from users where id=rounds.oid) as oid"),
]);
// 過濾搜尋條件
// 取總筆數
$cnt = $rounds->count();
// 排序
$rounds = $rounds
->orderByRaw((int)$orderColumn . ' ' . $orderDir);
// 彙整
// 分頁
$rounds = $rounds
->skip($start)->take($length);
// 實際取資料
$rounds = $rounds
->get()
->toArray();
// 整理返回值並返回
return $rounds;
}
public function getRoundById($id)
{
// 取得參數
// 調用資料庫(或者其他業務邏輯)
$rounds = $this->roundManagementDb->select([
'id',
'roundName',
\DB::raw("dateBegin_tmp as dateBegin"),
\DB::raw("dateFinal_tmp as dateFinal"),
\DB::raw("redeemExtra_tmp as redeemExtra"),
'active',
'cdate',
'mdate',
\DB::raw("(select name from users where id=rounds.oid) as oid"),
])
->where('id', $id)
->first()
->toArray();
// 整理返回值並返回
return $rounds;
}
public function insertRound($roundName, $dateBegin, $dateFinal, $redeemExtra, $active, $oid)
{
// 取得參數
$data = [
'roundName' => $roundName,
'dateBegin' . '_tmp' => $dateBegin,
'dateFinal' . '_tmp' => $dateFinal,
'redeemExtra' . '_tmp' => $redeemExtra,
'active' => $active,
'cdate' => date('Y-m-d H:i:s'),
'mdate' => date('Y-m-d H:i:s'),
'oid' => $oid,
];
// 調用資料庫(或者其他業務邏輯)
$this->roundManagementDb
->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 modifyRound($id, $roundName, $dateBegin, $dateFinal, $redeemExtra, $active, $oid)
{
// 取得參數
$data = [
'roundName' => $roundName,
'dateBegin' . '_tmp' => $dateBegin,
'dateFinal' . '_tmp' => $dateFinal,
'redeemExtra' . '_tmp' => $redeemExtra,
'active' => $active,
'mdate' => date('Y-m-d H:i:s'),
'oid' => $oid,
];
// 調用資料庫(或者其他業務邏輯)
$res = $this->roundManagementDb
->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;
}
}