<?php

namespace App\Http\Models;

use Illuminate\Database\Eloquent\Model;
use \App\Models;

/**
 * 签到模型类
 */
class Sign extends Model
{


    /**
     * 查询签到记录
     *
     * @access public
     * @param mixed $where 查询条件
     * @param mixed $between 查询条件
     * @param mixed $paginate 分页
     * @return array
     */
    public function getSignRecord($select, $paginate, $where='', $between='')
    {
        // 获取签到记录.
        $getSignModel = new Models\GetSign;
        $getSignModel = $getSignModel
            ->select($select)
            ->join('members', 'members.id', 'getsign.members_id');
        if (empty($where) === false) {
            $getSignModel = $getSignModel->where($where);
        }

        if (empty($between) === false) {
            $getSignModel = $getSignModel->whereBetween('getsign_addtime', $between);
        }

        $getSignModel = $getSignModel
            ->orderBy('getsign_addtime','desc')
            ->paginate($paginate)
            ->toArray();

        return $getSignModel;

    }//end getSignRecord()


    /**
     * 添加签到记录
     *
     * @access public
     * @param mixed $data 数据
     * @return array
     */
    public function addSign($data)
    {
        // 获取救济金记录.
        $getSignModel = new Models\GetSign;
        $result = $getSignModel->insert($data);

        return $result;

    }//end addSign()


    /**
     * 查询签到记录
     *
     * @access public
     * @param mixed $where 查询条件
     * @param mixed $between 查询条件
     * @param mixed $paginate 分页
     * @return array
     */
    public function countSign($where, $between)
    {
        // 获取救济金记录.
        $getSignModel = new Models\GetSign;
        $result = $getSignModel
            ->where($where)
            ->whereBetween('getsign_addtime', $between)
            ->count();

        return $result;

    }//end countSign()


    /**
     * 查询签到设置
     *
     * @access public
     * @param mixed $select 查询字段
     * @param mixed $where 查询条件
     * @param mixed $orWhere 查询条件
     * @return array
     */
    public function signConfig($select, $where, $orWhere)
    {
        // 查询救济金系统设置.
        $signModel = new Models\Sign;
        $signModel = $signModel->select($select);
        if ($where) {
            $signModel = $signModel->Where($where);
        }
        if ($orWhere) {
            $signModel = $signModel->orWhere($orWhere);
        }
        $signModel = $signModel->orderBy('sign_title', 'asc')->get();

        return $signModel;

    }//end signConfig()


    /**
     * 修改签到设置
     *
     * @access public
     * @param mixed $where 查询条件
     * @param mixed $data 数据
     * @return array
     */
    public function upSignConfig($where, $data)
    {
        // 查询救济金系统设置.
        $signModel = new Models\Sign;
        $signModel = $signModel
            ->where($where)
            ->update($data);

        return $signModel;

    }//end upSignConfig()


}
