75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Service\wx;
|
|
|
|
use App\BaseApp\BaseWxService;
|
|
use App\Models\business\FactoryClassificationModel;
|
|
use App\Models\business\FactoryImageModel;
|
|
use App\Models\business\FactoryInfoModel;
|
|
use App\Service\common\MediaUrlService;
|
|
|
|
/**
|
|
* 小程序工厂目录(只读)
|
|
*/
|
|
class WxFactoryService extends BaseWxService
|
|
{
|
|
protected bool $needLogin = false;
|
|
|
|
public function list(): array
|
|
{
|
|
$classId = (int) request()->get('classification', 0);
|
|
$keyword = trim((string) request()->get('keyword', ''));
|
|
$query = FactoryInfoModel::with('classificationInfo')
|
|
->where('deleted_at', 0)
|
|
->where('status', 0)
|
|
->orderByDesc('id');
|
|
if ($classId > 0) {
|
|
$query->where('classification', $classId);
|
|
}
|
|
if ($keyword !== '') {
|
|
$query->where('name', 'like', '%' . $keyword . '%');
|
|
}
|
|
$rows = $query->get()->toArray();
|
|
$media = MediaUrlService::getInstance();
|
|
foreach ($rows as &$row) {
|
|
$row['cover'] = $media->toPublic($row['cover'] ?? '');
|
|
$row['classification_name'] = $row['classification_info']['name'] ?? '';
|
|
unset($row['classification_info']);
|
|
}
|
|
unset($row);
|
|
return $rows;
|
|
}
|
|
|
|
public function detail(int $id): array
|
|
{
|
|
$info = FactoryInfoModel::with('classificationInfo')
|
|
->where('id', $id)
|
|
->where('deleted_at', 0)
|
|
->where('status', 0)
|
|
->first();
|
|
if (empty($info)) {
|
|
$this->utils->errorThrow('工厂不存在');
|
|
}
|
|
$info = $info->toArray();
|
|
$media = MediaUrlService::getInstance();
|
|
$info['cover'] = $media->toPublic($info['cover'] ?? '');
|
|
$info['classification_name'] = $info['classification_info']['name'] ?? '';
|
|
unset($info['classification_info']);
|
|
$images = FactoryImageModel::where('factory', $id)->where('deleted_at', 0)->orderBy('id')->get()->toArray();
|
|
$media->publicEach($images, ['url']);
|
|
$info['images'] = $images;
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 工厂分类
|
|
*/
|
|
public function classList(): array
|
|
{
|
|
return FactoryClassificationModel::where('deleted_at', 0)
|
|
->orderBy('id')
|
|
->get(['id', 'name'])
|
|
->toArray();
|
|
}
|
|
}
|