Commit b60f5eda40171bf4a56dd665b456cb8a3f2ecbc4
1 parent
e5a695f1
Exists in
master
1. 删除部分冗余代码
2. 厂商账号登录可以进入操作, 部分权限文件误删除了
Showing
13 changed files
with
653 additions
and
314 deletions
Show diff stats
app-ht/config/params.php
app-ht/modules/datas/config/perm.php
app-ht/modules/device/controllers/DeviceController.php
@@ -329,7 +329,17 @@ class DeviceController extends BaseController | @@ -329,7 +329,17 @@ class DeviceController extends BaseController | ||
329 | $type = $req->post('type'); | 329 | $type = $req->post('type'); |
330 | $keyword = $req->post('query'); | 330 | $keyword = $req->post('query'); |
331 | $e = new stdClass(); | 331 | $e = new stdClass(); |
332 | - $list = CreateBatchRepository::getSerialNoComponent($type, $keyword); | 332 | + $where = []; |
333 | + if ('manufacture' == $type) { | ||
334 | + $user = Yii::$app->user->identity; | ||
335 | + if (isset($user->is_manufacture) && $user->is_manufacture == 1) { | ||
336 | + $where = 'sys_user_id = '.$user->id; | ||
337 | + | ||
338 | + } else { | ||
339 | + $where = 'id >0'; | ||
340 | + } | ||
341 | + } | ||
342 | + $list = CreateBatchRepository::getSerialNoComponent($type, $where); | ||
333 | $e->list = $list; | 343 | $e->list = $list; |
334 | 344 | ||
335 | return $this->renderJson($e); | 345 | return $this->renderJson($e); |
app-ht/modules/home/controllers/BoardController.php
@@ -37,179 +37,6 @@ class BoardController extends BaseController | @@ -37,179 +37,6 @@ class BoardController extends BaseController | ||
37 | return $this->render("index", $params); | 37 | return $this->render("index", $params); |
38 | } | 38 | } |
39 | 39 | ||
40 | - // 获取仪表盘信息 | ||
41 | - public function actionGetData() | ||
42 | - { | ||
43 | - $act = $this->request->get('pickOrder'); | ||
44 | - $e= new stdClass(); | ||
45 | - | ||
46 | - if (empty($act)) { | ||
47 | - $e->engineerAuth = $this->getEngineerAuth(EngineerStatus::STATUS_REALNAME_REVIEW); | ||
48 | - $e->engineerAvaliable = $this->getEngineerAuth(); | ||
49 | - $e->engineerSkillAuth = $this->getEngineerSkillAuth(); | ||
50 | - $e->deviceReview = $this->getDeviceReview(); | ||
51 | - $e->appeal = $this->getAppeal(); | ||
52 | - $e->errorInvoice = $this->getErrorInvoice(); | ||
53 | - $e->withdraw = $this->getWithdraw(); | ||
54 | - } else { | ||
55 | - $queryPickOrder = RepairOrderModel::find(); | ||
56 | - $queryPickOrder->where(['status' => RepairOrderStatus::STATUS_WAIT_PICK]); | ||
57 | - $count = $queryPickOrder->count(); | ||
58 | - if (empty($count)) { | ||
59 | - $count = 0; | ||
60 | - } | ||
61 | - $e->pickOrderCount = $count; | ||
62 | - } | ||
63 | - | ||
64 | - return $this->renderJson($e); | ||
65 | - } | ||
66 | - | ||
67 | - // 获取订单数据 | ||
68 | - public function actionGetOrderData() | ||
69 | - { | ||
70 | - $e = new stdClass(); | ||
71 | - $e->success = true; | ||
72 | - $end = time(); | ||
73 | - $endT = strtotime(date('Y-m-d')) + 1; | ||
74 | - $start = $endT - 6 * 24 * 3600; | ||
75 | - $status = array( | ||
76 | - RepairOrderStatus::STATUS_FINISH, | ||
77 | - RepairOrderStatus::STATUS_WAIT_RATE, | ||
78 | - RepairOrderStatus::STATUS_USER_CANCEL, | ||
79 | - RepairOrderStatus::STATUS_ENGINEER_CANCEL, | ||
80 | - RepairOrderStatus::STATUS_USER_CLOSE, | ||
81 | - RepairOrderStatus::STATUS_ENGINEER_CLOSE | ||
82 | - ); | ||
83 | - | ||
84 | - $type = 0; | ||
85 | - $orderListTmp = $this->getOrder($start, $end, $type, $status); | ||
86 | - $orderList = array(); | ||
87 | - if ($orderListTmp) { | ||
88 | - foreach ($orderListTmp as $k => $v) { | ||
89 | - $orderList[$v['mydate']] = $v; | ||
90 | - } | ||
91 | - } | ||
92 | - $dateList = $this->genDate($start); | ||
93 | - $data =array(); | ||
94 | - foreach ($dateList as $kk => $vv) { | ||
95 | - $myArr = array(); | ||
96 | - $myArr['date'] = $kk; | ||
97 | - if ($type == 0) { | ||
98 | - $myArr['pay_price'] = isset($orderList[$kk]['pay_price']) ? $orderList[$kk]['pay_price'] : 0; | ||
99 | - $myArr['repair_price'] = isset($orderList[$kk]['repair_price']) ? $orderList[$kk]['repair_price'] : 0; | ||
100 | - } | ||
101 | - | ||
102 | - $data[] = $myArr; | ||
103 | - } | ||
104 | - $e->data = $data; | ||
105 | - return $this->renderJson($e); | ||
106 | - } | ||
107 | - | ||
108 | - // 热力图 | ||
109 | - public function actionGetHeatData() | ||
110 | - { | ||
111 | - $e= new stdClass(); | ||
112 | - $e->success = true; | ||
113 | - $north_east= $this->request->get('north_east'); | ||
114 | - $south_west = $this->request->get('south_west'); | ||
115 | - $zoom = $this->request->get('zoom'); | ||
116 | - $distance = 25000; //25公里内的点 | ||
117 | - $earthRadius = Distance::EARTH_RADIUS; | ||
118 | - $table1 = 'address'; | ||
119 | - $end = time(); | ||
120 | - $endT =strtotime(date('Y-m-d')) + 1; | ||
121 | - $start = $endT - 6 * 24 * 3600; | ||
122 | - $status =array( | ||
123 | - RepairOrderStatus::STATUS_FINISH, | ||
124 | - RepairOrderStatus::STATUS_WAIT_RATE, | ||
125 | - RepairOrderStatus::STATUS_USER_CANCEL, | ||
126 | - RepairOrderStatus::STATUS_ENGINEER_CANCEL, | ||
127 | - RepairOrderStatus::STATUS_USER_CLOSE, | ||
128 | - RepairOrderStatus::STATUS_ENGINEER_CLOSE | ||
129 | - ); | ||
130 | - | ||
131 | - /* | ||
132 | - $vRadian= "$earthRadius * acos( cos( radians('$lat') ) * cos( radians( $table1.latitude ) ) * cos( radians( $table1.longitude ) - radians('$lng') ) + | ||
133 | - sin( radians('$lat') ) * sin( radians( $table1.latitude ) ) )"; | ||
134 | - */ | ||
135 | - | ||
136 | - $repairOrderModel = RepairOrderModel::find(); | ||
137 | - $repairOrderModel->leftJoin("address","address.id = repair_order.address_id"); | ||
138 | - $repairOrderModel->select(["concat(address.latitude,'_',address.longitude) as latlng", "count(*) as mycount"]); | ||
139 | - $repairOrderModel->where(['repair_order.status' => $status]); | ||
140 | - $repairOrderModel->andFilterWhere(['>', 'repair_order.created_at', $start]); | ||
141 | - $repairOrderModel->andFilterWhere(['<', 'repair_order.created_at', $end]); | ||
142 | - | ||
143 | - $repairOrderModel->andFilterWhere(['<', "address.latitude", $north_east[0]]); | ||
144 | - $repairOrderModel->andFilterWhere(['>', "address.latitude", $south_west[0]]); | ||
145 | - | ||
146 | - $repairOrderModel->andFilterWhere(['<', "address.longitude", $north_east[1]]); | ||
147 | - $repairOrderModel->andFilterWhere(['>', "address.longitude", $south_west[1]]); | ||
148 | - $repairOrderModel->groupBy('latlng'); | ||
149 | - $repairOrderModel->asArray(); | ||
150 | - $olist = $repairOrderModel->all(); | ||
151 | - | ||
152 | - | ||
153 | - $item = array('max' => 100, 'data' => array()); | ||
154 | - if ($olist) { | ||
155 | - foreach ($olist as $k => $v) { | ||
156 | - $latlngTemp = explode('_', $v['latlng']); | ||
157 | - $item['data'][] = array('lat' => $latlngTemp[0], 'lng' => $latlngTemp[1], 'count' => $v['mycount']); | ||
158 | - } | ||
159 | - } | ||
160 | - $e->item =$item; | ||
161 | - return $this->renderJson($e); | ||
162 | - } | ||
163 | - | ||
164 | - // 获取通知 | ||
165 | - public function actionGetNotice() | ||
166 | - { | ||
167 | - $act = $this->request->post('act'); | ||
168 | - if ($act == 'remove') { | ||
169 | - $id = $this->request->post('id'); | ||
170 | - return $this->removeNotice($id); | ||
171 | - } | ||
172 | - $e = new stdClass(); | ||
173 | - $e->success = false; | ||
174 | - | ||
175 | - $e->count = 0; | ||
176 | - | ||
177 | - $noticeInfoModel = NoticeInfoModel::find(); | ||
178 | - $noticeInfoModel->where(['status' => NoticeInfoModel::STATUS_UNREAD]); | ||
179 | - | ||
180 | - $noticeInfoModel->asArray(); | ||
181 | - $count = $noticeInfoModel->count(); | ||
182 | - $noticeInfoModel->limit(6); | ||
183 | - $nList = $noticeInfoModel->all(); | ||
184 | - $e->msgList = array(); | ||
185 | - if ($nList) { | ||
186 | - $tt = time(); | ||
187 | - foreach ($nList as $k => $v) { | ||
188 | - $v['created_date_time'] = date('Y-m-d H:i:s', $v['created_at']); | ||
189 | - $v['created_time'] = $this->getTime($v['created_at'], $tt); | ||
190 | - $nList[$k] = $v; | ||
191 | - } | ||
192 | - $e->count = $count; | ||
193 | - $e->msgList = $nList; | ||
194 | - $e->success = true; | ||
195 | - } | ||
196 | - | ||
197 | - return $this->renderJson($e); | ||
198 | - } | ||
199 | - | ||
200 | - // 删除 | ||
201 | - protected function removeNotice($id) | ||
202 | - { | ||
203 | - $e= new stdClass(); | ||
204 | - $e->success = false; | ||
205 | - $e->error = 'Fail'; | ||
206 | - $noticeInfo = NoticeInfoModel::findOne($id); | ||
207 | - if ($noticeInfo && $noticeInfo->delete()) { | ||
208 | - $e->success = true; | ||
209 | - } | ||
210 | - | ||
211 | - return $this->renderJson($e); | ||
212 | - } | ||
213 | 40 | ||
214 | // 判断时间 | 41 | // 判断时间 |
215 | protected function getTime($t, $curT) | 42 | protected function getTime($t, $curT) |
@@ -241,124 +68,4 @@ class BoardController extends BaseController | @@ -241,124 +68,4 @@ class BoardController extends BaseController | ||
241 | return $dataArr; | 68 | return $dataArr; |
242 | } | 69 | } |
243 | 70 | ||
244 | - // 贴码设备 | ||
245 | - protected function getDeviceReview() | ||
246 | - { | ||
247 | - $bindDeviceModel = BindDeviceApplyModel::find(); | ||
248 | - $wh = array('status' => BindDeviceApplyModel::STATUS_APPLYING); | ||
249 | - $bindDeviceModel->where($wh); | ||
250 | - $count = $bindDeviceModel->count(); | ||
251 | - | ||
252 | - $url = Url::toRoute('/device/userdevice/apply?status=0'); | ||
253 | - $returnArr = array(0, $url); | ||
254 | - if ($count > 0) { | ||
255 | - $returnArr = array($count, $url); | ||
256 | - } | ||
257 | - | ||
258 | - return $returnArr; | ||
259 | - } | ||
260 | - | ||
261 | - // 质保申请 | ||
262 | - protected function getAppeal() | ||
263 | - { | ||
264 | - $repairOrderAppealModel = RepairOrderAppealModel::find(); | ||
265 | - $wh = array('status' => RepairOrderAppealModel::STATUS_APPEALING); | ||
266 | - $repairOrderAppealModel->where($wh); | ||
267 | - $count = $repairOrderAppealModel->count(); | ||
268 | - $url = Url::toRoute('/trade/appeal/index'); | ||
269 | - $returnArr = array(0, $url); | ||
270 | - if ($count > 0) { | ||
271 | - $returnArr = array($count, $url); | ||
272 | - } | ||
273 | - | ||
274 | - return $returnArr; | ||
275 | - } | ||
276 | - | ||
277 | - // 工程师认证 | ||
278 | - protected function getEngineerAuth($status = EngineerStatus::STATUS_SKILL_AUTH) | ||
279 | - { | ||
280 | - $engineerModel = EngineerModel::find(); | ||
281 | - $wh = array('status' => $status, 'is_fake_id' => 0); | ||
282 | - $engineerModel->where($wh); | ||
283 | - $count = $engineerModel->count(); | ||
284 | - $url = Url::toRoute('/engineer/engineer/index?status=2'); | ||
285 | - $returnArr = array(0, $url); | ||
286 | - if ($count > 0) { | ||
287 | - $returnArr = array($count, $url); | ||
288 | - } | ||
289 | - | ||
290 | - return $returnArr; | ||
291 | - } | ||
292 | - | ||
293 | - // 技能审核,这里不能以人为单位,应该以技能为单位,一个人可以多项技能认证 | ||
294 | - protected function getEngineerSkillAuth() | ||
295 | - { | ||
296 | - $engineerSkillModel = EngineerSkillsModel::find(); | ||
297 | - $wh = array('engineer_skills.status' => EngineerSkillsModel::STATUS_REVIEWING); | ||
298 | - $engineerSkillModel->select(["engineer_skills.engineer_id"]); | ||
299 | - $engineerSkillModel->distinct(); | ||
300 | - $engineerSkillModel->where($wh); | ||
301 | - | ||
302 | - $count = $engineerSkillModel->count(); | ||
303 | - $url = Url::toRoute('/engineer/engineer/index?status=6'); | ||
304 | - $returnArr = array(0, $url); | ||
305 | - if ($count > 0) { | ||
306 | - $returnArr = array($count, $url); | ||
307 | - } | ||
308 | - | ||
309 | - return $returnArr; | ||
310 | - } | ||
311 | - | ||
312 | - // 提现审核 | ||
313 | - protected function getWithdraw() | ||
314 | - { | ||
315 | - $count = EngineerWithdrawRepository::getReviewingWithdrawCount(); | ||
316 | - $url = Url::toRoute('/engineer/withdraw/index'); | ||
317 | - $returnArr = array(0, $url); | ||
318 | - if ($count > 0) { | ||
319 | - $returnArr = array($count, $url); | ||
320 | - } | ||
321 | - | ||
322 | - return $returnArr; | ||
323 | - } | ||
324 | - | ||
325 | - // 发票出错 | ||
326 | - protected function getErrorInvoice($kplx = InvoiceApi::KPLX_NORMAL) | ||
327 | - { | ||
328 | - $invoiceModel = InvoiceModel::find(); | ||
329 | - $wh = array('status' => InvoiceModel::STATUS_ERROR, 'kplx' => $kplx); | ||
330 | - $invoiceModel->where($wh); | ||
331 | - $count = $invoiceModel->count(); | ||
332 | - $url = Url::toRoute(['/invoice/invoice/index', 'invoice_status' => InvoiceModel::STATUS_ERROR]); | ||
333 | - $returnArr = array(0, $url); | ||
334 | - if ($count > 0) { | ||
335 | - $returnArr = array($count, $url); | ||
336 | - } | ||
337 | - | ||
338 | - return $returnArr; | ||
339 | - } | ||
340 | - | ||
341 | - /* 订单数据 */ | ||
342 | - //获取订单数量(当日和七天,已支付,未支付) | ||
343 | - protected function getOrder($start, $end, $selectType = 0, $status = 0) | ||
344 | - { | ||
345 | - $orderModel = RepairOrderModel::find(); | ||
346 | - if ($status != 0) { | ||
347 | - $orderModel->where(['status' => $status]); | ||
348 | - } | ||
349 | - | ||
350 | - if ($selectType == 0) { | ||
351 | - $orderModel->select(['FROM_UNIXTIME(`created_at`, "%Y-%m-%d") as mydate','sum(pay_price) as pay_price','sum(repair_price) as repair_price']); | ||
352 | - } else { | ||
353 | - $orderModel->select(['FROM_UNIXTIME(`created_at`, "%Y-%m-%d") as mydate','count(*) as cc']); | ||
354 | - } | ||
355 | - | ||
356 | - $orderModel->andFilterWhere(['>', 'created_at', $start]); | ||
357 | - $orderModel->andFilterWhere(['<', 'created_at', $end]); | ||
358 | - $orderModel->groupBy('mydate'); | ||
359 | - $orderModel->asArray(); | ||
360 | - $oList = $orderModel->all(); | ||
361 | - | ||
362 | - return $oList; | ||
363 | - } | ||
364 | } | 71 | } |
365 | \ No newline at end of file | 72 | \ No newline at end of file |
app-ht/modules/home/views/board/index.php
app-ht/modules/upgrade/controllers/UpgradeController.php
@@ -76,7 +76,7 @@ class UpgradeController extends BaseController | @@ -76,7 +76,7 @@ class UpgradeController extends BaseController | ||
76 | } | 76 | } |
77 | $user = Yii::$app->user->identity; | 77 | $user = Yii::$app->user->identity; |
78 | if (isset($user->is_manufacture) && $user->is_manufacture == 1) { | 78 | if (isset($user->is_manufacture) && $user->is_manufacture == 1) { |
79 | - $where[] = ['like', 'mf.sys_user_id', $user->id]; | 79 | + $where[] = ['=', 'mf.sys_user_id', $user->id];// ??? |
80 | } | 80 | } |
81 | if ($type == 0) { | 81 | if ($type == 0) { |
82 | $pageList = UpgradeRepository::getPageList($where, 0 , 0); | 82 | $pageList = UpgradeRepository::getPageList($where, 0 , 0); |
app-ht/views/layouts/_main-header.php
@@ -13,10 +13,10 @@ use yii\helpers\Url; | @@ -13,10 +13,10 @@ use yii\helpers\Url; | ||
13 | <div class="navbar-custom-menu"> | 13 | <div class="navbar-custom-menu"> |
14 | <ul class="nav navbar-nav"> | 14 | <ul class="nav navbar-nav"> |
15 | <li> | 15 | <li> |
16 | - <a href="<?= Url::toRoute(['/my']) ?>">我的账号</a> | 16 | + <a href="javascript:window.location.href='#/my/default/my-index';window.location.reload()" >我的账号</a> |
17 | </li> | 17 | </li> |
18 | <li> | 18 | <li> |
19 | - <a href="<?= Url::toRoute(['/my/default/password']) ?>">修改密码</a> | 19 | + <a href="javascript:window.location.href='#/my/default/password';window.location.reload()">修改密码</a> |
20 | </li> | 20 | </li> |
21 | <li class="dropdown user user-menu"> | 21 | <li class="dropdown user user-menu"> |
22 | <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"> | 22 | <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"> |
domain/device/CreateBatchRepository.php
@@ -27,16 +27,16 @@ class CreateBatchRepository | @@ -27,16 +27,16 @@ class CreateBatchRepository | ||
27 | 27 | ||
28 | /** | 28 | /** |
29 | * @param $type | 29 | * @param $type |
30 | - * @param $keyword | 30 | + * @param $where |
31 | * @return array | 31 | * @return array |
32 | */ | 32 | */ |
33 | - static function getSerialNoComponent($type, $keyword) | 33 | + static function getSerialNoComponent($type, $where) |
34 | { | 34 | { |
35 | if ('manufacture' == $type) { | 35 | if ('manufacture' == $type) { |
36 | $q = new Query(); | 36 | $q = new Query(); |
37 | $q->select(['concat(id, "_", manufacture_no) as uid', 'id','manufacture_no', 'name']); | 37 | $q->select(['concat(id, "_", manufacture_no) as uid', 'id','manufacture_no', 'name']); |
38 | $q->from('manufacture'); | 38 | $q->from('manufacture'); |
39 | - $q->where('id >0'); | 39 | + $q->where($where); |
40 | 40 | ||
41 | $list = $q->all(); | 41 | $list = $q->all(); |
42 | 42 | ||
@@ -45,7 +45,7 @@ class CreateBatchRepository | @@ -45,7 +45,7 @@ class CreateBatchRepository | ||
45 | $q = new Query(); | 45 | $q = new Query(); |
46 | $q->select(['concat(id,"_", project_no) as uid', 'id','project_no', 'name']); | 46 | $q->select(['concat(id,"_", project_no) as uid', 'id','project_no', 'name']); |
47 | $q->from('project'); | 47 | $q->from('project'); |
48 | - $q->where('id >0'); | 48 | + $q->where('id >0 and is_delete = 0'); |
49 | 49 | ||
50 | $list = $q->all(); | 50 | $list = $q->all(); |
51 | 51 | ||
@@ -54,7 +54,7 @@ class CreateBatchRepository | @@ -54,7 +54,7 @@ class CreateBatchRepository | ||
54 | $q = new Query(); | 54 | $q = new Query(); |
55 | $q->select(['concat(id,"_", model_no) as uid','id','model_no', 'name']); | 55 | $q->select(['concat(id,"_", model_no) as uid','id','model_no', 'name']); |
56 | $q->from('model'); | 56 | $q->from('model'); |
57 | - $q->where('id >0'); | 57 | + $q->where('id >0 and is_delete = 0'); |
58 | $list = $q->all(); | 58 | $list = $q->all(); |
59 | 59 | ||
60 | return $list; | 60 | return $list; |
@@ -62,7 +62,7 @@ class CreateBatchRepository | @@ -62,7 +62,7 @@ class CreateBatchRepository | ||
62 | $q = new Query(); | 62 | $q = new Query(); |
63 | $q->select(['concat(id,"_", production_no) as uid','id','production_no', 'name']); | 63 | $q->select(['concat(id,"_", production_no) as uid','id','production_no', 'name']); |
64 | $q->from('production'); | 64 | $q->from('production'); |
65 | - $q->where('id >0'); | 65 | + $q->where('id >0 and is_delete = 0'); |
66 | $list = $q->all(); | 66 | $list = $q->all(); |
67 | 67 | ||
68 | return $list; | 68 | return $list; |
@@ -0,0 +1,119 @@ | @@ -0,0 +1,119 @@ | ||
1 | +<?php | ||
2 | +namespace domain\system; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use domain\system\models\AuthPerm as AuthPermModel; | ||
6 | +use domain\system\models\AuthPermsRoutes as AuthPermsRoutesModel; | ||
7 | + | ||
8 | + | ||
9 | +class AuthPerm | ||
10 | +{ | ||
11 | + const LEVEL_MODULE = 1; // | ||
12 | + const LEVEL_CONTROLLER = 2; // | ||
13 | + const LEVEL_ACTION = 3; // | ||
14 | + | ||
15 | + /** | ||
16 | + * @param $item | ||
17 | + * @return null|object | ||
18 | + * @throws \yii\base\InvalidConfigException | ||
19 | + */ | ||
20 | + static function create($item) | ||
21 | + { | ||
22 | + if (empty($item)) { | ||
23 | + return null; | ||
24 | + } | ||
25 | + $arr = [ | ||
26 | + 'class' => AuthPermModel::className(), | ||
27 | + 'name' => $item['name'], | ||
28 | + 'parent_id' => $item['parent_id'], | ||
29 | + 'level' => $item['level'], | ||
30 | + 'desc' => $item['desc'], | ||
31 | + ]; | ||
32 | + | ||
33 | + $model = Yii::createObject($arr); | ||
34 | + $model->save(); | ||
35 | + | ||
36 | + return $model; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * @param $condition | ||
41 | + * @return bool|int | ||
42 | + */ | ||
43 | + static function deleteAll($condition) | ||
44 | + { | ||
45 | + if (empty($condition)) { | ||
46 | + return false; | ||
47 | + } | ||
48 | + | ||
49 | + return AuthPermModel::deleteAll($condition); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * @param $item | ||
54 | + * @param $routers | ||
55 | + * @return array|null | ||
56 | + * @throws \yii\base\InvalidConfigException | ||
57 | + */ | ||
58 | + static function createWithRouters($item, $routers) | ||
59 | + { | ||
60 | + if (empty($item) || empty($routers)) { | ||
61 | + return null; | ||
62 | + } | ||
63 | + $arr = [ | ||
64 | + 'class' => AuthPermModel::className(), | ||
65 | + 'name' => $item['name'], | ||
66 | + 'parent_id' => $item['parent_id'], | ||
67 | + 'level' => $item['level'], | ||
68 | + 'desc' => $item['desc'], | ||
69 | + ]; | ||
70 | + | ||
71 | + $model = Yii::createObject($arr); | ||
72 | + $routerArr = []; | ||
73 | + if ($model->save()) { | ||
74 | + foreach ($routers as $k => $v) { | ||
75 | + $tmpArr = [ | ||
76 | + 'class' => AuthPermsRoutesModel::className(), | ||
77 | + 'perm_id' => $model->perm_id, | ||
78 | + 'route' => $v, | ||
79 | + ]; | ||
80 | + $routerModel = Yii::createObject($tmpArr); | ||
81 | + $routerModel->save(); | ||
82 | + $routerArr[] = $routerModel; | ||
83 | + } | ||
84 | + return [$model, $routerArr]; | ||
85 | + } | ||
86 | + | ||
87 | + return null; | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * @param $permId | ||
92 | + * @param $router | ||
93 | + * @return bool|object | ||
94 | + * @throws \yii\base\InvalidConfigException | ||
95 | + */ | ||
96 | + static function createRouter($permId, $router) | ||
97 | + { | ||
98 | + if (empty($permId) || empty($router)) { | ||
99 | + return false; | ||
100 | + } | ||
101 | + $modelArr = [ | ||
102 | + 'class' => AuthPermsRoutesModel::className(), | ||
103 | + 'perm_id' => $permId, | ||
104 | + 'route' => $router, | ||
105 | + ]; | ||
106 | + $routerModel = Yii::createObject($modelArr); | ||
107 | + $routerModel->save(); | ||
108 | + return $routerModel; | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * @param $permId | ||
113 | + * @return int | ||
114 | + */ | ||
115 | + static function deletePermRouters($permId) | ||
116 | + { | ||
117 | + return AuthPermsRoutesModel::deleteAll(['perm_id' => $permId]); | ||
118 | + } | ||
119 | +} |
@@ -0,0 +1,148 @@ | @@ -0,0 +1,148 @@ | ||
1 | +<?php | ||
2 | +namespace domain\system; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use domain\system\models\AuthPerm as AuthPermModel; | ||
6 | +use domain\system\models\AuthPermsRoutes as AuthPermsRoutesModel; | ||
7 | + | ||
8 | +use function count; | ||
9 | +use function explode; | ||
10 | +use function implode; | ||
11 | + | ||
12 | +class AuthPermRepository | ||
13 | +{ | ||
14 | + /** | ||
15 | + * @param $condition | ||
16 | + * @return null|static[] | ||
17 | + */ | ||
18 | + static function findAll($condition) | ||
19 | + { | ||
20 | + if (empty($condition)) { | ||
21 | + return null; | ||
22 | + } | ||
23 | + return AuthPermModel::findAll($condition); | ||
24 | + } | ||
25 | + | ||
26 | + /** | ||
27 | + * @param $condition | ||
28 | + * @return array|\yii\db\ActiveRecord[] | ||
29 | + */ | ||
30 | + static function getAllItems($condition, $limit = null) | ||
31 | + { | ||
32 | + if (empty($condition)) { | ||
33 | + return null; | ||
34 | + } | ||
35 | + $findModel = AuthPermModel::find(); | ||
36 | + $findModel->where($condition); | ||
37 | + if ($limit) { | ||
38 | + $findModel->limit($limit); | ||
39 | + } | ||
40 | + $rows = $findModel->all(); | ||
41 | + return $rows; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * @param $condition | ||
46 | + * @return null|static | ||
47 | + */ | ||
48 | + static function findOne($condition) | ||
49 | + { | ||
50 | + if (empty($condition)) { | ||
51 | + return null; | ||
52 | + } | ||
53 | + | ||
54 | + return AuthPermModel::findOne($condition); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * 根据扫描的route 返回他对应的级别 | ||
59 | + * @param $route | ||
60 | + * @return int | ||
61 | + */ | ||
62 | + static function routeLevel($route) | ||
63 | + { | ||
64 | + $items = explode('/',$route); | ||
65 | + $len = count($items); | ||
66 | + | ||
67 | + if (2 == $len) { | ||
68 | + if ('*' == $items[1]) { | ||
69 | + return AuthPerm::LEVEL_MODULE; | ||
70 | + } else { | ||
71 | + return 0; | ||
72 | + } | ||
73 | + } else if(3 == $len){ | ||
74 | + if ('*' == $items[2]) { | ||
75 | + return AuthPerm::LEVEL_CONTROLLER; | ||
76 | + } else { | ||
77 | + return AuthPerm::LEVEL_ACTION; | ||
78 | + } | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * @param $where | ||
84 | + * @param $asArr | ||
85 | + * @return array|\yii\db\ActiveRecord[] | ||
86 | + */ | ||
87 | + static function getPermsRouters($where, $asArr = false) | ||
88 | + { | ||
89 | + $routersModel = AuthPermsRoutesModel::find(); | ||
90 | + $routersModel->where($where); | ||
91 | + if ($asArr) { | ||
92 | + $routersModel->asArray(); | ||
93 | + } | ||
94 | + $return = $routersModel->all(); | ||
95 | + | ||
96 | + return $return; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * @param $confirmRouters | ||
101 | + * @return array | ||
102 | + */ | ||
103 | + static function getGroupPermsRouters($confirmRouters) | ||
104 | + { | ||
105 | + $routers = $confirmRouters; | ||
106 | + $modulesArr = []; | ||
107 | + $controllerArr = []; | ||
108 | + $actionArr = []; | ||
109 | + $groupRouter = []; | ||
110 | + | ||
111 | + $permModel = AuthPermModel::find(); | ||
112 | + $permModel->where('perm_id >0'); | ||
113 | + $permModel->asArray(); | ||
114 | + $confirmPerms = $permModel->all(); | ||
115 | + | ||
116 | + foreach ($routers as $rk => $rv) { | ||
117 | + $groupRouter[$rv['perm_id']][] = $rv['route']; | ||
118 | + } | ||
119 | + | ||
120 | + foreach ($confirmPerms as $k => $v) { | ||
121 | + if (AuthPerm::LEVEL_MODULE == $v['level']) { | ||
122 | + $modulesArr[$v['perm_id']] = ['id' => $v['perm_id'], 'label' => $v['name'],'items' => [],'routes' => '', 'parent_id' => $v['parent_id']]; | ||
123 | + } else if (AuthPerm::LEVEL_CONTROLLER == $v['level']) { | ||
124 | + $controllerArr[$v['perm_id']] = ['id' => $v['perm_id'], 'label' => $v['name'],'items' => [],'routes' => '', 'parent_id' => $v['parent_id']]; | ||
125 | + } else if (AuthPerm::LEVEL_ACTION == $v['level']) { | ||
126 | + $myRouters = isset($groupRouter[$v['perm_id']])? implode(',', $groupRouter[$v['perm_id']]): ''; | ||
127 | + $actionArr[$v['perm_id']] = ['id' => $v['perm_id'], 'label' => $v['name'], 'items' => [], 'routes' => $myRouters, 'parent_id' => $v['parent_id']]; | ||
128 | + } | ||
129 | + } | ||
130 | + | ||
131 | + foreach ($actionArr as $ak => $av) { | ||
132 | + if (isset($controllerArr[$av['parent_id']])) { | ||
133 | + $controllerArr[$av['parent_id']]['items'][] = $av; | ||
134 | + } | ||
135 | + | ||
136 | + } | ||
137 | + | ||
138 | + foreach ($controllerArr as $ck => $cv) { | ||
139 | + if (isset($modulesArr[$cv['parent_id']])) { | ||
140 | + $modulesArr[$cv['parent_id']]['items'][] = $cv; | ||
141 | + } | ||
142 | + } | ||
143 | + | ||
144 | + return $modulesArr; | ||
145 | + | ||
146 | + } | ||
147 | + | ||
148 | +} |
@@ -0,0 +1,307 @@ | @@ -0,0 +1,307 @@ | ||
1 | +<?php | ||
2 | +namespace domain\system; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use yii\base\Object; | ||
6 | +use yii\caching\TagDependency; | ||
7 | +use yii\helpers\VarDumper; | ||
8 | +use yii\helpers\ArrayHelper; | ||
9 | +use yii\web\Application; | ||
10 | +use Exception; | ||
11 | + | ||
12 | + | ||
13 | +class Route extends Object | ||
14 | +{ | ||
15 | + const CACHE_TAG = 'jiwork.admin.route'; | ||
16 | + | ||
17 | + const PREFIX_ADVANCED = '@'; | ||
18 | + const PREFIX_BASIC = '/'; | ||
19 | + | ||
20 | + private $_routePrefix; | ||
21 | + | ||
22 | + | ||
23 | + /** | ||
24 | + * Returns route prefix depending on the configuration. | ||
25 | + * @return string Route prefix | ||
26 | + */ | ||
27 | + public function getRoutePrefix() | ||
28 | + { | ||
29 | + if (!$this->_routePrefix) { | ||
30 | + $this->_routePrefix = self::PREFIX_BASIC; | ||
31 | + } | ||
32 | + return $this->_routePrefix; | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * Returns the correct permission name depending on the configuration. | ||
37 | + * @param string $route Route | ||
38 | + * @return string Permission name | ||
39 | + */ | ||
40 | + public function getPermissionName($route) | ||
41 | + { | ||
42 | + if (self::PREFIX_BASIC == $this->routePrefix) { | ||
43 | + return self::PREFIX_BASIC . trim($route, self::PREFIX_BASIC); | ||
44 | + } else { | ||
45 | + return self::PREFIX_ADVANCED . ltrim(trim($route, self::PREFIX_BASIC), self::PREFIX_ADVANCED); | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Get available and assigned routes | ||
51 | + * @return array | ||
52 | + */ | ||
53 | + public function getRoutes() | ||
54 | + { | ||
55 | + //$manager = Configs::authManager(); | ||
56 | + // Get advanced configuration | ||
57 | + //$advanced = Configs::instance()->advanced; | ||
58 | + $advanced = null; | ||
59 | + if ($advanced) { | ||
60 | + // Use advanced route scheme. | ||
61 | + // Set advanced route prefix. | ||
62 | + $this->_routePrefix = self::PREFIX_ADVANCED; | ||
63 | + // Create empty routes array. | ||
64 | + $routes = []; | ||
65 | + // Save original app. | ||
66 | + $yiiApp = Yii::$app; | ||
67 | + // Step through each configured application | ||
68 | + foreach ($advanced as $id => $configPaths) { | ||
69 | + // Force correct id string. | ||
70 | + $id = $this->routePrefix . ltrim(trim($id), $this->routePrefix); | ||
71 | + // Create empty config array. | ||
72 | + $config = []; | ||
73 | + // Assemble configuration for current app. | ||
74 | + foreach ($configPaths as $configPath) { | ||
75 | + // Merge every new configuration with the old config array. | ||
76 | + $config = ArrayHelper::merge($config, require (Yii::getAlias($configPath))); | ||
77 | + } | ||
78 | + // Create new app using the config array. | ||
79 | + unset($config['bootstrap']); | ||
80 | + $app = new Application($config); | ||
81 | + // Get all the routes of the newly created app. | ||
82 | + $r = $this->getAppRoutes($app); | ||
83 | + // Dump new app | ||
84 | + unset($app); | ||
85 | + // Prepend the app id to all routes. | ||
86 | + foreach ($r as $route) { | ||
87 | + $routes[$id . $route] = $id . $route; | ||
88 | + } | ||
89 | + } | ||
90 | + // Switch back to original app. | ||
91 | + Yii::$app = $yiiApp; | ||
92 | + unset($yiiApp); | ||
93 | + } else { | ||
94 | + // Use basic route scheme. | ||
95 | + // Set basic route prefix | ||
96 | + $this->_routePrefix = self::PREFIX_BASIC; | ||
97 | + // Get basic app routes. | ||
98 | + $routes = $this->getAppRoutes(); | ||
99 | + } | ||
100 | + $exists = []; | ||
101 | + /* | ||
102 | + foreach (array_keys($manager->getPermissions()) as $name) { | ||
103 | + if ($name[0] !== $this->routePrefix) { | ||
104 | + continue; | ||
105 | + } | ||
106 | + $exists[] = $name; | ||
107 | + unset($routes[$name]); | ||
108 | + }*/ | ||
109 | + return [ | ||
110 | + 'available' => array_keys($routes), | ||
111 | + 'assigned' => $exists, | ||
112 | + ]; | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Get list of application routes | ||
117 | + * @return array | ||
118 | + */ | ||
119 | + public function getAppRoutes($module = null) | ||
120 | + { | ||
121 | + if ($module === null) { | ||
122 | + $module = Yii::$app; | ||
123 | + } elseif (is_string($module)) { | ||
124 | + $module = Yii::$app->getModule($module); | ||
125 | + } | ||
126 | + $key = [__METHOD__, Yii::$app->id, $module->getUniqueId()]; | ||
127 | + | ||
128 | + $cache = Yii::$app->cache; | ||
129 | + if ($cache === null || ($result = $cache->get($key)) === false) { | ||
130 | + $result = []; | ||
131 | + $this->getRouteRecursive($module, $result); | ||
132 | + if ($cache !== null) { | ||
133 | + $cache->set($key, $result, $cache->cacheDuration, new TagDependency([ | ||
134 | + 'tags' => self::CACHE_TAG, | ||
135 | + ])); | ||
136 | + | ||
137 | + } | ||
138 | + } | ||
139 | + | ||
140 | + return $result; | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * 后台路由 | ||
145 | + * @param null $module | ||
146 | + * @return array|mixed | ||
147 | + */ | ||
148 | + public function getHtAppRoutes($module = null) | ||
149 | + { | ||
150 | + if ($module === null) { | ||
151 | + $module = Yii::$app; | ||
152 | + } elseif (is_string($module)) { | ||
153 | + $module = Yii::$app->getModule($module); | ||
154 | + } | ||
155 | + | ||
156 | + $result = []; | ||
157 | + $this->getRouteRecursive($module, $result); | ||
158 | + $result = $this->ltrimRouter($result); | ||
159 | + | ||
160 | + return $result; | ||
161 | + } | ||
162 | + | ||
163 | + /** | ||
164 | + * delete router left / | ||
165 | + * @param $routers | ||
166 | + * @return array | ||
167 | + */ | ||
168 | + public function ltrimRouter($routers) | ||
169 | + { | ||
170 | + $returnRouters = []; | ||
171 | + foreach ($routers as $k => $v) { | ||
172 | + $returnRouters[] = ltrim($v, '/'); | ||
173 | + } | ||
174 | + | ||
175 | + return $returnRouters; | ||
176 | + } | ||
177 | + | ||
178 | + /** | ||
179 | + * Get route(s) recursive | ||
180 | + * @param \yii\base\Module $module | ||
181 | + * @param array $result | ||
182 | + */ | ||
183 | + protected function getRouteRecursive($module, &$result) | ||
184 | + { | ||
185 | + $token = "Get Route of '" . get_class($module) . "' with id '" . $module->uniqueId . "'"; | ||
186 | + Yii::beginProfile($token, __METHOD__); | ||
187 | + try { | ||
188 | + foreach ($module->getModules() as $id => $child) { | ||
189 | + if (($child = $module->getModule($id)) !== null) { | ||
190 | + $this->getRouteRecursive($child, $result); | ||
191 | + } | ||
192 | + } | ||
193 | + | ||
194 | + foreach ($module->controllerMap as $id => $type) { | ||
195 | + $this->getControllerActions($type, $id, $module, $result); | ||
196 | + } | ||
197 | + | ||
198 | + $namespace = trim($module->controllerNamespace, '\\') . '\\'; | ||
199 | + $this->getControllerFiles($module, $namespace, '', $result); | ||
200 | + $all = '/' . ltrim($module->uniqueId . '/*', '/'); | ||
201 | + $result[$all] = $all; | ||
202 | + } catch (Exception $exc) { | ||
203 | + Yii::error($exc->getMessage(), __METHOD__); | ||
204 | + } | ||
205 | + Yii::endProfile($token, __METHOD__); | ||
206 | + } | ||
207 | + | ||
208 | + /** | ||
209 | + * Get list controller under module | ||
210 | + * @param \yii\base\Module $module | ||
211 | + * @param string $namespace | ||
212 | + * @param string $prefix | ||
213 | + * @param mixed $result | ||
214 | + * @return mixed | ||
215 | + */ | ||
216 | + protected function getControllerFiles($module, $namespace, $prefix, &$result) | ||
217 | + { | ||
218 | + $path = Yii::getAlias('@' . str_replace('\\', '/', $namespace), false); | ||
219 | + $token = "Get controllers from '$path'"; | ||
220 | + Yii::beginProfile($token, __METHOD__); | ||
221 | + try { | ||
222 | + if (!is_dir($path)) { | ||
223 | + return; | ||
224 | + } | ||
225 | + foreach (scandir($path) as $file) { | ||
226 | + if ($file == '.' || $file == '..') { | ||
227 | + continue; | ||
228 | + } | ||
229 | + if (is_dir($path . '/' . $file) && preg_match('%^[a-z0-9_/]+$%i', $file . '/')) { | ||
230 | + $this->getControllerFiles($module, $namespace . $file . '\\', $prefix . $file . '/', $result); | ||
231 | + } elseif (strcmp(substr($file, -14), 'Controller.php') === 0) { | ||
232 | + $baseName = substr(basename($file), 0, -14); | ||
233 | + $name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $baseName)); | ||
234 | + $id = ltrim(str_replace(' ', '-', $name), '-'); | ||
235 | + $className = $namespace . $baseName . 'Controller'; | ||
236 | + if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\base\Controller')) { | ||
237 | + $this->getControllerActions($className, $prefix . $id, $module, $result); | ||
238 | + } | ||
239 | + } | ||
240 | + } | ||
241 | + } catch (Exception $exc) { | ||
242 | + Yii::error($exc->getMessage(), __METHOD__); | ||
243 | + } | ||
244 | + Yii::endProfile($token, __METHOD__); | ||
245 | + } | ||
246 | + | ||
247 | + /** | ||
248 | + * Get list action of controller | ||
249 | + * @param mixed $type | ||
250 | + * @param string $id | ||
251 | + * @param \yii\base\Module $module | ||
252 | + * @param string $result | ||
253 | + */ | ||
254 | + protected function getControllerActions($type, $id, $module, &$result) | ||
255 | + { | ||
256 | + $token = "Create controller with cofig=" . VarDumper::dumpAsString($type) . " and id='$id'"; | ||
257 | + Yii::beginProfile($token, __METHOD__); | ||
258 | + try { | ||
259 | + /* @var $controller \yii\base\Controller */ | ||
260 | + $controller = Yii::createObject($type, [$id, $module]); | ||
261 | + $this->getActionRoutes($controller, $result); | ||
262 | + $all = "/{$controller->uniqueId}/*"; | ||
263 | + $result[$all] = $all; | ||
264 | + } catch (Exception $exc) { | ||
265 | + Yii::error($exc->getMessage(), __METHOD__); | ||
266 | + } | ||
267 | + Yii::endProfile($token, __METHOD__); | ||
268 | + } | ||
269 | + | ||
270 | + /** | ||
271 | + * Get route of action | ||
272 | + * @param \yii\base\Controller $controller | ||
273 | + * @param array $result all controller action. | ||
274 | + */ | ||
275 | + protected function getActionRoutes($controller, &$result) | ||
276 | + { | ||
277 | + $token = "Get actions of controller '" . $controller->uniqueId . "'"; | ||
278 | + Yii::beginProfile($token, __METHOD__); | ||
279 | + try { | ||
280 | + $prefix = '/' . $controller->uniqueId . '/'; | ||
281 | + foreach ($controller->actions() as $id => $value) { | ||
282 | + $result[$prefix . $id] = $prefix . $id; | ||
283 | + } | ||
284 | + $class = new \ReflectionClass($controller); | ||
285 | + foreach ($class->getMethods() as $method) { | ||
286 | + $name = $method->getName(); | ||
287 | + if ($method->isPublic() && !$method->isStatic() && strpos($name, 'action') === 0 && $name !== 'actions') { | ||
288 | + $name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', substr($name, 6))); | ||
289 | + $id = $prefix . ltrim(str_replace(' ', '-', $name), '-'); | ||
290 | + $result[$id] = $id; | ||
291 | + } | ||
292 | + } | ||
293 | + } catch (Exception $exc) { | ||
294 | + Yii::error($exc->getMessage(), __METHOD__); | ||
295 | + } | ||
296 | + Yii::endProfile($token, __METHOD__); | ||
297 | + } | ||
298 | + | ||
299 | + /** | ||
300 | + * Ivalidate cache | ||
301 | + */ | ||
302 | + public static function invalidate() | ||
303 | + { | ||
304 | + | ||
305 | + } | ||
306 | + | ||
307 | +} |
@@ -0,0 +1,35 @@ | @@ -0,0 +1,35 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace domain\system\models; | ||
4 | + | ||
5 | +use yii\db\ActiveRecord; | ||
6 | +use yii\behaviors\TimestampBehavior; | ||
7 | + | ||
8 | +/** | ||
9 | + * 路由权限 | ||
10 | + * This is the model class for table "{{%auth_perm.}}". | ||
11 | + */ | ||
12 | +class AuthPerm extends ActiveRecord | ||
13 | +{ | ||
14 | + /** | ||
15 | + * @inheritdoc | ||
16 | + */ | ||
17 | + public static function tableName() | ||
18 | + { | ||
19 | + return '{{%auth_perm}}'; | ||
20 | + } | ||
21 | + | ||
22 | + /** | ||
23 | + * @return array | ||
24 | + */ | ||
25 | + public function behaviors() | ||
26 | + { | ||
27 | + return [ | ||
28 | + 'time' => [ | ||
29 | + 'class' => TimestampBehavior::className(), | ||
30 | + 'createdAtAttribute' => 'created_at', | ||
31 | + 'updatedAtAttribute' => 'updated_at', | ||
32 | + ] | ||
33 | + ]; | ||
34 | + } | ||
35 | +} | ||
0 | \ No newline at end of file | 36 | \ No newline at end of file |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +namespace domain\system\models; | ||
4 | + | ||
5 | +use yii\db\ActiveRecord; | ||
6 | + | ||
7 | +/** | ||
8 | + * 路由权限 | ||
9 | + * This is the model class for table "{{%auth_perms_routes.}}". | ||
10 | + */ | ||
11 | +class AuthPermsRoutes extends ActiveRecord | ||
12 | +{ | ||
13 | + /** | ||
14 | + * @inheritdoc | ||
15 | + */ | ||
16 | + public static function tableName() | ||
17 | + { | ||
18 | + return '{{%auth_perms_routes}}'; | ||
19 | + } | ||
20 | + | ||
21 | +} | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |