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

namespace app\admin\controller\bbfxshop\queue_mode;

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\QueueMode;
    }
    
    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);
        
        $list = Db::name("bbfx_queue_mode_user")->alias("a")->join("bbfx_user b","a.user_id=b.id","LEFT")->where($where)->field("a.*,b.nickname,b.avatar")->order("a.id asc")->limit(($pindex - 1) * $psize,$psize)->select();
        $total = Db::name("bbfx_queue_mode_user")->alias("a")->join("bbfx_user b","a.user_id=b.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("操作成功",['total'=>$total,'list'=>$list]);
    }
    public function getRecords(){
        $params = $this->param();
        $pindex = max(1, intval($params["page"]));
        $pid = intval($params['pid']);
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        
        $where = array("a.uniacid"=>UNIACID);
        if($pid > 0){
            $where['a.pid'] = $pid;
        }
        
        $list = Db::name("bbfx_queue_mode_user_record")->alias("a")->join("bbfx_queue_mode_user b","a.pid=b.id","LEFT")->join("bbfx_user c","b.user_id=c.id","LEFT")->where($where)->field("a.*,c.nickname,c.avatar,b.user_id")->order("a.id asc")->limit(($pindex - 1) * $psize,$psize)->select();
        $total = Db::name("bbfx_queue_mode_user_record")->alias("a")->join("bbfx_queue_mode_user b","a.pid=b.id","LEFT")->join("bbfx_user c","b.user_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("操作成功",['total'=>$total,'list'=>$list]);
    }

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

}