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

namespace app\admin\controller\bbfxshop\deposit_release;

use app\admin\controller\bbfxshop\Base;
use think\Db;
use app\common\model\bbfxshop\User;


class Withdrawal extends Base
{

    public function _initialize(){
        parent::_initialize();
    }
    
    public function check(){
        global $_W;
        $params = $this->param();
        $id = intval($params['id']);
        $status = intval($params['status']);
        $is_manual = intval($params['is_manual']);
        $remarks = $params['remarks'];

        $result = \app\common\model\bbfxshop\UserTixian::dakuan($id,$status,$is_manual,$remarks);

        if($result['code'] == 1){
            \app\admin\model\AdminLog::record("","",['id'=>$id,'status'=>$status],"bbfx_withdrawal_log");
        }
        
        __result($result); 
        
    }
    
    public function list(){
        $params = $this->param();
        
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        $where = array("a.uniacid"=>UNIACID,'a.withdrawal_type'=>6);
        $status = trim($params['status']);
        $startTime = trim($params['startTime']);
        $endTime = trim($params['endTime']);
        
        $keyword = trim($params['keyword']);
        
        $type = max(1,intval($params['type']));
        if(!empty($keyword)){
            
            if($type == 1){
                $where['b.nickname'] = ['like',"%".$keyword."%"];
            }
            else if($type == 2){
                $where['a.realname'] = ['like',"%".$keyword."%"];
            }
            else if($type == 3){
                $where['b.mobile'] = $keyword;
            }
            else if($type == 4){
                $where['a.user_id'] = intval($keyword);
            }
        }
         
        if($status != ''){
            $where['a.status'] = intval($status);
        }
        
        $whereTime = [];
        if($startTime){
            $startTime = strtotime($startTime." 00:00:00");
            $where['a.createtime'] = ['>=',$startTime];
        }
        
        if($endTime){
            $whereTime['a.createtime'] = ['<=',$endTime];
        }
        
        $list = Db::name("bbfx_withdrawal_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 &$val){
    	    $val['avatar'] = cdnurl($val['avatar']);
    	    $val['skqrcode'] = cdnurl($val['skqrcode']);
    	    $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
    	    if($val['paytime']){
    	        $val['paytime'] = date("Y-m-d H:i:s",$val['paytime']);
    	    }
    	    else{
    	        $val['paytime'] = "";
    	    }
    	}
    	unset($val);
      
    	$total = Db::name("bbfx_withdrawal_log")->alias("a")->join("bbfx_user b","a.user_id=b.id")->where($where)->where($whereTime)->count();
      	
        __success("操作成功",['total'=>$total,'list'=>$list]);
    }
    
    public function delete(){
        $this->commonDelete("bbfx_withdrawal_log");
    }
    
}