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

namespace app\admin\controller\bbfxshop\txabonus;

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



class User extends Base
{
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Txabonus;
    }

    public function getMoneyList(){
        $params = $this->param();
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):20;
        
        $where = array("a.uniacid"=>UNIACID,'a.type'=>37);
        
        $keyword = trim($params['keyword']);
        $startTime = trim($params['startTime']);
        $endTime = trim($params['endTime']);
        $type = max(1,intval($params['type']));
        if($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['b.id'] = intval($keyword);
            }
            else if($type == 5){
                $where['a.remarks'] = ['like','%'.$keyword.'%'];
            }
            
        }
        
        if($startTime){
            $startTime = strtotime($startTime." 00:00:00");
            $where['a.createtime'] = ['>=',$startTime];
        }
        
        $whereTime = [];
        if($endTime){
            $endTime = strtotime($endTime." 23:59:59");
            $whereTime['a.createtime'] = ['<=',$endTime];
        }
        $export = intval($params['export']);
        if($export == 1){
            $pindex = 1;
            $psize = 999999;
        }
        
        $list = Db::name("bbfx_fenxiao_order")->alias("a")->join("bbfx_user b","a.user_id = b.id")->where($where)->where($whereTime)->field('a.*,b.nickname,b.avatar,b.mobile')->order('a.createtime desc,a.id 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:s",$val['createtime']);
            $val['title'] = Fenxiao::getTypeText($val['type']);
    	    if($export == 1){
    	        $export_list[] = array(
    	            $val['id'],
    	            "【".$val['user_id']."】".$val['nickname'],
    	            $val['money'],
    	            $val['title'],
    	            $val['createtime']
    	        );
    	    }
    	}
    	unset($val);
    	
    	if($export == 1){
    	    $headArr = ["ID","用户信息","奖励金额","标题","操作时间"];
    	    \app\common\model\PhpOffice::excelExport("fenxiao_order-".date("Y-m-d"),$headArr,$export_list);
    	}
    	
    	$total = Db::name("bbfx_fenxiao_order")->alias("a")->join("bbfx_user b","a.user_id = b.id")->where($where)->where($whereTime)->count();
    	
    	__success("操作成功",['total'=>$total,'list'=>$list]);
    }
}