更新
This commit is contained in:
@@ -6,6 +6,7 @@ namespace app\adminapi\controller\order;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\order\OrderLists;
|
||||
use app\adminapi\logic\order\OrderActionLogLogic;
|
||||
use app\adminapi\logic\order\OrderLogic;
|
||||
use app\adminapi\validate\order\OrderValidate;
|
||||
|
||||
@@ -140,15 +141,62 @@ class OrderController extends BaseAdminController
|
||||
public function detail()
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('detail');
|
||||
$detail = OrderLogic::detail((int)$params['id']);
|
||||
$orderId = (int)$params['id'];
|
||||
$detail = OrderLogic::detail($orderId);
|
||||
|
||||
if (!$detail) {
|
||||
return $this->fail('订单不存在');
|
||||
}
|
||||
|
||||
$this->logOrderAction($orderId, 'view_detail', '查看订单详情');
|
||||
|
||||
return $this->data($detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 支付单操作日志(单条订单,分页)
|
||||
*/
|
||||
public function actionLogs()
|
||||
{
|
||||
$orderId = (int)$this->request->get('order_id', 0);
|
||||
if ($orderId <= 0) {
|
||||
return $this->fail('order_id 必填');
|
||||
}
|
||||
$pageNo = (int)$this->request->get('page_no', 1);
|
||||
$pageSize = (int)$this->request->get('page_size', 20);
|
||||
$data = OrderActionLogLogic::listByOrderId($orderId, $pageNo, $pageSize);
|
||||
|
||||
return $this->success('', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 按人统计操作次数(时间范围内)
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function actionLogStats()
|
||||
{
|
||||
$start = trim((string)$this->request->get('start_time', ''));
|
||||
$end = trim((string)$this->request->get('end_time', ''));
|
||||
if ($start === '' || $end === '') {
|
||||
$endTime = time();
|
||||
$startTime = $endTime - 7 * 86400;
|
||||
} else {
|
||||
$startTime = strtotime($start . ' 00:00:00') ?: 0;
|
||||
$endTime = strtotime($end . ' 23:59:59') ?: 0;
|
||||
}
|
||||
if ($startTime <= 0 || $endTime < $startTime) {
|
||||
return $this->fail('时间范围无效');
|
||||
}
|
||||
$limit = (int)$this->request->get('limit', 50);
|
||||
$rows = OrderActionLogLogic::statsByAdmin($startTime, $endTime, $limit);
|
||||
|
||||
return $this->success('', [
|
||||
'list' => $rows,
|
||||
'start_time' => date('Y-m-d H:i:s', $startTime),
|
||||
'end_time' => date('Y-m-d H:i:s', $endTime),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 创建订单
|
||||
* @return \think\response\Json
|
||||
@@ -157,11 +205,14 @@ class OrderController extends BaseAdminController
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('create');
|
||||
$params['creator_id'] = $this->adminId;
|
||||
|
||||
$params['payment_channel'] = (string)$this->request->post('payment_channel', 'normal');
|
||||
$params['require_payment_slip_audit'] = (int)$this->request->post('require_payment_slip_audit', 0);
|
||||
|
||||
$result = OrderLogic::create($params);
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$this->logOrderAction((int)$result->id, 'create', '创建支付单(普通/付呗等)');
|
||||
|
||||
return $this->success('创建成功', $result->toArray());
|
||||
}
|
||||
@@ -181,6 +232,10 @@ class OrderController extends BaseAdminController
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$ord = $result['order'] ?? null;
|
||||
if (is_array($ord) && !empty($ord['id'])) {
|
||||
$this->logOrderAction((int)$ord['id'], 'create_wechat_work', '创建支付单(企业微信对外收款)');
|
||||
}
|
||||
|
||||
return $this->success('创建成功,请在企业微信收款时使用以下订单号', [
|
||||
'order_no' => $result['order_no'],
|
||||
@@ -189,6 +244,51 @@ class OrderController extends BaseAdminController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 批量指派医助(写入 order.assistant_id,并记操作日志)
|
||||
*/
|
||||
public function assignAssistant()
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('assign_assistant');
|
||||
$rawIds = $params['order_ids'] ?? [];
|
||||
if (!\is_array($rawIds) || $rawIds === []) {
|
||||
return $this->fail('请选择订单');
|
||||
}
|
||||
$orderIds = array_map('intval', $rawIds);
|
||||
$orderIds = array_values(array_unique(array_filter($orderIds, static fn (int $id) => $id > 0)));
|
||||
if ($orderIds === []) {
|
||||
return $this->fail('请选择有效订单');
|
||||
}
|
||||
$allowed = [];
|
||||
foreach ($orderIds as $id) {
|
||||
$order = \app\common\model\Order::find($id);
|
||||
if (!$order) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->canEditOrder($order)) {
|
||||
return $this->fail('无权限操作订单:' . (string) ($order->order_no ?? $id));
|
||||
}
|
||||
$allowed[] = $id;
|
||||
}
|
||||
if ($allowed === []) {
|
||||
return $this->fail('没有可指派的订单');
|
||||
}
|
||||
$assistantId = (int) $params['assistant_id'];
|
||||
$result = OrderLogic::batchAssignAssistant($allowed, $assistantId);
|
||||
if ($result === false) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
foreach ($result['per_log'] as $row) {
|
||||
$this->logOrderAction((int) $row['order_id'], 'assign_assistant', (string) ($row['summary'] ?? ''));
|
||||
}
|
||||
$msg = '已变更「创建人」' . (int) $result['success'] . ' 单';
|
||||
if (!empty($result['errors'])) {
|
||||
$msg .= ',说明:' . implode(';', $result['errors']);
|
||||
}
|
||||
|
||||
return $this->success($msg, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑订单(关联患者、订单类型)
|
||||
* 权限:超管或指定角色组可修改任意订单;其他用户只能修改自己创建的订单
|
||||
@@ -210,6 +310,7 @@ class OrderController extends BaseAdminController
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$this->logOrderAction($orderId, 'edit', '编辑患者/订单类型等');
|
||||
|
||||
return $this->success('编辑成功');
|
||||
}
|
||||
@@ -261,6 +362,7 @@ class OrderController extends BaseAdminController
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$this->logOrderAction($orderId, 'pay', '确认支付/标记已付,方式:' . (string)($params['payment_method'] ?? ''));
|
||||
|
||||
return $this->success('支付成功');
|
||||
}
|
||||
@@ -273,10 +375,12 @@ class OrderController extends BaseAdminController
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('cancel');
|
||||
|
||||
$result = OrderLogic::cancel((int)$params['id']);
|
||||
$oid = (int)$params['id'];
|
||||
$result = OrderLogic::cancel($oid);
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$this->logOrderAction($oid, 'cancel', '取消订单');
|
||||
|
||||
return $this->success('取消成功');
|
||||
}
|
||||
@@ -289,10 +393,12 @@ class OrderController extends BaseAdminController
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('refund');
|
||||
|
||||
$result = OrderLogic::refund((int)$params['id']);
|
||||
$oid = (int)$params['id'];
|
||||
$result = OrderLogic::refund($oid);
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$this->logOrderAction($oid, 'refund', '退款');
|
||||
|
||||
return $this->success('退款成功');
|
||||
}
|
||||
@@ -305,10 +411,12 @@ class OrderController extends BaseAdminController
|
||||
{
|
||||
$params = (new OrderValidate())->post()->goCheck('delete');
|
||||
|
||||
$result = OrderLogic::delete((int)$params['id']);
|
||||
$oid = (int)$params['id'];
|
||||
$result = OrderLogic::delete($oid);
|
||||
if (!$result) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
$this->logOrderAction($oid, 'delete', '删除订单(软删)');
|
||||
|
||||
return $this->success('删除成功');
|
||||
}
|
||||
@@ -409,4 +517,9 @@ class OrderController extends BaseAdminController
|
||||
return \app\common\model\Order::find((int)$params['id']);
|
||||
}
|
||||
}
|
||||
|
||||
private function logOrderAction(int $orderId, string $action, string $summary = ''): void
|
||||
{
|
||||
OrderActionLogLogic::record($orderId, (int) $this->adminId, $this->adminInfo, $action, $summary);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user