作者 景琛

问题修改

@@ -36,6 +36,46 @@ class Team extends Backend @@ -36,6 +36,46 @@ class Team extends Backend
36 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 36 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
37 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 37 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
38 */ 38 */
  39 + /**
  40 + * 添加
  41 + *
  42 + * @return string
  43 + * @throws \think\Exception
  44 + */
  45 + public function add()
  46 + {
  47 + if (false === $this->request->isPost()) {
  48 + return $this->view->fetch();
  49 + }
  50 + $params = $this->request->post('row/a');
  51 + if (empty($params)) {
  52 + $this->error(__('Parameter %s can not be empty', ''));
  53 + }
  54 + $params = $this->preExcludeFields($params);
  55 +
  56 + if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
  57 + $params[$this->dataLimitField] = $this->auth->id;
  58 + }
  59 + $result = false;
  60 + Db::startTrans();
  61 + try {
  62 + //是否采用模型验证
  63 + if ($this->modelValidate) {
  64 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  65 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
  66 + $this->model->validateFailException()->validate($validate);
  67 + }
  68 + $result = $this->model->allowField(true)->save($params);
  69 + Db::commit();
  70 + } catch (ValidateException|PDOException|Exception $e) {
  71 + Db::rollback();
  72 + $this->error($e->getMessage());
  73 + }
  74 + if ($result === false) {
  75 + $this->error(__('No rows were inserted'));
  76 + }
  77 + $this->success();
  78 + }
39 79
40 /** 80 /**
41 * 编辑 81 * 编辑
@@ -31,10 +31,6 @@ class Team extends Model @@ -31,10 +31,6 @@ class Team extends Model
31 31
32 protected static function init() 32 protected static function init()
33 { 33 {
34 - self::afterInsert(function ($row) {  
35 - $pk = $row->getPk();  
36 - $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);  
37 - });  
38 } 34 }
39 35
40 public function getRankTextAttr($value,$data){ 36 public function getRankTextAttr($value,$data){