2026-08-14 23:21:21 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
|
|
|
|
use App\BaseApp\BaseController;
|
|
|
|
|
|
use App\Service\business\CatalogueService;
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 商品图册
|
|
|
|
|
|
*/
|
|
|
|
|
|
class CatalogueController extends BaseController
|
|
|
|
|
|
{
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
|
{
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
$this->service = CatalogueService::getInstance();
|
|
|
|
|
|
$this->insertField = ['title', 'category_id', 'cover', 'identifier'];
|
|
|
|
|
|
$this->updateField = ['id', 'title', 'category_id', 'cover', 'identifier'];
|
2026-08-20 19:16:49 +08:00
|
|
|
|
$this->notRequest = ['alias', 'pdf', 'video', 'price', 'status'];
|
2026-08-14 23:21:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 启用 / 禁用
|
|
|
|
|
|
* @Method POST
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function status(): JsonResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->insertField = ['id', 'status'];
|
|
|
|
|
|
$params = $this->checkRequiredFields(request()->post());
|
|
|
|
|
|
return jok($this->service->status($params['id'], $params['status']), '操作成功');
|
|
|
|
|
|
}
|
2026-08-20 19:16:49 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 导出商品表(结构化数据,前端 ExcelJS 画 xlsx)
|
|
|
|
|
|
* @Method GET
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function export(): JsonResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
return jok($this->service->exportExcel());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 导入商品表:前端已把 xlsx 拆成 rows
|
|
|
|
|
|
* @Method POST
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function import(): JsonResponse
|
|
|
|
|
|
{
|
|
|
|
|
|
$rows = request()->post('rows', []);
|
|
|
|
|
|
$priceSheets = request()->post('price_sheets', []);
|
|
|
|
|
|
return jok($this->service->importRows(
|
|
|
|
|
|
is_array($rows) ? $rows : [],
|
|
|
|
|
|
is_array($priceSheets) ? $priceSheets : [],
|
|
|
|
|
|
), '导入完成');
|
|
|
|
|
|
}
|
2026-08-14 23:21:21 +08:00
|
|
|
|
}
|