BoardController.php
12 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?php
namespace app\ht\modules\home\controllers;
use yii\helpers\Url;
use app\ht\controllers\BaseController;
use common\exts\Invoice\baiwang\InvoiceApi;
use common\helpers\Distance;
use common\models\BindDeviceApply as BindDeviceApplyModel;
use common\models\Engineer as EngineerModel;
use common\models\EngineerSkills as EngineerSkillsModel;
use common\models\NoticeInfo as NoticeInfoModel;
use common\models\RepairOrder as RepairOrderModel;
use common\models\RepairOrderAppeal as RepairOrderAppealModel;
use domain\finance\models\Invoice as InvoiceModel;
use domain\engineer\EngineerStatus;
use domain\trade\RepairOrderStatus;
use domain\finance\EngineerWithdrawRepository;
use stdClass;
use function time;
use function strtotime;
use function date;
use function intval;
use function explode;
/**
* 管理->帐号管理
*/
class BoardController extends BaseController
{
/**
* 帐号管理显示页面
*/
public function actionIndex()
{
$params = array();
return $this->render("index", $params);
}
// 获取仪表盘信息
public function actionGetData()
{
$act = $this->request->get('pickOrder');
$e= new stdClass();
if (empty($act)) {
$e->engineerAuth = $this->getEngineerAuth(EngineerStatus::STATUS_REALNAME_REVIEW);
$e->engineerAvaliable = $this->getEngineerAuth();
$e->engineerSkillAuth = $this->getEngineerSkillAuth();
$e->deviceReview = $this->getDeviceReview();
$e->appeal = $this->getAppeal();
$e->errorInvoice = $this->getErrorInvoice();
$e->withdraw = $this->getWithdraw();
} else {
$queryPickOrder = RepairOrderModel::find();
$queryPickOrder->where(['status' => RepairOrderStatus::STATUS_WAIT_PICK]);
$count = $queryPickOrder->count();
if (empty($count)) {
$count = 0;
}
$e->pickOrderCount = $count;
}
return $this->renderJson($e);
}
// 获取订单数据
public function actionGetOrderData()
{
$e = new stdClass();
$e->success = true;
$end = time();
$endT = strtotime(date('Y-m-d')) + 1;
$start = $endT - 6 * 24 * 3600;
$status = array(
RepairOrderStatus::STATUS_FINISH,
RepairOrderStatus::STATUS_WAIT_RATE,
RepairOrderStatus::STATUS_USER_CANCEL,
RepairOrderStatus::STATUS_ENGINEER_CANCEL,
RepairOrderStatus::STATUS_USER_CLOSE,
RepairOrderStatus::STATUS_ENGINEER_CLOSE
);
$type = 0;
$orderListTmp = $this->getOrder($start, $end, $type, $status);
$orderList = array();
if ($orderListTmp) {
foreach ($orderListTmp as $k => $v) {
$orderList[$v['mydate']] = $v;
}
}
$dateList = $this->genDate($start);
$data =array();
foreach ($dateList as $kk => $vv) {
$myArr = array();
$myArr['date'] = $kk;
if ($type == 0) {
$myArr['pay_price'] = isset($orderList[$kk]['pay_price']) ? $orderList[$kk]['pay_price'] : 0;
$myArr['repair_price'] = isset($orderList[$kk]['repair_price']) ? $orderList[$kk]['repair_price'] : 0;
}
$data[] = $myArr;
}
$e->data = $data;
return $this->renderJson($e);
}
// 热力图
public function actionGetHeatData()
{
$e= new stdClass();
$e->success = true;
$north_east= $this->request->get('north_east');
$south_west = $this->request->get('south_west');
$zoom = $this->request->get('zoom');
$distance = 25000; //25公里内的点
$earthRadius = Distance::EARTH_RADIUS;
$table1 = 'address';
$end = time();
$endT =strtotime(date('Y-m-d')) + 1;
$start = $endT - 6 * 24 * 3600;
$status =array(
RepairOrderStatus::STATUS_FINISH,
RepairOrderStatus::STATUS_WAIT_RATE,
RepairOrderStatus::STATUS_USER_CANCEL,
RepairOrderStatus::STATUS_ENGINEER_CANCEL,
RepairOrderStatus::STATUS_USER_CLOSE,
RepairOrderStatus::STATUS_ENGINEER_CLOSE
);
/*
$vRadian= "$earthRadius * acos( cos( radians('$lat') ) * cos( radians( $table1.latitude ) ) * cos( radians( $table1.longitude ) - radians('$lng') ) +
sin( radians('$lat') ) * sin( radians( $table1.latitude ) ) )";
*/
$repairOrderModel = RepairOrderModel::find();
$repairOrderModel->leftJoin("address","address.id = repair_order.address_id");
$repairOrderModel->select(["concat(address.latitude,'_',address.longitude) as latlng", "count(*) as mycount"]);
$repairOrderModel->where(['repair_order.status' => $status]);
$repairOrderModel->andFilterWhere(['>', 'repair_order.created_at', $start]);
$repairOrderModel->andFilterWhere(['<', 'repair_order.created_at', $end]);
$repairOrderModel->andFilterWhere(['<', "address.latitude", $north_east[0]]);
$repairOrderModel->andFilterWhere(['>', "address.latitude", $south_west[0]]);
$repairOrderModel->andFilterWhere(['<', "address.longitude", $north_east[1]]);
$repairOrderModel->andFilterWhere(['>', "address.longitude", $south_west[1]]);
$repairOrderModel->groupBy('latlng');
$repairOrderModel->asArray();
$olist = $repairOrderModel->all();
$item = array('max' => 100, 'data' => array());
if ($olist) {
foreach ($olist as $k => $v) {
$latlngTemp = explode('_', $v['latlng']);
$item['data'][] = array('lat' => $latlngTemp[0], 'lng' => $latlngTemp[1], 'count' => $v['mycount']);
}
}
$e->item =$item;
return $this->renderJson($e);
}
// 获取通知
public function actionGetNotice()
{
$act = $this->request->post('act');
if ($act == 'remove') {
$id = $this->request->post('id');
return $this->removeNotice($id);
}
$e = new stdClass();
$e->success = false;
$e->count = 0;
$noticeInfoModel = NoticeInfoModel::find();
$noticeInfoModel->where(['status' => NoticeInfoModel::STATUS_UNREAD]);
$noticeInfoModel->asArray();
$count = $noticeInfoModel->count();
$noticeInfoModel->limit(6);
$nList = $noticeInfoModel->all();
$e->msgList = array();
if ($nList) {
$tt = time();
foreach ($nList as $k => $v) {
$v['created_date_time'] = date('Y-m-d H:i:s', $v['created_at']);
$v['created_time'] = $this->getTime($v['created_at'], $tt);
$nList[$k] = $v;
}
$e->count = $count;
$e->msgList = $nList;
$e->success = true;
}
return $this->renderJson($e);
}
// 删除
protected function removeNotice($id)
{
$e= new stdClass();
$e->success = false;
$e->error = 'Fail';
$noticeInfo = NoticeInfoModel::findOne($id);
if ($noticeInfo && $noticeInfo->delete()) {
$e->success = true;
}
return $this->renderJson($e);
}
// 判断时间
protected function getTime($t, $curT)
{
$timeDistance = $curT - $t;
if ($timeDistance < 60) {
$str = '刚刚';
} elseif ($timeDistance >= 60 && $timeDistance < 3600) {
$str = intval($timeDistance / 60) . '分钟前';
} elseif ($timeDistance >= 3600 && $timeDistance < 3600 * 24) {
$str = intval($timeDistance /(60 * 60)) . '小时前';
} else {
$str = intval($timeDistance /(60 * 60 * 24)) . '天前';
}
return $str;
}
// 组装日期列表
private function genDate($start)
{
$dataArr = array();
$days = 7;
for ($i = 0; $i < $days; $i++) {
$dataArr[date('Y-m-d', $start)] = array();
$start = $start + (3600 * 24);
}
return $dataArr;
}
// 贴码设备
protected function getDeviceReview()
{
$bindDeviceModel = BindDeviceApplyModel::find();
$wh = array('status' => BindDeviceApplyModel::STATUS_APPLYING);
$bindDeviceModel->where($wh);
$count = $bindDeviceModel->count();
$url = Url::toRoute('/device/userdevice/apply?status=0');
$returnArr = array(0, $url);
if ($count > 0) {
$returnArr = array($count, $url);
}
return $returnArr;
}
// 质保申请
protected function getAppeal()
{
$repairOrderAppealModel = RepairOrderAppealModel::find();
$wh = array('status' => RepairOrderAppealModel::STATUS_APPEALING);
$repairOrderAppealModel->where($wh);
$count = $repairOrderAppealModel->count();
$url = Url::toRoute('/trade/appeal/index');
$returnArr = array(0, $url);
if ($count > 0) {
$returnArr = array($count, $url);
}
return $returnArr;
}
// 工程师认证
protected function getEngineerAuth($status = EngineerStatus::STATUS_SKILL_AUTH)
{
$engineerModel = EngineerModel::find();
$wh = array('status' => $status, 'is_fake_id' => 0);
$engineerModel->where($wh);
$count = $engineerModel->count();
$url = Url::toRoute('/engineer/engineer/index?status=2');
$returnArr = array(0, $url);
if ($count > 0) {
$returnArr = array($count, $url);
}
return $returnArr;
}
// 技能审核,这里不能以人为单位,应该以技能为单位,一个人可以多项技能认证
protected function getEngineerSkillAuth()
{
$engineerSkillModel = EngineerSkillsModel::find();
$wh = array('engineer_skills.status' => EngineerSkillsModel::STATUS_REVIEWING);
$engineerSkillModel->select(["engineer_skills.engineer_id"]);
$engineerSkillModel->distinct();
$engineerSkillModel->where($wh);
$count = $engineerSkillModel->count();
$url = Url::toRoute('/engineer/engineer/index?status=6');
$returnArr = array(0, $url);
if ($count > 0) {
$returnArr = array($count, $url);
}
return $returnArr;
}
// 提现审核
protected function getWithdraw()
{
$count = EngineerWithdrawRepository::getReviewingWithdrawCount();
$url = Url::toRoute('/engineer/withdraw/index');
$returnArr = array(0, $url);
if ($count > 0) {
$returnArr = array($count, $url);
}
return $returnArr;
}
// 发票出错
protected function getErrorInvoice($kplx = InvoiceApi::KPLX_NORMAL)
{
$invoiceModel = InvoiceModel::find();
$wh = array('status' => InvoiceModel::STATUS_ERROR, 'kplx' => $kplx);
$invoiceModel->where($wh);
$count = $invoiceModel->count();
$url = Url::toRoute(['/invoice/invoice/index', 'invoice_status' => InvoiceModel::STATUS_ERROR]);
$returnArr = array(0, $url);
if ($count > 0) {
$returnArr = array($count, $url);
}
return $returnArr;
}
/* 订单数据 */
//获取订单数量(当日和七天,已支付,未支付)
protected function getOrder($start, $end, $selectType = 0, $status = 0)
{
$orderModel = RepairOrderModel::find();
if ($status != 0) {
$orderModel->where(['status' => $status]);
}
if ($selectType == 0) {
$orderModel->select(['FROM_UNIXTIME(`created_at`, "%Y-%m-%d") as mydate','sum(pay_price) as pay_price','sum(repair_price) as repair_price']);
} else {
$orderModel->select(['FROM_UNIXTIME(`created_at`, "%Y-%m-%d") as mydate','count(*) as cc']);
}
$orderModel->andFilterWhere(['>', 'created_at', $start]);
$orderModel->andFilterWhere(['<', 'created_at', $end]);
$orderModel->groupBy('mydate');
$orderModel->asArray();
$oList = $orderModel->all();
return $oList;
}
}