2025-12-08 17:37:34 +08:00
|
|
|
<?php
|
|
|
|
|
namespace app\common\controller;
|
|
|
|
|
|
|
|
|
|
use app\common\controller\BaseController;
|
|
|
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
|
|
|
use app\common\service\SkuService;
|
2025-12-11 17:57:22 +08:00
|
|
|
use support\Request;
|
2025-12-10 14:59:41 +08:00
|
|
|
use function Symfony\Component\Translation\t;
|
2025-12-08 17:37:34 +08:00
|
|
|
|
|
|
|
|
class SkuController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
use CrudControllerTrait;
|
|
|
|
|
|
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->service = new SkuService();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 17:57:22 +08:00
|
|
|
/**
|
|
|
|
|
* 获取列表
|
|
|
|
|
*
|
|
|
|
|
* @param Request $request 请求对象
|
|
|
|
|
* @return mixed 返回分页数据及总数
|
|
|
|
|
*/
|
|
|
|
|
public function preset(Request $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$raw = $this->service->serviceListAll($request);
|
|
|
|
|
$data = [];
|
|
|
|
|
foreach ($raw as $item) {
|
|
|
|
|
unset($item['created_at']);
|
|
|
|
|
unset($item['updated_at']);
|
|
|
|
|
$data[] = $this->indexFormat($item);
|
|
|
|
|
}
|
|
|
|
|
return $this->success($data);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return $this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-08 17:37:34 +08:00
|
|
|
/**
|
|
|
|
|
* 列表页数据格式化
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2025-12-10 14:59:41 +08:00
|
|
|
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;
|
|
|
|
|
}
|
2025-12-08 17:37:34 +08:00
|
|
|
}
|