<?php

namespace plugin\admin\app\controller;

use app\model\User;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;
use support\Request;
use support\Response;
use Throwable;

/**
 * 用户提现 
 */
class WithdrawlController  extends Crud
{
    
    /**
     * @var \plugin\admin\app\model\Withdrawl
     */
    protected $model = null;
    protected $relationSearch = ['user'];
    /**
     * 构造函数
     * @return void
     */
    function __construct()
    {
        $this->model = new \plugin\admin\app\model\Withdrawl();
        $statusList = $this->model->getStatusList();
        $this->assign("statusList", $statusList);
        $this->assignconfig("statusList", $statusList);
        $networkList = $this->model->getNetworkList();
        $this->assign("networkList", $networkList);
        $this->assignconfig("networkList", $networkList);
    }
    
    protected function formatNormal($items, $total): Response
    {
        return json([
            'code' => 0, 
            'msg' => 'ok', 
            'count' => $total, 
            'data' => $items,
            'wait_amount'  =>  \app\model\Withdrawl::where('status',0)->sum('recive_amount'),
            'wait_count'  =>  \app\model\Withdrawl::where('status',0)->count('id')
        ]);
    }
    function multi(){
        $ids = Request()->post('ids');
        $params = Request()->post('params');
        parse_str($params,$s);
        if(!is_array($ids)){
            $ids = explode(',',$ids);
        }
        //$this->model = new \app\model\Withdrawl1;
        
        foreach ($ids as $id){
            if(\app\model\Withdrawl::where('id',$id)->value('status')!=$s['status']){
                $this->doUpdate($id, $s);
            }
        }
        return $this->success('操作成功');
    }

}
