<?php


namespace app\admin\controller\bbfxshop\pabonus;

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


class User extends Base
{
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Pabonus;
    }
    
    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);
        $type = $this->param("type/d");
        $keyword = $this->param("keyword/s");
        if(!empty($keyword)){
            if($type == 1){
                $where['b.name'] = ['like','%'.$keyword.'%'];
            }
            else if($type == 2){
                $where['b.id'] = intval($keyword);
            }
            else if($type == 3){
                $where['a.user_id'] = intval($keyword);
            }
        }
        
        $list = Db::name("bbfx_pabonus_user")->alias("a")->join("bbfx_pabonus_goods b","a.pid=b.id","LEFT")->join("bbfx_user c","a.user_id=c.id","LEFT")->where($where)->field("a.*,b.name,c.nickname,c.avatar")->order('a.id desc')->limit(($pindex - 1) * $psize,$psize)->select();
        $total = Db::name("bbfx_pabonus_user")->alias("a")->join("bbfx_pabonus_goods b","a.pid=b.id","LEFT")->join("bbfx_user c","a.user_id=c.id","LEFT")->where($where)->count();
        
        foreach ($list as $key => &$val){
            $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
            $val['avatar'] = cdnurl($val['avatar']);
        }
        unset($val);
        
        __success("操作成功",['total'=>$total,'list'=>$list]);
    }

    public function delete(){
        $this->commonDelete("bbfx_pabonus_user");
    }
}