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

namespace app\model;


use think\Request;
use think\Session;

class GOperatingRecords extends BaseModel
{

    /**
     * 行为日志记录
     *
     * @param int $agents_id
     * @param string $type
     * @param string $remark
     * @param $houses_id
     * @return bool|false|int
     */
    public function record($agents_id = 0, $type = '' ,$remark = '', $houses_id = '')
    {
        $result = false;
        $agents_id = $agents_id ? $agents_id : Session::get('userId');
        if ($agents_id>0) {
            $request = Request::instance();
            $name = Session::get('userName');
            if ($name) {
                $name = db('a_agents')->where('id',$agents_id)->value('name');
            }
            $data = [
                'agents_id'      => $agents_id,
                'name'           => $name,
                'url'            => $request->url(),
                'ip'             => $request->ip(),
                'remark'         => $remark,
                'houses_id'      => $houses_id,
                'type'           => $type,
                'create_time'    => date('Y-m-d H:i:s'),
            ];
            $result = $this->isUpdate(false)->data($data)->save();
        }

        return $result;
    }
}