public function save() { if (is_numeric($this->id)) { $select = TbSelect::findOne($this->id); } else { $select = new TbSelect(); } $select->fdName = $this->name; if (!$select->save()) { echo json_encode(['code' => -1, 'msg' => json_encode($select->errors, JSON_UNESCAPED_UNICODE)]); return false; } echo json_encode(['code' => 0, 'msg' => '请求操作成功', 'result' => ['id' => $select->id]]); return true; }
public static function getSelectID() { if (empty(self::$select_ret)) { self::$select_ret = ['0' => '未选']; $selects = TbSelect::find()->where('fdDisabled = 0')->all(); foreach ($selects as $select) { self::$select_ret[$select->id] = $select->fdName; } } return self::$select_ret; }
public function search() { $search = TbSelect::find(); if ($this->name > '') { $search->andWhere("fdName like :name", [":name" => "%" . $this->name . "%"]); } if ($this->disabled > '') { $search->andWhere("fdDisabled = :disabled", [":disabled" => $this->disabled]); } $pages = new Pagination(['totalCount' => $search->count(), 'pageSize' => 10]); $datas = $search->offset($pages->offset)->limit($pages->limit)->all(); return ['datas' => $datas, 'pages' => $pages]; }
public function enable($id) { $operator = TbSelect::updateAll(['fdDisabled' => 0], "id = :id", [":id" => $id]); echo json_encode(['code' => 0, 'msg' => '请求操作成功'], JSON_UNESCAPED_UNICODE); }