Files
nl-mall-api/app/Service/CodeGeneration/MallClassificationService.php
lq 035ab1105c
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
商品、订单部分相关代码生成,下一步先把商品搞完再搞订单
2025-05-20 16:52:47 +08:00

101 lines
2.3 KiB
PHP

<?php
namespace App\Service\CodeGeneration;
use App\BaseApp\BaseService;
use App\Models\MallClassificationModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class MallClassificationService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->selectField = ["id", "name", "pid", "status", "created_at", "updated_at", "deleted_at"];
$this->queryField = ['name' => 'like','pid' => '=,status='];
$this->model = MallClassificationModel::class;
}
/**
* 获取店铺行业列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function list(): array
{
return $this->getPageList();
}
/**
* 获取店铺行业详情
* @param $id
* @return mixed
* @throws Exception
*/
public function detail($id)
{
return $this->getDetail($id);
}
/**
* 店铺行业下拉列表
* @return mixed
*/
public function option()
{
$this->optionField = ['id', 'name', 'pid'];
$this->where[] = ['pid', '=', 0];
$result = $this->getOption();
$result = $result->toArray();
$ids = array_column($result, 'id');
$this->whereIn = ['pid', $ids];
// 查询所有的子分类,然后放在父级分类下面
$this->where = [['deleted_at', '=', 0]];
$children = $this->getOption();
$children = $children->toArray();
$arr = array_merge($result, $children);
$data = tree($arr);
array_unshift($data, ['id' => 0, 'name' => '不分类', 'pid' => 0]);
return $data;
}
/**
* 创建店铺行业
* @param $params
* @return mixed
* @throws Exception
*/
public function create($params): mixed
{
return $this->insert($params);
}
/**
* 编辑店铺行业
* @param $id
* @param $params
* @return mixed
* @throws Exception
*/
public function update($id, $params): mixed
{
return $this->save($id, $params);
}
/**
* 删除店铺行业
* @param $ids
* @return mixed|true
* @throws Exception
*/
public function delete($ids): mixed
{
return $this->del($ids);
}
}