<?php
/**
 * Created by PhpStorm.
 * User: fuju
 * Date: 2018/1/20
 * Time: 17:52
 */

namespace app\model;


use think\Request;

class GOperatingRecords extends BaseModel
{
    /**
     * 行为日志记录
     *
     * @param int $agents_id
     * @param array $data
     * @param string $type
     * @param string $remark
     * @return bool|false|int
     */
    public function record($agents_id = 0, $data = [],$type = '' ,$remark = '')
    {
        $result = false;
        if ($agents_id>0) {
            $request = Request::instance();
            $name = db('a_agents')->where('id',$agents_id)->value('username');
            $data = [
                'agents_id'      => $agents_id,
                'name'           => $name,
                'request_method' => $request->method(),
                'url'            => $request->url(),
                'data'           => $data,
                'ip'             => $request->ip(),
                'remark'         => $remark,
                'type'           => $type,
            ];
            $result = $this->isUpdate(false)->data($data)->save();
        }

        return $result;
    }
}