<?php

namespace App\Models;
use Illuminate\Support\Facades\DB;
/**
 *
 */
class AgentMoney extends BaseModel {

	protected $table = 'agent_money';
	public $timestamps = false;
	//插入代理流水
    function insertData($data){
        $res=$this->insert($data);
        if(!$res){
            return -8070000122;//添加流水记录失败
        }
        return 1;
    }
    //获取代理流水列表
    function getMoneyList($where,$list=20){
//        DB::connection()->enableQueryLog();
        $model=$this;
        if(!empty($where)&&count($where)>0){

            $model=$model->where($where);
        }
        $model=$model->orderBy('id','desc');
        $data=$model->paginate($list);
//        $queries = DB::getQueryLog();
//        print_r($queries);
        if(!$data){
            return -8031234;
        }
        return $data->toArray();
    }
    //id=>setle结算金额
    protected function Settle(){
        $data=$this->select(DB::raw('SUM(money) as money,agent_identity'))->groupBy('agent_identity')->get();
        if(!$data){
            return -803233;
        }
        $data=$data->toArray();
        $arr=array();
        foreach ($data as $v){
            $arr[$v['agent_identity']]=$v['money'];
        }
        return $arr;
    }
}

?>