70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
|
|
class Controller extends BaseController
|
|
{
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
|
|
|
protected $res = [
|
|
'httpCode' => 200,
|
|
'message' => '操作成功',
|
|
'errorCode' => 0,
|
|
'errorMessage' => '',
|
|
];
|
|
|
|
protected $log;
|
|
|
|
protected function setValidatorFailResponse($errorMessage)
|
|
{
|
|
return $this->res = [
|
|
'httpCode' => 400,
|
|
'errorCode' => 400416,
|
|
'errorMessage' => $errorMessage,
|
|
];
|
|
}
|
|
|
|
protected function setBeforeUpdateForLog($data)
|
|
{
|
|
$this->log->before_update = is_array($data) ? json_encode($data, 256) : $data;
|
|
}
|
|
|
|
protected function setAfterUpdateForLog($data)
|
|
{
|
|
$this->log->after_update = is_array($data) ? json_encode($data, 256) : $data;
|
|
}
|
|
|
|
protected function addLog($targetId = 0, $targetField = '', $targetType = '')
|
|
{
|
|
if ($targetType) {
|
|
$this->log->target_type = $targetType;
|
|
}
|
|
|
|
return $this->log->add($targetId, $targetField);
|
|
}
|
|
|
|
public function success($data=[], $msg = "")
|
|
{
|
|
return [
|
|
"success" => true,
|
|
"msg" => $msg,
|
|
"data" => $data
|
|
];
|
|
}
|
|
|
|
public function error($errorCode, $msg = "")
|
|
{
|
|
return [
|
|
"success" => false,
|
|
"msg" => $msg,
|
|
"errorCode" => $errorCode,
|
|
"data" => []
|
|
];
|
|
}
|
|
}
|