getCondition($request); $pageSize = $request->input('limit', 20); $list = BooksService::bookList($where, [], $pageSize); $settlementTypes = array_column($this->settlementTypes(), null, 'value'); if (!$list->isEmpty()) { foreach ($list as $value) { $value->is_on_shelf = 0; if (!is_empty($value->end_date) && $value->end_date < date("Y-m-d")) { $value->is_on_shelf = 1; } $value->settlement_type_text = $settlementTypes[$value->settlement_type]['name'] ?? ""; $value->status_text = $value->status == 1 ? "完本" : "连载"; $value->channel_text = $value->channel == 1 ? "男频" : "女频"; } } return $list; } /** * 结算方式 * name: settlementTypes * @return \string[][] * date 2023/03/23 13:49 */ public function settlementTypes() { return [ ['value' => 'buyout', 'name' => '买断'], ['value' => 'bottomline', 'name' => '保底'], ['value' => 'share', 'name' => '分成'], //['value' => 'zhuishuyun', 'name' => '追书云计算'], ]; } // 查询条件拼接 private function getCondition(Request $request): array { $where = []; if (!empty($request->input('name', ""))) { $where['name'] = $request->input('name'); } if (!empty($request->input('cp_id', 0))) { $where['cp_id'] = $request->input('cp_id', 0); } if (!empty($request->input('settlement_type', ''))) { $where['settlement_type'] = $request->input('settlement_type', ''); } if (!empty($request->input('bid', 0))) { $where['id'] = $request->input('bid', 0); } if (!empty($request->input('author', 0))) { $where['author'] = $request->input('author', 0); } $createStart = $request->input("create_start", ""); $createEnd = $request->input("create_end", ""); if (!empty($createStart) || !empty($createEnd)) { if ($createStart == $createEnd) { $createEnd = date("Y-m-d H:i:s", strtotime($createStart) + 86400); } if ($createStart > $createEnd) { $temp = $createEnd; $createEnd = $createStart; $createStart = $temp; } $where['create_start'] = $createStart; if (!empty($createEnd)) { $where['create_end'] = $createEnd; } } $createStart = $request->input("start_date", ""); $createEnd = $request->input("end_date", ""); if (!empty($createStart) || !empty($createEnd)) { if ($createStart == $createEnd) { $createEnd = date("Y-m-d", strtotime($createStart) + 86400); } if ($createStart > $createEnd) { $temp = $createEnd; $createEnd = $createStart; $createStart = $temp; } $where['start_date'] = $createStart; if (!empty($createEnd)) { $where['end_date'] = $createEnd; } } $where['is_export'] = $request->input('is_export', 0); return $where; } /** * 编辑版权时间和结算方式 * name: editAuthorByBid * @param BookRequest $request * @return bool * date 2023/03/23 13:49 */ public function editAuthorByBid(BookRequest $request) { $bids = explode(',', $request->input('bid')); $param = []; if ($request->has("status")){ $status = $request->input('status'); if (!in_array($status,[0,1])){ throw new FailedException('连载状态不正确'); } $param['status'] = $status; } if ($request->has("settlement_type")){ if (!in_array($request->input('settlement_type'), array_column($this->settlementTypes(), 'value'))) { throw new FailedException('结算方式不正确'); } $param['settlement_type'] = $request->input('settlement_type'); if ($param['settlement_type'] == 'bottomline') { if (!$request->has('bottomline')) { throw new FailedException('保底金额必填!'); } $bottomline = $request->input('bottomline'); if (!is_numeric($bottomline) || $bottomline < 0) { throw new FailedException('保底金额不正确!'); } $param['bottomline'] = $bottomline; } } if (!empty($request->input('start_date', ''))) { $param['start_date'] = $request->input('start_date'); } if (!empty($request->input('end_date', ''))) { $param['end_date'] = $request->input('end_date'); } $distributePrivilege = $request->input('distribution_privilege'); if($distributePrivilege) { foreach ($bids as $bid) { BooksService::distributeSubmit($bid, $distributePrivilege); } } if (!empty($param)){ return BooksService::editAuthorByBids($bids, $param); } return true; } /** * 书籍编辑时获取书籍信息 * name: bookInfo * @param $bid * @return Model|null * date 2023/03/23 15:35 */ public function bookInfo($bid) { return (new Book())->firstBy($bid); } /** * 获取书籍版权分库信息 * name: distributeInfo * @param $bid * date 2023/03/23 15:51 */ public function distributeInfo($bid) { return BooksService::distributeInfo($bid); } /** * 获取书籍版权分库信息 * name: distributeInfo * @param $bid * date 2023/03/23 15:51 */ public function distributeSubmit($bid, Request $request) { $param = $request->input('channels'); return BooksService::distributeSubmit($bid, $param); } public function export($bid) { return BooksService::exportByBid($bid); } public function createBook(Request $request){ $cp_id = $request->post('cp_id'); $cp_name = $request->post('cp_name'); $book_name = $request->post('book_name'); $author = $request->post('author'); $channel = $request->post('channel'); $status = $request->post('status',1); $category_id = $request->post('category_id'); $category_name = $request->post('category_name'); $vip_start = $request->post('vip_start',10); $path = $request->post('path'); \Log::info('import',['path'=>$path]); $result = BooksService::createBook([ 'cp_name'=>$cp_name,'cp_id'=>$cp_id,'name'=>$book_name,'author'=>$author,'intro'=>'','cover'=>'','category_id'=>$category_id, 'category_name'=>$category_name,'status'=>$status,'channel'=>$channel ]); if(!$result){ throw new FailedException('已经导过了'); } $chapter_result = ChapterService::createChapterFromFile($result->id,1,$vip_start,storage_path('app/'.$path)); Storage::delete($path); $result->size = $chapter_result['size']; $result->chapter_count = $chapter_result['chapter_count']; $result->first_cid = $chapter_result['first_cid']; $result->last_cid = $chapter_result['last_cid']; $result->last_chapter = $chapter_result['last_chapter']; $result->save(); $chapter_result['bid'] = $result->id; return $chapter_result; } public function import(Request $request){ if (!$request->hasFile('file')) { throw new FailedException('缺少文件哦'); } $file = $request->file('file'); $path = $file->path(); \Log::info('import',['path'=>$path]); $extension = $request->file->extension(); $name = \Str::random(40).'.'.$extension; $path = $request->file->storeAs('book',$name); return ['path'=>$path]; } public function categoryList(Request $request){ $bookCategories = new BookCategories(); $category_list = $bookCategories->show() ->select('id','category_name','channel_id','channel_name','pid')->get(); $result = [ ['channel_id'=>1,'channel_name'=>'男频','list'=>[]], ['channel_id'=>2,'channel_name'=>'女频','list'=>[]], ]; foreach ($category_list as $item){ //if($item->pid == 0) continue; $temp = ['category_id'=>$item->id,'category_name'=>$item->category_name]; if($item->channel_id == 1){ $result[0]['list'][] = $temp; } if($item->channel_id == 2){ $result[1]['list'][] = $temp; } } return $result; } }