253 lines
8.0 KiB
PHP
253 lines
8.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\controller\tcm;
|
|
|
|
use app\adminapi\controller\BaseAdminController;
|
|
use app\adminapi\lists\tcm\PrescriptionOrderLists;
|
|
use app\adminapi\logic\order\OrderLogic;
|
|
use app\adminapi\logic\tcm\PrescriptionOrderLogic;
|
|
use app\adminapi\validate\tcm\PrescriptionOrderValidate;
|
|
|
|
/**
|
|
* 处方业务订单(非支付单)
|
|
*/
|
|
class PrescriptionOrderController extends BaseAdminController
|
|
{
|
|
public function lists()
|
|
{
|
|
return $this->dataLists(new PrescriptionOrderLists());
|
|
}
|
|
|
|
/**
|
|
* 指定诊单下已支付支付单(创建/编辑业务订单时多选关联)
|
|
*/
|
|
public function paidPayOrders()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->get()->goCheck('paidPayOrders');
|
|
$exceptPo = (int) $this->request->get('prescription_order_id', 0);
|
|
$lists = OrderLogic::listPaidOrdersForDiagnosis(
|
|
(int) $params['diagnosis_id'],
|
|
$this->adminId,
|
|
$this->adminInfo,
|
|
$exceptPo > 0 ? $exceptPo : null
|
|
);
|
|
|
|
$min = PrescriptionOrderLogic::depositMinAmount();
|
|
|
|
// if ($min > 0) {
|
|
// $lists = array_values(array_filter(
|
|
// $lists,
|
|
// static fn(array $r): bool => round((float) ($r['amount'] ?? 0), 2) >= $min
|
|
// ));
|
|
// }
|
|
|
|
return $this->success('', [
|
|
'lists' => $lists,
|
|
'deposit_min_amount' => $min,
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('create');
|
|
$result = PrescriptionOrderLogic::create($params, $this->adminId, $this->adminInfo);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('创建成功', $result);
|
|
}
|
|
|
|
public function detail()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->get()->goCheck('detail');
|
|
$detail = PrescriptionOrderLogic::detail((int) $params['id'], $this->adminId, $this->adminInfo);
|
|
if ($detail === null) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->data($detail);
|
|
}
|
|
|
|
/**
|
|
* 快递轨迹查询(对接快递100;未配置时仍可跳转顺丰/京东官网)
|
|
*/
|
|
public function logisticsTrace()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->get()->goCheck('logisticsTrace');
|
|
$expressOverride = trim((string) $this->request->get('express_company', ''));
|
|
$data = PrescriptionOrderLogic::logisticsTrace(
|
|
(int) $params['id'],
|
|
$expressOverride,
|
|
$this->adminId,
|
|
$this->adminInfo
|
|
);
|
|
if ($data === null) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('', $data);
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('edit');
|
|
$result = PrescriptionOrderLogic::edit($params, $this->adminId, $this->adminInfo);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('保存成功', $result);
|
|
}
|
|
|
|
public function auditPrescription()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('auditPrescription');
|
|
$result = PrescriptionOrderLogic::auditPrescription(
|
|
(int) $params['id'],
|
|
(string) $params['action'],
|
|
(string) ($params['remark'] ?? ''),
|
|
$this->adminId,
|
|
$this->adminInfo
|
|
);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('操作成功', $result);
|
|
}
|
|
|
|
/**
|
|
* 撤回处方审核
|
|
*/
|
|
public function revokeRxAudit()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('detail');
|
|
$result = PrescriptionOrderLogic::revokeRxAudit(
|
|
(int) $params['id'],
|
|
$this->adminId,
|
|
$this->adminInfo
|
|
);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('处方审核已撤回', $result);
|
|
}
|
|
|
|
public function auditPayment()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('auditPayment');
|
|
$result = PrescriptionOrderLogic::auditPaymentSlip(
|
|
(int) $params['id'],
|
|
(string) $params['action'],
|
|
(string) ($params['remark'] ?? ''),
|
|
$this->adminId,
|
|
$this->adminInfo
|
|
);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('操作成功', $result);
|
|
}
|
|
|
|
/**
|
|
* 撤回支付单审核
|
|
*/
|
|
public function revokePayAudit()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('detail');
|
|
$result = PrescriptionOrderLogic::revokePayAudit(
|
|
(int) $params['id'],
|
|
$this->adminId,
|
|
$this->adminInfo
|
|
);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('支付单审核已撤回', $result);
|
|
}
|
|
|
|
/**
|
|
* 确认发货:将履约状态推进到 5(已发货),同时更新快递信息
|
|
*/
|
|
public function ship()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('ship');
|
|
$result = PrescriptionOrderLogic::ship(
|
|
(int) $params['id'],
|
|
(string) ($params['express_company'] ?? 'auto'),
|
|
(string) ($params['tracking_number'] ?? ''),
|
|
$this->adminId,
|
|
$this->adminInfo
|
|
);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('发货成功', $result);
|
|
}
|
|
|
|
/**
|
|
* 医助/创建人撤回:仅「待双审通过」可撤(未通过或双审均驳回等仍为该状态)
|
|
*/
|
|
public function withdraw()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('withdraw');
|
|
$result = PrescriptionOrderLogic::withdraw((int) $params['id'], $this->adminId, $this->adminInfo);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('已撤回', $result);
|
|
}
|
|
|
|
/**
|
|
* 获取业务订单操作日志
|
|
*/
|
|
public function logs()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->get()->goCheck('logs');
|
|
$result = PrescriptionOrderLogic::getLogs((int) $params['id'], $this->adminId, $this->adminInfo);
|
|
|
|
// 遇到没有权限或者订单不存在,逻辑里设置了 self::$error
|
|
if ($result === [] && PrescriptionOrderLogic::getError() !== '') {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('', $result);
|
|
}
|
|
|
|
/**
|
|
* 为「已发货」订单新增一条关联支付单,并重置支付单审核状态为待审核
|
|
*/
|
|
public function addPayOrder()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('addPayOrder');
|
|
$result = PrescriptionOrderLogic::addPayOrder($params, $this->adminId, $this->adminInfo);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('新增支付单成功', $result);
|
|
}
|
|
|
|
/**
|
|
* 将「已发货」且支付审核已通过的订单标记为「已完成」
|
|
*/
|
|
public function complete()
|
|
{
|
|
$params = (new PrescriptionOrderValidate())->post()->goCheck('complete');
|
|
$result = PrescriptionOrderLogic::complete((int) $params['id'], $this->adminId, $this->adminInfo);
|
|
if ($result === false) {
|
|
return $this->fail(PrescriptionOrderLogic::getError());
|
|
}
|
|
|
|
return $this->success('订单已完成', $result);
|
|
}
|
|
}
|