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

namespace app\api\controller\dynamic_redpacket;

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


class Index extends Base
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\DynamicRedpacket;
    }
    
    public function index(){
        $config = $this->model->getSet();
        $user = $this->user;
        $redpacket_sequence = Db::name("bbfx_dynamic_redpacket_sequence")->where(['uniacid'=>UNIACID])->order("id desc")->find();
        $redpacket_realtime_price = 0;
        $money = 0;
        $rucang_money = 0;
        $property_part = 0;
        $user_property_part = 0;
        $user_dividend_money = 0;
        $dividend_money = 0;
        $redpacket_part = 0;
        if($redpacket_sequence['status'] == 0){
            $redpacket_realtime_price = $redpacket_sequence['redpacket_realtime_price'];
            $money = Db::name("bbfx_dynamic_redpacket_sequence_item")->where(['pid'=>$redpacket_sequence['id'],'user_id'=>$user['id']])->value("money");
            $money = round($money,2);
            $rucang_money = $redpacket_sequence['rucang_money'];
            $property_part  = $redpacket_sequence['property_part'];
            $user_property_part = Db::name("bbfx_dynamic_redpacket_sequence_item")->where(['pid'=>$redpacket_sequence['id'],'user_id'=>$user['id']])->value("user_property_part");
            $user_property_part = round($user_property_part,2);
            $user_dividend_money = Db::name("bbfx_dynamic_redpacket_sequence_item")->where(['pid'=>$redpacket_sequence['id'],'user_id'=>$user['id']])->value("user_dividend_money");
            $user_dividend_money = round($user_dividend_money,2);
            $dividend_money = $redpacket_sequence['dividend_money'];
            $redpacket_part = $redpacket_sequence['redpacket_part'];
        }
        else{
            $redpacket_part = $config['redpacket_part'];
            $rucang_money = $config['rucang_money'];
        }
        
        $result = array(
            "redpacket_realtime_price"=>$redpacket_realtime_price,
            "money"=>$money,
            "rucang_money"=>$rucang_money,
            "property_part"=>$redpacket_part,
            "redpacket_part"=>$redpacket_part,
            "user_property_part"=>$user_property_part,
            "user_dividend_money"=>$user_dividend_money,
            "dividend_money"=>$dividend_money,
        );
        
        __success("操作成功",$result);
    }
}