问题说明:用户收货或核销后系统处理收货记录时间过长,影响后面问题处理
修改文件:app\listener\order\Take
use app\jobs\order\OrderStatusJob;
public function handle($event): void
{
[$orderInfo, $storeTitle, $isRecord] = $event;
try {
//修改收货状态
/** @var UserBrokerageServices $userBrokerageServices */
$userBrokerageServices = app()->make(UserBrokerageServices::class);
$userBrokerageServices->takeUpdate((int)$orderInfo['uid'], (int)$orderInfo['id']);
/** @var StoreOrderStatusServices $statusService */
$statusService = app()->make(StoreOrderStatusServices::class);
//增加收货订单状态
OrderStatusJob::dispatch(['take', $orderInfo['id']]);
//配送员送货 用户自己点确认收货 写入核销记录
if (isset($orderInfo['delivery_type']) && $orderInfo['delivery_type'] == 'send' && isset($orderInfo['verify_code']) && $orderInfo['verify_code'] && $isRecord) {
OrderWriteoffJob::dispatch([(int)$orderInfo['id'], [], [], $orderInfo]);
}
//更新完成时间
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
$order = $orderServices->get((int)$orderInfo['id']);
if ($order['store_id']) {
StoreFinanceJob::dispatchDo('takeDoJob', [$order, time()]);
} else if ($order['supplier_id']) {
SupplierFinanceJob::dispatchDo('takeDoJob', [$order, time()]);
}
//收货给用户发送消息
event('notice.notice', [['order' => $orderInfo, 'storeTitle' => $storeTitle], 'order_takever']);
//收货给客服发送消息
event('notice.notice', [['order' => $orderInfo, 'storeTitle' => $storeTitle], 'send_admin_confirm_take_over']);
//发送短信
// $storeOrderTake->smsSend($orderInfo, $storeTitle);
// $storeOrderTake->smsSendTake($orderInfo);
//检测主订单 是否全部收货
if ($orderInfo['pid']) {
$id = (int)$orderInfo['pid'];
/** @var StoreOrderServices $orderServices */
$orderServices = app()->make(StoreOrderServices::class);
//默认部分收货
$take_data = ['status' => '5'];
$status_data = ['oid' => $id, 'change_time' => time()];
if ($orderServices->count(['pid' => $id]) == $orderServices->count(['pid' => $id, 'status' => 3])) {
$take_data = ['status' => 2];
$status_data['change_type'] = 'take_split';
$status_data['change_message'] = '已拆分收货';
} else {
$status_data['change_type'] = 'take_part_split';
$status_data['change_message'] = '已拆分部分收货';
}
//改变主订单状态
$orderServices->update($id, $take_data);
//记录主订单状态
$statusService->save($status_data);
}
} catch (\Throwable $e) {
}
//销毁锁
$key = md5('lock_order_take_' . $orderInfo['id']);
CacheService::unLock($key);
}
修改文件:app\services\order\StoreOrderStatusServices
修改方法:saveStatus()
public function saveStatus(string $type, int $orderId, array $data = [])
{
if (!$type || !$orderId) {
return true;
}
$statusData = ['oid' => $orderId, 'change_time' => time(), 'change_type' => ''];
switch ($type) {
case 'create'://创建
$statusData['change_type'] = 'cache_key_create_order';
$statusData['change_message'] = '订单生成';
if (isset($data['changePrice']) && $data['changePrice'] > 0) {//有改价
$this->saveStatus('edit', $orderId, $data);
}
break;
case 'edit'://改价
$statusData['change_type'] = 'order_edit';
$statusData['change_message'] = '商品总价为:' . ($data['totalPrice'] ?? 0) . ' 修改实际支付金额为:' . ($data['payPrice'] ?? 0);
break;
case 'pay'://支付
$statusData['change_type'] = 'pay_success';
$statusData['change_message'] = '用户付款成功';
break;
case 'delivery'://发货
break;
case 'take'://收货
if (!$this->dao->count(['oid' => $orderId, 'change_type' => ['take_delivery', 'user_take_delivery']])) {//是否已经写入收货消息
$statusData['change_type'] = 'take_delivery';
$statusData['change_message'] = '已收货';
}
break;
case 'reply'://评价
break;
default:
throw new ValidateException('未知订单类型记录');
break;
}
$this->dao->save($statusData);
return true;
}