2025-07-08 14:17:38 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\apis\controller;
|
|
|
|
|
|
|
|
|
|
use app\apis\model\AdModel;
|
|
|
|
|
use support\Request;
|
|
|
|
|
use support\Response;
|
|
|
|
|
use app\apis\model\AdpModel;
|
|
|
|
|
use app\apis\service\AdpService;
|
|
|
|
|
use app\apis\validate\AdpValidator;
|
|
|
|
|
use app\mzl\common\controller\BaseController;
|
|
|
|
|
|
|
|
|
|
class AdpController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 不需要验证token的接口
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $noNeedJwt = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 验证器
|
|
|
|
|
*/
|
|
|
|
|
protected mixed $validator = AdpValidator::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回业务 Service 实例
|
|
|
|
|
*/
|
|
|
|
|
protected function getService()
|
|
|
|
|
{
|
|
|
|
|
return new AdpService(new AdpModel());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 额外字段处理 (根据场景处理)
|
|
|
|
|
* @param array $item
|
|
|
|
|
* @param string $scene
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function postProcessItem(array $item, string $scene): array
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if ($scene === 'default') {
|
|
|
|
|
$item['title'] = isset($item['translation']) ? $item['translation']['title'] : '';
|
|
|
|
|
unset($item['translation']);
|
|
|
|
|
$ad = AdModel::with('translation')->where(['adp_id' => $item['id'], 'status' => 1])->limit(8)->get();
|
|
|
|
|
foreach ($ad as $k => $v) {
|
|
|
|
|
$v['alt'] = isset($v['translation']) ? $v['translation']['alt'] : '';
|
|
|
|
|
$v['title'] = isset($v['translation']) ? $v['translation']['title'] : '';
|
2025-07-08 15:38:43 +08:00
|
|
|
$v['full_img'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($v['img']);
|
2025-07-08 14:17:38 +08:00
|
|
|
unset($v['translation']);
|
|
|
|
|
$item['ad'][$k] = $ad;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 参数预处理 (根据场景处理)
|
|
|
|
|
* @param Request $request
|
|
|
|
|
* @param string $scene
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareParams(Request $request, string $scene): array
|
|
|
|
|
{
|
|
|
|
|
$params = parent::prepareParams($request, $scene);
|
|
|
|
|
|
|
|
|
|
if ($scene === 'default') {
|
|
|
|
|
$params['filters'] = [];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request 请求对象
|
|
|
|
|
* @return Response 响应对象
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request, string $scene = 'default'): Response
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return parent::index($request, $scene);
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
return $this->errorResponse($th->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|