作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

@@ -7,7 +7,10 @@ @@ -7,7 +7,10 @@
7 */ 7 */
8 namespace App\Http\Controllers\Api; 8 namespace App\Http\Controllers\Api;
9 9
  10 +use App\Enums\Common\Code;
10 use App\Http\Controllers\Controller; 11 use App\Http\Controllers\Controller;
  12 +use Illuminate\Http\Exceptions\HttpResponseException;
  13 +use Illuminate\Http\JsonResponse;
11 14
12 /** 15 /**
13 * Class BaseController 16 * Class BaseController
@@ -38,4 +41,23 @@ class BaseController extends Controller @@ -38,4 +41,23 @@ class BaseController extends Controller
38 $array = compact('status', 'message', 'data'); 41 $array = compact('status', 'message', 'data');
39 return json_encode($array, JSON_UNESCAPED_UNICODE); 42 return json_encode($array, JSON_UNESCAPED_UNICODE);
40 } 43 }
41 -}  
  44 +
  45 + /**
  46 + * @name :统一返回参数
  47 + * @return JsonResponse
  48 + * @author :liyuhang
  49 + * @method
  50 + */
  51 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  52 + {
  53 + $code = Code::fromValue($code);
  54 + $result = [
  55 + 'code' => $code->value,
  56 + 'data' => $data,
  57 + 'message' => $msg == ' ' ? $code->description : $msg,
  58 + ];
  59 + $header['Content-Type'] = $type;
  60 + $response = response($result,$result_code,$header);
  61 + throw new HttpResponseException($response);
  62 + }
  63 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Api;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\Product\Product;
  7 +use App\Services\ProjectServer;
  8 +use Illuminate\Http\Request;
  9 +use Illuminate\Support\Arr;
  10 +
  11 +/**
  12 + * Class ProductController
  13 + * @package App\Http\Controllers\Api
  14 + * @author zbj
  15 + * @date 2024/2/1
  16 + */
  17 +class ProductController extends BaseController
  18 +{
  19 + /**
  20 + * 获取项目随机产品的图片
  21 + * @param Request $request
  22 + * @return void
  23 + */
  24 + public function getImages(Request $request)
  25 + {
  26 + $project_id = $request->input('project_id');
  27 +
  28 + $project = ProjectServer::useProject($project_id);
  29 + if (!$project) {
  30 + $this->response('项目不存在', Code::SYSTEM_ERROR);
  31 + }
  32 +
  33 + try {
  34 + $gallery = Product::where('status', Product::STATUS_ON)->whereNotNull('gallery')->inRandomOrder()->value('gallery');
  35 + $gallery = array_map(function ($item) use ($project) {
  36 + return getImageUrl($item, $project['storage_type'], $project['project_location']);
  37 + }, Arr::pluck($gallery, 'url'));
  38 + } catch (\Exception $e) {
  39 + $gallery = [];
  40 + }
  41 + $this->response('success', Code::SUCCESS, $gallery);
  42 + }
  43 +}
@@ -69,13 +69,18 @@ class AyrReleaseController extends BaseController @@ -69,13 +69,18 @@ class AyrReleaseController extends BaseController
69 } 69 }
70 //参数处理 70 //参数处理
71 $this->param['mediaUrls'] = $ayrReleaseLogic->image_file_param($data); 71 $this->param['mediaUrls'] = $ayrReleaseLogic->image_file_param($data);
72 - //时间处理  
73 - //统一生成发布  
74 $param = [ 72 $param = [
75 'post'=>$this->param['content'], 73 'post'=>$this->param['content'],
76 'platforms'=>$this->param['platforms'], 74 'platforms'=>$this->param['platforms'],
77 'mediaUrls'=>$this->param['mediaUrls'],//参数处理 75 'mediaUrls'=>$this->param['mediaUrls'],//参数处理
78 ]; 76 ];
  77 + //统一生成发布
  78 + foreach ($this->param['platforms'] as $value){
  79 + if($value == 'youtube'){
  80 + $param['youTubeOptions'] = ['title'=>$this->param['title']];
  81 + }
  82 + }
  83 +
