12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Repositories\Eloquent;
- use App\Exceptions\HOError;
- use Illuminate\Support\Facades\Log;
- class BaseRepository
- {
- protected $startTime;
- protected $error;
- const SUCCESS_CODE = 1000;
- public function startTime()
- {
- Log::debug('获取程序开始时间');
- $this->startTime = microtime(TRUE);
- return $this->startTime;
- }
- /**
- * 成功返回
- */
- public function response($data=null, $msg = '成功')
- {
- return response()->horesp(1000, $data, $msg);
- }
- public function fail($data=null, $msg = '失败')
- {
- return response()->horesp(9999, $data, $msg);
- }
- /**
- * 异常错误
- *
- * @return \App\Exceptions\HOError
- */
- public function error()
- {
- $this->error = new HOError();
- return $this->error;
- }
- /**
- * 统一格式输出日志
- *
- * @param string $typeName 类别名
- * @param string $startTime 开始时间
- * @param array $log 日志详情
- * @param string $ac 指定动作
- */
- public function setLog(string $typeName, $startTime = 0.00, $log = [], $ac = 'info')
- {
- //传入的时间
- $sTime = $startTime;
- //当前时间,相当于结束时间
- $eTime = microtime(TRUE);
- //计算时间差
- $diffTime = (($eTime - $sTime) * 1000);
- $msg = '执行时间:'.round($diffTime, 3).'ms'.' 执行内容:'.$typeName;
- switch ($ac){
- case 'debug':
- Log::debug($msg, $log);
- break;
- case 'info':
- Log::info($msg, $log);
- break;
- case 'error':
- Log::error($msg, $log);
- break;
- }
- }
- }
|