最新服务器上的版本,以后用这个
zhangmeng
2023-04-19 e3f5aa12f58d986098a9de0f5cb38060e403036d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
 * Created by PhpStorm.
 * User: 风哀伤
 * Date: 2019/2/14
 * Time: 16:06
 * @copyright: ©2019 浙江禾匠信息科技
 * @link: http://www.zjhejiang.com
 */
 
namespace app\handlers;
 
 
use app\events\OrderEvent;
use app\forms\common\order\CommonOrder;
use app\forms\common\prints\Exceptions\PrintException;
use app\jobs\OrderSalesJob;
use app\jobs\PrintJob;
use app\models\CoreQueueData;
use app\models\Order;
 
class OrderConfirmedHandler extends HandlerBase
{
    public function register()
    {
        \Yii::$app->on(Order::EVENT_CONFIRMED, function ($event) {
            /** @var OrderEvent $event */
            \Yii::$app->setMchId($event->order->mch_id);
            $orderAutoSaleTime = \Yii::$app->mall->getMallSettingOne('after_sale_time');
            if (is_numeric($orderAutoSaleTime) && $orderAutoSaleTime >= 0) {
                // 订单过售后
                $id = \Yii::$app->queue->delay($orderAutoSaleTime * 86400)->push(new OrderSalesJob([
                    'orderId' => $event->order->id
                ]));
                CoreQueueData::add($id, $event->order->token);
                $autoSalesTime = strtotime($event->order->confirm_time) + $orderAutoSaleTime * 86400;
                $event->order->auto_sales_time = mysql_timestamp($autoSalesTime);
                $event->order->save();
            }
            $commonOrder = CommonOrder::getCommonOrder($event->order->sign);
            $orderConfig = $commonOrder->getOrderConfig();
            try {
                if ($orderConfig->is_print != 1) {
                    throw new PrintException($event->order->sign . '未开启小票打印');
                }
                $job = new PrintJob();
                $job->mall = \Yii::$app->mall;
                $job->order = $event->order;
                $job->orderType = 'confirm';
                \Yii::$app->queue->delay(0)->push($job);
            } catch (PrintException $e) {
                \Yii::error("小票打印机打印出错:" . $e->getMessage());
            }
        });
    }
}