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]); } }