<?php

namespace app\jinyou\model;

use fastphp\base\Model;

class UserPrice extends Model
{
    protected $table = 'product_user_price';


    public function get_user_price($user_id,$discount,$package_info){
        $price = 100000;

        //根据用户价格
        if ($discount != 0) {
            if ($discount == -1) {
                $user_price = $this->getOne(['UserId' => $user_id,'PackageId' => $package_info['Id']]);
                if (isset($user_price['UserPrice'])) {
                    $price = $user_price['UserPrice'];
                }
            } else {
                $scheme_model = new PriceScheme;
                $discount = $scheme_model->getone(['Id' => $discount])['discount'];
                $price = $package_info['LinePrice'] * $discount / 100;
            }
            //判读最低价
            if ($price < $package_info['MinPrice']) {
                $price = $package_info['MinPrice'];
            }
            if ($price < $package_info['Price']) {
                $package_info['Price'] = $price;
            }

            if ($price > $package_info['Price'] && $price < 100000) {
                $package_info['Price'] = $price;
            }
        }

        return $package_info['Price'];
    }

}
