更新采集

This commit is contained in:
mkm 2023-10-10 14:54:50 +08:00
parent b11b8fa387
commit caddda1c41

View File

@ -57,7 +57,7 @@ use app\common\service\TopClient;
use app\controller\api\Ceshi; use app\controller\api\Ceshi;
use taobao\request\TbkItemInfoGetRequest; use taobao\request\TbkItemInfoGetRequest;
use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\ProductRepository;
use crmeb\services\UploadService; use think\facade\App;
/** /**
* Class Auth * Class Auth
@ -69,33 +69,36 @@ class Auth extends BaseController
{ {
public function caiji() public function caiji()
{ {
$url=$this->request->host();
$parmas = $this->request->param(); $parmas = $this->request->param();
$query = parse_url($parmas['url']); $query=parse_url($parmas['url']);
$itemId = $this->convertUrlQuery($query['query']); $itemId=$this->convertUrlQuery($query['query']);
$c = new TopClient; $c = new TopClient;
$c->appkey = '34537213'; $c->appkey = '34537213';
$c->secretKey = '4a35f3657156580c1f533750295c54c4'; $c->secretKey = '4a35f3657156580c1f533750295c54c4';
$req = new TbkItemInfoGetRequest; $req = new TbkItemInfoGetRequest;
$req->setNumIids($itemId['itemId']); $req->setNumIids($itemId['itemId']);
$resp = $c->execute($req); $resp = $c->execute($req);
$res = $resp->results->n_tbk_item; $res=$resp->results->n_tbk_item;
$arr = json_decode(json_encode($res), true); $images=[];
$images = []; $filename = basename($res->pict_url); // 获取文件名
$upload = UploadService::create(); $destination = public_path('uploads').'img/' . $filename; // 目标路径
$dir = 'def/' . date('Y-m-d'); $pict_url= $url.'/uploads/img/'.$filename;
file_put_contents($destination, file_get_contents($res->pict_url));
$oss = $upload->to($dir)->stream(file_get_contents($arr['pict_url']));
if($resp && isset($resp->small_images) && isset($resp->small_images->string)){
$pict_url = $oss->filePath; foreach($resp->small_images->string as $k=>$v){
foreach ($arr['small_images']['string'] as $k => $v) { $filename = basename($v); // 获取文件名
$oss = $upload->to($dir)->stream(file_get_contents($v)); $destination = public_path('uploads').'img/' . $filename; // 目标路径
$images[] = $oss->filePath; file_put_contents($destination, file_get_contents($v));
$images[]=$url.'/uploads/img/'.$filename;
}
} }
$data = [ $data=[
"image" => $pict_url, "image" => $pict_url,
"slider_image" => $images, "slider_image" =>$images,
"store_name" => $arr['title'], "store_name" => json_decode(json_encode($res->title),true)[0],
"store_info" => $arr['cat_leaf_name'], "store_info" => json_decode(json_encode($res->cat_leaf_name),true)[0],
"keyword" => "", "keyword" => "",
"bar_code" => "", "bar_code" => "",
"guarantee_template_id" => "", "guarantee_template_id" => "",
@ -115,8 +118,8 @@ class Auth extends BaseController
"attr" => [], "attr" => [],
"mer_labels" => [], "mer_labels" => [],
"delivery_way" => [ "delivery_way" => [
0 => "1", 0 => "1",
1 => "2" 1 => "2"
], ],
"delivery_free" => 0, "delivery_free" => 0,
"param_temp_id" => [], "param_temp_id" => [],
@ -128,17 +131,17 @@ class Auth extends BaseController
"once_min_count" => 0, "once_min_count" => 0,
"pay_limit" => 0, "pay_limit" => 0,
"attrValue" => [ "attrValue" => [
0 => [ 0 => [
"image" => $pict_url, "image" => $pict_url,
"price" => bcsub($arr['reserve_price'], ($arr['reserve_price'] * 0.05), 2), "price" => bcsub($res->reserve_price,($res->reserve_price*0.05),2),
"cost" => 0, "cost" => 0,
"ot_price" => 0, "ot_price" => 0,
"svip_price" => null, "svip_price" => null,
"stock" => 100, "stock" => 100,
"bar_code" => "", "bar_code" => "",
"weight" => 0, "weight" => 0,
"volume" => 0, "volume" => 0,
], ],
], ],
"give_coupon_ids" => [], "give_coupon_ids" => [],
"type" => 0, "type" => 0,
@ -149,22 +152,22 @@ class Auth extends BaseController
"status" => 0, "status" => 0,
"mer_status" => 1, "mer_status" => 1,
"rate" => 3, "rate" => 3,
]; ];
$a = app()->make(ProductRepository::class)->create($data, 0, 1); $a= app()->make( ProductRepository::class)->create($data,0,1);
// 下载图片并保存到目标路径 // 下载图片并保存到目标路径
return app('json')->success($a); return app('json')->success($a);
} }
function convertUrlQuery($query) function convertUrlQuery($query)
{ {
$queryParts = explode('&', $query); $queryParts = explode('&', $query);
$params = array(); $params = array();
foreach ($queryParts as $param) { foreach ($queryParts as $param) {
$item = explode('=', $param); $item = explode('=', $param);
$params[$item[0]] = $item[1]; $params[$item[0]] = $item[1];
} }
return $params; return $params;
} }
public function dotest() public function dotest()
{ {