<?php

Doo::loadCore('db/DooModel');

class scUser extends DooModel {

    public $sid;
    public $uid;
    public $Name;
    public $MobileNum;
    public $Company;
    public $PhoneNum;
    public $QQ;
    public $Province;
    public $Address;
    public $KnowFrom;
    public $KnowOther;
    
    public $_table = 'sc_user';
    public $_primarykey = 'sid';
    public $_fields = array('sid', 'uid', 'Name', 'MobileNum', 'Company', 'PhoneNum', 'QQ','Province' ,'Address', 'KnowFrom', 
    'KnowOther');

    public function __construct() {
        parent::setupModel(__CLASS__);
    }

    /**
     *
     * @param type $param
     */
    public function userAdd($uArray) {
        if (!is_array($uArray))
            return FALSE;
        $this->username = $uArray['username'];
        $this->useremail = $uArray['useremail'];
        $this->userpasswd = $uArray['userpasswd'];
        $this->actstate = 0;
        $this->regip = $uArray['clientip'];
        $this->intime = time();
        $this->salt = $uArray['salt'];
        return $this->insert();
    }

    /**
     *
     * @param type $param
     */
    public function getAll($limit) {
        return $this->find(array('select' => 'username,useremail,lastloginip,lastlogintime', 'limit' => $limit, 'asArray' => TRUE));
    }

    /**
     *
     * @param type $param
     */
    public function getCountz() {
        return $this->count();
    }

    /**
     *
     * @param type $param
     */
    public function updateBank($uid, $money) {
        $this->bank = new DooDbExpression('bank+' . $money);
        return $this->update(array('where' => 'id=' . $uid));
    }

    public function getRowByUid($uid) {
        if (empty($uid))
            return false;
        return $this->find(array('select' => 'bank,username,useremail', 'where' => 'id=' . $uid, 'asArray' => TRUE));
    }

}

?>