123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\services\system;
- use app\model\system\SystemLog;
- use app\services\system\admin\SystemAdminServices;
- use app\services\system\admin\SystemMenusServices;
- use qiniu\basic\BaseServices;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- /**
- * 系统日志
- * Class SystemLogServices
- * @package app\services\system\log
- * @mixin SystemLog
- */
- class SystemLogServices extends BaseServices
- {
- /**
- * 构造方法
- * SystemLogServices constructor.
- * @param SystemLog $model
- */
- public function __construct(SystemLog $model)
- {
- $this->model = $model;
- }
- /**
- * 记录访问日志
- * @param int $adminId
- * @param string $adminName
- * @param string $module
- * @param string $rule
- * @param string $ip
- * @param string $type
- * @param string $params
- * @return bool
- */
- public function recordAdminLog(int $adminId, string $adminName, string $module, string $rule, string $ip, string $type, string $params)
- {
- /** @var SystemMenusServices $service */
- $service = app()->make(SystemMenusServices::class);
- $data = [
- 'method' => $module,
- 'add_time' => time(),
- 'admin_name' => $adminName,
- 'path' => $rule,
- 'page' => $service->getVisitName($rule) ?: '未知',
- 'ip' => $ip,
- 'type' => $type,
- 'params' => $params,
- ];
- if ($type == 'store') {
- $data['store_id'] = $adminId;
- } else {
- $data['admin_id'] = $adminId;
- }
- if ($this->model->save($data)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 获取系统日志列表
- * @param array $where
- * @param int $level
- * @return array
- * @throws DataNotFoundException
- * @throws DbException
- * @throws ModelNotFoundException
- */
- public function getLogList(array $where, int $level)
- {
- [$page, $limit] = $this->getPageValue();
- if (!$where['admin_id']) {
- /** @var SystemAdminServices $service */
- $service = app()->make(SystemAdminServices::class);
- $where['admin_id'] = $service->getAdminIds($level);
- }
- $list = $this->model->getList($where, '*', $page, $limit);
- $count = $this->model->getCount($where);
- return compact('list', 'count');
- }
- }
|