<?php
/**
 *------Create thems Model------
 *------SCWPHP  Version 1.0.0------
 *------Dev Model Jions------
 *------Create Time 2017-06-12 05:08:18------
 */
namespace App\Api\Model;

use \System\Model;
use Biz\Account\AccountManager;

class MoneyPrize extends Model {
    /**
     * 中奖记录
     *
     * @access public
     * @return String
     */
    public function prizeRecord()
    {
        // 获取用户信息
        $accountManagerClass = new AccountManager;
        $userInfo = $accountManagerClass -> getCurrentUser();
        if (empty($userInfo['identity'])) {
            Render([], '2001', lang('Common','Api') -> get('user does login'));
        }
        $prizeRecordWhere = array();
        // 用户ID
        $prizeRecordWhere['account_identity'] = $userInfo['identity'];
        $prizeRecordWhere['status'] = 1;
        // 时间区间
        $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
        $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
        $prizeRecordBetween = [$startTime, $endTime];
        // 当前页
        $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
        // 分页大小
        $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
        // 起始查询位置
        $begin = ($currentPage - 1) * $pageSize;
        $prizeRecord = lm('money_prize', "commons");
        //$prizeRecordSelect = ['info_identity', 'trade_id', 'account_identity', 'money', 'money_time', 'money_type'];
        // 获取盈亏记录
        $result['list'] = $prizeRecord -> prizeRecord($prizeRecordWhere, $prizeRecordBetween, $begin, $pageSize);
        // 获取记录总数
        $result['total'] = $prizeRecord -> prizeRecordTotal($prizeRecordWhere, $prizeRecordBetween);
        // 总页数计算
        $result['countPage'] = ceil($result['total'] / $pageSize);
        $result['currentPage'] = $currentPage;

        return $result;
    }
}
