代码拉取完成,页面将自动刷新
<?php
/**
* 通用控制器
* User: Administrator
* Date: 2018/12/26
* Time: 10:15
*/
namespace PKCore;
use function PKCore\Route\language;
abstract class PKController
{
protected static $pageIndex, $pageSize;
abstract public function Main();
/**
* 处理请求参数中带有翻页参数
* @param string $indexField
* @param string $rowsField
*/
final protected function postByPages($indexField = 'PageIndex', $rowsField = 'PageSize')
{
self::$pageIndex = $this->checkPostParamIsEmpty($indexField) ? Formats::isNumeric(Request::post($indexField)) : 1;
self::$pageSize = $this->checkPostParamIsEmpty($rowsField) ? Formats::isNumeric(Request::post($rowsField)) : 10;
}
/**
* 处理请求参数有时间区间参数,转为 SQL 查询参数
* @param $dbViewStartField
* @param null $dbViewEndField
* @param string $startTimeField
* @param string $endTimeField
* @return array
*/
final protected function postByDateIntervalToSQLParam($dbViewStartField, $dbViewEndField = null,
$startTimeField = 'StartTime', $endTimeField = 'EndTime')
{
$result = [];
$startTimeFieldIsEmpty = Request::has($startTimeField, 'post');
$endTimeFieldIsEmpty = Request::has($endTimeField, 'post');
if ($startTimeFieldIsEmpty && $endTimeFieldIsEmpty) {
$startTime = strtotime(Request::post($startTimeField));
$endTime = strtotime(Request::post($endTimeField));
$startTime < $endTime ?: Statics::error(500481);
// 如果数据表查询的字段为相同字段可为 null
!empty($dbViewEndField) ?: $dbViewEndField = $dbViewStartField;
$result[] = "unix_timestamp(`{$dbViewStartField}`) >= '{$startTime}'";
$result[] = "unix_timestamp(`{$dbViewEndField}`) <= '{$endTime}'";
}
return $result;
}
final protected function checkPostParamIsEmpty($field, $tips = null)
{
$isNotEmpty = Request::has($field, 'post');
$isNotEmpty ?: ($tips == null ?: fail(language($tips)));
if ($tips != null) {
return is_string(Request::post($field)) ? trim(Request::post($field)) : Request::post($field);
}
return $isNotEmpty;
}
final protected function checkPostParamIsExists($field, $tips = null)
{
$isExists = Request::has($field, 'post', false);
if (!$isExists) {
// 不存在 POST 请求的参数时
$tips == null ?: Statics::error($tips);
}
return $isExists;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。