77 lines
2.5 KiB
PHP
77 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Service\wx;
|
|
|
|
use App\BaseApp\BaseWxService;
|
|
use App\Models\business\CardClassModel;
|
|
use App\Models\business\ColorcardModel;
|
|
use App\Models\business\CompanyModel;
|
|
use App\Service\common\MediaUrlService;
|
|
|
|
/**
|
|
* 小程序色卡目录(只读)
|
|
*/
|
|
class WxColorcardService extends BaseWxService
|
|
{
|
|
protected bool $needLogin = false;
|
|
|
|
public function list(): array
|
|
{
|
|
$classId = (int) request()->get('card_class', 0);
|
|
$companyId = (int) request()->get('company', 0);
|
|
$keyword = trim((string) request()->get('keyword', ''));
|
|
$query = ColorcardModel::with(['cardClassInfo', 'companyInfo'])
|
|
->where('deleted_at', 0)
|
|
->where('status', 0)
|
|
->orderByDesc('id');
|
|
if ($classId > 0) {
|
|
$query->where('card_class', $classId);
|
|
}
|
|
if ($companyId > 0) {
|
|
$query->where('company', $companyId);
|
|
}
|
|
if ($keyword !== '') {
|
|
$query->where('description', 'like', '%' . $keyword . '%');
|
|
}
|
|
$rows = $query->get()->toArray();
|
|
$media = MediaUrlService::getInstance();
|
|
foreach ($rows as &$row) {
|
|
$row['cover'] = $media->toPublic($row['cover'] ?? '');
|
|
$row['card_class_name'] = $row['card_class_info']['name'] ?? '';
|
|
$row['company_name'] = $row['company_info']['name'] ?? '';
|
|
unset($row['card_class_info'], $row['company_info']);
|
|
}
|
|
unset($row);
|
|
return $rows;
|
|
}
|
|
|
|
public function detail(int $id): array
|
|
{
|
|
$info = ColorcardModel::with(['cardClassInfo', 'companyInfo'])
|
|
->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['card_class_name'] = $info['card_class_info']['name'] ?? '';
|
|
$info['company_name'] = $info['company_info']['name'] ?? '';
|
|
unset($info['card_class_info'], $info['company_info']);
|
|
return $info;
|
|
}
|
|
|
|
public function classList(): array
|
|
{
|
|
return CardClassModel::where('deleted_at', 0)->orderBy('id')->get(['id', 'name'])->toArray();
|
|
}
|
|
|
|
public function companyList(): array
|
|
{
|
|
return CompanyModel::where('deleted_at', 0)->orderBy('id')->get(['id', 'name'])->toArray();
|
|
}
|
|
}
|