This commit is contained in:
2025-12-10 14:59:41 +08:00
parent 6b3fb790f7
commit c0bd385b1a
7 changed files with 55 additions and 10 deletions
+9
View File
@@ -4,6 +4,7 @@ namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\model\PostCategory;
use app\common\model\PostMedia;
use app\common\model\Sku;
use app\common\model\User;
use app\common\service\OssService;
use app\common\traits\crud\CrudControllerTrait;
@@ -87,6 +88,14 @@ class PostController extends BaseController
$data['user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['user']['avatar']);
}
}
if (isset($data['sku_id'])){
$sku = Sku::where('id', $data['sku_id'])->first();
if($sku){
$sku['main_image_pull'] = $ossservice->generatePrivateUrl($sku['main_image']);
}
$data['sku'] = $sku;
}
return $data;
}
}
+2
View File
@@ -46,6 +46,8 @@ class SkuController extends BaseController
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['spec_json']))
$data['spec'] = json_decode($data['spec_json'], true);
return $data;
}
}
+11
View File
@@ -7,6 +7,7 @@ use app\common\model\PostComment;
use app\common\model\PostFavorite;
use app\common\model\PostLike;
use app\common\model\PostMedia;
use app\common\model\Sku;
use app\common\model\User;
use app\common\service\OssService;
use app\common\traits\crud\CrudControllerTrait;
@@ -96,6 +97,16 @@ class PostController extends BaseController
$data['user']['avatar_pull'] = $ossservice->generatePrivateUrl($data['user']['avatar']);
}
}
if (isset($data['sku_id'])){
$sku = Sku::where('id', $data['sku_id'])->first();
if($sku){
$sku['main_image_pull'] = $ossservice->generatePrivateUrl($sku['main_image']);
}
$data['sku'] = $sku;
}
return $data;
}
+11 -8
View File
@@ -4,6 +4,7 @@ namespace app\common\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\common\service\SkuService;
use function Symfony\Component\Translation\t;
class SkuController extends BaseController
{
@@ -22,12 +23,14 @@ class SkuController extends BaseController
* @param array $data
* @return array
*/
// protected function indexFormat($data)
// {
// if (isset($data['created_at']))
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
// if (isset($data['updated_at']))
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
// return $data;
// }
protected function indexFormat($data)
{
if (isset($data['created_at']))
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
if (isset($data['updated_at']))
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
if (isset($data['spec_json']))
$data['spec_json'] = json_decode($data['spec_json'],true);
return $data;
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ class Post extends Model
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'user_id', 'category_id', 'content', 'location_name', 'latitude', 'longitude', 'status', 'sort', 'like', 'favorite', 'comment', 'browse', 'created_at', 'updated_at'];
protected $fillable = ['id', 'user_id', 'category_id', 'sku_id', 'content', 'location_name', 'latitude', 'longitude', 'status', 'sort', 'like', 'favorite', 'comment', 'browse', 'created_at', 'updated_at'];
/**
* 不允许自动填充模型字段
+16 -1
View File
@@ -54,6 +54,22 @@ class SkuService
$data['spec_json'] = $spec_json;
$data['user_id'] = $request->user->uid;
$data['code'] = $this->generateUniqueCode();
// 将OSS直连地址替换为代理地址
$ossDomain = 'https://vehicle-album.oss-cn-beijing.aliyuncs.com/';
$proxyPath = '/console/upload/image/proxy?file=';
$data['desc'] = str_replace(
'?Expires=',
'&Expires=',
$data['desc']
);
$data['desc'] = str_replace(
$ossDomain,
$proxyPath,
$data['desc']
);
return $data;
}
@@ -65,7 +81,6 @@ class SkuService
{
$specs = Redis::get('sku_attr_'.$res['user_id']);
$specs= json_decode($specs,true);
var_dump($specs);
$spec = [];
foreach ($specs as $key => $value) {
$spec['category_id'] = $res['category_id'];
+5
View File
@@ -99,6 +99,11 @@ Route::group('/common', function () {
Route::group('/banner', function () {
Route::any('/list', [app\common\controller\BannerController::class, 'getAll']);
});
// sku
Route::group('/sku', function () {
Route::any('/list', [app\common\controller\SkuController::class, 'index']);
});
});