<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
/*
通用提交
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://myucms.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Api extends Controller
{
    //添加留言
    public function liuyan()
    {
        //查询当前ip留言次数控制
        if (fun_tj('comment','time', Date_k(0), 'time', Date_k(1), array('ip'=>$_SERVER["REMOTE_ADDR"]))>set('iply',3)) {
            $this->error(set('ipts',3));
        }
        $_data['time'] = time();
        $_data['name'] = xss(get('name'));
        $_data['email'] = xss(get('email'));
        $_data['phone'] = xss(get('phone'));
        $_data['content'] = xss(get('content'));
        $_data['ip'] = $_SERVER['REMOTE_ADDR'];
        if (!Db::name('comment')->strict(false)->data($_data)->insert()) {
            $this->error('提交留言失败');
        } else {
            if (set('tzly',3)==1) {
                //添加发送短信通知站长记录
                $data['phone'] = set('phone');
                $data['content'] = '【留言通知】来自[' . set('title') . ']您新的留言信息请登录网站后台查看';
                $data['open'] = 1;
                $data['uid'] = 1;
                $data['ip'] = $_SERVER["REMOTE_ADDR"];
                $data['time'] = time();
                $data['fl'] = 6;
                Db::name('yanzhengma')->insert($data);
                duanxin(set('phone'), $data['content']);
            } 
            $this->success('提交留言成功');
        }
    }
}