<?php
namespace Wechat\Model;

use Think\Model;

header("Content-Type:text/html;CharSet=UTF-8");
class StoresRenewModel extends Model
{
    /**
     * 通过订单号 完成订单支付
     * @param  string $sn 订单号
     * @return boolean
     */
    public function payBySn($sn, $transaction_id, $invalid_time)
    {
        if ($sn) {
            // 修改订单状态
            $data = array();
            $data['status'] = 2;
            $data['transaction_id'] = $transaction_id;
            $data['exp_date']   = $invalid_time;
            $result = $this->where("`sn`='{$sn}'")->save($data);
        }
        if ($result) {      
            return true;
        } else {
            return false;
        }
    }
    /**
     * 订单支付金额判断
     * @param  string $sn  订单号
     * @param  string $fee 支付金额
     * @return boolean
     */
    public function payFeeCheck($sn = "", $fee = "")
    {
        file_put_contents("./Logs/paySuccess.log", "Checking fee\r\n", FILE_APPEND);
        if ($sn && $fee) {
            // 读取订单金额
            $realFee = $this->where("`sn`='{$sn}'")->getField("money");
            $feeInt = $fee/100;
        }
        file_put_contents("./Logs/paySuccess.log", "Check finished:\r\n", FILE_APPEND);
        file_put_contents("./Logs/paySuccess.log", "realFee: {$realFee}\r\n", FILE_APPEND);
        file_put_contents("./Logs/paySuccess.log", "feeInt: {$feeInt}\r\n", FILE_APPEND);
        if ($realFee > 0 && ($feeInt == $realFee)) {
            return true;
        } else {
            return false;
        }
    }
}