<?php
// +----------------------------------------------------------------------
// | [ WE CAN DO IT MORE SIMPLE  ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2020 rights reserved.
// +----------------------------------------------------------------------
// | Author: TABLE ME
// +----------------------------------------------------------------------
// | Date: 2020-08-31 20:43
// +----------------------------------------------------------------------

namespace app\system\controller\v1;


use app\BaseController;
use app\model\system\Recharge as RechargeModel;
use app\model\system\Site as SiteModel;
use app\model\system\Member as MemberModel;
use library\services\UtilService;
use library\utils\IpLocation;
use app\Request;

class Recharge extends  BaseController
{

    public function getRecharge(Request $request)
    {
        $pageSize = 50;
        $post = UtilService::getMore([
            ['page',1],
            ['keyword','']
        ]);
        list($pageCount,$data) = (new RechargeModel())
            ->getList($post['page'],[function($query) use($post){
                if(!empty($post['keyword'])) {
                    $query->whereLike('uid',"%{$post['keyword']}%");
                }
                $query->where('status',1);
        }
        ],$pageSize,'*','time desc');
        $result = UtilService::getParam([
            'order_id',
            'v',
            'trade_no',
            'status',
            'uid',
            ['nickname','uid',function($item){
                return (new MemberModel())->where("uid",$item)->value('nickname');
            }],
            ['site_name','sassid',function($item){
                return (new SiteModel())->where("sassid",$item)->value('name');
            }],
            ['time','time','date("Y-m-d H:i:s",$1)'],
        ],$data);
        return app('json')->success([
            'list'      => $result,
            'pageCount' => $pageCount,
            'pageSize'  => $pageSize,
            'page'      => $post['page']
        ]);
    }
    
}