64, '34' => 99, '100' => 1000 ]; $str[] = '
Quick Power Bank ORICO K27660
'; $str[] = ''; $str[] = '
'; tiaoshi($str);die; } public function jianzhan() { echo 1;die; set_time_limit(0); $begin_time = time(); $country_code = 'de'; // ---------同步产品分类begin---------- $product_cat_us = model('product_category')->where(['country_code' => 'US', 'stat' => 0])->select(); $product_cat_us_map = []; foreach ($product_cat_us as $key => $value) { $old_product_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_product_cat_id = model('product_category')->insertGetId($value); if (!$new_product_cat_id) { echo $key, ' ', $value, ' error'; } $product_cat_us_map[$old_product_cat_id] = $new_product_cat_id; } // 改pid $product_cat = model('product_category')->where(['country_code' => strtoupper($country_code)])->select(); foreach ($product_cat as $key => $value) { if ($value['pid'] == 0) { continue; } model('product_category')->where(['id' => $value['id']])->update(['pid' => $product_cat_us_map[$value['pid']]]); } // ---------同步产品分类e n d---------- // ---------同步横幅begin---------- $banner_cat_us = model('banner_type')->where(['country_code' => 'US', 'stat' => 0])->select(); $banner_cat_us_map = []; foreach ($banner_cat_us as $key => $value) { $old_banner_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_banner_cat_id = model('banner_type')->insertGetId($value); $banner_cat_us_map[$old_banner_cat_id] = $new_banner_cat_id; } $banner_us = model('banner')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($banner_us as $key => $value) { unset($value['id']); $value['typeid'] = isset($banner_cat_us_map[$value['typeid']]) ? $banner_cat_us_map[$value['typeid']] : 0; $cate_id = $value['categoryid']; if ($cate_id != '') { $arr_cate_id = explode(",", $cate_id); foreach ($arr_cate_id as $k => $v) { if (isset($product_cat_us_map[$v])) { $arr_cate_id[$k] = $product_cat_us_map[$v]; } $value['categoryid'] = implode(",", $arr_cate_id); } } $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_banner_id = model('banner')->insertGetId($value); } // ---------同步横幅e n d---------- // ---------同步产品begin---------- $product_us_map = []; $product_us = model('product')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($product_us as $k => $v) { $old_product_id = $v['id']; unset($v['id']); $v['cid'] = isset($product_cat_us_map[$v['cid']]) ? $product_cat_us_map[$v['cid']] : 0; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_id = model('product')->insertGetId($v); $product_us_map[$old_product_id] = $new_product_id; } // ---------同步产品e n d---------- // ---------同步广告begin---------- $ad_cat_us = model('ad_type')->where(['country_code' => 'US', 'stat' => 0])->select(); $ad_cat_us_map = []; foreach ($ad_cat_us as $key => $value) { $old_ad_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_ad_cat_id = model('ad_type')->insertGetId($value); $ad_cat_us_map[$old_ad_cat_id] = $new_ad_cat_id; } $ad_us = model('ad')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($ad_us as $key => $value) { unset($value['id']); if ($value['typeid'] != 0 && isset($ad_cat_us_map[$value['typeid']])) { $value['typeid'] = $ad_cat_us_map[$value['typeid']]; } else { $value['typeid'] = 0; } foreach ($product_cat_us_map as $k => $v) { $tmp = substr($value['tags'], strrpos($value['tags'], '_') + 1); if ($tmp == (string) $k) { $value['tags'] = str_replace((string) $k, (string) $v, $value['tags']); } } $normbody = $value['normbody']; if (strpos($normbody, 'mobile/product/detail/id/') !== false) { $len = strpos($normbody, '">') - (strpos($normbody, 'mobile/product/detail/id/') + 25); $tmp = substr($normbody, strpos($normbody, 'mobile/product/detail/id/') + 25, $len); foreach ($product_us_map as $k => $v) { if ($tmp == $k) { $normbody = str_replace((string) $tmp, (string) $v, $normbody); } } } else if (strpos($normbody, '/product/detail/') !== false) { $len = strpos($normbody, '.html') - (strpos($normbody, '/product/detail/') + 16); $tmp = substr($normbody, strpos($normbody, '/product/detail/') + 16, $len); foreach ($product_us_map as $k => $v) { if ($tmp == $k) { $normbody = str_replace((string) $tmp, (string) $v, $normbody); } } } $value['normbody'] = $normbody; $value = json_decode($value, true); $value['country_code'] = strtoupper($country_code); $new_ad_id = model('ad')->insertGetId($value); } // ---------同步广告e n d---------- // ---------同步产品下载begin---------- $product_dl_us = model('product_dl')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($product_dl_us as $k => $v) { if ($v['product_id'] == 0) { continue; } unset($v['id']); $v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_dl_id = model('product_dl')->insertGetId($v); } // ---------同步产品下载e n d---------- // ---------同步产品图片begin---------- $product_image_us = model('product_image')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($product_image_us as $k => $v) { if ($v['product_id'] == 0) { continue; } unset($v['id']); $v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_image_id = model('product_image')->insertGetId($v); } // ---------同步产品图片e n d---------- // ---------同步关联产品begin---------- $product_related_us = model('product_related')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($product_related_us as $k => $v) { if ($v['product_id'] == 0 || !isset($product_us_map[$v['related_product_id']]) || !isset($product_us_map[$v['product_id']])) { continue; } unset($v['id']); $v['product_id'] = $product_us_map[$v['product_id']]; $v['related_product_id'] = $product_us_map[$v['related_product_id']]; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_related_id = model('product_related')->insertGetId($v); } // ---------同步关联产品e n d---------- // ---------同步产品2级列表图begin---------- $product_two_img_us = model('product_two_img')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($product_two_img_us as $k => $v) { if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) { continue; } unset($v['id']); $v['product_id'] = $product_us_map[$v['product_id']]; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_two_img_id = model('product_two_img')->insertGetId($v); } // ---------同步产品2级列表图e n d---------- // ---------同步产品背景图begin---------- $product_bk_img_us = model('product_bk_img')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($product_bk_img_us as $k => $v) { if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) { continue; } unset($v['id']); $v['product_id'] = $product_us_map[$v['product_id']]; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_bk_img_id = model('product_bk_img')->insertGetId($v); } // ---------同步产品背景图e n d---------- $article_cat_us = model('article_category')->where(['country_code' => 'US', 'stat' => 0])->select(); $cat_us_map = []; foreach ($article_cat_us as $key => $value) { $old_article_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_article_cat_id = model('article_category')->insertGetId($value); $cat_us_map[$old_article_cat_id] = $new_article_cat_id; } $article_us = model('article')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($article_us as $key => $value) { unset($value['id']); $value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0; $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_article_id = model('article')->insertGetId($value); } $video_cat_us = model('video_category')->where(['country_code' => 'US', 'stat' => 0])->select(); $cat_us_map = []; foreach ($video_cat_us as $key => $value) { $old_video_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_video_cat_id = model('video_category')->insertGetId($value); $cat_us_map[$old_video_cat_id] = $new_video_cat_id; } $video_us = model('video')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($video_us as $key => $value) { unset($value['id']); $value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0; $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_video_id = model('video')->insertGetId($value); } $download_cat_us = model('download_category')->where(['country_code' => 'US', 'stat' => 0])->select(); $cat_us_map = []; foreach ($download_cat_us as $key => $value) { $old_download_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_download_cat_id = model('download_category')->insertGetId($value); $cat_us_map[$old_download_cat_id] = $new_download_cat_id; } $download_us = model('download')->where(['country_code' => 'US', 'stat' => 0])->select(); foreach ($download_us as $key => $value) { unset($value['id']); $value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0; $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_download_id = model('download')->insertGetId($value); } $end_time = time(); echo $end_time - $begin_time;die; } public function tongbu_product() { die; set_time_limit(0); $begin_time = time(); $country_code = 'vn'; // ---------同步产品分类begin---------- $product_cat_us = model('product_category_' . $country_code)->select(); $product_cat_us_map = []; foreach ($product_cat_us as $key => $value) { $old_product_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_product_cat_id = model('product_category')->insertGetId($value); if (!$new_product_cat_id) { echo $key, ' ', $value, ' error'; } $product_cat_us_map[$old_product_cat_id] = $new_product_cat_id; } // 改pid $product_cat = model('product_category')->where(['country_code' => strtoupper($country_code)])->select(); foreach ($product_cat as $key => $value) { if ($value['pid'] == 0) { continue; } model('product_category')->where(['id' => $value['id']])->update(['pid' => $product_cat_us_map[$value['pid']]]); } // ---------同步产品分类e n d---------- // ---------同步横幅begin---------- $banner_cat_us = model('banner_type_' . $country_code)->select(); $banner_cat_us_map = []; foreach ($banner_cat_us as $key => $value) { $old_banner_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_banner_cat_id = model('banner_type')->insertGetId($value); $banner_cat_us_map[$old_banner_cat_id] = $new_banner_cat_id; } $banner_us = model('banner_' . $country_code)->select(); foreach ($banner_us as $key => $value) { unset($value['id']); $value['typeid'] = isset($banner_cat_us_map[$value['typeid']]) ? $banner_cat_us_map[$value['typeid']] : 0; $cate_id = $value['categoryid']; if ($cate_id != '') { $arr_cate_id = explode(",", $cate_id); foreach ($arr_cate_id as $k => $v) { if (isset($product_cat_us_map[$v])) { $arr_cate_id[$k] = $product_cat_us_map[$v]; } $value['categoryid'] = implode(",", $arr_cate_id); } } $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_banner_id = model('banner')->insertGetId($value); } // ---------同步横幅e n d---------- // ---------同步产品begin---------- $product_us_map = []; $product_us = model('product_' . $country_code)->select(); foreach ($product_us as $k => $v) { $old_product_id = $v['id']; unset($v['id']); $v['cid'] = isset($product_cat_us_map[$v['cid']]) ? $product_cat_us_map[$v['cid']] : 0; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_id = model('product')->insertGetId($v); $product_us_map[$old_product_id] = $new_product_id; } // ---------同步产品e n d---------- // ---------同步广告begin---------- $ad_cat_us = model('ad_type_' . $country_code)->select(); $ad_cat_us_map = []; foreach ($ad_cat_us as $key => $value) { $old_ad_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_ad_cat_id = model('ad_type')->insertGetId($value); $ad_cat_us_map[$old_ad_cat_id] = $new_ad_cat_id; } $ad_us = model('ad_' . $country_code)->select(); foreach ($ad_us as $key => $value) { unset($value['id']); if ($value['typeid'] != 0 && isset($ad_cat_us_map[$value['typeid']])) { $value['typeid'] = $ad_cat_us_map[$value['typeid']]; } else { $value['typeid'] = 0; } foreach ($product_cat_us_map as $k => $v) { $tmp = substr($value['tags'], strrpos($value['tags'], '_') + 1); if ($tmp == (string) $k) { $value['tags'] = str_replace((string) $k, (string) $v, $value['tags']); } } $normbody = $value['normbody']; if (strpos($normbody, 'mobile/product/detail/id/') !== false) { $len = strpos($normbody, '">') - (strpos($normbody, 'mobile/product/detail/id/') + 25); $tmp = substr($normbody, strpos($normbody, 'mobile/product/detail/id/') + 25, $len); foreach ($product_us_map as $k => $v) { if ($tmp == $k) { $normbody = str_replace((string) $tmp, (string) $v, $normbody); } } } else if (strpos($normbody, '/product/detail/') !== false) { $len = strpos($normbody, '.html') - (strpos($normbody, '/product/detail/') + 16); $tmp = substr($normbody, strpos($normbody, '/product/detail/') + 16, $len); foreach ($product_us_map as $k => $v) { if ($tmp == $k) { $normbody = str_replace((string) $tmp, (string) $v, $normbody); } } } $value['normbody'] = $normbody; $value = json_decode($value, true); $value['country_code'] = strtoupper($country_code); $new_ad_id = model('ad')->insertGetId($value); } // ---------同步广告e n d---------- // ---------同步产品下载begin---------- $product_dl_us = model('product_dl_' . $country_code)->select(); foreach ($product_dl_us as $k => $v) { if ($v['product_id'] == 0) { continue; } unset($v['id']); $v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_dl_id = model('product_dl')->insertGetId($v); } // ---------同步产品下载e n d---------- // ---------同步产品图片begin---------- $product_image_us = model('product_image_' . $country_code)->select(); foreach ($product_image_us as $k => $v) { if ($v['product_id'] == 0) { continue; } unset($v['id']); $v['product_id'] = isset($product_us_map[$v['product_id']]) ? $product_us_map[$v['product_id']] : 0; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_image_id = model('product_image')->insertGetId($v); } // ---------同步产品图片e n d---------- // ---------同步关联产品begin---------- $product_related_us = model('product_related_' . $country_code)->select(); foreach ($product_related_us as $k => $v) { if ($v['product_id'] == 0 || !isset($product_us_map[$v['related_product_id']]) || !isset($product_us_map[$v['product_id']])) { continue; } unset($v['id']); $v['product_id'] = $product_us_map[$v['product_id']]; $v['related_product_id'] = $product_us_map[$v['related_product_id']]; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_related_id = model('product_related')->insertGetId($v); } // ---------同步关联产品e n d---------- // ---------同步产品2级列表图begin---------- $product_two_img_us = model('product_two_img_' . $country_code)->select(); foreach ($product_two_img_us as $k => $v) { if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) { continue; } unset($v['id']); $v['product_id'] = $product_us_map[$v['product_id']]; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_two_img_id = model('product_two_img')->insertGetId($v); } // ---------同步产品2级列表图e n d---------- // ---------同步产品背景图begin---------- $product_bk_img_us = model('product_bk_img_' . $country_code)->select(); foreach ($product_bk_img_us as $k => $v) { if ($v['product_id'] == 0 || !isset($product_us_map[$v['product_id']])) { continue; } unset($v['id']); $v['product_id'] = $product_us_map[$v['product_id']]; $v = json_decode(json_encode($v), true); $v['country_code'] = strtoupper($country_code); $new_product_bk_img_id = model('product_bk_img')->insertGetId($v); } // ---------同步产品背景图e n d---------- $end_time = time(); echo $end_time - $begin_time;die; } public function tongbu_article() { die; $country_code = 'vn'; $article_cat_us = model('article_category_' . $country_code)->select(); $cat_us_map = []; foreach ($article_cat_us as $key => $value) { $old_article_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_article_cat_id = model('article_category')->insertGetId($value); $cat_us_map[$old_article_cat_id] = $new_article_cat_id; } $article_us = model('article_' . $country_code)->select(); foreach ($article_us as $key => $value) { unset($value['id']); $value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0; $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_article_id = model('article')->insertGetId($value); } echo 1;die; } public function tongbu_video() { die; $country_code = 'vn'; $video_cat_us = model('video_category_' . $country_code)->select(); $cat_us_map = []; foreach ($video_cat_us as $key => $value) { $old_video_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_video_cat_id = model('video_category')->insertGetId($value); $cat_us_map[$old_video_cat_id] = $new_video_cat_id; } $video_us = model('video_' . $country_code)->select(); foreach ($video_us as $key => $value) { unset($value['id']); $value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0; $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_video_id = model('video')->insertGetId($value); } echo 2;die; } public function tongbu_download() { die; $country_code = 'vn'; $download_cat_us = model('download_category_' . $country_code)->select(); $cat_us_map = []; foreach ($download_cat_us as $key => $value) { $old_download_cat_id = $value['id']; unset($value['id']); $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_download_cat_id = model('download_category')->insertGetId($value); $cat_us_map[$old_download_cat_id] = $new_download_cat_id; } $download_us = model('download_' . $country_code)->select(); foreach ($download_us as $key => $value) { unset($value['id']); $value['cid'] = isset($cat_us_map[$value['cid']]) ? $cat_us_map[$value['cid']] : 0; $value = json_decode(json_encode($value), true); $value['country_code'] = strtoupper($country_code); $new_download_id = model('download')->insertGetId($value); } echo 3;die; } }