public function actionSet() { if (Yii::$app->request->isGet) { $book_id = intval($this->get("id", 0)); if (!$book_id) { return $this->renderJSON([], "指定数据不存在~~", -1); } $book_info = Book::findOne(["id" => $book_id]); if (!$book_info) { return $this->renderJSON([], "指定数据不存在~~", -1); } $content_html = $this->renderPartial("set", ["info" => $book_info, 'read_status' => Constant::$read_desc]); return $this->renderJSON(['form_wrap' => $content_html]); } $book_id = intval($this->post("id", 0)); $read_status = intval($this->post("read_status", 0)); $read_start_time = trim($this->post("read_start_time", '')); $read_end_time = trim($this->post("read_end_time", '')); $date_now = date("Y-m-d H:i:s"); if (!$book_id) { return $this->renderJSON([], "操作数据可能不是你的吧!!", -1); } if ($read_status == -1 && (!$read_start_time || !$read_end_time)) { return $this->renderJSON([], "请选择读书开始和结束时间!!", -1); } $book_info = Book::findOne(["id" => $book_id]); if (!$book_info) { return $this->renderJSON([], "操作数据可能不是你的吧!!", -1); } $book_info->read_status = $read_status; $book_info->updated_time = $date_now; if (in_array($read_status, [-1, -2])) { $book_info->read_start_time = $read_start_time . " 00:00:00"; $book_info->read_end_time = $read_end_time . " 23:59:59"; } $book_info->update(0); return $this->renderJSON([], "操作成功!!"); }