79 if(isset($this->param['schedule_date']) && !empty($this->param['schedule_date'])){ 84 if(isset($this->param['schedule_date']) && !empty($this->param['schedule_date'])){
80 $datetime = new \DateTime($this->param['schedule_date'] ?? date('Y-m-d H:i:s')); 85 $datetime = new \DateTime($this->param['schedule_date'] ?? date('Y-m-d H:i:s'));
81 $formattedTime = $datetime->format("Y-m-d\TH:i:s\Z"); 86 $formattedTime = $datetime->format("Y-m-d\TH:i:s\Z");
@@ -40,7 +40,7 @@ class CategoryController extends BaseController @@ -40,7 +40,7 @@ class CategoryController extends BaseController
40 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id 40 $template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id
41 foreach ($list as $k =>$v){ 41 foreach ($list as $k =>$v){
42 $v['url'] = $this->user['domain'] . $v['route'].'/'; 42 $v['url'] = $this->user['domain'] . $v['route'].'/';
43 - $v['product_num'] = $category->getProductNum($v['id']); 43 + $v['product_num'] = $category->getProductNum($list,$v['id']);
44 $v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']); 44 $v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']);
45 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']); 45 $v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
46 $list[$k] = $v; 46 $list[$k] = $v;
@@ -96,7 +96,7 @@ class ProductController extends BaseController @@ -96,7 +96,7 @@ class ProductController extends BaseController
96 } 96 }
97 if(!empty($v['video'])){ 97 if(!empty($v['video'])){
98 $v['video']['url'] = getFileUrl($v['video']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']); 98 $v['video']['url'] = getFileUrl($v['video']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']);
99 - $v['video']['video_image'] = getImageUrl($v['video']['video_image'],$this->user['storage_type'] ?? 0,$this->user['project_location']); 99 + $v['video']['video_image'] = getImageUrl($v['video']['video_image'] ?? '',$this->user['storage_type'] ?? 0,$this->user['project_location']);
100 } 100 }
101 if(!empty($v['files']) && !empty($v['files']['url'])){ 101 if(!empty($v['files']) && !empty($v['files']['url'])){
102 $v['files']['url'] = getFileUrl($v['files']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']); 102 $v['files']['url'] = getFileUrl($v['files']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location']);
@@ -61,18 +61,16 @@ class AyrReleaseLogic extends BaseLogic @@ -61,18 +61,16 @@ class AyrReleaseLogic extends BaseLogic
61 $arr = []; 61 $arr = [];
62 foreach ($data as $k => $v){ 62 foreach ($data as $k => $v){
63 if($k == 'images'){ 63 if($k == 'images'){
64 - $images = $v;  
65 - $imageModel = new Image();  
66 - $list = $imageModel->list(['path'=>['in',$images]],'id');  
67 - foreach ($list as $v1){  
68 - $arr[] = getImageUrl($v1['path'],$this->user['storage_type'],$this->user['project_location']); 64 + foreach ($v as $v1){
  65 + $v1 = 'https://file.globalso.com'.str_replace_url($v1);
  66 + $arr[] = $v1;
69 } 67 }
70 }else{ 68 }else{
71 - $fileModel = new File();  
72 - $info = $fileModel->read(['path'=>$v]);  
73 - $arr[] = getFileUrl($info['path'],$this->user['storage_type'],$this->user['project_location']); 69 + $v = 'https://file.globalso.com'.str_replace_url($v);
  70 + $arr[] = $v;
74 } 71 }
75 } 72 }
  73 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export($arr, true) . PHP_EOL, FILE_APPEND);
76 return $this->success($arr); 74 return $this->success($arr);
77 } 75 }
78 76
@@ -72,6 +72,12 @@ class InquiryForm extends Base @@ -72,6 +72,12 @@ class InquiryForm extends Base
72 unset($data['globalso-domain']); 72 unset($data['globalso-domain']);
73 unset($data['globalso-edition']); 73 unset($data['globalso-edition']);
74 unset($data['globalso-date']); 74 unset($data['globalso-date']);
  75 +
  76 + foreach ($data as $k => $v){
  77 + if(in_array($k, ['name', 'email', 'message']) && empty($v)){
  78 + unset($data[$k]);
  79 + }
  80 + }
