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

namespace app\admin\controller\bbfxshop\image_check;

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


class Log extends Base
{
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\ImageCheck;
    }
    
    public function getList(){
        $params = $this->param();
        
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        
        $where = array("a.uniacid"=>UNIACID);
        
        $keyword = trim($params['keyword']);
        $startTime = trim($params['startTime']);
        $endTime = trim($params['endTime']);
        
        $type = max(1,intval($params['type']));
        if(!empty($keyword)){
            
            if($type == 1){
                $where['b.nickname'] = ['like',"%".$keyword."%"];
            }
            else if($type == 2){
                $where['b.realname'] = ['like',"%".$keyword."%"];
            }
            else if($type == 3){
                $where['b.mobile'] = $keyword;
            }
            else if($type == 4){
                $where['a.user_id'] = intval($keyword);
            }
        }
        
        $whereTime = [];
        if($startTime){
            $startTime = strtotime($startTime." 00:00:00");
            $where['a.createtime'] = ['>=',$startTime];
        }
        
        if($endTime){
            $endTime = strtotime($endTime." 23:59:59");
            $whereTime['a.createtime'] = ['<=',$endTime];
        }
        
        $list = Db::name("bbfx_image_check_log")->alias("a")->join("bbfx_user b","a.user_id=b.id")->where($where)->where($whereTime)->field('a.*,b.avatar,b.nickname')->order('a.createtime desc')->limit(($pindex - 1) * $psize,$psize)->select();
    	
    	foreach($list as $key=>&$val){
    	    $val['avatar'] = cdnurl($val['avatar']);
    	    $val['createtime'] = date("Y.m.d H:i",$val['createtime']);
    	    if($val['checktime'] > 0){
                $val['checktime'] = date("Y.m.d H:i",$val['checktime']);
            }
            else{
                $val['checktime'] = "";
            }
    	    $val['statusText'] = "未检测";
    	    if($val['status'] == 1){
    	        $val['statusText'] = "检测通过";
    	    }
    	    else if($val['status'] == 2){
                $val['statusText'] = "检测拒绝";
    	    }
    	    $val['result'] = iunserializer($val['result']);

            $url = Db::name("attachment")->where(['id'=>$val['pid']])->value("url");
            $val['url'] = cdnurl($url);
    	}
    	unset($val);
    	
        $total = Db::name("bbfx_image_check_log")->alias("a")->join("bbfx_user b","a.user_id=b.id")->where($where)->where($whereTime)->count();
    	$total = intval($total);
    	
    	__success("操作成功",['total'=>$total,'list'=>$list]);
    }
    
    public function delete(){
        $this->commonDelete("bbfx_image_check_log");
    }
    
}