Beispiel #1
0
function xt_cron_autoshare()
{
    global $wpdb;
    if (!IS_CLOUD) {
        set_time_limit(0);
    }
    $date = gmdate('Y-m-d H', current_time('timestamp'));
    $shares = $wpdb->get_results('SELECT * FROM ' . XT_TABLE_SHARE_CRON . ' WHERE create_date<=\'' . $date . '\' LIMIT 200');
    $deleteKeys = array();
    if (!empty($shares)) {
        foreach ($shares as $share) {
            $share_key = $share->share_key;
            $user_id = $share->user_id;
            $user_name = $share->user_name;
            $album_id = $share->album_id;
            $data = array();
            if (!empty($share->cache_data)) {
                $data = maybe_unserialize($share->cache_data);
                if (!empty($data)) {
                    if (xt_check_share($data['share_key'], $user_id)) {
                        $deleteKeys[] = $share_key;
                        continue;
                    }
                }
            }
            if (empty($data)) {
                $fetch = array();
                if (startsWith($share_key, 'tb')) {
                    //taobao
                    $fetch = xt_share_fetch('http://item.taobao.com/item.htm?id=' . str_replace('tb_', '', $share_key));
                } elseif (startWith($share_key, 'pp')) {
                    //paipai
                    $fetch = xt_share_fetch('http://auction1.paipai.com/' . str_replace('pp_', '', $share_key));
                }
                if (!empty($fetch)) {
                    $data = array('share_key' => $fetch['share_key'], 'title' => $fetch['title'], 'pic_url' => $fetch['pic_url'], 'price' => $fetch['price'], 'cid' => $fetch['cid'], 'cache_data' => $fetch['cache_data'], 'content' => '', 'from_type' => $fetch['from_type']);
                }
            }
            if (!empty($data)) {
                xt_share_share(array('share_key' => $data['share_key'], 'title' => $data['title'], 'pic_url' => $data['pic_url'], 'price' => $data['price'], 'cid' => (int) $data['cid'], 'user_id' => (int) $user_id, 'user_name' => $user_name, 'cache_data' => $data['cache_data'], 'from_type' => $data['from_type'], 'data_type' => 1, 'content' => isset($data['content']) ? trim(strip_tags($data['content'])) : null, 'album_id' => (int) $album_id));
            }
            $deleteKeys[] = $share_key;
        }
        if (!empty($deleteKeys)) {
            $_keys = array();
            foreach ($deleteKeys as $deleteKey) {
                $_keys[] = "'{$deleteKey}'";
            }
            $wpdb->query('DELETE FROM ' . XT_TABLE_SHARE_CRON . ' WHERE share_key in (' . implode(',', $_keys) . ')');
        }
        xt_catalogs_share(true);
        //reload catalogs and tags
        do_action('xt_page_updated', 'home');
        //clear home cache
    }
}
Beispiel #2
0
function xt_share_fetch_paipai($url, $user_id, $user_name, $result)
{
    $app = xt_get_app_paipai();
    if (empty($app) || empty($app['appKey']) || empty($app['appSecret'])) {
        $result['code'] = 501;
        $result['msg'] = '暂不支持拍拍';
        return $result;
    }
    $id = _xt_share_fetch_paipai_id($url);
    if (!$id) {
        $result['code'] = 501;
        $result['msg'] = '宝贝的地址不正确';
        return $result;
    }
    $key = 'pp_' . $id;
    //检查是否已分享该商品
    if ($user_id > 0) {
        if (xt_check_share($key, $user_id)) {
            $result['code'] = 502;
            $result['msg'] = '您已分享该宝贝';
            return $result;
        }
    }
    $goods = xt_paipai_item($id);
    if (is_wp_error($goods)) {
        $result['code'] = 500;
        $result['msg'] = $goods->get_error_message();
        return $result;
    }
    $goods = (array) $goods;
    $result = array();
    //$goods['commission'] = 0;
    $result['code'] = 0;
    $result['msg'] = '';
    $result['result']['share_key'] = $key;
    $result['result']['user_id'] = $user_id;
    $result['result']['user_name'] = $user_name;
    $result['result']['cid'] = $goods['classId'];
    $result['result']['title'] = $goods['itemName'];
    $result['result']['price'] = number_format($goods['itemPrice'] / 100, 2);
    $result['result']['pic_url'] = $goods['picLink'];
    $result['result']['location'] = $goods['regionInfo'];
    $result['result']['nick'] = $goods['sellerName'];
    $result['result']['cat'] = $goods['classId'];
    //    $resp = xt_paipaike_item($id);
    //    if (!is_wp_error($resp)) {
    //        $taoke = (array) $resp->cpsSearchCommData;
    //        if ($taoke['dwIsCpsFlag'] && $taoke['dwActiveFlag']) {
    //            if ($taoke['dwPrimaryCmm']) {
    //                $goods['commission'] = number_format($taoke['dwPrice'] * $taoke['dwPrimaryRate'] / (10000 * 100), 2);
    //            } else {
    //                $goods['commission'] = number_format($taoke['dwPrice'] * $taoke['dwClassRate'] / (10000 * 100), 2);
    //            }
    //        }
    //    }
    $result['result']['from_type'] = 'paipai';
    $result['result']['data_type'] = 1;
    $result['result']['cache_data'] = serialize(array('item' => _xt_share_fetch_paipai_convert($goods), 'comment' => array('total' => 0, 'comments' => array())));
    return $result;
}