75 81
76 ksort($data); 82 ksort($data);
77 $field = array_keys($data); 83 $field = array_keys($data);
@@ -48,12 +48,11 @@ class Category extends Base @@ -48,12 +48,11 @@ class Category extends Base
48 * @method :post 48 * @method :post
49 * @time :2023/10/18 15:10 49 * @time :2023/10/18 15:10
50 */ 50 */
51 - public function getAllSub($id,&$str = []){  
52 - $list = $this->list(['pid'=>$id,'status'=>1],['id','pid']);  
53 - if(!empty($list)){  
54 - foreach ($list as $v){ 51 + public function getAllSub($list,$id,&$str = []){
  52 + foreach ($list as $k =>$v){
  53 + if($v['pid'] == $id){
55 $str[] = $v['id']; 54 $str[] = $v['id'];
56 - $this->getAllSub($v['id'],$str); 55 + $this->getAllSub($list,$v['id'],$str);
57 } 56 }
58 } 57 }
59 return $str; 58 return $str;
@@ -66,9 +65,9 @@ class Category extends Base @@ -66,9 +65,9 @@ class Category extends Base
66 * @author zbj 65 * @author zbj
67 * @date 2023/4/28 66 * @date 2023/4/28
68 */ 67 */
69 - public function getProductNum($cate_id){ 68 + public function getProductNum($list,$cate_id){
70 $str[] = $cate_id; 69 $str[] = $cate_id;
71 - $cate_ids = $this->getAllSub($cate_id,$str); 70 + $cate_ids = $this->getAllSub($list,$cate_id,$str);
72 $productArr = CategoryRelated::whereIn('cate_id',$cate_ids)->pluck('product_id')->unique()->toArray(); 71 $productArr = CategoryRelated::whereIn('cate_id',$cate_ids)->pluck('product_id')->unique()->toArray();
73 $count = count($productArr); 72 $count = count($productArr);
74 return $count; 73 return $count;
@@ -95,7 +95,14 @@ class SyncSubmitTaskService @@ -95,7 +95,14 @@ class SyncSubmitTaskService
95 { 95 {
96 96
97 $visit_data = $data['data']; 97 $visit_data = $data['data'];
98 - $visit_data['referrer_url'] = $data['data']['referrer_url']??''; 98 + $referrer_url = '';
  99 + if($data['data']['referrer_url']){
  100 + $url_arr = parse_url($data['data']['referrer_url']);
  101 + if(!empty($url_arr['scheme']) && !empty($url_arr['host'])){
  102 + $referrer_url = $url_arr['scheme'] . '://' . $url_arr['host'] . '/';
  103 + }
  104 + }
  105 + $visit_data['referrer_url'] = $referrer_url;
99 $visit_data['device_port'] = $data['data']['device_port']??''; 106 $visit_data['device_port'] = $data['data']['device_port']??'';
100 $visit_data['url'] = $data['data']['url']??''; 107 $visit_data['url'] = $data['data']['url']??'';
101 $visit_data['domain'] = $data['domain']??''; 108 $visit_data['domain'] = $data['domain']??'';
@@ -20,4 +20,6 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { @@ -20,4 +20,6 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
20 20
21 Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit'); 21 Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit');
22 Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController::class, 'optimizeProjectList'])->name('api.optimize_project_list'); 22 Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController::class, 'optimizeProjectList'])->name('api.optimize_project_list');
23 -Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::class, 'getProjectRoute'])->name('api.get_project_route');  
  23 +Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::class, 'getProjectRoute'])->name('api.get_project_route');
  24 +Route::any('get_product_images', [\App\Http\Controllers\Api\ProductController::class, 'getImages'])->name('api.get_product_images');
  25 +