131 lines
3.9 KiB
PHP
131 lines
3.9 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace app\miniapi\controller;
|
|
|
|
use app\miniapi\service\CustomerCenter\CustomerCenterService;
|
|
|
|
final class CustomerCenter extends Base
|
|
{
|
|
public function applicants()
|
|
{
|
|
$userId = $this->requireLogin();
|
|
if (!is_int($userId)) {
|
|
return $userId;
|
|
}
|
|
|
|
$result = (new CustomerCenterService())->applicants($userId);
|
|
if ((int)($result['code'] ?? 0) !== 1) {
|
|
return $this->fail((string)($result['msg'] ?? '服务异常,请稍后重试'));
|
|
}
|
|
|
|
return $this->ok((array)($result['data'] ?? []));
|
|
}
|
|
|
|
public function applications()
|
|
{
|
|
$userId = $this->requireLogin();
|
|
if (!is_int($userId)) {
|
|
return $userId;
|
|
}
|
|
|
|
$result = (new CustomerCenterService())->applications(
|
|
$userId,
|
|
(int)$this->request->param('page', 1),
|
|
(int)$this->request->param('page_size', 20)
|
|
);
|
|
if ((int)($result['code'] ?? 0) !== 1) {
|
|
return $this->fail((string)($result['msg'] ?? '服务异常,请稍后重试'));
|
|
}
|
|
|
|
return $this->ok((array)($result['data'] ?? []));
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
$userId = $this->requireLogin();
|
|
if (!is_int($userId)) {
|
|
return $userId;
|
|
}
|
|
|
|
$payStatus = strtolower(trim((string)$this->request->param('pay_status', 'pay')));
|
|
if (!in_array($payStatus, ['pay', 'nopay'], true)) {
|
|
return $this->fail('支付状态参数错误');
|
|
}
|
|
|
|
$result = (new CustomerCenterService())->orders(
|
|
$userId,
|
|
$payStatus,
|
|
(int)$this->request->param('page', 1),
|
|
(int)$this->request->param('page_size', 20)
|
|
);
|
|
if ((int)($result['code'] ?? 0) !== 1) {
|
|
return $this->fail((string)($result['msg'] ?? '服务异常,请稍后重试'));
|
|
}
|
|
|
|
return $this->ok((array)($result['data'] ?? []));
|
|
}
|
|
|
|
public function applicant()
|
|
{
|
|
$action = strtolower(trim((string)$this->request->param('_action', '')));
|
|
if ($action === 'save') {
|
|
return $this->saveApplicant();
|
|
}
|
|
|
|
$userId = $this->requireLogin();
|
|
if (!is_int($userId)) {
|
|
return $userId;
|
|
}
|
|
|
|
$applicantId = (int)$this->request->param('applicant_id', 0);
|
|
if ($applicantId <= 0) {
|
|
return $this->fail('参数错误');
|
|
}
|
|
$result = (new CustomerCenterService())->applicant(
|
|
$userId,
|
|
$applicantId,
|
|
(bool)$this->request->param('include_materials', false)
|
|
);
|
|
if ((int)($result['code'] ?? 0) !== 1) {
|
|
return $this->fail((string)($result['msg'] ?? '服务异常,请稍后重试'));
|
|
}
|
|
|
|
return $this->ok((array)($result['data'] ?? []));
|
|
}
|
|
|
|
public function saveApplicant()
|
|
{
|
|
$userId = $this->requireLogin();
|
|
if (!is_int($userId)) {
|
|
return $userId;
|
|
}
|
|
|
|
$result = (new CustomerCenterService())->saveApplicant($userId, $this->postData());
|
|
if ((int)($result['code'] ?? 0) !== 1) {
|
|
return $this->fail((string)($result['msg'] ?? '保存失败,请稍后重试'));
|
|
}
|
|
|
|
return $this->ok((array)($result['data'] ?? []), '保存成功');
|
|
}
|
|
|
|
public function removeApplicant()
|
|
{
|
|
$userId = $this->requireLogin();
|
|
if (!is_int($userId)) {
|
|
return $userId;
|
|
}
|
|
|
|
$applicantId = (int)$this->request->param('applicant_id', 0);
|
|
if ($applicantId <= 0) {
|
|
return $this->fail('参数错误');
|
|
}
|
|
$result = (new CustomerCenterService())->removeApplicant($userId, $applicantId);
|
|
if ((int)($result['code'] ?? 0) !== 1) {
|
|
return $this->fail((string)($result['msg'] ?? '移除失败,请稍后重试'));
|
|
}
|
|
|
|
return $this->ok([], '已移除');
|
|
}
|
|
}
|