1. 【新增】售后单售后原因类型支持搜索

2. 【新增】手工创建订单折扣可输入正数

3. 【优化】盘点申请单确认

4. 【修复】采购退货单模拟出库失败问题

5. 【新增】订单金额客户实付与结算金额

6. 【优化】仓库发货统计报表物料名称显示

7. 【优化】自有仓储虚拟发货逻辑

8. 【修复】基础物料分类管理问题
This commit is contained in:
chenping
2026-04-01 11:59:17 +08:00
parent 9341122827
commit 61783b7d01
754 changed files with 46179 additions and 5700 deletions

View File

@@ -32,7 +32,15 @@ class monitor_ctl_admin_setting extends desktop_controller
{
$this->begin();
app::get('monitor')->setConf('email.config', $_POST['email']);
$emailConfig = (array) app::get('monitor')->getConf('email.config');
$emailPost = isset($_POST['email']) && is_array($_POST['email']) ? $_POST['email'] : array();
// 密码未提交或提交为空字符串时保留历史值,避免误清空(如字符串"0"被empty误判
if ($emailPost && (!array_key_exists('smtppasswd', $emailPost) || $emailPost['smtppasswd'] === '') && !empty($emailConfig['smtppasswd'])) {
$emailPost['smtppasswd'] = $emailConfig['smtppasswd'];
}
app::get('monitor')->setConf('email.config', $emailPost);
app::get('monitor')->setConf('workwx.config', $_POST['workwx']);

View File

@@ -84,6 +84,7 @@ $db['event_notify'] = array(
'sms' => '短信',
'email' => '邮箱',
'workwx'=>'企微',
'zhannei'=>'站内',
),
'default' => 'email',
'label' => '发送类型',

View File

@@ -68,6 +68,7 @@ $db['event_template'] = array(
// 'sms' => '短信',
'email' => '邮箱',
'workwx' => '企微',
'zhannei' => '站内',
),
'default' => 'email',
'label' => '发送类型',

View File

@@ -108,7 +108,32 @@ INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_
VALUES ('order_360buy_delivery_error', '【京东】订单挂起不可以发货', 'order_360buy_delivery_error', 'workwx', '以下订单挂起不可以发货:
>订单号:<font color=\"warning\">{order_bn}</font>', '1', 'system', '2024-05-08 10:22:23', '2024-05-08 10:22:23');
-- 库存回写监控模板
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`,
`source`, `disabled`, `at_time`, `up_time`)
VALUES ('order_ship_refund_apply', '订单已发货仅退款发起申请', 'order_ship_refund_apply', 'email', '订单[{order_bn}]已发货,不可以退款。退款单号:{refund_apply_bn},退款金额:{refund_fee}', '1', 'system', 'true', '2025-06-18 10:22:23', '2025-06-18 10:22:23');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`,
`source`, `disabled`, `at_time`, `up_time`)
VALUES ('order_unship_refund_apply', '订单未发货退款发起申请', 'order_unship_refund_apply', 'email', '订单[{order_bn}]未生成发货单,可以退款。退款单号:{refund_apply_bn},退款金额:{refund_fee}', '1', 'system', 'true', '2025-06-18 10:22:23', '2025-06-18 10:22:23');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`,
`source`, `disabled`, `at_time`, `up_time`)
VALUES ('order_refund_apply_reback_fail', '订单退款发起申请发货单撤销失败', 'order_refund_apply_reback_fail', 'email', '订单[{order_bn}]对应发货单[{delivery_bn}]撤销失败,失败原因:{msg}。退款单号[{refund_apply_bn}]不可退款,退款金额:{refund_fee}', '1', 'system', 'true', '2025-06-18 10:22:23', '2025-06-18 10:22:23');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`,
`source`, `disabled`, `at_time`, `up_time`)
VALUES ('order_part_ship_refund_apply', '订单部分发货仅退款发起申请', 'order_part_ship_refund_apply', 'email', '订单[{order_bn}]对应发货单[{delivery_bn}]发货完成。退款单号[{refund_apply_bn}]不可退款,退款金额:{refund_fee}', '1', 'system', 'true', '2025-06-18 10:22:23', '2025-06-18 10:22:23');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`,
`source`, `disabled`, `at_time`, `up_time`)
VALUES ('order_refund_apply_reback_succ', '退款申请对应发货单均撤回', 'order_refund_apply_reback_succ', 'email', '退款单号[{refund_apply_bn}]对应子单号都已叫回,可退款。退款金额:{refund_fee},订单号:{order_bn}', '1', 'system', 'true', '2025-06-18 10:22:23', '2025-06-18 10:22:23');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`,
`source`, `disabled`, `at_time`, `up_time`)
VALUES ('order_refund_apply_force_refund', '退款单强制退款', 'order_refund_apply_force_refund', 'email', '订单[{order_bn}]平台小二已介入强制退款,请尽快联系客户上门取件。', '1', 'system', 'true', '2025-06-18 10:22:23', '2025-06-18 10:22:23');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`, `source`, `at_time`, `up_time`)
VALUES ('order_delivery_timeliness', '订单发货时效提醒', 'order_delivery_timeliness', 'email', '订单发货时效提醒
>订单号:<font color=\"warning\">{order_bn}</font>
>平台:<font color=\"warning\">{shop_type}</font>
>支付时间:<font color=\"warning\">{paytime}</font>
>剩余时间:<font color=\"warning\">{remaining_hours}</font>小时', '1', 'system', '2025-01-20 00:00:00', '2025-01-20 00:00:00');
-- 库存回写监控模板
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`, `source`, `at_time`, `up_time`)
VALUES ('inventory_calc_error', '库存计算异常报警', 'inventory_calc_error', 'email', '库存计算异常报警
>时间:<font color=\"warning\">{datetime}</font>
@@ -118,3 +143,25 @@ VALUES ('inventory_calc_error', '库存计算异常报警', 'inventory_calc_erro
>异常信息:<font color=\"warning\">{error_message}</font>
>异常位置:<font color=\"warning\">{error_location}</font>
>规则信息:<font color=\"warning\">{regulation_info}</font>', '1', 'system', '2024-12-19 00:00:00', '2024-12-19 00:00:00');
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`, `source`, `at_time`, `up_time`)
VALUES ('order_delivery_platform_sync_error', '订单发货回写平台失败', 'order_delivery_platform_sync_error', 'email', '订单发货回写平台失败
>订单号:<font color=\"warning\">{order_bn}</font>
>发货单号:<font color=\"warning\">{delivery_bn}</font>
>平台:<font color=\"warning\">{platform}</font>
>店铺:<font color=\"warning\">{shop_name}</font>
>错误信息:<font color=\"warning\">{errmsg}</font>', '1', 'system', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`, `source`, `at_time`, `up_time`)
VALUES ('delivery_cancel_wms_notify', '发货单撤销WMS通知', 'delivery_cancel_wms', 'email', '{shop_type}平台{shop_name}店铺发货单号({delivery_bn}已撤销明细如下请WMS端及时取消出货谢谢。
{detail_list}', '1', 'system', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- 订单缺货通知模板
INSERT INTO `sdb_monitor_event_template`(`template_bn`, `template_name`, `event_type`, `send_type`, `content`, `status`, `source`, `at_time`, `up_time`)
VALUES ('order_lack_notify', '订单缺货通知', 'order_lack_notify', 'email', '订单缺货通知
>订单号:<font color=\"warning\">{order_bn}</font>
>仓库:<font color=\"warning\">{branch_name}</font>
>缺货商品数量:<font color=\"warning\">{lack_count}</font>
>缺货商品详情:
{lack_products}', '1', 'system', '2024-12-19 00:00:00', '2024-12-19 00:00:00');

View File

@@ -28,6 +28,14 @@ class monitor_autotask_timer_checkfreezestore
set_time_limit(0);
ignore_user_abort(1);
@ini_set('memory_limit', '1024M');
// ---------------------------init time---------------------------
// ---------------------------init time---------------------------
// $init_time = strtotime('2026-03-27 09:00:00');
// base_kvstore::instance('monitor/checkfreezestore')->store('sync-lastexectime-exec', $init_time);
// base_kvstore::instance('monitor/checkfreezestore')->store('sync-lastexectime', $init_time);
// ---------------------------init time---------------------------
// ---------------------------init time---------------------------
$now = time();
@@ -528,8 +536,33 @@ class monitor_autotask_timer_checkfreezestore
}
// 定时场景下做二次复检,过滤瞬时抖动导致的误报
$skipDoubleCheck = false;
if (!$params['show'] && !$params['script'] && !$params['skip_double_check'] && $failInfo) {
$candidateBmIds = $this->collectFailBmIds($failInfo);
if ($candidateBmIds) {
$candidateCount = count($candidateBmIds);
if ($candidateCount > 600) {
$skipDoubleCheck = true;
} else {
sleep(6);
$scriptParams = [
'script' => true,
'uptime' => false,
'script_bm_id_list' => $candidateBmIds,
'skip_double_check' => true,
];
$tmpErr = '';
$doubleCheckFailInfo = $this->process($scriptParams, $tmpErr);
if (is_array($doubleCheckFailInfo)) {
$failInfo = $doubleCheckFailInfo;
}
}
}
}
$msgHead = [
'时间:' . ($last_modified ? date('m/d H:i:s', $last_modified) : 'NULL') . '——' . $timeEnd,
'时间:' . ($last_modified ? date('m/d H:i:s', $last_modified) : 'NULL') . '——' . $timeEnd . ($skipDoubleCheck ? ' (未复检)' : ''),
// '域名:' . kernel::base_url(1),
"====== ====== ======",
];
@@ -545,7 +578,7 @@ class monitor_autotask_timer_checkfreezestore
$earliest = $sfv['last_modified'];
}
if ($sfk<$showNum) {
$stock_freeze_msg = array_merge($msgHead, json_encode($sfv, JSON_UNESCAPED_UNICODE));
$stock_freeze_msg = array_merge($msgHead, [json_encode($sfv, JSON_UNESCAPED_UNICODE)]);
}
}
}
@@ -686,6 +719,51 @@ class monitor_autotask_timer_checkfreezestore
return true;
}
/**
* 汇总各维度异常中的 bm_id做二次复检用
*/
private function collectFailBmIds($failInfo)
{
$bmIds = [];
if (!is_array($failInfo)) {
return [];
}
if (!empty($failInfo['vsFreeze'])) {
foreach ($failInfo['vsFreeze'] as $list) {
foreach ((array)$list as $info) {
if (isset($info['bmId'])) {
$bmIds[(int)$info['bmId']] = 1;
}
}
}
}
if (!empty($failInfo['vsStore'])) {
foreach ($failInfo['vsStore'] as $list) {
foreach ((array)$list as $info) {
if (isset($info['bmId'])) {
$bmIds[(int)$info['bmId']] = 1;
}
}
}
}
if (!empty($failInfo['vsBmFreeze'])) {
foreach ((array)$failInfo['vsBmFreeze'] as $bmId => $info) {
$bmIds[(int)$bmId] = 1;
}
}
if (!empty($failInfo['vsBmStore'])) {
foreach ((array)$failInfo['vsBmStore'] as $bmId => $info) {
$bmIds[(int)$bmId] = 1;
}
}
return array_keys($bmIds);
}
private function getMainInfo($type = 'freeze', $info = '')
{
$freezeLib = kernel::single('material_basic_material_stock_freeze');

View File

@@ -25,12 +25,15 @@ class monitor_autotask_timer_checkorderisdelivery {
@ini_set('memory_limit', '1024M');
$now = time() - 180;
$last = strtotime('-1 week');
$sql = "select order_bn,order_bool_type from sdb_ome_orders where is_delivery='N' and status='active' and createtime<{$now} and createtime>{$last} and process_status in ('unconfirmed','confirmed')";
$sql = "select order_bn,order_bool_type,pay_status from sdb_ome_orders where is_delivery='N' and status='active' and createtime<{$now} and createtime>{$last} and process_status in ('unconfirmed','confirmed')";
$list = kernel::database()->select($sql);
foreach($list as $k => $order) {
if($order['order_bool_type'] & ome_order_bool_type::__RISK_CODE) {
unset($list[$k]);
}
if($order['pay_status'] != 1) {
unset($list[$k]);
}
}
if($list) {
kernel::single('monitor_event_notify')->addNotify('order_360buy_delivery_error', [

View File

@@ -48,7 +48,7 @@ class monitor_event_notify
$notifyData['template_id'] = $templateInfo['template_id'];
$notifyData['event_type'] = $eventType;
$notifyData['original_content'] = $templateInfo['content'];
$notifyData['send_content'] = '**域名:'.kernel::base_url(1)."**\n".$this->getNotifyParams($templateInfo, $params);
$notifyData['send_content'] = ($templateInfo['send_type'] == 'workwx' ? '**域名:'.kernel::base_url(1)."**\n" : '').$this->getNotifyParams($templateInfo, $params);
$notifyData['send_type'] = $templateInfo['send_type'];
$notifyData['params'] = json_encode($params);
$notifyData['file_path'] = json_encode($params['file_path'],JSON_UNESCAPED_SLASHES);
@@ -78,7 +78,10 @@ class monitor_event_notify
//同步发送
if ($is_sync) {
//调用发送方法
$this->sendNotify($result);
if($params['receiver']) {
$notifyData['receiver'] = $params['receiver'];
}
$this->sendNotify($result, $notifyData);
}
}
return true;
@@ -213,14 +216,22 @@ class monitor_event_notify
* 每天检测将超过30天的发送数据清除
*/
public function clean($clean_time = 30){
$db = kernel::database();
$time = time();
$where = " WHERE `at_time`<'".date('Y-m-d',$time-$clean_time*24*60*60).' 00:00:00'."' ";
$del_sql = " DELETE FROM `sdb_monitor_event_notify` $where ";
kernel::database()->exec($del_sql);
// // 只查询一条数据,判断是否有数据
// $select_sql = "SELECT notify_id FROM sdb_monitor_event_notify ". $where ." LIMIT 0, 1";
// $dataList = $db->select($select_sql);
// if(empty($dataList)){
// return true;
// }
// 删除数据
$del_sql = " DELETE FROM `sdb_monitor_event_notify` $where ";
$db->exec($del_sql);
return true;
}

View File

@@ -56,11 +56,30 @@ class monitor_event_template
'rpc_warning' => 'RPC调用失败报警',
'store_freeze_abnormal' => '库存或冻结消费异常报警',
'inventory_calc_error' => '库存计算异常报警',
'order_ship_refund_apply' => '订单已发货仅退款发起申请',
'order_unship_refund_apply' => '订单未发货退款发起申请',
'order_refund_apply_reback_fail' => '订单退款发起申请发货单撤销失败',
'order_part_ship_refund_apply' => '订单部分发货仅退款发起申请',
'order_refund_apply_reback_succ' => '退款申请对应发货单均撤回',
'order_refund_apply_force_refund' => '退款单强制退款',
'order_delivery_timeliness' => '订单发货时效提醒',
'order_delivery_platform_sync_error' => '订单发货回写平台失败',
'inventory_calc_error' => '库存计算异常报警',
// 新增事件类型
'delivery_cancel_success' => '发货单取消成功通知',
'reship_cancel_success' => '退货单取消成功通知',
'delivery_cancel_wms' => '发货单撤销WMS通知',
'sap_sync_error' => 'SAP同步异常报警',
'order_lack_notify' => '订单缺货通知',
);
foreach(kernel::servicelist('monitor.service.event.template.get.after') as $object) {
if(method_exists($object, 'getEventType')){
$rs = $object->getEventType();
if(is_array($rs) && $rs) {
$eventType = array_merge($eventType, $rs);
}
}
}
return $eventType;
}
@@ -161,6 +180,29 @@ SAP同步异常报警
>接口名:<font color="warning">{method}</font>
>错误信息:<font color="warning">{errmsg}</font>
TPL
,
'order_delivery_platform_sync_error' => <<<TPL
订单发货回写平台失败
>订单号:<font color="warning">{order_bn}</font>
>发货单号:<font color="warning">{delivery_bn}</font>
>平台:<font color="warning">{platform}</font>
>店铺:<font color="warning">{shop_name}</font>
>错误信息:<font color="warning">{errmsg}</font>
TPL
,
'delivery_cancel_wms' => <<<TPL
{shop_type}平台{shop_name}店铺发货单号({delivery_bn}已撤销明细如下请WMS端及时取消出货谢谢。
{detail_list}
TPL
,
'order_lack_notify' => <<<TPL
订单缺货通知
>订单号:<font color="warning">{order_bn}</font>
>仓库:<font color="warning">{branch_name}</font>
>缺货商品数量:<font color="warning">{lack_count}</font>
>缺货商品详情:
{lack_products}
TPL
,
);
}

View File

@@ -71,7 +71,14 @@ class monitor_event_trigger_notify_email extends monitor_event_trigger_notify_co
$receiverInfo = $eventReceiverMdl->getList('receiver',['id'=>$receiverId]);
}
}else{
$receiverInfo[] = ['receiver'=>$notifyInfo['receiver']];
$receiverInfo = [];
if(is_array($notifyInfo['receiver'])) {
foreach($notifyInfo['receiver'] as $receiver) {
$receiverInfo[] = ['receiver'=>$receiver];
}
}else{
$receiverInfo[] = ['receiver'=>$notifyInfo['receiver']];
}
}
// 安全检查:确保$receiverInfo有值且包含有效的receiver字段
if (empty($receiverInfo) || !is_array($receiverInfo)) {
@@ -132,4 +139,4 @@ class monitor_event_trigger_notify_email extends monitor_event_trigger_notify_co
return ['rsp' =>'fail','msg'=> $emailLib->ErrorInfo];
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* @Author: xueding@shopex.cn
* @Vsersion: 2022/10/18
* @Describe: 预警通知邮件发送
*/
class monitor_event_trigger_notify_zhannei extends monitor_event_trigger_notify_common
{
public function send($notifyInfo)
{
if (!$notifyInfo['send_content']) {
return ['rsp' => 'fail', 'msg' => '发送失败,发送内容为空'];
}
if ($notifyInfo['status'] == '1') {
return ['rsp' => 'fail', 'msg' => '已发送不能重复发送'];
}
// 系统消息推送到 servicemonitor.service.notify.zhannei以便业务自定义扩展行为
foreach (kernel::servicelist('monitor.service.notify.zhannei') as $object) {
if (method_exists($object, 'send')) {
$object->send($notifyInfo);
}
}
try {
// 获取rpcnotify模型
$rpcNotifyMdl = app::get('base')->model('rpcnotify');
// 准备插入数据
$data = [
'callback' => '', // 空回调地址
'rsp' => 'succ', // 默认成功状态
'msg' => $notifyInfo['send_content'], // 发送内容作为消息
'notifytime' => time(), // 当前时间戳
'status' => 'false', // 默认未读状态
];
// 插入数据到rpcnotify表
$result = $rpcNotifyMdl->insert($data);
if ($result) {
return ['rsp' => 'succ', 'msg' => '数据已成功写入rpcnotify表'];
} else {
return ['rsp' => 'fail', 'msg' => '数据写入失败'];
}
} catch (Exception $e) {
return ['rsp' => 'fail', 'msg' => $e->getMessage()];
}
}
}

View File

@@ -0,0 +1,142 @@
<?php
class monitor_notice_refund_apply
{
public function erpapi_create($refundApplyId) {
$refundApplyModel = app::get('ome')->model('refund_apply');
$refundApply = $refundApplyModel->db_dump($refundApplyId, 'order_id, refund_apply_bn, money,product_data');
if (!$refundApply) return [false, ['msg' => '退款申请单不存在']];
$orderModel = app::get('ome')->model('orders');
$order = $orderModel->db_dump($refundApply['order_id'], 'order_id, order_bn, ship_status');
if (!$order) return [false, ['msg' => '订单不存在']];
$notifyData = [
'order_bn' => $order['order_bn'],
'refund_apply_bn' => $refundApply['refund_apply_bn'],
'refund_fee' => $refundApply['money']
];
if ($order['ship_status'] == '1') {
kernel::single('monitor_event_notify')->addNotify('order_ship_refund_apply', $notifyData);
return [true, ['msg' => '订单已发货退款发起申请']];
}
$deliveryOrderModel = app::get('ome')->model('delivery_order');
$deliverys = $deliveryOrderModel->getList('delivery_id', array('order_id' => $order['order_id']));
if (empty($deliverys)) {
kernel::single('monitor_event_notify')->addNotify('order_unship_refund_apply', $notifyData);
return [false, ['msg' => '没有发货单']];
}
$arrProduct = unserialize($refundApply['product_data']);
$order_item_id = is_array($arrProduct) ? array_column($arrProduct, 'order_item_id') : [];
$deliveryModel = app::get('ome')->model('delivery');
$deliveryList = $deliveryModel->getList('delivery_id,delivery_bn, sync_msg, status', array('delivery_id' => array_column($deliverys, 'delivery_id'), 'parent_id'=>0));
$didItems = app::get('ome')->model('delivery_items_detail')->getList('delivery_id,order_id,order_item_id', ['delivery_id'=>array_column($deliveryList, 'delivery_id')]);
foreach ($deliveryList as $delivery) {
$needBack = false;
if($order_item_id) {
foreach ($didItems as $didItem) {
if ($didItem['delivery_id'] == $delivery['delivery_id'] && in_array($didItem['order_item_id'], $order_item_id)) {
$needBack = true;
break;
}
}
} else {
$needBack = true;
}
if(!$needBack) {
continue;
}
if (in_array($delivery['status'], ['ready','progress'])) {
$failureMsg = $delivery['sync_msg'] ?: '未知原因';
kernel::single('monitor_event_notify')->addNotify('order_refund_apply_reback_fail', array_merge($notifyData, [
'msg' => $failureMsg,
'delivery_bn' => $delivery['delivery_bn']
]));
return [false, ['msg' => '发货单撤销失败']];
}
if (in_array($delivery['status'], ['succ'])) {
kernel::single('monitor_event_notify')->addNotify('order_part_ship_refund_apply', array_merge($notifyData, [
'delivery_bn' => $delivery['delivery_bn']
]));
return [false, ['msg' => '发货单部分发货']];
}
}
kernel::single('monitor_event_notify')->addNotify('order_refund_apply_reback_succ', $notifyData);
return [true, ['msg' => '发货单撤销成功']];
}
public function erpapi_refund($refundApplyId) {
$refundApplyModel = app::get('ome')->model('refund_apply');
$refundApply = $refundApplyModel->db_dump($refundApplyId, 'order_id, refund_apply_bn, money, product_data');
if (!$refundApply) return [false, ['msg' => '退款申请单不存在']];
$orderModel = app::get('ome')->model('orders');
$order = $orderModel->db_dump($refundApply['order_id'], 'order_id, order_bn, ship_status');
if (!$order) return [false, ['msg' => '订单不存在']];
$notifyData = [
'order_bn' => $order['order_bn'],
'refund_apply_bn' => $refundApply['refund_apply_bn'],
'refund_fee' => $refundApply['money']
];
// 获取订单关联的发货单
$deliveryOrderModel = app::get('ome')->model('delivery_order');
$deliverys = $deliveryOrderModel->getList('delivery_id', array('order_id' => $order['order_id']));
if (empty($deliverys)) {
return [true, ['msg' => '没有发货单']];
}
// 解析退款申请的商品数据,获取 order_item_id
$arrProduct = unserialize($refundApply['product_data']);
$order_item_id = is_array($arrProduct) ? array_column($arrProduct, 'order_item_id') : [];
// 获取发货单详细信息
$deliveryModel = app::get('ome')->model('delivery');
$deliveryList = $deliveryModel->getList('delivery_id, delivery_bn, sync_msg, status', array(
'delivery_id' => array_column($deliverys, 'delivery_id'),
'parent_id' => 0
));
// 获取发货单明细信息
$didItems = app::get('ome')->model('delivery_items_detail')->getList('delivery_id, order_id, order_item_id', [
'delivery_id' => array_column($deliveryList, 'delivery_id')
]);
// 仅检查 ready 和 progress 状态的发货单
foreach ($deliveryList as $delivery) {
if (!in_array($delivery['status'], ['ready', 'progress', 'succ'])) {
continue;
}
$needBack = false;
// 优先使用 order_item_id 匹配
if ($order_item_id) {
foreach ($didItems as $didItem) {
if ($didItem['delivery_id'] == $delivery['delivery_id'] && in_array($didItem['order_item_id'], $order_item_id)) {
$needBack = true;
break;
}
}
} else {
// 如果没有 order_item_id则匹配所有发货单
$needBack = true;
}
if ($needBack) {
$failureMsg = $delivery['sync_msg'] ?: ($delivery['status'] == 'succ' ? '发货单已发货' : '未知原因');
kernel::single('monitor_event_notify')->addNotify('order_refund_apply_reback_fail', array_merge($notifyData, [
'msg' => $failureMsg,
'delivery_bn' => $delivery['delivery_bn']
]));
return [false, ['msg' => '发货单撤销失败']];
}
}
return [true, ['msg' => '发货单撤销成功']];
}
}

View File

@@ -27,6 +27,6 @@ class monitor_task
public function post_install()
{
kernel::log('Initial monitor');
kernel::single('base_initial', 'monitor')->init();
//kernel::single('base_initial', 'monitor')->init();
}
}