Files
lgp-admin-plus-api/app/Service/business/AfterSaleService.php
2026-08-20 19:16:49 +08:00

62 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Service\business;
use App\BaseApp\BaseService;
use App\Models\business\AfterSaleModel;
/**
* 后台售后审核。通过只改状态,线下退款,不自动打微信。
*/
class AfterSaleService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->model = AfterSaleModel::class;
$this->selectField = [
'id', 'order_id', 'user_id', 'reason', 'amount', 'images',
'status', 'admin_remark', 'created_at', 'updated_at',
];
$this->queryField = ['order_id' => '=', 'user_id' => '=', 'status' => '='];
$this->with = ['order', 'user'];
}
public function list(): array
{
$result = $this->getPageList();
$price = PriceService::getInstance();
foreach ($result['items'] as &$item) {
$item['user_name'] = $item['user']['nick_name'] ?? '';
$item['order_no'] = $item['order']['order_no'] ?? '';
$item['amount_text'] = $price->centsToYuan((int) ($item['amount'] ?? 0));
unset($item['user'], $item['order']);
}
unset($item);
return $result;
}
/**
* 审核pass=true 通过
*/
public function audit(int $id, bool $pass, string $remark = ''): mixed
{
$row = AfterSaleModel::where('id', $id)->where('deleted_at', 0)->first();
if (empty($row)) {
$this->utils->errorThrow('售后单不存在');
}
if ((int) $row['status'] !== AfterSaleModel::STATUS_PENDING) {
$this->utils->errorThrow('已处理过');
}
return $this->save($id, [
'status' => $pass ? AfterSaleModel::STATUS_APPROVED : AfterSaleModel::STATUS_REJECTED,
'admin_remark' => mb_substr(trim($remark), 0, 255),
]);
}
public function delete($ids): mixed
{
return $this->del(is_array($ids) ? $ids : [$ids]);
}
}