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

namespace app\api\controller\fenxiao;

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


class Poster extends Base
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Fenxiao;
    }

    public function index(){
        $params = $this->param();
        
        $posters = Db::name("bbfx_fenxiao_poster")->where(['uniacid'=>UNIACID,'status'=>1])->field(['id','name','content','jump_type'])->order('sort desc')->select();
        
        if(empty($posters)){
            $posters[] = array(
                "id"=>0,
                "name"=>"默认海报",
                "content"=>'a:4:{s:2:"bg";s:27:"/assets/images/poster-bg.png";s:5:"width";i:320;s:6:"height";i:919;s:4:"list";a:3:{i:0;a:8:{s:4:"type";s:6:"avatar";s:7:"content";s:23:"/assets/images/logo.png";s:5:"align";s:0:"";s:5:"width";i:73;s:6:"height";i:73;s:4:"left";i:35;s:3:"top";i:65;s:5:"style";s:6:"radius";}i:1;a:10:{s:4:"type";s:8:"nickname";s:7:"content";s:12:"这是昵称";s:5:"align";s:0:"";s:5:"width";i:76;s:6:"height";i:32;s:4:"left";i:109;s:3:"top";i:86;s:8:"fontSize";i:16;s:5:"color";s:7:"#000000";s:5:"style";s:0:"";}i:2;a:8:{s:4:"type";s:6:"qrcode";s:7:"content";s:25:"/assets/images/qrcode.png";s:5:"align";s:0:"";s:5:"width";i:140;s:6:"height";i:140;s:4:"left";i:90;s:3:"top";i:153;s:5:"style";s:0:"";}}}'
            );
        }
        
        $list = [];
        foreach ($posters as $key => $val){
            $result = \app\common\model\bbfxshop\Poster::createPoster($val,$this->user['id'],$params['platform']);
            if(!empty($result)){
                $list[] = $result;
            }
        }
        
        if(empty($list)){
            __error("暂未配置海报");
        }
        
        __success("操作成功",['list'=>$list]);
    }
}