<?php
namespace Smi\Model;

use Think\Model;

header("Content-type:text/html;charset=utf-8");
class FundLogModel extends Model
{
    /**
     * 计算总收益
     * @param  string $openid 当前用户 openid
     * @return mix
     */
    public function calTotalBenefit($openid)
    {
        if ($openid) {
            $benefit = $this->where("`openid` = '$openid'")->sum("benefit");
            if ($benefit > 0) {
                return $benefit;
            } else {
                return 0;
            }
        } else {
            return false;
        }
    }

    /**
     * 计算冻结佣金
     * @param  string $openid 当前用户 openid
     * @return mix
     */
    public function calFrozen($openid)
    {
        if ($openid) {
            $benefit = $this->where("`openid` = '$openid' AND `status` = 1")->sum("benefit");
            if ($benefit > 0) {
                return $benefit;
            } else {
                return 0;
            }
        } else {
            return false;
        }
    }
}