Sfoglia il codice sorgente

完善后台昵称审核

15954078560 3 anni fa
parent
commit
0762c9941a

+ 79 - 10
application/admin/controller/applys/Nickname.php

@@ -138,25 +138,95 @@ class Nickname extends Backend
         }
         if ($this->request->isPost()) {
             $params = $this->request->post("row/a");
+            $params['status'] = 1;
             if ($params) {
                 $params = $this->preExcludeFields($params);
                 $result = false;
                 Db::startTrans();
                 try {
-                    if($row['status'] == 0 && $row['status'] != $params['status']) {
-                        if($params['status'] == 1) {
-                            \app\common\model\User::update(['nickname'=>$params['nickname']],['id'=>$params['user_id']]);
+//                    if($row['status'] == 0 && $row['status'] != $params['status']) {
+//                        if($params['status'] == 1) {
+                            \app\common\model\User::update(['nickname'=>$row['nickname']],['id'=>$row['user_id']]);
                             $title = '昵称审核成功!';
                             $content = '恭喜您,您的昵称修改审核成功!';
                             \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
-                        }
-                        if($params['status'] == -1) {
-                            \app\common\model\User::update(['nickname'=>$params['old_nickname']],['id'=>$params['user_id']]);
+//                        }
+//                        if($params['status'] == -1) {
+//                            \app\common\model\User::update(['nickname'=>$params['old_nickname']],['id'=>$params['user_id']]);
+//                            $title = '昵称审核失败!';
+//                            $content = '非常抱歉,您的昵称由于不符合平台规范,管理员已审核拒绝!';
+//                            \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
+//                        }
+//                    }
+
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                        $row->validateFailException(true)->validate($validate);
+                    }
+                    $result = $row->allowField(true)->save($params);
+                    delUserInfo($row['user_id']);
+                    Db::commit();
+                } catch (ValidateException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (PDOException $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                } catch (Exception $e) {
+                    Db::rollback();
+                    $this->error($e->getMessage());
+                }
+                if ($result !== false) {
+                    $this->success();
+                } else {
+                    $this->error(__('No rows were updated'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $this->view->assign("row", $row);
+        return $this->view->fetch();
+    }
+
+    /**
+     * 拒绝
+     */
+    public function del($ids = null)
+    {
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            if (!in_array($row[$this->dataLimitField], $adminIds)) {
+                $this->error(__('You have no permission'));
+            }
+        }
+        if ($this->request->isPost()) {
+            $params = $this->request->post("row/a");
+            $params['status'] = -1;
+            if ($params) {
+                $params = $this->preExcludeFields($params);
+                $result = false;
+                Db::startTrans();
+                try {
+//                    if($row['status'] == 0 && $row['status'] != $params['status']) {
+//                        if($params['status'] == 1) {
+//                            \app\common\model\User::update(['nickname'=>$params['nickname']],['id'=>$params['user_id']]);
+//                            $title = '昵称审核成功!';
+//                            $content = '恭喜您,您的昵称修改审核成功!';
+//                            \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
+//                        }
+//                        if($params['status'] == -1) {
+                            \app\common\model\User::update(['nickname'=>$row['old_nickname']],['id'=>$row['user_id']]);
                             $title = '昵称审核失败!';
                             $content = '非常抱歉,您的昵称由于不符合平台规范,管理员已审核拒绝!';
                             \app\common\model\SysMsg::sendSysMsg($row['user_id'],2,$title,$content);
-                        }
-                    }
+//                        }
+//                    }
 
                     //是否采用模型验证
                     if ($this->modelValidate) {
@@ -165,7 +235,7 @@ class Nickname extends Backend
                         $row->validateFailException(true)->validate($validate);
                     }
                     $result = $row->allowField(true)->save($params);
-                    delUserInfo($params['user_id']);
+                    delUserInfo($row['user_id']);
                     Db::commit();
                 } catch (ValidateException $e) {
                     Db::rollback();
@@ -188,6 +258,5 @@ class Nickname extends Backend
         $this->view->assign("row", $row);
         return $this->view->fetch();
     }
-    
 
 }

+ 10 - 4
public/assets/js/backend/applys/nickname.js

@@ -39,16 +39,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     name: 'edit',
                                     text: '同意',
                                     icon: 'fa fa-pencil',
-                                    title: __('Edit'),
+                                    title: __('同意'),
                                     extend: 'data-toggle="tooltip"',
-                                    classname: 'btn btn-xs btn-success btn-editone'
+                                    classname: 'btn btn-xs btn-success btn-ajax',
+                                    confirm: '确认通过?',
+                                    url: 'applys/nickname/edit',
+                                    refresh: true,
                                 }, {
                                     name: 'del',
                                     text: '拒绝',
                                     icon: 'fa fa-trash',
-                                    title: __('Del'),
+                                    title: __('拒绝'),
                                     extend: 'data-toggle="tooltip"',
-                                    classname: 'btn btn-xs btn-danger btn-delone'
+                                    classname: 'btn btn-xs btn-danger btn-ajax',
+                                    confirm: '确认拒绝?',
+                                    url: 'applys/nickname/del',
+                                    refresh: true,
                                 },
                             ]
                         }