Commit c8082ab0c3d96a3a304d83ee166d08693e68e80b

Authored by xu
1 parent 069e7a54
Exists in master

app-ht

1. F 彻底删除序列号记录
app-ht/modules/device/controllers/DeviceController.php
... ... @@ -7,6 +7,7 @@ use yii\base\Exception;
7 7 use yii\data\Pagination;
8 8 use app\ht\controllers\BaseController;
9 9 use common\helpers\Utils;
  10 +use common\models\AdminLog as AdminLogModel;
10 11 use domain\device\DeviceAuthFailRepository;
11 12 use domain\device\models\DeviceAuthFail as DeviceAuthFailModel;
12 13 use domain\device\DeviceStatus;
... ... @@ -17,6 +18,7 @@ use domain\device\models\Device as DeviceModel;
17 18 use domain\device\CreateBatch;
18 19  
19 20 use stdClass;
  21 +use yii\helpers\Url;
20 22  
21 23 /**
22 24 * 设备管理
... ... @@ -151,7 +153,12 @@ class DeviceController extends BaseController
151 153 public function actionDeleteIndex()
152 154 {
153 155 $params = $this->dataList(1, 1);
154   -
  156 + $user = Yii::$app->user->identity;
  157 + if (isset($user->username) && 'admin' == $user->username) {
  158 + $params['is_admin'] = 1;
  159 + } else {
  160 + $params['is_admin'] = 0;
  161 + }
155 162 return $this->render('delete-index', $params);
156 163 }
157 164  
... ... @@ -281,7 +288,6 @@ class DeviceController extends BaseController
281 288 $user = Yii::$app->user->identity;
282 289 if (isset($user->is_manufacture) && $user->is_manufacture == 1) {
283 290 $where = 'sys_user_id = '.$user->id;
284   -
285 291 } else {
286 292 $where = 'id >0';
287 293 }
... ... @@ -536,6 +542,59 @@ class DeviceController extends BaseController
536 542 }
537 543  
538 544 /**
  545 + * @return string
  546 + */
  547 + public function actionDelDeviceForever()
  548 + {
  549 + $req = Yii::$app->request;
  550 + $ids = $req->post('ids');
  551 + $e = new stdClass();
  552 + $e->success = false;
  553 + $e->message = 'fail';
  554 + $ids = explode(',', $ids);
  555 +
  556 + $user = Yii::$app->user->identity;
  557 + if (!isset($user->username) || 'admin' != $user->username || 1 == $user->is_manufacture) {
  558 + $e->message = '删除失败, 只有超管理员能删除';
  559 + return $this->renderJson($e);
  560 + }
  561 + $deviceModels = DeviceRepository::findAll(['id' => $ids]);
  562 + if (empty($deviceModels)) {
  563 + $e->message = '找不到该设备';
  564 + return $this->renderJson($e);
  565 + }
  566 +
  567 + $deleteItems = [];
  568 + foreach ($deviceModels as $k => $v) {
  569 + $deleteItems[] = $v->toArray();
  570 + }
  571 + $trans = Yii::$app->getDb()->beginTransaction();
  572 + try {
  573 + DeviceModel::deleteAll(['id' => $ids]);
  574 + $userName = Yii::$app->user->identity->username;
  575 + $tableName = DeviceModel::tableName();
  576 + $description = sprintf("%s删除了表%s的数据%s", $userName, $tableName, json_encode($deleteItems, JSON_UNESCAPED_UNICODE));
  577 + $route = Url::to();
  578 + $userId = Yii::$app->user->id;
  579 + $ip = Utils::clientIp();
  580 + $model = new AdminLogModel();
  581 + $model->route = $route;
  582 + $model->description = $description;
  583 + $model->user_id = $userId;
  584 + $model->ip = $ip;
  585 + $model->save();
  586 + $trans->commit();
  587 + $e->message = '成功删除'. count($ids).'条记录';
  588 + $e->success = true;
  589 + } catch(Exception $exception) {
  590 + $trans->rollBack();
  591 + $e->message = '删除失败';
  592 + }
  593 +
  594 + return $this->renderJson($e);
  595 + }
  596 +
  597 + /**
539 598 * 编辑
540 599 * @return string
541 600 */
... ...
app-ht/modules/device/views/device/delete-index.php
... ... @@ -91,7 +91,7 @@ $this->params['breadcrumbs'][] = $this->title;
91 91 <div class="panel-body">
92 92 <ul id="countryTab" class="nav nav-tabs" style="margin-bottom: 20px">
93 93 <li ><a style="padding: 10px 20px;" href="<?=Url::toRoute('/device/device/index')?>" >全部序列号</a></li>
94   - <li class="active" ><a style="padding: 10px 12px;" href="<?=Url::toRoute('/device/device/delete-index')?>" >删除序列号</a></li>
  94 + <li class="active" ><a style="padding: 10px 12px;" href="<?=Url::toRoute('/device/device/delete-index')?>" >已删序列号</a></li>
