<?php
/**
 *------Create thems Model------
 *------SCWPHP  Version 1.0.0------
 *------Dev Model Jions------
 *------Create Time 2017-06-12 02:45:54------
 */
namespace App\Commons\Model;
use \System\Model;

class Money_take extends Model {

	protected $table = 'money_take';

    /**
     * 提现记录查询
     *
     * @access public
     * @param mixed $select 查询字段
     * @param mixed $where 查询条件
     * @param mixed $orderBy 排序
     * @param mixed $order 顺序
     * @return array JsonString
     */
    public function takeRecord($select, $where, $orderBy = 'apply_time', $order = 'desc') {
        $result = $this
            -> select($select)
            -> where($where)
            -> orderBy($orderBy, $order)
            -> first();

        return $result;
    }

    /**
     * 提现记录查询
     *
     * @access public
     * @param mixed $select 查询字段
     * @param mixed $where 查询条件
     * @param mixed $between 查询区间 demo: ['apply_time' => [2019-04-19 10:46:35, 2019-04-19 10:46:35],'id'=>[99448,99448]];
     * @param mixed $begin 起始位置
     * @param mixed $pageSize 分页大小
     * @param mixed $orderBy 排序 demo: ['apply_time'=>'desc','id'=>'desc']
     * @return array JsonString
     */
    public function moneyTake($select, $where = '', $between = '', $begin = '', $pageSize = '', $orderBy = '') {
        $result = $this -> select($select);
        if (!empty($where)) {
            $result = $result -> where($where);
        }
        if (!empty($between)) {
            foreach ($between as $key => $value) {
                $result = $result -> whereBetween($key, $value);
            }
        }
        if (count($begin) && isset($pageSize)) {
            $result = $result -> offset($begin) -> limit($pageSize);
        }
        if (!empty($orderBy)) {
            foreach ($orderBy as $key => $value) {
                $result = $result -> orderBy($key, $value);
            }
        } else {
            $result = $result -> orderBy('apply_time', 'desc');
        }
        $result = $result -> get();

        return $result;
    }

    /**
     * 提现记录总数
     *
     * @access public
     * @param mixed $where 查询条件
     * @param mixed $between 查询条件区间
     * @return array JsonString
     */
    public function moneyTakeTotal($where, $between) {
        $result = $this;
        if (!empty($where)) {
            $result = $result -> where($where);
        }
        if (!empty($between)) {
            foreach ($between as $key => $value) {
                $result = $result -> whereBetween($key, $value);
            }
        }
        $result = $result -> count();

        return $result;
    }

    /**
     * 添加提现记录
     *
     * @access public
     * @param mixed $data 添加的字段
     * @return array JsonString
     */
    public function insertTake($data) {
        $result = $this -> insert($data);

        return $result;
    }
}
