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

namespace app\api\controller\apopup;

use app\api\controller\Base;
use think\Db;


class Index extends Base
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    
    public function getList(){
        
        $all = Db::name("bbfx_apopup")->where(['uniacid'=>UNIACID,'status'=>1])->order('sort desc')->select();
        $user = $this->user;
        $list = [];
        
        $set = Db::name("bbfx_apopup_set")->where(['uniacid'=>UNIACID])->find();
        if($set['status'] != 1){
            __error('未开启活动弹窗');
        }
        
        foreach ($all as $key => &$val){
            $val['thumb'] = cdnurl($val['thumb']);
            $val['link'] = iunserializer($val['link']);
            
            if($val['tanchu'] > 0 && !empty($user)){
                $count = Db::name("bbfx_apopup_log")->where(['uniacid'=>UNIACID,'user_id'=>$user['id'],'pid'=>$val['id']])->count();
                if($count < $val['tanchu']){
                    $list[] = $val;
                    $data = array(
                        "uniacid"=>UNIACID,
                        "user_id"=>$user['id'],
                        "pid"=>$val['id'],
                        "createtime"=>time()
                    );
                    Db::name("bbfx_apopup_log")->insert($data);
                }
            }
            else{
                $list[] = $val;
            }
        }
        unset($val);
        
        if(empty($list)){
            __error('无活动弹窗数据');
        }
        
        __success("操作成功",['set'=>$set,'list'=>$list]);
    }
}