<?php
/*
 本代码由 焕岱科技 创建
 技术支持 WX：15285007200
 严禁反编译、逆向等任何形式的侵权行为，违者将追究法律责任
*/

namespace app\api\controller\capitalpool;

use app\api\controller\Base;
use think\Db;
use app\common\model\bbfxshop\User;


class Capitalpool extends Base
{
    protected $noNeedLogin = ['ceshi'];
    protected $noNeedRight = ['*'];
    
    public $model = null;
    public function _initialize(){
        parent::_initialize();
        $this->model = new \app\common\model\bbfxshop\Capitalpool;
    }

    public function index(){
        $where = ['uniacid'=>UNIACID];
        $abonus_money1 = Db::name("bbfx_capitalpool_money_log")->where($where)->where(['money'=>['>',0]])->sum("money");
        $abonus_money2 = Db::name("bbfx_capitalpool_money_log")->where($where)->where(['money'=>['<',0]])->sum("money");
        $abonus_money = Db::name("bbfx_capitalpool")->where($where)->value('abonus_money');
        
        $result = [
            'abonus_money1'=>round($abonus_money1,2),
            'abonus_money2'=>abs(round($abonus_money2,2)),
            'abonus_money'=>round($abonus_money,2),
        ];

        __success("操作成功",$result);
    }

    public function getList(){
        $params = $this->param(['page/d','limit/d','keyword/s','startTime/s','endTime/s','type/d']);
        $pindex = max(1, intval($params["page"]));
        $psize = intval($params["limit"])?intval($params["limit"]):10;
        
        
        $where = ["uniacid"=>UNIACID];
        
        $keyword = trim($params['keyword']);
        $startTime = trim($params['startTime']);
        $endTime = trim($params['endTime']);
        $type = intval($params['type']);
        
        if($keyword){
            
        }
        if($type == 1){
            $where['money'] = ['>',0];
        }
        else{
            $where['money'] = ['<',0];
        }
        $whereTime = [];
        if($startTime){
            $startTime = strtotime($startTime." 00:00:00");
            $where['createtime'] = ['>=',$startTime];
        }
        
        if($endTime){
            $endTime = strtotime($endTime." 23:59:59");
            $whereTime['createtime'] = ['<=',$endTime];
        }

        // echo "<pre>";
        // print_r($where);die;
        
        $list = Db::name("bbfx_capitalpool_money_log")->where($where)->where($whereTime)->order("createtime desc")->limit(($pindex-1)*$psize,$psize)->select();
        
        foreach($list as $key=>&$val){
    	    $val['createtime'] = date("Y-m-d H:i:s",$val['createtime']);
            $val['money'] = abs($val['money']);
        }

        __success("操作成功",['list'=>$list]);
    }
}