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

namespace app\admin\controller\bbfxshop\activity;

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


class Baoming extends Base
{

    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Activity;
    }

    public function getList(){
        $page = max(1,$this->param("page/d"));
        $limit = max(10,$this->param("limit/d"));
        $keyword = $this->param("keyword/s");
        $startTime = $this->param("startTime/s");
        $endTime = $this->param("endTime/s");
        $type = $this->param("type/d");
        $where = ['a.uniacid'=>UNIACID,'a.is_pay'=>1];
        if($keyword){
            if($type == 1){
                $where['c.title'] = ['like',"%".$keyword."%"];
            }
            else if($type == 2){
                $where['a.realname'] = ['like',"%".$keyword."%"];
            }
            else if($type == 3){
                $where['a.mobile'] = ['like',$keyword];
            }
            else if($type == 4){
                $where['a.user_id'] = intval($keyword);
            }
            else if($type == 5){
                $where['b.nickname'] = ['like',"%".$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_activity_baoming")->alias("a")->join("bbfx_user b","a.user_id=b.id","left")->join("bbfx_activity_list c","a.activity_id=c.id","left")->where($where)->field("a.*,b.avatar,b.nickname,c.title as activity_title,c.is_hexiao")->order("a.id desc")->limit(($page-1)*$limit,$limit)->select();
        $total = Db::name("bbfx_activity_baoming")->alias("a")->join("bbfx_user b","a.user_id=b.id","left")->join("bbfx_activity_list c","a.activity_id=c.id","left")->where($where)->count();
        
        foreach ($list as $key => &$val){
            $val['avatar'] = cdnurl($val['avatar']);
            $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
        }
        unset($val);
        
        
        __success("操作成功",['list'=>$list,'total'=>$total]);
    }
}