79 lines
3.0 KiB
PHP
Executable File
79 lines
3.0 KiB
PHP
Executable File
<?php
|
|
declare (strict_types = 1);
|
|
|
|
namespace app\subscribe;
|
|
|
|
use app\model\Order AS OrderModel;
|
|
use app\model\OrderSku;
|
|
use app\repository\OrderRepository;
|
|
use think\facade\Log;
|
|
|
|
class Order
|
|
{
|
|
public function onOrderCheck()
|
|
{
|
|
Log::info('触发订单检测事件:自动收货、自动过期');
|
|
$day = 3;//自动收货时间 发货后N天
|
|
// $expiredList = OrderRepository::getInstance()->expiredList();
|
|
$needAcceptList = OrderRepository::getInstance()->autoReceiptList($day);
|
|
// var_dump($expiredList->isEmpty());
|
|
// var_dump($needAcceptList->isEmpty());
|
|
// exit;
|
|
/*
|
|
if (!$expiredList->isEmpty()) {
|
|
OrderModel::whereIn('id', $expiredList->column('id'))->save([
|
|
'status' => OrderModel::STATUS_EXPIRED,
|
|
]);
|
|
}
|
|
*/
|
|
|
|
if (!$needAcceptList->isEmpty()) {
|
|
// OrderModel::whereIn('id', $needAcceptList->column('id'))->save([
|
|
// 'status' => OrderModel::STATUS_COMPLETED,
|
|
//// 'completed_at' => date('Y-m-d H:i:s'),
|
|
// 'accepted_at' => date('Y-m-d H:i:s'),
|
|
// ]);
|
|
|
|
// TODO 循环处理 后面再改成批量操作
|
|
foreach ($needAcceptList as $order) {
|
|
OrderRepository::getInstance()->orderAccepted($order['id']);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function onOrderSpuCheck(string $orderCoding = '')
|
|
{
|
|
Log::info('触发订单商品核验事件');
|
|
// 订单商品核验后[线上|线下核验] 1、是否所有商品均核验且没有实体商品 是则订单完成
|
|
Log::info('订单号 '.$orderCoding);
|
|
|
|
if (!$order = OrderModel::where('coding', $orderCoding)->find()) {
|
|
Log::error('订单号不存在 '.$orderCoding);
|
|
} else {
|
|
$orderSkuList = OrderSku::where('coding', $orderCoding)->select();
|
|
$orderSkuCount = $orderSkuList->count();
|
|
$virtualCount = $orderSkuList->where('is_virtual', OrderModel::COMMON_ON)
|
|
->where('is_check', OrderModel::COMMON_ON)
|
|
->count();
|
|
Log::info('订单商品数量 '.$orderSkuCount);
|
|
Log::info('已核验商品数量 '.$virtualCount);
|
|
// 所有产品都是虚拟商品 且 都核验完成则订单设为已完成
|
|
if ($virtualCount == $orderSkuCount) {
|
|
Log::info('订单设为已完成');
|
|
if ($order['status'] != OrderModel::STATUS_ARRIVED) {
|
|
$order->save([
|
|
'status' => OrderModel::STATUS_ARRIVED,
|
|
'accepted_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function onCheckShoppingCart(int $accountId = 0)
|
|
{
|
|
Log::info('触发时间:检测并清理无效购物车数据 清理用户ID='.$accountId. 'ID=0表示清理所有人');
|
|
OrderRepository::getInstance()->checkShoppingCart($accountId);
|
|
}
|
|
}
|