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

namespace app\api\controller\crazy;

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

class Group extends Base
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Crazy;
    }
    
    public function getList(){
        $page = max(1,$this->param("page/d"));
        $limit = 20;
        
        $list = Db::name("bbfx_crazy_group_user")->alias("a")->join("bbfx_crazy_group b","a.group_id=b.id","LEFT")->where(['a.uniacid'=>UNIACID,'a.user_id'=>$this->user['id']])->group("a.group_id")->order("b.id desc")->field("b.*")->select();
        
        foreach ($list as $key => &$val){
            $user_list = Db::name("bbfx_crazy_group_user")->alias("a")->join("bbfx_crazy_user b","a.pid=b.id","LEFT")->where(["a.uniacid"=>UNIACID,"a.group_id"=>$val['id']])->order("a.id asc")->field("a.*,b.info")->select();
            
            foreach ($user_list as $k => &$v){
                $info = iunserializer($v['info']);
                $v['avatar'] = cdnurl($info['avatar']);
                $v['nickname'] = $info['nickname'];
                unset($v['info']);
            }
            unset($v);
            
            $val['user_list'] = $user_list;
            
            $val['stime'] = date('Y-m-d H:i:s',$val['stime']);
            if(!empty($val['etime'])){
                $val['etime'] = date('Y-m-d H:i:s',$val['etime']);
            }
            
        }
        unset($val);
        
        __success("操作成功",['list'=>$list]);
    }
}