<?php
/*
 本代码由 焕岱科技 创建
 技术支持 WX：15285007200
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace app\admin\controller\bbfxshop\short_video;

use app\admin\controller\bbfxshop\Base;
use think\Db;


class Comment extends Base
{
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\ShortVideo;
    }
    
    public function getList(){
        $params = $this->param();
        
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        $keyword = $params['keyword'];
        $status = $params['status'];
        
        $where = array("a.uniacid"=>UNIACID);
        if(!empty($keyword)){
            $where['a.content'] = ['like','%'.$keyword.'%'];
        }
        
        if($status !== ''){
            $where['a.status'] = $status;
        }
        
        $list = Db::name("bbfx_short_video_comment")->alias("a")->join("bbfx_short_video_list b","a.pid=b.id","LEFT")->join("bbfx_user c","a.user_id=c.id","LEFT")->where($where)->order('a.createtime desc,a.id desc')->field("a.*,b.title,c.nickname,avatar")->limit(($pindex - 1) * $psize,$psize)->select();
        $total = Db::name("bbfx_short_video_comment")->alias("a")->join("bbfx_short_video_list b","a.pid=b.id","LEFT")->join("bbfx_user c","a.user_id=c.id","LEFT")->where($where)->count();
        
        foreach ($list as $key => &$val){
            $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
            $val['avatar'] = cdnurl($val['avatar']);
        }
        unset($val);
        
        __success("操作成功",['total'=>$total,'list'=>$list]);
    } 
    
    public function shenhe(){
        $params = $this->param();
        
        
        $ids = explode(",",$params['id']);
        
        $status = intval($params['status']);
        $comment = Db::name("bbfx_short_video_comment")->where(["uniacid"=>UNIACID,'status'=>0,"id"=>['in',$ids]])->find();
        if(empty($comment)){
            __error("请选择需要审核的数据");
        }
        
        $res = Db::name("bbfx_short_video_comment")->where(['id'=>['in',$ids]])->update(['status'=>$status]);
        if($res){
            \app\admin\model\AdminLog::record("","",['id'=>$ids,'status'=>$status],"bbfx_short_video_comment");
            __success("操作成功");
        }
        else{
            __success("操作成功");
        }
    }
    
    public function delete(){
        $this->commonDelete('bbfx_short_video_comment');
    }
}