<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
/**
 * 提建议
 */
class Newmessage extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    public function send(){
        $msg = $this->request->request('msg');
        $images = $this->request->request('images');
        if(!$msg){
            $this->error('不能为空');
        }

        if($images && strpos($images,',')){
            if(count(explode(',',$images)) > 9){
                $this->error('一次最多只能上传9张图片');
            }
        }

        $data = [
            'user_id' => $this->auth->id,
            'message' => $msg,
            'images' => $images,
            'createtime'=> time(),
            'updatetime'=> time(),
        ];

        $mid = Db::name('news_message')->insertGetId($data);

        $this->success('提交成功');
    }

    //我提出的建议
    public function lists(){
        $list = Db::name('news_message')->where('user_id',$this->auth->id)->order('id desc')->autopage()->select();
        $list = list_domain_image($list,['images']);
        $this->success('success',$list);
    }
}
