• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / logistics / 10654302660

01 Sep 2024 01:03PM UTC coverage: 35.354% (-1.2%) from 36.522%
10654302660

push

github

semantic-release-bot
chore(release): publish

See CHANGELOG.md for more details.

24 of 103 branches covered (23.3%)

210 of 594 relevant lines covered (35.35%)

2.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/LogisticsPlugin.php
1
<?php
2

3
namespace Miaoxing\Logistics;
4

5
use Miaoxing\Address\Service\Address;
6
use Miaoxing\Admin\Service\AdminMenu;
7
use Miaoxing\Logistics\Service\Logistics;
8
use Miaoxing\Order\Service\Order;
9
use Miaoxing\Product\Service\Product;
10
use Wei\RetTrait;
11

12
class LogisticsPlugin extends \Miaoxing\Plugin\BasePlugin
13
{
14
    use RetTrait;
15

16
    protected $name = '物流管理,包括运费模板等';
17

18
    public function onAdminMenuGetMenus(AdminMenu $menu)
19
    {
20
        $setting = $menu->child('setting');
×
21

22
        $tpls = $setting->addChild()->setLabel('运费模板管理')->setUrl('admin/shipping-tpls')->setSort(200);
×
23
        $tpls->addChild()->setUrl('admin/shipping-tpls/new')->setLabel('添加');
×
24
        $tpls->addChild()->setUrl('admin/shipping-tpls/[id]/edit')->setLabel('编辑');
×
25

26
        $addresses = $setting->addChild()->setLabel('地址管理')->setUrl('admin/logistics-addresses')->setSort(100);
×
27
        $addresses->addChild()->setUrl('admin/logistics-addresses/new')->setLabel('添加');
×
28
        $addresses->addChild()->setUrl('admin/logistics-addresses/[id]/edit')->setLabel('编辑');
×
29
    }
30

31
    /**
32
     * 商品详情页,展示配送方式,运费等
33
     *
34
     * @param Product $product
35
     * @phpstan-ignore-next-line
36
     */
37
    public function onProductsShowItemMin(Product $product)
38
    {
39
        if ($product['isVirtual'] || $product['config']['selfPickUp']) {
×
40
            return;
×
41
        }
42
        if (!$product['config']['requireAddress']) {
×
43
            return;
×
44
        }
45

46
        $shippingTpl = $product->getShippingTpl();
×
47

48
        $config = $shippingTpl->getShippingConfig();
×
49

50
        $city = $config['city'];
×
51
        $services = $config['services'];
×
52
        $defaultServices = isset($services[1]) ? $services[1] : $services[0];
×
53

54
        $this->view->display('@logistics/shippingTpls/productsShowItem.php', get_defined_vars());
×
55
    }
56

57
    /**
58
     * @param Order $order
59
     * @param Address|null $address
60
     * @phpstan-ignore-next-line
61
     */
62
    public function onPostOrderCartRender(Order $order, ?Address $address = null)
63
    {
64
        if (!$order->isRequireAddress()) {
×
65
            return;
×
66
        }
67

68
        $this->view->display('@logistics/shippingTpls/postOrderCartRender.php', [
×
69
            'addressId' => $address ? $address['id'] : 0,
×
70
        ]);
×
71
    }
72

73
    /**
74
     * 根据指定的物流服务,计算运费
75
     * @param mixed $data
76
     * @phpstan-ignore-next-line
77
     */
78
    public function onPreOrderCreate(Order $order, ?Address $address = null, $data = [], array $options = [])
79
    {
80
        // 自提自动设置
81
        if ($order->getCarts()->isSelfPickUp()) {
×
82
            $order['userLogisticsId'] = Logistics::ID_SELF_PICKUP;
×
83
            return;
×
84
        }
85

86
        if (isset($options['requireAddress']) && !$options['requireAddress']) {
×
87
            return;
×
88
        }
89
        if (!$order->isRequireAddress()) {
×
90
            return;
×
91
        }
92

93
        if (!$address) {
×
94
            return $this->err('请选择收货地址', -9);
×
95
        }
96

97
        if (!$data['userLogisticsId']) {
×
98
            return $this->err('请选择配送方式', -10);
×
99
        }
100

101
        $order['userLogisticsId'] = $data['userLogisticsId'];
×
102
        $carts = $order->getCarts();
×
103
        $services = wei()->shippingTpl->getShippingServices($carts, $address);
×
104

105
        $useService = false;
×
106
        foreach ($services as $service) {
×
107
            if ($service['id'] == $data['userLogisticsId']) {
×
108
                $useService = $service;
×
109
                break;
×
110
            }
111
        }
112
        if (!$useService) {
×
113
            return $this->err('配送方式不存在,请重新选择', -8);
×
114
        }
115

116
        $order->setAmountRule('address', ['name' => '运费', 'shippingFee' => $useService['fee']]);
×
117
    }
118

119
    /**
120
     * 订单导出事件
121
     *
122
     * @param array $order
123
     * @param array $cart
124
     * @param array $rowData
125
     * @param array $outputData
126
     */
127
    public function onRenderOrder(array $order, array $cart, array &$rowData, array &$outputData)
128
    {
129
        if (!in_array('物流', $outputData[0], true)) {
×
130
            $outputData[0][] = '物流';
×
131
        }
132

133
        if (!in_array('用户指定物流', $outputData[0], true)) {
×
134
            $outputData[0][] = '用户指定物流';
×
135
        }
136

137
        if (!in_array('运单号', $outputData[0], true)) {
×
138
            $outputData[0][] = '运单号';
×
139
        }
140

141
        $rowData[] = $order['logisticsName'];
×
142
        $rowData[] = $order['userLogisticsName'];
×
143
        $rowData[] = '\'' . $order['logisticsNo'];
×
144
    }
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc