/** * 添加资源 * @method POST_indexAction * @author NewFuture */ public function POST_indexAction() { $pid = $this->authPrinter(); if (Input::post('books', $books)) { /*批量插入*/ $books = explode("\n", $books); $books = array_map(array('\\Parse\\Filter', 'title'), $books); $books = array_filter($books); $data = array(); foreach ($books as $key => $name) { $data[] = [$pid, $name]; } /*全部插入*/ if (BookModel::insertAll(['pri_id', 'name'], $data)) { $this->response(1, $books); } else { $this->response(0, '批量插入失败'); } } elseif (Input::post('name', $name, 'title')) { /*单个插入*/ $book['name'] = $name; $book['pri_id'] = $pid; if (Input::post('price', $price, 'float')) { $book['price'] = $price; } if (Input::post('detail', $detail, 'text')) { $book['detail'] = $detail; } if ($book['id'] = BookModel::insert($book)) { $this->response(1, $book); } else { $this->response(0, '添加失败'); } } else { $this->response(0, '数据无效'); } }