<?php namespace Channel\Api;
use Dever;
use \Dever\Helper\Redis;
use \Dever\Helper\Str;
class Task
{
    # 定时查询渠道的余额
    public function yue()
    {
        $channel = Dever::db('info', 'channel')->select(array('type' => 1, 'status' => 1));
        if ($channel) {
            foreach ($channel as $k => $v) {
                if ($v['connect_id'] && $v['host'] && $v['appkey'] && $v['appsecret']) {
                    $connect = Dever::db('info', 'connect')->find($v['connect_id']);
                    if ($connect) {
                        $api = Dever::db('api', 'connect')->find(array('type' => 3, 'connect_id' => $connect['id']));
                        if ($api) {
                            # 获取余额
                            $result = Dever::load('func/api', 'connect')->run(3, false, $v);
                            if ($result['status'] == 1 && isset($result['data']['yue'])) {
                                Dever::db('info', 'channel')->update($v['id'], array('cash' => $result['data']['yue']));
                            }
                        }
                    }
                }
            }
        }
        return 'ok';
    }
}