1
This commit is contained in:
@@ -41,4 +41,29 @@ class UsedCarController extends BaseController
|
|||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页数据格式化
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function showFormat($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 (!empty($data['images'])){
|
||||||
|
$images = explode(',', $data['images']);
|
||||||
|
$ossService = new OssService();
|
||||||
|
$images_pull = [];
|
||||||
|
foreach ($images as $image){
|
||||||
|
$images_pull[] = $ossService->generatePrivateUrl($image);
|
||||||
|
}
|
||||||
|
$data['images_pull'] = $images_pull;
|
||||||
|
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,55 @@ class UsedCarService
|
|||||||
return new $this->validator;
|
return new $this->validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造 CrudUtil 查询配置
|
||||||
|
*/
|
||||||
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||||
|
{
|
||||||
|
$p = $request->all();
|
||||||
|
|
||||||
|
$config = [];
|
||||||
|
$config['model'] = $this->modelClass;
|
||||||
|
switch ($scene) {
|
||||||
|
case 'default':
|
||||||
|
$config['where']['status'] = 1;
|
||||||
|
$config['order']['sort'] = 'desc';
|
||||||
|
$config['order']['id'] = 'desc';
|
||||||
|
break;
|
||||||
|
case 'index':
|
||||||
|
$config['where']['status'] = 1;
|
||||||
|
|
||||||
|
if (isset($p['scene']) && $p['scene'] == 'self') {
|
||||||
|
$config['where']['user_id'] = $request->user['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关键字
|
||||||
|
if (isset($p['keyword']) && $p['keyword']) {
|
||||||
|
$k = '%' . $p['keyword'] . '%';
|
||||||
|
foreach (['product_name'] as $col) {
|
||||||
|
$config['orWhere'][] = [$col, 'like', $k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$config['order']['sort'] = 'desc';
|
||||||
|
$config['order']['id'] = 'desc';
|
||||||
|
break;
|
||||||
|
case 'show':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
$config['where']['status'] = 1;
|
||||||
|
break;
|
||||||
|
case 'store':
|
||||||
|
break;
|
||||||
|
case 'update':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
break;
|
||||||
|
case 'destroy':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function beforeServiceStore($data, Request $request): array
|
public function beforeServiceStore($data, Request $request): array
|
||||||
{
|
{
|
||||||
@@ -40,6 +89,7 @@ class UsedCarService
|
|||||||
if(empty($data['images'])){
|
if(empty($data['images'])){
|
||||||
throw new BusinessException('产品图片不能为空');
|
throw new BusinessException('产品图片不能为空');
|
||||||
}
|
}
|
||||||
|
$data['user_id'] = $request->user['id'];
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user