更新
This commit is contained in:
@@ -10,4 +10,7 @@ namespace app\common\model;
|
||||
class ExpressQueryLog extends BaseModel
|
||||
{
|
||||
protected $name = 'express_query_log';
|
||||
|
||||
// 表只有 create_time、无 update_time;config/database.php 全局 auto_timestamp=true,需显式关闭避免 Unknown column 'update_time'
|
||||
protected $autoWriteTimestamp = false;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ class ExpressStateLog extends BaseModel
|
||||
{
|
||||
protected $name = 'express_state_log';
|
||||
|
||||
// 表只有 create_time、无 update_time;config/database.php 全局 auto_timestamp=true,需显式关闭避免 Unknown column 'update_time'
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
/**
|
||||
* 关联主表
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,9 @@ class ExpressTrace extends BaseModel
|
||||
{
|
||||
protected $name = 'express_trace';
|
||||
|
||||
// 表只有 create_time、无 update_time;config/database.php 全局 auto_timestamp=true,需显式关闭避免 Unknown column 'update_time'
|
||||
protected $autoWriteTimestamp = false;
|
||||
|
||||
/**
|
||||
* 关联主表
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\model\finance;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class DeptPerformanceTarget extends BaseModel
|
||||
{
|
||||
protected $name = 'dept_performance_target';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
protected $createTime = 'create_time';
|
||||
|
||||
protected $updateTime = 'update_time';
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use app\common\model\ExpressTrace;
|
||||
use app\common\model\ExpressStateLog;
|
||||
use app\common\model\ExpressQueryLog;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderLog;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
@@ -154,6 +155,12 @@ class ExpressTrackingService
|
||||
$tracking->auto_update = 0; // 停止自动更新
|
||||
}
|
||||
|
||||
// 物流为「签收」(STATE_SIGNED) → 自动推进关联业务订单到「已签收」(fulfillment_status=6)
|
||||
// 排除「退签/拒签」等其它终态,避免误把退/拒签的订单标成已签收
|
||||
if ($tracking->current_state === ExpressTracking::STATE_SIGNED) {
|
||||
self::autoMarkOrderAsSigned($tracking);
|
||||
}
|
||||
|
||||
// 计算下次更新时间
|
||||
if ($tracking->auto_update == 1 && !ExpressTracking::isFinalState($tracking->current_state)) {
|
||||
$tracking->next_update_time = $now + $tracking->update_interval;
|
||||
@@ -170,6 +177,62 @@ class ExpressTrackingService
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 物流签收时,自动将关联处方业务订单的履约状态推进到「已签收」(6)
|
||||
*
|
||||
* 仅在当前 fulfillment_status 属于「待双审通过(1)/待发货(2)/已发货(5)」时升级,
|
||||
* 避免覆盖「已完成(3)/已取消(4)/已签收(6)/拒收(9)/退款(10)」等业务终态。
|
||||
*/
|
||||
private static function autoMarkOrderAsSigned(ExpressTracking $tracking): void
|
||||
{
|
||||
if ((string) $tracking->order_type !== 'prescription') {
|
||||
return;
|
||||
}
|
||||
$orderId = (int) $tracking->order_id;
|
||||
if ($orderId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$order = PrescriptionOrder::where('id', $orderId)->whereNull('delete_time')->find();
|
||||
if (!$order) {
|
||||
return;
|
||||
}
|
||||
|
||||
$currentFs = (int) $order->fulfillment_status;
|
||||
if (!in_array($currentFs, [1, 2, 5], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$order->fulfillment_status = 6;
|
||||
$order->save();
|
||||
|
||||
try {
|
||||
$log = new PrescriptionOrderLog();
|
||||
$log->prescription_order_id = $orderId;
|
||||
$log->admin_id = 0;
|
||||
$log->admin_name = '系统';
|
||||
$log->action = 'auto_sign';
|
||||
$log->summary = mb_substr(
|
||||
'物流签收(运单:' . (string) $tracking->tracking_number . '),订单状态自动更新为「已签收」',
|
||||
0,
|
||||
500
|
||||
);
|
||||
$log->create_time = time();
|
||||
$log->save();
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Auto sign order log save failed: ' . $e->getMessage(), [
|
||||
'order_id' => $orderId,
|
||||
]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('Auto sign order failed: ' . $e->getMessage(), [
|
||||
'tracking_id' => (int) $tracking->id,
|
||||
'order_id' => $orderId,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 物流表未存收件人手机时,从关联业务订单回填(顺丰/京东等查件必填后四位)
|
||||
*/
|
||||
@@ -334,6 +397,7 @@ class ExpressTrackingService
|
||||
// 3. is_signed = 0(未签收)
|
||||
// 4. current_state 不是终态(排除已签收、退签、拒签)
|
||||
// 5. 关联业务订单 tcm_prescription_order:已存在甘草单号 gancao_reciperl_order_no 的不再走本任务(由甘草侧物流拉取)
|
||||
// 6. 关联业务订单 fulfillment_status 不在终态白名单:3/4/6/8/9/10/11/12(已完成/已取消/已签收/暂不制药/拒收/退款/保留药方/制药缓发)
|
||||
$list = ExpressTracking::alias('et')
|
||||
->leftJoin("{$poTable} po", "et.order_id = po.id AND et.order_type = 'prescription'")
|
||||
->where('et.auto_update', 1)
|
||||
@@ -349,6 +413,10 @@ class ExpressTrackingService
|
||||
"(et.order_type <> ? OR TRIM(COALESCE(po.gancao_reciperl_order_no, '')) = '')",
|
||||
['prescription']
|
||||
)
|
||||
->whereRaw(
|
||||
"(et.order_type <> ? OR po.id IS NULL OR po.fulfillment_status NOT IN (3,4,6,8,9,10,11,12))",
|
||||
['prescription']
|
||||
)
|
||||
->field('et.*')
|
||||
->limit($limit)
|
||||
->select();
|
||||
|
||||
Reference in New Issue
Block a user