<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 评论管理
 */
namespace app\ais\model;
use think\Model;

class AisInfoReply extends Model{

    protected $pk = 'id';
    protected $autoWriteTimestamp = true;
    protected $datetime_format = 'Y-m-d H:i:s.u';

    //用户
    public function user(){
        return $this->hasOne('app\common\model\SystemUser','id','uid');
    }

    //用户
    public function info(){
        return $this->hasOne('AisInfo','id','info_id');
    }

    //添加或编辑
    public static function postReply($param){
        $data['reply']             = trim($param['content']);
        $data['member_miniapp_id'] = (int)$param['member_miniapp_id'];
        $data['uid']               = (int)$param['uid'];
        $data['info_id']           = (int)$param['info_id'];
        $data['create_time']       = time();
        $data['state']             = 0;
        return self::create($data);
    }

    /**
     * 锁定
     * @param integer $id
     */
    public static function lock(int $id){
        $result = self::where(['id' => $id])->find();
        $result->state = $result->state ? 0 : 1;
        return $result->save();;
    }
}