<?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\citys\model;
use think\Model;

class CitysReply extends Model{

    protected $pk = 'id';
    protected $autoWriteTimestamp = true;
    

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

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

    //添加或编辑
    public static function postReply($param){
        $data['reply']             = $param['content'];
        $data['member_miniapp_id'] = $param['member_miniapp_id'];
        $data['uid']               = $param['uid'];
        $data['info_id']           = $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::get($id);
        $result->state = $result->state ? 0 : 1;
        return $result->save();;
    }
}