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

namespace app\admin\controller\bbfxshop;

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


class Plugin extends Base
{

    public function _initialize(){
        parent::_initialize();
    }

    public function list(){
        $list = \app\common\model\bbfxshop\Plugin::getPlugins();
        __success("操作成功",['list'=>$list]);
    }

    public function buyPlugin(){
        $id = $this->param("id/d");
        
        $id_text = random(32);
        Cache::set($id_text,$id);
        $pay_url = request()->domain()."/api/plugin/buy?id=".$id_text;
        $result = \app\common\model\QRcode::create($pay_url,"pay_qrcode_".$id);
        if($result['code'] != 1){
            __result($result);
        }
        $qrcode = cdnurl($result['data']['url'])."?t=".time();
        __success("操作成功",['qrcode'=>$qrcode]);
    }

    public function agreePluginxieyi(){
        $plugin_id = $this->param("plugin_id/d");
        if(empty($plugin_id)){
            __error("应用ID错误");
        }

        $plugin_xieyi = Db::name("bbfx_base")->where(['uniacid'=>UNIACID])->value("plugin_xieyi");
        if(empty($plugin_xieyi)){
            $plugin_xieyi = [];
        }
        else{
            $plugin_xieyi = iunserializer($plugin_xieyi);
        }
        
        if(in_array($plugin_id,$plugin_xieyi)){
            __error("已同意应用协议");
        }

        $plugin_xieyi[] = $plugin_id;
        Db::name("bbfx_base")->where(['uniacid'=>UNIACID])->update(['plugin_xieyi'=>iserializer($plugin_xieyi)]);
        
        __success("操作成功");
    }
}