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

namespace app\common\model\bbfxshop;

use think\Model;
use think\Db;
use app\common\model\bbfxshop\User;


class Floatamount extends Model
{
    public static function getSet(){
        global $_W;
        $base = $_W['base'];
        if(empty($base)){
            $base = \app\common\model\bbfxshop\Common::getConfig(true);
        }
        
        return $base['floatamount'];
    }

    public static function jisuanGoodsPrice($goods){
        $config = self::getSet();
        if($config['status'] != 1){
            return __json(0,"未开启浮动金额");
        }
        $float_amount = 0;
        $plugin = iunserializer($goods['plugin']);
        if($plugin['floatamount']['status'] == 1){
            $type = $plugin['floatamount']['type'];
            $price = max(0,round($plugin['floatamount']['price'],2));
            if($price > 0){
                if($type == 1){
                    $min = 0;
                    $max = $price;
                }
                else if($type == 2){
                    $min = 0 - $price;
                    $max = 0;
                }
                else{
                    $min = 0 - $price;
                    $max = $price;
                }
                $factor = 100;
                $float = random_int($min * $factor, $max * $factor) / $factor;
                $float_amount = $float;
            }
            
        }

        return __json(1,"操作成功",['float_price'=>round($float_amount,2)]);
    }
}