作者 张关杰

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

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