quanwei
2025-12-10 898043fc97d2ab8b793fd317a049b874ed207c6d
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
<?php
 
namespace app\supplier\service;
 
use app\supplier\model\order\OrderRefund;
use app\supplier\model\product\Product;
use app\supplier\model\order\Order;
use app\supplier\model\supplier\Supplier as SupplierModel;
use app\supplier\model\user\Favorite as FavoriteModel;
/**
 * 商城模型
 */
class ShopService
{
    // 商品模型
    private $ProductModel;
    // 订单模型
    private $OrderModel;
    // 订单退款模型
    private $OrderRefund;
    // 收藏模型
    private $FavoriteModel;
    // 商户id
    private $shop_supplier_id;
 
    /**
     * 构造方法
     */
    public function __construct($shop_supplier_id)
    {
        /* 初始化模型 */
        $this->ProductModel = new Product();
        $this->OrderModel = new Order();
        $this->OrderRefund = new OrderRefund();
        $this->FavoriteModel = new FavoriteModel();
        $this->shop_supplier_id = $shop_supplier_id;
    }
 
    /**
     * 后台首页数据
     */
    public function getHomeData()
    {
        $today = date('Y-m-d');
        $yesterday = date('Y-m-d', strtotime('-1 day'));
        $supplier = SupplierModel::detail($this->shop_supplier_id);
        $data = [
            'top_data' => [
                // 商品总量
                'product_total' => $this->getProductTotal(),
                // 订单总量
                'order_total' => $this->getOrderTotal(),
                // 订单销售额
                'total_money' => $this->getOrderTotalMoney($today),
                // 店铺关注人数
                'fav_count' => $supplier['fav_count'],
                // 配送评分
                'express_score' => $supplier['express_score'],
                // 服务评分
                'server_score' => $supplier['server_score'],
                // 描述评分
                'describe_score' => $supplier['describe_score'],
            ],
            'order_data' => [
                // 销售额(元)
                'order_total_price' => [
                    'tday' => $this->getOrderTotalPrice($today),
                    'ytd' => $this->getOrderTotalPrice($yesterday)
                ],
                // 支付订单数
                'order_total' => [
                    'tday' => $this->getOrderTotal($today),
                    'ytd' => $this->getOrderTotal($yesterday)
                ],
                // 下单用户数
                'order_user_total' => [
                    'tday' => $this->getPayOrderUserTotal($today),
                    'ytd' => $this->getPayOrderUserTotal($yesterday)
                ],
                // 店铺关注人数
                'fav_user_total' => [
                    'tday' => $this->getFavUserTotal($today),
                    'ytd' => $this->getFavUserTotal($yesterday)
                ]
            ],
            'wait_data' => [
                //订单
                'order' => [
                    'delivery' => $this->getReviewOrderTotal(),
                    'refund' => $this->getRefundOrderTotal(),
                ],
                //商品
                'product' => [
                    'audit' => $this->getProductAuditTotal(),
                ],
                //库存
                'stock' => [
                    'product' => $this->getProductStockTotal(),
                ],
            ]
        ];
        return $data;
    }
 
    /**
     * 获取商品总量
     */
    private function getProductTotal()
    {
        return number_format($this->ProductModel->getProductTotal(['shop_supplier_id'=> $this->shop_supplier_id]));
    }
 
    /**
     * 获取商品总量
     */
    private function getProductAuditTotal()
    {
        return number_format($this->ProductModel->getProductTotal([
            'shop_supplier_id'=> $this->shop_supplier_id,
            'product_status' => 40
        ]));
    }
    /**
     * 获取商品库存告急总量
     */
    private function getProductStockTotal()
    {
        return number_format($this->ProductModel->getProductStockTotal($this->shop_supplier_id));
    }
 
    /**
     * 获取订单总量
     */
    private function getOrderTotal($day = null)
    {
        return number_format($this->OrderModel->getOrderData($day, null, 'order_total', $this->shop_supplier_id));
    }
 
    /**
     * 获取待处理订单总量
     */
    private function getReviewOrderTotal()
    {
        return number_format($this->OrderModel->getReviewOrderTotal($this->shop_supplier_id));
    }
 
    /**
     * 获取售后订单总量
     */
    private function getRefundOrderTotal()
    {
        return number_format($this->OrderRefund->getRefundOrderTotal($this->shop_supplier_id));
    }
 
    /**
     * 获取某天的总销售额
     */
    private function getOrderTotalPrice($day)
    {
        return sprintf('%.2f', $this->OrderModel->getOrderTotalPrice($day, null, $this->shop_supplier_id));
    }
 
    /**
     * 店铺总销售额
     */
    private function getOrderTotalMoney($day)
    {
        return sprintf('%.2f', $this->OrderModel->getOrderTotalPrice(null, $day, $this->shop_supplier_id));
    }
 
    /**
     * 获取某天的下单用户数
     */
    private function getPayOrderUserTotal($day)
    {
        return number_format($this->OrderModel->getPayOrderUserTotal($day, $this->shop_supplier_id));
    }
 
    /**
     * 获取某天的关注用户数
     */
    private function getFavUserTotal($day)
    {
        return number_format($this->FavoriteModel->getUserTotal($day, $this->shop_supplier_id));
    }
}