huangsijun
2025-09-22 a78c011de350b188afb03beb2f26a73f35f71986
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
 
namespace app\supplier\controller\order;
 
use app\common\enum\settings\DeliveryTypeEnum;
use app\supplier\model\store\Store as StoreModel;
use app\supplier\controller\Controller;
use app\supplier\model\order\Order as OrderModel;
use app\common\model\settings\Express as ExpressModel;
use app\supplier\model\store\Clerk as ClerkModel;
use app\common\service\order\OrderPrinterService;
use app\common\enum\order\OrderSourceEnum;
 
/**
 * 订单控制器
 */
class Order extends Controller
{
    /**
     * 订单列表
     */
    public function index($dataType = 'all')
    {
        // 订单列表
        $model = new OrderModel();
        $list = $model->getList($dataType, $this->postData(), $this->getSupplierId());
        $order_count = [
            'order_count' => [
                'payment' => $model->getCount('payment', $this->getSupplierId()),
                'delivery' => $model->getCount('delivery', $this->getSupplierId()),
                'received' => $model->getCount('received', $this->getSupplierId()),
                'cancel' => $model->getCount('cancel', $this->getSupplierId()),
            ],];
        // 自提门店列表
        $shop_list = StoreModel::getAllList($this->getSupplierId());
        $ex_style = DeliveryTypeEnum::data();
        $orderSource = OrderSourceEnum::data();
        return $this->renderSuccess('', compact('list', 'order_count', 'shop_list', 'ex_style', 'orderSource'));
    }
 
    /**
     *
     */
   /* public function test()
    {
        $model = new OrderModel();
        // 测试小票打印
        $order = $model::detail(2074);
        (new OrderPrinterService)->printTicket($order);
    }*/
 
 
 
    /**
     * 订单详情
     */
    public function detail($order_id)
    {
        // 订单详情
        $detail = OrderModel::detail($order_id);
        if (isset($detail['pay_time']) && $detail['pay_time'] != '') {
            $detail['pay_time'] = date('Y-m-d H:i:s', $detail['pay_time']);
        }
        if (isset($detail['delivery_time']) && $detail['delivery_time'] != '') {
            $detail['delivery_time'] = date('Y-m-d H:i:s', $detail['delivery_time']);
        }
        if ($detail['order_source'] == 70 && isset($detail['advance'])) {
            $detail['pay_price'] = round($detail['pay_price'] + $detail['advance']['pay_price'], 2);
            $detail['order_price'] = round($detail['order_price'] + $detail['advance']['pay_price'], 2);
        }
        // 物流公司列表
        $model = new ExpressModel();
        $expressList = $model->getAll();
        // 门店店员列表
        $shopClerkList = (new ClerkModel)->getClerk($detail['extract_store_id']);
        
        // 配送门店信息
        $delivery_storeinfo=array();
        if (isset($detail['delivery_store']) && $detail['delivery_store'] != '') {
            $delivery_storeinfo = StoreModel::detail($detail['delivery_store']);
        }
        // 虚拟商品可核销门店列表 by lyzflash
        $verifyShopList = !empty($detail['verify']['verify_store_ids']) ? (new StoreModel)->getListByIds($detail['verify']['verify_store_ids'], $detail['shop_supplier_id']) : (new StoreModel)->getCheckList($detail['shop_supplier_id']);
        return $this->renderSuccess('', compact('detail', 'expressList', 'shopClerkList','delivery_storeinfo', 'verifyShopList'));
    }
 
    /**
     * 确认发货
     */
    public function delivery($order_id)
    {
        $model = OrderModel::detail($order_id);
        if ($model->delivery($this->postData('param'))) {
            // 微信发货
            $model->wxDelivery();
            return $this->renderSuccess('发货成功');
        }
        return $this->renderError('发货失败');
    }
 
    /**
     * 修改订单价格
     */
    public function updatePrice($order_id)
    {
        $model = OrderModel::detail($order_id);
        if ($model->updatePrice($this->postData('order'))) {
            return $this->renderSuccess('修改成功');
        }
        return $this->renderError($model->getError() ?: '修改失败');
    }
 
    /**
     * 获取物流信息
     */
    public function express($order_id)
    {
        // 订单信息
        $order = OrderModel::detail($order_id);
        if (!$order['express_no']) {
            return $this->renderError('没有物流信息');
        }
        // 获取物流信息
        $model = $order['express'];
        $express = $model->dynamic($model['express_name'], $model['express_code'], $order['express_no']);
        if ($express === false) {
            return $this->renderError($model->getError());
        }
        return $this->renderSuccess('', compact('express'));
    }
 
    /**
     * 订单改地址
     */
    public function updateAddress($order_id)
    {
        // 订单信息
        $order = OrderModel::detail($order_id);
        if (($order['delivery_type']['value'] == 10 || $order['delivery_type']['value'] == 40 ) && $order['delivery_status']['value'] == 20) {
            return $this->renderError('订单已发货不允许修改');
        }
        // 获取物流信息
        $model = $order['address'];
        if (!$model->updateAddress($this->postData())) {
            return $this->renderError($model->getError() ?: '修改失败');
        }
        return $this->renderSuccess('修改成功');
    }
 
    /**
     * 取消订单(后台主动取消)
     */
    public function orderCancel($order_no)
    {
        // 订单信息
        $model = OrderModel::detail(['order_no' => $order_no]);
        if ($model->orderCancel($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 虚拟商品发货
     */
    public function virtual($order_id)
    {
        // 订单信息
        $model = OrderModel::detail($order_id);
        if ($model->virtual($this->postData())) {
            return $this->renderSuccess('操作成功');
        }
        return $this->renderError($model->getError() ?: '操作失败');
    }
 
    /**
     * 微信小程序发货
     */
    public function wxDelivery($order_id)
    {
        $model = OrderModel::detail($order_id);
        if ($model->wxDelivery()) {
            return $this->renderSuccess('发货成功');
        }
        return $this->renderError($model->getError() ?: '发货失败');
    }
}