quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
 
namespace app\operations\service;
 
use app\operations\model\order\OrderRefund;
use app\operations\model\product\Product;
use app\operations\model\order\Order;
use app\operations\model\user\User;
use app\operations\model\product\Comment;
use app\operations\model\plus\agent\Cash as AgentCashModel;
use app\operations\model\supplier\Supplier as SupplierModel;
use app\operations\model\plus\agent\Apply as AgentApplyModel;
use app\operations\model\supplier\Apply as SupplierApplyModel;
use app\operations\model\supplier\Cash as SupplierCashModel;
use app\operations\model\supplier\DepositRefund as DepositRefundModel;
use app\operations\model\plus\point\Product as PointProductModel;
use app\operations\model\plus\bargain\Product as BargainProductModel;
use app\operations\model\plus\assemble\Product as AssembleProductModel;
use app\operations\model\plus\seckill\Product as SeckillProductModel;
use app\operations\model\supplier\ServiceApply as ServiceApplyModel;
/**
 * 区域代理服务
 */
class ShopService
{
    // 商品模型
    private $ProductModel;
    // 订单模型
    private $OrderModel;
    // 用户模型
    private $UserModel;
    // 订单退款模型
    private $OrderRefund;
 
    /**
     * 构造方法
     */
    public function __construct()
    {
        /* 初始化模型 */
        $this->ProductModel = new Product();
        $this->OrderModel = new Order();
        $this->UserModel = new User();
        $this->OrderRefund = new OrderRefund();
    }
 
    /**
     * 后台首页数据
     */
    public function getHomeData()
    {
        $today = date('Y-m-d');
        $yesterday = date('Y-m-d', strtotime('-1 day'));
        // 最近七天日期
        $lately7days = $this->getLately7days();
        $data = [
            'top_data' => [
                // 商品总量
                'product_total' => $this->getProductTotal(),
                // 用户总量
                'user_total' => $this->getUserTotal(),
                // 订单总量
                'order_total' => $this->getOrderTotal(),
                // 店铺总量
                'supplier_total' => $this->getSupplierTotal()
            ],
            'wait_data' => [
                //订单
                'order' => [
                    'disposal' => $this->getReviewOrderTotal(),
                    'refund' => $this->getRefundOrderTotal(),
                    'plate' => $this->getPlateOrderTotal(),
                ],
                //分销商
                'agent' => [
                    'cash_apply' => $this->getAgentApplyTotal(10),
                    'apply' => AgentApplyModel::getApplyCount(),
                    'cash_money' => $this->getAgentApplyTotal(20),
                ],
                //供应商
                'supplier' => [
                    'apply' => SupplierApplyModel::getApplyCount(),
                    'cash_apply' => SupplierCashModel::getApplyCount(10),
                    'cash_money' => SupplierCashModel::getApplyCount(20),
                    'refund' => DepositRefundModel::getRefundCount(),
                    'service' => ServiceApplyModel::getApplyCount(),
                ],
                //活动
                'activity' => [
                    'point' => PointProductModel::getApplyCount(),
                    'bargain' => BargainProductModel::getApplyCount(),
                    'assemble' => AssembleProductModel::getApplyCount(),
                    'seckill' => SeckillProductModel::getApplyCount(),
                ],
                // 待审核
                'audit' => [
                    'comment' => $this->getReviewCommentTotal(),
                    'product' => $this->ProductModel->getProductTotal([
                        'product_status' => '40'
                    ]),
                ]
            ],
            'today_data' => [
                // 销售额(元)
                'order_total_price' => [
                    'tday' => $this->getOrderTotalPrice($today),
                    'ytd' => $this->getOrderTotalPrice($yesterday)
                ],
                // 支付订单数
                'order_total' => [
                    'tday' => $this->getOrderTotal($today),
                    'ytd' => $this->getOrderTotal($yesterday)
                ],
                // 新增用户数
                'new_user_total' => [
                    'tday' => $this->getUserTotal($today),
                    'ytd' => $this->getUserTotal($yesterday)
                ],
                // 新供应商数
                'new_supplier_total' => [
                    'tday' => SupplierModel::getSupplierTotalByDay($today),
                    'ytd' => SupplierModel::getSupplierTotalByDay($yesterday)
                ],
                // 申请供应商数
                'apply_supplier_total' => [
                    'tday' => SupplierApplyModel::getApplyCountByDay($today),
                    'ytd' => SupplierApplyModel::getApplyCountByDay($yesterday)
                ]
            ],
        ];
        return $data;
    }
 
    /**
     * 最近七天日期
     */
    private function getLately7days()
    {
        // 获取当前周几
        $date = [];
        for ($i = 0; $i < 7; $i++) {
            $date[] = date('Y-m-d', strtotime('-' . $i . ' days'));
        }
        return array_reverse($date);
    }
 
    /**
     * 获取商品总量
     */
    private function getProductTotal()
    {
        return number_format($this->ProductModel->getProductTotal());
    }
 
    /**
     * 获取待审核提现总数量
     */
    private function getAgentApplyTotal($apply_status)
    {
        $model = new AgentCashModel;
        return number_format($model->getAgentApplyTotal($apply_status));
    }
 
    /**
     * 获取用户总量
     */
    private function getUserTotal($day = null)
    {
        return number_format($this->UserModel->getUserTotal($day));
    }
 
    /**
     * 获取订单总量
     */
    private function getOrderTotal($day = null)
    {
        return number_format($this->OrderModel->getOrderData($day, null, 'order_total'));
    }
 
    /**
     * 获取待处理订单总量
     */
    private function getReviewOrderTotal()
    {
        return number_format($this->OrderModel->getReviewOrderTotal());
    }
 
    /**
     * 获取售后订单总量
     */
    private function getRefundOrderTotal()
    {
        return number_format($this->OrderRefund->getRefundOrderTotal());
    }
 
    /**
     * 获取平台售后订单总量
     */
    private function getPlateOrderTotal()
    {
        return number_format($this->OrderRefund->getPlateOrderTotal());
    }
 
    /**
     * 获取供应商总量
     */
    private function getSupplierTotal()
    {
        $model = new SupplierModel;
        return number_format($model->getSupplierTotal());
    }
    /**
     * 获取待审核评价总量
     */
    private function getReviewCommentTotal()
    {
        $model = new Comment;
        return number_format($model->getReviewCommentTotal());
    }
 
    /**
     * 获取某天的总销售额
     */
    private function getOrderTotalPrice($day)
    {
        return sprintf('%.2f', $this->OrderModel->getOrderTotalPrice($day));
    }
}