GuestdeviceController.php
4.63 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
<?php
namespace app\ht\modules\device\controllers;
use Yii;
use yii\data\Pagination;
use app\ht\controllers\BaseController;
use common\models\GuestDevice as GuestDeviceModel;
use domain\device\BrandRepository;
use domain\device\DeviceCatRepository;
use domain\trade\RepairOrderRepository;
use function intval;
use function implode;
/**
* 维修方案管理
* @package app\ht\modules\catalog\controllers
*/
class GuestdeviceController extends BaseController
{
public function actionIndex()
{
// 获取父级分类
$deviceCatParentList = DeviceCatRepository::getTopParentCats();//find()->select("id,name,parent_id")->where(["parent_id" => 0])->asArray()->all();
$req = Yii::$app->request;
$pId = $req->get('deviceParentCat');
if (empty($pId)) {
$pId = intval($deviceCatParentList[0]['id']);
}
// 获取子级分类
$deviceCatChildList = DeviceCatRepository::getSubCatsByParentId($pId);//find()->select("id,name,parent_id")->where(["parent_id" => $pId])->asArray()->all();
$params = array();
$params = $this->dataList();
$params['deviceCatParentList'] = $deviceCatParentList;
$params['deviceCatChildList'] = $deviceCatChildList;
$params['catPid'] = 0;
$params['catId'] = 0;
$params['brandId'] = 0;
$params['brandList'] = BrandRepository::getAllAvailableBrands();
return $this->render("index", $params);
}
protected function dataList()
{
$req = Yii::$app->request;
$cat_pid = $req->get('deviceParentCat');//设备一级分类
$cat_id = $req->get('deviceChildCat');//设备二级分类
$brand = $req->get('brand');
$display_scope = $req->get('display_scope');
$display_scope = !empty($display_scope) ? 1 : 0;
$get = array();
$get['cat_pid'] = empty($cat_pid) ? 0 : $cat_pid;
$get['cat_id'] = empty($cat_id) ? 0 : $cat_id;
#可以构建一个解析器。。
$map = array();
// 过滤设备分类
if ($cat_pid > 0) {
if ($cat_id > 0) { // 选择了二级分类则精准查找
$map[] = array("=", "d.device_cat_id", $cat_id, "I");
} else { // 仅选择了一级分类, 则查询一级分类下所有子分类的数据
$deviceCatIdArray = array();
$childrens = DeviceCatRepository::getSubCatsByParentId($cat_pid, 'sort_order ASC', false);//find()->where(['parent_id' => $cat_pid])->orderBy('sort_order ASC')->all();
foreach ($childrens as $child) {
$deviceCatIdArray[] = $child->id;
}
// 父节点
$deviceCatIdArray[] = $cat_pid;
$deviceCatIds = '(' . implode(",", $deviceCatIdArray) . ')';
$map[] = array("in", "d.device_cat_id", $deviceCatIds, "I"); // 转换为sql: id IN (1,2,3)
}
}
if (!empty($brand)) {
$map[] = array("=", "d.brand_id", intval($brand), "I"); #I : int , S:string
$get['brand_id'] = intval($brand);
} else {
$get['brand_id'] = 0;
}
if (!empty($display_scope)) {
if ($display_scope == 1) {
$map[] = array("=", "d.model_id", 0, "I"); #I : int , S:string
} else {
//$map[] = array(">","d.model_id", 0, "I"); #I : int , S:string
}
$get['display_scope'] = $display_scope;
} else {
$get['display_scope'] = -1;
}
/**
* 分页处理
*/
$guestDeviceModel = new GuestDeviceModel();
$pageSize = $req->get("pageSize") ? (int)$req->get("pageSize") : 20;
$pages = new Pagination(['totalCount' => $guestDeviceModel->getGuestDeviceListCount($map), 'pageSize' => $pageSize]);
$guestDeviceList = $guestDeviceModel->getGuestDeviceList($pages->offset, $pages->limit, $map);
return [
'guestDeviceList' => $guestDeviceList,
'pages' => $pages,
'gets' => $get,
];
}
public function actionInfo()
{
$req = Yii::$app->request;
$id = $req->get('id');
$guestDeviceModel = new GuestDeviceModel();
$guestDevice = $guestDeviceModel->getGuestDeviceInfo(intval($id));
// 读取历史维修信息. repair_device_type=0 为游客
$repalirLogList = RepairOrderRepository::getRepairLogList(intval($id), 0);
$params = array();
$params['guestDevice'] = $guestDevice;
$params['repalirLogList'] = $repalirLogList;
return $this->render("info", $params);
}
}