Browse Source

fix:标签组问题

super-yimizi 2 months ago
parent
commit
5376538b1c

+ 107 - 0
application/admin/controller/shop/GoodsLabelGroup.php

@@ -56,5 +56,112 @@ class GoodsLabelGroup extends Backend
         }
         }
         return $this->view->fetch();
         return $this->view->fetch();
     }
     }
+
+         /**
+     * 添加
+     */
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $params = $this->request->post('row/a');
+            if ($params) {
+                if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
+                    $params[$this->dataLimitField] = $this->auth->id;
+                }
+                // 检查标签名称是否唯一
+                $label = $this->model->where('name', $params['name'])->find();
+                if ($label) {
+                    $this->error('分组名称已存在');
+                }
+                $result = false;
+                Db::startTrans();
+                try {
+                    //是否采用模型验证
+                    if ($this->modelValidate) {
+                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
+                        $this->model->validateFailException(true)->validate($validate);
+                    }
+                    $result = $this->model->allowField(true)->save($params);
+                    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 inserted'));
+                }
+            }
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        return $this->view->fetch();
+    }
   
   
+
+    /**
+     * 编辑
+     */
+    public function edit($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');
+            if ($params) {
+                // 检查标签名称是否唯一
+                $label = $this->model->where('name', $params['name'])->where('id', 'neq', $row->id)->find();
+                if ($label) {
+                    $this->error('分组名称已存在');
+                }
+                $params = $this->preExcludeFields($params);
+                $result = false;
+                Db::startTrans();
+                try {
+                    //是否采用模型验证
+                    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);
+                    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();
+    }
+
 }
 }

+ 8 - 7
application/admin/view/shop/goods_label_group/edit.html

@@ -1,8 +1,8 @@
-<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
     <div class="form-group">
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">分组名称:</label>
         <label class="control-label col-xs-12 col-sm-2">分组名称:</label>
         <div class="col-xs-12 col-sm-8">
         <div class="col-xs-12 col-sm-8">
-            <input id="c-name" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}" placeholder="请输入分组名称" data-rule="required">
+            <input id="c-name" class="form-control" name="row[name]" type="text" placeholder="请输入分组名称" data-rule="required" value="{$row.name|htmlentities}">
         </div>
         </div>
     </div>
     </div>
     <div class="form-group">
     <div class="form-group">
@@ -12,14 +12,15 @@
         </div>
         </div>
     </div>
     </div>
     <div class="form-group">
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">状态:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
         <div class="col-xs-12 col-sm-8">
         <div class="col-xs-12 col-sm-8">
+            
             <div class="radio">
             <div class="radio">
-                {foreach name="statusList" item="vo"}
-                <label for="row[status]-{$key|htmlentities}"><input id="row[status]-{$key|htmlentities}" data-rule="required" name="row[status]" type="radio" value="{$key|htmlentities}" {in name="key" value="{$row.status}"}checked{/in} /> {$vo|htmlentities}</label>
-                {/foreach}
-               
+            {foreach name="statusList" item="vo"}
+            <label for="row[status]-{$key}"><input id="row[status]-{$key}" name="row[status]" type="radio" value="{$key}" {in name="key" value="$row.status"}checked{/in} /> {$vo}</label> 
+            {/foreach}
             </div>
             </div>
+
         </div>
         </div>
     </div>
     </div>
     <div class="form-group layer-footer">
     <div class="form-group layer-footer">