From 78e9a291e9c311122a5468f5b697252a41cab086 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 10 Oct 2023 16:49:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=87=87=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Auth.php | 98 ++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 9c7458db..5bef6a8d 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -57,7 +57,7 @@ use app\common\service\TopClient; use app\controller\api\Ceshi; use taobao\request\TbkItemInfoGetRequest; use app\common\repositories\store\product\ProductRepository; -use think\facade\App; +use crmeb\services\UploadService; /** * Class Auth @@ -69,36 +69,32 @@ class Auth extends BaseController { public function caiji() { - $url= env('SHOP_URL', 'https://test.shop.lihaink.cn'); $parmas = $this->request->param(); - $query=parse_url($parmas['url']); - $itemId=$this->convertUrlQuery($query['query']); + $query = parse_url($parmas['url']); + $itemId = $this->convertUrlQuery($query['query']); $c = new TopClient; $c->appkey = '34537213'; $c->secretKey = '4a35f3657156580c1f533750295c54c4'; $req = new TbkItemInfoGetRequest; $req->setNumIids($itemId['itemId']); $resp = $c->execute($req); - $res=$resp->results->n_tbk_item; - $arr=json_decode(json_encode($res),true); - $images=[]; - $filename = basename($arr['pict_url']); // 获取文件名 - $destination = public_path('uploads').'img/' . $filename; // 目标路径 - $pict_url= $url.'/uploads/img/'.$filename; - file_put_contents($destination, file_get_contents($arr['pict_url'])); - // if($resp && isset($resp->small_images) && isset($resp->small_images->string)){ - foreach($arr['small_images']['string'] as $k=>$v){ - // halt($v); - $filename = basename($v); // 获取文件名 - $destination = public_path('uploads').'img/' . $filename; // 目标路径 - file_put_contents($destination, file_get_contents($v)); - $images[]=$url.'/uploads/img/'.$filename; - } - // } - $data=[ + $res = $resp->results->n_tbk_item; + $arr = json_decode(json_encode($res), true); + $images = []; + $upload = UploadService::create(); + $dir = 'def/' . date('Y-m-d'); + + $oss = $upload->to($dir)->stream(file_get_contents($arr['pict_url'])); + + $pict_url = $oss->filePath; + foreach ($arr['small_images']['string'] as $k => $v) { + $oss = $upload->to($dir)->stream(file_get_contents($v)); + $images[] = $oss->filePath; + } + $data = [ "image" => $pict_url, - "slider_image" =>$images, - "store_name" =>$arr['title'], + "slider_image" => $images, + "store_name" => $arr['title'], "store_info" => $arr['cat_leaf_name'], "keyword" => "", "bar_code" => "", @@ -119,8 +115,8 @@ class Auth extends BaseController "attr" => [], "mer_labels" => [], "delivery_way" => [ - 0 => "1", - 1 => "2" + 0 => "1", + 1 => "2" ], "delivery_free" => 0, "param_temp_id" => [], @@ -132,17 +128,17 @@ class Auth extends BaseController "once_min_count" => 0, "pay_limit" => 0, "attrValue" => [ - 0 => [ - "image" => $pict_url, - "price" => bcsub($arr['reserve_price'],($arr['reserve_price']*0.05),2), - "cost" => 0, - "ot_price" => 0, - "svip_price" => null, - "stock" => 100, - "bar_code" => "", - "weight" => 0, - "volume" => 0, - ], + 0 => [ + "image" => $pict_url, + "price" => bcsub($arr['reserve_price'], ($arr['reserve_price'] * 0.05), 2), + "cost" => 0, + "ot_price" => 0, + "svip_price" => null, + "stock" => 100, + "bar_code" => "", + "weight" => 0, + "volume" => 0, + ], ], "give_coupon_ids" => [], "type" => 0, @@ -153,22 +149,22 @@ class Auth extends BaseController "status" => 1, "mer_status" => 1, "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); } function convertUrlQuery($query) { - $queryParts = explode('&', $query); - - $params = array(); - foreach ($queryParts as $param) { - $item = explode('=', $param); - $params[$item[0]] = $item[1]; - } - - return $params; + $queryParts = explode('&', $query); + + $params = array(); + foreach ($queryParts as $param) { + $item = explode('=', $param); + $params[$item[0]] = $item[1]; + } + + return $params; } public function dotest() { @@ -389,11 +385,11 @@ class Auth extends BaseController } if ($merchant['margin'] == 0) { $margin = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin'); - $margin = bcsub($margin,$merchant['paid_margin'],2); - }else{ - $margin=$merchant['margin']; + $margin = bcsub($margin, $merchant['paid_margin'], 2); + } else { + $margin = $merchant['margin']; } - if($margin==0){ + if ($margin == 0) { return app('json')->fail('当前金额为0,不能进行充值'); } $orderSn = "bzj" . date('YmdHis') . uniqid();