95 95 </ul>
96 96  
97 97 <table class="table table-striped table-bordered" id="brand-table">
... ... @@ -107,7 +107,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
107 107 <th width="8%">申请时间</th>
108 108 <th width="8%">授权时间</th>
109 109 <th width="8%">状态</th>
110   - <th width="7%">状态</th>
  110 + <th width="8%">状态</th>
111 111 <th >操作</th>
112 112 </tr>
113 113 </thead>
... ... @@ -150,6 +150,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
150 150 <td class="td-cls">
151 151 <button class="btn btn-info btn-sm btn_edit" aid="<?=$item['id'] ?>" data-action="edit">编辑</button> &nbsp;|&nbsp;
152 152 <button class="btn btn-warning btn-sm btn_restore" aid="<?=$item['id'] ?>">恢复</button>
  153 + <?php if($is_admin) {?><button class="btn btn-danger btn-sm btn_del_forever" aid="<?=$item['id'] ?>">彻底删除</button><?php }?>
153 154 </td>
154 155 </tr>
155 156 <?php endforeach; ?>
... ... @@ -164,6 +165,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
164 165 </table>
165 166 <div class="action-box">
166 167 <label><input type="checkbox" class="check-all" value="all" /> 本页全选 </label> <button class="btn btn-primary btn-sm btn_batch_auth" >批量恢复</button>
  168 + <?php if($is_admin) {?><button class="btn btn-danger btn-sm btn_batch_del_forever" >彻底删除</button><?php }?>
167 169 </div>
168 170 </div>
169 171  
... ... @@ -180,6 +182,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
180 182 <script>
181 183 var authURL = "<?=Url::toRoute('/device/device/auth-device')?>";
182 184 var delURL = "<?=Url::toRoute('/device/device/del-device')?>";
  185 + var delForeverURL = "<?=Url::toRoute('/device/device/del-device-forever')?>";
183 186 var restoreURL = "<?=Url::toRoute('/device/device/restore-device')?>";
184 187 var batchRestoreURL = "<?=Url::toRoute('/device/device/batch-restore-device')?>";
185 188 var doEditURL = "<?=Url::toRoute('/device/device/do-edit')?>";
... ... @@ -276,5 +279,49 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
276 279 }, 'json')
277 280 })
278 281  
  282 + $('.btn_del_forever').click(function(e){
  283 + if(!confirm('彻底删除之后不能恢复!')) {
  284 + return false;
  285 + }
  286 + var ids = $(this).attr('aid');
  287 + $.post(delForeverURL,{ids:ids},function(res){
  288 + if (res.success) {
  289 + alert(res.message);
  290 + var _body = window.parent;
  291 + var _iframe1=_body.document.getElementById('x-iframe');
  292 + _iframe1.contentWindow.location.reload(true);
  293 + } else {
  294 + alert(res.message);
  295 + }
  296 + }, 'json')
  297 + })
  298 +
  299 + $('.btn_batch_del_forever').click(function(e) {
  300 + var checkedItems = $('.check-item:checked');
  301 + if (0 == checkedItems.length) {
  302 + alert('未选择删除项');
  303 + return false;
  304 + }
  305 + if(!confirm('选中'+checkedItems.length+'条记录。彻底删除之后不能恢复!')) {
  306 + return false;
  307 + }
  308 + var ids = [];
  309 + $.each(checkedItems, function(i,n){
  310 + ids.push($(n).val())
  311 + })
  312 + ids = ids.join(',');
  313 +
  314 + $.post(delForeverURL,{ids:ids},function(res){
  315 + if (res.success) {
  316 + alert(res.message);
  317 + var _body = window.parent;
  318 + var _iframe1=_body.document.getElementById('x-iframe');
  319 + _iframe1.contentWindow.location.reload(true);
  320 + } else {
  321 + alert(res.message);
  322 + }
  323 + }, 'json')
  324 + })
  325 +
279 326 });
280 327 </script>
281 328 \ No newline at end of file
... ...
app-ht/modules/device/views/device/index.php
... ... @@ -93,7 +93,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
93 93 <div class="panel-body">
94 94 <ul id="countryTab" class="nav nav-tabs" style="margin-bottom: 20px">
95 95 <li class="active" ><a style="padding: 10px 20px;" href="<?=Url::toRoute('/device/device/index')?>" >全部序列号</a></li>
96   - <li ><a style="padding: 10px 12px;" href="<?=Url::toRoute('/device/device/delete-index')?>" >删除序列号</a></li>
  96 + <li ><a style="padding: 10px 12px;" href="<?=Url::toRoute('/device/device/delete-index')?>" >已删序列号</a></li>
97 97 </ul>
98 98  
99 99 <table class="table table-striped table-bordered" id="brand-table">
... ...