<?php

namespace Bill\Lib;

use Dever;

class Tixian
{
    public function up($mid, $ycash, $cash, $name, $bank, $bankname, $card)
    {
        $member = Dever::db('agent/member')->find(array('id' => $mid, 'clear' => true));
        if ($member['status'] <= 2) {
        	$cash = -1*$cash;
        	$ycash = -1*$ycash;
        	$data['mid'] = $mid;
    		$data['order_num'] = $this->getOrderId();
    		$data['yue'] = $member['cash'] + $ycash;
    		$data['ycash'] = $ycash;
    		$data['cash'] = $cash;
    		$data['name'] = $name;
    		$data['bank'] = $bank;
    		$data['bankname'] = $bankname;
    		$data['card'] = $card;
            $data['status'] = 1;
    		return Dever::db('bill/tixian')->insert($data);
        }

        return false;
    }

    /**
     * 生成订单号
     *
     * @return mixed
     */
    public function getOrderId()
    {
        $where['order_num'] = Dever::order('C');
        $state = Dever::db('bill/cash')->one($where);
        if (!$state) {
            return $where['order_num'];
        } else {
            return $this->getOrderId();
        }
    }
}