<?php
namespace app\http\model;

use fastphp\base\Model;
use enum\http\Order as HttpOrderEnum;

class Package extends Model
{
    protected $table = 'http_package';

    
    // order_info:{
    //     order_type:1,//1:预储值、2：短效无限量、3：短效包天、4：短效包量、5：长效游戏
    //     money:1,
    //     pay_type:2,//1聚币 2支付宝 3微信
    //     data:{}
    // },
    public function get_price($data) {
        $where = [];
        
        if (isset($data['data']['title'])) {
            unset($data['data']['title']);
        }
        if (isset($data['data']['packId'])) {
            unset($data['data']['packId']);
        }
        if (isset($data['data']['packType'])) {
            unset($data['data']['packType']);
        }
        if (isset($data['data']['ipAmount'])) {
            unset($data['data']['ipAmount']);
        }
        if (isset($data['data']['ids'])) {
            unset($data['data']['ids']);
        }
        
        switch ($data['order_type']) {
            case 2:
                $where = $data['data'];
                $where['package_type'] = HttpOrderEnum::$dxwxl;
                $where['periodAmount'] = 1;
                unset($where['maxWhitelist']);
                break;
            case 3:
                $where = $data['data'];
                $where['package_type'] = HttpOrderEnum::$dxbt;
                $where['periodAmount'] = 1;
                $where['ipAmount'] = 1;
                break;
            case 4:
                $where = $data['data'];
                $where['package_type'] = HttpOrderEnum::$dxbl;
                unset($where['ipAmount']);
                break;
            case 5:
            case 6:
                $where = [
                    'periodType' => $data['data']['periodType'],
                    'isAbroad' => $data['data']['isAbroad'],
                    'shareType' => $data['data']['shareType'],
                    'isRelayed' => $data['data']['isRelayed'],
                    'lineType' => $data['data']['lineType'],
                    'bandwidth' => $data['data']['bandwidth'],
                    'package_type' => HttpOrderEnum::$cxyx
                ];
                if ($data['data']['isAbroad'] == 0) {
                    unset($where['isRelayed']);
                }
                if ($data['data']['shareType'] == 1) {
                    unset($where['lineType']);
                }
                break;
            
        }

        $price = $this->getOne($where, 'ipAmount,price');
        return $price;
    }
}