// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\console\task; use app\common\model\Order as OrderModel; use app\console\service\Order as OrderService; use app\console\service\OrderGood as OrderGoodService; use app\console\model\Setting as SettingModel; /** * 定时任务:商城订单 * Class Order * @package app\console\task */ class Order extends Task { // 当前任务唯一标识 private $taskKey = 'Order'; // 任务执行间隔时长 (单位:秒) protected $taskExpire = 60 * 30; // 当前商城ID private $storeId; /** * 任务处理 * @param array $param * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function handle(array $param) { if(env('SERVE_ENV')=='test'){ $this->taskExpire = 30; } ['storeId' => $this->storeId] = $param; $this->setInterval($this->storeId, $this->taskKey, $this->taskExpire, function () { echo $this->taskKey . PHP_EOL; // 未支付订单自动关闭--待支付订单定时频率太快,单独拿出来处理-2021年11月2日 11:58:18 // 已发货订单自动确认收货 $this->receiveEvent(); // 确认收货订单自动评价 $this->commentEvent(); }); } /** * 自动确认收货订单的天数 * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function receiveEvent() { // 取消n天以前的的未付款订单 // $receiveDays = (int)$this->getRefundSetting()['receive_days']; // // 执行自动确认收货 // if ($receiveDays > 0) { $service = new OrderGoodService; $service->receiveEvent($this->storeId, 0); // } } /** * 已完成订单自动结算 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function settledEvent() { // 取消n天以前的的未付款订单 $refundDays = (int)$this->getRefundSetting()['refund_days']; // 执行自动确认收货 if ($refundDays > 0) { $service = new OrderService; $service->settledEvent($this->storeId, $refundDays); } } /** * 已完成订单自动评价 * 确认收货的订单,15天内显示“去评价”按钮;超过15天用户未评价则默认五星好评,默认评价语是“此用户没有填写评价。” */ private function commentEvent() { // 自动评价n天以前的的已确认收货的订单商品 $commentDays = OrderModel::getCommentDeadline(); // 执行自动评价 if ($commentDays > 0) { $service = new OrderService; $service->commentEvent($this->storeId, $commentDays); } } /** * 获取商城交易设置 * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ private function getRefundSetting() { return SettingModel::getItem('refund', $this->storeId); } }