更新
This commit is contained in:
@@ -7,6 +7,7 @@ namespace app\adminapi\logic\order;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\OrderDetail;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\auth\AdminRole;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
@@ -38,13 +39,25 @@ class OrderLogic
|
||||
public static function create(array $params)
|
||||
{
|
||||
try {
|
||||
$channel = (string)($params['payment_channel'] ?? 'normal');
|
||||
if (!in_array($channel, ['normal', 'fubei'], true)) {
|
||||
$channel = 'normal';
|
||||
}
|
||||
$requirePaymentSlipAudit = (int)($params['require_payment_slip_audit'] ?? 0) === 1;
|
||||
|
||||
$order = new Order();
|
||||
$order->order_no = self::generateOrderNo();
|
||||
$order->patient_id = $params['patient_id'];
|
||||
$order->creator_id = $params['creator_id'];
|
||||
$order->order_type = $params['order_type'];
|
||||
$order->amount = $params['amount'];
|
||||
$order->status = 1; // 待支付
|
||||
// 付呗且申请审核支付单:待审核(5);否则待支付(1)
|
||||
if ($channel === 'fubei') {
|
||||
$order->payment_method = 'fubei';
|
||||
$order->status = $requirePaymentSlipAudit ? 5 : 1;
|
||||
} else {
|
||||
$order->status = 1; // 待支付
|
||||
}
|
||||
$order->remark = $params['remark'] ?? '';
|
||||
$order->save();
|
||||
|
||||
@@ -331,7 +344,13 @@ class OrderLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($order->status != 1) {
|
||||
$st = (int)$order->status;
|
||||
// 1=待支付;5=待审核(付呗+申请支付单审核) 时允许录入手动到账
|
||||
if ($st === 1) {
|
||||
// 正常待支付
|
||||
} elseif ($st === 5 && (string)($order->payment_method ?? '') === 'fubei') {
|
||||
// 待审核的付呗单,通过人工确认后标记已支付
|
||||
} else {
|
||||
self::setError('订单状态不允许支付');
|
||||
return false;
|
||||
}
|
||||
@@ -362,8 +381,9 @@ class OrderLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($order->status != 1) {
|
||||
self::setError('只有待支付的订单才能取消');
|
||||
$st = (int)$order->status;
|
||||
if ($st !== 1 && !($st === 5 && (string)($order->payment_method ?? '') === 'fubei')) {
|
||||
self::setError('只有待支付或待审核(付呗)的订单才能取消');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1097,4 +1117,84 @@ class OrderLogic
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量指派给医助:将「创建人」变更为目标医助(须为医助 role_id=2),用于列表筛选项为创建人=该医助
|
||||
*
|
||||
* @param int[] $orderIds
|
||||
* @return array{success: int, per_log: list<array{order_id: int, summary: string}>, fail: int, errors: list<string>}|false
|
||||
*/
|
||||
public static function batchAssignAssistant(array $orderIds, int $assistantAdminId)
|
||||
{
|
||||
$assistantAdminId = (int) $assistantAdminId;
|
||||
if ($assistantAdminId <= 0) {
|
||||
self::setError('请选择医助');
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
AdminRole::where('admin_id', $assistantAdminId)
|
||||
->where('role_id', 2)
|
||||
->count() === 0
|
||||
) {
|
||||
self::setError('目标账号不是医助角色');
|
||||
return false;
|
||||
}
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $orderIds), static fn (int $id) => $id > 0)));
|
||||
if ($ids === []) {
|
||||
self::setError('请选择订单');
|
||||
return false;
|
||||
}
|
||||
if (count($ids) > 200) {
|
||||
self::setError('单次最多200单');
|
||||
return false;
|
||||
}
|
||||
|
||||
$targetName = (string) Admin::where('id', $assistantAdminId)->whereNull('delete_time')->value('name');
|
||||
if ($targetName === '') {
|
||||
$targetName = (string) $assistantAdminId;
|
||||
}
|
||||
$perLog = [];
|
||||
$errors = [];
|
||||
foreach ($ids as $oid) {
|
||||
$order = Order::where('id', $oid)->whereNull('delete_time')->find();
|
||||
if (! $order) {
|
||||
$errors[] = "订单{$oid}不存在或已删除";
|
||||
continue;
|
||||
}
|
||||
$oldCreatorId = (int) $order->creator_id;
|
||||
if ($oldCreatorId === $assistantAdminId) {
|
||||
$errors[] = "订单{$oid}创建人已是该医助,已跳过";
|
||||
continue;
|
||||
}
|
||||
$oldName = $oldCreatorId > 0
|
||||
? (string) Admin::where('id', $oldCreatorId)->whereNull('delete_time')->value('name')
|
||||
: '';
|
||||
if ($oldName === '' && $oldCreatorId > 0) {
|
||||
$oldName = (string) $oldCreatorId;
|
||||
} elseif ($oldName === '') {
|
||||
$oldName = '—';
|
||||
}
|
||||
$order->creator_id = $assistantAdminId;
|
||||
if (! $order->save()) {
|
||||
$errors[] = "订单{$oid}保存失败";
|
||||
continue;
|
||||
}
|
||||
$perLog[] = [
|
||||
'order_id' => (int) $order->id,
|
||||
'summary' => '创建人由「' . $oldName . '」变更为医助「' . $targetName . '」',
|
||||
];
|
||||
}
|
||||
|
||||
if ($perLog === []) {
|
||||
self::setError($errors !== [] ? implode(';', $errors) : '未能变更任何订单');
|
||||
return false;
|
||||
}
|
||||
|
||||
return [
|
||||
'success' => count($perLog),
|
||||
'per_log' => $perLog,
|
||||
'fail' => count($errors),
|
||||
'errors' => $errors,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user