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

namespace app\admin\controller\bbfxshop\feedback;

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


class Feedback extends Base
{

    protected $model = null;

    public function getList(){
        $params = $this->param();
        
        
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        
        $where = array("uniacid"=>UNIACID);
        
        $list = Db::name("bbfx_feedback")->where($where)->order('id desc')->limit(($pindex - 1) * $psize,$psize)->select();
        $total = Db::name("bbfx_feedback")->where($where)->count();
        foreach($list as $key => &$val){
            $user = Db::name("bbfx_user")->where(['id'=>$val['user_id']])->field("id,nickname,avatar")->find();
            $user['avatar'] = cdnurl($user['avatar']); 
            $val['user'] = $user;
            $val['statusText'] = "待处理";
            if($val['status'] == 1){
                $val['statusText'] = "已处理";
            }
            $val['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
        }
        unset($val);
        
        __success("操作成功",['total'=>$total,'list'=>$list]);
    }
    
    public function status(){
        $params = $this->param(['id/d','status/d']);
        
        $status = 1;
        
        $res = Db::name("bbfx_feedback")->where("id",$params['id'])->update(['status'=>$status]);
        if($res){
            \app\admin\model\AdminLog::record("","",["id"=>$params['id'],"id",$params['id']],"bbfx_feedback");
            __success("操作成功");
        }
        else{
            __success("操作成功");
        }
    }
    
    public function detail(){
        $params = $this->param();
        
        $info = Db::name("bbfx_feedback")->where("id",$params['id'])->find();
        
        
        if(empty($info)){
            __error("数据不存在");
        }
        __success('操作成功',$info);
    }
    
    
    public function delete(){
        $this->commonDelete("bbfx_feedback");
    }
    
}