Esempio n. 1
0
    public function collectReport($time, $page)
    {
        setTimeLimit(3600);
        global $_FANWE;
        if ($page <= 1) {
            FDB::query('TRUNCATE TABLE ' . FDB::table('taobaoke_report_temp'));
        }
        include_once FANWE_ROOT . 'sdks/taobao/TopClient.php';
        include_once FANWE_ROOT . 'sdks/taobao/request/TaobaokeReportGetRequest.php';
        Cache::getInstance()->loadCache('business');
        $client = new TopClient();
        $client->appkey = trim($_FANWE['cache']['business']['taobao']['app_key']);
        $client->secretKey = trim($_FANWE['cache']['business']['taobao']['app_secret']);
        $req = new TaobaokeReportGetRequest();
        $req->setFields("num_iid,outer_code,commission_rate,real_pay_fee,app_key,outer_code,pay_time,pay_price,commission,item_title,item_num,trade_id");
        $page_size = 100;
        $time = fToDate($time, 'Ymd');
        $req->setDate($time);
        $req->setPageNo($page);
        $req->setPageSize($page_size);
        $resp = (array) $client->execute($req, trim($_FANWE["cache"]["business"]["taobao"]["session_key"]));
        $is_complete = false;
        $total_results = 0;
        if (isset($resp['taobaoke_report'])) {
            $count = 0;
            $taobaoke_report = (array) $resp['taobaoke_report'];
            $total_results = (int) $taobaoke_report['total_results'];
            if ($total_results > 0) {
                $taobaoke_report_members = $taobaoke_report['taobaoke_report_members'];
                foreach ($taobaoke_report_members->taobaoke_report_member as $item) {
                    $item = (array) $item;
                    $item['pay_time'] = str2Time($item['pay_time']);
                    $item['outer_code'] = isset($item['outer_code']) ? $item['outer_code'] : '';
                    $pay_day = fToDate($item['pay_time'], 'Y-m-d 00:00:00');
                    $item['pay_day'] = str2Time($pay_day);
                    $item['commission_rate'] = $item['commission_rate'] * 100;
                    $item['item_title'] = addslashes($item['item_title']);
                    if (!empty($item['outer_code']) && preg_match("/^o\\d+\$/", $item['outer_code'])) {
                        $order_id = (double) substr($item['outer_code'], 1);
                        if ($order_id == 0) {
                            continue;
                        }
                        $bln = (int) FDB::resultFirst('SELECT COUNT(id) FROM ' . FDB::table('taobaoke_report') . " \n\t\t\t\t\t\t\tWHERE outer_code = '" . addslashes($item['outer_code']) . "' \n\t\t\t\t\t\t\t\tAND num_iid = '" . addslashes($item['num_iid']) . "' \n\t\t\t\t\t\t\t\tAND pay_time = '" . addslashes($item['pay_time']) . "'");
                        if ($bln > 0) {
                            continue;
                        }
                        $is_insert = false;
                        $res = FDB::query('SELECT * FROM ' . FDB::table('goods_order') . ' 
							WHERE order_id = ' . $order_id . ' AND keyid = \'taobao_' . $item['num_iid'] . '\' AND status = 0');
                        while ($order = FDB::fetch($res)) {
                            $commission = (double) $item['commission'] * ((double) $order['commission_rate'] / 100);
                            if ($_FANWE['setting']['goods_buy_score_type'] > 0 && $_FANWE['setting']['goods_buy_score_rate'] > 0) {
                                $score = 0;
                                $rate = (double) $_FANWE['setting']['goods_buy_score_rate'];
                                if ($_FANWE['setting']['goods_buy_score_type'] == 1) {
                                    $score = (double) $item['real_pay_fee'] * $rate;
                                } else {
                                    $score = (double) $item['commission'] * $rate;
                                }
                                $score = round($score);
                                if ($score > 0) {
                                    FS('User')->updateUserScore((int) $order['uid'], 'goods', 'commission', '成功购买商品 ' . $item['item_title'] . ' 获得积分', $order_id, $score);
                                }
                            }
                            FDB::query('UPDATE ' . FDB::table('goods_order') . ' SET status = 1,settlement_time = ' . TIME_UTC . ',commission = ' . $commission . ' WHERE order_id = ' . $order_id . ' AND uid = ' . (int) $order['uid']);
                            $is_insert = true;
                        }
                        if ($is_insert) {
                            FDB::insert('taobaoke_report_temp', $item);
                        }
                    }
                }
                if ($page * $page_size >= $total_results) {
                    FDB::query('INSERT INTO ' . FDB::table('taobaoke_report') . '(id,trade_id,num_iid,item_title,item_num,pay_price,real_pay_fee,commission_rate,commission,outer_code,app_key,pay_time,pay_day) SELECT NULL AS id,trade_id,num_iid,item_title,item_num,pay_price,real_pay_fee,commission_rate,commission,outer_code,app_key,pay_time,pay_day FROM ' . FDB::table('taobaoke_report_temp') . ' ORDER BY pay_time ASC,trade_id ASC');
                    return 1;
                } else {
                    return 0;
                }
            } else {
                return 1;
            }
        }
        return -1;
    }
Esempio n. 2
0
function xt_taobaoke_report($date, $page = 1, $page_size = 40)
{
    $app = xt_taobao_is_ready();
    if (!$app) {
        return new WP_Error('系统错误', '尚未配置淘宝开放平台!');
    }
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/RequestCheckUtil.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/TopClient.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/request/TaobaokeReportGetRequest.php';
    $client = new TopClient();
    $client->format = 'json';
    $client->appkey = $app['appKey'];
    $client->secretKey = $app['appSecret'];
    $req = new TaobaokeReportGetRequest();
    $req->setFields("trade_parent_id,trade_id,real_pay_fee,commission_rate,commission,app_key,outer_code,pay_time,pay_price,num_iid,item_title,item_num,category_id,category_name,shop_title,seller_nick");
    $req->setDate($date);
    $req->setPageNo($page);
    $req->setPageSize($page_size);
    $resp = $client->execute($req);
    if (isset($resp->sub_code)) {
        return new WP_Error($resp->sub_code > 0 ? $resp->sub_code : '500', $resp->sub_msg);
    } elseif (isset($resp->code)) {
        return new WP_Error($resp->code > 0 ? $resp->code : '500', $resp->msg);
    }
    if (isset($resp->taobaoke_report)) {
        return $resp->taobaoke_report;
    }
    return array();
}